From 67b34c34f0c8e026712ee9fb11fb586b979d6be4 Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Wed, 12 Jun 2013 14:14:24 +1200 Subject: [PATCH] MDL-40136 cache: fixed dirroot change bugs with plugin caches --- lib/moodlelib.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 1581cd77edf..0be295e6fc5 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -8219,7 +8219,14 @@ function get_plugin_types($fullpaths=true) { $cache = cache::make('core', 'plugintypes'); if ($fullpaths) { - $cached = $cache->get(1); + // First confirm that dirroot and the stored dirroot match. + if ($CFG->dirroot === $cache->get('dirroot')) { + // They match we can use it. + $cached = $cache->get(1); + } else { + // Oops they didn't match. The moodle directory has been moved on us. + $cached = false; + } } else { $cached = $cache->get(0); } @@ -8279,6 +8286,9 @@ function get_plugin_types($fullpaths=true) { $cache->set(0, $info); $cache->set(1, $fullinfo); + // We cache the dirroot as well so that we can compare it when we + // retrieve full info from the cache. + $cache->set('dirroot', $CFG->dirroot); return ($fullpaths ? $fullinfo : $info); } @@ -8301,7 +8311,9 @@ function is_valid_plugin_name($name) { function get_plugin_list($plugintype) { global $CFG; - $cache = cache::make('core', 'pluginlist'); + // We use the dirroot as an identifier here because if it has changed the whole cache + // can be considered invalid. + $cache = cache::make('core', 'pluginlist', array('dirroot' => $CFG->dirroot)); $cached = $cache->get($plugintype); if ($cached !== false) { return $cached;