/** * Upgrades local customisations. * * @param object $upgrade The version to upgrade to * @return bool Whether the upgrade succeeded or not * @throws SQLException If the upgrade failed due to a database error */ function upgrade_local($upgrade) { db_begin(); require_once get_config('docroot') . 'local/upgrade.php'; xmldb_local_upgrade($upgrade->from); set_config('localversion', $upgrade->to); set_config('localrelease', $upgrade->torelease); db_commit(); return true; }
/** * This function checks to see whether local database customisations are up-to-date * by comparing $CFG->local_version to the variable $local_version defined in * local/version.php. If not, it looks for a function called 'xmldb_local_upgrade' * in a file called 'local/db/upgrade.php', and if it's there calls it with the * appropiate $oldversion parameter. Then it updates $CFG->local_version. * On success it prints a continue link. On failure it prints an error. * * @uses $CFG * @uses $db to do something really evil with the debug setting that should probably be eliminated. TODO! * @param string $continueto a URL passed to print_continue() if the local upgrades succeed. */ function upgrade_local_db($continueto) { global $CFG, $db; // if we don't have code version or a db upgrade file, just return true, we're unneeded if (!file_exists($CFG->dirroot . '/local/version.php') || !file_exists($CFG->dirroot . '/local/db/upgrade.php')) { return true; } require_once $CFG->dirroot . '/local/version.php'; // Get code versions if (empty($CFG->local_version)) { // normally we'd install, but just replay all the upgrades. $CFG->local_version = 0; } if ($local_version > $CFG->local_version) { // upgrade! $strdatabaseupgrades = get_string('databaseupgrades'); print_header($strdatabaseupgrades, $strdatabaseupgrades, build_navigation(array(array('name' => $strdatabaseupgrades, 'link' => null, 'type' => 'misc'))), '', upgrade_get_javascript()); upgrade_log_start(); require_once $CFG->dirroot . '/local/db/upgrade.php'; $db->debug = true; if (xmldb_local_upgrade($CFG->local_version)) { $db->debug = false; if (set_config('local_version', $local_version)) { notify(get_string('databasesuccess'), 'notifysuccess'); notify(get_string('databaseupgradelocal', '', $local_version), 'notifysuccess'); print_continue($continueto); print_footer('none'); exit; } else { error('Upgrade of local database customisations failed! (Could not update version in config table)'); } } else { $db->debug = false; error('Upgrade failed! See local/version.php'); } } else { if ($local_version < $CFG->local_version) { upgrade_log_start(); notify('WARNING!!! The local version you are using is OLDER than the version that made these databases!'); } } /// Capabilities if (!update_capabilities('local')) { error('Could not set up the capabilities for local!'); } if (!events_update_definition('local')) { error('Could not set up the events definitions for local!'); } upgrade_log_finish(); }
/** * This function checks to see whether local database customisations are up-to-date * by comparing $CFG->local_version to the variable $local_version defined in * local/version.php. If not, it looks for a function called 'xmldb_local_upgrade' * in a file called 'local/db/upgrade.php', and if it's there calls it with the * appropiate $oldversion parameter. Then it updates $CFG->local_version. * * @uses $CFG */ function upgrade_local_db($startcallback, $endcallback) { global $CFG, $DB; // if we don't have code version, just return false if (!file_exists($CFG->dirroot . '/local/version.php')) { return; } $local_version = null; require $CFG->dirroot . '/local/version.php'; // Get code versions if (empty($CFG->local_version)) { // install $startcallback('local', true); if (file_exists($CFG->dirroot . '/local/db/install.php')) { require_once $CFG->dirroot . '/local/db/install.php'; xmldb_local_install(); } set_config('local_version', $local_version); /// Install various components events_update_definition('local'); update_capabilities('local'); message_update_providers('local'); $endcallback('local', true); } else { if ($local_version > $CFG->local_version) { // upgrade! $startcallback('local', false); if (file_exists($CFG->dirroot . '/local/db/upgrade.php')) { require_once $CFG->dirroot . '/local/db/upgrade.php'; xmldb_local_upgrade($CFG->local_version); } set_config('local_version', $local_version); /// Upgrade various components events_update_definition('local'); update_capabilities('local'); message_update_providers('local'); $endcallback('local', false); } else { if ($local_version < $CFG->local_version) { throw new downgrade_exception('local', $CFG->local_version, $local_version); } } } }