Skip to content

Commit

Permalink
MDL-58777 mod_quiz: Explicitly sort records and set event priority
Browse files Browse the repository at this point in the history
The quiz 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).
  • Loading branch information
cameorn1730 committed May 10, 2017
1 parent 9c98546 commit 4133df6
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions mod/quiz/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1205,14 +1205,17 @@ function quiz_update_events($quiz, $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 lesson, so we need to add all the overrides.
$overrides = $DB->get_records('quiz_overrides', array('quiz' => $quiz->id));
// As well as the original quiz (empty override).
$overrides[] = new stdClass();
// We are updating the primary settings for the quiz, so we need to add all the overrides.
$overrides = $DB->get_records('quiz_overrides', array('quiz' => $quiz->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);
Expand Down Expand Up @@ -1251,6 +1254,7 @@ function quiz_update_events($quiz, $override = null) {
$event->timesort = $timeopen;
$event->visible = instance_is_visible('quiz', $quiz);
$event->eventtype = QUIZ_EVENT_TYPE_OPEN;
$event->priority = null;

// Determine the event name and priority.
if ($groupid) {
Expand Down

0 comments on commit 4133df6

Please sign in to comment.