From c2ca2d8e9126f7446b2440af228e6bae0adc67e0 Mon Sep 17 00:00:00 2001 From: Dan Poltawski Date: Mon, 15 Jul 2013 13:56:39 +0800 Subject: [PATCH] MDL-28466 remove the enrol_authorize data If there are no records, remove the plugin --- lib/accesslib.php | 1 + lib/db/upgrade.php | 34 ++++++++++++++++++++++++++++++++++ lib/moodlelib.php | 1 + version.php | 2 +- 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/accesslib.php b/lib/accesslib.php index a31aedd4b52..a3e2a224eb0 100644 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -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' diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index b593aef76f5..4c2e9bc3acd 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -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; } diff --git a/lib/moodlelib.php b/lib/moodlelib.php index fcb1e18f62e..cbcdef58079 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -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. diff --git a/version.php b/version.php index 8920a08849a..e3a379dee50 100644 --- a/version.php +++ b/version.php @@ -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