MDL-36386 cache: upgrades now trigger definitions to be updated

This commit is contained in:
Sam Hemelryk 2012-11-07 10:36:09 +13:00
parent 6109f2112c
commit 75af47ee1e
4 changed files with 33 additions and 10 deletions

View File

@ -453,4 +453,19 @@ class cache_helper {
public static function hash_key($key) { public static function hash_key($key) {
return crc32($key); return crc32($key);
} }
/**
* Finds all definitions and updates them within the cache config file.
*
* @param bool $coreonly If set to true only core definitions will be updated.
*/
public static function update_definitions($coreonly = false) {
global $CFG;
// Include locallib
require_once($CFG->dirroot.'/cache/locallib.php');
// First update definitions
cache_config_writer::update_definitions($coreonly);
// Second reset anything we have already initialised to ensure we're all up to date.
cache_factory::reset();
}
} }

23
cache/locallib.php vendored
View File

@ -364,18 +364,21 @@ class cache_config_writer extends cache_config {
* Updates the definition in the configuration from those found in the cache files. * Updates the definition in the configuration from those found in the cache files.
* *
* Calls config_save further down, you should redirect immediately or asap after calling this method. * Calls config_save further down, you should redirect immediately or asap after calling this method.
*
* @param bool $coreonly If set to true only core definitions will be updated.
*/ */
public static function update_definitions() { public static function update_definitions($coreonly = false) {
$config = self::instance(); $config = self::instance();
$config->write_definitions_to_cache(self::locate_definitions()); $config->write_definitions_to_cache(self::locate_definitions($coreonly));
} }
/** /**
* Locates all of the definition files. * Locates all of the definition files.
* *
* @param bool $coreonly If set to true only core definitions will be updated.
* @return array * @return array
*/ */
protected static function locate_definitions() { protected static function locate_definitions($coreonly = false) {
global $CFG; global $CFG;
$files = array(); $files = array();
@ -383,12 +386,14 @@ class cache_config_writer extends cache_config {
$files['core'] = $CFG->dirroot.'/lib/db/caches.php'; $files['core'] = $CFG->dirroot.'/lib/db/caches.php';
} }
$plugintypes = get_plugin_types(); if (!$coreonly) {
foreach ($plugintypes as $type => $location) { $plugintypes = get_plugin_types();
$plugins = get_plugin_list_with_file($type, 'db/caches.php'); foreach ($plugintypes as $type => $location) {
foreach ($plugins as $plugin => $filepath) { $plugins = get_plugin_list_with_file($type, 'db/caches.php');
$component = clean_param($type.'_'.$plugin, PARAM_COMPONENT); // Standardised plugin name. foreach ($plugins as $plugin => $filepath) {
$files[$component] = $filepath; $component = clean_param($type.'_'.$plugin, PARAM_COMPONENT); // Standardised plugin name.
$files[$component] = $filepath;
}
} }
} }

View File

@ -1492,6 +1492,8 @@ function upgrade_core($version, $verbose) {
external_update_descriptions('moodle'); external_update_descriptions('moodle');
events_update_definition('moodle'); events_update_definition('moodle');
message_update_providers('moodle'); message_update_providers('moodle');
// Update core definitions.
cache_helper::update_definitions(true);
// Reset caches again, just to be sure // Reset caches again, just to be sure
purge_all_caches(); purge_all_caches();
@ -1525,6 +1527,7 @@ function upgrade_noncore($verbose) {
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);
} }
cache_helper::update_definitions();
} catch (Exception $ex) { } catch (Exception $ex) {
upgrade_handle_exception($ex); upgrade_handle_exception($ex);
} }

View File

@ -30,7 +30,7 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$version = 2012110101.00; // YYYYMMDD = weekly release date of this DEV branch $version = 2012110700.00; // YYYYMMDD = weekly release date of this DEV branch
// RR = release increments - 00 in DEV branches // RR = release increments - 00 in DEV branches
// .XX = incremental changes // .XX = incremental changes