MDL-44403 events: MDL-44403 events: bug fix in legacy event data for unknown_service_api_called

This commit is contained in:
Marina Glancy 2014-02-28 16:15:26 +08:00
parent 24c32bdf2f
commit d5bc7b66e9
3 changed files with 32 additions and 12 deletions

View File

@ -44,16 +44,28 @@ defined('MOODLE_INTERNAL') || die();
*/
class unknown_service_api_called extends \core\event\base {
/** Old data to be used for the legacy event. */
protected $legacydata;
/** @var \stdClass Data to be used by event observers. */
protected $eventdata;
/**
* Set method for legacy data.
* Sets custom data used by event observers.
*
* @param stdClass $data legacy event data.
* @param \stdClass $data
*/
public function set_legacy_data($data) {
$this->legacydata = $data;
public function set_message_data(\stdClass $data) {
$this->eventdata = $data;
}
/**
* Returns custom data for event observers.
*
* @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.');
}
return $this->eventdata;
}
/**
@ -99,7 +111,7 @@ class unknown_service_api_called extends \core\event\base {
* @return mixed
*/
protected function get_legacy_eventdata() {
return $this->legacydata;
return $this->eventdata;
}
}

View File

@ -146,15 +146,17 @@ switch ($messagetype) {
//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.
$data = new stdClass();
$data->body = $rawbody;
$data->xml = $xml;
$data->messagetype = $messagetype;
$data->consumerkey = $consumerkey;
$data->sharedsecret = $sharedsecret;
$eventdata = array();
$eventdata['other'] = array();
$eventdata['other']['body'] = $rawbody;
$eventdata['other']['messageid'] = lti_parse_message_id($xml);
$eventdata['other']['messagetype'] = $messagetype;
$eventdata['other']['consumerkey'] = $consumerkey;
$eventdata['other']['sharedsecret'] = $sharedsecret;
// Before firing the event, allow subplugins a chance to handle.
if (lti_extend_lti_services((object) $eventdata['other'])) {
@ -168,7 +170,7 @@ switch ($messagetype) {
try {
$event = \mod_lti\event\unknown_service_api_called::create($eventdata);
$event->set_legacy_data($eventdata);
$event->set_message_data($data);
$event->trigger();
} catch (Exception $e) {
$lti_web_service_handled = false;

6
mod/lti/upgrade.txt Normal file
View File

@ -0,0 +1,6 @@
This files describes API changes in the lti code.
=== 2.7 ===
* mod_lti\event\unknown_service_api_called now has less data stored in 'other'
but everything is still available for event observers via method get_message_data()