From 7192cfe5495be0dcf317acc9613adfa69fffc700 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Thu, 16 Oct 2025 08:09:47 -0600 Subject: [PATCH] synced restore changes Signed-off-by: Andy Miller --- bin/{grav-restore => restore} | 63 ++++++++++++++++++++++++++++++++--- 1 file changed, 58 insertions(+), 5 deletions(-) rename bin/{grav-restore => restore} (70%) diff --git a/bin/grav-restore b/bin/restore similarity index 70% rename from bin/grav-restore rename to bin/restore index a8087148a..e949471fe 100755 --- a/bin/grav-restore +++ b/bin/restore @@ -25,6 +25,7 @@ if (!file_exists($root . '/index.php')) { exit(1); } +use Grav\Common\Recovery\RecoveryManager; use Grav\Common\Upgrade\SafeUpgradeService; use Symfony\Component\Yaml\Yaml; @@ -32,19 +33,24 @@ const RESTORE_USAGE = << [--staging-root=/absolute/path] + bin/restore apply [--staging-root=/absolute/path] Restores the specified snapshot created by safe-upgrade. + bin/restore recovery [status|clear] + Shows the recovery flag context or clears it. + Options: --staging-root Overrides the staging directory (defaults to configured value). Examples: - bin/grav-restore list - bin/grav-restore apply stage-68eff31cc4104 - bin/grav-restore apply stage-68eff31cc4104 --staging-root=/var/grav-backups + bin/restore list + bin/restore apply stage-68eff31cc4104 + bin/restore apply stage-68eff31cc4104 --staging-root=/var/grav-backups + bin/restore recovery status + bin/restore recovery clear USAGE; /** @@ -207,6 +213,53 @@ switch ($command) { echo "Restored snapshot {$snapshotId} (Grav {$version}).\n"; exit(0); + case 'recovery': + $action = strtolower($arguments[0] ?? 'status'); + $manager = new RecoveryManager(GRAV_ROOT); + + switch ($action) { + case 'clear': + if ($manager->isActive()) { + $manager->clear(); + echo "Recovery flag cleared.\n"; + } else { + echo "Recovery mode is not active.\n"; + } + exit(0); + + case 'status': + if (!$manager->isActive()) { + echo "Recovery mode is not active.\n"; + exit(0); + } + + $context = $manager->getContext(); + if (!$context) { + echo "Recovery flag present but context could not be parsed.\n"; + exit(1); + } + + $created = isset($context['created_at']) ? date('c', (int)$context['created_at']) : 'unknown'; + $token = $context['token'] ?? '(missing)'; + $message = $context['message'] ?? '(no message)'; + $plugin = $context['plugin'] ?? '(none detected)'; + $file = $context['file'] ?? '(unknown file)'; + $line = $context['line'] ?? '(unknown line)'; + + echo "Recovery flag context:\n"; + echo " Token: {$token}\n"; + echo " Message: {$message}\n"; + echo " Plugin: {$plugin}\n"; + echo " File: {$file}\n"; + echo " Line: {$line}\n"; + echo " Created: {$created}\n"; + exit(0); + + default: + echo "Unknown recovery action: {$action}\n\n" . RESTORE_USAGE . "\n"; + exit(1); + } + case 'help': default: echo RESTORE_USAGE . "\n";