MDL-28169 Installation Added 2.1 upgrade (idiot proof) lines to upgrade scripts.
[moodle.git] / question / type / match / db / upgrade.php
blobfa89bf3d874c432fcf2043a3721a491484c155e1
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17 /**
18 * Matching question type upgrade code.
20 * @package qtype
21 * @subpackage match
22 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') || die();
30 /**
31 * Upgrade code for the matching question type.
32 * @param int $oldversion the version we are upgrading from.
34 function xmldb_qtype_match_upgrade($oldversion) {
35 global $CFG, $DB;
37 $dbman = $DB->get_manager();
39 if ($oldversion < 2009072100) {
41 // Define field questiontextformat to be added to question_match_sub
42 $table = new xmldb_table('question_match_sub');
43 $field = new xmldb_field('questiontextformat', XMLDB_TYPE_INTEGER, '2', null,
44 XMLDB_NOTNULL, null, '0', 'questiontext');
46 // Conditionally launch add field questiontextformat
47 if (!$dbman->field_exists($table, $field)) {
48 $dbman->add_field($table, $field);
51 // In the past, question_match_sub.questiontext assumed to contain
52 // content of the same form as question.questiontextformat. If we are
53 // using the HTML editor, then convert FORMAT_MOODLE content to FORMAT_HTML.
54 $rs = $DB->get_recordset_sql('
55 SELECT qms.*, q.oldquestiontextformat
56 FROM {question_match_sub} qms
57 JOIN {question} q ON qms.question = q.id');
58 foreach ($rs as $record) {
59 if ($CFG->texteditors !== 'textarea' &&
60 $record->oldquestiontextformat == FORMAT_MOODLE) {
61 $record->questiontext = text_to_html($record->questiontext, false, false, true);
62 $record->questiontextformat = FORMAT_HTML;
63 } else {
64 $record->questiontextformat = $record->oldquestiontextformat;
66 $DB->update_record('question_match_sub', $record);
68 $rs->close();
70 // match savepoint reached
71 upgrade_plugin_savepoint(true, 2009072100, 'qtype', 'match');
74 if ($oldversion < 2011011300) {
76 // Define field correctfeedback to be added to question_match
77 $table = new xmldb_table('question_match');
78 $field = new xmldb_field('correctfeedback', XMLDB_TYPE_TEXT, 'small', null,
79 null, null, null, 'shuffleanswers');
81 // Conditionally launch add field correctfeedback
82 if (!$dbman->field_exists($table, $field)) {
83 $dbman->add_field($table, $field);
85 // Now fill it with '';
86 $DB->set_field('question_match', 'correctfeedback', '');
88 // Now add the not null constraint.
89 $field = new xmldb_field('correctfeedback', XMLDB_TYPE_TEXT, 'small', null,
90 XMLDB_NOTNULL, null, null, 'shuffleanswers');
91 $dbman->change_field_notnull($table, $field);
94 // match savepoint reached
95 upgrade_plugin_savepoint(true, 2011011300, 'qtype', 'match');
98 if ($oldversion < 2011011301) {
100 // Define field correctfeedbackformat to be added to question_match
101 $table = new xmldb_table('question_match');
102 $field = new xmldb_field('correctfeedbackformat', XMLDB_TYPE_INTEGER, '2', null,
103 XMLDB_NOTNULL, null, '0', 'correctfeedback');
105 // Conditionally launch add field correctfeedbackformat
106 if (!$dbman->field_exists($table, $field)) {
107 $dbman->add_field($table, $field);
110 // match savepoint reached
111 upgrade_plugin_savepoint(true, 2011011301, 'qtype', 'match');
114 if ($oldversion < 2011011302) {
116 // Define field partiallycorrectfeedback to be added to question_match
117 $table = new xmldb_table('question_match');
118 $field = new xmldb_field('partiallycorrectfeedback', XMLDB_TYPE_TEXT, 'small', null,
119 null, null, null, 'correctfeedbackformat');
121 // Conditionally launch add field partiallycorrectfeedback
122 if (!$dbman->field_exists($table, $field)) {
123 $dbman->add_field($table, $field);
125 // Now fill it with '';
126 $DB->set_field('question_match', 'partiallycorrectfeedback', '');
128 // Now add the not null constraint.
129 $field = new xmldb_field('partiallycorrectfeedback', XMLDB_TYPE_TEXT, 'small', null,
130 XMLDB_NOTNULL, null, null, 'correctfeedbackformat');
131 $dbman->change_field_notnull($table, $field);
134 // match savepoint reached
135 upgrade_plugin_savepoint(true, 2011011302, 'qtype', 'match');
138 if ($oldversion < 2011011303) {
140 // Define field partiallycorrectfeedbackformat to be added to question_match
141 $table = new xmldb_table('question_match');
142 $field = new xmldb_field('partiallycorrectfeedbackformat', XMLDB_TYPE_INTEGER, '2', null,
143 XMLDB_NOTNULL, null, '0', 'partiallycorrectfeedback');
145 // Conditionally launch add field partiallycorrectfeedbackformat
146 if (!$dbman->field_exists($table, $field)) {
147 $dbman->add_field($table, $field);
150 // match savepoint reached
151 upgrade_plugin_savepoint(true, 2011011303, 'qtype', 'match');
154 if ($oldversion < 2011011304) {
156 // Define field incorrectfeedback to be added to question_match
157 $table = new xmldb_table('question_match');
158 $field = new xmldb_field('incorrectfeedback', XMLDB_TYPE_TEXT, 'small', null,
159 null, null, null, 'partiallycorrectfeedbackformat');
161 // Conditionally launch add field incorrectfeedback
162 if (!$dbman->field_exists($table, $field)) {
163 $dbman->add_field($table, $field);
165 // Now fill it with '';
166 $DB->set_field('question_match', 'incorrectfeedback', '');
168 // Now add the not null constraint.
169 $field = new xmldb_field('incorrectfeedback', XMLDB_TYPE_TEXT, 'small', null,
170 XMLDB_NOTNULL, null, null, 'partiallycorrectfeedbackformat');
171 $dbman->change_field_notnull($table, $field);
174 // match savepoint reached
175 upgrade_plugin_savepoint(true, 2011011304, 'qtype', 'match');
178 if ($oldversion < 2011011305) {
180 // Define field incorrectfeedbackformat to be added to question_match
181 $table = new xmldb_table('question_match');
182 $field = new xmldb_field('incorrectfeedbackformat', XMLDB_TYPE_INTEGER, '2', null,
183 XMLDB_NOTNULL, null, '0', 'incorrectfeedback');
185 // Conditionally launch add field incorrectfeedbackformat
186 if (!$dbman->field_exists($table, $field)) {
187 $dbman->add_field($table, $field);
190 // match savepoint reached
191 upgrade_plugin_savepoint(true, 2011011305, 'qtype', 'match');
194 if ($oldversion < 2011011306) {
196 // Define field shownumcorrect to be added to question_match
197 $table = new xmldb_table('question_match');
198 $field = new xmldb_field('shownumcorrect', XMLDB_TYPE_INTEGER, '2', null,
199 XMLDB_NOTNULL, null, '0', 'incorrectfeedbackformat');
201 // Conditionally launch add field shownumcorrect
202 if (!$dbman->field_exists($table, $field)) {
203 $dbman->add_field($table, $field);
206 // match savepoint reached
207 upgrade_plugin_savepoint(true, 2011011306, 'qtype', 'match');
210 // Moodle v2.1.0 release upgrade line
211 // Put any upgrade step following this
213 return true;