@@ -50,13 +50,14 @@ public function is_uninstall_allowed() {
50
50
if ($ this ->is_standard ()) {
51
51
return false ;
52
52
}
53
- $ lib = lib_manager::get_trigger_lib ($ this ->name );
54
- if ($ lib ->has_multiple_instances ()) {
55
- // Only allow to uninstall if no active workflow for the trigger is present.
56
- $ triggers = trigger_manager::get_instances ($ this ->name );
57
- foreach ($ triggers as $ trigger ) {
58
- if (workflow_manager::is_active ($ trigger ->workflowid )) {
59
- return false ;
53
+ if ($ lib = lib_manager::get_trigger_lib ($ this ->name )) {
54
+ if ($ lib ->has_multiple_instances ()) {
55
+ // Only allow to uninstall if no active workflow for the trigger is present.
56
+ $ triggers = trigger_manager::get_instances ($ this ->name );
57
+ foreach ($ triggers as $ trigger ) {
58
+ if (workflow_manager::is_active ($ trigger ->workflowid )) {
59
+ return false ;
60
+ }
60
61
}
61
62
}
62
63
}
@@ -70,17 +71,18 @@ public function is_uninstall_allowed() {
70
71
* @throws \moodle_exception
71
72
*/
72
73
public function uninstall (\progress_trace $ progress ) {
73
- $ lib = lib_manager::get_trigger_lib ($ this ->name );
74
- if ($ lib ->has_multiple_instances ()) {
75
- trigger_manager::remove_all_instances ($ this ->name );
76
- } else {
77
- $ instances = trigger_manager::get_instances ($ this ->name );
78
- foreach ($ instances as $ instance ) {
79
- $ workflow = workflow_manager::get_workflow ($ instance ->workflowid );
80
- if (step_manager::count_steps_of_workflow ($ workflow ->id ) > 0 ) {
81
- throw new \moodle_exception ('There should be no steps for the workflow of the trigger ' . $ this ->name );
74
+ if ($ lib = lib_manager::get_trigger_lib ($ this ->name )) {
75
+ if ($ lib ->has_multiple_instances ()) {
76
+ trigger_manager::remove_all_instances ($ this ->name );
77
+ } else {
78
+ $ instances = trigger_manager::get_instances ($ this ->name );
79
+ foreach ($ instances as $ instance ) {
80
+ $ workflow = workflow_manager::get_workflow ($ instance ->workflowid );
81
+ if (step_manager::count_steps_of_workflow ($ workflow ->id ) > 0 ) {
82
+ throw new \moodle_exception ('There should be no steps for the workflow of the trigger ' . $ this ->name );
83
+ }
84
+ workflow_manager::remove ($ workflow ->id );
82
85
}
83
- workflow_manager::remove ($ workflow ->id );
84
86
}
85
87
}
86
88
return true ;
0 commit comments