}
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, " ", " ");
+ 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);
return true;
}
-function upgrade_RPC_functions($returnurl) {
+function upgrade_RPC_functions() {
global $CFG;
// TODO: rewrite this thing so that it:
* 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;
$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])) {
$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);
}
}
}
$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']))){
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
*
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.
}
$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;
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');
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);
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);
$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;
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');
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) {
}
/// 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);
}
} else { // module not installed yet, so install it
- print_upgrade_header();
upgrade_log_start();
print_heading($module->name);
$updated_modules = true;
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);
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);
*
* 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;
+ }
+ }
}
/**
if ($currblock->version == $block->version) {
// do nothing
} else if ($currblock->version < $block->version) {
- print_upgrade_header();
$updated_blocks = true;
upgrade_log_start();
// [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);
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 />';
}
}
* 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
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;
}
/**
* @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);
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 == '') {
}
}
- // 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);
}