From 7416c93c087317bb19a9ee55cdf7215c916355a4 Mon Sep 17 00:00:00 2001 From: Melanie Treitinger Date: Wed, 27 Mar 2024 15:35:26 +0100 Subject: [PATCH] Use field courseid for logging events --- classes/event/process_proceeded.php | 9 ++++----- classes/event/process_rollback.php | 14 +++++++------- classes/event/process_triggered.php | 8 ++++---- tests/process_status_message_test.php | 3 ++- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/classes/event/process_proceeded.php b/classes/event/process_proceeded.php index 5aada6de..0e6149ff 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(), + 'context' => \context_course::instance($process->courseid), + 'courseid' => $process->courseid, '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..93eb3f7e 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(), + 'context' => \context_course::instance($process->courseid), + 'courseid' => $process->courseid, '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..aa27c47a 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(), + 'context' => \context_course::instance($process->courseid), + 'courseid' => $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/tests/process_status_message_test.php b/tests/process_status_message_test.php index dad40e11..ffd15a4b 100644 --- a/tests/process_status_message_test.php +++ b/tests/process_status_message_test.php @@ -77,7 +77,8 @@ public function setUp() : void { * @covers \tool_lifecycle\local\manager\interaction_manager */ public function test_get_status_message() { - $process = $this->generator->create_process(2, $this->workflow->id); + $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);