MDL-44321 events: make sure the full object is passed to add_record_snapshot()
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
)
|
||||
);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user