Skip to content

Commit

Permalink
MDL-58857 admin: Terminate the session if a major upgrade is required
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed May 9, 2017
1 parent 48ad736 commit a011eff
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
6 changes: 6 additions & 0 deletions admin/index.php
Expand Up @@ -101,6 +101,12 @@
// 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

Expand Down
32 changes: 25 additions & 7 deletions lib/setuplib.php
Expand Up @@ -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 redirect_if_major_upgrade_required() {
function is_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)) {

$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;
if (is_major_upgrade_required()) {
try {
@\core\session\manager::terminate_current();
} catch (Exception $e) {
Expand Down

0 comments on commit a011eff

Please sign in to comment.