diff --git a/admin/index.php b/admin/index.php index 466832c535785..1f186b6417a06 100644 --- a/admin/index.php +++ b/admin/index.php @@ -66,6 +66,16 @@ } require('../config.php'); + +// Invalidate the cache of version.php in any circumstances to help core_component +// detecting if the version has changed and component cache should be reset. +if (function_exists('opcache_invalidate')) { + opcache_invalidate($CFG->dirroot . '/version.php', true); +} +// Make sure the component cache gets rebuilt if necessary, any method that +// indirectly calls the protected init() method is good here. +core_component::get_core_subsystems(); + require_once($CFG->libdir.'/adminlib.php'); // various admin-only functions require_once($CFG->libdir.'/upgradelib.php'); // general upgrade/install related functions require_once($CFG->libdir.'/pluginlib.php'); // available updates notifications diff --git a/lib/classes/component.php b/lib/classes/component.php index d5ec8ac85979d..7d4949ae190b0 100644 --- a/lib/classes/component.php +++ b/lib/classes/component.php @@ -43,6 +43,8 @@ class core_component { protected static $classmap = null; /** @var null list of some known files that can be included. */ protected static $filemap = null; + /** @var int|float core version. */ + protected static $version = null; /** @var array list of the files to map. */ protected static $filestomap = array('lib.php', 'settings.php'); @@ -133,8 +135,11 @@ protected static function init() { include($cachefile); if (!is_array($cache)) { // Something is very wrong. - } else if (!isset($cache['plugintypes']) or !isset($cache['plugins']) or !isset($cache['subsystems']) or !isset($cache['classmap'])) { + } else if (!isset($cache['version'])) { // Something is very wrong. + } else if ((float) $cache['version'] !== (float) self::fetch_core_version()) { + // Outdated cache. We trigger an error log to track an eventual repetitive failure of float comparison. + error_log('Resetting core_component cache after core upgrade to version ' . self::fetch_core_version()); } else if ($cache['plugintypes']['mod'] !== "$CFG->dirroot/mod") { // $CFG->dirroot was changed. } else { @@ -227,6 +232,7 @@ public static function get_cache_content() { 'plugins' => self::$plugins, 'classmap' => self::$classmap, 'filemap' => self::$filemap, + 'version' => self::$version, ); return 'dirroot . '/version.php'); + self::$version = $version; + } + return self::$version; } /** @@ -870,9 +893,7 @@ public static function get_all_versions_hash() { $versions = array(); // Main version first. - $version = null; - include($CFG->dirroot.'/version.php'); - $versions['core'] = $version; + $versions['core'] = self::fetch_core_version(); // The problem here is tha the component cache might be stable, // we want this to work also on frontpage without resetting the component cache.