diff --git a/admin/index.php b/admin/index.php index b39146080d3..95f7c8e1dec 100644 --- a/admin/index.php +++ b/admin/index.php @@ -94,6 +94,10 @@ } 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; @@ -172,11 +176,6 @@ /// do not show certificates in log ;-) $DB->set_debug(false); - - print_continue("index.php"); - print_footer('none'); - - die; } @@ -201,7 +200,6 @@ $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 @@ -280,9 +278,7 @@ } 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, " ", " "); + upgrade_log_start(); /// return to original debugging level $CFG->debug = $origdebug; @@ -312,15 +308,10 @@ 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'); @@ -341,50 +332,40 @@ } } - // 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); diff --git a/admin/mnet/adminlib.php b/admin/mnet/adminlib.php index 33da317f21d..4514f9c7223 100644 --- a/admin/mnet/adminlib.php +++ b/admin/mnet/adminlib.php @@ -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: diff --git a/lib/accesslib.php b/lib/accesslib.php index fa1270f4669..5c1dc6483f4 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -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']))){ diff --git a/lib/adminlib.php b/lib/adminlib.php index 26fab9c2568..01d8b30bacf 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -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, ' ', ' '); -} - /** * 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, ' ', ' '); + } + 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; + } + } } /** diff --git a/lib/blocklib.php b/lib/blocklib.php index 66b030910ba..ec7f57df73f 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -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 '