From a011effb499c2ff0592fbc77c846233be81f37ec Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 9 May 2017 15:00:00 +0800 Subject: [PATCH] MDL-58857 admin: Terminate the session if a major upgrade is required --- admin/index.php | 6 ++++++ lib/setuplib.php | 32 +++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/admin/index.php b/admin/index.php index 30ba5cb2c43..6cf7f45e91b 100644 --- a/admin/index.php +++ b/admin/index.php @@ -101,6 +101,12 @@ if (function_exists('opcache_invalidate')) { // indirectly calls the protected init() method is good here. core_component::get_core_subsystems(); +if (is_major_upgrade_required() && isloggedin()) { + // A major upgrade is required. + // Terminate the session and redirect back here before anything DB-related happens. + redirect_if_major_upgrade_required(); +} + require_once($CFG->libdir.'/adminlib.php'); // various admin-only functions require_once($CFG->libdir.'/upgradelib.php'); // general upgrade/install related functions diff --git a/lib/setuplib.php b/lib/setuplib.php index 67ac2a4b6ad..9759ced0279 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -1388,16 +1388,34 @@ function disable_output_buffering() { } /** - * Check whether a major upgrade is needed. That is defined as an upgrade that - * changes something really fundamental in the database, so nothing can possibly - * work until the database has been updated, and that is defined by the hard-coded - * version number in this function. + * Check whether a major upgrade is needed. + * + * That is defined as an upgrade that changes something really fundamental + * in the database, so nothing can possibly work until the database has + * been updated, and that is defined by the hard-coded version number in + * this function. + * + * @return bool + */ +function is_major_upgrade_required() { + global $CFG; + $lastmajordbchanges = 2017040403.00; + + $required = empty($CFG->version); + $required = $required || (float)$CFG->version < $lastmajordbchanges; + $required = $required || during_initial_install(); + $required = $required || !empty($CFG->adminsetuppending); + + return $required; +} + +/** + * Redirect to the Notifications page if a major upgrade is required, and + * terminate the current user session. */ function redirect_if_major_upgrade_required() { global $CFG; - $lastmajordbchanges = 2017040403.00; - if (empty($CFG->version) or (float)$CFG->version < $lastmajordbchanges or - during_initial_install() or !empty($CFG->adminsetuppending)) { + if (is_major_upgrade_required()) { try { @\core\session\manager::terminate_current(); } catch (Exception $e) {