|
22 | 22 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
23 | 23 | */ |
24 | 24 |
|
| 25 | +use tool_lifecycle\local\manager\step_manager; |
| 26 | +use tool_lifecycle\local\manager\trigger_manager; |
25 | 27 | use tool_lifecycle\local\manager\workflow_manager; |
26 | 28 |
|
27 | 29 | /** |
@@ -562,30 +564,40 @@ function xmldb_tool_lifecycle_upgrade($oldversion) { |
562 | 564 | $dbman->add_field($table, $field); |
563 | 565 | } |
564 | 566 |
|
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. |
566 | 568 | $purgecaches = false; |
567 | 569 | $pluginmanager = core_plugin_manager::instance(); |
568 | 570 | if ($plugininfo = $pluginmanager->get_plugin_info('lifecycletrigger_sitecourse')) { |
569 | 571 | $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); |
574 | 580 | } |
| 581 | + $pluginmanager->uninstall_plugin($plugininfo->component, $trace); |
575 | 582 | $purgecaches = true; |
576 | 583 | } else { |
577 | 584 | $DB->set_field('tool_lifecycle_workflow', 'includesitecourse', 1); |
578 | 585 | } |
579 | 586 |
|
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. |
581 | 588 | $pluginmanager = core_plugin_manager::instance(); |
582 | 589 | if ($plugininfo = $pluginmanager->get_plugin_info('lifecycletrigger_delayedcourses')) { |
583 | 590 | $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); |
588 | 599 | } |
| 600 | + $pluginmanager->uninstall_plugin($plugininfo->component, $trace); |
589 | 601 | $purgecaches = true; |
590 | 602 | } else { |
591 | 603 | $DB->set_field('tool_lifecycle_workflow', 'includedelayedcourses', 1); |
|
0 commit comments