]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10863 - multichoice question type won't upgrade to 1.9 beta because MySQL sometim...
authortjhunt <tjhunt>
Fri, 17 Aug 2007 10:01:34 +0000 (10:01 +0000)
committertjhunt <tjhunt>
Fri, 17 Aug 2007 10:01:34 +0000 (10:01 +0000)
question/type/multichoice/db/install.xml
question/type/multichoice/db/upgrade.php
question/type/multichoice/questiontype.php
question/type/multichoice/version.php

index d6b39f76bfc26cca2cdc55122f46da6b17922bb7..7c504cc65fb2d8c2d7f0177633da148f1d7f9178 100644 (file)
@@ -15,7 +15,7 @@
         <FIELD NAME="correctfeedback" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="shuffleanswers" NEXT="partiallycorrectfeedback"/>
         <FIELD NAME="partiallycorrectfeedback" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="correctfeedback" NEXT="incorrectfeedback"/>
         <FIELD NAME="incorrectfeedback" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="partiallycorrectfeedback" NEXT="answernumbering"/>
-        <FIELD NAME="answernumbering" TYPE="char" LENGTH="10" NOTNULL="true" DEFAULT="abc" SEQUENCE="false" ENUM="true" ENUMVALUES="'abc', 'ABC', '123', 'none'" COMMENT="Indicates how and whether the choices should be numbered." PREVIOUS="incorrectfeedback"/>
+        <FIELD NAME="answernumbering" TYPE="char" LENGTH="10" NOTNULL="true" DEFAULT="abc" SEQUENCE="false" ENUM="false" COMMENT="Indicates how and whether the choices should be numbered." PREVIOUS="incorrectfeedback"/>
       </FIELDS>
       <KEYS>
         <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for question_multichoice" NEXT="question"/>
index 722b9d4e4f8440658e5004b4edd2112955d3044a..3f4b4273b8c7e164afc9b0661b2bf1d75b6215bd 100644 (file)
@@ -30,16 +30,17 @@ function xmldb_qtype_multichoice_upgrade($oldversion=0) {
     // with a defaultgrade of 1, when it shoud be 0. We need to reset them all to 0.
     // See MDL-7925. 
     if ($result && $oldversion < 2006121500) {
-        $result = set_field('question', 'defaultgrade', 0,
+        $result = $result && set_field('question', 'defaultgrade', 0,
                 'qtype', DESCRIPTION, 'defaultgrade', 1);
     }
 
-    // Add a field so that question authors can choose whether and how the 
-    // Choices are numbered.
+    // Add a field so that question authors can choose whether and how the Choices are numbered.
+    // Subsequently changed to not create an enum constraint, because it was causing problems -
+    // See 2007081700 update.
     if ($result && $oldversion < 2007041300) {
         $table = new XMLDBTable('question_multichoice');
         $field = new XMLDBField('answernumbering');
-        $field->setAttributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, XMLDB_ENUM, array('abc', 'ABC', '123', 'none'), 'abc', 'incorrectfeedback');
+        $field->setAttributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, 'abc', 'incorrectfeedback');
         $result = $result && add_field($table, $field);
     }
 
@@ -50,10 +51,22 @@ function xmldb_qtype_multichoice_upgrade($oldversion=0) {
     // with a defaultgrade of 1, when it shoud be 0. We need to reset them all to 0.
     // This is re-occurrence of MDL-7925, so we need to do it again. 
     if ($result && $oldversion < 2007072000) {
-        $result = set_field('question', 'defaultgrade', 0,
+        $result = $result && set_field('question', 'defaultgrade', 0,
                 'qtype', DESCRIPTION, 'defaultgrade', 1);
     }
 
+    // Drop enum constraint on 'answernumbering' column, and change ABC to ABCD becuase MySQL
+    // sometimes can't cope with things that differ only by case.
+    if ($result && $oldversion < 2007081700) {
+        if ($result && $oldversion >= 2007041300) {
+            $table = new XMLDBTable('question_multichoice');
+            $field = new XMLDBField('answernumbering');
+            $field->setAttributes(XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, null, null, 'abc', 'incorrectfeedback');
+            $result = $result && change_field_enum($table, $field);
+        }
+        $result = $result && set_field('question_multichoice', 'answernumbering', 'ABCD', 'answernumbering', 'ABC');
+    }
+
     return $result;
 }
 
index 4af601ffe51542fabcf39f643c79db6c32a3c4b4..042b632e24d106e78ece65fa6ebce15a0190c2a0 100644 (file)
@@ -594,7 +594,7 @@ class question_multichoice_qtype extends default_questiontype {
      *      and it should be listed in the definition of this column in install.xml.
      */
     function get_numbering_styles() {
-        return array('abc', 'ABC', '123', 'none');
+        return array('abc', 'ABCD', '123', 'none');
     }
 
     function number_html($qnum) {
@@ -610,7 +610,7 @@ class question_multichoice_qtype extends default_questiontype {
         switch($style) {
             case 'abc':
                 return $this->number_html(chr(ord('a') + $num));
-            case 'ABC':
+            case 'ABCD':
                 return $this->number_html(chr(ord('A') + $num));
             case '123':
                 return $this->number_html(($num + 1));
index 1d2c643da2163a099bccb96fb9d211d85e638dd9..8d81a7724756175da80aa57c0e80d06964b0b01a 100644 (file)
@@ -1,6 +1,6 @@
 <?PHP // $Id$
 
-$plugin->version  = 2007072000;
+$plugin->version  = 2007081700;
 $plugin->requires = 2006032200;
 
 ?>