mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-38387 cache: fixed inifinite initialisation loop with site id
This commit is contained in:
parent
8673a98d1d
commit
17200a016d
2 changed files with 26 additions and 3 deletions
27
cache/classes/helper.php
vendored
27
cache/classes/helper.php
vendored
|
@ -511,6 +511,7 @@ class cache_helper {
|
||||||
* Update the site identifier stored by the cache API.
|
* Update the site identifier stored by the cache API.
|
||||||
*
|
*
|
||||||
* @param string $siteidentifier
|
* @param string $siteidentifier
|
||||||
|
* @return string The new site identifier.
|
||||||
*/
|
*/
|
||||||
public static function update_site_identifier($siteidentifier) {
|
public static function update_site_identifier($siteidentifier) {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
@ -519,9 +520,10 @@ class cache_helper {
|
||||||
$factory = cache_factory::instance();
|
$factory = cache_factory::instance();
|
||||||
$factory->updating_started();
|
$factory->updating_started();
|
||||||
$config = $factory->create_config_instance(true);
|
$config = $factory->create_config_instance(true);
|
||||||
$config->update_site_identifier($siteidentifier);
|
$siteidentifier = $config->update_site_identifier($siteidentifier);
|
||||||
$factory->updating_finished();
|
$factory->updating_finished();
|
||||||
cache_factory::reset();
|
cache_factory::reset();
|
||||||
|
return $siteidentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -530,11 +532,30 @@ class cache_helper {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function get_site_identifier() {
|
public static function get_site_identifier() {
|
||||||
if (is_null(self::$siteidentifier)) {
|
global $CFG;
|
||||||
$factory = cache_factory::instance();
|
if (!is_null(self::$siteidentifier)) {
|
||||||
|
return self::$siteidentifier;
|
||||||
|
}
|
||||||
|
// If site identifier hasn't been collected yet attempt to get it from the cache config.
|
||||||
|
$factory = cache_factory::instance();
|
||||||
|
// If the factory is initialising then we don't want to try to get it from the config or we risk
|
||||||
|
// causing the cache to enter an infinite initialisation loop.
|
||||||
|
if (!$factory->is_initialising()) {
|
||||||
$config = $factory->create_config_instance();
|
$config = $factory->create_config_instance();
|
||||||
self::$siteidentifier = $config->get_site_identifier();
|
self::$siteidentifier = $config->get_site_identifier();
|
||||||
}
|
}
|
||||||
|
if (is_null(self::$siteidentifier)) {
|
||||||
|
// If the site identifier is still null then config isn't aware of it yet.
|
||||||
|
// We'll see if the CFG is loaded, and if not we will just use unknown.
|
||||||
|
// It's very important here that we don't use get_config. We don't want an endless cache loop!
|
||||||
|
if (isset($CFG->siteidentifier)) {
|
||||||
|
self::$siteidentifier = self::update_site_identifier($CFG->siteidentifier);
|
||||||
|
} else {
|
||||||
|
// It's not being recorded in MUC's config and the config data hasn't been loaded yet.
|
||||||
|
// Likely we are initialising.
|
||||||
|
return 'unknown';
|
||||||
|
}
|
||||||
|
}
|
||||||
return self::$siteidentifier;
|
return self::$siteidentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
cache/locallib.php
vendored
2
cache/locallib.php
vendored
|
@ -529,10 +529,12 @@ class cache_config_writer extends cache_config {
|
||||||
* Update the site identifier stored by the cache API.
|
* Update the site identifier stored by the cache API.
|
||||||
*
|
*
|
||||||
* @param string $siteidentifier
|
* @param string $siteidentifier
|
||||||
|
* @return string The new site identifier.
|
||||||
*/
|
*/
|
||||||
public function update_site_identifier($siteidentifier) {
|
public function update_site_identifier($siteidentifier) {
|
||||||
$this->siteidentifier = md5((string)$siteidentifier);
|
$this->siteidentifier = md5((string)$siteidentifier);
|
||||||
$this->config_save();
|
$this->config_save();
|
||||||
|
return $this->siteidentifier;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue