diff --git a/index.php b/index.php index 242794a05..30e2e0ae6 100644 --- a/index.php +++ b/index.php @@ -20,6 +20,19 @@ if (PHP_SAPI === 'cli-server') { } } +// Maintenance mode during core upgrade +if (file_exists(__DIR__ . '/.upgrading')) { + if (time() - filemtime(__DIR__ . '/.upgrading') > 300) { + @unlink(__DIR__ . '/.upgrading'); // Stale flag (>5 min), remove it + } else { + http_response_code(503); + header('Retry-After: 60'); + echo 'Upgrading'; + echo '

Site Upgrading

Please try again in a moment.

'; + exit; + } +} + // Ensure vendor libraries exist $autoload = __DIR__ . '/vendor/autoload.php'; if (!is_file($autoload)) { diff --git a/system/src/Grav/Common/GPM/Installer.php b/system/src/Grav/Common/GPM/Installer.php index 84d656261..2b4b0fe72 100644 --- a/system/src/Grav/Common/GPM/Installer.php +++ b/system/src/Grav/Common/GPM/Installer.php @@ -298,6 +298,12 @@ class Installer */ public static function sophisticatedInstall($source_path, $install_path, $ignores = [], $keep_source = false) { + // Set maintenance mode flag and clear opcache before file operations + @file_put_contents(GRAV_ROOT . '/.upgrading', date('Y-m-d H:i:s')); + if (function_exists('opcache_reset')) { + @opcache_reset(); + } + foreach (new DirectoryIterator($source_path) as $file) { if ($file->isLink() || $file->isDot() || in_array($file->getFilename(), $ignores, true)) { continue; @@ -325,6 +331,13 @@ class Installer } } + // Remove maintenance mode flag and clear opcache after file operations + @unlink(GRAV_ROOT . '/.upgrading'); + clearstatcache(true); + if (function_exists('opcache_reset')) { + @opcache_reset(); + } + return true; } diff --git a/system/src/Grav/Installer/Install.php b/system/src/Grav/Installer/Install.php index 0db7036b9..99f1ad1c3 100644 --- a/system/src/Grav/Installer/Install.php +++ b/system/src/Grav/Installer/Install.php @@ -122,6 +122,33 @@ final class Install /** @var static */ private static $instance; + /** + * Backward-compatibility: older versions (e.g. 1.7.50) with safe-upgrade call + * forceSafeUpgrade() / getLastManifest() on the Install singleton loaded from + * the update package. These stubs prevent fatal errors when downgrading from + * a safe-upgrade-aware release to one that removed it. + */ + + /** @var bool|null */ + private static $forceSafeUpgrade = null; + + /** + * @param bool|null $state + * @return void + */ + public static function forceSafeUpgrade(?bool $state = true): void + { + self::$forceSafeUpgrade = $state; + } + + /** + * @return array|null + */ + public function getLastManifest(): ?array + { + return null; + } + /** * @return static */