MDL-16411 Move all plugintype_pluginname_version values from config to config_plugins

This commit is contained in:
tjhunt 2008-09-10 10:15:05 +00:00
parent 0b88fedf88
commit d849880e56
3 changed files with 65 additions and 19 deletions

View file

@ -120,7 +120,28 @@ function upgrade_blocks_savepoint($result, $version, $blockname) {
} }
function upgrade_plugin_savepoint($result, $version, $type, $dir) { 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) { function upgrade_backup_savepoint($result, $version) {
@ -344,16 +365,17 @@ function upgrade_plugins($type, $dir, $return) {
} }
$plugin->name = $plug; // The name MUST match the directory $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)) { if ($installedversion === false) {
set_config($pluginversion, 0); set_config('version', 0, $plugin->fullname);
} }
if ($CFG->$pluginversion == $plugin->version) { if ($installedversion == $plugin->version) {
// do nothing // do nothing
} else if ($CFG->$pluginversion < $plugin->version) { } else if ($installedversion < $plugin->version) {
if (!$updated_plugins && !$embedded) { if (!$updated_plugins && !$embedded) {
print_header($strpluginsetup, $strpluginsetup, print_header($strpluginsetup, $strpluginsetup,
build_navigation(array(array('name' => $strpluginsetup, 'link' => null, 'type' => 'misc'))), '', build_navigation(array(array('name' => $strpluginsetup, 'link' => null, 'type' => 'misc'))), '',
@ -367,7 +389,7 @@ function upgrade_plugins($type, $dir, $return) {
} }
@set_time_limit(0); // To allow slow databases to complete the long SQL @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 /// Both old .sql files and new install.xml are supported
/// but we priorize install.xml (XMLDB) if present /// but we priorize install.xml (XMLDB) if present
if (file_exists($fullplug . '/db/install.xml')) { if (file_exists($fullplug . '/db/install.xml')) {
@ -380,7 +402,7 @@ function upgrade_plugins($type, $dir, $return) {
/// Continue with the instalation, roles and other stuff /// Continue with the instalation, roles and other stuff
if ($status) { if ($status) {
/// OK so far, now update the plugins record /// OK so far, now update the plugins record
set_config($pluginversion, $plugin->version); set_config('version', $plugin->version, $plugin->fullname);
/// Install capabilities /// Install capabilities
if (!update_capabilities($type.'/'.$plug)) { if (!update_capabilities($type.'/'.$plug)) {
@ -393,8 +415,8 @@ function upgrade_plugins($type, $dir, $return) {
message_update_providers($type.'/'.$plug); message_update_providers($type.'/'.$plug);
/// Run local install function if there is one /// Run local install function if there is one
if (is_readable($fullplug .'/lib.php')) { if (is_readable($fullplug . '/lib.php')) {
include_once($fullplug .'/lib.php'); include_once($fullplug . '/lib.php');
$installfunction = $plugin->name.'_install'; $installfunction = $plugin->name.'_install';
if (function_exists($installfunction)) { if (function_exists($installfunction)) {
if (! $installfunction() ) { if (! $installfunction() ) {
@ -408,16 +430,14 @@ function upgrade_plugins($type, $dir, $return) {
notify('Installing '. $plugin->name .' FAILED!'); notify('Installing '. $plugin->name .' FAILED!');
} }
} else { // Upgrade existing install } else { // Upgrade existing install
/// Run de old and new upgrade functions for the module /// Run the upgrade function for the plugin.
$newupgrade_function = 'xmldb_' . $type.'_'.$plugin->name .'_upgrade'; $newupgrade_function = 'xmldb_' .$plugin->fullname .'_upgrade';
/// Then, the new function if exists and the old one was ok
$newupgrade_status = true; $newupgrade_status = true;
if ($newupgrade && function_exists($newupgrade_function)) { if ($newupgrade && function_exists($newupgrade_function)) {
if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) { if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
$DB->set_debug(true); $DB->set_debug(true);
} }
$newupgrade_status = $newupgrade_function($CFG->$pluginversion); $newupgrade_status = $newupgrade_function($installedversion);
} else if ($newupgrade) { } else if ($newupgrade) {
notify ('Upgrade function ' . $newupgrade_function . ' was not available in ' . notify ('Upgrade function ' . $newupgrade_function . ' was not available in ' .
$fullplug . '/db/upgrade.php'); $fullplug . '/db/upgrade.php');
@ -428,7 +448,7 @@ function upgrade_plugins($type, $dir, $return) {
/// Now analyze upgrade results /// Now analyze upgrade results
if ($newupgrade_status) { // No upgrading failed if ($newupgrade_status) { // No upgrading failed
/// OK so far, now update the plugins record /// 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)) { if (!update_capabilities($type.'/'.$plug)) {
print_error('cannotupdateplugincap', '', '', $plugin->name); print_error('cannotupdateplugincap', '', '', $plugin->name);
} }
@ -440,7 +460,7 @@ function upgrade_plugins($type, $dir, $return) {
notify(get_string('modulesuccess', '', $plugin->name), 'notifysuccess'); notify(get_string('modulesuccess', '', $plugin->name), 'notifysuccess');
} else { } 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 ) { if (!defined('CLI_UPGRADE') || !CLI_UPGRADE ) {
@ -448,7 +468,7 @@ function upgrade_plugins($type, $dir, $return) {
} }
} else { } else {
upgrade_log_start(); 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));
} }
} }

View file

@ -799,6 +799,32 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint($result, 2008090108); 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; return $result;
} }

View file

@ -6,7 +6,7 @@
// This is compared against the values stored in the database to determine // This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php) // whether upgrades should be performed (see lib/db/*.php)
$version = 2008090800; // YYYYMMDD = date of the last version bump $version = 2008091000; // YYYYMMDD = date of the last version bump
// XX = daily increments // XX = daily increments
$release = '2.0 dev (Build: 20080910)'; // Human-friendly version name $release = '2.0 dev (Build: 20080910)'; // Human-friendly version name