From c0fdc91ea3315ef2e452ed53b39556cb1f5620fb Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Thu, 6 Feb 2020 09:10:17 +0000 Subject: [PATCH] MDL-67891 tool_cohortroles: move upgrade step inside plugin. The step added in MDL-67458 was added to core, which broke the upgrade process if this plugin had been uninstalled prior. --- admin/tool/cohortroles/db/upgrade.php | 45 +++++++++++++++++++++++++++ admin/tool/cohortroles/version.php | 2 +- lib/db/upgrade.php | 3 -- 3 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 admin/tool/cohortroles/db/upgrade.php diff --git a/admin/tool/cohortroles/db/upgrade.php b/admin/tool/cohortroles/db/upgrade.php new file mode 100644 index 00000000000..ced8aafc951 --- /dev/null +++ b/admin/tool/cohortroles/db/upgrade.php @@ -0,0 +1,45 @@ +. + +/** + * Plugin upgrade code + * + * @package tool_cohortroles + * @copyright 2020 Paul Holden + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * Function to upgrade tool_cohortroles. + * + * @param int $oldversion the version we are upgrading from + * @return bool result + */ +function xmldb_tool_cohortroles_upgrade($oldversion) { + global $DB; + + if ($oldversion < 2019052001) { + // Delete any tool_cohortroles mappings for roles which no longer exist. + $DB->delete_records_select('tool_cohortroles', 'roleid NOT IN (SELECT id FROM {role})'); + + // Cohortroles savepoint reached. + upgrade_plugin_savepoint(true, 2019052001, 'tool', 'cohortroles'); + } + + return true; +} diff --git a/admin/tool/cohortroles/version.php b/admin/tool/cohortroles/version.php index d740274c0d0..65ee82b9c5d 100644 --- a/admin/tool/cohortroles/version.php +++ b/admin/tool/cohortroles/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2019052000; // The current plugin version (Date: YYYYMMDDXX). +$plugin->version = 2019052001; // The current plugin version (Date: YYYYMMDDXX). $plugin->requires = 2019051100; // Requires this Moodle version. $plugin->component = 'tool_cohortroles'; // Full name of the plugin (used for diagnostics). diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 993679dcd8e..234f7a20f09 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -3449,9 +3449,6 @@ function xmldb_main_upgrade($oldversion) { } if ($oldversion < 2019052003.05) { - // Delete any tool_cohortroles mappings for roles which no longer exist. - $DB->delete_records_select('tool_cohortroles', "roleid NOT IN (SELECT id FROM {role})"); - // Delete any role assignments for roles which no longer exist. $DB->delete_records_select('role_assignments', "roleid NOT IN (SELECT id FROM {role})");