MDL-52203 qtype_multianswer: avoid fatal error during upgrade
authorMarina Glancy <marina@moodle.com>
Thu, 19 Nov 2015 03:06:48 +0000 (11:06 +0800)
committerMarina Glancy <marina@moodle.com>
Thu, 19 Nov 2015 03:06:48 +0000 (11:06 +0800)
question/type/multianswer/db/upgrade.php

index c6935d3..e5c3839 100644 (file)
@@ -67,10 +67,10 @@ function xmldb_qtype_multianswer_upgrade($oldversion) {
                  FROM {question} q
                  JOIN {question_multianswer} qma ON q.id = qma.question");
         foreach ($rs as $q) {
-            if (!empty($q->sequence)) {
+            $sequence = preg_split('/,/', $q->sequence, -1, PREG_SPLIT_NO_EMPTY);
+            if ($sequence) {
                 // Get relevant data indexed by positionkey from the multianswers table.
-                $wrappedquestions = $DB->get_records_list('question', 'id',
-                        explode(',', $q->sequence), 'id ASC');
+                $wrappedquestions = $DB->get_records_list('question', 'id', $sequence, 'id ASC');
                 foreach ($wrappedquestions as $wrapped) {
                     if ($wrapped->qtype == 'multichoice') {
                         $options = $DB->get_record('qtype_multichoice_options', array('questionid' => $wrapped->id), '*');