Skip to content

Commit

Permalink
MDL-41599 events: Set relateduserid instead of userid in blog events
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitagarwal committed Sep 5, 2013
1 parent b69ec28 commit 77037e2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
18 changes: 10 additions & 8 deletions blog/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,11 @@ public function add() {
tag_set('post', $this->id, $this->tags);

// Trigger an event for the new entry.
$event = \core\event\blog_entry_created::create(array('objectid' => $this->id,
'userid' => $this->userid,
'other' => array ("subject" => $this->subject)
));
$event = \core\event\blog_entry_created::create(array(
'objectid' => $this->id,
'relateduserid' => $this->userid,
'other' => array('subject' => $this->subject)
));
$event->set_custom_data($this);
$event->trigger();
}
Expand Down Expand Up @@ -321,10 +322,11 @@ public function delete() {
$DB->delete_records('post', array('id' => $this->id));
tag_set('post', $this->id, array());

$event = \core\event\blog_entry_deleted::create(array('objectid' => $this->id,
'userid' => $this->userid,
'other' => array("record" => (array)$record)
));
$event = \core\event\blog_entry_deleted::create(array(
'objectid' => $this->id,
'relateduserid' => $this->userid,
'other' => array('record' => (array) $record)
));
$event->add_record_snapshot("post", $record);
$event->set_custom_data($this);
$event->trigger();
Expand Down
13 changes: 10 additions & 3 deletions blog/tests/bloglib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,11 @@ public function test_blog_entry_events() {

$this->setAdminUser();
$this->resetAfterTest();
$user = $this->getDataGenerator()->create_user();

// Create a blog entry.
// Create a blog entry for another user as Admin.
$blog = new blog_entry();
$blog->userid = $user->id;
$blog->summary = "This is summary of blog";
$blog->subject = "Subject of blog";
$states = blog_entry::get_applicable_publish_states();
Expand All @@ -177,9 +179,12 @@ public function test_blog_entry_events() {
$this->assertEquals($sitecontext->id, $event->contextid);
$this->assertEquals($blog->id, $event->objectid);
$this->assertEquals($USER->id, $event->userid);
$this->assertEquals($user->id, $event->relateduserid);
$this->assertEquals("post", $event->objecttable);
$arr = array(SITEID, 'blog', 'add', 'index.php?userid=' . $user->id . '&entryid=' . $blog->id, $blog->subject);
$this->assertEventLegacyLogData($arr, $event);

// Delete a blog entry.
// Delete a user blog entry as Admin.
$record = $DB->get_record('post', array('id' => $blog->id));
$blog->delete();
$events = $sink->get_events();
Expand All @@ -190,9 +195,11 @@ public function test_blog_entry_events() {
$this->assertEquals(context_system::instance()->id, $event->contextid);
$this->assertEquals($blog->id, $event->objectid);
$this->assertEquals($USER->id, $event->userid);
$this->assertEquals($user->id, $event->relateduserid);
$this->assertEquals("post", $event->objecttable);
$this->assertEquals($record, $event->get_record_snapshot("post", $blog->id));
$this->assertSame('blog_entry_deleted', $event->get_legacy_eventname());

$arr = array(SITEID, 'blog', 'delete', 'index.php?userid=' . $user->id, 'deleted blog entry with entry id# '. $blog->id);
$this->assertEventLegacyLogData($arr, $event);
}
}
3 changes: 2 additions & 1 deletion lib/classes/event/blog_entry_created.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ protected function get_legacy_eventdata() {
* @return array of parameters to be passed to legacy add_to_log() function.
*/
protected function get_legacy_logdata() {
return array (SITEID, 'blog', 'add', 'index.php?userid='.$this->userid.'&entryid='.$this->objectid, $this->customobject->subject);
return array (SITEID, 'blog', 'add', 'index.php?userid=' . $this->relateduserid . '&entryid=' . $this->objectid,
$this->customobject->subject);
}
}
3 changes: 2 additions & 1 deletion lib/classes/event/blog_entry_deleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ protected function get_legacy_eventdata() {
* @return array of parameters to be passed to legacy add_to_log() function.
*/
protected function get_legacy_logdata() {
return array (SITEID, 'blog', 'delete', 'index.php?userid='.$this->userid, 'deleted blog entry with entry id# '. $this->objectid);
return array (SITEID, 'blog', 'delete', 'index.php?userid=' . $this->relateduserid, 'deleted blog entry with entry id# '.
$this->objectid);
}
}

0 comments on commit 77037e2

Please sign in to comment.