From 52f0d5f1d789ad561ef16a890196a1969b006734 Mon Sep 17 00:00:00 2001 From: Andy Miller Date: Sun, 19 Oct 2025 17:32:55 -0600 Subject: [PATCH] more fixes for recovery.window and recovery.flag Signed-off-by: Andy Miller --- system/src/Grav/Common/Recovery/RecoveryManager.php | 6 ++++-- .../src/Grav/Common/Upgrade/SafeUpgradeService.php | 12 +++++++++--- system/src/Grav/Console/Gpm/UpdateCommand.php | 2 ++ .../Grav/Common/Upgrade/SafeUpgradeServiceTest.php | 4 ++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/system/src/Grav/Common/Recovery/RecoveryManager.php b/system/src/Grav/Common/Recovery/RecoveryManager.php index e75f7267e..2e59ab2af 100644 --- a/system/src/Grav/Common/Recovery/RecoveryManager.php +++ b/system/src/Grav/Common/Recovery/RecoveryManager.php @@ -303,7 +303,7 @@ class RecoveryManager */ private function windowPath(): string { - return $this->rootPath . '/system/recovery.window'; + return $this->userPath . '/data/recovery.window'; } /** @@ -403,7 +403,9 @@ class RecoveryManager 'expires_at' => $createdAt + $ttl, ]; - file_put_contents($this->windowPath(), json_encode($payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n"); + $path = $this->windowPath(); + Folder::create(dirname($path)); + file_put_contents($path, json_encode($payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . "\n"); } /** diff --git a/system/src/Grav/Common/Upgrade/SafeUpgradeService.php b/system/src/Grav/Common/Upgrade/SafeUpgradeService.php index b8cab0a8a..a0670750b 100644 --- a/system/src/Grav/Common/Upgrade/SafeUpgradeService.php +++ b/system/src/Grav/Common/Upgrade/SafeUpgradeService.php @@ -418,9 +418,15 @@ class SafeUpgradeService */ public function clearRecoveryFlag(): void { - $flag = $this->rootPath . '/user/data/recovery.flag'; - if (is_file($flag)) { - @unlink($flag); + $paths = [ + $this->rootPath . '/user/data/recovery.flag', + $this->rootPath . '/user/data/recovery.window', + ]; + + foreach ($paths as $path) { + if (is_file($path)) { + @unlink($path); + } } } diff --git a/system/src/Grav/Console/Gpm/UpdateCommand.php b/system/src/Grav/Console/Gpm/UpdateCommand.php index 143500c08..af6ba77e5 100644 --- a/system/src/Grav/Console/Gpm/UpdateCommand.php +++ b/system/src/Grav/Console/Gpm/UpdateCommand.php @@ -235,6 +235,8 @@ class UpdateCommand extends GpmCommand return 1; } + $recovery->closeUpgradeWindow(); + return 0; } diff --git a/tests/unit/Grav/Common/Upgrade/SafeUpgradeServiceTest.php b/tests/unit/Grav/Common/Upgrade/SafeUpgradeServiceTest.php index 1b6f64acd..504c488d0 100644 --- a/tests/unit/Grav/Common/Upgrade/SafeUpgradeServiceTest.php +++ b/tests/unit/Grav/Common/Upgrade/SafeUpgradeServiceTest.php @@ -191,8 +191,11 @@ PHP; { [$root] = $this->prepareLiveEnvironment(); $flag = $root . '/user/data/recovery.flag'; + $window = $root . '/user/data/recovery.window'; Folder::create(dirname($flag)); file_put_contents($flag, 'flag'); + Folder::create(dirname($window)); + file_put_contents($window, json_encode(['expires_at' => time() + 120])); $service = new SafeUpgradeService([ 'root' => $root, @@ -200,6 +203,7 @@ PHP; $service->clearRecoveryFlag(); self::assertFileDoesNotExist($flag); + self::assertFileDoesNotExist($window); } /**