Skip to content

Commit

Permalink
MDL-36386 cache: upgrades now trigger definitions to be updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Hemelryk committed Nov 6, 2012
1 parent 6109f21 commit 75af47e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
15 changes: 15 additions & 0 deletions cache/classes/helper.php
Expand Up @@ -453,4 +453,19 @@ public static function get_definition_name($definition) {
public static function hash_key($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 changes: 14 additions & 9 deletions cache/locallib.php
Expand Up @@ -364,31 +364,36 @@ public static function create_default_configuration() {
* 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.
*
* @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->write_definitions_to_cache(self::locate_definitions());
$config->write_definitions_to_cache(self::locate_definitions($coreonly));
}

/**
* Locates all of the definition files.
*
* @param bool $coreonly If set to true only core definitions will be updated.
* @return array
*/
protected static function locate_definitions() {
protected static function locate_definitions($coreonly = false) {
global $CFG;

$files = array();
if (file_exists($CFG->dirroot.'/lib/db/caches.php')) {
$files['core'] = $CFG->dirroot.'/lib/db/caches.php';
}

$plugintypes = get_plugin_types();
foreach ($plugintypes as $type => $location) {
$plugins = get_plugin_list_with_file($type, 'db/caches.php');
foreach ($plugins as $plugin => $filepath) {
$component = clean_param($type.'_'.$plugin, PARAM_COMPONENT); // Standardised plugin name.
$files[$component] = $filepath;
if (!$coreonly) {
$plugintypes = get_plugin_types();
foreach ($plugintypes as $type => $location) {
$plugins = get_plugin_list_with_file($type, 'db/caches.php');
foreach ($plugins as $plugin => $filepath) {
$component = clean_param($type.'_'.$plugin, PARAM_COMPONENT); // Standardised plugin name.
$files[$component] = $filepath;
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions lib/upgradelib.php
Expand Up @@ -1492,6 +1492,8 @@ function upgrade_core($version, $verbose) {
external_update_descriptions('moodle');
events_update_definition('moodle');
message_update_providers('moodle');
// Update core definitions.
cache_helper::update_definitions(true);

// Reset caches again, just to be sure
purge_all_caches();
Expand Down Expand Up @@ -1525,6 +1527,7 @@ function upgrade_noncore($verbose) {
foreach ($plugintypes as $type=>$location) {
upgrade_plugins($type, 'print_upgrade_part_start', 'print_upgrade_part_end', $verbose);
}
cache_helper::update_definitions();
} catch (Exception $ex) {
upgrade_handle_exception($ex);
}
Expand Down
2 changes: 1 addition & 1 deletion version.php
Expand Up @@ -30,7 +30,7 @@
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
// .XX = incremental changes

Expand Down

0 comments on commit 75af47e

Please sign in to comment.