mirror of
https://github.com/getgrav/grav.git
synced 2026-02-26 00:21:31 +01:00
Add upgrade resilience: maintenance mode, opcache reset, and 1.7.50 compat stubs
This commit is contained in:
13
index.php
13
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 '<!DOCTYPE html><html><head><title>Upgrading</title></head>';
|
||||
echo '<body><h1>Site Upgrading</h1><p>Please try again in a moment.</p></body></html>';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure vendor libraries exist
|
||||
$autoload = __DIR__ . '/vendor/autoload.php';
|
||||
if (!is_file($autoload)) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user