Skip to content

Commit f1ef4a6

Browse files
authored
Reorder the remaining active workflows when disabling a workflow (#201)
This fixes #128.
1 parent 2a33a60 commit f1ef4a6

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

classes/local/manager/workflow_manager.php

+25-1
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,36 @@ public static function remove($workflowid, $hard = false) {
8282
* @throws \dml_transaction_exception
8383
*/
8484
public static function disable($workflowid) {
85+
global $DB;
86+
$transaction = $DB->start_delegated_transaction();
8587
$workflow = self::get_workflow($workflowid);
8688
if ($workflow && self::is_disableable($workflowid)) {
8789
$workflow->timeactive = null;
90+
self::remove_from_sortindex($workflow);
8891
$workflow->sortindex = null;
8992
$workflow->timedeactive = time();
90-
self::insert_or_update($workflow);
93+
$DB->update_record('tool_lifecycle_workflow', $workflow);
94+
}
95+
$transaction->allow_commit();
96+
}
97+
98+
/**
99+
* Removes a workflow from the sortindex.
100+
*
101+
* @param workflow $toberemoved
102+
* @throws \dml_exception
103+
* @throws \dml_transaction_exception
104+
*/
105+
public static function remove_from_sortindex($toberemoved) {
106+
global $DB;
107+
if (isset($toberemoved->sortindex)) {
108+
$workflows = self::get_active_automatic_workflows();
109+
foreach ($workflows as $workflow) {
110+
if ($workflow->sortindex > $toberemoved->sortindex) {
111+
$workflow->sortindex--;
112+
$DB->update_record('tool_lifecycle_workflow', $workflow);
113+
}
114+
}
91115
}
92116
}
93117

0 commit comments

Comments
 (0)