Skip to content

Commit a3559b2

Browse files
committed
improve uninstall
1 parent 243c93e commit a3559b2

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

classes/plugininfo/lifecycletrigger.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,14 @@ public function is_uninstall_allowed() {
5050
if ($this->is_standard()) {
5151
return false;
5252
}
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+
}
6061
}
6162
}
6263
}
@@ -70,17 +71,18 @@ public function is_uninstall_allowed() {
7071
* @throws \moodle_exception
7172
*/
7273
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);
8285
}
83-
workflow_manager::remove($workflow->id);
8486
}
8587
}
8688
return true;

0 commit comments

Comments
 (0)