Skip to content

Commit

Permalink
Fix sortindex gaps in upgrade step
Browse files Browse the repository at this point in the history
  • Loading branch information
justusdieckmann committed Apr 24, 2024
1 parent e6190e8 commit 5b31c19
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions classes/local/manager/workflow_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
20 changes: 20 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

0 comments on commit 5b31c19

Please sign in to comment.