MDL-82171 core: Rewarm bootstrap.php after a cache purge

This commit is contained in:
Brendan Heywood
2024-07-08 12:53:38 +10:00
parent fd32ceac7c
commit 6bdf1b78b2
3 changed files with 35 additions and 9 deletions
+15 -5
View File
@@ -675,19 +675,29 @@ if (PHPUNIT_TEST and !PHPUNIT_UTIL) {
}
// Load any immutable bootstrap config from local cache.
$bootstrapcachefile = $CFG->localcachedir . '/bootstrap.php';
if (is_readable($bootstrapcachefile)) {
$bootstraplocalfile = $CFG->localcachedir . '/bootstrap.php';
$bootstrapsharedfile = $CFG->cachedir . '/bootstrap.php';
if (!is_readable($bootstraplocalfile) && is_readable($bootstrapsharedfile)) {
// If we don't have a local cache but do have a shared cache then clone it,
// for example when scaling up new front ends.
make_localcache_directory('', true);
copy($bootstrapsharedfile, $bootstraplocalfile);
}
if (is_readable($bootstraplocalfile)) {
try {
require_once($bootstrapcachefile);
require_once($bootstraplocalfile);
// Verify the file is not stale.
if (!isset($CFG->bootstraphash) || $CFG->bootstraphash !== hash_local_config_cache()) {
// Something has changed, the bootstrap.php file is stale.
unset($CFG->siteidentifier);
@unlink($bootstrapcachefile);
@unlink($bootstraplocalfile);
@unlink($bootstrapsharedfile);
}
} catch (Throwable $e) {
// If it is corrupted then attempt to delete it and it will be rebuilt.
@unlink($bootstrapcachefile);
@unlink($bootstraplocalfile);
@unlink($bootstrapsharedfile);
}
}