From 69384c193919be84b3d3a69b658fac9039367b01 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 30 Jun 2011 15:20:42 +0100 Subject: [PATCH 1/2] MDL-28127 incorrect lang string placeholder in question engine upgrade. --- question/engine/upgrade/upgradelib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/question/engine/upgrade/upgradelib.php b/question/engine/upgrade/upgradelib.php index 8cbe1be0fe4..5ca15b35fba 100644 --- a/question/engine/upgrade/upgradelib.php +++ b/question/engine/upgrade/upgradelib.php @@ -67,7 +67,7 @@ class question_engine_attempt_upgrader { gc_collect_cycles(); // This was really helpful in PHP 5.2. Perhaps remove. $a = new stdClass(); $a->done = $done; - $a->todo = $outof; + $a->outof = $outof; $a->info = $quizid; $this->progressbar->update($done, $outof, get_string('upgradingquizattempts', 'quiz', $a)); } From ceb4d2ed0b4c2d11ed97139f027d1b890e578e0a Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Thu, 30 Jun 2011 16:00:15 +0100 Subject: [PATCH 2/2] MDL-28128 finish the fix for MDL-28035. There was one place where I had only fixed the backup code to work-around bad data from Moodle 2.0. I needed to make the equivalent change in the upgrade code. The bad data is that the seq_number fields can be wrong (not unique). Se already have data ordered by (seq_number, id) and the array keys of the array we are building are not used for anything, so this fix deals with the problem. --- question/engine/upgrade/upgradelib.php | 2 +- .../db/simpletest/testupgradelibnewqe.php | 197 ++++++++++++++++++ 2 files changed, 198 insertions(+), 1 deletion(-) diff --git a/question/engine/upgrade/upgradelib.php b/question/engine/upgrade/upgradelib.php index 5ca15b35fba..21b1c674171 100644 --- a/question/engine/upgrade/upgradelib.php +++ b/question/engine/upgrade/upgradelib.php @@ -333,7 +333,7 @@ class question_engine_attempt_upgrader { } // Add the new state to the array, and advance. - $qstates[$state->seq_number] = $state; + $qstates[] = $state; $questionsstatesrs->next(); } diff --git a/question/type/truefalse/db/simpletest/testupgradelibnewqe.php b/question/type/truefalse/db/simpletest/testupgradelibnewqe.php index 78db2ed9a39..d14100bc416 100644 --- a/question/type/truefalse/db/simpletest/testupgradelibnewqe.php +++ b/question/type/truefalse/db/simpletest/testupgradelibnewqe.php @@ -962,6 +962,203 @@ class qtype_truefalse_attempt_upgrader_test extends question_attempt_upgrader_te ), ); + $this->compare_qas($expectedqa, $qa); + } + + public function test_truefalse_adaptive_qsession3() { + $quiz = (object) array( + 'id' => '1', + 'course' => '2', + 'name' => 'Test Quiz', + 'intro' => '', + 'introformat' => '1', + 'timeopen' => '0', + 'timeclose' => '0', + 'preferredbehaviour' => 'adaptive', + 'attempts' => '0', + 'attemptonlast' => '0', + 'grademethod' => '1', + 'decimalpoints' => '2', + 'questiondecimalpoints' => '-1', + 'reviewattempt' => '69888', + 'reviewcorrectness' => '69888', + 'reviewmarks' => '69888', + 'reviewspecificfeedback' => '69888', + 'reviewgeneralfeedback' => '69888', + 'reviewrightanswer' => '69888', + 'reviewoverallfeedback' => '4352', + 'questionsperpage' => '1', + 'shufflequestions' => '0', + 'shuffleanswers' => '1', + 'questions' => '1,0', + 'sumgrades' => '1.00000', + 'grade' => '10.00000', + 'timecreated' => '0', + 'timemodified' => '1309441728', + 'timelimit' => '0', + 'password' => '', + 'subnet' => '', + 'popup' => '0', + 'delay1' => '0', + 'delay2' => '0', + 'showuserpicture' => '0', + 'showblocks' => '0', + ); + $attempt = (object) array( + 'id' => '3', + 'uniqueid' => '3', + 'quiz' => '1', + 'userid' => '4', + 'attempt' => '2', + 'sumgrades' => null, + 'timestart' => '1309441460', + 'timefinish' => '1309441471', + 'timemodified' => '1309441969', + 'layout' => '1,0', + 'preview' => '0', + 'needsupgradetonewqe' => 1, + ); + $question = (object) array( + 'id' => '1', + 'category' => '2', + 'parent' => '0', + 'name' => 'Does 1 + 1 = 2?', + 'questiontext' => '', + 'questiontextformat' => '1', + 'generalfeedback' => '', + 'generalfeedbackformat' => '1', + 'defaultmark' => '1.0000000', + 'penalty' => '1.0000000', + 'qtype' => 'truefalse', + 'length' => '1', + 'stamp' => 'localhost:8888+110630134237+QzfsHZ', + 'version' => 'localhost:8888+110630134237+IaYGE6', + 'hidden' => '0', + 'timecreated' => '1309441357', + 'timemodified' => '1309441357', + 'createdby' => '3', + 'modifiedby' => '3', + 'maxmark' => '1.0000000', + 'options' => (object) array( + 'id' => '1', + 'question' => '1', + 'trueanswer' => '1', + 'falseanswer' => '2', + 'answers' => array( + 1 => (object) array( + 'id' => '1', + 'question' => '1', + 'answer' => 'True', + 'answerformat' => '0', + 'fraction' => '1.0000000', + 'feedback' => '', + 'feedbackformat' => '1', + ), + 2 => (object) array( + 'id' => '2', + 'question' => '1', + 'answer' => 'False', + 'answerformat' => '0', + 'fraction' => '0.0000000', + 'feedback' => '', + 'feedbackformat' => '1', + ), + ), + ), + ); + $qsession = (object) array( + 'id' => '3', + 'attemptid' => '3', + 'questionid' => '1', + 'newest' => '7', + 'newgraded' => '7', + 'sumpenalty' => '1.0000000', + 'manualcomment' => '', + 'manualcommentformat' => '1', + 'flagged' => '0', + ); + $qstates = array( + 5 => (object) array( + 'id' => '5', + 'attempt' => '3', + 'question' => '1', + 'seq_number' => '0', + 'answer' => '', + 'timestamp' => '1309441460', + 'event' => '0', + 'grade' => '0.0000000', + 'raw_grade' => '0.0000000', + 'penalty' => '0.0000000', + ), + 6 => (object) array( + 'id' => '6', + 'attempt' => '3', + 'question' => '1', + 'seq_number' => '1', + 'answer' => '1', + 'timestamp' => '1309441463', + 'event' => '3', + 'grade' => '1.0000000', + 'raw_grade' => '1.0000000', + 'penalty' => '1.0000000', + ), + 7 => (object) array( + 'id' => '7', + 'attempt' => '3', + 'question' => '1', + 'seq_number' => '1', + 'answer' => '1', + 'timestamp' => '1309441463', + 'event' => '6', + 'grade' => '1.0000000', + 'raw_grade' => '1.0000000', + 'penalty' => '1.0000000', + ), + ); + + $qa = $this->updater->convert_question_attempt($quiz, $attempt, $question, $qsession, $qstates); + + $expectedqa = (object) array( + 'behaviour' => 'adaptive', + 'questionid' => 1, + 'variant' => 1, + 'maxmark' => 1.0000000, + 'minfraction' => 0, + 'flagged' => 0, + 'questionsummary' => '', + 'rightanswer' => 'True', + 'responsesummary' => 'True', + 'timemodified' => 1309441463, + 'steps' => array( + 0 => (object) array( + 'sequencenumber' => 0, + 'state' => 'todo', + 'fraction' => null, + 'timecreated' => 1309441460, + 'userid' => 4, + 'data' => array(), + ), + 1 => (object) array( + 'sequencenumber' => 1, + 'state' => 'complete', + 'fraction' => 1, + 'timecreated' => 1309441463, + 'userid' => 4, + 'data' => array('answer' => 1, '-submit' => 1, + '-_try' => 1, '-_rawfraction' => 1), + ), + 2 => (object) array( + 'sequencenumber' => 2, + 'state' => 'gradedright', + 'fraction' => 1, + 'timecreated' => 1309441463, + 'userid' => 4, + 'data' => array('answer' => 1, '-finish' => 1, + '-_try' => 1, '-_rawfraction' => 1), + ), + ), + ); + $this->compare_qas($expectedqa, $qa); } }