diff --git a/lib/adminlib.php b/lib/adminlib.php index 7c800b4b8a561..fae4e7088f2cc 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -120,7 +120,28 @@ function upgrade_blocks_savepoint($result, $version, $blockname) { } 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) { @@ -344,16 +365,17 @@ function upgrade_plugins($type, $dir, $return) { } $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'))), '', @@ -367,7 +389,7 @@ function upgrade_plugins($type, $dir, $return) { } @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')) { @@ -380,7 +402,7 @@ function upgrade_plugins($type, $dir, $return) { /// 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)) { @@ -393,8 +415,8 @@ function upgrade_plugins($type, $dir, $return) { 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() ) { @@ -408,16 +430,14 @@ function upgrade_plugins($type, $dir, $return) { 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'); @@ -428,7 +448,7 @@ function upgrade_plugins($type, $dir, $return) { /// 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); } @@ -440,7 +460,7 @@ function upgrade_plugins($type, $dir, $return) { 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 ) { @@ -448,7 +468,7 @@ function upgrade_plugins($type, $dir, $return) { } } 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)); } } diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index e9c1901c53580..eb84e0b19bbff 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -799,6 +799,32 @@ function xmldb_main_upgrade($oldversion) { 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; } diff --git a/version.php b/version.php index 28dc481d7b9b6..9f7307ed1e438 100644 --- a/version.php +++ b/version.php @@ -6,7 +6,7 @@ // This is compared against the values stored in the database to determine // 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 $release = '2.0 dev (Build: 20080910)'; // Human-friendly version name