Skip to content

Commit eea82d4

Browse files
Use field courseid for logging events (#203)
1 parent d6d55be commit eea82d4

File tree

7 files changed

+35
-20
lines changed

7 files changed

+35
-20
lines changed

classes/event/process_proceeded.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
* - int processid: the id of the process.
3636
* - int workflowid: the id of the workflow.
3737
* - int stepindex: the index of the step.
38-
* - int courseid: the id of the course.
3938
* }
4039
*
4140
* @package tool_lifecycle
@@ -54,12 +53,12 @@ class process_proceeded extends \core\event\base {
5453
*/
5554
public static function event_from_process($process) {
5655
$data = [
57-
'context' => \context_system::instance(),
56+
'courseid' => $process->courseid,
57+
'context' => $process->context,
5858
'other' => [
5959
'processid' => $process->id,
6060
'workflowid' => $process->workflowid,
6161
'stepindex' => $process->stepindex,
62-
'courseid' => $process->courseid,
6362
],
6463
];
6564
return self::create($data);
@@ -84,7 +83,7 @@ public function get_description() {
8483
$processid = $this->other['processid'];
8584
$workflowid = $this->other['workflowid'];
8685
$stepindex = $this->other['stepindex'];
87-
$courseid = $this->other['courseid'];
86+
$courseid = $this->courseid;
8887

8988
return "The workflow with id '$workflowid' finished step '$stepindex' successfully for course '$courseid' " .
9089
"in the process with id '$processid'";
@@ -130,7 +129,7 @@ protected function validate_data() {
130129
throw new \coding_exception('The \'stepindex\' value must be set');
131130
}
132131

133-
if (!isset($this->other['courseid'])) {
132+
if (!isset($this->courseid)) {
134133
throw new \coding_exception('The \'courseid\' value must be set');
135134
}
136135
}

classes/event/process_rollback.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ class process_rollback extends \core\event\base {
5454
*/
5555
public static function event_from_process($process) {
5656
$data = [
57-
'context' => \context_system::instance(),
57+
'courseid' => $process->courseid,
58+
'context' => $process->context,
5859
'other' => [
59-
'processid' => $process->id,
60-
'workflowid' => $process->workflowid,
61-
'stepindex' => $process->stepindex,
62-
'courseid' => $process->courseid,
60+
'processid' => $process->id,
61+
'workflowid' => $process->workflowid,
62+
'stepindex' => $process->stepindex,
6363
],
6464
];
6565
return self::create($data);
@@ -84,7 +84,7 @@ public function get_description() {
8484
$processid = $this->other['processid'];
8585
$workflowid = $this->other['workflowid'];
8686
$stepindex = $this->other['stepindex'];
87-
$courseid = $this->other['courseid'];
87+
$courseid = $this->courseid;
8888

8989
return "The workflow with id '$workflowid' was rolled back on step '$stepindex' for course '$courseid' " .
9090
"in the process with id '$processid'";
@@ -130,7 +130,7 @@ protected function validate_data() {
130130
throw new \coding_exception('The \'stepindex\' value must be set');
131131
}
132132

133-
if (!isset($this->other['courseid'])) {
133+
if (!isset($this->courseid)) {
134134
throw new \coding_exception('The \'courseid\' value must be set');
135135
}
136136
}

classes/event/process_triggered.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ class process_triggered extends \core\event\base {
5353
*/
5454
public static function event_from_process($process) {
5555
$data = [
56-
'context' => \context_system::instance(),
56+
'courseid' => $process->courseid,
57+
'context' => \context_course::instance($process->courseid),
5758
'other' => [
5859
'processid' => $process->id,
5960
'workflowid' => $process->workflowid,
60-
'courseid' => $process->courseid,
6161
],
6262
];
6363
return self::create($data);
@@ -81,7 +81,7 @@ protected function init() {
8181
public function get_description() {
8282
$processid = $this->other['processid'];
8383
$workflowid = $this->other['workflowid'];
84-
$courseid = $this->other['courseid'];
84+
$courseid = $this->courseid;
8585

8686
return "The workflow with id '$workflowid' triggered for course '$courseid' and created process with id '$processid'";
8787
}
@@ -122,7 +122,7 @@ protected function validate_data() {
122122
throw new \coding_exception('The \'workflowid\' value must be set');
123123
}
124124

125-
if (!isset($this->other['courseid'])) {
125+
if (!isset($this->courseid)) {
126126
throw new \coding_exception('The \'courseid\' value must be set');
127127
}
128128
}

classes/local/entity/process.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,24 @@ class process {
5050
/** @var /timestamp $timestepchanged Date the process was moved to the current step instance */
5151
public $timestepchanged;
5252

53+
/** @var int $context context of the course in the workflow */
54+
public $context;
55+
5356
/**
5457
* Process constructor.
5558
* @param int $id Id of the process.
5659
* @param int $workflowid Id of the workflow.
5760
* @param int $courseid Id of the course.
61+
* @param int $context context of the course.
5862
* @param int $stepindex Sortindex of the step within the workflow.
5963
* @param bool $waiting True if course is in status waiting.
6064
* @param null $timestepchanged Date the process was moved to the current step instance.
6165
*/
62-
private function __construct($id, $workflowid, $courseid, $stepindex, $waiting = false, $timestepchanged = null) {
66+
private function __construct($id, $workflowid, $courseid, $context, $stepindex, $waiting = false, $timestepchanged = null) {
6367
$this->id = $id;
6468
$this->workflowid = $workflowid;
6569
$this->courseid = $courseid;
70+
$this->context = $context;
6671
$this->waiting = $waiting;
6772
$this->stepindex = $stepindex;
6873
if ($timestepchanged === null) {
@@ -99,7 +104,14 @@ public static function from_record($record) {
99104
$stepindex = 0;
100105
}
101106

102-
$instance = new self($record->id, $record->workflowid, $record->courseid, $stepindex, $waiting, $record->timestepchanged);
107+
$context = \context_course::instance($record->courseid);
108+
$instance = new self($record->id,
109+
$record->workflowid,
110+
$record->courseid,
111+
$context,
112+
$stepindex,
113+
$waiting,
114+
$record->timestepchanged);
103115

104116
return $instance;
105117
}

classes/local/manager/process_manager.php

+2
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ public static function proceed_process(&$process) {
157157
$DB->update_record('tool_lifecycle_process', $process);
158158
return true;
159159
} else {
160+
unset($process->context);
160161
self::remove_process($process);
161162
return false;
162163
}
@@ -181,6 +182,7 @@ public static function set_process_waiting(&$process) {
181182
*/
182183
public static function rollback_process($process) {
183184
process_rollback::event_from_process($process)->trigger();
185+
unset($process->context);
184186
for ($i = $process->stepindex; $i >= 1; $i--) {
185187
$step = step_manager::get_step_instance_by_workflow_index($process->workflowid, $i);
186188
$lib = lib_manager::get_step_lib($step->subpluginname);

classes/processor.php

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ public function process_courses() {
124124
$result = $lib->process_course($process->id, $step->id, $course);
125125
}
126126
} catch (\Exception $e) {
127+
unset($process->context);
127128
process_manager::insert_process_error($process, $e);
128129
break;
129130
}

tests/process_status_message_test.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ public function setUp(): void {
7676
* Test getting status message for a process.
7777
* @covers \tool_lifecycle\local\manager\interaction_manager
7878
*/
79-
public function test_get_status_message(): void {
80-
$process = $this->generator->create_process(2, $this->workflow->id);
79+
public function test_get_status_message() {
80+
$course = $this->getDataGenerator()->create_course();
81+
$process = $this->generator->create_process($course->id, $this->workflow->id);
8182
$message = \tool_lifecycle\local\manager\interaction_manager::get_process_status_message($process->id);
8283
$this->assertEquals(get_string("workflow_started", "tool_lifecycle"), $message);
8384

0 commit comments

Comments
 (0)