From cd5be9a5045c4ab2ccaf21d472febe6cdecee0f2 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Tue, 25 Feb 2014 13:45:01 +0800 Subject: [PATCH] MDL-44321 events: make sure the full object is passed to add_record_snapshot() --- badges/classes/observer.php | 4 ++-- cohort/lib.php | 1 - group/externallib.php | 2 +- lib/accesslib.php | 1 + .../event/course_module_completion_updated.php | 14 ++++++++++++++ lib/completionlib.php | 3 +-- lib/tests/completionlib_test.php | 3 +++ mod/forum/lib.php | 7 +++++++ mod/forum/post.php | 1 - mod/quiz/locallib.php | 2 ++ mod/workshop/submission.php | 2 +- 11 files changed, 32 insertions(+), 8 deletions(-) diff --git a/badges/classes/observer.php b/badges/classes/observer.php index 39c2c4ceb03..a2859e417b9 100644 --- a/badges/classes/observer.php +++ b/badges/classes/observer.php @@ -40,8 +40,8 @@ class core_badges_observer { require_once($CFG->dirroot.'/lib/badgeslib.php'); $eventdata = $event->get_record_snapshot('course_modules_completion', $event->objectid); - $userid = $event->other['relateduserid']; - $mod = $eventdata->coursemoduleid; + $userid = $event->relateduserid; + $mod = $event->contextinstanceid; if ($eventdata->completionstate == COMPLETION_COMPLETE || $eventdata->completionstate == COMPLETION_COMPLETE_PASS diff --git a/cohort/lib.php b/cohort/lib.php index 51ac01c163f..66396393168 100644 --- a/cohort/lib.php +++ b/cohort/lib.php @@ -85,7 +85,6 @@ function cohort_update_cohort($cohort) { 'context' => context::instance_by_id($cohort->contextid), 'objectid' => $cohort->id, )); - $event->add_record_snapshot('cohort', $cohort); $event->trigger(); } diff --git a/group/externallib.php b/group/externallib.php index a316b51af6d..7836758abe2 100644 --- a/group/externallib.php +++ b/group/externallib.php @@ -312,7 +312,7 @@ class core_group_external extends external_api { foreach ($params['groupids'] as $groupid) { // validate params $groupid = validate_param($groupid, PARAM_INT); - if (!$group = groups_get_group($groupid, 'id, courseid', IGNORE_MISSING)) { + if (!$group = groups_get_group($groupid, '*', IGNORE_MISSING)) { // silently ignore attempts to delete nonexisting groups continue; } diff --git a/lib/accesslib.php b/lib/accesslib.php index 6680b41a16b..0e988b6c078 100644 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -1744,6 +1744,7 @@ function role_assign($roleid, $userid, $contextid, $component = '', $itemid = 0, $ra->itemid = $itemid; $ra->timemodified = $timemodified; $ra->modifierid = empty($USER->id) ? 0 : $USER->id; + $ra->sortorder = 0; $ra->id = $DB->insert_record('role_assignments', $ra); diff --git a/lib/classes/event/course_module_completion_updated.php b/lib/classes/event/course_module_completion_updated.php index 86fe91f0ca0..53897cbb559 100644 --- a/lib/classes/event/course_module_completion_updated.php +++ b/lib/classes/event/course_module_completion_updated.php @@ -81,4 +81,18 @@ class course_module_completion_updated extends base { return $this->get_record_snapshot('course_modules_completion', $this->objectid); } + /** + * Custom validation. + * + * @throws \coding_exception in case of a problem. + */ + protected function validate_data() { + // Make sure the context level is set to module. + if ($this->contextlevel !== CONTEXT_MODULE) { + throw new \coding_exception('Context passed must be module context.'); + } + if (!isset($this->relateduserid)) { + throw new \coding_exception('relateduserid must be set'); + } + } } diff --git a/lib/completionlib.php b/lib/completionlib.php index b109afcbbde..96c3f6a975d 100644 --- a/lib/completionlib.php +++ b/lib/completionlib.php @@ -1042,9 +1042,8 @@ class completion_info { // Trigger an event for course module completion changed. $event = \core\event\course_module_completion_updated::create( array('objectid' => $data->id, - 'userid' => $USER->id, 'context' => $cmcontext, - 'courseid' => $coursecontext->instanceid, + 'relateduserid' => $data->userid, 'other' => array('relateduserid' => $data->userid) ) ); diff --git a/lib/tests/completionlib_test.php b/lib/tests/completionlib_test.php index 23d7770bc2d..5062e3b23ee 100644 --- a/lib/tests/completionlib_test.php +++ b/lib/tests/completionlib_test.php @@ -500,6 +500,7 @@ class core_completionlib_testcase extends advanced_testcase { $data->coursemoduleid = $cm->id; $data->completionstate = COMPLETION_COMPLETE; $data->timemodified = time(); + $data->viewed = COMPLETION_NOT_VIEWED; $c->internal_set_data($cm, $data); $d1 = $DB->get_field('course_modules_completion', 'id', array('coursemoduleid' => $cm->id)); @@ -518,6 +519,7 @@ class core_completionlib_testcase extends advanced_testcase { $d2->coursemoduleid = $cm2->id; $d2->completionstate = COMPLETION_COMPLETE; $d2->timemodified = time(); + $d2->viewed = COMPLETION_NOT_VIEWED; $c->internal_set_data($cm2, $d2); $this->assertFalse(isset($SESSION->completioncache)); @@ -533,6 +535,7 @@ class core_completionlib_testcase extends advanced_testcase { $d3->coursemoduleid = $cm3->id; $d3->completionstate = COMPLETION_COMPLETE; $d3->timemodified = time(); + $d3->viewed = COMPLETION_NOT_VIEWED; $DB->insert_record('course_modules_completion', $d3); $c->internal_set_data($cm, $data); } diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 856ff598105..37bae10900c 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -4342,6 +4342,12 @@ function forum_add_new_post($post, $mform, &$message) { $post->mailed = FORUM_MAILED_PENDING; $post->userid = $USER->id; $post->attachment = ""; + if (!isset($post->totalscore)) { + $post->totalscore = 0; + } + if (!isset($post->mailnow)) { + $post->mailnow = 0; + } $post->id = $DB->insert_record("forum_posts", $post); $post->message = file_save_draft_area_files($post->itemid, $context->id, 'mod_forum', 'post', $post->id, @@ -4469,6 +4475,7 @@ function forum_add_discussion($discussion, $mform=null, $unused=null, $userid=nu $discussion->timemodified = $timenow; $discussion->usermodified = $post->userid; $discussion->userid = $userid; + $discussion->assessed = 0; $post->discussion = $DB->insert_record("forum_discussions", $discussion); diff --git a/mod/forum/post.php b/mod/forum/post.php index 868c51412cc..84223fc34ab 100644 --- a/mod/forum/post.php +++ b/mod/forum/post.php @@ -755,7 +755,6 @@ if ($fromform = $mform_post->get_data()) { } $event = \mod_forum\event\post_updated::create($params); - $event->add_record_snapshot('forum_posts', $fromform); $event->add_record_snapshot('forum_discussions', $discussion); $event->trigger(); diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index 480e7a57234..9e054a790c3 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -127,6 +127,8 @@ function quiz_create_attempt(quiz $quizobj, $attemptnumber, $lastattempt, $timen $attempt->timefinish = 0; $attempt->timemodified = $timenow; $attempt->state = quiz_attempt::IN_PROGRESS; + $attempt->currentpage = 0; + $attempt->sumgrades = null; // If this is a preview, mark it as such. if ($ispreview) { diff --git a/mod/workshop/submission.php b/mod/workshop/submission.php index 999be07dd74..abf0cb5ebcd 100644 --- a/mod/workshop/submission.php +++ b/mod/workshop/submission.php @@ -232,7 +232,7 @@ if ($edit) { // store the updated values or re-save the new submission (re-saving needed because URLs are now rewritten) $DB->update_record('workshop_submissions', $formdata); $event = \mod_workshop\event\submission_updated::create($params); - $event->add_record_snapshot('workshop_submissions', $formdata); + $event->add_record_snapshot('workshop', $workshop); $event->trigger(); // send submitted content for plagiarism detection