Script for downgrading moodle version numbers
authorAdrian Greeve <adrian@moodle.com>
Fri, 11 Sep 2015 06:00:37 +0000 (14:00 +0800)
committerFrederic Massart <fred@moodle.com>
Wed, 16 Sep 2015 04:14:02 +0000 (12:14 +0800)
This will check to see if the main version number and any plugins have
a status of downgraded (The version number in the database is
higher than the new one). Then it will change the version numbers
in the config_plugin table.

mdk/scripts/version.php [new file with mode: 0644]

diff --git a/mdk/scripts/version.php b/mdk/scripts/version.php
new file mode 100644 (file)
index 0000000..f26e326
--- /dev/null
@@ -0,0 +1,45 @@
+<?php
+
+define('CLI_SCRIPT', true);
+require(dirname(__FILE__).'/config.php');
+require_once($CFG->libdir.'/clilib.php');
+require("$CFG->dirroot/version.php");
+
+// Purge caches to ensure that all version information is up-to-date.
+purge_all_caches();
+
+cli_separator();
+cli_heading('Update all version numbers');
+
+$possiblecandidates = array();
+
+// Check that the main version hasn't changed.
+$versiondifference = false;
+if ((float)$CFG->version !== $version) {
+    $versiondifference = true;
+}
+
+$pluginmanager = core_plugin_manager::instance();
+$plugininfo = $pluginmanager->get_plugins();
+foreach ($plugininfo as $plugins) {
+    foreach ($plugins as $key => $plugin) {
+        $statuscode = $plugin->get_status();
+        if ($statuscode == "downgrade") {
+            $possiblecandidates[] = $plugin;
+        }
+    }
+}
+
+// Fix everything.
+if ($versiondifference) {
+    set_config('version', $version);
+    mtrace('Main version updated');
+}
+if (!empty($possiblecandidates)) {
+
+    foreach ($possiblecandidates as $plugin) {
+        $name = $plugin->type . '_' . $plugin->name;
+        set_config('version', $plugin->versiondisk, $name);
+        mtrace($plugin->displayname . ' updated.');
+    }
+}