]> git.mjollnir.org Git - moodle.git/commitdiff
upgrade: MDL-19763 Improve the redirect that forces a DB upgrade when there are major...
authortjhunt <tjhunt>
Fri, 10 Jul 2009 08:44:01 +0000 (08:44 +0000)
committertjhunt <tjhunt>
Fri, 10 Jul 2009 08:44:01 +0000 (08:44 +0000)
Also fix redirect, so 303 redirects don't need to fully initialise $OUTPUT.

index.php
lang/en_utf8/moodle.php
lib/setuplib.php
lib/weblib.php
login/index.php

index 0b244e0c68c97df87d19930b99132ea4f1286a03..bad1b72d4e4d6330681ac47dc05fb1c7cdf5f89f 100644 (file)
--- a/index.php
+++ b/index.php
     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();
index 19bf6a56c212da7cceeae94a002aecf5860f9eff..c32233df6934963df9a44dd3d6972035ce0d5b72 100644 (file)
@@ -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';
index d73a8c74fe657616e0fa8d5424b0402037ffc515..ab2a3a42b8c13be088aa1387c53c9ce1ffbcb02b 100644 (file)
@@ -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 = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" ' . $htmllang . '>
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
-<title>' . $strerror . '</title>
-</head><body>
-<div style="margin-top: 6em; margin-left:auto; margin-right:auto; color:#990000; text-align:center; font-size:large; border-width:1px;
+        $content = '<div style="margin-top: 6em; margin-left:auto; margin-right:auto; color:#990000; text-align:center; font-size:large; border-width:1px;
     border-color:black; background-color:#ffffee; border-style:solid; border-radius: 20px; border-collapse: collapse;
     width: 80%; -moz-border-radius: 20px; padding: 15px">
 ' . $message . '
 </div>';
         if (!empty($CFG->debug) && $CFG->debug >= DEBUG_DEVELOPER) {
             if (!empty($debuginfo)) {
-                $output .= '<div class="notifytiny">' . $debuginfo . '</div>';
+                $content .= '<div class="notifytiny">' . $debuginfo . '</div>';
             }
             if (!empty($backtrace)) {
-                $output .= '<div class="notifytiny">Stack trace: ' . format_backtrace($backtrace, false) . '</div>';
+                $content .= '<div class="notifytiny">Stack trace: ' . format_backtrace($backtrace, false) . '</div>';
             }
         }
-    
-        $output .= '</body></html>';
-        return $output;
+
+        return self::plain_page($strerror, $content);
     }
 
     public static function early_notification($message, $classes = 'notifyproblem') {
         return '<div class="' . $classes . '">' . $message . '</div>';
     }
+
+    public static function plain_redirect_message($encodedurl) {
+        $message = '<p>' . get_string('pageshouldredirect') . '</p><p><a href="'.
+                $encodedurl .'">'. get_string('continue') .'</a></p>';
+        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 '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" ' . $htmllang . '>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<title>' . $title . '</title>
+</head><body>' . $content . '</body></html>';
+    }
 }
index 81032bcff08cad4630728d77f1234229586ebec3..c61c4fe92c82034569a194b65e78b49c66bc6793 100644 (file)
@@ -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.
index d6105c3b2cc49d41e8f0907433ca846ebd6647fc..8ec7ac2cee503ecc921211082e7764862ef53049 100644 (file)
@@ -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