mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 10:26:40 +02:00
Merge branch 'wip-MDL-39526-m25' of git://github.com/samhemelryk/moodle
This commit is contained in:
commit
887e724796
8 changed files with 66 additions and 35 deletions
|
@ -151,6 +151,12 @@ if ($interactive) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($version > $CFG->version) {
|
if ($version > $CFG->version) {
|
||||||
|
// We purge all of MUC's caches here.
|
||||||
|
// Caches are disabled for upgrade by CACHE_DISABLE_ALL so we must set the first arg to true.
|
||||||
|
// This ensures a real config object is loaded and the stores will be purged.
|
||||||
|
// This is the only way we can purge custom caches such as memcache or APC.
|
||||||
|
// Note: all other calls to caches will still used the disabled API.
|
||||||
|
cache_helper::purge_all(true);
|
||||||
upgrade_core($version, true);
|
upgrade_core($version, true);
|
||||||
}
|
}
|
||||||
set_config('release', $release);
|
set_config('release', $release);
|
||||||
|
|
|
@ -222,6 +222,13 @@ if ($cache) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($version > $CFG->version) { // upgrade
|
if ($version > $CFG->version) { // upgrade
|
||||||
|
// We purge all of MUC's caches here.
|
||||||
|
// Caches are disabled for upgrade by CACHE_DISABLE_ALL so we must set the first arg to true.
|
||||||
|
// This ensures a real config object is loaded and the stores will be purged.
|
||||||
|
// This is the only way we can purge custom caches such as memcache or APC.
|
||||||
|
// Note: all other calls to caches will still used the disabled API.
|
||||||
|
cache_helper::purge_all(true);
|
||||||
|
// We then purge the regular caches.
|
||||||
purge_all_caches();
|
purge_all_caches();
|
||||||
|
|
||||||
$PAGE->set_pagelayout('maintenance');
|
$PAGE->set_pagelayout('maintenance');
|
||||||
|
|
12
cache/classes/config.php
vendored
12
cache/classes/config.php
vendored
|
@ -396,10 +396,18 @@ class cache_config {
|
||||||
* @param string $storename
|
* @param string $storename
|
||||||
* @return array Associative array of definitions, id=>definition
|
* @return array Associative array of definitions, id=>definition
|
||||||
*/
|
*/
|
||||||
public static function get_definitions_by_store($storename) {
|
public function get_definitions_by_store($storename) {
|
||||||
$definitions = array();
|
$definitions = array();
|
||||||
|
|
||||||
$config = cache_config::instance();
|
// This function was accidentally made static at some stage in the past.
|
||||||
|
// It was converted to an instance method but to be backwards compatible
|
||||||
|
// we must step around this in code.
|
||||||
|
if (!isset($this)) {
|
||||||
|
$config = cache_config::instance();
|
||||||
|
} else {
|
||||||
|
$config = $this;
|
||||||
|
}
|
||||||
|
|
||||||
$stores = $config->get_all_stores();
|
$stores = $config->get_all_stores();
|
||||||
if (!array_key_exists($storename, $stores)) {
|
if (!array_key_exists($storename, $stores)) {
|
||||||
// The store does not exist.
|
// The store does not exist.
|
||||||
|
|
28
cache/classes/helper.php
vendored
28
cache/classes/helper.php
vendored
|
@ -414,12 +414,17 @@ class cache_helper {
|
||||||
* Think twice before calling this method. It will purge **ALL** caches regardless of whether they have been used recently or
|
* Think twice before calling this method. It will purge **ALL** caches regardless of whether they have been used recently or
|
||||||
* anything. This will involve full setup of the cache + the purge operation. On a site using caching heavily this WILL be
|
* anything. This will involve full setup of the cache + the purge operation. On a site using caching heavily this WILL be
|
||||||
* painful.
|
* painful.
|
||||||
|
*
|
||||||
|
* @param bool $usewriter If set to true the cache_config_writer class is used. This class is special as it avoids
|
||||||
|
* it is still usable when caches have been disabled.
|
||||||
|
* Please use this option only if you really must. It's purpose is to allow the cache to be purged when it would be
|
||||||
|
* otherwise impossible.
|
||||||
*/
|
*/
|
||||||
public static function purge_all() {
|
public static function purge_all($usewriter = false) {
|
||||||
$config = cache_config::instance();
|
$factory = cache_factory::instance();
|
||||||
|
$config = $factory->create_config_instance($usewriter);
|
||||||
foreach ($config->get_all_stores() as $store) {
|
foreach ($config->get_all_stores() as $store) {
|
||||||
self::purge_store($store['name']);
|
self::purge_store($store['name'], $config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -427,10 +432,13 @@ class cache_helper {
|
||||||
* Purges a store given its name.
|
* Purges a store given its name.
|
||||||
*
|
*
|
||||||
* @param string $storename
|
* @param string $storename
|
||||||
|
* @param cache_config $config
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function purge_store($storename) {
|
public static function purge_store($storename, cache_config $config = null) {
|
||||||
$config = cache_config::instance();
|
if ($config === null) {
|
||||||
|
$config = cache_config::instance();
|
||||||
|
}
|
||||||
|
|
||||||
$stores = $config->get_all_stores();
|
$stores = $config->get_all_stores();
|
||||||
if (!array_key_exists($storename, $stores)) {
|
if (!array_key_exists($storename, $stores)) {
|
||||||
|
@ -450,10 +458,10 @@ class cache_helper {
|
||||||
|
|
||||||
foreach ($config->get_definitions_by_store($storename) as $id => $definition) {
|
foreach ($config->get_definitions_by_store($storename) as $id => $definition) {
|
||||||
$definition = cache_definition::load($id, $definition);
|
$definition = cache_definition::load($id, $definition);
|
||||||
$instance = new $class($store['name'], $store['configuration']);
|
$definitioninstance = clone($instance);
|
||||||
$instance->initialise($definition);
|
$definitioninstance->initialise($definition);
|
||||||
$instance->purge();
|
$definitioninstance->purge();
|
||||||
unset($instance);
|
unset($definitioninstance);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
22
cache/disabledlib.php
vendored
22
cache/disabledlib.php
vendored
|
@ -253,13 +253,28 @@ class cache_factory_disabled extends cache_factory {
|
||||||
* Creates a cache config instance with the ability to write if required.
|
* Creates a cache config instance with the ability to write if required.
|
||||||
*
|
*
|
||||||
* @param bool $writer Unused.
|
* @param bool $writer Unused.
|
||||||
* @return cache_config|cache_config_writer
|
* @return cache_config_disabled|cache_config_writer
|
||||||
*/
|
*/
|
||||||
public function create_config_instance($writer = false) {
|
public function create_config_instance($writer = false) {
|
||||||
|
// We are always going to use the cache_config_disabled class for all regular request.
|
||||||
|
// However if the code has requested the writer then likely something is changing and
|
||||||
|
// we're going to need to interact with the config.php file.
|
||||||
|
// In this case we will still use the cache_config_writer.
|
||||||
$class = 'cache_config_disabled';
|
$class = 'cache_config_disabled';
|
||||||
|
if ($writer) {
|
||||||
|
// If the writer was requested then something is changing.
|
||||||
|
$class = 'cache_config_writer';
|
||||||
|
}
|
||||||
if (!array_key_exists($class, $this->configs)) {
|
if (!array_key_exists($class, $this->configs)) {
|
||||||
self::set_state(self::STATE_INITIALISING);
|
self::set_state(self::STATE_INITIALISING);
|
||||||
$configuration = $class::create_default_configuration();
|
if ($class === 'cache_config_disabled') {
|
||||||
|
$configuration = $class::create_default_configuration();
|
||||||
|
} else {
|
||||||
|
$configuration = false;
|
||||||
|
if (!cache_config::config_file_exists()) {
|
||||||
|
cache_config_writer::create_default_configuration(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
$this->configs[$class] = new $class;
|
$this->configs[$class] = new $class;
|
||||||
$this->configs[$class]->load($configuration);
|
$this->configs[$class]->load($configuration);
|
||||||
}
|
}
|
||||||
|
@ -361,9 +376,10 @@ class cache_config_disabled extends cache_config_writer {
|
||||||
/**
|
/**
|
||||||
* Creates the default configuration and saves it.
|
* Creates the default configuration and saves it.
|
||||||
*
|
*
|
||||||
|
* @param bool $forcesave Ignored because we are disabled!
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function create_default_configuration() {
|
public static function create_default_configuration($forcesave = false) {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
// HACK ALERT.
|
// HACK ALERT.
|
||||||
|
|
5
cache/locallib.php
vendored
5
cache/locallib.php
vendored
|
@ -388,10 +388,11 @@ class cache_config_writer extends cache_config {
|
||||||
* This function calls config_save, however it is safe to continue using it afterwards as this function should only ever
|
* This function calls config_save, however it is safe to continue using it afterwards as this function should only ever
|
||||||
* be called when there is no configuration file already.
|
* be called when there is no configuration file already.
|
||||||
*
|
*
|
||||||
|
* @param bool $forcesave If set to true then we will forcefully save the default configuration file.
|
||||||
* @return true|array Returns true if the default configuration was successfully created.
|
* @return true|array Returns true if the default configuration was successfully created.
|
||||||
* Returns a configuration array if it could not be saved. This is a bad situation. Check your error logs.
|
* Returns a configuration array if it could not be saved. This is a bad situation. Check your error logs.
|
||||||
*/
|
*/
|
||||||
public static function create_default_configuration() {
|
public static function create_default_configuration($forcesave = false) {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
// HACK ALERT.
|
// HACK ALERT.
|
||||||
|
@ -433,7 +434,7 @@ class cache_config_writer extends cache_config {
|
||||||
$factory = cache_factory::instance();
|
$factory = cache_factory::instance();
|
||||||
// We expect the cache to be initialising presently. If its not then something has gone wrong and likely
|
// We expect the cache to be initialising presently. If its not then something has gone wrong and likely
|
||||||
// we are now in a loop.
|
// we are now in a loop.
|
||||||
if ($factory->get_state() !== cache_factory::STATE_INITIALISING) {
|
if (!$forcesave && $factory->get_state() !== cache_factory::STATE_INITIALISING) {
|
||||||
return $writer->generate_configuration_array();
|
return $writer->generate_configuration_array();
|
||||||
}
|
}
|
||||||
$factory->set_state(cache_factory::STATE_SAVING);
|
$factory->set_state(cache_factory::STATE_SAVING);
|
||||||
|
|
|
@ -1391,9 +1391,6 @@ function get_config($plugin, $name = NULL) {
|
||||||
// install the database.
|
// install the database.
|
||||||
$siteidentifier = $DB->get_field('config', 'value', array('name' => 'siteidentifier'));
|
$siteidentifier = $DB->get_field('config', 'value', array('name' => 'siteidentifier'));
|
||||||
} catch (dml_exception $ex) {
|
} catch (dml_exception $ex) {
|
||||||
// It's failed. We'll use this opportunity to disable cache stores so that we don't inadvertingly start using
|
|
||||||
// old caches. People should delete their moodledata dirs when reinstalling the database... but they don't.
|
|
||||||
cache_factory::disable_stores();
|
|
||||||
// Set siteidentifier to false. We don't want to trip this continually.
|
// Set siteidentifier to false. We don't want to trip this continually.
|
||||||
$siteidentifier = false;
|
$siteidentifier = false;
|
||||||
throw $ex;
|
throw $ex;
|
||||||
|
|
|
@ -486,7 +486,7 @@ function upgrade_plugins($type, $startcallback, $endcallback, $verbose) {
|
||||||
message_update_processors($plug);
|
message_update_processors($plug);
|
||||||
}
|
}
|
||||||
upgrade_plugin_mnet_functions($component);
|
upgrade_plugin_mnet_functions($component);
|
||||||
|
cache_helper::purge_all(true);
|
||||||
purge_all_caches();
|
purge_all_caches();
|
||||||
$endcallback($component, true, $verbose);
|
$endcallback($component, true, $verbose);
|
||||||
|
|
||||||
|
@ -519,7 +519,7 @@ function upgrade_plugins($type, $startcallback, $endcallback, $verbose) {
|
||||||
message_update_processors($plug);
|
message_update_processors($plug);
|
||||||
}
|
}
|
||||||
upgrade_plugin_mnet_functions($component);
|
upgrade_plugin_mnet_functions($component);
|
||||||
|
cache_helper::purge_all(true);
|
||||||
purge_all_caches();
|
purge_all_caches();
|
||||||
$endcallback($component, false, $verbose);
|
$endcallback($component, false, $verbose);
|
||||||
|
|
||||||
|
@ -1467,10 +1467,6 @@ function install_core($version, $verbose) {
|
||||||
remove_dir($CFG->dataroot.'/muc', true);
|
remove_dir($CFG->dataroot.'/muc', true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Disable the use of cache stores here. We will reset the factory after we've performed the installation.
|
|
||||||
// This ensures that we don't permanently cache anything during installation.
|
|
||||||
cache_factory::disable_stores();
|
|
||||||
|
|
||||||
set_time_limit(600);
|
set_time_limit(600);
|
||||||
print_upgrade_part_start('moodle', true, $verbose); // does not store upgrade running flag
|
print_upgrade_part_start('moodle', true, $verbose); // does not store upgrade running flag
|
||||||
|
|
||||||
|
@ -1519,9 +1515,7 @@ function upgrade_core($version, $verbose) {
|
||||||
try {
|
try {
|
||||||
// Reset caches before any output
|
// Reset caches before any output
|
||||||
purge_all_caches();
|
purge_all_caches();
|
||||||
// Disable the use of cache stores here. We will reset the factory after we've performed the installation.
|
cache_helper::purge_all(true);
|
||||||
// This ensures that we don't permanently cache anything during installation.
|
|
||||||
cache_factory::disable_stores();
|
|
||||||
|
|
||||||
// Upgrade current language pack if we can
|
// Upgrade current language pack if we can
|
||||||
upgrade_language_pack();
|
upgrade_language_pack();
|
||||||
|
@ -1552,8 +1546,6 @@ function upgrade_core($version, $verbose) {
|
||||||
// Update core definitions.
|
// Update core definitions.
|
||||||
cache_helper::update_definitions(true);
|
cache_helper::update_definitions(true);
|
||||||
|
|
||||||
// Reset the cache, this returns it to a normal operation state.
|
|
||||||
cache_factory::reset();
|
|
||||||
// Purge caches again, just to be sure we arn't holding onto old stuff now.
|
// Purge caches again, just to be sure we arn't holding onto old stuff now.
|
||||||
purge_all_caches();
|
purge_all_caches();
|
||||||
|
|
||||||
|
@ -1582,10 +1574,6 @@ function upgrade_noncore($verbose) {
|
||||||
|
|
||||||
// upgrade all plugins types
|
// upgrade all plugins types
|
||||||
try {
|
try {
|
||||||
// Disable the use of cache stores here.
|
|
||||||
// We don't reset this, the site can live without proper caching for life of this request.
|
|
||||||
cache_factory::disable_stores();
|
|
||||||
|
|
||||||
$plugintypes = get_plugin_types();
|
$plugintypes = get_plugin_types();
|
||||||
foreach ($plugintypes as $type=>$location) {
|
foreach ($plugintypes as $type=>$location) {
|
||||||
upgrade_plugins($type, 'print_upgrade_part_start', 'print_upgrade_part_end', $verbose);
|
upgrade_plugins($type, 'print_upgrade_part_start', 'print_upgrade_part_end', $verbose);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue