MDL-17845 now only one page per installs/upgrade :-D

This commit is contained in:
skodak 2009-01-12 15:13:44 +00:00
parent 940b5fbb72
commit 5c144d605e
8 changed files with 91 additions and 170 deletions

View File

@ -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);

View 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:

View File

@ -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']))){

View 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, ' ', ' ');
}
/**
* 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;
}
}
}
/**

View 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 />';
}
}

View File

@ -112,15 +112,15 @@
* 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;
}
/**

View 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);

View 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);
}