MDL-58777 mod_assign: Explicitly sort records and set event priority

The assign update events code depends on the "old" events in the
DB being returned in the same order as they were originally made,
however there was no guarantee that this would be the case.

There were also situations where the priority would not be explicitly
set (e.g., when creating the "original" event).
This commit is contained in:
Cameron Ball 2017-05-05 16:46:22 +08:00
parent 8dada7e334
commit 56d1ddd775
No known key found for this signature in database
GPG Key ID: 305B7F70214D810C

View File

@ -231,14 +231,17 @@ function assign_update_events($assign, $override = null) {
$conds['groupid'] = $override->groupid;
}
}
$oldevents = $DB->get_records('event', $conds);
$oldevents = $DB->get_records('event', $conds, 'id ASC');
// Now make a to-do list of all that needs to be updated.
if (empty($override)) {
// We are updating the primary settings for the assign, so we need to add all the overrides.
$overrides = $DB->get_records('assign_overrides', array('assignid' => $assigninstance->id));
// As well as the original assign (empty override).
$overrides[] = new stdClass();
// We are updating the primary settings for the assignment, so we need to add all the overrides.
$overrides = $DB->get_records('assign_overrides', array('assignid' => $assigninstance->id), 'id ASC');
// It is necessary to add an empty stdClass to the beginning of the array as the $oldevents
// list contains the original (non-override) event for the module. If this is not included
// the logic below will end up updating the wrong row when we try to reconcile this $overrides
// list against the $oldevents list.
array_unshift($overrides, new stdClass());
} else {
// Just do the one override.
$overrides = array($override);
@ -272,6 +275,7 @@ function assign_update_events($assign, $override = null) {
$event->timesort = $event->timestart + $event->timeduration;
$event->visible = instance_is_visible('assign', $assigninstance);
$event->eventtype = ASSIGN_EVENT_TYPE_DUE;
$event->priority = null;
// Determine the event name and priority.
if ($groupid) {