Skip to content

Commit

Permalink
MDL-16411 Move all plugintype_pluginname_version values from config t…
Browse files Browse the repository at this point in the history
…o config_plugins
  • Loading branch information
tjhunt committed Sep 10, 2008
1 parent 0b88fed commit d849880
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 19 deletions.
56 changes: 38 additions & 18 deletions lib/adminlib.php
Expand Up @@ -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) {
Expand Down Expand Up @@ -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'))), '',
Expand All @@ -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')) {
Expand All @@ -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)) {
Expand All @@ -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() ) {
Expand All @@ -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');
Expand All @@ -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);
}
Expand All @@ -440,15 +460,15 @@ 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 ) {
echo '<hr />';
}
} 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));
}
}

Expand Down
26 changes: 26 additions & 0 deletions lib/db/upgrade.php
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion version.php
Expand Up @@ -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
Expand Down

0 comments on commit d849880

Please sign in to comment.