@@ -82,12 +82,36 @@ public static function remove($workflowid, $hard = false) {
82
82
* @throws \dml_transaction_exception
83
83
*/
84
84
public static function disable ($ workflowid ) {
85
+ global $ DB ;
86
+ $ transaction = $ DB ->start_delegated_transaction ();
85
87
$ workflow = self ::get_workflow ($ workflowid );
86
88
if ($ workflow && self ::is_disableable ($ workflowid )) {
87
89
$ workflow ->timeactive = null ;
90
+ self ::remove_from_sortindex ($ workflow );
88
91
$ workflow ->sortindex = null ;
89
92
$ 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
+ }
91
115
}
92
116
}
93
117
0 commit comments