MDL-28466 remove the enrol_authorize data
authorDan Poltawski <dan@moodle.com>
Mon, 15 Jul 2013 05:56:39 +0000 (13:56 +0800)
committerDan Poltawski <dan@moodle.com>
Mon, 15 Jul 2013 06:48:23 +0000 (14:48 +0800)
If there are no records, remove the plugin

lib/accesslib.php
lib/db/upgrade.php
lib/moodlelib.php
version.php

index a31aedd..a3e2a22 100644 (file)
@@ -2667,6 +2667,7 @@ function update_capabilities($component = 'moodle') {
 /**
  * Deletes cached capabilities that are no longer needed by the component.
  * Also unassigns these capabilities from any roles that have them.
+ * NOTE: this function is called from lib/db/upgrade.php
  *
  * @access private
  * @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results'
index b593aef..4c2e9bc 100644 (file)
@@ -2259,5 +2259,39 @@ function xmldb_main_upgrade($oldversion) {
         upgrade_main_savepoint(true, 2013070800.01);
     }
 
+    if ($oldversion < 2013071500.01) {
+        // The enrol_authorize plugin has been removed, if there are no records
+        // and no plugin files then remove the plugin data.
+        $enrolauthorize = new xmldb_table('enrol_authorize');
+        $enrolauthorizerefunds = new xmldb_table('enrol_authorize_refunds');
+
+        if (!file_exists($CFG->dirroot.'/enrol/authorize/version.php') &&
+            $dbman->table_exists($enrolauthorize) &&
+            $dbman->table_exists($enrolauthorizerefunds)) {
+
+            $enrolauthorizecount = $DB->count_records('enrol_authorize');
+            $enrolauthorizerefundcount = $DB->count_records('enrol_authorize_refunds');
+
+            if (empty($enrolauthorizecount) && empty($enrolauthorizerefundcount)) {
+
+                // Drop the database tables.
+                $dbman->drop_table($enrolauthorize);
+                $dbman->drop_table($enrolauthorizerefunds);
+
+                // Drop the message provider and associated data manually.
+                $DB->delete_records('message_providers', array('component' => 'enrol_authorize'));
+                $DB->delete_records_select('config_plugins', "plugin = 'message' AND ".$DB->sql_like('name', '?', false), array("%_provider_enrol_authorize_%"));
+                $DB->delete_records_select('user_preferences', $DB->sql_like('name', '?', false), array("message_provider_enrol_authorize_%"));
+
+                // Remove capabilities.
+                capabilities_cleanup('enrol_authorize');
+
+                // Remove all other associated config.
+                unset_all_config_for_plugin('enrol_authorize');
+            }
+        }
+        upgrade_main_savepoint(true, 2013071500.01);
+    }
+
     return true;
 }
index fcb1e18..cbcdef5 100644 (file)
@@ -1468,6 +1468,7 @@ function unset_config($name, $plugin=NULL) {
 
 /**
  * Remove all the config variables for a given plugin.
+ * NOTE: this function is called from lib/db/upgrade.php
  *
  * @param string $plugin a plugin, for example 'quiz' or 'qtype_multichoice';
  * @return boolean whether the operation succeeded.
index 8920a08..e3a379d 100644 (file)
@@ -29,7 +29,7 @@
 
 defined('MOODLE_INTERNAL') || die();
 
-$version  = 2013071500.00;              // YYYYMMDD      = weekly release date of this DEV branch
+$version  = 2013071500.01;              // YYYYMMDD      = weekly release date of this DEV branch
                                         //         RR    = release increments - 00 in DEV branches
                                         //           .XX = incremental changes