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 ;
27- use tool_lifecycle \local \manager \workflow_manager ;
25+ use \tool_lifecycle \local \manager \workflow_manager ;
2826
2927/**
3028 * Fix any gaps in the workflows sortindex.
@@ -569,16 +567,11 @@ function xmldb_tool_lifecycle_upgrade($oldversion) {
569567 $ pluginmanager = core_plugin_manager::instance ();
570568 if ($ plugininfo = $ pluginmanager ->get_plugin_info ('lifecycletrigger_sitecourse ' )) {
571569 $ trace = new \null_progress_trace ();
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 );
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 );
580574 }
581- $ pluginmanager ->uninstall_plugin ($ plugininfo ->component , $ trace );
582575 $ purgecaches = true ;
583576 } else {
584577 $ DB ->set_field ('tool_lifecycle_workflow ' , 'includesitecourse ' , 1 );
@@ -588,16 +581,11 @@ function xmldb_tool_lifecycle_upgrade($oldversion) {
588581 $ pluginmanager = core_plugin_manager::instance ();
589582 if ($ plugininfo = $ pluginmanager ->get_plugin_info ('lifecycletrigger_delayedcourses ' )) {
590583 $ trace = new \null_progress_trace ();
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 );
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 );
599588 }
600- $ pluginmanager ->uninstall_plugin ($ plugininfo ->component , $ trace );
601589 $ purgecaches = true ;
602590 } else {
603591 $ DB ->set_field ('tool_lifecycle_workflow ' , 'includedelayedcourses ' , 1 );
0 commit comments