<?php
$version_to_rollback = '0.02'; // Or read from history
$backup_dir = "backup/v$version_to_rollback/";

if (!is_dir($backup_dir)) {
    die("Backup not found.\n");
}

// Recursively restore backup
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($backup_dir));
foreach ($rii as $file) {
    if (!$file->isDir()) {
        $source = $file->getPathname();
        $dest = str_replace($backup_dir, '', $source);
        copy($source, $dest);
    }
}

file_put_contents('version.txt', $version_to_rollback);
echo "Rollback to version $version_to_rollback completed.\n";
