Skip to content

Commit

Permalink
Reorder the remaining active workflows when disabling a workflow (#201)
Browse files Browse the repository at this point in the history
This fixes #128.
  • Loading branch information
olivabigyo authored Mar 14, 2024
1 parent 2a33a60 commit f1ef4a6
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion classes/local/manager/workflow_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,36 @@ public static function remove($workflowid, $hard = false) {
* @throws \dml_transaction_exception
*/
public static function disable($workflowid) {
global $DB;
$transaction = $DB->start_delegated_transaction();
$workflow = self::get_workflow($workflowid);
if ($workflow && self::is_disableable($workflowid)) {
$workflow->timeactive = null;
self::remove_from_sortindex($workflow);
$workflow->sortindex = null;
$workflow->timedeactive = time();
self::insert_or_update($workflow);
$DB->update_record('tool_lifecycle_workflow', $workflow);
}
$transaction->allow_commit();
}

/**
* Removes a workflow from the sortindex.
*
* @param workflow $toberemoved
* @throws \dml_exception
* @throws \dml_transaction_exception
*/
public static function remove_from_sortindex($toberemoved) {
global $DB;
if (isset($toberemoved->sortindex)) {
$workflows = self::get_active_automatic_workflows();
foreach ($workflows as $workflow) {
if ($workflow->sortindex > $toberemoved->sortindex) {
$workflow->sortindex--;
$DB->update_record('tool_lifecycle_workflow', $workflow);
}
}
}
}

Expand Down

0 comments on commit f1ef4a6

Please sign in to comment.