diff --git a/classes/local/manager/workflow_manager.php b/classes/local/manager/workflow_manager.php index 16a3552d..2bcc7bb0 100644 --- a/classes/local/manager/workflow_manager.php +++ b/classes/local/manager/workflow_manager.php @@ -68,6 +68,8 @@ public static function insert_or_update(workflow &$workflow) { public static function remove($workflowid, $hard = false) { global $DB; if ($hard || self::is_removable($workflowid)) { + $workflow = self::get_workflow($workflowid); + // self::remove_from_sortindex($workflow); trigger_manager::remove_instances_of_workflow($workflowid); step_manager::remove_instances_of_workflow($workflowid); $DB->delete_records('tool_lifecycle_workflow', ['id' => $workflowid]); diff --git a/db/upgrade.php b/db/upgrade.php index 5cd87a33..cf580022 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -22,6 +22,17 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +function tool_lifecycle_fix_workflow_sortindex() { + $workflows = \tool_lifecycle\local\manager\workflow_manager::get_active_workflows(); + for ($i = 1; $i <= count($workflows); $i++) { + $workflow = $workflows[$i - 1]; + if ($workflow->sortindex != $i) { + $workflow->sortindex = $i; + \tool_lifecycle\local\manager\workflow_manager::insert_or_update($workflow); + } + } +} + /** * Update script for tool_lifecycle. * @param int $oldversion Version id of the previously installed version. @@ -475,5 +486,14 @@ function xmldb_tool_lifecycle_upgrade($oldversion) { upgrade_plugin_savepoint(true, 2021112300, 'tool', 'lifecycle'); } + if ($oldversion < 2024042300) { + + tool_lifecycle_fix_workflow_sortindex(); + + // Lifecycle savepoint reached. + upgrade_plugin_savepoint(true, 2024042300, 'tool', 'lifecycle'); + + } + return true; } diff --git a/version.php b/version.php index 28244903..618a4f8e 100644 --- a/version.php +++ b/version.php @@ -25,7 +25,7 @@ defined('MOODLE_INTERNAL') || die; $plugin->maturity = MATURITY_BETA; -$plugin->version = 2024022000; +$plugin->version = 2024042300; $plugin->component = 'tool_lifecycle'; $plugin->requires = 2020061500; // Requires Moodle 3.9+. $plugin->release = 'v4.2-r1';