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
This commit is contained in:
Rajesh Taneja
2014-01-29 11:39:44 +08:00
parent fefcd9abab
commit fdc729ea57
73 changed files with 154 additions and 136 deletions
+1 -1
View File
@@ -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.');
}
}
+1 -1
View File
@@ -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.');
+1 -1
View File
@@ -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']}";
}
/**
+6 -1
View File
@@ -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;
}
}
/**
+6 -1
View File
@@ -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;
}
}
/**
+6 -1
View File
@@ -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.');
}
}
+3 -3
View File
@@ -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);
}
/**