$agreelicence = optional_param('agreelicence',0, PARAM_BOOL);
+/// check upgrade status first
+ upgrade_check_running("Upgrade already running, please wait!", 10);
+
/// Check some PHP server settings
$documentationlink = "please read the <a href=\"../doc/?frame=install.html&sub=webserver\">install documentation</a>";
print_header($strdatabasesetup, $strdatabasesetup, $strdatabasesetup,
"", $linktoscrolltoerrors, false, " ", " ");
if (file_exists("$CFG->libdir/db/$CFG->dbtype.sql")) {
+ upgrade_log_start();
$db->debug = true;
if (modify_database("$CFG->libdir/db/$CFG->dbtype.sql")) {
$db->debug = false;
} else {
error("Error: Your database ($CFG->dbtype) is not yet fully supported by Moodle. See the lib/db directory.");
}
+ upgrade_log_finish();
print_continue("index.php");
die;
}
$strdatabasesuccess = get_string("databasesuccess");
print_header($strdatabasechecking, $stradministration, $strdatabasechecking,
"", $linktoscrolltoerrors, false, " ", " ");
+ upgrade_log_start();
print_heading($strdatabasechecking);
$db->debug=true;
if (main_upgrade($CFG->version)) {
if (set_config("version", $version)) {
remove_dir($CFG->dataroot . '/cache', true); // flush cache
notify($strdatabasesuccess, "green");
+ upgrade_log_finish();
print_continue("index.php");
exit;
} else {
$db->debug=false;
notify("Upgrade failed! See /version.php");
}
+ upgrade_log_finish();
}
} else if ($version < $CFG->version) {
notify("WARNING!!! The code you are using is OLDER than the version that made these databases!");
"", "", false, " ", " ");
if (!set_config("version", $version)) {
+ upgrade_log_start();
$db->debug=true;
if (main_upgrade(0)) {
+ upgrade_log_finish();
print_continue("index.php");
+ exit;
} else {
error("A problem occurred inserting current version into databases");
}
print_header($strcurrentrelease, $strcurrentrelease, $strcurrentrelease, "", "", false, " ", " ");
print_heading("Moodle $release");
if (!set_config("release", $release)) {
+ upgrade_log_start();
notify("ERROR: Could not update release version in database!!");
+ upgrade_log_finish();
}
notice(get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/en/Release_Notes'), 'index.php');
exit;
require_once("$CFG->dirroot/lib/locallib.php");
upgrade_local_db("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
+/// just make sure upgrade logging is properly terminated
+ upgrade_log_finish();
/// Set up the overall site name etc.
if (! $site = get_site()) {
'<script type="text/javascript" src="' . $CFG->wwwroot . '/lib/scroll_to_errors.js"></script>',
false, " ", " ");
+ upgrade_log_start();
$db->debug=true;
if (modify_database("$CFG->dirroot/backup/db/$CFG->dbtype.sql")) {
$db->debug = false;
if (set_config("backup_version", $backup_version) and set_config("backup_release", $backup_release)) {
notify(get_string("databasesuccess"), "green");
notify(get_string("databaseupgradebackups", "", $backup_version));
+ upgrade_log_finish();
print_continue($continueto);
exit;
} else {
print_header($strdatabaseupgrades, $strdatabaseupgrades, $strdatabaseupgrades, '',
'<script type="text/javascript" src="' . $CFG->wwwroot . '/lib/scroll_to_errors.js"></script>');
+ upgrade_log_start();
require_once ("$CFG->dirroot/backup/db/$CFG->dbtype.php");
$db->debug=true;
if (set_config("backup_version", $backup_version) and set_config("backup_release", $backup_release)) {
notify(get_string("databasesuccess"), "green");
notify(get_string("databaseupgradebackups", "", $backup_version));
+ upgrade_log_finish();
print_continue($continueto);
exit;
} else {
}
} else if ($backup_version < $CFG->backup_version) {
+ upgrade_log_start();
notify("WARNING!!! The code you are using is OLDER than the version that made these databases!");
}
+
}
error('No '.$type.' plugins installed!');
}
+ $updated_plugins = false;
+ $strpluginsetup = get_string('pluginsetup');
+
foreach ($plugs as $plug) {
$fullplug = $CFG->dirroot .'/'.$dir.'/'. $plug;
$info->pluginversion = $plugin->version;
$info->currentmoodle = $CFG->version;
$info->requiremoodle = $plugin->requires;
+ if (!$updated_plugins) {
+ print_header($strpluginsetup, $strpluginsetup, $strpluginsetup, '',
+ '<script type="text/javascript" src="' . $CFG->wwwroot . '/lib/scroll_to_errors.js"></script>',
+ false, ' ', ' ');
+ }
+ upgrade_log_start();
notify(get_string('pluginrequirementsnotmet', 'error', $info));
+ $updated_plugins = true;
unset($info);
continue;
}
if ($CFG->$pluginversion == $plugin->version) {
// do nothing
} else if ($CFG->$pluginversion < $plugin->version) {
- if (empty($updated_plugins)) {
- $strpluginsetup = get_string('pluginsetup');
+ if (!$updated_plugins) {
print_header($strpluginsetup, $strpluginsetup, $strpluginsetup, '',
'<script type="text/javascript" src="' . $CFG->wwwroot . '/lib/scroll_to_errors.js"></script>',
false, ' ', ' ');
}
+ upgrade_log_start();
print_heading($plugin->name .' plugin needs upgrading');
-
if ($CFG->$pluginversion == 0) { // It's a new install of this plugin
if (file_exists($fullplug .'/db/'. $CFG->dbtype .'.sql')) {
$db->debug = true;
}
echo '<hr />';
$updated_plugins = true;
-
} else {
+ upgrade_log_start();
error('Version mismatch: '. $plugin->name .' can\'t downgrade '. $CFG->$pluginversion .' -> '. $plugin->version .' !');
}
}
- if (!empty($updated_plugins)) {
+ upgrade_log_finish();
+
+ if ($updated_plugins) {
print_continue($return);
die;
}
error('No modules installed!');
}
+ $updated_modules = false;
+ $strmodulesetup = get_string('modulesetup');
+
foreach ($mods as $mod) {
if ($mod == 'NEWMODULE') { // Someone has unzipped the template, ignore it
$info->moduleversion = $module->version;
$info->currentmoodle = $CFG->version;
$info->requiremoodle = $module->requires;
+ if (!$updated_modules) {
+ print_header($strmodulesetup, $strmodulesetup, $strmodulesetup, '',
+ '<script type="text/javascript" src="' . $CFG->wwwroot . '/lib/scroll_to_errors.js"></script>',
+ false, ' ', ' ');
+ }
+ upgrade_log_start();
notify(get_string('modulerequirementsnotmet', 'error', $info));
+ $updated_modules = true;
unset($info);
continue;
}
if ($currmodule->version == $module->version) {
// do nothing
} else if ($currmodule->version < $module->version) {
- if (empty($updated_modules)) {
- $strmodulesetup = get_string('modulesetup');
+ if (!$updated_modules) {
print_header($strmodulesetup, $strmodulesetup, $strmodulesetup, '',
'<script type="text/javascript" src="' . $CFG->wwwroot . '/lib/scroll_to_errors.js"></script>',
false, ' ', ' ');
}
+ upgrade_log_start();
print_heading($module->name .' module needs upgrading');
$upgrade_function = $module->name.'_upgrade';
if (function_exists($upgrade_function)) {
}
$updated_modules = true;
} else {
+ upgrade_log_start();
error('Version mismatch: '. $module->name .' can\'t downgrade '. $currmodule->version .' -> '. $module->version .' !');
}
} else { // module not installed yet, so install it
- if (empty($updated_modules)) {
- $strmodulesetup = get_string('modulesetup');
+ if (!$updated_modules) {
print_header($strmodulesetup, $strmodulesetup, $strmodulesetup, '',
'<script type="text/javascript" src="' . $CFG->wwwroot . '/lib/scroll_to_errors.js"></script>',
false, ' ', ' ');
}
+ upgrade_log_start();
print_heading($module->name);
$updated_modules = true;
$db->debug = true;
}
}
- if (!empty($updated_modules)) {
+ upgrade_log_finish(); // finish logging if started
+
+ if ($updated_modules) {
print_continue($return);
print_footer();
die;
sleep($sleeptime);
}
}
+
+////////////////////////////////////////////////
+/// upgrade logging functions
+////////////////////////////////////////////////
+
+$upgradeloghandle = false;
+global $upgradeloghandle; // needed for access from callback funtion
+
+/**
+ * Check if upgrade is already running.
+ *
+ * If anything goes wrong due to missing call to upgrade_log_finish()
+ * just restart the browser.
+ *
+ * @param string warning message indicating upgrade is already running
+ * @param int page reload timeout
+ */
+function upgrade_check_running($message, $timeout) {
+ if (!empty($_SESSION['upgraderunning'])) {
+ print_header();
+ redirect(me(), $message, $timeout);
+ }
+}
+
+/**
+ * Start logging of output into file (if not disabled) and
+ * prevent aborting and concurrent execution of upgrade script.
+ *
+ * Please note that you can not write into session variables after calling this function!
+ *
+ * This function may be called repeatedly.
+ */
+function upgrade_log_start() {
+ global $upgradeloghandle;
+
+ if (!empty($_SESSION['upgraderunning'])) {
+ return; // logging already started
+ }
+
+ @ignore_user_abort(true); // ignore if user stops or otherwise aborts page loading
+ $_SESSION['upgraderunning'] = 1; // set upgrade indicator
+ session_write_close(); // from now on user can reload page - will be displayed warning
+ make_upload_directory('upgradelogs');
+ ob_start('upgrade_log_callback', 2); // function for logging to disk; flush each line of text ASAP
+}
+
+/**
+ * Terminate logging of output, flush all data, allow script aborting
+ * and reopen session for writing. Function error() does terminate the logging too.
+ *
+ * Please make sure that each upgrade_log_start() is properly terminated by
+ * this function or error().
+ *
+ * This function may be called repeatedly.
+ */
+function upgrade_log_finish() {
+ global $upgradeloghandle;
+
+ if (empty($_SESSION['upgraderunning'])) {
+ return; // logging already terminated
+ }
+
+ @ob_end_flush();
+ @fclose($upgradeloghandle);
+ @session_start(); // ignore header errors, we only need to reopen session
+ $_SESSION['upgraderunning'] = 0; // clear upgrade indicator
+ if (connection_aborted()) {
+ die;
+ }
+ @ignore_user_abort(false);
+}
+
+/**
+ * Callback function for logging into files. Not more than one file is created per minute,
+ * upgrade session (terminated by upgrade_log_finish()) is always stored in one file.
+ *
+ * This function must not output any characters or throw warnigns and errors!
+ */
+function upgrade_log_callback($string) {
+ global $CFG, $upgradeloghandle;
+
+ if (empty($CFG->disableupgradelogging) and ($string != '') and ($upgradeloghandle !== 'error')) {
+ if ($upgradeloghandle or ($upgradeloghandle = @fopen($CFG->dataroot.'/upgradelogs/upg_'.date('Ymd-Hi').'.html', 'a'))) {
+ @fwrite($upgradeloghandle, $string);
+ } else {
+ $upgradeloghandle = 'error';
+ }
+ }
+ return $string;
+}
+
?>
'<script type="text/javascript" src="' . $CFG->wwwroot . '/lib/scroll_to_errors.js"></script>',
false, ' ', ' ');
+ upgrade_log_start();
$db->debug=true;
if (modify_database($CFG->dirroot .'/blocks/db/'. $CFG->dbtype .'.sql')) {
$db->debug = false;
if (set_config('blocks_version', $blocks_version)) {
notify(get_string('databasesuccess'), 'notifysuccess');
notify(get_string('databaseupgradeblocks', '', $blocks_version));
+ upgrade_log_finish();
print_continue($continueto);
exit;
} else {
$strdatabaseupgrades = get_string('databaseupgrades');
print_header($strdatabaseupgrades, $strdatabaseupgrades, $strdatabaseupgrades, '',
'<script type="text/javascript" src="' . $CFG->wwwroot . '/lib/scroll_to_errors.js"></script>');
+
+ upgrade_log_start();
require_once ($CFG->dirroot .'/blocks/db/'. $CFG->dbtype .'.php');
$db->debug=true;
if (set_config('blocks_version', $blocks_version)) {
notify(get_string('databasesuccess'), 'notifysuccess');
notify(get_string('databaseupgradeblocks', '', $blocks_version));
+ upgrade_log_finish();
print_continue($continueto);
exit;
} else {
}
} else if ($blocks_version < $CFG->blocks_version) {
+ upgrade_log_start();
notify('WARNING!!! The Blocks version you are using is OLDER than the version that made these databases!');
}
+
}
//This function finds all available blocks and install them
'<script type="text/javascript" src="' . $CFG->wwwroot . '/lib/scroll_to_errors.js"></script>',
false, ' ', ' ');
}
+ upgrade_log_start();
print_heading('New version of '.$blocktitle.' ('.$block->name.') exists');
$upgrade_function = $block->name.'_upgrade';
if (function_exists($upgrade_function)) {
}
$updated_blocks = true;
} else {
+ upgrade_log_start();
error('Version mismatch: block '. $block->name .' can\'t downgrade '. $currblock->version .' -> '. $block->version .'!');
}
'<script type="text/javascript" src="' . $CFG->wwwroot . '/lib/scroll_to_errors.js"></script>',
false, ' ', ' ');
}
+ upgrade_log_start();
print_heading($block->name);
$updated_blocks = true;
$db->debug = true;
}
if(!empty($notices)) {
+ upgrade_log_start();
foreach($notices as $notice) {
notify($notice);
}
// Finally, if we are in the first_install of BLOCKS (this means that we are
// upgrading from Moodle < 1.3), put blocks in all existing courses.
if ($first_install) {
+ upgrade_log_start();
//Iterate over each course
if ($courses = get_records('course')) {
foreach ($courses as $course) {
}
if (!empty($CFG->siteblocksadded)) { /// This is a once-off hack to make a proper upgrade
+ upgrade_log_start();
$page = page_create_object(PAGE_COURSE_VIEW, SITEID);
blocks_repopulate_page($page);
delete_records('config', 'name', 'siteblocksadded');
}
+ upgrade_log_finish();
+
if (!empty($updated_blocks)) {
print_continue($continueto);
die;
print_header($strdatabaseupgrades, $strdatabaseupgrades, $strdatabaseupgrades, '',
'<script type="text/javascript" src="' . $CFG->wwwroot . '/lib/scroll_to_errors.js"></script>');
+ upgrade_log_start();
require_once ($CFG->dirroot .'/local/db/'. $CFG->dbtype .'.php');
$db->debug=true;
if (set_config('local_version', $local_version)) {
notify(get_string('databasesuccess'), 'notifysuccess');
notify(get_string('databaseupgradelocal', '', $local_version));
+ upgrade_log_finish();
print_continue($continueto);
exit;
} else {
}
} else if ($local_version < $CFG->local_version) {
+ upgrade_log_start();
notify('WARNING!!! The local version you are using is OLDER than the version that made these databases!');
}
+ upgrade_log_finish();
}
/**
for ($i=0;$i<512;$i++) { // Padding to help IE work with 404
echo ' ';
}
+
+ // clean upgrade indicator if needed; buffer and log file will be closed automatically
+ if (!empty($_SESSION['upgraderunning'])) {
+ $_SESSION['upgraderunning'] = 0;
+ }
+
die;
}
continue;
}
+ upgrade_log_start();
$db->debug=true;
if (!modify_database($fullpath .'/db/'.$CFG->dbtype.'.sql')) {
notify("Error installing tables for submodule '$type'!");
$upgrade_function = 'assignment_'.$type.'_upgrade';
if (function_exists($upgrade_function)) {
+ upgrade_log_start();
$db->debug=true;
if ($upgrade_function($CFG->$currentversion)) {
$db->debug=false;