$plugin = "auth/$auth";
$name = $matches[1];
if (!set_config($name, $value, $plugin)) {
- print_error("cannotsaveconfig", 'error', '', array($name, $value, $plugin));
+ print_error("cannotsaveconfig", 'error', '', (object)array('name'=>$name, 'value'=>$value, 'plugin'=>$plugin));
}
}
}
$DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml"); //New method
- // all new installs are in unicode - keep for backwards compatibility and 1.8 upgrade checks
- set_config('unicodedb', 1);
-
/// Continue with the instalation
// Install the roles system.
if ($CFG->version) {
if ($version > $CFG->version) { // upgrade
- /// If the database is not already Unicode then we do not allow upgrading!
- /// Instead, we print an error telling them to upgrade to 1.7 first. MDL-6857
- if (empty($CFG->unicodedb)) {
- console_write(STDERR,'unicodeupgradeerror', 'error');
- }
-
$a->oldversion = "$CFG->release ($CFG->version)";
$a->newversion = "$release ($version)";
$strdatabasechecking = get_string("databasechecking", "", $a);
die;
}
-/// Turn off time limits and try to flush everything all the time, sometimes upgrades can be slow.
-
- @set_time_limit(0);
+/// try to flush everything all the time
@ob_implicit_flush(true);
while(@ob_end_clean()); // ob_end_flush prevents sending of headers
- require_once('../config.php');
- require_once($CFG->libdir.'/adminlib.php'); // Contains various admin-only functions
- require_once($CFG->libdir.'/db/upgradelib.php'); // Upgrade-related functions
+ require('../config.php');
+ require_once($CFG->libdir.'/adminlib.php'); // Contains various admin-only functions
$id = optional_param('id', '', PARAM_TEXT);
$confirmupgrade = optional_param('confirmupgrade', 0, PARAM_BOOL);
$confirmrelease = optional_param('confirmrelease', 0, PARAM_BOOL);
+ $confirmplugins = optional_param('confirmplugincheck', 0, PARAM_BOOL);
$agreelicense = optional_param('agreelicense', 0, PARAM_BOOL);
$autopilot = optional_param('autopilot', 0, PARAM_BOOL);
- $ignoreupgradewarning = optional_param('ignoreupgradewarning', 0, PARAM_BOOL);
- $confirmplugincheck = optional_param('confirmplugincheck', 0, PARAM_BOOL);
-
-/// check upgrade status first
- if ($ignoreupgradewarning) {
- $SESSION->upgraderunning = 0;
- }
- upgrade_check_running("Upgrade already running in this session, please wait!<br />Click on the exclamation marks to ignore this warning (<a href=\"index.php?ignoreupgradewarning=1\">!!!</a>).", 10);
/// set install/upgrade autocontinue session flag
if ($autopilot) {
$documentationlink = '<a href="http://docs.moodle.org/en/Installation">Installation docs</a>';
if (ini_get_bool('session.auto_start')) {
- print_error('phpvaroff', 'debug', '', array('session.auto_start', $documentationlink));
+ print_error('phpvaroff', 'debug', '', (object)array('name'=>'session.auto_start', 'link'=>$documentationlink));
}
if (ini_get_bool('magic_quotes_runtime')) {
- print_error('phpvaroff', 'debug', '', array('magic_quotes_runtime', $documentationlink));
+ print_error('phpvaroff', 'debug', '', (object)array('name'=>'magic_quotes_runtime', 'link'=>$documentationlink));
}
if (!ini_get_bool('file_uploads')) {
- print_error('phpvaron', 'debug', '', array('file_uploads', $documentationlink));
+ print_error('phpvaron', 'debug', '', (object)array('name'=>'file_uploads', 'link'=>$documentationlink));
}
/// Check that config.php has been edited
$dirroot = dirname(realpath("../index.php"));
if (!empty($dirroot) and $dirroot != $CFG->dirroot) {
- print_error('fixsetting', 'debug', '', array($CFG->dirroot, $dirroot));
+ print_error('fixsetting', 'debug', '', (object)array('current'=>$CFG->dirroot, 'found'=>$dirroot));
}
/// Set some necessary variables during set-up to avoid PHP warnings later on this page
$CFG->version = "";
}
- if (is_readable("$CFG->dirroot/version.php")) {
- include_once("$CFG->dirroot/version.php"); // defines $version
- }
+ $version = null;
+ $release = null;
+ include("$CFG->dirroot/version.php"); // defines $version and $release
if (!$version or !$release) {
print_error('withoutversion', 'debug'); // without version, stop
} else { // Check for missing main tables
$maintables = true;
- $mtables = array("config", "course", "course_categories", "course_modules",
- "course_sections", "log", "log_display", "modules",
- "user");
+ $mtables = array('config', 'course', 'groupings'); // some tables used in 1.9 and 2.0, preferable something from the start and end of install.xml
foreach ($mtables as $mtable) {
if (!in_array($mtable, $tables)) {
$maintables = false;
}
}
}
+ unset($mtables);
+ unset($tables);
- if (! $maintables) {
+ if (!$maintables) {
/// hide errors from headers in case debug enabled in config.php
$origdebug = $CFG->debug;
$CFG->debug = DEBUG_MINIMAL;
upgrade_log_start();
$DB->set_debug(true);
- /// Both old .sql files and new install.xml are supported
- /// But we prioritise install.xml (XMLDB) if present
-
if (!$DB->setup_is_unicodedb()) {
if (!$DB->change_db_encoding()) {
// If could not convert successfully, throw error, and prevent installation
}
}
- $DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml"); //New method
-
- // all new installs are in unicode - keep for backwards compatibility and 1.8 upgrade checks
- set_config('unicodedb', 1);
+ $DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml");
/// Continue with the instalation
- $DB->set_debug(false);
-
- /// Groups install is now in core above.
// Install the roles system.
moodle_install_roles();
events_update_definition();
// Install core message providers
- require_once($CFG->libdir .'/messagelib.php'); // Messagelib functions
message_update_providers();
/// This is used to handle any settings that must exist in $CFG but which do not exist in
// (this should only have any effect during initial install).
admin_apply_default_settings(NULL, true);
- notify($strdatabasesuccess, "green");
+ // store main version
+ if (!set_config('version', $version)) {
+ print_error('cannotupdateversion', 'debug');
+ }
+
+ notify($strdatabasesuccess, 'notifysuccess');
+
+ /// do not show certificates in log ;-)
+ $DB->set_debug(false);
+
+ // hack - set up mnet
require_once $CFG->dirroot.'/mnet/lib.php';
print_continue('index.php');
print_footer('none');
+
die;
}
/// Check version of Moodle code on disk compared with database
/// and upgrade if possible.
- require_once("$CFG->dirroot/lib/db/upgrade.php"); # defines new upgrades
- $stradministration = get_string("administration");
+ $stradministration = get_string('administration');
- if ($CFG->version) {
- if ($version > $CFG->version) { // upgrade
+ if (empty($CFG->version)) {
+ print_error('missingconfigversion', 'debug');
+ }
- /// If the database is not already Unicode then we do not allow upgrading!
- /// Instead, we print an error telling them to upgrade to 1.7 first. MDL-6857
- if (empty($CFG->unicodedb)) {
- print_error('unicodeupgradeerror', 'error', '', $version);
- }
+ if ($version > $CFG->version) { // upgrade
- $a->oldversion = "$CFG->release ($CFG->version)";
- $a->newversion = "$release ($version)";
- $strdatabasechecking = get_string("databasechecking", "", $a);
+ require_once($CFG->libdir.'/db/upgrade.php'); // Defines upgrades
+ require_once($CFG->libdir.'/db/upgradelib.php'); // Upgrade-related functions
- // hide errors from headers in case debug is enabled
- $origdebug = $CFG->debug;
- $CFG->debug = DEBUG_MINIMAL;
- error_reporting($CFG->debug);
+ $a->oldversion = "$CFG->release ($CFG->version)";
+ $a->newversion = "$release ($version)";
+ $strdatabasechecking = get_string("databasechecking", "", $a);
- // 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
- if ($CFG->version < 2007101500) {
- require_logout();
- }
+ // hide errors from headers in case debug is enabled
+ $origdebug = $CFG->debug;
+ $CFG->debug = DEBUG_MINIMAL;
+ error_reporting($CFG->debug);
- if (empty($confirmupgrade)) {
- $navigation = build_navigation(array(array('name'=>$strdatabasechecking, 'link'=>null, 'type'=>'misc')));
- print_header($strdatabasechecking, $stradministration, $navigation,
- "", "", 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
+ if ($CFG->version < 2007101500) {
+ require_logout();
+ }
- notice_yesno(get_string('upgradesure', 'admin', $a->newversion), 'index.php?confirmupgrade=1', 'index.php');
- print_footer('none');
- exit;
-
- } else if (empty($confirmrelease)){
- $strcurrentrelease = get_string("currentrelease");
- $navigation = build_navigation(array(array('name'=>$strcurrentrelease, 'link'=>null, 'type'=>'misc')));
- print_header($strcurrentrelease, $strcurrentrelease, $navigation, "", "", false, " ", " ");
- print_heading("Moodle $release");
- print_box(get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/en/Release_Notes'));
-
- require_once($CFG->libdir.'/environmentlib.php');
- print_heading(get_string('environment', 'admin'));
- if (!check_moodle_environment($release, $environment_results, true)) {
- print_box_start('generalbox', 'notice'); // MDL-8330
- print_string('langpackwillbeupdated', 'admin');
- print_box_end();
- notice_yesno(get_string('environmenterrorupgrade', 'admin'),
- 'index.php?confirmupgrade=1&confirmrelease=1', 'index.php');
- } else {
- notify(get_string('environmentok', 'admin'), 'notifysuccess');
- print_box_start('generalbox', 'notice'); // MDL-8330
- print_string('langpackwillbeupdated', 'admin');
- print_box_end();
- echo '<form action="index.php"><div>';
- echo '<input type="hidden" name="confirmupgrade" value="1" />';
- echo '<input type="hidden" name="confirmrelease" value="1" />';
- echo '</div>';
- echo '<div class="continuebutton">';
- echo '<br /><br /><input type="submit" value="'.get_string('continue').'" /></div>';
- echo '</form>';
- }
+ if (empty($confirmupgrade)) {
+ $navigation = build_navigation(array(array('name'=>$strdatabasechecking, 'link'=>null, 'type'=>'misc')));
+ print_header($strdatabasechecking, $stradministration, $navigation,
+ "", "", false, " ", " ");
- print_footer('none');
- die;
- } elseif (empty($confirmplugincheck)) {
- $strplugincheck = get_string('plugincheck');
- $navigation = build_navigation(array(array('name'=>$strplugincheck, 'link'=>null, 'type'=>'misc')));
- print_header($strplugincheck, $strplugincheck, $navigation, "", "", false, " ", " ");
- print_heading($strplugincheck);
+ notice_yesno(get_string('upgradesure', 'admin', $a->newversion), 'index.php?confirmupgrade=1', 'index.php');
+ print_footer('none');
+ exit;
+
+ } else if (empty($confirmrelease)){
+ $strcurrentrelease = get_string("currentrelease");
+ $navigation = build_navigation(array(array('name'=>$strcurrentrelease, 'link'=>null, 'type'=>'misc')));
+ print_header($strcurrentrelease, $strcurrentrelease, $navigation, "", "", false, " ", " ");
+ print_heading("Moodle $release");
+ print_box(get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/en/Release_Notes'));
+
+ require_once($CFG->libdir.'/environmentlib.php');
+ print_heading(get_string('environment', 'admin'));
+ if (!check_moodle_environment($release, $environment_results, true)) {
print_box_start('generalbox', 'notice'); // MDL-8330
- print_string('pluginchecknotice');
+ print_string('langpackwillbeupdated', 'admin');
+ print_box_end();
+ notice_yesno(get_string('environmenterrorupgrade', 'admin'),
+ 'index.php?confirmupgrade=1&confirmrelease=1', 'index.php');
+ } else {
+ notify(get_string('environmentok', 'admin'), 'notifysuccess');
+ print_box_start('generalbox', 'notice'); // MDL-8330
+ print_string('langpackwillbeupdated', 'admin');
print_box_end();
- print_plugin_tables();
- echo "<br />";
- echo '<div class="continuebutton">';
- print_single_button('index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1), get_string('reload'), 'get');
- echo '</div><br />';
echo '<form action="index.php"><div>';
echo '<input type="hidden" name="confirmupgrade" value="1" />';
echo '<input type="hidden" name="confirmrelease" value="1" />';
- echo '<input type="hidden" name="confirmplugincheck" value="1" />';
echo '</div>';
- echo '<div class="continuebutton"><input name="autopilot" id="autopilot" type="checkbox" value="1" /><label for="autopilot">'.get_string('unattendedoperation', 'admin').'</label>';
+ echo '<div class="continuebutton">';
echo '<br /><br /><input type="submit" value="'.get_string('continue').'" /></div>';
echo '</form>';
- print_footer('none');
- die();
+ }
- } 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, " ", " ");
+ print_footer('none');
+ die;
+ } elseif (empty($confirmplugins)) {
+ $strplugincheck = get_string('plugincheck');
+ $navigation = build_navigation(array(array('name'=>$strplugincheck, 'link'=>null, 'type'=>'misc')));
+ print_header($strplugincheck, $strplugincheck, $navigation, "", "", false, " ", " ");
+ print_heading($strplugincheck);
+ print_box_start('generalbox', 'notice'); // MDL-8330
+ print_string('pluginchecknotice');
+ print_box_end();
+ print_plugin_tables();
+ echo "<br />";
+ echo '<div class="continuebutton">';
+ print_single_button('index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1), get_string('reload'), 'get');
+ echo '</div><br />';
+ echo '<form action="index.php"><div>';
+ echo '<input type="hidden" name="confirmupgrade" value="1" />';
+ echo '<input type="hidden" name="confirmrelease" value="1" />';
+ echo '<input type="hidden" name="confirmplugincheck" value="1" />';
+ echo '</div>';
+ echo '<div class="continuebutton"><input name="autopilot" id="autopilot" type="checkbox" value="1" /><label for="autopilot">'.get_string('unattendedoperation', 'admin').'</label>';
+ echo '<br /><br /><input type="submit" value="'.get_string('continue').'" /></div>';
+ echo '</form>';
+ print_footer('none');
+ die();
- /// return to original debugging level
- $CFG->debug = $origdebug;
- error_reporting($CFG->debug);
- upgrade_log_start();
+ } else {
- /// Upgrade current language pack if we can
- upgrade_language_pack();
+ $strdatabasesuccess = get_string("databasesuccess");
+ $navigation = build_navigation(array(array('name'=>$strdatabasesuccess, 'link'=>null, 'type'=>'misc')));
+ print_header($strdatabasechecking, $stradministration, $navigation,
+ "", upgrade_get_javascript(), false, " ", " ");
- print_heading($strdatabasechecking);
- $DB->set_debug(true);
- /// Launch the old main upgrade (if exists)
- $status = true;
- if (function_exists('main_upgrade')) {
- $status = main_upgrade($CFG->version);
- }
- /// If succesful and exists launch the new main upgrade (XMLDB), called xmldb_main_upgrade
- if ($status && function_exists('xmldb_main_upgrade')) {
- $status = xmldb_main_upgrade($CFG->version);
+ /// return to original debugging level
+ $CFG->debug = $origdebug;
+ error_reporting($CFG->debug);
+ upgrade_log_start();
+
+ /// Upgrade current language pack if we can
+ upgrade_language_pack();
+
+ print_heading($strdatabasechecking);
+ $DB->set_debug(true);
+ /// Launch the old main upgrade (if exists)
+ $status = true;
+ if (function_exists('main_upgrade')) {
+ $status = main_upgrade($CFG->version);
+ }
+ /// If succesful and exists launch the new main upgrade (XMLDB), called xmldb_main_upgrade
+ if ($status && function_exists('xmldb_main_upgrade')) {
+ $status = xmldb_main_upgrade($CFG->version);
+ }
+ $DB->set_debug(false);
+ /// If successful, continue upgrading roles and setting everything properly
+ if ($status) {
+ if (!update_capabilities()) {
+ print_error('cannotupgradecapabilities', 'debug');
}
- $DB->set_debug(false);
- /// If successful, continue upgrading roles and setting everything properly
- if ($status) {
- if (!update_capabilities()) {
- print_error('cannotupgradecapabilities', 'debug');
- }
-
- // Update core events
- events_update_definition();
-
- // Update core message providers
- require_once($CFG->libdir .'/messagelib.php'); // Messagelib functions
- message_update_providers();
-
- 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');
- }
- /// Main upgrade not success
- } else {
- notify('Main Upgrade failed! See lib/db/upgrade.php');
- print_continue('index.php?confirmupgrade=1&confirmrelease=1&confirmplugincheck=1');
+
+ // Update core events
+ events_update_definition();
+
+ // Update core message providers
+ message_update_providers();
+
+ if (set_config("version", $version)) {
+ remove_dir($CFG->dataroot . '/cache', true); // flush cache
+ notify($strdatabasesuccess, "green");
+ print_continue("upgradesettings.php");
print_footer('none');
- die;
+ exit;
+ } else {
+ print_error('cannotupdateversion', 'debug');
}
- upgrade_log_finish();
+ /// Main upgrade not success
+ } else {
+ notify('Main Upgrade failed! See lib/db/upgrade.php');
+ print_continue('index.php?confirmupgrade=1&confirmrelease=1&confirmplugincheck=1');
+ print_footer('none');
+ die;
}
- } else if ($version < $CFG->version) {
- upgrade_log_start();
- notify("WARNING!!! The code you are using is OLDER than the version that made these databases!");
upgrade_log_finish();
}
- } else {
- if (!set_config("version", $version)) {
- print_error('cannotupdateversion', 'debug');
- }
+ } else if ($version < $CFG->version) {
+ upgrade_log_start();
+ notify("WARNING!!! The code you are using is OLDER than the version that made these databases!");
+ upgrade_log_finish();
}
/// Updated human-readable release version if necessary
}
}
-/// Groups install/upgrade is now in core above.
-
-
/// Find and check all main modules and load them up or upgrade them if necessary
/// first old *.php update and then the new upgrade.php script
upgrade_activity_modules("$CFG->wwwroot/$CFG->admin/index.php"); // Return here afterwards
if ($location || $plugin) {
// file in an extra location
if ($currentfile != "{$prefix}{$plugin}.php") {
- print_error('filemismatch', 'error', '', array($currectfile, $prefix, $plugin));
+ print_error('filemismatch', 'error', '', (object)array('current'=>$currectfile, 'file'=>$prefix.$plugin.'.php'));
}
if (!$uselocal) {
notify($streditingnoncorelangfile);
} else {
// file in standard location
if ($currentfile != $filename) {
- print_error('filemismatch', 'error', '', array($currectfile, $filename, ''));
+ print_error('filemismatch', 'error', '', (object)array('current'=>$currectfile, 'file'=>$filename.'.php'));
}
}
if (lang_save_file($saveinto, $currentfile, $newstrings, $uselocal, $packstring)) {
notify(get_string("changessaved")." ($saveinto/$currentfile)", "notifysuccess");
} else {
- print_error('cannotsavefile', 'error', 'lang.php?mode=compare&currentfile=$currentfile', array($saveinto, $currentfile));
+ print_error('cannotsavefile', 'error', 'lang.php?mode=compare&currentfile=$currentfile', $saveinto.'/'.$currentfile);
}
unset($packstring);
}
// Completion system
require_once($CFG->libdir.'/completionlib.php');
- $temp->add(new admin_setting_configcheckbox('enablecompletion',get_string('enablecompletion','completion'),get_string('configenablecompletion','completion'),COMPLETION_DISABLED));
- $temp->add(new admin_setting_pickroles('progresstrackedroles',get_string('progresstrackedroles','completion'),get_string('configprogresstrackedroles','completion')));
+ $temp->add(new admin_setting_configcheckbox('enablecompletion', get_string('enablecompletion','completion'), get_string('configenablecompletion','completion'), COMPLETION_DISABLED));
+ $temp->add(new admin_setting_pickroles('progresstrackedroles', get_string('progresstrackedroles','completion'), get_string('configprogresstrackedroles', 'completion'), array('moodle/legacy:student')));
$ADMIN->add('misc', $temp);
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_backup_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_backup_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_block_activity_modules_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_block_activity_modules_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_block_admin_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_block_admin_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_block_calendar_month_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_block_calendar_month_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_block_calendar_upcoming_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_block_calendar_upcoming_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_block_course_list_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_block_course_list_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_block_course_summary_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_block_course_summary_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_blocks_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_blocks_upgrade($oldversion) {
+ global $CFG, $DB;
$dbman = $DB->get_manager();
-
$result = true;
/// And upgrade begins here. For each one, you'll need one
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_block_news_items_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_block_news_items_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_block_online_users_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_block_online_users_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_block_participants_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_block_participants_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_block_recent_activity_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_block_recent_activity_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_block_rss_client_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_block_rss_client_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
if(isset($CFG->block_search_pdf_to_text_cmd)) {
p($CFG->block_search_pdf_to_text_cmd);
} else {
- $encoding = ($CFG->unicodedb) ? "-enc UTF-8" : "-enc ISO-8859-1" ;
if ($CFG->ostype == 'WINDOWS'){
- p("lib/xpdf/win32/pdftotext.exe -eol dos $encoding -q");
+ p("lib/xpdf/win32/pdftotext.exe -eol dos -enc UTF-8 -q");
}
else{
- p("lib/xpdf/linux/pdftotext $encoding -eol unix -q");
+ p("lib/xpdf/linux/pdftotext -enc UTF-8 -eol unix -q");
}
} ?>"/><br/><br/>
</td>
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_block_search_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_block_search_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_block_search_forums_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_block_search_forums_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_block_section_links_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_block_section_links_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_block_social_activities_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_block_social_activities_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
The function must look like:
- function xmldb_format_yourformat_upgrade($oldversion=0) {
+ function xmldb_format_yourformat_upgrade($oldversion) {
...
* yourformat/version.php
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_enrol_authorize_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_enrol_authorize_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
//===== 1.9.0 upgrade line ======//
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_enrol_paypal_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_enrol_paypal_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
Once you do this you can not go back again. <br /><br />
Please note that this process can take a long time. <br /><br />
Are you sure you want to upgrade this server to this version?';
+$string['upgradetimedout'] = 'Upgrade timed out, please restart the upgrade.';
$string['upgradingdata'] = 'Upgrading data';
$string['upgradinglogs'] = 'Upgrading logs';
$string['uploaduserspreview'] = 'Upload users preview';
$string['cannotadd'] = 'Can not add entries!';
$string['cannotdeletepreset'] = 'Error deleting a preset!';
$string['cannotrate'] = 'Rating of items not allowed!';
-$string['cannotupdaterate'] = 'Could not update an old rating ($a[0] = $a[1])';
$string['cannotunziptopreset'] = 'Cannot unzip to the preset directory';
-$string['cannotinsertrate'] = 'Could not insert a new rating ($a[0] = $a[1])';
$string['cannotinsertempty'] = 'Could not make an empty record!';
$string['cancel'] = 'Cancel';
$string['checkbox'] = 'Checkbox';
* debug information for developer only
*/
$string['authpluginnotfound'] = 'Authentication plugin $a not found.';
+$string['blocknotexist'] = '$a block doesn\'t exist';
$string['cannotbenull'] = '$a cannot be null!';
$string['cannotcreateadminuser'] = 'SERIOUS ERROR: Could not create admin user record !!!';
-$string['cannotdowngrade'] = 'Cannot downgrade from $a[0] to $a[1].';
-$string['cannotinitpage'] = 'Cannot fully initialize page: invalid $a[0] id $a[1]';
+$string['cannotdowngrade'] = 'Cannot downgrade from $a->oldversion to $a->newversion.';
+$string['cannotinitpage'] = 'Cannot fully initialize page: invalid $a->name id $a->id';
$string['cannotupgradecapabilities'] = 'Had trouble upgrading the core capabilities for the Roles System';
$string['cannotupdateversion'] = 'Upgrade failed! (Could not update version in config table)';
$string['cannotupdaterelease'] = 'ERROR: Could not update release version in database!!';
$string['dbnotsetup'] = 'Error: Main databases NOT set up successfully';
$string['doesnotworkwitholdversion'] = 'This script does not work with this old version of Moodle';
$string['erroroccur'] = 'An error has occurred during this process';
-$string['fixsetting'] = 'Please fix your settings in config.php: <p>You have:</p> <p>\$CFG->dirroot = \"$a[0]\";</p> <p>but it should be:</p> <p>\$CFG->dirroot = \"$a[1]\"</p>';
+$string['fixsetting'] = 'Please fix your settings in config.php: <p>You have:</p> <p>\$CFG->dirroot = \"$a->current\";</p> <p>but it should be:</p> <p>\$CFG->dirroot = \"$a->found\"</p>';
$string['invalideventdata'] = 'Incorrect eventadata submitted: $a';
$string['invalidarraysize'] = 'Incorrect size of arrays in params of $a';
+$string['missingconfigversion'] = 'Config table does not contain version, can not continue, sorry.';
$string['mustbeoveride'] = 'Abstract $a method must be overriden.';
$string['morethanonerecordinfetch'] = 'Found more than one record in fetch() !';
$string['noadminrole'] = 'No admin role could be found';
$string['noreports'] = 'No reports accessible';
$string['nomodules'] = 'No modules found!!';
$string['modulenotexist'] = '$a module doesn\'t exist';
-$string['phpvaroff'] = 'The PHP server variable \'$a[0]\' should be Off - $a[1]';
-$string['phpvaron'] = 'The PHP server variable \'$a[0]\' is not turned On - $a[1]';
-$string['prefixcannotbeempty'] = 'Table prefix \"$a[0]\" cannot be empty for your target DB ($a[1])'; // obsoleted 2.0
-$string['prefixlimit'] = 'Table prefix \"$a\" maximum allowed length for Oracle DBs is 2cc.'; // obsoleted in 2.0
-$string['withoutversion'] = 'Main version.php was not readable or specified';
+$string['phpvaroff'] = 'The PHP server variable \'$a->name\' should be Off - $a->link';
+$string['phpvaron'] = 'The PHP server variable \'$a->name\' is not turned On - $a->link';
$string['sessionmissing'] = '$a object missing from session';
$string['siteisnotdefined'] = 'Site is not defined!';
$string['sqlrelyonobsoletetable'] = 'This SQL relies on obsolete table(s): $a! Your code must be fixed by a developer.';
$string['upgradefail'] = 'Upgrade failed! see: $a';
-$string['withoutversion'] = 'Main version.php was not readable or specified';
+$string['withoutversion'] = 'Main version.php file is missing, not readable or broken.';
$string['xmlizeunavailable'] = 'xmlize functions are not available';
?>
$string['blockcannotinistantiate'] = 'Problem in instantiating block object';
$string['blockcannotread'] = 'Could not read data for blockid= $a ';
$string['blockcannotconfig'] = 'This block does not support global configuration';
-$string['blocknameconflict'] = 'Naming conflict: block $a[0] has the same title with an existing block: $a[1]!';
+$string['blocknameconflict'] = 'Naming conflict: block $a->name has the same title with an existing block: $a->conflict!';
$string['backupcontainexternal'] = 'This backup file contains external Moodle Network Hosts that are not configured locally';
$string['backuptablefail'] = 'Backup tables could NOT be set up successfully!';
-$string['boundsyntaxnotsupport'] = 'Pg $1, $2 bound syntax not supported yet :-(';
+$string['boundsyntaxnotsupport'] = 'Pg \$1, \$2 bound syntax not supported yet :-(';
$string['cannotassignanthing'] = 'Cannot assign moodle/site:doanything';
$string['cannotassignrole'] = 'Cannot assign role in course';
$string['cannotassignselfasparent'] = 'Cannot assign self as parent!';
$string['cannotaddmodule'] = '$a module could not be added to the module list!';
$string['cannotaddnewmodule'] = 'Could not add a new module of $a';
$string['cannotaddnewinstance'] = 'Could not add a new instance of $a';
-$string['cannotsaveconfig'] = 'Problem saving config \"$a[0]\" as \"$a[1]\" for plugin \"$a[2]\"';
+$string['cannotsaveconfig'] = 'Problem saving config \"$a->name\" as \"$a=>value\" for plugin \"$a->plugin\"';
$string['cannotsavecomment'] = 'Cannot save comment';
-$string['cannotsavefile'] = 'Cannot save the file\"$a[0]\/$a[1]\"!';
+$string['cannotsavefile'] = 'Cannot save the file \"$a\"!';
$string['cannotsavedata'] = 'Cannot save data';
$string['cannotsaveagreement'] = 'Could not save your agreement';
$string['cannotcallscript'] = 'You cannot call this script in that way';
$string['cannotresetmail'] = 'Error resetting password and mailing you';
$string['cannotsaveblock'] = 'Error saving block configuration';
$string['cannotsavefile'] = 'Cannot save the file \"$a\"';
-$string['cannotinitpage'] = 'Cannot quickly initialize page, course id: $a';
$string['cannotinsertcategory'] = 'Weird error. The category was not inserted.';
$string['cannotinsertcomment'] = 'Could not insert this new comment';
$string['cannotinsertgrade'] = 'Cannot insert grade item without course id!';
$string['cannotinsertrecord'] = 'Could not insert new record ID $a';
-$string['cannotinsertrate'] = 'Could not insert a new rating ($a[0] = $a[1])';
+$string['cannotinsertrate'] = 'Could not insert a new rating ($a->id = $a->rating)';
$string['cannotinsertkey'] = 'Cannot insert new key';
$string['cannotsavecomment'] = 'Error while saving comment';
$string['cannotsavemd5file'] = 'Cannot save md5 file';
$string['cannotupdatefield'] = 'Error updating field';
$string['cannotupdatelevel'] = 'Could not update the indent level on that course module';
$string['cannotupdategroup'] = 'Error updating group';
+$string['cannotupdaterate'] = 'Could not update an old rating ($a->id = $a->rating)';
$string['cannotupdaterecord'] = 'Could not update record ID $a';
$string['cannotupdaterole'] = 'Cannot update role!';
$string['cannotupdatemod'] = 'Could not update $a';
$string['cannotuseadmin'] = 'You need to be an admin user to use this page';
$string['cannotuseadminadminorteacher'] = 'You need to be a teacher or admin user to use this page';
$string['cannotunassignrolefrom'] = 'Cannot unassign this user from role id: $a';
-$string['cannotunassigncap'] = 'Could not unassign deprecated capability $a[0] from role $a[1]';
+$string['cannotunassigncap'] = 'Could not unassign deprecated capability $a->cap from role $a->role';
$string['cannotrestoreadminorcreator'] = 'You need to be a creator or admin user to restore into new course!';
$string['cannotrestoreadminoredit'] = 'You need to be a editing teacher or admin user to restore into selected course!';
$string['cannotusepage'] = 'Only teachers and administrators can use this page';
$string['failtoloadblocks'] = 'One or more blocks are registered in the database, but they all failed to load!';
$string['fieldrequired'] = '\"$a\" is a required field';
$string['filenotfound'] = 'Sorry, the requested file could not be found';
-$string['filemismatch'] = 'Non-core file name mismatch. The file \"$a[0]\" should be {$a[1]}{$a[2]}.php';
+$string['filemismatch'] = 'Non-core file name mismatch. The file \"$a->current\" should be $a->file';
$string['filternotinstalled'] = 'Filter $a is not currently installed';
$string['filternotactive'] = 'Filter $a is not currently active';
$string['forumblockingtoomanyposts'] = 'You have exceeded the posting threshold set for this forum';
$string['updatersserror'] = 'There was an error trying to update RSS feed with id: $a';
$string['upgradeversionfail'] = 'Upgrade of backup system failed! (Could not update version in config table.)';
$string['upgradefail'] = 'Upgrade failed! $a';
+$string['upgraderunning'] = 'Site is being upgraded, please retry later.';
$string['younotteacher'] = 'You are not a teacher!';
$string['wrongcall'] = 'This script is called wrongly';
$string['wrongcontextid'] = 'Context ID was incorrect (cannot find it)';
$string['cannotremovesubscriber'] = 'Could not remove subscriber with id $a from this forum!';
$string['cannotfindorcreateforum'] = 'Could not find or create a main news forum for the site';
$string['cannotfindfirstpost'] = 'Could not find the first post in this forum';
-$string['cannotupdaterate'] = 'Could not update an old rating ($a[0] = $a[1])';
-$string['cannotinsertrate'] = 'Could not insert a new rating ($a[0] = $a[1])';
$string['cannottrack'] = 'Could not stop tracking that forum';
$string['cleanreadtime'] = 'Mark old posts as read hour';
$string['completiondiscussions'] = 'User must create discussions:';
if ($roles = get_roles_with_capability($cachedcap->name)) {
foreach($roles as $role) {
if (!unassign_capability($cachedcap->name, $role->id)) {
- print_error('cannotunassigncap', '', '', array($cachedcap->name, $role->name));
+ print_error('cannotunassigncap', 'error', '', (object)array('cap'=>$cachedcap->name, 'role'=>$role->name));
}
}
}
require_once($CFG->libdir.'/xmlize.php');
require_once($CFG->libdir .'/messagelib.php'); // Messagelib functions
+global $upgradeloghandle, $upgradelogbuffer;
+
+$upgradeloghandle = false;
+$upgradelogbuffer = '';
+
+
+/**
+ * Upgrade savepoint, marks end of each upgrade block.
+ * It stores new main version, resets upgrade timeout
+ * and abort upgrade if user cancels page loading.
+ *
+ * Please do not make large upgrade blocks with lots of operations,
+ * for example when adding tables keep only one table operation per block.
+ *
+ * @param bool $result false if upgrade step failed, true if completed
+ * @param string or float $version main version
+ * @return void
+ */
function upgrade_main_savepoint($result, $version) {
global $CFG;
if ($result) {
if ($CFG->version >= $version) {
// something really wrong is going on in main upgrade script
- print_error('cannotdowngrade', 'debug', '', array($CFG->version, $version));
+ print_error('cannotdowngrade', 'debug', '', (object)array('oldversion'=>$CFG->version, 'newversion'=>$version));
}
set_config('version', $version);
} else {
notify ("Upgrade savepoint: Error during main upgrade to version $version");
}
+
+ // reset upgrade timeout to default
+ upgrade_set_timeout();
+
+ // this is a safe place to stop upgrades if user aborts page loading
+ if (connection_aborted()) {
+ die;
+ }
}
+/**
+ * Module upgrade savepoint, marks end of module upgrade blocks
+ * It stores module version, resets upgrade timeout
+ * and abort upgrade if usercancels page loading.
+ *
+ * @param bool $result false if upgrade step failed, true if completed
+ * @param string or float $version main version
+ * @return void
+ */
function upgrade_mod_savepoint($result, $version, $modname) {
global $DB;
if ($result) {
if ($module->version >= $version) {
// something really wrong is going on in upgrade script
- print_error('cannotdowngrade', 'debug', '', array($module->version, $version));
+ print_error('cannotdowngrade', 'debug', '', (object)array('oldversion'=>$module->version, 'newversion'=>$version));
}
$module->verions = $version;
$DB->update_record('modules', $module);
} else {
notify ("Upgrade savepoint: Error during mod upgrade to version $version");
}
+
+ // reset upgrade timeout to default
+ upgrade_set_timeout();
+
+ // this is a safe place to stop upgrades if user aborts page loading
+ if (connection_aborted()) {
+ die;
+ }
+}
+
+function upgrade_blocks_savepoint($result, $version, $blockname) {
+ global $DB;
+
+ if (!$block = $DB->get_record('block', array('name'=>$blockname))) {
+ print_error('blocknotexist', 'debug', '', $blockname);
+ }
+
+ if ($result) {
+ if ($block->version >= $version) {
+ // something really wrong is going on in upgrade script
+ print_error('cannotdowngrade', 'debug', '', (object)array('oldversion'=>$block->version, 'newversion'=>$version));
+ }
+ $block->verions = $version;
+ $DB->update_record('block', $block);
+ } else {
+ notify ("Upgrade savepoint: Error during mod upgrade to version $version");
+ }
+
+ // reset upgrade timeout to default
+ upgrade_set_timeout();
+
+ // this is a safe place to stop upgrades if user aborts page loading
+ if (connection_aborted()) {
+ die;
+ }
}
function upgrade_plugin_savepoint($result, $version, $type, $dir) {
//TODO
}
-function upgrade_blocks_savepoint($result, $version, $type) {
- //TODO
-}
-
/**
* Delete all plugin tables
* @name string name of plugin, used as table prefix
}
} else {
upgrade_log_start();
- print_error('cannotdowngrade', 'debug', '', array($CFG->pluginversion, $plugin->version));
+ print_error('cannotdowngrade', 'debug', '', (object)array('oldversion'=>$CFG->pluginversion, 'newversion'=>$plugin->version));
}
}
if ($updated_plugins && !$embedded) {
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
- print_continue($return);
- print_footer('none');
- die;
+ print_continue($return);
+ print_footer('none');
+ die;
} else if (CLI_UPGRADE && ($interactive > CLI_SEMI )) {
console_write(STDOUT,'askcontinue');
if (read_boolean()){
return ;
- }else {
+ } else {
console_write(STDERR,'','',false);
}
}
remove_dir($CFG->dataroot . '/cache', true); // flush cache
notify(get_string('modulesuccess', '', $module->name), 'notifysuccess');
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE) {
- echo '<hr />';
+ echo '<hr />';
}
} else {
notify('Upgrading '. $module->name .' from '. $currmodule->version .' to '. $module->version .' FAILED!');
} else {
upgrade_log_start();
- print_error('cannotdowngrade', 'debug', '', array($currmodule->version, $module->version));
+ print_error('cannotdowngrade', 'debug', '', (object)array('oldversion'=>$currmodule->version, 'newversion'=>$module->version));
}
} else { // module not installed yet, so install it
if (!$updated_modules) {
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
- print_header($strmodulesetup, $strmodulesetup,
+ print_header($strmodulesetup, $strmodulesetup,
build_navigation(array(array('name' => $strmodulesetup, 'link' => null, 'type' => 'misc'))), '',
upgrade_get_javascript(), false, ' ', ' ');
- }
+ }
}
upgrade_log_start();
print_heading($module->name);
notify(get_string('modulesuccess', '', $module->name), 'notifysuccess');
if (!defined('CLI_UPGRADE')|| !CLI_UPGRADE ) {
- echo '<hr />';
+ echo '<hr />';
}
} else {
print_error('cannotaddmodule', '', '', $module->name);
if ($updated_modules) {
if (!defined('CLI_UPGRADE')|| !CLI_UPGRADE ) {
- print_continue($return);
- print_footer('none');
- die;
+ print_continue($return);
+ print_footer('none');
+ die;
} else if ( CLI_UPGRADE && ($interactive > CLI_SEMI) ) {
console_write(STDOUT,'askcontinue');
if (read_boolean()){
foreach ($adminroles as $adminrole) {
role_assign($adminrole->id, $user->id, 0, $sitecontext->id);
}
-
+
//set default message preferences
if (!message_set_default_message_preferences( $user )){
print_error('cannotsavemessageprefs', 'message');
load_all_capabilities();
if (!defined('CLI_UPGRADE')||!CLI_UPGRADE) {
- redirect("$CFG->wwwroot/user/editadvanced.php?id=$user->id"); // Edit thyself
+ redirect("$CFG->wwwroot/user/editadvanced.php?id=$user->id"); // Edit thyself
}
} else {
print_error('cannotcreateadminuser', 'debug');
/// upgrade logging functions
////////////////////////////////////////////////
-$upgradeloghandle = false;
-$upgradelogbuffer = '';
-// I did not find out how to use static variable in callback function,
-// the problem was that I could not flush the static buffer :-(
-global $upgradeloghandle, $upgradelogbuffer;
-
/**
- * 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
+ * Marks start of upgrade, blocks any other access to site.
+ * The upgrade is finished at the end of script or after timeout.
*/
-function upgrade_check_running($message, $timeout) {
- global $SESSION;
+function start_upgrade() {
+ global $CFG;
- if (!empty($SESSION->upgraderunning)) {
- print_header();
- redirect(me(), $message, $timeout);
+ static $started = false;
+
+ if ($started) {
+ upgrade_set_timeout(120);
+
+ } else {
+ ignore_user_abort(true);
+ register_shutdown_function('upgrade_finished_handler');
+ if ($CFG->version === '') {
+ // db not installed yet
+ $CFG->upgraderunning = time()+300;
+ } else {
+ set_config('upgraderunning', time()+300);
+ }
+ $started = true;
}
}
+/**
+ * Internal function - executed at the very end of each upgrade.
+ */
+function upgrade_finished_handler() {
+ upgrade_log_finish();
+ unset_config('upgraderunning');
+ ignore_user_abort(false);
+}
+
/**
* Start logging of output into file (if not disabled) and
* prevent aborting and concurrent execution of upgrade script.
* This function may be called repeatedly.
*/
function upgrade_log_start() {
- global $CFG, $upgradeloghandle, $SESSION;
+ global $upgradeloghandle;
- if (!empty($SESSION->upgraderunning)) {
- return; // logging already started
- }
+ start_upgrade(); // make sure the upgrade is started
- @ignore_user_abort(true); // ignore if user stops or otherwise aborts page loading
- $SESSION->upgraderunning = 1; // set upgrade indicator
- if (empty($CFG->dbsessions)) { // workaround for bug in adodb, db session can not be restarted
- session_write_close(); // from now on user can reload page - will be displayed warning
+ if ($upgradeloghandle and ($upgradeloghandle !== 'error')) {
+ return;
}
+
make_upload_directory('upgradelogs');
ob_start('upgrade_log_callback', 2); // function for logging to disk; flush each line of text ASAP
- register_shutdown_function('upgrade_log_finish'); // in case somebody forgets to stop logging
}
/**
- * Terminate logging of output, flush all data, allow script aborting
- * and reopen session for writing. Function print_error() does terminate the logging too.
+ * Terminate logging of output, flush all data.
*
* Please make sure that each upgrade_log_start() is properly terminated by
* this function or print_error().
* This function may be called repeatedly.
*/
function upgrade_log_finish() {
- global $CFG, $upgradeloghandle, $upgradelogbuffer, $SESSION;
-
- if (empty($SESSION->upgraderunning)) {
- return; // logging already terminated
- }
+ global $CFG, $upgradeloghandle, $upgradelogbuffer;
@ob_end_flush();
if ($upgradelogbuffer !== '') {
@fclose($upgradeloghandle);
$upgradeloghandle = false;
}
- @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);
}
/**
$data = $adminroot->errors[$fullname]->data;
} else {
$data = $setting->get_setting();
- if (is_null($data)) {
- $data = $setting->get_defaultsetting();
- }
+ // do not use defaults if settings not available - upgrdesettings handles the defaults!
}
$return .= $setting->output_html($data);
}
$default = array();
}
if (is_null($data)) {
- foreach ($default as $value) {
- if ($value) {
- $data[] = $value;
- }
- }
+ $data = array();
}
-
$options = array();
$defaults = array();
foreach($this->choices as $key=>$description) {
* which identify roles that will be enabled by default. Default is the
* student role
*/
- function admin_setting_pickroles($name, $visiblename, $description,$types=array('moodle/legacy:student')) {
+ function admin_setting_pickroles($name, $visiblename, $description, $types) {
parent::admin_setting_configmulticheckbox($name, $visiblename, $description, NULL, NULL);
- $this->types=$types;
+ $this->types = $types;
}
function load_choices() {
function get_defaultsetting() {
global $CFG;
if (empty($CFG->rolesactive)) {
- return array(0);
+ return null;
}
$result = array();
foreach($this->types as $capability) {
if ($caproles = get_roles_with_capability($capability, CAP_ALLOW)) {
foreach ($caproles as $caprole) {
- if(!in_array($caprole->id,$result)) {
+ if (!in_array($caprole->id, $result)) {
$result[] = $caprole->id;
}
}
class admin_setting_special_gradebookroles extends admin_setting_pickroles {
function admin_setting_special_gradebookroles() {
parent::admin_setting_pickroles('gradebookroles', get_string('gradebookroles', 'admin'),
- get_string('configgradebookroles', 'admin'));
+ get_string('configgradebookroles', 'admin'),
+ array('moodle/legacy:student'));
}
}
function admin_setting_special_coursemanager() {
parent::admin_setting_pickroles('coursemanager', get_string('coursemanager', 'admin'),
get_string('configcoursemanager', 'admin'),
- 'moodle/legacy:editingteacher');
+ array('moodle/legacy:editingteacher'));
}
}
$data = $adminroot->errors[$fullname]->data;
} else {
$data = $setting->get_setting();
- if (is_null($data)) {
- $data = $setting->get_defaultsetting();
- }
+ // do not use defaults if settings not available - upgrdesettings handles the defaults!
}
$return .= $setting->output_html($data, $query);
}
parent::admin_setting('managerepository', get_string('managerepository', 'repository'), '', '');
$this->baseurl = $CFG->wwwroot . '/' . $CFG->admin . '/repository.php?sesskey=' . sesskey();
}
-
+
function get_setting() {
return true;
}
}
} else {
upgrade_log_start();
- print_error('cannotdowngrade', 'debug', '', array($currblock->version, $block->version));
+ print_error('cannotdowngrade', 'debug', '', (object)array('oldversion'=>$currblock->version, 'newversion'=>$block->version));
}
} else { // block not installed yet, so install it
if($conflictblock !== false && $conflictblock !== NULL) {
// Duplicate block titles are not allowed, they confuse people
// AND PHP's associative arrays ;)
- if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
- print_error('blocknameconflict', '', '', array($block->name, $conflictblock));
- } else if (CLI_UPGRADE) {
- print_error('blocknameconflict', '', '', array($block->name, $conflictblock));
- }
+ print_error('blocknameconflict', '', '', (object)array('name'=>$block->name, 'conflict'=>$conflictblock));
}
if (empty($updated_blocks)) {
$strblocksetup = get_string('blocksetup');
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-
-function xmldb_main_upgrade($oldversion=0) {
+function xmldb_main_upgrade($oldversion) {
global $CFG, $THEME, $USER, $DB;
$result = true;
////////////////////////////////////////
if ($result && $oldversion < 2008030700) {
+ upgrade_set_timeout(60*20); // this may take a while
/// Define index contextid-lowerboundary (not unique) to be dropped form grade_letters
$table = new xmldb_table('grade_letters');
}
if ($result && $oldversion < 2008050700) {
+ upgrade_set_timeout(60*20); // this may take a while
+
/// Fix minor problem caused by MDL-5482.
require_once($CFG->dirroot . '/question/upgrade.php');
$result = $result && question_fix_random_question_parents();
if ($result && $oldversion < 2008051201) {
notify('Increasing size of user idnumber field, this may take a while...', 'notifysuccess');
+ upgrade_set_timeout(60*20); // this may take a while
/// Under MySQL and Postgres... detect old NULL contents and change them by correct empty string. MDL-14859
if ($CFG->dbfamily == 'mysql' || $CFG->dbfamily == 'postgres') {
}
if ($result && $oldversion < 2008063001) {
+ upgrade_set_timeout(60*20); // this may take a while
+
// table to be modified
$table = new xmldb_table('tag_instance');
// add field
/// Main savepoint reached
upgrade_main_savepoint($result, 2008070701);
}
-
- if ($result && $oldversion < 2008072400) {
- /// Create the database tables for message_processors and message_providers
- $table = new xmldb_table('message_providers');
- $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
- $table->add_field('modulename', XMLDB_TYPE_CHAR, '166', null, XMLDB_NOTNULL, null, null, null, null);
- $table->add_field('modulefile', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
- $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
- $dbman->create_table($table);
+ if ($result && $oldversion < 2008072400) {
+ /// Create the database tables for message_processors
$table = new xmldb_table('message_processors');
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->add_field('name', XMLDB_TYPE_CHAR, '166', null, XMLDB_NOTNULL, null, null, null, null);
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$dbman->create_table($table);
-
- $provider = new object();
- $provider->modulename = 'moodle';
- $provider->modulefile = 'index.php';
- $DB->insert_record('message_providers', $provider);
-
/// delete old and create new fields
$table = new xmldb_table('message');
$field = new xmldb_field('messagetype');
$field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'defaultrole');
/// Launch add field enablecompletion
- if(!$dbman->field_exists($table,$field)) {
+ if (!$dbman->field_exists($table,$field)) {
$dbman->add_field($table, $field);
}
-
+
/// Define field completion to be added to course_modules
$table = new xmldb_table('course_modules');
$field = new xmldb_field('completion');
$field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'groupmembersonly');
/// Launch add field completion
- if(!$dbman->field_exists($table,$field)) {
+ if (!$dbman->field_exists($table,$field)) {
$dbman->add_field($table, $field);
}
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, null, null, 'completion');
/// Launch add field completiongradeitemnumber
- if(!$dbman->field_exists($table,$field)) {
+ if (!$dbman->field_exists($table,$field)) {
$dbman->add_field($table, $field);
}
$field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completiongradeitemnumber');
/// Launch add field completionview
- if(!$dbman->field_exists($table,$field)) {
+ if (!$dbman->field_exists($table,$field)) {
$dbman->add_field($table, $field);
}
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'completionview');
/// Launch add field completionexpected
- if(!$dbman->field_exists($table,$field)) {
+ if (!$dbman->field_exists($table,$field)) {
$dbman->add_field($table, $field);
}
/// Define table course_modules_completion to be created
$table = new xmldb_table('course_modules_completion');
- if(!$dbman->table_exists($table)) {
+ if (!$dbman->table_exists($table)) {
/// Adding fields to table course_modules_completion
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->add_field('completionstate', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
$table->add_field('viewed', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, null, null);
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, null);
-
+
/// Adding keys to table course_modules_completion
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
-
+
/// Adding indexes to table course_modules_completion
$table->add_index('coursemoduleid', XMLDB_INDEX_NOTUNIQUE, array('coursemoduleid'));
$table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid'));
-
+
/// Launch create table for course_modules_completion
$dbman->create_table($table);
}
/// Main savepoint reached
upgrade_main_savepoint($result, 2008072800);
}
-
+
if ($result && $oldversion < 2008073000) {
/// Define table portfolio_log to be created
/// Main savepoint reached
upgrade_main_savepoint($result, 2008080600);
}
+
if ($result && $oldversion < 2008080701) {
/// Define field visible to be added to repository
upgrade_main_savepoint($result, 2008081506);
}
+ if ($result && $oldversion < 2008081600) {
+
+ /// all 1.9 sites and fresh installs must already be unicode, not needed anymore
+ unset_config('unicodedb');
+
+ /// Main savepoint reached
+ upgrade_main_savepoint($result, 2008081600);
+ }
+
return $result;
}
$i = 0;
foreach ($rs as $course) {
$i++;
+ upgrade_set_timeout(60*5); // set up timeout, may also abort execution
$context = get_context_instance(CONTEXT_COURSE, $course->id);
upgrade_migrate_files_course($context, '/', true);
$pbar->update($i, $count, "Migrated course files - course $i/$count.");
}
if ($item->isLink()) {
- // do not delete symbolic links or its children
+ // do not delete symbolic links or its children
$delete_this = false;
} else {
$delete_this = $delete;
if ($rs = $DB->get_recordset_select('post', "module='blog' AND attachment IS NOT NULL AND attachment <> 1")) {
+ upgrade_set_timeout(60*20); // set up timeout, may also abort execution
+
$pbar = new progress_bar('migrateblogfiles', 500, true);
$olddebug = $DB->get_debug();
$i++;
$pathname = "$CFG->dataroot/blog/attachments/$entry->id/$entry->attachment";
if (!file_exists($pathname)) {
- // hmm, we could set atatchment NULL here, but it would break badly in concurrent ugprades, disabling for now
- //$entry->attachment = NULL;
- //$DB->update_record('post', $entry);
+ $entry->attachment = NULL;
+ $DB->update_record('post', $entry);
continue;
}
if (!$fs->file_exists(SYSCONTEXTID, 'blog', $entry->id, '/', $filename)) {
$file_record = array('contextid'=>SYSCONTEXTID, 'filearea'=>'blog', 'itemid'=>$entry->id, 'filepath'=>'/', 'filename'=>$filename,
- 'timecreated'=>filectime($pathname), 'timemodified'=>filemtime($pathname), 'userid'=>$post->userid);
+ 'timecreated'=>filectime($pathname), 'timemodified'=>filemtime($pathname), 'userid'=>$entry->userid);
$fs->create_file_from_pathname($file_record, $pathname);
}
@unlink($pathname);
$DB->set_debug($olddebug); // reset debug level
$rs->close();
}
-
+
@rmdir("$CFG->dataroot/blog/attachments/");
@rmdir("$CFG->dataroot/blog/");
}
$CFG->fullnamedisplay = $SESSION->fullnamedisplay;
}
- if ($CFG->fullnamedisplay == 'firstname lastname') {
+ if (!isset($CFG->fullnamedisplay) or $CFG->fullnamedisplay === 'firstname lastname') {
return $user->firstname .' '. $user->lastname;
} else if ($CFG->fullnamedisplay == 'lastname firstname') {
return false;
}
+/**
+ * Sets maximum expected time needed for upgrade task.
+ * Please always make sure that upgrade will not run longer!
+ *
+ * The script may be automatically aborted if upgrade times out.
+ *
+ * @param int $max_execution_time in seconds (can not be less than 60 s)
+ * @return void
+ */
+function upgrade_set_timeout($max_execution_time=300) {
+ global $CFG;
+
+ if (!isset($CFG->upgraderunning) or $CFG->upgraderunning < time()) {
+ $upgraderunning = get_config(null, 'upgraderunning');
+ } else {
+ $upgraderunning = $CFG->upgraderunning;
+ }
+
+ if (!$upgraderunning) {
+ // upgrade not running or aborted
+ print_error('upgradetimedout', 'admin', "$CFG->wwroot/$CFG->admin/");
+ die;
+ }
+
+ if ($max_execution_time < 60) {
+ // protection against 0 here
+ $max_execution_time = 60;
+ }
+
+ $expected_end = time() + $max_execution_time;
+
+ if ($expected_end < $upgraderunning + 10 and $expected_end > $upgraderunning - 10) {
+ // no need to store new end, it is nearly the same ;-)
+ return;
+ }
+
+ set_time_limit($max_execution_time);
+ set_config('upgraderunning', $expected_end); // keep upgrade locked until this time
+}
/// MISCELLANEOUS ////////////////////////////////////////////////////////////////////
// Do NOT load up "expensive" resouces (e.g. SQL data) here!
function init_quick($data) {
if(empty($data->pageid) && !defined('ADMIN_STICKYBLOCKS')) {
- print_error('cannotinitpage', '', '', null);
+ print_error('cannotinitpage', 'debug', '', (object)array('name'=>'course', 'id'=>'?'));
}
parent::init_quick($data);
}
}
if(empty($this->courserecord) && !defined('ADMIN_STICKYBLOCKS')) {
- print_error('cannotinitpage', '', '', $this->id);
+ print_error('cannotinitpage', 'debug', '', (object)array('name'=>'course', 'id'=>$this->id));
}
$this->context = get_context_instance(CONTEXT_COURSE, $this->id);
print_error('noactivityname', 'debug');
}
if (!$this->modulerecord = get_coursemodule_from_instance($this->activityname, $this->id)) {
- print_error('cannotinitpager', 'debug', '', array($this->activityname, $this->id));
+ print_error('cannotinitpager', 'debug', '', (object)array('name'=>$this->activityname, 'id'=>$this->id));
}
$this->courserecord = $DB->get_record('course', array('id'=>$this->modulerecord->course));
if(empty($this->courserecord)) {
}
$this->activityrecord = $DB->get_record($this->activityname, array('id'=>$this->id));
if(empty($this->activityrecord)) {
- print_error('cannotinitpager', 'debug', '', array($this->activityname, $this->id));
+ print_error('cannotinitpager', 'debug', '', (object)array('name'=>$this->activityname, 'id'=>$this->id));
}
$this->full_init_done = true;
}
/// Load up any configuration from the config table
$CFG = get_config();
+/// Verify upgrade is not running
+ if (isset($CFG->upgraderunning)) {
+ if ($CFG->upgraderunning < time()) {
+ unset_config('upgraderunning');
+ } else {
+ print_error('upgraderunning');
+ }
+ }
+
/// Turn on SQL logging if required
if (!empty($CFG->logsql)) {
$DB->set_logging(true);
$module = 'error';
}
- if (!isset($CFG->theme)) {
+ if (!isset($CFG->theme) or !isset($CFG->stylesheets)) {
// error found before setup.php finished
_print_early_error($errorcode, $module, $a);
} else {
* @package
*/
-function xmldb_message_email_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_message_email_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
if ($result && $oldversion < 2008072401) {
* @package
*/
-function xmldb_message_jabber_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_message_jabber_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
if ($result && $oldversion < 2008072401) {
* @package
*/
-function xmldb_message_popup_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_message_popup_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
if ($result && $oldversion < 2008072401) {
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_assignment_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_assignment_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
//===== 1.9.0 upgrade line ======//
if ($result && $oldversion < 2007101511) {
- notify('Processing assignment grades, this may take a while if there are many assignments...', 'notifysuccess');
// change grade typo to text if no grades MDL-13920
require_once $CFG->dirroot.'/mod/assignment/lib.php';
- // too much debug output
- $DB->set_debug(false);
- assignment_update_grades();
- $DB->set_debug(true);
+ assignment_upgrade_grades();
upgrade_mod_savepoint($result, 2007101511, 'assignment');
}
$pbar = new progress_bar('migrateassignmentfiles', 500, true);
$olddebug = $DB->get_debug();
-// $DB->set_debug(false); // lower debug level, there might be many files
+ $DB->set_debug(false); // lower debug level, there might be many files
$i = 0;
foreach ($rs as $submission) {
$i++;
+ upgrade_set_timeout(180); // set up timeout, may also abort execution
$basepath = "$CFG->dataroot/$submission->course/$CFG->moddata/assignment/$submission->assignment/$submission->userid/";
if (!file_exists($basepath)) {
//no files
}
/**
- * Update grades by firing grade_updated event
+ * Update activity grades
*
- * @param object $assignment null means all assignments
- * @param int $userid specific user only, 0 mean all
+ * @param object $assignment
+ * @param int $userid specific user only, 0 means all
*/
-function assignment_update_grades($assignment=null, $userid=0, $nullifnone=true) {
+function assignment_update_grades($assignment, $userid=0, $nullifnone=true) {
global $CFG, $DB;
require_once($CFG->libdir.'/gradelib.php');
- if ($assignment != null) {
- if ($grades = assignment_get_user_grades($assignment, $userid)) {
- foreach($grades as $k=>$v) {
- if ($v->rawgrade == -1) {
- $grades[$k]->rawgrade = null;
- }
+ if ($assignment->grade == 0) {
+ assignment_grade_item_update($assignment);
+
+ } else if ($grades = assignment_get_user_grades($assignment, $userid)) {
+ foreach($grades as $k=>$v) {
+ if ($v->rawgrade == -1) {
+ $grades[$k]->rawgrade = null;
}
- assignment_grade_item_update($assignment, $grades);
- } else {
- assignment_grade_item_update($assignment);
}
+ assignment_grade_item_update($assignment, $grades);
} else {
- $sql = "SELECT a.*, cm.idnumber as cmidnumber, a.course as courseid
- FROM {assignment} a, {course_modules} cm, {modules} m
- WHERE m.name='assignment' AND m.id=cm.module AND cm.instance=a.id";
- if ($rs = $DB->get_recordset_sql($sql)) {
- foreach ($rs as $assignment) {
- if ($assignment->grade != 0) {
- assignment_update_grades($assignment);
- } else {
- assignment_grade_item_update($assignment);
- }
- }
- $rs->close();
- }
+ assignment_grade_item_update($assignment);
+ }
+}
+
+/**
+ * Update all grades in gradebook.
+ */
+function assignment_upgrade_grades() {
+ global $DB;
+
+ $sql = "SELECT COUNT('x')
+ FROM {assignment} a, {course_modules} cm, {modules} m
+ WHERE m.name='assignment' AND m.id=cm.module AND cm.instance=a.id";
+ $count = $DB->count_records_sql($sql);
+
+ $sql = "SELECT a.*, cm.idnumber AS cmidnumber, a.course AS courseid
+ FROM {assignment} a, {course_modules} cm, {modules} m
+ WHERE m.name='assignment' AND m.id=cm.module AND cm.instance=a.id";
+ if ($rs = $DB->get_recordset_sql($sql)) {
+ // too much debug output
+ $prevdebug = $DB->get_debug();
+ $DB->set_debug(false);
+ $pbar = new progress_bar('assignmentupgradegrades', 500, true);
+ $i=0;
+ foreach ($rs as $assignment) {
+ $i++;
+ upgrade_set_timeout(60*5); // set up timeout, may also abort execution
+ assignment_update_grades($assignment);
+ $pbar->update($i, $count, "Updating Assignment grades ($i/$count).");
+ }
+ $DB->set_debug($prevdebug);
+ $rs->close();
+ upgrade_set_timeout(); // reset to default timeout
}
}
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_chat_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_chat_upgrade($oldversion) {
+ global $CFG, $DB;
$dbman = $DB->get_manager();
-
$result = true;
+//===== 1.9.0 upgrade line ======//
+
if ($result && $oldversion < 2008072400) {
/// Define table chat_messages_current to be created
$table->add_index('groupid', XMLDB_INDEX_NOTUNIQUE, array('groupid'));
$table->add_index('timestamp-chatid', XMLDB_INDEX_NOTUNIQUE, array('timestamp', 'chatid'));
- /// Conditionally launch create table for chat_messages_current
- if (!$dbman->table_exists($table)) {
- $dbman->create_table($table);
- }
+ /// create table for chat_messages_current
+ $dbman->create_table($table);
/// chat savepoint reached
upgrade_mod_savepoint($result, 2008072400, 'chat');
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_choice_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_choice_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
-/// And upgrade begins here. For each one, you'll need one
-/// block of code similar to the next one. Please, delete
-/// this comment lines once this file start handling proper
-/// upgrade code.
-
-/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
-/// $result = result of database_manager methods
-/// }
-
//===== 1.9.0 upgrade line ======//
return $result;
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_data_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_data_upgrade($oldversion) {
+ global $CFG, $DB;
$dbman = $DB->get_manager();
-
$result = true;
//===== 1.9.0 upgrade line ======//
}
/**
- * Update grades by firing grade_updated event
+ * Update activity grades
*
- * @param object $data null means all databases
- * @param int $userid specific user only, 0 mean all
+ * @param object $data
+ * @param int $userid specific user only, 0 means all
*/
-function data_update_grades($data=null, $userid=0, $nullifnone=true) {
+function data_update_grades($data, $userid=0, $nullifnone=true) {
global $CFG, $DB;
require_once($CFG->libdir.'/gradelib.php');
- if ($data != null) {
- if ($grades = data_get_user_grades($data, $userid)) {
- data_grade_item_update($data, $grades);
+ if (!$data->assessed) {
+ data_grade_item_update($data);
- } else if ($userid and $nullifnone) {
- $grade = new object();
- $grade->userid = $userid;
- $grade->rawgrade = NULL;
- data_grade_item_update($data, $grade);
+ } else if ($grades = data_get_user_grades($data, $userid)) {
+ data_grade_item_update($data, $grades);
- } else {
- data_grade_item_update($data);
- }
+ } else if ($userid and $nullifnone) {
+ $grade = new object();
+ $grade->userid = $userid;
+ $grade->rawgrade = NULL;
+ data_grade_item_update($data, $grade);
} else {
- $sql = "SELECT d.*, cm.idnumber as cmidnumber
- FROM {data} d, {course_modules} cm, {modules} m
- WHERE m.name='data' AND m.id=cm.module AND cm.instance=d.id";
- if ($rs = $DB->get_recordset_sql($sql)) {
- foreach ($rs as $data) {
- if ($data->assessed) {
- data_update_grades($data, 0, false);
- } else {
- data_grade_item_update($data);
- }
- }
- $rs->close();
- }
+ data_grade_item_update($data);
+ }
+}
+
+/**
+ * Update all grades in gradebook.
+ */
+function data_upgrade_grades() {
+ global $DB;
+
+ $sql = "SELECT COUNT('x')
+ FROM {data} d, {course_modules} cm, {modules} m
+ WHERE m.name='data' AND m.id=cm.module AND cm.instance=d.id";
+ $count = $DB->count_records_sql($sql);
+
+ $sql = "SELECT d.*, cm.idnumber AS cmidnumber, d.course AS courseid
+ FROM {data} d, {course_modules} cm, {modules} m
+ WHERE m.name='data' AND m.id=cm.module AND cm.instance=d.id";
+ if ($rs = $DB->get_recordset_sql($sql)) {
+ // too much debug output
+ $prevdebug = $DB->get_debug();
+ $DB->set_debug(false);
+ $pbar = new progress_bar('dataupgradegrades', 500, true);
+ $i=0;
+ foreach ($rs as $data) {
+ $i++;
+ upgrade_set_timeout(60*5); // set up timeout, may also abort execution
+ data_update_grades($data, 0, false);
+ $pbar->update($i, $count, "Updating Database grades ($i/$count).");
+ }
+ $DB->set_debug($prevdebug);
+ $rs->close();
}
}
} else if ($rating != $oldrating->rating) {
$oldrating->rating = $rating;
if (!$DB->update_record('data_ratings', $oldrating)) {
- print_error('cannotupdaterate', 'data', '', array($record->id, $rating));
+ print_error('cannotupdaterate', 'error', '', (object)array('id'=>$record->id, 'rating'=>$rating));
}
data_update_grades($data, $record->userid);
$newrating->recordid = $record->id;
$newrating->rating = $rating;
if (! $DB->insert_record('data_ratings', $newrating)) {
- print_error('cannotinsertrate', 'data', '', array($record->id, $rating));
+ print_error('cannotinsertrate', 'error', '', (object)array('id'=>$record->id, 'rating'=>$rating));
}
data_update_grades($data, $record->userid);
}
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_feedback_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_feedback_upgrade($oldversion) {
+ global $CFG, $DB;
$dbman = $DB->get_manager();
-
$result = true;
if ($result && $oldversion < 2007012310) {
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_forum_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_forum_upgrade($oldversion) {
+ global $CFG, $DB;
$dbman = $DB->get_manager(); // loads ddl manager and xmldb classes
-
$result = true;
-/// And upgrade begins here. For each one, you'll need one
-/// block of code similar to the next one. Please, delete
-/// this comment lines once this file start handling proper
-/// upgrade code.
-
-/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
-/// $result = result of database_manager methods
-/// }
-
//===== 1.9.0 upgrade line ======//
if ($result and $oldversion < 2007101511) {
- notify('Processing forum grades, this may take a while if there are many forums...', 'notifysuccess');
//MDL-13866 - send forum ratins to gradebook again
require_once($CFG->dirroot.'/mod/forum/lib.php');
- // too much debug output
- $DB->set_debug(false);
- forum_update_grades();
- $DB->set_debug(true);
-
+ forum_upgrade_grades();
upgrade_mod_savepoint($result, 2007101511, 'forum');
}
}
/**
- * Update grades by firing grade_updated event
+ * Update activity grades
*
- * @param object $forum null means all forums
- * @param int $userid specific user only, 0 mean all
+ * @param object $forum
+ * @param int $userid specific user only, 0 means all
* @param boolean $nullifnone return null if grade does not exist
* @return void
*/
-function forum_update_grades($forum=null, $userid=0, $nullifnone=true) {
+function forum_update_grades($forum, $userid=0, $nullifnone=true) {
global $CFG, $DB;
+ require_once($CFG->libdir.'/gradelib.php');
- if ($forum != null) {
- require_once($CFG->libdir.'/gradelib.php');
- if ($grades = forum_get_user_grades($forum, $userid)) {
- forum_grade_item_update($forum, $grades);
+ if (!$forum->assessed) {
+ forum_grade_item_update($forum);
- } else if ($userid and $nullifnone) {
- $grade = new object();
- $grade->userid = $userid;
- $grade->rawgrade = NULL;
- forum_grade_item_update($forum, $grade);
+ } else if ($grades = forum_get_user_grades($forum, $userid)) {
+ forum_grade_item_update($forum, $grades);
- } else {
- forum_grade_item_update($forum);
- }
+ } else if ($userid and $nullifnone) {
+ $grade = new object();
+ $grade->userid = $userid;
+ $grade->rawgrade = NULL;
+ forum_grade_item_update($forum, $grade);
} else {
- $sql = "SELECT f.*, cm.idnumber as cmidnumber
- FROM {forum} f, {course_modules} cm, {modules} m
- WHERE m.name='forum' AND m.id=cm.module AND cm.instance=f.id";
- if ($rs = $DB->get_recordset_sql($sql)) {
- foreach ($rs as $forum) {
- if ($forum->assessed) {
- forum_update_grades($forum, 0, false);
- } else {
- forum_grade_item_update($forum);
- }
- }
- $rs->close();
- }
+ forum_grade_item_update($forum);
+ }
+}
+
+/**
+ * Update all grades in gradebook.
+ */
+function forum_upgrade_grades() {
+ global $DB;
+
+ $sql = "SELECT COUNT('x')
+ FROM {forum} f, {course_modules} cm, {modules} m
+ WHERE m.name='forum' AND m.id=cm.module AND cm.instance=f.id";
+ $count = $DB->count_records_sql($sql);
+
+ $sql = "SELECT f.*, cm.idnumber AS cmidnumber, f.course AS courseid
+ FROM {forum} f, {course_modules} cm, {modules} m
+ WHERE m.name='forum' AND m.id=cm.module AND cm.instance=f.id";
+ if ($rs = $DB->get_recordset_sql($sql)) {
+ // too much debug output
+ $prevdebug = $DB->get_debug();
+ $DB->set_debug(false);
+ $pbar = new progress_bar('forumupgradegrades', 500, true);
+ $i=0;
+ foreach ($rs as $forum) {
+ $i++;
+ upgrade_set_timeout(60*5); // set up timeout, may also abort execution
+ forum_update_grades($forum, 0, false);
+ $pbar->update($i, $count, "Updating Forum grades ($i/$count).");
+ }
+ $DB->set_debug($prevdebug);
+ $rs->close();
}
}
$oldrating->rating = $rating;
$oldrating->time = time();
if (!$DB->update_record('forum_ratings', $oldrating)) {
- print_error('cannotupdaterate', 'forum', '',
- array($post->id, $rating));
+ print_error('cannotupdaterate', 'error', '', (object)array('id'=>$post->id, 'rating'=>$rating));
}
forum_update_grades($forum, $post->userid);
}
$newrating->rating = $rating;
if (! $DB->insert_record('forum_ratings', $newrating)) {
- print_error('cannotinsertrate', 'forum', '',
- array($postid, $rating));
+ print_error('cannotinsertrate', 'error', '', (object)array('id'=>$postid, 'rating'=>$rating));
}
forum_update_grades($forum, $post->userid);
}
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_glossary_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_glossary_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
-/// And upgrade begins here. For each one, you'll need one
-/// block of code similar to the next one. Please, delete
-/// this comment lines once this file start handling proper
-/// upgrade code.
-
-/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
-/// $result = result of database_manager methods
-/// }
-
//===== 1.9.0 upgrade line ======//
return $result;
}
/**
- * Update grades by firing grade_updated event
+ * Update activity grades
*
* @param object $glossary null means all glossaries
- * @param int $userid specific user only, 0 mean all
+ * @param int $userid specific user only, 0 means all
*/
function glossary_update_grades($glossary=null, $userid=0, $nullifnone=true) {
global $CFG, $DB;
require_once($CFG->libdir.'/gradelib.php');
- if ($glossary != null) {
- if ($grades = glossary_get_user_grades($glossary, $userid)) {
- glossary_grade_item_update($glossary, $grades);
+ if (!$glossary->assessed) {
+ glossary_grade_item_update($glossary);
- } else if ($userid and $nullifnone) {
- $grade = new object();
- $grade->userid = $userid;
- $grade->rawgrade = NULL;
- glossary_grade_item_update($glossary, $grade);
+ } else if ($grades = glossary_get_user_grades($glossary, $userid)) {
+ glossary_grade_item_update($glossary, $grades);
- } else {
- glossary_grade_item_update($glossary);
- }
+ } else if ($userid and $nullifnone) {
+ $grade = new object();
+ $grade->userid = $userid;
+ $grade->rawgrade = NULL;
+ glossary_grade_item_update($glossary, $grade);
} else {
- $sql = "SELECT g.*, cm.idnumber as cmidnumber
- FROM {glossary} g, {course_modules} cm, {modules} m
- WHERE m.name='glossary' AND m.id=cm.module AND cm.instance=g.id";
- if ($rs = $DB->get_recordset_sql($sql)) {
- foreach ($rs as $glossary) {
- if ($glossary->assessed) {
- glossary_update_grades($glossary, 0, false);
- } else {
- glossary_grade_item_update($glossary);
- }
- }
- $rs->close();
- }
+ glossary_grade_item_update($glossary);
+ }
+}
+
+/**
+ * Update all grades in gradebook.
+ */
+function glossary_upgrade_grades() {
+ global $DB;
+
+ $sql = "SELECT COUNT('x')
+ FROM {glossary} g, {course_modules} cm, {modules} m
+ WHERE m.name='glossary' AND m.id=cm.module AND cm.instance=g.id";
+ $count = $DB->count_records_sql($sql);
+
+ $sql = "SELECT g.*, cm.idnumber AS cmidnumber, g.course AS courseid
+ FROM {glossary} g, {course_modules} cm, {modules} m
+ WHERE m.name='glossary' AND m.id=cm.module AND cm.instance=g.id";
+ if ($rs = $DB->get_recordset_sql($sql)) {
+ $prevdebug = $DB->get_debug();
+ $DB->set_debug(false);
+ $pbar = new progress_bar('glossaryupgradegrades', 500, true);
+ $i=0;
+ foreach ($rs as $glossary) {
+ $i++;
+ upgrade_set_timeout(60*5); // set up timeout, may also abort execution
+ glossary_update_grades($glossary, 0, false);
+ $pbar->update($i, $count, "Updating Glossary grades ($i/$count).");
+ }
+ $DB->set_debug($prevdebug);
+ $rs->close();
}
}
$oldrating->rating = $rating;
$oldrating->time = time();
if (! $DB->update_record("glossary_ratings", $oldrating)) {
- print_error('cannotinsertrate', '', '', array($entry, $rating));
+ print_error('cannotinsertrate', 'error', '', (object)array('id'=>$entry->id, 'rating'=>$rating));
}
glossary_update_grades($glossary, $entry->userid);
}
$newrating->rating = $rating;
if (! $DB->insert_record("glossary_ratings", $newrating)) {
- print_error('cannotinsertrate', '', '', array($entry->id, $rating));
+ print_error('cannotinsertrate', 'error', '', (object)array('id'=>$entry->id, 'rating'=>$rating));
}
glossary_update_grades($glossary, $entry->userid);
}
<?php //$Id$
// This file keeps track of upgrades to the hotpot module
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_hotpot_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_hotpot_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
//===== 1.9.0 upgrade line ======//
// update hotpot grades from sites earlier than Moodle 1.9, 27th March 2008
if ($result && $oldversion < 2007101511) {
-
- // ensure "hotpot_update_grades" function is available
+ // ensure "hotpot_upgrade_grades" function is available
require_once $CFG->dirroot.'/mod/hotpot/lib.php';
-
- // disable display of debugging messages
- $DB->set_debug(false);
-
- notify('Processing hotpot grades, this may take a while if there are many hotpots...', 'notifysuccess');
- hotpot_update_grades();
-
- // restore debug
- $DB->set_debug(true);
+ hotpot_upgrade_grades();
}
return $result;
/**
* Update grades in central gradebook
- * this function is called from db/upgrade.php
- * it is initially called with no arguments, which forces it to get a list of all hotpots
- * it then iterates through the hotpots, calling itself to create a grade record for each hotpot
- *
- * @param object $hotpot null means all hotpots
+ * @param object $hotpot
* @param int $userid specific user only, 0 means all users
*/
-function hotpot_update_grades($hotpot=null, $userid=0, $nullifnone=true) {
+function hotpot_update_grades($hotpot, $userid=0, $nullifnone=true) {
global $CFG, $DB;
require_once($CFG->libdir.'/gradelib.php');
- if (is_null($hotpot)) {
- // update (=create) grades for all hotpots
- $sql = "
- SELECT h.*, cm.idnumber as cmidnumber
- FROM {hotpot} h, {course_modules} cm, {modules} m
- WHERE m.name='hotpot' AND m.id=cm.module AND cm.instance=h.id"
- ;
- if ($rs = $DB->get_recordset_sql($sql)) {
- foreach ($rs as $hotpot) {
- hotpot_update_grades($hotpot, 0, false);
- }
- $rs->close();
- }
+ // update (=create) grade for a single hotpot
+ if ($grades = hotpot_get_user_grades($hotpot, $userid)) {
+ hotpot_grade_item_update($hotpot, $grades);
+
+ } else if ($userid && $nullifnone) {
+ // no grades for this user, but we must force the creation of a "null" grade record
+ $grade = new object();
+ $grade->userid = $userid;
+ $grade->rawgrade = null;
+ hotpot_grade_item_update($hotpot, $grade);
+
} else {
- // update (=create) grade for a single hotpot
- if ($grades = hotpot_get_user_grades($hotpot, $userid)) {
- hotpot_grade_item_update($hotpot, $grades);
+ // no grades and no userid
+ hotpot_grade_item_update($hotpot);
+ }
+}
- } else if ($userid && $nullifnone) {
- // no grades for this user, but we must force the creation of a "null" grade record
- $grade = new object();
- $grade->userid = $userid;
- $grade->rawgrade = null;
- hotpot_grade_item_update($hotpot, $grade);
+/**
+ * Update all grades in gradebook.
+ * this function is called from db/upgrade.php
+ * it iterates through the hotpots, calling hotpot_update_grades() to create a grade record for each hotpot
+ */
+function hotpot_upgrade_grades() {
+ global $DB;
- } else {
- // no grades and no userid
- hotpot_grade_item_update($hotpot);
+ // upgrade (=create) grades for all hotpots
+ $sql = "
+ SELECT COUNT('x')
+ FROM {hotpot} h, {course_modules} cm, {modules} m
+ WHERE m.name='hotpot' AND m.id=cm.module AND cm.instance=h.id";
+ $count = $DB->count_records_sql($sql);
+
+ $sql = "
+ SELECT h.*, cm.idnumber AS cmidnumber
+ FROM {hotpot} h, {course_modules} cm, {modules} m
+ WHERE m.name='hotpot' AND m.id=cm.module AND cm.instance=h.id";
+ if ($rs = $DB->get_recordset_sql($sql)) {
+ // too much debug output
+ $prevdebug = $DB->get_debug();
+ $DB->set_debug(false);
+ $pbar = new progress_bar('hotpotupgradegrades', 500, true);
+ $i=0;
+ foreach ($rs as $hotpot) {
+ $i++;
+ upgrade_set_timeout(60*5); // set up timeout, may also abort execution
+ hotpot_update_grades($hotpot, 0, false);
+ $pbar->update($i, $count, "Updating Hotpot grades ($i/$count).");
}
+ $DB->set_debug($prevdebug);
+ $rs->close();
}
}
if (empty($str)) {
$this->xml = array();
} else {
- if (empty($CFG->unicodedb)) {
- $str = utf8_encode($str);
- }
$this->xml = xmlize($str, 0);
}
$this->xml_root = $xml_root;
eval('$value = &$this->xml'.$this->xml_root.$tags.$more_tags.';');
if (is_string($value)) {
- if (empty($CFG->unicodedb)) {
- $value = utf8_decode($value);
- }
// decode angle brackets
$value = strtr($value, array('<'=>'<', '>'=>'>', '&'=>'&'));
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_label_upgrade($oldversion=0) {
- global $CFG, $THEME, $DB;
+function xmldb_label_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
-/// And upgrade begins here. For each one, you'll need one
-/// block of code similar to the next one. Please, delete
-/// this comment lines once this file start handling proper
-/// upgrade code.
-
-/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
-/// $result = result of database_manager methods
-/// }
-
//===== 1.9.0 upgrade line ======//
+
if ($oldversion < 2007101510) {
$sql = "UPDATE {log_display} SET mtable = 'label' WHERE module = 'label'";
$result = $DB->execute($sql);
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_lesson_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_lesson_upgrade($oldversion) {
+ global $CFG, $DB;
$dbman = $DB->get_manager();
-
$result = true;
//===== 1.9.0 upgrade line ======//
/**
* Update grades in central gradebook
*
- * @param object $lesson null means all lessons
- * @param int $userid specific user only, 0 mean all
+ * @param object $lesson
+ * @param int $userid specific user only, 0 means all
*/
-function lesson_update_grades($lesson=null, $userid=0, $nullifnone=true) {
+function lesson_update_grades($lesson, $userid=0, $nullifnone=true) {
global $CFG, $DB;
- if (!function_exists('grade_update')) { //workaround for buggy PHP versions
- require_once($CFG->libdir.'/gradelib.php');
- }
+ require_once($CFG->libdir.'/gradelib.php');
- if ($lesson != null) {
- if ($grades = lesson_get_user_grades($lesson, $userid)) {
- lesson_grade_item_update($lesson, $grades);
+ if ($lesson->grade == 0) {
+ lesson_grade_item_update($lesson);
- } else if ($userid and $nullifnone) {
- $grade = new object();
- $grade->userid = $userid;
- $grade->rawgrade = NULL;
- lesson_grade_item_update($lesson, $grade);
+ } else if ($grades = lesson_get_user_grades($lesson, $userid)) {
+ lesson_grade_item_update($lesson, $grades);
- } else {
- lesson_grade_item_update($lesson);
- }
+ } else if ($userid and $nullifnone) {
+ $grade = new object();
+ $grade->userid = $userid;
+ $grade->rawgrade = NULL;
+ lesson_grade_item_update($lesson, $grade);
} else {
- $sql = "SELECT l.*, cm.idnumber as cmidnumber, l.course as courseid
- FROM {lesson} l, {course_modules} cm, {modules} m
- WHERE m.name='lesson' AND m.id=cm.module AND cm.instance=l.id";
- if ($rs = $DB->get_recordset_sql($sql)) {
- foreach ($rs as $lesson) {
- if ($lesson->grade != 0) {
- lesson_update_grades($lesson, 0, false);
- } else {
- lesson_grade_item_update($lesson);
- }
- }
- $rs->close();
+ lesson_grade_item_update($lesson);
+ }
+}
+
+/**
+ * Update all grades in gradebook.
+ */
+function lesson_upgrade_grades() {
+ global $DB;
+
+ $sql = "SELECT COUNT('x')
+ FROM {lesson} l, {course_modules} cm, {modules} m
+ WHERE m.name='lesson' AND m.id=cm.module AND cm.instance=l.id";
+ $count = $DB->count_records_sql($sql);
+
+ $sql = "SELECT l.*, cm.idnumber AS cmidnumber, l.course AS courseid
+ FROM {lesson} l, {course_modules} cm, {modules} m
+ WHERE m.name='lesson' AND m.id=cm.module AND cm.instance=l.id";
+ if ($rs = $DB->get_recordset_sql($sql)) {
+ $prevdebug = $DB->get_debug();
+ $DB->set_debug(false);
+ $pbar = new progress_bar('lessonupgradegrades', 500, true);
+ $i=0;
+ foreach ($rs as $lesson) {
+ $i++;
+ upgrade_set_timeout(60*5); // set up timeout, may also abort execution
+ lesson_update_grades($lesson, 0, false);
+ $pbar->update($i, $count, "Updating Lesson grades ($i/$count).");
}
+ $DB->set_debug($prevdebug);
+ $rs->close();
}
}
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_quiz_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_quiz_upgrade($oldversion) {
+ global $CFG, $DB;
$dbman = $DB->get_manager();
-
$result = true;
//===== 1.9.0 upgrade line ======//
/**
* Update grades in central gradebook
*
- * @param object $quiz null means all quizs
- * @param int $userid specific user only, 0 mean all
+ * @param object $quiz
+ * @param int $userid specific user only, 0 means all
*/
-function quiz_update_grades($quiz=null, $userid=0, $nullifnone=true) {
+function quiz_update_grades($quiz, $userid=0, $nullifnone=true) {
global $CFG, $DB;
- if (!function_exists('grade_update')) { //workaround for buggy PHP versions
- require_once($CFG->libdir.'/gradelib.php');
- }
+ require_once($CFG->libdir.'/gradelib.php');
- if ($quiz != null) {
- if ($grades = quiz_get_user_grades($quiz, $userid)) {
- quiz_grade_item_update($quiz, $grades);
+ if ($quiz->grade == 0) {
+ quiz_grade_item_update($quiz);
- } else if ($userid and $nullifnone) {
- $grade = new object();
- $grade->userid = $userid;
- $grade->rawgrade = NULL;
- quiz_grade_item_update($quiz, $grade);
+ } else if ($grades = quiz_get_user_grades($quiz, $userid)) {
+ quiz_grade_item_update($quiz, $grades);
- } else {
- quiz_grade_item_update($quiz);
- }
+ } else if ($userid and $nullifnone) {
+ $grade = new object();
+ $grade->userid = $userid;
+ $grade->rawgrade = NULL;
+ quiz_grade_item_update($quiz, $grade);
} else {
- $sql = "SELECT a.*, cm.idnumber as cmidnumber, a.course as courseid
- FROM {quiz} a, {course_modules} cm, {modules} m
- WHERE m.name='quiz' AND m.id=cm.module AND cm.instance=a.id";
- if ($rs = $DB->get_recordset_sql($sql)) {
- foreach ($rs as $quiz) {
- if ($quiz->grade != 0) {
- quiz_update_grades($quiz, 0, false);
- } else {
- quiz_grade_item_update($quiz);
- }
- }
- $rs->close();
+ quiz_grade_item_update($quiz);
+ }
+}
+
+/**
+ * Update all grades in gradebook.
+ */
+function quiz_upgrade_grades() {
+ global $DB;
+
+ $sql = "SELECT COUNT('x')
+ FROM {quiz} a, {course_modules} cm, {modules} m
+ WHERE m.name='quiz' AND m.id=cm.module AND cm.instance=a.id";
+ $count = $DB->count_records_sql($sql);
+
+ $sql = "SELECT a.*, cm.idnumber AS cmidnumber, a.course AS courseid
+ FROM {quiz} a, {course_modules} cm, {modules} m
+ WHERE m.name='quiz' AND m.id=cm.module AND cm.instance=a.id";
+ if ($rs = $DB->get_recordset_sql($sql)) {
+ $prevdebug = $DB->get_debug();
+ $DB->set_debug(false);
+ $pbar = new progress_bar('quizupgradegrades', 500, true);
+ $i=0;
+ foreach ($rs as $quiz) {
+ $i++;
+ upgrade_set_timeout(60*5); // set up timeout, may also abort execution
+ quiz_update_grades($quiz, 0, false);
+ $pbar->update($i, $count, "Updating Quiz grades ($i/$count).");
}
+ $DB->set_debug($prevdebug);
+ $rs->close();
}
}
function init_quick($data) {
if(empty($data->pageid)) {
- print_error('cannotinitpage', '', '', null);
+ print_error('cannotinitpage', 'debug', '', (object)array('name'=>'quiz', 'id'=>'?'));
}
$this->activityname = 'quiz';
parent::init_quick($data);
<?php // $Id$
-function xmldb_quizreport_overview_upgrade($oldversion=0) {
+function xmldb_quizreport_overview_upgrade($oldversion) {
+ global $CFG, $DB;
- global $CFG, $THEME, $DB;
-
$dbman = $DB->get_manager();
-
$result = true;
//===== 1.9.0 upgrade line ======//
<?php // $Id$
-function xmldb_quizreport_statistics_upgrade($oldversion=0) {
+function xmldb_quizreport_statistics_upgrade($oldversion) {
global $DB;
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_resource_upgrade($oldversion=0) {
- global $CFG, $THEME, $DB;
+function xmldb_resource_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
-/// And upgrade begins here. For each one, you'll need one
-/// block of code similar to the next one. Please, delete
-/// this comment lines once this file start handling proper
-/// upgrade code.
-
-/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
-/// $result = result of database_manager methods
-/// }
-
//===== 1.9.0 upgrade line ======//
return $result;
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_scorm_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_scorm_upgrade($oldversion) {
+ global $CFG, $DB;
$dbman = $DB->get_manager();
-
$result = true;
//===== 1.9.0 upgrade line ======//
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'grademethod');
/// Launch add field whatgrade
- if(!$dbman->field_exists($table,$field)) {
+ if (!$dbman->field_exists($table,$field)) {
$dbman->add_field($table, $field);
}
/**
* Update grades in central gradebook
*
- * @param object $scorm null means all scormbases
+ * @param object $scorm
* @param int $userid specific user only, 0 mean all
*/
-function scorm_update_grades($scorm=null, $userid=0, $nullifnone=true) {
+function scorm_update_grades($scorm, $userid=0, $nullifnone=true) {
global $CFG, $DB;
- if (!function_exists('grade_update')) { //workaround for buggy PHP versions
- require_once($CFG->libdir.'/gradelib.php');
- }
+ require_once($CFG->libdir.'/gradelib.php');
- if ($scorm != null) {
- if ($grades = scorm_get_user_grades($scorm, $userid)) {
- scorm_grade_item_update($scorm, $grades);
+ if ($grades = scorm_get_user_grades($scorm, $userid)) {
+ scorm_grade_item_update($scorm, $grades);
- } else if ($userid and $nullifnone) {
- $grade = new object();
- $grade->userid = $userid;
- $grade->rawgrade = NULL;
- scorm_grade_item_update($scorm, $grade);
-
- } else {
- scorm_grade_item_update($scorm);
- }
+ } else if ($userid and $nullifnone) {
+ $grade = new object();
+ $grade->userid = $userid;
+ $grade->rawgrade = NULL;
+ scorm_grade_item_update($scorm, $grade);
} else {
- $sql = "SELECT s.*, cm.idnumber as cmidnumber
- FROM {scorm} s, {course_modules} cm, {modules} m
- WHERE m.name='scorm' AND m.id=cm.module AND cm.instance=s.id";
- if ($rs = $DB->get_recordset_sql($sql)) {
- foreach ($rs as $scorm) {
- scorm_update_grades($scorm, 0, false);
- }
- $rs->close();
+ scorm_grade_item_update($scorm);
+ }
+}
+
+/**
+ * Update all grades in gradebook.
+ */
+function scorm_upgrade_grades() {
+ global $DB;
+
+ $sql = "SELECT COUNT('x')
+ FROM {scorm} s, {course_modules} cm, {modules} m
+ WHERE m.name='scorm' AND m.id=cm.module AND cm.instance=s.id";
+ $count = $DB->count_records_sql($sql);
+
+ $sql = "SELECT s.*, cm.idnumber AS cmidnumber, s.course AS courseid
+ FROM {scorm} s, {course_modules} cm, {modules} m
+ WHERE m.name='scorm' AND m.id=cm.module AND cm.instance=s.id";
+ if ($rs = $DB->get_recordset_sql($sql)) {
+ $prevdebug = $DB->get_debug();
+ $DB->set_debug(false);
+ $pbar = new progress_bar('scormupgradegrades', 500, true);
+ $i=0;
+ foreach ($rs as $scorm) {
+ $i++;
+ upgrade_set_timeout(60*5); // set up timeout, may also abort execution
+ scorm_update_grades($scorm, 0, false);
+ $pbar->update($i, $count, "Updating Scorm grades ($i/$count).");
}
+ $DB->set_debug($prevdebug);
+ $rs->close();
}
}
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_survey_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_survey_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
-/// And upgrade begins here. For each one, you'll need one
-/// block of code similar to the next one. Please, delete
-/// this comment lines once this file start handling proper
-/// upgrade code.
-
-/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
-/// $result = result of database_manager methods
-/// }
-
//===== 1.9.0 upgrade line ======//
return $result;
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_wiki_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_wiki_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
-/// And upgrade begins here. For each one, you'll need one
-/// block of code similar to the next one. Please, delete
-/// this comment lines once this file start handling proper
-/// upgrade code.
-
-/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
-/// $result = result of database_manager methods
-/// }
-
//===== 1.9.0 upgrade line ======//
return $result;
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_qtype_calculated_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_qtype_calculated_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_qtype_datasetdependent_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_qtype_datasetdependent_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_qtype_essay_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_qtype_essay_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_qtype_match_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_qtype_match_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_qtype_multianswer_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_qtype_multianswer_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
-/// And upgrade begins here. For each one, you'll need one
-/// block of code similar to the next one. Please, delete
-/// this comment lines once this file start handling proper
-/// upgrade code.
-
-/// if ($result && $oldversion < YYYYMMDD00) { //New version in version.php
-/// $result = result of database_manager methods
-/// }
-
if ($result && $oldversion < 2008050800) {
question_multianswer_fix_subquestion_parents_and_categories();
}
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_qtype_multichoice_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_qtype_multichoice_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
return $result;
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_qtype_numerical_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_qtype_numerical_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
//===== 1.9.0 upgrade line ======//
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_qtype_randomsamatch_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_qtype_randomsamatch_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_qtype_shortanswer_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_qtype_shortanswer_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
+//
+// Please do not forget to use upgrade_set_timeout()
+// before any action that may take longer time to finish.
-function xmldb_qtype_truefalse_upgrade($oldversion=0) {
-
- global $CFG, $THEME, $DB;
+function xmldb_qtype_truefalse_upgrade($oldversion) {
+ global $CFG, $DB;
+ $dbman = $DB->get_manager();
$result = true;
/// And upgrade begins here. For each one, you'll need one
$iconpath = $CFG->modpixpath.'/'.$listing->doctype.'/icon.gif';
$coursename = get_field('course', 'fullname', 'id', $listing->courseid);
$courseword = mb_convert_case(get_string('course', 'moodle'), MB_CASE_LOWER, 'UTF-8');
- //if ($CFG->unicodedb) {
- //$listing->title = mb_convert_encoding($listing->title, 'auto', 'UTF8');
- //}
$title_post_processing_function = $listing->doctype.'_link_post_processing';
$searchable_instance = $searchables[$listing->doctype];
if ($searchable_instance->location == 'internal'){
$mform->setType('lastname', PARAM_NOTAGS);
// Do not show email field if change confirmation is pending
- if ($CFG->emailchangeconfirmation && !empty($user->preference_newemail)) {
+ if (!empty($CFG->emailchangeconfirmation) and !empty($user->preference_newemail)) {
$notice = get_string('auth_emailchangepending', 'auth', $user);
$notice .= '<br /><a href="edit.php?cancelemailchange=1&id='.$user->id.'">'
. get_string('auth_emailchangecancel', 'auth') . '</a>';
$mform->setAdvanced('trackforums');
}
- if ($CFG->htmleditor) {
+ if (!empty($CFG->htmleditor)) {
$choices = array();
$choices['0'] = get_string('texteditor');
$choices['1'] = get_string('htmleditor');
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
- $version = 2008081506; // YYYYMMDD = date of the last version bump
+ $version = 2008081600; // YYYYMMDD = date of the last version bump
// XX = daily increments
$release = '2.0 dev (Build: 20080816)'; // Human-friendly version name