From c4d5fb53ce2abfbef5b6b434ea62c3093395189a Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Thu, 20 Oct 2016 11:16:52 +0800 Subject: [PATCH] MDL-52777 tool_usertours: Only check plugin for needs update The moodle_needs_upgrade() function includes every version.php in Moodle which poses a performance issue, especially when called on every page. --- admin/tool/usertours/classes/manager.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/admin/tool/usertours/classes/manager.php b/admin/tool/usertours/classes/manager.php index 94a46f264f9..ff3ac0c27fb 100644 --- a/admin/tool/usertours/classes/manager.php +++ b/admin/tool/usertours/classes/manager.php @@ -561,8 +561,8 @@ class manager { public static function get_matching_tours(\moodle_url $pageurl) { global $DB, $PAGE; - // Do not show tours whilst upgrades are pending. - if (moodle_needs_upgrading()) { + if (self::tour_upgrade_pending()) { + // Do not show tours whilst upgrades are pending agains the plugin. return null; } @@ -587,6 +587,21 @@ EOF; return null; } + /** + * Determine whether the tour plugin is pending an upgrade. + * + * @return bool + */ + public static function tour_upgrade_pending() { + $plugin = new \stdClass(); + include(dirname(__DIR__) . '/version.php'); + + $manager = \core_plugin_manager::instance(); + $plugininfo = $manager->get_plugin_info('tool_usertours'); + + return ($plugin->version != $plugininfo->versiondb); + } + /** * Import the provided tour JSON. *