Skip to content

Commit

Permalink
MDL-44321 events: make sure the full object is passed to add_record_s…
Browse files Browse the repository at this point in the history
…napshot()
  • Loading branch information
marinaglancy committed Feb 28, 2014
1 parent 5e70ea2 commit cd5be9a
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 8 deletions.
4 changes: 2 additions & 2 deletions badges/classes/observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public static function course_module_criteria_review(\core\event\course_module_c
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
Expand Down
1 change: 0 additions & 1 deletion cohort/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion group/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public static function delete_groups($groupids) {
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;
}
Expand Down
1 change: 1 addition & 0 deletions lib/accesslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
14 changes: 14 additions & 0 deletions lib/classes/event/course_module_completion_updated.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,18 @@ protected function get_legacy_eventdata() {
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');
}
}
}
3 changes: 1 addition & 2 deletions lib/completionlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1042,9 +1042,8 @@ public function internal_set_data($cm, $data) {
// 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)
)
);
Expand Down
3 changes: 3 additions & 0 deletions lib/tests/completionlib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ public function test_internal_set_data() {
$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));
Expand All @@ -518,6 +519,7 @@ public function test_internal_set_data() {
$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));

Expand All @@ -533,6 +535,7 @@ public function test_internal_set_data() {
$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);
}
Expand Down
7 changes: 7 additions & 0 deletions mod/forum/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down
1 change: 0 additions & 1 deletion mod/forum/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,6 @@
}

$event = \mod_forum\event\post_updated::create($params);
$event->add_record_snapshot('forum_posts', $fromform);
$event->add_record_snapshot('forum_discussions', $discussion);
$event->trigger();

Expand Down
2 changes: 2 additions & 0 deletions mod/quiz/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion mod/workshop/submission.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
// 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
Expand Down

0 comments on commit cd5be9a

Please sign in to comment.