Skip to content

Commit 5e9f660

Browse files
committed
fix upgrade job to remove sitecourse and delayedcourses trigger
1 parent 536cb74 commit 5e9f660

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

db/upgrade.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2323
*/
2424

25+
use tool_lifecycle\local\manager\step_manager;
26+
use tool_lifecycle\local\manager\trigger_manager;
2527
use tool_lifecycle\local\manager\workflow_manager;
2628

2729
/**
@@ -562,30 +564,40 @@ function xmldb_tool_lifecycle_upgrade($oldversion) {
562564
$dbman->add_field($table, $field);
563565
}
564566

565-
// Remove sitecourse subplugin if there is one. Otherwise set all workflows to includesitecourse = 1.
567+
// Remove sitecourse subplugin if there is one, otherwise set all workflows to includesitecourse = 1.
566568
$purgecaches = false;
567569
$pluginmanager = core_plugin_manager::instance();
568570
if ($plugininfo = $pluginmanager->get_plugin_info('lifecycletrigger_sitecourse')) {
569571
$trace = new \null_progress_trace();
570-
$plugininfo->uninstall($trace);
571-
if ($pluginmanager->is_plugin_folder_removable($plugininfo->component)) {
572-
$pluginmanager->uninstall_plugin($plugininfo->component, $trace);
573-
$pluginmanager->remove_plugin_folder($plugininfo);
572+
$instances = trigger_manager::get_instances('lifecycletrigger_sitecourse');
573+
foreach ($instances as $instance) {
574+
$workflow = workflow_manager::get_workflow($instance->workflowid);
575+
if (step_manager::count_steps_of_workflow($workflow->id) > 0) {
576+
throw new \moodle_exception('There should be no steps for the workflow of the trigger ' .
577+
'lifecycletrigger_sitecourse');
578+
}
579+
workflow_manager::remove($workflow->id);
574580
}
581+
$pluginmanager->uninstall_plugin($plugininfo->component, $trace);
575582
$purgecaches = true;
576583
} else {
577584
$DB->set_field('tool_lifecycle_workflow', 'includesitecourse', 1);
578585
}
579586

580-
// Remove delayedcourses subplugin if there is one. Otherwise set all workflows to includedelayedcourses = 1.
587+
// Remove delayedcourses subplugin if there is one, otherwise set all workflows to includedelayedcourses = 1.
581588
$pluginmanager = core_plugin_manager::instance();
582589
if ($plugininfo = $pluginmanager->get_plugin_info('lifecycletrigger_delayedcourses')) {
583590
$trace = new \null_progress_trace();
584-
$plugininfo->uninstall($trace);
585-
if ($pluginmanager->is_plugin_folder_removable($plugininfo->component)) {
586-
$pluginmanager->uninstall_plugin($plugininfo->component, $trace);
587-
$pluginmanager->remove_plugin_folder($plugininfo);
591+
$instances = trigger_manager::get_instances('lifecycletrigger_delayedcourses');
592+
foreach ($instances as $instance) {
593+
$workflow = workflow_manager::get_workflow($instance->workflowid);
594+
if (step_manager::count_steps_of_workflow($workflow->id) > 0) {
595+
throw new \moodle_exception('There should be no steps for the workflow of the trigger ' .
596+
'lifecycletrigger_delayedcourses');
597+
}
598+
workflow_manager::remove($workflow->id);
588599
}
600+
$pluginmanager->uninstall_plugin($plugininfo->component, $trace);
589601
$purgecaches = true;
590602
} else {
591603
$DB->set_field('tool_lifecycle_workflow', 'includedelayedcourses', 1);

0 commit comments

Comments
 (0)