From be7809f5fd65221b1d423916971cd7aa5d90c4cb Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Wed, 7 May 2014 19:12:06 -0700 Subject: [PATCH] MDL-45445 events: added missing 'other' validation --- lib/classes/event/course_category_deleted.php | 14 +++++++++ lib/classes/event/course_content_deleted.php | 14 +++++++++ lib/classes/event/course_created.php | 14 +++++++++ lib/classes/event/course_deleted.php | 14 +++++++++ lib/classes/event/course_restored.php | 30 +++++++++++++++++++ lib/classes/event/role_assigned.php | 8 +++++ lib/classes/event/role_deleted.php | 14 +++++++++ lib/classes/event/role_unassigned.php | 8 +++++ lib/classes/event/user_graded.php | 4 +++ lib/classes/event/user_loggedinas.php | 8 +++++ .../event/webservice_token_created.php | 4 +++ mod/scorm/classes/event/report_viewed.php | 4 +++ .../event/assessment_evaluations_reset.php | 14 +++++++++ .../classes/event/assessments_reset.php | 14 +++++++++ mod/workshop/classes/event/phase_switched.php | 14 +++++++++ .../classes/event/submission_assessed.php | 4 +++ .../classes/event/submission_reassessed.php | 4 +++ 17 files changed, 186 insertions(+) diff --git a/lib/classes/event/course_category_deleted.php b/lib/classes/event/course_category_deleted.php index 5c6bbee5a21..4d80eeea830 100644 --- a/lib/classes/event/course_category_deleted.php +++ b/lib/classes/event/course_category_deleted.php @@ -122,4 +122,18 @@ class course_category_deleted extends base { protected function get_legacy_logdata() { return array(SITEID, 'category', 'delete', 'index.php', $this->other['name'] . '(ID ' . $this->objectid . ')'); } + + /** + * Custom validation. + * + * @throws \coding_exception + * @return void + */ + protected function validate_data() { + parent::validate_data(); + + if (!isset($this->other['name'])) { + throw new \coding_exception('The \'name\' value must be set in other.'); + } + } } diff --git a/lib/classes/event/course_content_deleted.php b/lib/classes/event/course_content_deleted.php index 42161dd9ece..dbea00d4d3a 100644 --- a/lib/classes/event/course_content_deleted.php +++ b/lib/classes/event/course_content_deleted.php @@ -90,4 +90,18 @@ class course_content_deleted extends base { return $course; } + + /** + * Custom validation. + * + * @throws \coding_exception + * @return void + */ + protected function validate_data() { + parent::validate_data(); + + if (!isset($this->other['options'])) { + throw new \coding_exception('The \'options\' value must be set in other.'); + } + } } diff --git a/lib/classes/event/course_created.php b/lib/classes/event/course_created.php index 56a6d61c210..0836ccb10fa 100644 --- a/lib/classes/event/course_created.php +++ b/lib/classes/event/course_created.php @@ -105,4 +105,18 @@ class course_created extends base { protected function get_legacy_logdata() { return array(SITEID, 'course', 'new', 'view.php?id=' . $this->objectid, $this->other['fullname'] . ' (ID ' . $this->objectid . ')'); } + + /** + * Custom validation. + * + * @throws \coding_exception + * @return void + */ + protected function validate_data() { + parent::validate_data(); + + if (!isset($this->other['fullname'])) { + throw new \coding_exception('The \'fullname\' value must be set in other.'); + } + } } diff --git a/lib/classes/event/course_deleted.php b/lib/classes/event/course_deleted.php index ca272809efe..d89aa1966f1 100644 --- a/lib/classes/event/course_deleted.php +++ b/lib/classes/event/course_deleted.php @@ -100,4 +100,18 @@ class course_deleted extends base { protected function get_legacy_logdata() { return array(SITEID, 'course', 'delete', 'view.php?id=' . $this->objectid, $this->other['fullname'] . '(ID ' . $this->objectid . ')'); } + + /** + * Custom validation. + * + * @throws \coding_exception + * @return void + */ + protected function validate_data() { + parent::validate_data(); + + if (!isset($this->other['fullname'])) { + throw new \coding_exception('The \'fullname\' value must be set in other.'); + } + } } diff --git a/lib/classes/event/course_restored.php b/lib/classes/event/course_restored.php index 8ccfc26fd26..1d5230c200c 100644 --- a/lib/classes/event/course_restored.php +++ b/lib/classes/event/course_restored.php @@ -107,4 +107,34 @@ class course_restored extends base { 'samesite' => $this->other['samesite'], ); } + + /** + * Custom validation. + * + * @throws \coding_exception + * @return void + */ + protected function validate_data() { + parent::validate_data(); + + if (!isset($this->other['type'])) { + throw new \coding_exception('The \'type\' value must be set in other.'); + } + + if (!isset($this->other['target'])) { + throw new \coding_exception('The \'target\' value must be set in other.'); + } + + if (!isset($this->other['mode'])) { + throw new \coding_exception('The \'mode\' value must be set in other.'); + } + + if (!isset($this->other['operation'])) { + throw new \coding_exception('The \'operation\' value must be set in other.'); + } + + if (!isset($this->other['samesite'])) { + throw new \coding_exception('The \'samesite\' value must be set in other.'); + } + } } diff --git a/lib/classes/event/role_assigned.php b/lib/classes/event/role_assigned.php index 85c6051420a..6722959d9bf 100644 --- a/lib/classes/event/role_assigned.php +++ b/lib/classes/event/role_assigned.php @@ -122,5 +122,13 @@ class role_assigned extends base { if (!isset($this->relateduserid)) { throw new \coding_exception('The \'relateduserid\' must be set.'); } + + if (!isset($this->other['id'])) { + throw new \coding_exception('The \'id\' value must be set in other.'); + } + + if (!isset($this->other['component'])) { + throw new \coding_exception('The \'component\' value must be set in other.'); + } } } diff --git a/lib/classes/event/role_deleted.php b/lib/classes/event/role_deleted.php index a259419bf00..f80003de35f 100644 --- a/lib/classes/event/role_deleted.php +++ b/lib/classes/event/role_deleted.php @@ -88,4 +88,18 @@ class role_deleted extends base { return array(SITEID, 'role', 'delete', 'admin/roles/manage.php?action=delete&roleid=' . $this->objectid, $this->other['shortname'], ''); } + + /** + * Custom validation. + * + * @throws \coding_exception + * @return void + */ + protected function validate_data() { + parent::validate_data(); + + if (!isset($this->other['shortname'])) { + throw new \coding_exception('The \'shortname\' value must be set in other.'); + } + } } diff --git a/lib/classes/event/role_unassigned.php b/lib/classes/event/role_unassigned.php index f0888be2483..79928c31cac 100644 --- a/lib/classes/event/role_unassigned.php +++ b/lib/classes/event/role_unassigned.php @@ -119,5 +119,13 @@ class role_unassigned extends base { if (!isset($this->relateduserid)) { throw new \coding_exception('The \'relateduserid\' must be set.'); } + + if (!isset($this->other['id'])) { + throw new \coding_exception('The \'id\' value must be set in other.'); + } + + if (!isset($this->other['component'])) { + throw new \coding_exception('The \'component\' value must be set in other.'); + } } } diff --git a/lib/classes/event/user_graded.php b/lib/classes/event/user_graded.php index 61c89803a24..9af099f4194 100644 --- a/lib/classes/event/user_graded.php +++ b/lib/classes/event/user_graded.php @@ -151,5 +151,9 @@ class user_graded extends base { if (!isset($this->relateduserid)) { throw new \coding_exception('The \'relateduserid\' must be set.'); } + + if (!isset($this->other['itemid'])) { + throw new \coding_exception('The \'itemid\' value must be set in other.'); + } } } diff --git a/lib/classes/event/user_loggedinas.php b/lib/classes/event/user_loggedinas.php index 0e32b29aa07..494038fd001 100644 --- a/lib/classes/event/user_loggedinas.php +++ b/lib/classes/event/user_loggedinas.php @@ -103,5 +103,13 @@ class user_loggedinas extends base { if (!isset($this->relateduserid)) { throw new \coding_exception('The \'relateduserid\' must be set.'); } + + if (!isset($this->other['originalusername'])) { + throw new \coding_exception('The \'originalusername\' value must be set in other.'); + } + + if (!isset($this->other['loggedinasusername'])) { + throw new \coding_exception('The \'loggedinasusername\' value must be set in other.'); + } } } diff --git a/lib/classes/event/webservice_token_created.php b/lib/classes/event/webservice_token_created.php index 65da1bb0ba2..a816dbead50 100644 --- a/lib/classes/event/webservice_token_created.php +++ b/lib/classes/event/webservice_token_created.php @@ -103,5 +103,9 @@ class webservice_token_created extends base { if (!isset($this->relateduserid)) { throw new \coding_exception('The \'relateduserid\' must be set.'); } + + if (!isset($this->other['auto'])) { + throw new \coding_exception('The \'auto\' value must be set in other.'); + } } } diff --git a/mod/scorm/classes/event/report_viewed.php b/mod/scorm/classes/event/report_viewed.php index a4a5538a7ec..689a43ca023 100644 --- a/mod/scorm/classes/event/report_viewed.php +++ b/mod/scorm/classes/event/report_viewed.php @@ -97,6 +97,10 @@ class report_viewed extends \core\event\base { protected function validate_data() { parent::validate_data(); + if (empty($this->other['scormid'])) { + throw new \coding_exception('The \'scormid\' value must be set in other.'); + } + if (empty($this->other['mode'])) { throw new \coding_exception('The \'mode\' value must be set in other.'); } diff --git a/mod/workshop/classes/event/assessment_evaluations_reset.php b/mod/workshop/classes/event/assessment_evaluations_reset.php index 32418cb46ba..21a9d314b7e 100644 --- a/mod/workshop/classes/event/assessment_evaluations_reset.php +++ b/mod/workshop/classes/event/assessment_evaluations_reset.php @@ -89,4 +89,18 @@ class assessment_evaluations_reset extends \core\event\base { public function get_url() { return new \moodle_url('/mod/workshop/view.php', array('id' => $this->contextinstanceid)); } + + /** + * Custom validation. + * + * @throws \coding_exception + * @return void + */ + protected function validate_data() { + parent::validate_data(); + + if (!isset($this->other['workshopid'])) { + throw new \coding_exception('The \'workshopid\' value must be set in other.'); + } + } } diff --git a/mod/workshop/classes/event/assessments_reset.php b/mod/workshop/classes/event/assessments_reset.php index 96a55669a67..b5bc6ff3317 100644 --- a/mod/workshop/classes/event/assessments_reset.php +++ b/mod/workshop/classes/event/assessments_reset.php @@ -88,4 +88,18 @@ class assessments_reset extends \core\event\base { public function get_url() { return new \moodle_url('/mod/workshop/view.php', array('id' => $this->contextinstanceid)); } + + /** + * Custom validation. + * + * @throws \coding_exception + * @return void + */ + protected function validate_data() { + parent::validate_data(); + + if (!isset($this->other['workshopid'])) { + throw new \coding_exception('The \'workshopid\' value must be set in other.'); + } + } } diff --git a/mod/workshop/classes/event/phase_switched.php b/mod/workshop/classes/event/phase_switched.php index 447900a6cf1..c83fa1f87cc 100644 --- a/mod/workshop/classes/event/phase_switched.php +++ b/mod/workshop/classes/event/phase_switched.php @@ -89,4 +89,18 @@ class phase_switched extends \core\event\base { public function get_url() { return new \moodle_url('/mod/workshop/view.php', array('id' => $this->contextinstanceid)); } + + /** + * Custom validation. + * + * @throws \coding_exception + * @return void + */ + protected function validate_data() { + parent::validate_data(); + + if (!isset($this->other['workshopphase'])) { + throw new \coding_exception('The \'workshopphase\' value must be set in other.'); + } + } } diff --git a/mod/workshop/classes/event/submission_assessed.php b/mod/workshop/classes/event/submission_assessed.php index bc872660e6c..c4740e41fa7 100644 --- a/mod/workshop/classes/event/submission_assessed.php +++ b/mod/workshop/classes/event/submission_assessed.php @@ -103,5 +103,9 @@ class submission_assessed extends \core\event\base { if (!isset($this->relateduserid)) { throw new \coding_exception('The \'relateduserid\' must be set.'); } + + if (!isset($this->other['submissionid'])) { + throw new \coding_exception('The \'submissionid\' value must be set in other.'); + } } } diff --git a/mod/workshop/classes/event/submission_reassessed.php b/mod/workshop/classes/event/submission_reassessed.php index f59e3caa7b2..9cdd6ce9356 100644 --- a/mod/workshop/classes/event/submission_reassessed.php +++ b/mod/workshop/classes/event/submission_reassessed.php @@ -104,5 +104,9 @@ class submission_reassessed extends \core\event\base { if (!isset($this->relateduserid)) { throw new \coding_exception('The \'relateduserid\' must be set.'); } + + if (!isset($this->other['submissionid'])) { + throw new \coding_exception('The \'submissionid\' value must be set in other.'); + } } }