Skip to content

Commit

Permalink
MDL-17845 now only one page per installs/upgrade :-D
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Jan 12, 2009
1 parent 940b5fb commit 5c144d6
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 170 deletions.
61 changes: 21 additions & 40 deletions admin/index.php
Expand Up @@ -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;
Expand Down Expand Up @@ -172,11 +176,6 @@

/// do not show certificates in log ;-)
$DB->set_debug(false);

print_continue("index.php");
print_footer('none');

die;
}


Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion admin/mnet/adminlib.php
Expand Up @@ -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:
Expand Down
15 changes: 4 additions & 11 deletions lib/accesslib.php
Expand Up @@ -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;
Expand All @@ -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])) {
Expand All @@ -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);
}
}
}
Expand All @@ -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']))){
Expand Down
62 changes: 26 additions & 36 deletions lib/adminlib.php
Expand Up @@ -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
*
Expand Down Expand Up @@ -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.
}
Expand All @@ -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;
Expand All @@ -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');
Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand All @@ -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');
Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
}
}

/**
Expand Down

0 comments on commit 5c144d6

Please sign in to comment.