Skip to content
Snippets Groups Projects
Commit 7dff2888 authored by Justus Dieckmann's avatar Justus Dieckmann
Browse files

Add Upgrade-Step that removes processes with deleted courses

parent 30abb343
Branches
Tags
No related merge requests found
......@@ -230,10 +230,19 @@ class process_manager {
public static function course_deletion_observed($event) {
$process = self::get_process_by_course_id($event->get_data()['courseid']);
if ($process) {
self::abort_process($process);
}
}
/**
* Aborts a running process.
* @param process $process The process to abort.
* @throws \dml_exception
*/
public static function abort_process($process) {
$step = step_manager::get_step_instance_by_workflow_index($process->workflowid, $process->stepindex);
$steplib = lib_manager::get_step_lib($step->subpluginname);
$steplib->abort_course($process);
self::remove_process($process);
}
}
}
......@@ -433,5 +433,18 @@ function xmldb_tool_lifecycle_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2019082300, 'tool', 'lifecycle');
}
if ($oldversion < 2020091800) {
$sql = "SELECT p.* FROM {tool_lifecycle_process} p " .
"LEFT JOIN {course} c ON p.courseid = c.id " .
"WHERE c.id IS NULL";
$processes = $DB->get_records_sql($sql);
foreach ($processes as $procrecord) {
$process = \tool_lifecycle\local\entity\process::from_record($procrecord);
\tool_lifecycle\local\manager\process_manager::abort_process($process);
}
upgrade_plugin_savepoint(true, 2020091800, 'tool', 'lifecycle');
}
return true;
}
\ No newline at end of file
......@@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die;
$plugin->maturity = MATURITY_BETA;
$plugin->version = 2020060500;
$plugin->version = 2020091800;
$plugin->component = 'tool_lifecycle';
$plugin->requires = 2017111300; // Require Moodle 3.4 (or above).
$plugin->release = 'v3.9-r1';
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment