]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-17845 now only one page per installs/upgrade :-D
authorskodak <skodak>
Mon, 12 Jan 2009 15:13:44 +0000 (15:13 +0000)
committerskodak <skodak>
Mon, 12 Jan 2009 15:13:44 +0000 (15:13 +0000)
admin/index.php
admin/mnet/adminlib.php
lib/accesslib.php
lib/adminlib.php
lib/blocklib.php
lib/locallib.php
lib/moodlelib.php
lib/weblib.php

index b39146080d3566daa5a6c3938cf3ed9517d22df4..95f7c8e1dec5e88776da71addefdaae9ad483d77 100644 (file)
     }
     unset($tables);
 
+    // Turn off xmlstrictheaders during upgrade.
+    $origxmlstrictheaders = !empty($CFG->xmlstrictheaders);
+    $CFG->xmlstrictheaders = false;
+
     if (!$maintables) {
     /// hide errors from headers in case debug enabled in config.php
         $origdebug = $CFG->debug;
 
         /// do not show certificates in log ;-)
         $DB->set_debug(false);
-
-        print_continue("index.php");
-        print_footer('none');
-
-        die;
     }
 
 
         $origdebug = $CFG->debug;
         $CFG->debug = DEBUG_MINIMAL;
         error_reporting($CFG->debug);
-        $CFG->xmlstrictheaders = false;
 
         // logo ut in case we are upgrading from pre 1.9 version in order to prevent
         // weird session/role problems caused by incorrect data in USER and SESSION
         } else {
 
             $strdatabasesuccess  = get_string("databasesuccess");
-            $navigation = build_navigation(array(array('name'=>$strdatabasesuccess, 'link'=>null, 'type'=>'misc')));
-            print_header($strdatabasechecking, $stradministration, $navigation,
-                    "", upgrade_get_javascript(), false, "&nbsp;", "&nbsp;");
+            upgrade_log_start();
 
         /// return to original debugging level
             $CFG->debug = $origdebug;
                 message_update_providers();
                 message_update_providers('message');
 
-                if (set_config("version", $version)) {
-                    remove_dir($CFG->dataroot . '/cache', true); // flush cache
-                    notify($strdatabasesuccess, "green");
-                    print_continue("upgradesettings.php");
-                    print_footer('none');
-                    exit;
-                } else {
-                    print_error('cannotupdateversion', 'debug');
-                }
+                set_config("version", $version);
+                remove_dir($CFG->dataroot . '/cache', true); // flush cache
+                notify($strdatabasesuccess, "green");
+
         /// Main upgrade not success
             } else {
                 notify('Main Upgrade failed!  See lib/db/upgrade.php');
         }
     }
 
-    // Turn off xmlstrictheaders during upgrade.
-    $origxmlstrictheaders = !empty($CFG->xmlstrictheaders);
-    $CFG->xmlstrictheaders = false;
-
 /// upgrade all plugins types
-    $upgradedplugins = false;
     $plugintypes = get_plugin_types();
     foreach ($plugintypes as $type=>$location) {
-        $upgradedplugins = upgrade_plugins($type, $location) || $upgradedplugins;
-    }
-
-    if ($upgradedplugins) {
-        print_continue($FULLSCRIPT);
-        print_footer('none');
-        die;
+        upgrade_plugins($type, $location);
     }
 
 /// Check for changes to RPC functions
     if ($CFG->mnet_dispatcher_mode != 'off') {
         require_once("$CFG->dirroot/$CFG->admin/mnet/adminlib.php");
-        upgrade_RPC_functions($FULLSCRIPT);  // Return here afterwards
+        upgrade_RPC_functions();  // Return here afterwards
     }
 
 /// Check for local database customisations
     require_once("$CFG->dirroot/lib/locallib.php");
-    upgrade_local_db($FULLSCRIPT);  // Return here afterwards
-
-/// just make sure upgrade logging is properly terminated
-    upgrade_log_finish();
-
-    // Turn xmlstrictheaders back on now.
-    $CFG->xmlstrictheaders = $origxmlstrictheaders;
+    upgrade_local_db();  // Return here afterwards
 
 /// make sure admin user is created - this is the last step because we need
 /// session to be working properly in order to edit admin account
     if (empty($CFG->rolesactive)) {
         $adminuser = create_admin_user();
         $adminuser->newadminuser = 1;
-        complete_user_login($adminuser);
+        complete_user_login($adminuser, false);
+        upgrade_log_finish("$CFG->wwwroot/user/editadvanced.php?id=$adminuser->id"); // Edit thyself
 
-        redirect("$CFG->wwwroot/user/editadvanced.php?id=$adminuser->id");  // Edit thyself
+    } else {
+    /// just make sure upgrade logging is properly terminated
+        upgrade_log_finish('upgradesettings.php');
     }
 
 
+    // Turn xmlstrictheaders back on now.
+    $CFG->xmlstrictheaders = $origxmlstrictheaders;
+    unset($origxmlstrictheaders);
+
 /// Check for valid admin user - no guest autologin
     require_login(0, false);
     $context = get_context_instance(CONTEXT_SYSTEM);
index 33da317f21de456a8eb3b0588c96ea903017020b..4514f9c7223612634eb85c674ec2d7de0df8e25f 100644 (file)
@@ -140,7 +140,7 @@ function mnet_get_functions($type, $parentname) {
     return true;
 }
 
-function upgrade_RPC_functions($returnurl) {
+function upgrade_RPC_functions() {
     global $CFG;
 
     // TODO: rewrite this thing so that it:
index fa1270f46696a9950aef1987c22a69de349c48ef..5c1dc6483f449d27b498ad26119af55db2743101 100755 (executable)
@@ -3257,7 +3257,7 @@ function reset_role_capabilities($roleid) {
  * the database.
  *
  * @param $component - examples: 'moodle', 'mod/forum', 'block/quiz_results'
- * @return boolean
+ * @return boolean true if success, exception in case of any problems
  */
 function update_capabilities($component='moodle') {
     global $DB;
@@ -3278,9 +3278,7 @@ function update_capabilities($component='moodle') {
                     $updatecap = new object();
                     $updatecap->id = $cachedcap->id;
                     $updatecap->riskbitmask = $filecaps[$cachedcap->name]['riskbitmask'];
-                    if (!$DB->update_record('capabilities', $updatecap)) {
-                        return false;
-                    }
+                    $DB->update_record('capabilities', $updatecap);
                 }
 
                 if (!array_key_exists('contextlevel', $filecaps[$cachedcap->name])) {
@@ -3290,9 +3288,7 @@ function update_capabilities($component='moodle') {
                     $updatecap = new object();
                     $updatecap->id = $cachedcap->id;
                     $updatecap->contextlevel = $filecaps[$cachedcap->name]['contextlevel'];
-                    if (!$DB->update_record('capabilities', $updatecap)) {
-                        return false;
-                    }
+                    $DB->update_record('capabilities', $updatecap);
                 }
             }
         }
@@ -3319,10 +3315,7 @@ function update_capabilities($component='moodle') {
         $capability->component = $component;
         $capability->riskbitmask = $capdef['riskbitmask'];
 
-        if (!$DB->insert_record('capabilities', $capability, false)) {
-            return false;
-        }
-
+        $DB->insert_record('capabilities', $capability, false);
 
         if (isset($capdef['clonepermissionsfrom']) && in_array($capdef['clonepermissionsfrom'], $storedcaps)){
             if ($rolecapabilities = $DB->get_records('role_capabilities', array('capability'=>$capdef['clonepermissionsfrom']))){
index 26fab9c256857030d58340f81108467b6a04b2d3..01d8b30bacf020b6cee3e8f8c3a0c8689ea4c15d 100644 (file)
@@ -317,18 +317,6 @@ function get_db_directories() {
     return $dbdirs;
 }
 
-function print_upgrade_header() {
-    if (defined('HEADER_PRINTED')) {
-        return;
-    }
-
-    $strpluginsetup  = get_string('pluginsetup');
-
-    print_header($strpluginsetup, $strpluginsetup,
-        build_navigation(array(array('name' => $strpluginsetup, 'link' => null, 'type' => 'misc'))), '',
-        upgrade_get_javascript(), false, '&nbsp;', '&nbsp;');
-}
-
 /**
  * Upgrade plugins
  *
@@ -358,7 +346,7 @@ function upgrade_plugins($type, $dir) {
         unset($plugin);
 
         if (is_readable($fullplug .'/version.php')) {
-            include_once($fullplug .'/version.php');  // defines $plugin with version etc
+            include($fullplug .'/version.php');  // defines $plugin with version etc
         } else {
             continue;                              // Nothing to do.
         }
@@ -380,7 +368,6 @@ function upgrade_plugins($type, $dir) {
                 $info->pluginversion  = $plugin->version;
                 $info->currentmoodle = $CFG->version;
                 $info->requiremoodle = $plugin->requires;
-                print_upgrade_header();
                 upgrade_log_start();
                 notify(get_string('pluginrequirementsnotmet', 'error', $info));
                 $updated_plugins = true;
@@ -400,7 +387,6 @@ function upgrade_plugins($type, $dir) {
         if ($installedversion == $plugin->version) {
             // do nothing
         } else if ($installedversion < $plugin->version) {
-            print_upgrade_header();
             $updated_plugins = true;
             upgrade_log_start();
             print_heading($dir.'/'. $plugin->name .' plugin needs upgrading');
@@ -425,9 +411,8 @@ function upgrade_plugins($type, $dir) {
                     set_config('version', $plugin->version, $plugin->fullname);
 
                 /// Install capabilities
-                    if (!update_capabilities($type.'/'.$plug)) {
-                        print_error('cannotsetupcapforplugin', '', '', $plugin->name);
-                    }
+                    update_capabilities($type.'/'.$plug);
+
                 /// Install events
                     events_update_definition($type.'/'.$plug);
 
@@ -469,9 +454,7 @@ function upgrade_plugins($type, $dir) {
                 if ($newupgrade_status) {    // No upgrading failed
                 /// OK so far, now update the plugins record
                     set_config('version', $plugin->version, $plugin->fullname);
-                    if (!update_capabilities($type.'/'.$plug)) {
-                        print_error('cannotupdateplugincap', '', '', $plugin->name);
-                    }
+                    update_capabilities($type.'/'.$plug);
                 /// Update events
                     events_update_definition($type.'/'.$plug);
 
@@ -546,7 +529,6 @@ function upgrade_activity_modules() {
                 $info->moduleversion  = $module->version;
                 $info->currentmoodle = $CFG->version;
                 $info->requiremoodle = $module->requires;
-                print_upgrade_header();
                 upgrade_log_start();
                 notify(get_string('modulerequirementsnotmet', 'error', $info));
                 $updated_modules = true;
@@ -567,7 +549,6 @@ function upgrade_activity_modules() {
                     notify('Upgrade file ' . $mod . ': ' . $fullmod . '/db/upgrade.php is not readable');
                     continue;
                 }
-                print_upgrade_header();
                 upgrade_log_start();
 
                 print_heading($module->name .' module needs upgrading');
@@ -593,9 +574,7 @@ function upgrade_activity_modules() {
                 if ($newupgrade_status) {    // No upgrading failed
                     // OK so far, now update the modules record
                     $module->id = $currmodule->id;
-                    if (!$DB->update_record('modules', $module)) {
-                        print_error('cannotupdatemod', '', '', $module->name);
-                    }
+                    $DB->update_record('modules', $module);
                     remove_dir($CFG->dataroot . '/cache', true); // flush cache
                     notify(get_string('modulesuccess', '', $module->name), 'notifysuccess');
                     if (!defined('CLI_UPGRADE') || !CLI_UPGRADE) {
@@ -606,9 +585,7 @@ function upgrade_activity_modules() {
                 }
 
             /// Update the capabilities table?
-                if (!update_capabilities('mod/'.$module->name)) {
-                    print_error('cannotupdatemodcap', '', '', $module->name);
-                }
+                update_capabilities('mod/'.$module->name);
 
             /// Update events
                 events_update_definition('mod/'.$module->name);
@@ -623,7 +600,6 @@ function upgrade_activity_modules() {
             }
 
         } else {    // module not installed yet, so install it
-            print_upgrade_header();
             upgrade_log_start();
             print_heading($module->name);
             $updated_modules = true;
@@ -648,9 +624,7 @@ function upgrade_activity_modules() {
                 if ($module->id = $DB->insert_record('modules', $module)) {
 
                 /// Capabilities
-                    if (!update_capabilities('mod/'.$module->name)) {
-                        print_error('cannotsetupcapformod', '', '', $module->name);
-                    }
+                    update_capabilities('mod/'.$module->name);
 
                 /// Events
                     events_update_definition('mod/'.$module->name);
@@ -887,6 +861,14 @@ function upgrade_log_start() {
         upgrade_set_timeout(120);
 
     } else {
+        if (!CLI_SCRIPT and !defined('HEADER_PRINTED')) {
+            $strupgrade  = get_string('upgrade');
+
+            print_header($strupgrade, $strupgrade,
+                build_navigation(array(array('name' => $strupgrade, 'link' => null, 'type' => 'misc'))), '',
+                upgrade_get_javascript(), false, '&nbsp;', '&nbsp;');
+        }
+
         ignore_user_abort(true);
         register_shutdown_function('upgrade_finished_handler');
         set_config('upgraderunning', time()+300);
@@ -906,9 +888,17 @@ function upgrade_finished_handler() {
  *
  * This function may be called repeatedly.
  */
-function upgrade_log_finish() {
-    unset_config('upgraderunning');
-    ignore_user_abort(false);
+function upgrade_log_finish($continueurl=null) {
+    global $CFG;
+    if (!empty($CFG->upgraderunning)) {
+        unset_config('upgraderunning');
+        ignore_user_abort(false);
+        if ($continueurl) {
+            print_continue($continueurl);
+            print_footer('none');
+            die;
+        }
+    }
 }
 
 /**
index 66b030910ba92ba697140a457b7366cc41d39f9b..ec7f57df73f1bdf3dce896e4eb94041815c791f4 100644 (file)
@@ -1171,7 +1171,6 @@ function upgrade_blocks_plugins() {
             if ($currblock->version == $block->version) {
                 // do nothing
             } else if ($currblock->version < $block->version) {
-                print_upgrade_header();
                 $updated_blocks = true;
                 upgrade_log_start();
 
@@ -1242,12 +1241,11 @@ function upgrade_blocks_plugins() {
             // [pj] Normally this would be inline in the if, but we need to
             //      check for NULL (necessary for 4.0.5 <= PHP < 4.2.0)
             $conflictblock = array_search($blocktitle, $blocktitles);
-            if($conflictblock !== false && $conflictblock !== NULL) {
+            if ($conflictblock !== false && $conflictblock !== NULL) {
                 // Duplicate block titles are not allowed, they confuse people
                 // AND PHP's associative arrays ;)
                 print_error('blocknameconflict', '', '', (object)array('name'=>$block->name, 'conflict'=>$conflictblock));
             }
-            print_upgrade_header();
             $updated_blocks = true;
             upgrade_log_start();
             print_heading($block->name);
@@ -1261,34 +1259,24 @@ function upgrade_blocks_plugins() {
             if (file_exists($fullblock . '/db/install.xml')) {
                 $DB->get_manager()->install_from_xmldb_file($fullblock . '/db/install.xml'); //New method
             }
-            $status = true;
             if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
                 $DB->set_debug(false);
             }
-            if ($status) {
-                if ($block->id = $DB->insert_record('block', $block)) {
-                    $blockobj->after_install();
-                    $component = 'block/'.$block->name;
-                    if (!update_capabilities($component)) {
-                        notify('Could not set up '.$block->name.' capabilities!');
-                    }
+            $block->id = $DB->insert_record('block', $block);
+            $blockobj->after_install();
+            $component = 'block/'.$block->name;
+            update_capabilities($component);
 
-                    // Update events
-                    events_update_definition($component);
+            // Update events
+            events_update_definition($component);
 
-                    // Update message providers
-                    require_once($CFG->libdir .'/messagelib.php');      // Messagelib functions
-                    message_update_providers($component);
+            // Update message providers
+            require_once($CFG->libdir .'/messagelib.php');      // Messagelib functions
+            message_update_providers($component);
 
-                    notify(get_string('blocksuccess', '', $blocktitle), 'notifysuccess');
-                    if (!defined('CLI_UPGRADE')|| !CLI_UPGRADE) {
-                    echo '<hr />';
-                    }
-                } else {
-                    print_error('cannotaddblock', '', '', $block->name);
-                }
-            } else {
-                print_error('cannotsetupblock', '', '', $block->name);
+            notify(get_string('blocksuccess', '', $blocktitle), 'notifysuccess');
+            if (!defined('CLI_UPGRADE')|| !CLI_UPGRADE) {
+                echo '<hr />';
             }
         }
 
index 6b67e2c8c48df012d01c0bd30aeac75e6fbcc6bf..375c9977f3f8f5f5b15510a11d9d749ba5481135 100644 (file)
  * On success it prints a continue link. On failure it prints an error.
  *
  * @uses $CFG
- * @param string $continueto a URL passed to print_continue() if the local upgrades succeed.
+ * @return bool true if upgraded anything
  */
-function upgrade_local_db($continueto) {
+function upgrade_local_db() {
 
     global $CFG, $DB;
 
     // if we don't have code version or a db upgrade file, just return true, we're unneeded
     if (!file_exists($CFG->dirroot.'/local/version.php') || !file_exists($CFG->dirroot.'/local/db/upgrade.php')) {
-        return true;
+        return false;
     }
 
     require_once ($CFG->dirroot .'/local/version.php');  // Get code versions
@@ -131,54 +131,30 @@ function upgrade_local_db($continueto) {
 
     if ($local_version > $CFG->local_version) { // upgrade!
         $strdatabaseupgrades = get_string('databaseupgrades');
-        if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
-        print_header($strdatabaseupgrades, $strdatabaseupgrades,
-            build_navigation(array(array('name' => $strdatabaseupgrades, 'link' => null, 'type' => 'misc'))), '', upgrade_get_javascript());
-        }
-
         upgrade_log_start();
         require_once ($CFG->dirroot .'/local/db/upgrade.php');
 
         if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
             $DB->set_debug(true);
         }
-        if (xmldb_local_upgrade($CFG->local_version)) {
-            if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
-                $DB->set_debug(false);
-            }
-            if (set_config('local_version', $local_version)) {
-                notify(get_string('databasesuccess'), 'notifysuccess');
-                notify(get_string('databaseupgradelocal', '', $local_version), 'notifysuccess');
-                if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
-                print_continue($continueto);
-                print_footer('none');
-                exit;
-                } else if (CLI_UPGRADE && ($interactive > CLI_SEMI) ) {
-                    console_write('askcontinue');
-                    if (read_boolean()){
-                        return ;
-                    }else {
-                        console_write_error('','',false);
-                    }
-                }
-            } else {
-                print_error('cannotupgradedbcustom', 'debug');
-            }
-        } else {
-            if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
-                $DB->set_debug(false);
-            }
-            print_error('upgradefail', 'debug', '', 'local/version.php');
+        xmldb_local_upgrade($CFG->local_version);
+        if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
+            $DB->set_debug(false);
         }
+        set_config('local_version', $local_version);
+        notify(get_string('databasesuccess'), 'notifysuccess');
+        notify(get_string('databaseupgradelocal', '', $local_version), 'notifysuccess');
+
+        return true;
 
     } else if ($local_version < $CFG->local_version) {
         notify('WARNING!!!  The local version you are using is OLDER than the version that made these databases!');
     }
 
     /// Capabilities
-    if (!update_capabilities('local')) {
-        print_error('cannotsetupcapformod', 'error', '', 'local');
-    }
+    update_capabilities('local');
+
+    return false;
 }
 
 /**
index 4e6451366d7860aadb9d9b908d1f4712d181cfde..74cbb802f2232533f274534bb7bdd2f6909da606 100644 (file)
@@ -3172,23 +3172,26 @@ function authenticate_user_login($username, $password) {
  * @param string $user obj
  * @return object A {@link $USER} object - BC only, do not use
  */
-function complete_user_login($user) {
+function complete_user_login($user, $setcookie=true) {
     global $CFG, $USER, $SESSION;
 
     // check enrolments, load caps and setup $USER object
     session_set_user($user);
 
     update_user_login_times();
-    if (empty($CFG->nolastloggedin)) {
-        set_moodle_cookie($USER->username);
-    } else {
-        // do not store last logged in user in cookie
-        // auth plugins can temporarily override this from loginpage_hook()
-        // do not save $CFG->nolastloggedin in database!
-        set_moodle_cookie('nobody');
-    }
     set_login_session_preferences();
 
+    if ($setcookie) {
+        if (empty($CFG->nolastloggedin)) {
+            set_moodle_cookie($USER->username);
+        } else {
+            // do not store last logged in user in cookie
+            // auth plugins can temporarily override this from loginpage_hook()
+            // do not save $CFG->nolastloggedin in database!
+            set_moodle_cookie('nobody');
+        }
+    }
+
     /// Select password change url
     $userauth = get_auth_plugin($USER->auth);
 
index 45664d88470ba2b6db3bf7ae7fca34eba62905c9..fca6e2c25a7d371ebe29237e9886c508b4db5f3a 100644 (file)
@@ -3895,11 +3895,6 @@ function print_continue($link, $return=false) {
 
     global $CFG;
 
-    // in case we are logging upgrade in admin/index.php stop it
-    if (function_exists('upgrade_log_finish')) {
-        upgrade_log_finish();
-    }
-
     $output = '';
 
     if ($link == '') {
@@ -5731,11 +5726,6 @@ function _print_normal_error($errorcode, $module, $a, $link, $backtrace, $debugi
         }
     }
 
-    // in case we are logging upgrade in admin/index.php stop it
-    if (function_exists('upgrade_log_finish')) {
-        upgrade_log_finish();
-    }
-
     if (!empty($link)) {
         print_continue($link);
     }