@@ -58,28 +58,26 @@ public static function delete_rules_parameters(): external_function_parameters {
58
58
* @return array
59
59
*/
60
60
public static function delete_rules (array $ ruleids ): array {
61
- global $ DB ;
62
-
63
61
self ::validate_parameters (self ::delete_rules_parameters (), ['ruleids ' => $ ruleids ]);
64
62
65
63
$ context = context_system::instance ();
66
64
self ::validate_context ($ context );
67
65
require_capability ('tool/dynamic_cohorts:manage ' , $ context );
68
66
69
67
// We would like to treat deletion for multiple rules as one operation.
70
- // If one failed we would like to fail whole call and roll back.
71
- $ transaction = $ DB ->start_delegated_transaction ();
72
- try {
73
- foreach ($ ruleids as $ ruleid ) {
74
- $ rule = rule::get_record (['id ' => (int ) $ ruleid ]);
75
- if (empty ($ rule )) {
76
- throw new invalid_parameter_exception ('Rule does not exist. ID: ' . $ ruleid );
77
- }
78
- rule_manager::delete_rule ($ rule );
79
- //$transaction->allow_commit();
68
+ // So let's check that all rules exist and then delete them.
69
+ // Otherwise throw an exception and fail whole WS call.
70
+ $ rulestodelete = [];
71
+ foreach ($ ruleids as $ ruleid ) {
72
+ $ rule = rule::get_record (['id ' => (int ) $ ruleid ]);
73
+ if (empty ($ rule )) {
74
+ throw new invalid_parameter_exception ('Rule does not exist. ID: ' . $ ruleid );
80
75
}
81
- } catch (throwable $ ex ) {
82
- $ transaction ->rollback ($ ex );
76
+ $ rulestodelete [] = $ rule ;
77
+ }
78
+
79
+ foreach ($ rulestodelete as $ rule ) {
80
+ rule_manager::delete_rule ($ rule );
83
81
}
84
82
85
83
return [];
0 commit comments