diff --git a/index.php b/index.php index 0b244e0c68c..bad1b72d4e4 100644 --- a/index.php +++ b/index.php @@ -34,14 +34,7 @@ require_once($CFG->dirroot .'/course/lib.php'); require_once($CFG->libdir .'/filelib.php'); - // check if major upgrade needed - also present in login/index.php - if (empty($CFG->version) or (int)$CFG->version < 2009071000 or !empty($CFG->adminsetuppending)) { //1.9 or older - try { - @require_logout(); - } catch (Exception $e) { - } - redirect("$CFG->wwwroot/$CFG->admin/"); - } + redirect_if_major_upgrade_required(); if ($CFG->forcelogin) { require_login(); diff --git a/lang/en_utf8/moodle.php b/lang/en_utf8/moodle.php index 19bf6a56c21..c32233df693 100644 --- a/lang/en_utf8/moodle.php +++ b/lang/en_utf8/moodle.php @@ -1284,6 +1284,7 @@ $string['recentactivity'] = 'Recent Activity'; $string['recentactivityreport'] = 'Full report of recent activity...'; $string['recipientslist'] = 'Recipients list'; $string['recreatedcategory'] = 'Recreated category $a'; +$string['redirect'] = 'Redirect'; $string['refreshingevents'] = 'Refreshing events'; $string['refresh'] = 'Refresh'; $string['registration'] = 'Moodle Registration'; diff --git a/lib/setuplib.php b/lib/setuplib.php index d73a8c74fe6..ab2a3a42b8c 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -655,6 +655,29 @@ function get_real_size($size=0) { return $size; } +/** + * 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. + */ +function redirect_if_major_upgrade_required() { + global $CFG; + $lastmajordbchanges = 2009071000; + if (empty($CFG->version) or (int)$CFG->version < $lastmajordbchanges or + during_initial_install() or !empty($CFG->adminsetuppending)) { + try { + @session_get_instance()->terminate_current(); + } catch (Exception $e) { + // Ignore any errors, redirect to upgrade anyway. + } + @header($_SERVER['SERVER_PROTOCOL'] . ' 303 See Other'); + @header('Location: ' . $CFG->wwwroot . '/' . $CFG->admin . '/index.php'); + echo bootstrap_renderer::plain_redirect_message($encodedurl); + exit; + } +} + /** * Create a directory. * @@ -839,39 +862,51 @@ class bootstrap_renderer { @header('Expires: Mon, 20 Aug 1969 09:23:00 GMT'); @header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); - if (function_exists('get_string') && function_exists('get_html_lang')) { - $htmllang = get_html_lang(); + if (function_exists('get_string')) { $strerror = get_string('error'); } else { - $htmllang = ''; $strerror = 'Error'; } - $output = ' - - - -' . $strerror . ' - -
' . $message . '
'; if (!empty($CFG->debug) && $CFG->debug >= DEBUG_DEVELOPER) { if (!empty($debuginfo)) { - $output .= '
' . $debuginfo . '
'; + $content .= '
' . $debuginfo . '
'; } if (!empty($backtrace)) { - $output .= '
Stack trace: ' . format_backtrace($backtrace, false) . '
'; + $content .= '
Stack trace: ' . format_backtrace($backtrace, false) . '
'; } } - - $output .= ''; - return $output; + + return self::plain_page($strerror, $content); } public static function early_notification($message, $classes = 'notifyproblem') { return '
' . $message . '
'; } + + public static function plain_redirect_message($encodedurl) { + $message = '

' . get_string('pageshouldredirect') . '

'. get_string('continue') .'

'; + return plain_page(get_string('redirect'), $message); + } + + protected static function plain_page($title, $content) { + if (function_exists('get_string') && function_exists('get_html_lang')) { + $htmllang = get_html_lang(); + } else { + $htmllang = ''; + } + + return ' + + + +' . $title . ' +' . $content . ''; + } } diff --git a/lib/weblib.php b/lib/weblib.php index 81032bcff08..c61c4fe92c8 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -4941,6 +4941,8 @@ function redirect($url, $message='', $delay=-1) { //302 might not work for POST requests, 303 is ignored by obsolete clients. @header($_SERVER['SERVER_PROTOCOL'] . ' 303 See Other'); @header('Location: '.$url); + echo bootstrap_renderer::plain_redirect_message($encodedurl); + exit; } // Include a redirect message, even with a HTTP redirect, because that is recommended practice. diff --git a/login/index.php b/login/index.php index d6105c3b2cc..8ec7ac2cee5 100644 --- a/login/index.php +++ b/login/index.php @@ -3,14 +3,7 @@ require_once("../config.php"); -/// check if major upgrade needed - also present in /index.php - if ((int)$CFG->version < 2009071000) { //1.9 or older - try { - @require_logout(); - } catch (Exception $e) { - } - redirect("$CFG->wwwroot/$CFG->admin/"); - } + redirect_if_major_upgrade_required(); $loginguest = optional_param('loginguest', 0, PARAM_BOOL); // determines whether visitors are logged in as guest automatically $testcookies = optional_param('testcookies', 0, PARAM_BOOL); // request cookie test