diff --git a/blog/locallib.php b/blog/locallib.php index a4e42105b9c92..28010c7ab92c8 100644 --- a/blog/locallib.php +++ b/blog/locallib.php @@ -267,7 +267,7 @@ public function add() { 'objectid' => $this->id, 'relateduserid' => $this->userid )); - $event->set_custom_data($this); + $event->set_blog_entry($this); $event->trigger(); } @@ -309,7 +309,7 @@ public function edit($params=array(), $form=null, $summaryoptions=array(), $atta 'objectid' => $entry->id, 'relateduserid' => $entry->userid )); - $event->set_custom_data($entry); + $event->set_blog_entry($entry); $event->trigger(); } @@ -334,7 +334,7 @@ public function delete() { 'relateduserid' => $this->userid )); $event->add_record_snapshot("post", $record); - $event->set_custom_data($this); + $event->set_blog_entry($this); $event->trigger(); } diff --git a/group/lib.php b/group/lib.php index 22051bcfa9cbf..970ce787bb48a 100644 --- a/group/lib.php +++ b/group/lib.php @@ -326,7 +326,6 @@ function groups_create_grouping($data, $editoroptions=null) { 'objectid' => $id ); $event = \core\event\grouping_created::create($params); - $event->set_legacy_eventdata($data); $event->trigger(); return $id; @@ -442,7 +441,6 @@ function groups_update_grouping($data, $editoroptions=null) { 'objectid' => $data->id ); $event = \core\event\grouping_updated::create($params); - $event->set_legacy_eventdata($data); $event->trigger(); return true; diff --git a/group/tests/lib_test.php b/group/tests/lib_test.php index baf4b3ebeee69..d845868310cbf 100644 --- a/group/tests/lib_test.php +++ b/group/tests/lib_test.php @@ -124,12 +124,6 @@ public function test_grouping_created_event() { $this->assertInstanceOf('\core\event\grouping_created', $event); - // 'Repairing' the object for comparison because of type of variables being wrong. - $group->id = (int) $group->id; - $group->timemodified = (int) $group->timemodified; - $group->timecreated = (int) $group->timecreated; - unset($group->idnumber); - unset($group->configdata); $this->assertEventLegacyData($group, $event); $this->assertSame('groups_grouping_created', $event->get_legacy_eventname()); @@ -187,10 +181,16 @@ public function test_grouping_updated_event() { $this->assertInstanceOf('\core\event\grouping_updated', $event); - // 'Repairing' the object for comparison because of type of variables being wrong. - $data->id = (int) $grouping->id; + // Get the timemodified from DB for comparison with snapshot. $data->timemodified = $DB->get_field('groupings', 'timemodified', array('id'=>$grouping->id)); $this->assertTimeCurrent($data->timemodified); + // Following fields were not updated so the snapshot should have them the same as in original group. + $data->description = $grouping->description; + $data->descriptionformat = $grouping->descriptionformat; + $data->configdata = $grouping->configdata; + $data->idnumber = $grouping->idnumber; + $data->timecreated = $grouping->timecreated; + // Assert legacy event data. $this->assertEventLegacyData($data, $event); $this->assertSame('groups_grouping_updated', $event->get_legacy_eventname()); diff --git a/lib/classes/event/blog_entry_created.php b/lib/classes/event/blog_entry_created.php index 4e1518a970f79..df979f9cd8c0e 100644 --- a/lib/classes/event/blog_entry_created.php +++ b/lib/classes/event/blog_entry_created.php @@ -37,8 +37,8 @@ */ class blog_entry_created extends \core\event\base { - /** @var \blog_entry A reference to the active blog_entry object. */ - protected $customobject; + /** @var \blog_entry A reference to the active blog_entry object. */ + protected $blogentry; /** * Set basic properties for the event. @@ -53,10 +53,34 @@ protected function init() { /** * Set custom data of the event. * - * @param \blog_entry $data A reference to the active blog_entry object. + * @param \blog_entry $data */ public function set_custom_data(\blog_entry $data) { - $this->customobject = $data; + // This function will be removed in 2.7. + $this->set_blog_entry($data); + } + + /** + * Set blog_entry object to be used by observers. + * + * @since 2.6.2 + * @param \blog_entry $data A reference to the active blog_entry object. + */ + public function set_blog_entry(\blog_entry $blogentry) { + $this->blogentry = $blogentry; + } + + /** + * Returns created blog_entry object for event observers. + * + * @since 2.6.2 + * @return \blog_entry + */ + public function get_blog_entry() { + if ($this->is_restored()) { + throw new \coding_exception('Function get_blog_entry() can not be used on restored events.'); + } + return $this->blogentry; } /** @@ -100,7 +124,7 @@ public static function get_legacy_eventname() { * @return \blog_entry */ protected function get_legacy_eventdata() { - return $this->customobject; + return $this->blogentry; } /** @@ -110,6 +134,6 @@ protected function get_legacy_eventdata() { */ protected function get_legacy_logdata() { return array (SITEID, 'blog', 'add', 'index.php?userid=' . $this->relateduserid . '&entryid=' . $this->objectid, - $this->customobject->subject); + $this->blogentry->subject); } } diff --git a/lib/classes/event/blog_entry_deleted.php b/lib/classes/event/blog_entry_deleted.php index b7275d53963da..6052334bdfe40 100644 --- a/lib/classes/event/blog_entry_deleted.php +++ b/lib/classes/event/blog_entry_deleted.php @@ -37,7 +37,7 @@ class blog_entry_deleted extends \core\event\base { /** @var \blog_entry A reference to the active blog_entry object. */ - protected $customobject; + protected $blogentry; /** * Set basic event properties. @@ -64,7 +64,31 @@ public static function get_name() { * @param \blog_entry $data A reference to the active blog_entry object. */ public function set_custom_data(\blog_entry $data) { - $this->customobject = $data; + // Note, this function will be removed in 2.7. + $this->set_blog_entry($data); + } + + /** + * Sets blog_entry object to be used by observers. + * + * @since 2.6.2 + * @param \blog_entry $data A reference to the active blog_entry object. + */ + public function set_blog_entry(\blog_entry $blogentry) { + $this->blogentry = $blogentry; + } + + /** + * Returns deleted blog entry for event observers. + * + * @since 2.6.2 + * @return \blog_entry + */ + public function get_blog_entry() { + if ($this->is_restored()) { + throw new \coding_exception('Function get_blog_entry() can not be used on restored events.'); + } + return $this->blogentry; } /** @@ -91,7 +115,7 @@ public static function get_legacy_eventname() { * @return \blog_entry */ protected function get_legacy_eventdata() { - return $this->customobject; + return $this->blogentry; } /** diff --git a/lib/classes/event/blog_entry_updated.php b/lib/classes/event/blog_entry_updated.php index 777ac2ecb8c56..6de6c0f688887 100644 --- a/lib/classes/event/blog_entry_updated.php +++ b/lib/classes/event/blog_entry_updated.php @@ -36,7 +36,7 @@ class blog_entry_updated extends base { /** @var \blog_entry A reference to the active blog_entry object. */ - protected $customobject; + protected $blogentry; /** * Set basic event properties. @@ -49,12 +49,34 @@ protected function init() { } /** - * Set custom data of the event. + * Set custom data of the event - updated blog entry. * * @param \blog_entry $data A reference to the active blog_entry object. */ public function set_custom_data(\blog_entry $data) { - $this->customobject = $data; + // Note, this function will be removed in 2.7. + $this->set_blog_entry($data); + } + + /** + * Sets blog_entry object to be used by observers. + * + * @param \blog_entry $data A reference to the active blog_entry object. + */ + public function set_blog_entry(\blog_entry $blogentry) { + $this->blogentry = $blogentry; + } + + /** + * Returns updated blog entry for event observers. + * + * @return \blog_entry + */ + public function get_blog_entry() { + if ($this->is_restored()) { + throw new \coding_exception('Function get_blog_entry() can not be used on restored events.'); + } + return $this->blogentry; } /** @@ -89,7 +111,7 @@ public function get_url() { * @return \blog_entry */ protected function get_legacy_eventdata() { - return $this->customobject; + return $this->blogentry; } /** @@ -108,7 +130,7 @@ public static function get_legacy_eventname() { */ protected function get_legacy_logdata() { return array(SITEID, 'blog', 'update', 'index.php?userid=' . $this->relateduserid . '&entryid=' . $this->objectid, - $this->customobject->subject); + $this->blogentry->subject); } } diff --git a/lib/classes/event/course_category_deleted.php b/lib/classes/event/course_category_deleted.php index ff7ecf3836966..8edea127146a2 100644 --- a/lib/classes/event/course_category_deleted.php +++ b/lib/classes/event/course_category_deleted.php @@ -83,7 +83,31 @@ protected function get_legacy_eventdata() { * @param coursecat $class instance of the coursecat class */ public function set_legacy_eventdata($class) { - $this->coursecat = $class; + // This function will be removed in 2.7. + $this->set_coursecat($class); + } + + /** + * Set custom data of the event - deleted coursecat. + * + * @since 2.6.2 + * @param \coursecat $coursecat + */ + public function set_coursecat(\coursecat $coursecat) { + $this->coursecat = $coursecat; + } + + /** + * Returns deleted coursecat for event observers. + * + * @since 2.6.2 + * @return \coursecat + */ + public function get_coursecat() { + if ($this->is_restored()) { + throw new \coding_exception('Function get_coursecat() can not be used on restored events.'); + } + return $this->coursecat; } /** diff --git a/lib/classes/event/grouping_created.php b/lib/classes/event/grouping_created.php index 1d331cfa5b4c5..2bdf027eb439b 100644 --- a/lib/classes/event/grouping_created.php +++ b/lib/classes/event/grouping_created.php @@ -34,13 +34,6 @@ */ class grouping_created extends \core\event\base { - /** - * Legacy data. - * - * @var mixed - */ - protected $legacydata; - /** * Returns description of what happened. * @@ -56,7 +49,7 @@ public function get_description() { * @return stdClass */ protected function get_legacy_eventdata() { - return $this->legacydata; + return $this->get_record_snapshot('groupings', $this->objectid); } /** @@ -104,7 +97,7 @@ protected function init() { * @return void */ public function set_legacy_eventdata($legacydata) { - $this->legacydata = $legacydata; + // This function is not used and will be removed in 2.7. } } diff --git a/lib/classes/event/grouping_updated.php b/lib/classes/event/grouping_updated.php index 8d35b492ded3d..a1021c0e4d4cd 100644 --- a/lib/classes/event/grouping_updated.php +++ b/lib/classes/event/grouping_updated.php @@ -34,13 +34,6 @@ */ class grouping_updated extends \core\event\base { - /** - * Legacy data. - * - * @var mixed - */ - protected $legacydata; - /** * Returns description of what happened. * @@ -56,7 +49,7 @@ public function get_description() { * @return stdClass */ protected function get_legacy_eventdata() { - return $this->legacydata; + return $this->get_record_snapshot('groupings', $this->objectid); } /** @@ -104,7 +97,7 @@ protected function init() { * @return void */ public function set_legacy_eventdata($legacydata) { - $this->legacydata = $legacydata; + // This function is not used and will be removed in 2.7. } } diff --git a/lib/coursecatlib.php b/lib/coursecatlib.php index 9323ea57f16ce..d3e5803b0c882 100644 --- a/lib/coursecatlib.php +++ b/lib/coursecatlib.php @@ -1632,7 +1632,7 @@ public function delete_full($showfeedback = true) { 'context' => $coursecatcontext, 'other' => array('name' => $this->name) )); - $event->set_legacy_eventdata($this); + $event->set_coursecat($this); $event->trigger(); // If we deleted $CFG->defaultrequestcategory, make it point somewhere else. @@ -1781,7 +1781,7 @@ public function delete_move($newparentid, $showfeedback = false) { 'context' => $context, 'other' => array('name' => $this->name) )); - $event->set_legacy_eventdata($this); + $event->set_coursecat($this); $event->trigger(); cache_helper::purge_by_event('changesincoursecat'); diff --git a/mod/lti/classes/event/unknown_service_api_called.php b/mod/lti/classes/event/unknown_service_api_called.php index dad8f78bdb636..9190e950b5525 100644 --- a/mod/lti/classes/event/unknown_service_api_called.php +++ b/mod/lti/classes/event/unknown_service_api_called.php @@ -34,16 +34,28 @@ */ class unknown_service_api_called extends \core\event\base { - /** Old data to be used for the legacy event. */ - protected $legacydata; - /** * Set method for legacy data. * * @param stdClass $data legacy event data. */ public function set_legacy_data($data) { - $this->legacydata = $data; + // This function is not used and will be removed in 2.7. + } + + /** + * Returns custom data for event observers. + * + * @since 2.6.2 + * @return \stdClass + */ + public function get_message_data() { + if ($this->is_restored()) { + throw new \coding_exception('Function get_message_data() can not be used on restored events.'); + } + $data = (object)$this->eventdata['other']; + $data->xml = new SimpleXMLElement($data->rawbody); + return $data; } /** @@ -89,7 +101,6 @@ public static function get_legacy_eventname() { * @return mixed */ protected function get_legacy_eventdata() { - return $this->legacydata; + return $this->get_message_data(); } - } diff --git a/mod/lti/service.php b/mod/lti/service.php index 3150bbb2a376c..1b547a320ff62 100644 --- a/mod/lti/service.php +++ b/mod/lti/service.php @@ -147,8 +147,6 @@ //Fire an event if we get a web service request which we don't support directly. //This will allow others to extend the LTI services, which I expect to be a common //use case, at least until the spec matures. - // Please note that you will have to change $eventdata['other']['body'] into an xml - // element in an event observer as done above. $eventdata = array(); $eventdata['other'] = array(); $eventdata['other']['body'] = $rawbody; @@ -169,7 +167,6 @@ try { $event = \mod_lti\event\unknown_service_api_called::create($eventdata); - $event->set_legacy_data($eventdata); $event->trigger(); } catch (Exception $e) { $lti_web_service_handled = false;