Commit fdc729ea authored by Rajesh Taneja's avatar Rajesh Taneja
Browse files

MDL-43736 Events: event->contextinstanceid should be used where possible

While restoring event context might not be present (deleted)
So before using context api's check context or use event properties
parent fefcd9ab
......@@ -59,7 +59,7 @@ abstract class assessable_submitted extends \core\event\base {
* @return void
*/
protected function validate_data() {
if (!$this->context->contextlevel === CONTEXT_MODULE) {
if (!$this->contextlevel === CONTEXT_MODULE) {
throw new \coding_exception('Content level must be CONTEXT_MODULE.');
}
}
......
......@@ -66,7 +66,7 @@ abstract class assessable_uploaded extends \core\event\base {
* @return void
*/
protected function validate_data() {
if (!$this->context->contextlevel === CONTEXT_MODULE) {
if (!$this->contextlevel === CONTEXT_MODULE) {
throw new \coding_exception('Content level must be CONTEXT_MODULE.');
} else if (!isset($this->other['pathnamehashes']) || !is_array($this->other['pathnamehashes'])) {
throw new \coding_exception('pathnamehashes must be set in $other and must be an array.');
......
......@@ -355,7 +355,7 @@ abstract class base implements \IteratorAggregate {
if (isset($this->context)) {
return $this->context;
}
$this->context = \context::instance_by_id($this->data['contextid'], false);
$this->context = \context::instance_by_id($this->data['contextid'], IGNORE_MISSING);
return $this->context;
}
......
......@@ -69,8 +69,8 @@ class blog_association_created extends \core\event\base {
* @return string
*/
public function get_description() {
return "Blog association added between entry id $this->other['blogid'] and $this->other['associatetype'] with id
$this->other['associateid']";
return "Blog association added between entry id {$this->other['blogid']} and {$this->other['associatetype']} with id
{$this->other['associateid']}";
}
/**
......
......@@ -79,7 +79,12 @@ abstract class comment_created extends \core\event\base {
* @return \moodle_url
*/
public function get_url() {
return $this->context->get_url();
$context = $this->get_context();
if ($context) {
return $context->get_url();
} else {
return null;
}
}
/**
......
......@@ -79,7 +79,12 @@ abstract class comment_deleted extends \core\event\base {
* @return \moodle_url
*/
public function get_url() {
return $this->context->get_url();
$context = $this->get_context();
if ($context) {
return $context->get_url();
} else {
return null;
}
}
/**
......
......@@ -72,6 +72,11 @@ abstract class comments_viewed extends \core\event\base {
* @return \moodle_url
*/
public function get_url() {
return $this->context->get_url();
$context = $this->get_context();
if ($context) {
return $context->get_url();
} else {
return null;
}
}
}
......@@ -105,7 +105,7 @@ abstract class course_module_instance_list_viewed extends base{
* @return void
*/
protected function validate_data() {
if ($this->context->contextlevel !== CONTEXT_COURSE) {
if ($this->contextlevel !== CONTEXT_COURSE) {
throw new \coding_exception('The context must be a course level context.');
}
}
......
......@@ -72,7 +72,7 @@ abstract class course_module_viewed extends base {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url("/mod/$this->objecttable/view.php", array('id' => $this->context->instanceid));
return new \moodle_url("/mod/$this->objecttable/view.php", array('id' => $this->contextinstanceid));
}
/**
......@@ -81,8 +81,8 @@ abstract class course_module_viewed extends base {
* @return array|null
*/
protected function get_legacy_logdata() {
return array($this->courseid, $this->objecttable, 'view', 'view.php?id=' . $this->context->instanceid, $this->objectid,
$this->context->instanceid);
return array($this->courseid, $this->objecttable, 'view', 'view.php?id=' . $this->contextinstanceid, $this->objectid,
$this->contextinstanceid);
}
/**
......
......@@ -75,7 +75,7 @@ class all_submissions_downloaded extends \core\event\base {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->context->instanceid));
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
}
/**
......
......@@ -65,7 +65,7 @@ class assessable_submitted extends \core\event\assessable_submitted {
protected function get_legacy_eventdata() {
$eventdata = new \stdClass();
$eventdata->modulename = 'assign';
$eventdata->cmid = $this->context->instanceid;
$eventdata->cmid = $this->contextinstanceid;
$eventdata->itemid = $this->objectid;
$eventdata->courseid = $this->courseid;
$eventdata->userid = $this->userid;
......@@ -106,7 +106,7 @@ class assessable_submitted extends \core\event\assessable_submitted {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->context->instanceid));
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
}
/**
......
......@@ -75,7 +75,7 @@ class extension_granted extends \core\event\base {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->context->instanceid));
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
}
/**
......
......@@ -75,7 +75,7 @@ class identities_revealed extends \core\event\base {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->context->instanceid));
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
}
/**
......
......@@ -81,7 +81,7 @@ class marker_updated extends \core\event\base {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->context->instanceid));
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
}
/**
......
......@@ -75,7 +75,7 @@ class statement_accepted extends \core\event\base {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->context->instanceid));
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
}
/**
......
......@@ -75,7 +75,7 @@ class submission_duplicated extends \core\event\base {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->context->instanceid));
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
}
/**
......
......@@ -75,7 +75,7 @@ class submission_graded extends \core\event\base {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->context->instanceid));
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
}
/**
......
......@@ -75,7 +75,7 @@ class submission_locked extends \core\event\base {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->context->instanceid));
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
}
/**
......
......@@ -81,7 +81,7 @@ class submission_status_updated extends \core\event\base {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->context->instanceid));
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
}
/**
......
......@@ -75,7 +75,7 @@ class submission_unlocked extends \core\event\base {
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/mod/assign/view.php', array('id' => $this->context->instanceid));
return new \moodle_url('/mod/assign/view.php', array('id' => $this->contextinstanceid));
}
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment