}
function upgrade_plugin_savepoint($result, $version, $type, $dir) {
- //TODO
+ if ($result) {
+ $fullname = $type . '_' . $dir;
+ $installedversion = get_config($fullname, 'version');
+ if ($installedversion >= $version) {
+ // Something really wrong is going on in the upgrade script
+ $a = new stdClass;
+ $a->oldversion = $installedversion;
+ $a->newversion = $version;
+ print_error('cannotdowngrade', 'debug', '', $a);
+ }
+ set_config('version', $version, $fullname);
+ } 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_backup_savepoint($result, $version) {
}
$plugin->name = $plug; // The name MUST match the directory
+ $plugin->fullname = $type.'_'.$plug; // The name MUST match the directory
- $pluginversion = $type.'_'.$plug.'_version';
+ $installedversion = get_config($plugin->fullname, 'version');
- if (!isset($CFG->$pluginversion)) {
- set_config($pluginversion, 0);
+ if ($installedversion === false) {
+ set_config('version', 0, $plugin->fullname);
}
- if ($CFG->$pluginversion == $plugin->version) {
+ if ($installedversion == $plugin->version) {
// do nothing
- } else if ($CFG->$pluginversion < $plugin->version) {
+ } else if ($installedversion < $plugin->version) {
if (!$updated_plugins && !$embedded) {
print_header($strpluginsetup, $strpluginsetup,
build_navigation(array(array('name' => $strpluginsetup, 'link' => null, 'type' => 'misc'))), '',
}
@set_time_limit(0); // To allow slow databases to complete the long SQL
- if ($CFG->$pluginversion == 0) { // It's a new install of this plugin
+ if ($installedversion == 0) { // It's a new install of this plugin
/// Both old .sql files and new install.xml are supported
/// but we priorize install.xml (XMLDB) if present
if (file_exists($fullplug . '/db/install.xml')) {
/// Continue with the instalation, roles and other stuff
if ($status) {
/// OK so far, now update the plugins record
- set_config($pluginversion, $plugin->version);
+ set_config('version', $plugin->version, $plugin->fullname);
/// Install capabilities
if (!update_capabilities($type.'/'.$plug)) {
message_update_providers($type.'/'.$plug);
/// Run local install function if there is one
- if (is_readable($fullplug .'/lib.php')) {
- include_once($fullplug .'/lib.php');
+ if (is_readable($fullplug . '/lib.php')) {
+ include_once($fullplug . '/lib.php');
$installfunction = $plugin->name.'_install';
if (function_exists($installfunction)) {
if (! $installfunction() ) {
notify('Installing '. $plugin->name .' FAILED!');
}
} else { // Upgrade existing install
- /// Run de old and new upgrade functions for the module
- $newupgrade_function = 'xmldb_' . $type.'_'.$plugin->name .'_upgrade';
-
- /// Then, the new function if exists and the old one was ok
+ /// Run the upgrade function for the plugin.
+ $newupgrade_function = 'xmldb_' .$plugin->fullname .'_upgrade';
$newupgrade_status = true;
if ($newupgrade && function_exists($newupgrade_function)) {
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
$DB->set_debug(true);
}
- $newupgrade_status = $newupgrade_function($CFG->$pluginversion);
+ $newupgrade_status = $newupgrade_function($installedversion);
} else if ($newupgrade) {
notify ('Upgrade function ' . $newupgrade_function . ' was not available in ' .
$fullplug . '/db/upgrade.php');
/// Now analyze upgrade results
if ($newupgrade_status) { // No upgrading failed
/// OK so far, now update the plugins record
- set_config($pluginversion, $plugin->version);
+ set_config('version', $plugin->version, $plugin->fullname);
if (!update_capabilities($type.'/'.$plug)) {
print_error('cannotupdateplugincap', '', '', $plugin->name);
}
notify(get_string('modulesuccess', '', $plugin->name), 'notifysuccess');
} else {
- notify('Upgrading '. $plugin->name .' from '. $CFG->$pluginversion .' to '. $plugin->version .' FAILED!');
+ notify('Upgrading '. $plugin->name .' from '. $installedversion .' to '. $plugin->version .' FAILED!');
}
}
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
}
} else {
upgrade_log_start();
- print_error('cannotdowngrade', 'debug', '', (object)array('oldversion'=>$CFG->pluginversion, 'newversion'=>$plugin->version));
+ print_error('cannotdowngrade', 'debug', '', (object)array('oldversion'=>$installedversion, 'newversion'=>$plugin->version));
}
}
upgrade_main_savepoint($result, 2008090108);
}
+ // MDL-16411 Move all plugintype_pluginname_version values from config to config_plugins.
+ if ($result && $oldversion < 2008091000) {
+ foreach (get_object_vars($CFG) as $name => $value) {
+ if (substr($name, strlen($name) - 8) !== '_version') {
+ continue;
+ }
+ $pluginname = substr($name, 0, strlen($name) - 8);
+ if (!strpos($pluginname, '_')) {
+ // Skip things like backup_version that don't contain an extra _
+ continue;
+ }
+ if ($pluginname == 'enrol_ldap_version') {
+ // Special case - this is something different from a plugin version number.
+ continue;
+ }
+ if (preg_match('/^\d{10}$/', $value)) {
+ // Extra safety check, skip anything that does not look like a Moodle
+ // version number (10 digits).
+ continue;
+ }
+ $result = $result && set_config('version', $value, $pluginname);
+ $result = $result && unset_config($name);
+ }
+ upgrade_main_savepoint($result, 2008091000);
+ }
+
return $result;
}