Merge branch 'MDL-82171-muc-sited-MOODLE_404_STABLE' of https://github.com/brendanheywood/moodle into MOODLE_404_STABLE

This commit is contained in:
Ilya Tregubov 2024-08-05 11:18:59 +08:00
commit abd4203547
3 changed files with 38 additions and 9 deletions

View File

@ -1262,6 +1262,9 @@ function purge_other_caches() {
remove_dir($CFG->localcachedir, true);
set_config('localcachedirpurged', time());
make_localcache_directory('', true);
// Rewarm the bootstrap.php files so the siteid is always present after a purge.
initialise_local_config_cache();
\core\task\manager::clear_static_caches();
}

View File

@ -680,19 +680,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);
}
}

View File

@ -876,9 +876,17 @@ function initialise_cfg() {
function initialise_local_config_cache() {
global $CFG;
$bootstrapcachefile = $CFG->localcachedir . '/bootstrap.php';
$bootstraplocalfile = $CFG->localcachedir . '/bootstrap.php';
$bootstrapsharedfile = $CFG->cachedir . '/bootstrap.php';
if (!empty($CFG->siteidentifier) && !file_exists($bootstrapcachefile)) {
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 (!empty($CFG->siteidentifier) && !file_exists($bootstrapsharedfile) && defined('SYSCONTEXTID')) {
$contents = "<?php
// ********** This file is generated DO NOT EDIT **********
\$CFG->siteidentifier = " . var_export($CFG->siteidentifier, true) . ";
@ -889,10 +897,15 @@ if (\$CFG->bootstraphash === hash_local_config_cache() && !defined('SYSCONTEXTID
}
";
$temp = $bootstrapcachefile . '.tmp' . uniqid();
// Create the central bootstrap first.
$temp = $bootstrapsharedfile . '.tmp' . uniqid();
file_put_contents($temp, $contents);
@chmod($temp, $CFG->filepermissions);
rename($temp, $bootstrapcachefile);
rename($temp, $bootstrapsharedfile);
// Then prewarm the local cache as well.
make_localcache_directory('', true);
copy($bootstrapsharedfile, $bootstraplocalfile);
}
}
@ -1922,6 +1935,9 @@ function make_localcache_directory($directory, $exceptiononerror = true) {
touch($timestampfile);
@chmod($timestampfile, $CFG->filepermissions);
clearstatcache();
// Then prewarm the local boostrap.php file as well.
initialise_local_config_cache();
}
if ($directory === '') {