Skip to content

Commit

Permalink
Use field courseid for logging events
Browse files Browse the repository at this point in the history
  • Loading branch information
melanietreitinger committed Apr 3, 2024
1 parent 33cbd05 commit 3f2b8ce
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 17 deletions.
9 changes: 4 additions & 5 deletions classes/event/process_proceeded.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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'";
Expand Down Expand Up @@ -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');
}
}
Expand Down
14 changes: 7 additions & 7 deletions classes/event/process_rollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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'";
Expand Down Expand Up @@ -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');
}
}
Expand Down
8 changes: 4 additions & 4 deletions classes/event/process_triggered.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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'";
}
Expand Down Expand Up @@ -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');
}
}
Expand Down
3 changes: 3 additions & 0 deletions classes/local/manager/process_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -179,7 +180,9 @@ public static function set_process_waiting(&$process) {
* @throws \dml_exception
*/
public static function rollback_process($process) {
$process->context = \context_course::instance($process->courseid);
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);
Expand Down
2 changes: 2 additions & 0 deletions classes/processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public function call_trigger() {
*/
public function process_courses() {
foreach (process_manager::get_processes() as $process) {
$process->context = \context_course::instance($process->courseid);
$workflow = workflow_manager::get_workflow($process->workflowid);
while (true) {

Expand Down Expand Up @@ -159,6 +160,7 @@ public function process_courses() {
*/
public function process_course_interactive($processid) {
$process = process_manager::get_process_by_id($processid);
$process->context = \context_course::instance($process->courseid);
$step = step_manager::get_step_instance_by_workflow_index($process->workflowid, $process->stepindex + 1);
// If there is no next step, then proceed, which will delete/finish the process.
if (!$step) {
Expand Down
3 changes: 2 additions & 1 deletion tests/process_status_message_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 3f2b8ce

Please sign in to comment.