Skip to content

Commit

Permalink
Merge pull request #205 from catalyst/issue#203
Browse files Browse the repository at this point in the history
Issue#203 Insert tool_trigger_events id into event other data
  • Loading branch information
dmitriim authored Jun 7, 2023
2 parents f658b40 + 565a947 commit 321535c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
7 changes: 6 additions & 1 deletion classes/helper/datafield_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ public function update_datafields($event, $stepresults) {
if (isset($newfields['other']) && is_array($newfields['other'])) {
foreach ($newfields['other'] as $key => $value) {
if (is_scalar($value) || is_null($value)) {
$newfields["other_{$key}"] = $value;
// Retrieve ID from eventid in other data.
if ($key == 'eventid') {
$newfields['id'] = $value;
} else {
$newfields["other_{$key}"] = $value;
}
}
}
unset($newfields['other']);
Expand Down
6 changes: 6 additions & 0 deletions classes/helper/processor_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public function restore_event(\stdClass $data) {
if ($data['other'] === false) {
$data['other'] = array();
}

// Insert eventid into other data.
if (isset($data['id'])) {
$data['other']['eventid'] = $data['id'];
}

unset($data['origin']);
unset($data['ip']);
unset($data['realuserid']);
Expand Down
6 changes: 6 additions & 0 deletions tests/datafield_manager_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public function test_get_datafields() {
$dfprovider->update_datafields($this->event, $stepdata);
$datafields = $dfprovider->get_datafields();

// Check event id.
$this->assertEquals(
1,
$datafields['id']
);

// A field from the event object.
$this->assertEquals(
$this->user2->id,
Expand Down
3 changes: 2 additions & 1 deletion tests/fixtures/user_event_fixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public function setup_user_event() {
'other' => [
'courseid' => $this->course->id,
'courseshortname' => $this->course->shortname,
'coursefullname' => $this->course->fullname
'coursefullname' => $this->course->fullname,
'eventid' => 1,
]
]);

Expand Down
3 changes: 3 additions & 0 deletions tests/processor_helper_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function setup():void {
*/
public function test_restore_event() {
$data = (object) [
'id' => 1,
'eventname' => '\\core\\event\\user_loggedin',
'component' => 'core',
'action' => 'loggedin',
Expand Down Expand Up @@ -98,6 +99,8 @@ public function test_restore_event() {
$this->assertEquals($expectedevent->userid, $actual->userid);
$this->assertEquals($expectedevent->objectid, $actual->objectid);
$this->assertEquals($expectedevent->get_username(), $actual->get_username());
// Tool trigger event id
$this->assertEquals(1, $actual->other['eventid']);
}

/**
Expand Down

0 comments on commit 321535c

Please sign in to comment.