From c389b50482c793853cbb4a6f3d08f076f7bec6d4 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Fri, 17 Aug 2007 10:01:34 +0000 Subject: [PATCH] MDL-10863 - multichoice question type won't upgrade to 1.9 beta because MySQL sometimes treats enum constants case-insensitively. --- question/type/multichoice/db/install.xml | 2 +- question/type/multichoice/db/upgrade.php | 23 +++++++++++++++++----- question/type/multichoice/questiontype.php | 4 ++-- question/type/multichoice/version.php | 2 +- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/question/type/multichoice/db/install.xml b/question/type/multichoice/db/install.xml index d6b39f76bf..7c504cc65f 100644 --- a/question/type/multichoice/db/install.xml +++ b/question/type/multichoice/db/install.xml @@ -15,7 +15,7 @@ - + diff --git a/question/type/multichoice/db/upgrade.php b/question/type/multichoice/db/upgrade.php index 722b9d4e4f..3f4b4273b8 100644 --- a/question/type/multichoice/db/upgrade.php +++ b/question/type/multichoice/db/upgrade.php @@ -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; } diff --git a/question/type/multichoice/questiontype.php b/question/type/multichoice/questiontype.php index 4af601ffe5..042b632e24 100644 --- a/question/type/multichoice/questiontype.php +++ b/question/type/multichoice/questiontype.php @@ -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)); diff --git a/question/type/multichoice/version.php b/question/type/multichoice/version.php index 1d2c643da2..8d81a77247 100644 --- a/question/type/multichoice/version.php +++ b/question/type/multichoice/version.php @@ -1,6 +1,6 @@ version = 2007072000; +$plugin->version = 2007081700; $plugin->requires = 2006032200; ?> -- 2.39.5