Skip to content

Commit 321535c

Browse files
authored
Merge pull request #205 from catalyst/issue#203
Issue#203 Insert tool_trigger_events id into event other data
2 parents f658b40 + 565a947 commit 321535c

File tree

5 files changed

+23
-2
lines changed

5 files changed

+23
-2
lines changed

classes/helper/datafield_manager.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,12 @@ public function update_datafields($event, $stepresults) {
9999
if (isset($newfields['other']) && is_array($newfields['other'])) {
100100
foreach ($newfields['other'] as $key => $value) {
101101
if (is_scalar($value) || is_null($value)) {
102-
$newfields["other_{$key}"] = $value;
102+
// Retrieve ID from eventid in other data.
103+
if ($key == 'eventid') {
104+
$newfields['id'] = $value;
105+
} else {
106+
$newfields["other_{$key}"] = $value;
107+
}
103108
}
104109
}
105110
unset($newfields['other']);

classes/helper/processor_helper.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ public function restore_event(\stdClass $data) {
4343
if ($data['other'] === false) {
4444
$data['other'] = array();
4545
}
46+
47+
// Insert eventid into other data.
48+
if (isset($data['id'])) {
49+
$data['other']['eventid'] = $data['id'];
50+
}
51+
4652
unset($data['origin']);
4753
unset($data['ip']);
4854
unset($data['realuserid']);

tests/datafield_manager_test.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ public function test_get_datafields() {
5151
$dfprovider->update_datafields($this->event, $stepdata);
5252
$datafields = $dfprovider->get_datafields();
5353

54+
// Check event id.
55+
$this->assertEquals(
56+
1,
57+
$datafields['id']
58+
);
59+
5460
// A field from the event object.
5561
$this->assertEquals(
5662
$this->user2->id,

tests/fixtures/user_event_fixture.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ public function setup_user_event() {
6262
'other' => [
6363
'courseid' => $this->course->id,
6464
'courseshortname' => $this->course->shortname,
65-
'coursefullname' => $this->course->fullname
65+
'coursefullname' => $this->course->fullname,
66+
'eventid' => 1,
6667
]
6768
]);
6869

tests/processor_helper_test.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function setup():void {
5353
*/
5454
public function test_restore_event() {
5555
$data = (object) [
56+
'id' => 1,
5657
'eventname' => '\\core\\event\\user_loggedin',
5758
'component' => 'core',
5859
'action' => 'loggedin',
@@ -98,6 +99,8 @@ public function test_restore_event() {
9899
$this->assertEquals($expectedevent->userid, $actual->userid);
99100
$this->assertEquals($expectedevent->objectid, $actual->objectid);
100101
$this->assertEquals($expectedevent->get_username(), $actual->get_username());
102+
// Tool trigger event id
103+
$this->assertEquals(1, $actual->other['eventid']);
101104
}
102105

103106
/**

0 commit comments

Comments
 (0)