From 9212fe7a792e10bd6fbdfcf545c94e8db81df53a Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Wed, 20 Jun 2012 16:00:54 +0100 Subject: [PATCH] MDL-32062 question engine: fix re-grading attempts from 2.0 The code to upgrade attempts from before Moodle 2.0 to 2.1 created attempt data that was not exactly the same as a new attempt created in 2.1+. This did not matter very much - revew and the quiz reports all worked OK - but it broke on re-grade. These changes detect the problem data in the re-grade code, an apply a work-around so that the re-grade gives the correct result. --- question/engine/questionattempt.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/question/engine/questionattempt.php b/question/engine/questionattempt.php index 070c4fc56b5..54c4d9f8390 100644 --- a/question/engine/questionattempt.php +++ b/question/engine/questionattempt.php @@ -1086,15 +1086,32 @@ class question_attempt { $first = true; foreach ($oldqa->get_step_iterator() as $step) { $this->observer->notify_step_deleted($step, $this); + if ($first) { + // First step of the attempt. $first = false; $this->start($oldqa->behaviour, $oldqa->get_variant(), $step->get_all_data(), $step->get_timecreated(), $step->get_user_id(), $step->get_id()); + + } else if ($step->has_behaviour_var('finish') && count($step->get_submitted_data()) > 1) { + // This case relates to MDL-32062. The upgrade code from 2.0 + // generates attempts where the final submit of the question + // data, and the finish action, are in the same step. The system + // cannot cope with that, so convert the single old step into + // two new steps. + $submitteddata = $step->get_submitted_data(); + unset($submitteddata['-finish']); + $this->process_action($submitteddata, + $step->get_timecreated(), $step->get_user_id(), $step->get_id()); + $this->finish($step->get_timecreated(), $step->get_user_id()); + } else { + // This is the normal case. Replay the next step of the attempt. $this->process_action($step->get_submitted_data(), $step->get_timecreated(), $step->get_user_id(), $step->get_id()); } } + if ($finished) { $this->finish(); }