diff --git a/classes/event/process_proceeded.php b/classes/event/process_proceeded.php index 5aada6de..8a6e56a0 100644 --- a/classes/event/process_proceeded.php +++ b/classes/event/process_proceeded.php @@ -35,7 +35,6 @@ * - int processid: the id of the process. * - int workflowid: the id of the workflow. * - int stepindex: the index of the step. - * - int courseid: the id of the course. * } * * @package tool_lifecycle @@ -54,12 +53,12 @@ class process_proceeded extends \core\event\base { */ public static function event_from_process($process) { $data = [ - 'context' => \context_system::instance(), + 'courseid' => $process->courseid, + 'context' => $process->context, 'other' => [ 'processid' => $process->id, 'workflowid' => $process->workflowid, 'stepindex' => $process->stepindex, - 'courseid' => $process->courseid, ], ]; return self::create($data); @@ -84,7 +83,7 @@ public function get_description() { $processid = $this->other['processid']; $workflowid = $this->other['workflowid']; $stepindex = $this->other['stepindex']; - $courseid = $this->other['courseid']; + $courseid = $this->courseid; return "The workflow with id '$workflowid' finished step '$stepindex' successfully for course '$courseid' " . "in the process with id '$processid'"; @@ -130,7 +129,7 @@ protected function validate_data() { throw new \coding_exception('The \'stepindex\' value must be set'); } - if (!isset($this->other['courseid'])) { + if (!isset($this->courseid)) { throw new \coding_exception('The \'courseid\' value must be set'); } } diff --git a/classes/event/process_rollback.php b/classes/event/process_rollback.php index cafc1031..9a76c675 100644 --- a/classes/event/process_rollback.php +++ b/classes/event/process_rollback.php @@ -54,12 +54,12 @@ class process_rollback extends \core\event\base { */ public static function event_from_process($process) { $data = [ - 'context' => \context_system::instance(), + 'courseid' => $process->courseid, + 'context' => $process->context, 'other' => [ - 'processid' => $process->id, - 'workflowid' => $process->workflowid, - 'stepindex' => $process->stepindex, - 'courseid' => $process->courseid, + 'processid' => $process->id, + 'workflowid' => $process->workflowid, + 'stepindex' => $process->stepindex, ], ]; return self::create($data); @@ -84,7 +84,7 @@ public function get_description() { $processid = $this->other['processid']; $workflowid = $this->other['workflowid']; $stepindex = $this->other['stepindex']; - $courseid = $this->other['courseid']; + $courseid = $this->courseid; return "The workflow with id '$workflowid' was rolled back on step '$stepindex' for course '$courseid' " . "in the process with id '$processid'"; @@ -130,7 +130,7 @@ protected function validate_data() { throw new \coding_exception('The \'stepindex\' value must be set'); } - if (!isset($this->other['courseid'])) { + if (!isset($this->courseid)) { throw new \coding_exception('The \'courseid\' value must be set'); } } diff --git a/classes/event/process_triggered.php b/classes/event/process_triggered.php index a71507ad..b890f679 100644 --- a/classes/event/process_triggered.php +++ b/classes/event/process_triggered.php @@ -53,11 +53,11 @@ class process_triggered extends \core\event\base { */ public static function event_from_process($process) { $data = [ - 'context' => \context_system::instance(), + 'courseid' => $process->courseid, + 'context' => \context_course::instance($process->courseid), 'other' => [ 'processid' => $process->id, 'workflowid' => $process->workflowid, - 'courseid' => $process->courseid, ], ]; return self::create($data); @@ -81,7 +81,7 @@ protected function init() { public function get_description() { $processid = $this->other['processid']; $workflowid = $this->other['workflowid']; - $courseid = $this->other['courseid']; + $courseid = $this->courseid; return "The workflow with id '$workflowid' triggered for course '$courseid' and created process with id '$processid'"; } @@ -122,7 +122,7 @@ protected function validate_data() { throw new \coding_exception('The \'workflowid\' value must be set'); } - if (!isset($this->other['courseid'])) { + if (!isset($this->courseid)) { throw new \coding_exception('The \'courseid\' value must be set'); } } diff --git a/classes/local/entity/process.php b/classes/local/entity/process.php index 3f94460e..c72cf1f0 100644 --- a/classes/local/entity/process.php +++ b/classes/local/entity/process.php @@ -50,19 +50,24 @@ class process { /** @var /timestamp $timestepchanged Date the process was moved to the current step instance */ public $timestepchanged; + /** @var int $context context of the course in the workflow */ + public $context; + /** * Process constructor. * @param int $id Id of the process. * @param int $workflowid Id of the workflow. * @param int $courseid Id of the course. + * @param int $context context of the course. * @param int $stepindex Sortindex of the step within the workflow. * @param bool $waiting True if course is in status waiting. * @param null $timestepchanged Date the process was moved to the current step instance. */ - private function __construct($id, $workflowid, $courseid, $stepindex, $waiting = false, $timestepchanged = null) { + private function __construct($id, $workflowid, $courseid, $context, $stepindex, $waiting = false, $timestepchanged = null) { $this->id = $id; $this->workflowid = $workflowid; $this->courseid = $courseid; + $this->context = $context; $this->waiting = $waiting; $this->stepindex = $stepindex; if ($timestepchanged === null) { @@ -99,7 +104,14 @@ public static function from_record($record) { $stepindex = 0; } - $instance = new self($record->id, $record->workflowid, $record->courseid, $stepindex, $waiting, $record->timestepchanged); + $context = \context_course::instance($record->courseid); + $instance = new self($record->id, + $record->workflowid, + $record->courseid, + $context, + $stepindex, + $waiting, + $record->timestepchanged); return $instance; } diff --git a/classes/local/manager/process_manager.php b/classes/local/manager/process_manager.php index ca92f0de..d889c85a 100644 --- a/classes/local/manager/process_manager.php +++ b/classes/local/manager/process_manager.php @@ -156,6 +156,7 @@ public static function proceed_process(&$process) { $DB->update_record('tool_lifecycle_process', $process); return true; } else { + unset($process->context); self::remove_process($process); return false; } @@ -180,6 +181,7 @@ public static function set_process_waiting(&$process) { */ public static function rollback_process($process) { process_rollback::event_from_process($process)->trigger(); + unset($process->context); for ($i = $process->stepindex; $i >= 1; $i--) { $step = step_manager::get_step_instance_by_workflow_index($process->workflowid, $i); $lib = lib_manager::get_step_lib($step->subpluginname); diff --git a/classes/processor.php b/classes/processor.php index 81a0e73f..b4377c60 100644 --- a/classes/processor.php +++ b/classes/processor.php @@ -123,6 +123,7 @@ public function process_courses() { $result = $lib->process_course($process->id, $step->id, $course); } } catch (\Exception $e) { + unset($process->context); process_manager::insert_process_error($process, $e); break; } diff --git a/tests/process_status_message_test.php b/tests/process_status_message_test.php index ecb0855a..0933d05a 100644 --- a/tests/process_status_message_test.php +++ b/tests/process_status_message_test.php @@ -76,8 +76,9 @@ public function setUp(): void { * Test getting status message for a process. * @covers \tool_lifecycle\local\manager\interaction_manager */ - public function test_get_status_message(): void { - $process = $this->generator->create_process(2, $this->workflow->id); + public function test_get_status_message() { + $course = $this->getDataGenerator()->create_course(); + $process = $this->generator->create_process($course->id, $this->workflow->id); $message = \tool_lifecycle\local\manager\interaction_manager::get_process_status_message($process->id); $this->assertEquals(get_string("workflow_started", "tool_lifecycle"), $message);