Merge branch 'MDL-41599-master' of git://github.com/ankitagarwal/moodle
authorSam Hemelryk <sam@moodle.com>
Tue, 10 Sep 2013 20:54:26 +0000 (08:54 +1200)
committerSam Hemelryk <sam@moodle.com>
Tue, 10 Sep 2013 20:54:26 +0000 (08:54 +1200)
blog/locallib.php
blog/tests/bloglib_test.php
lib/classes/event/blog_entry_created.php
lib/classes/event/blog_entry_deleted.php

index 97da6fb..3c5b102 100644 (file)
@@ -263,10 +263,11 @@ class blog_entry implements renderable {
         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();
     }
@@ -321,10 +322,11 @@ class blog_entry implements renderable {
         $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();
index 60e5858..2582ac8 100644 (file)
@@ -159,9 +159,11 @@ class core_bloglib_testcase extends advanced_testcase {
 
         $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();
@@ -177,9 +179,12 @@ class core_bloglib_testcase extends advanced_testcase {
         $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();
@@ -190,9 +195,11 @@ class core_bloglib_testcase extends advanced_testcase {
         $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);
     }
 }
index 8f68647..463d8a7 100644 (file)
@@ -107,6 +107,7 @@ class blog_entry_created extends \core\event\base {
      * @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);
     }
 }
index 9d02aab..a451f03 100644 (file)
@@ -98,6 +98,7 @@ class blog_entry_deleted extends \core\event\base {
      * @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);
     }
 }