Skip to content

Commit

Permalink
MDL-40441 fix obscure notice in the quiz.
Browse files Browse the repository at this point in the history
This can only happen if you have both a user with both a real attempt
and a preview, and then edit the quiz settings.

Also clean up this code a bit.
  • Loading branch information
timhunt committed Jul 9, 2013
1 parent 4c6f1ec commit b9f1aaa
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions mod/quiz/lib.php
Expand Up @@ -106,18 +106,24 @@ function quiz_add_instance($quiz) {
*/
function quiz_update_instance($quiz, $mform) {
global $CFG, $DB;
require_once($CFG->dirroot . '/mod/quiz/locallib.php');

// Process the options from the form.
$result = quiz_process_options($quiz);
if ($result && is_string($result)) {
return $result;
}

// Get the current value, so we can see what changed.
$oldquiz = $DB->get_record('quiz', array('id' => $quiz->instance));

// We need two values from the existing DB record that are not in the form,
// in some of the function calls below.
$quiz->sumgrades = $oldquiz->sumgrades;
$quiz->grade = $oldquiz->grade;

// Repaginate, if asked to.
if (!$quiz->shufflequestions && !empty($quiz->repaginatenow)) {
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
$quiz->questions = quiz_repaginate(quiz_clean_layout($oldquiz->questions, true),
$quiz->questionsperpage);
}
Expand All @@ -131,19 +137,15 @@ function quiz_update_instance($quiz, $mform) {
quiz_after_add_or_update($quiz);

if ($oldquiz->grademethod != $quiz->grademethod) {
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
$quiz->sumgrades = $oldquiz->sumgrades;
$quiz->grade = $oldquiz->grade;
quiz_update_all_final_grades($quiz);
quiz_update_grades($quiz);
}

$updateattempts = $oldquiz->timelimit != $quiz->timelimit
|| $oldquiz->timeclose != $quiz->timeclose
|| $oldquiz->graceperiod != $quiz->graceperiod;
if ($updateattempts) {
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
quiz_update_open_attempts(array('quizid'=>$quiz->id));
$quizdateschanged = $oldquiz->timelimit != $quiz->timelimit
|| $oldquiz->timeclose != $quiz->timeclose
|| $oldquiz->graceperiod != $quiz->graceperiod;
if ($quizdateschanged) {
quiz_update_open_attempts(array('quizid' => $quiz->id));
}

// Delete any previous preview attempts.
Expand Down

0 comments on commit b9f1aaa

Please sign in to comment.