mod-quiz MDL-25791 Added conditions around upgrade code so that it is only executed...
[moodle.git] / mod / quiz / db / upgrade.php
CommitLineData
83192608 1<?php
b8a342d7 2
271e6dec 3// This file keeps track of upgrades to
b8a342d7 4// the quiz module
5//
6// Sometimes, changes between versions involve
7// alterations to database structures and other
8// major things that may break installations.
9//
10// The upgrade function in this file will attempt
11// to perform all the necessary actions to upgrade
2e0406a5 12// your older installation to the current version.
b8a342d7 13//
14// If there's something it cannot do itself, it
15// will tell you what you need to do.
16//
17// The commands in here will all be database-neutral,
b1f93b15 18// using the methods of database_manager class
775f811a 19//
20// Please do not forget to use upgrade_set_timeout()
21// before any action that may take longer time to finish.
b8a342d7 22
0022ea36
SH
23/**
24 * @global moodle_database $DB
25 * @param int $oldversion
26 * @return bool
27 */
775f811a 28function xmldb_quiz_upgrade($oldversion) {
29 global $CFG, $DB;
84e628a0 30
f37f30d4 31 $dbman = $DB->get_manager();
b8a342d7 32
219f652b 33//===== 1.9.0 upgrade line ======//
271e6dec 34
a4cdd6d2 35 if ($oldversion < 2008062000) {
f37f30d4 36
37 /// Define table quiz_report to be created
38 $table = new xmldb_table('quiz_report');
39
40 /// Adding fields to table quiz_report
2a88f626 41 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
42 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null);
43 $table->add_field('displayorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
f37f30d4 44
45 /// Adding keys to table quiz_report
46 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
47
48 /// Conditionally launch create table for quiz_report
49 if (!$dbman->table_exists($table)) {
eee5d9bb 50 $dbman->create_table($table);
f37f30d4 51 }
52
a4cdd6d2 53 upgrade_mod_savepoint(true, 2008062000, 'quiz');
f37f30d4 54 }
04264aed 55
a4cdd6d2 56 if ($oldversion < 2008062001) {
39790bd8 57 $reporttoinsert = new stdClass();
f37f30d4 58 $reporttoinsert->name = 'overview';
59 $reporttoinsert->displayorder = 10000;
a4cdd6d2 60 $DB->insert_record('quiz_report', $reporttoinsert);
f37f30d4 61
39790bd8 62 $reporttoinsert = new stdClass();
f37f30d4 63 $reporttoinsert->name = 'responses';
64 $reporttoinsert->displayorder = 9000;
a4cdd6d2 65 $DB->insert_record('quiz_report', $reporttoinsert);
f37f30d4 66
39790bd8 67 $reporttoinsert = new stdClass();
f37f30d4 68 $reporttoinsert->name = 'regrade';
69 $reporttoinsert->displayorder = 7000;
a4cdd6d2 70 $DB->insert_record('quiz_report', $reporttoinsert);
f37f30d4 71
39790bd8 72 $reporttoinsert = new stdClass();
f37f30d4 73 $reporttoinsert->name = 'grading';
74 $reporttoinsert->displayorder = 6000;
a4cdd6d2 75 $DB->insert_record('quiz_report', $reporttoinsert);
04264aed 76
a4cdd6d2 77 upgrade_mod_savepoint(true, 2008062001, 'quiz');
f37f30d4 78 }
84e628a0 79
a4cdd6d2 80 if ($oldversion < 2008072402) {
17f1782c 81
82 /// Define field lastcron to be added to quiz_report
83 $table = new xmldb_table('quiz_report');
2a88f626 84 $field = new xmldb_field('lastcron', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'displayorder');
17f1782c 85
86 /// Conditionally launch add field lastcron
87 if (!$dbman->field_exists($table, $field)) {
88 $dbman->add_field($table, $field);
89 }
90
91 /// Define field cron to be added to quiz_report
2a88f626 92 $field = new xmldb_field('cron', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'lastcron');
17f1782c 93
94 /// Conditionally launch add field cron
95 if (!$dbman->field_exists($table, $field)) {
96 $dbman->add_field($table, $field);
97 }
98
99 /// quiz savepoint reached
a4cdd6d2 100 upgrade_mod_savepoint(true, 2008072402, 'quiz');
17f1782c 101 }
f37f30d4 102
a4cdd6d2 103 if ($oldversion < 2008072900) {
4d9f2c36 104 /// Delete the regrade report - it is now part of the overview report.
a4cdd6d2 105 $DB->delete_records('quiz_report', array('name' => 'regrade'));
4d9f2c36 106
107 /// quiz savepoint reached
a4cdd6d2 108 upgrade_mod_savepoint(true, 2008072900, 'quiz');
4d9f2c36 109 }
f37f30d4 110
a4cdd6d2 111 if ($oldversion < 2008081500) {
6b224376 112 /// Define table quiz_question_versions to be dropped
113 $table = new xmldb_table('quiz_question_versions');
114
115 /// Launch drop table for quiz_question_versions
116 $dbman->drop_table($table);
117
118 /// quiz savepoint reached
a4cdd6d2 119 upgrade_mod_savepoint(true, 2008081500, 'quiz');
6b224376 120 }
121
f9a2cf86 122 /// Changing the type of all the columns that store grades to be NUMBER(10, 5) or similar.
a4cdd6d2 123 if ($oldversion < 2008081501) {
f9a2cf86 124 $table = new xmldb_table('quiz');
0022ea36 125 $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'questions');
f9a2cf86 126 $dbman->change_field_type($table, $field);
a4cdd6d2 127 upgrade_mod_savepoint(true, 2008081501, 'quiz');
f9a2cf86 128 }
129
a4cdd6d2 130 if ($oldversion < 2008081502) {
f9a2cf86 131 $table = new xmldb_table('quiz');
0022ea36 132 $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'sumgrades');
f9a2cf86 133 $dbman->change_field_type($table, $field);
a4cdd6d2 134 upgrade_mod_savepoint(true, 2008081502, 'quiz');
f9a2cf86 135 }
136
a4cdd6d2 137 if ($oldversion < 2008081503) {
f9a2cf86 138 $table = new xmldb_table('quiz_attempts');
0022ea36 139 $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'attempt');
f9a2cf86 140 $dbman->change_field_type($table, $field);
a4cdd6d2 141 upgrade_mod_savepoint(true, 2008081503, 'quiz');
f9a2cf86 142 }
143
a4cdd6d2 144 if ($oldversion < 2008081504) {
f9a2cf86 145 $table = new xmldb_table('quiz_feedback');
0022ea36 146 $field = new xmldb_field('mingrade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'feedbacktext');
f9a2cf86 147 $dbman->change_field_type($table, $field);
a4cdd6d2 148 upgrade_mod_savepoint(true, 2008081504, 'quiz');
f9a2cf86 149 }
150
a4cdd6d2 151 if ($oldversion < 2008081505) {
f9a2cf86 152 $table = new xmldb_table('quiz_feedback');
0022ea36 153 $field = new xmldb_field('maxgrade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'mingrade');
f9a2cf86 154 $dbman->change_field_type($table, $field);
a4cdd6d2 155 upgrade_mod_savepoint(true, 2008081505, 'quiz');
f9a2cf86 156 }
157
a4cdd6d2 158 if ($oldversion < 2008081506) {
f9a2cf86 159 $table = new xmldb_table('quiz_grades');
0022ea36 160 $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'userid');
f9a2cf86 161 $dbman->change_field_type($table, $field);
a4cdd6d2 162 upgrade_mod_savepoint(true, 2008081506, 'quiz');
f9a2cf86 163 }
164
a4cdd6d2 165 if ($oldversion < 2008081507) {
f9a2cf86 166 $table = new xmldb_table('quiz_question_instances');
0022ea36 167 $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0', 'question');
f9a2cf86 168 $dbman->change_field_type($table, $field);
a4cdd6d2 169 upgrade_mod_savepoint(true, 2008081507, 'quiz');
f9a2cf86 170 }
171
e2249afe 172 /// Move all of the quiz config settings from $CFG to the config_plugins table.
a4cdd6d2 173 if ($oldversion < 2008082200) {
e2249afe 174 foreach (get_object_vars($CFG) as $name => $value) {
175 if (strpos($name, 'quiz_') === 0) {
176 $shortname = substr($name, 5);
177 if ($shortname == 'fix_adaptive') {
178 // Special case - remove old inconsistency.
179 $shortname == 'fix_optionflags';
180 }
a4cdd6d2
PS
181 set_config($shortname, $value, 'quiz');
182 unset_config($name);
e2249afe 183 }
184 }
a4cdd6d2 185 upgrade_mod_savepoint(true, 2008082200, 'quiz');
e2249afe 186 }
187
e4686e89 188 /// Now that the quiz is no longer responsible for creating all the question
189 /// bank tables, and some of the tables are now the responsibility of the
190 /// datasetdependent question type, which did not have a version.php file before,
191 /// we need to say that these tables are already installed, otherwise XMLDB
192 /// will try to create them again and give an error.
a4cdd6d2 193 if ($oldversion < 2008082600) {
98e82289 194 // Since MDL-16505 was fixed, and we eliminated the datasetdependent
195 // question type, this is now a no-op.
a4cdd6d2 196 upgrade_mod_savepoint(true, 2008082600, 'quiz');
e4686e89 197 }
84e628a0 198
a4cdd6d2 199 if ($oldversion < 2008112101) {
bbf4f440 200
201 /// Define field lastcron to be added to quiz_report
202 $table = new xmldb_table('quiz_report');
2a88f626 203 $field = new xmldb_field('capability', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'cron');
bbf4f440 204
205 /// Conditionally launch add field lastcron
206 if (!$dbman->field_exists($table, $field)) {
207 $dbman->add_field($table, $field);
208 }
84e628a0 209
bbf4f440 210 /// quiz savepoint reached
a4cdd6d2 211 upgrade_mod_savepoint(true, 2008112101, 'quiz');
bbf4f440 212 }
e4686e89 213
a4cdd6d2 214 if ($oldversion < 2009010700) {
a733c4b9 215
216 /// Define field showuserpicture to be added to quiz
217 $table = new xmldb_table('quiz');
2a88f626 218 $field = new xmldb_field('showuserpicture', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'delay2');
a733c4b9 219
220 /// Conditionally launch add field showuserpicture
221 if (!$dbman->field_exists($table, $field)) {
222 $dbman->add_field($table, $field);
223 }
224
225 /// quiz savepoint reached
a4cdd6d2 226 upgrade_mod_savepoint(true, 2009010700, 'quiz');
a733c4b9 227 }
228
a4cdd6d2 229 if ($oldversion < 2009030900) {
84e628a0 230 /// If there are no quiz settings set to advanced yet, the set up the default
231 /// advanced fields from Moodle 2.0.
232 $quizconfig = get_config('quiz');
233 $arealreadyadvanced = false;
234 foreach (array($quizconfig) as $name => $value) {
235 if (strpos($name, 'fix_') === 0 && !empty($value)) {
236 $arealreadyadvanced = true;
237 break;
238 }
239 }
240
241 if (!$arealreadyadvanced) {
242 set_config('fix_penaltyscheme', 1, 'quiz');
243 set_config('fix_attemptonlast', 1, 'quiz');
244 set_config('fix_questiondecimalpoints', 1, 'quiz');
245 set_config('fix_password', 1, 'quiz');
246 set_config('fix_subnet', 1, 'quiz');
247 set_config('fix_delay1', 1, 'quiz');
248 set_config('fix_delay2', 1, 'quiz');
249 set_config('fix_popup', 1, 'quiz');
250 }
251
252 /// quiz savepoint reached
a4cdd6d2 253 upgrade_mod_savepoint(true, 2009030900, 'quiz');
84e628a0 254 }
255
a4cdd6d2 256 if ($oldversion < 2009031000) {
84e628a0 257 /// Add new questiondecimaldigits setting, separate form the overall decimaldigits one.
258 $table = new xmldb_table('quiz');
0022ea36 259 $field = new xmldb_field('questiondecimalpoints', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '-2', 'decimalpoints');
84e628a0 260 if (!$dbman->field_exists($table, $field)) {
261 $dbman->add_field($table, $field);
262 }
263
264 /// quiz savepoint reached
a4cdd6d2 265 upgrade_mod_savepoint(true, 2009031000, 'quiz');
84e628a0 266 }
267
a4cdd6d2 268 if ($oldversion < 2009031001) {
84e628a0 269 /// Convert quiz.timelimit from minutes to seconds.
270 $DB->execute('UPDATE {quiz} SET timelimit = timelimit * 60');
271 $default = get_config('quiz', 'timelimit');
272 set_config('timelimit', 60 * $default, 'quiz');
273
274 /// quiz savepoint reached
a4cdd6d2 275 upgrade_mod_savepoint(true, 2009031001, 'quiz');
84e628a0 276 }
277
a4cdd6d2 278 if ($oldversion < 2009042000) {
18b5df91 279
280 /// Define field introformat to be added to quiz
281 $table = new xmldb_table('quiz');
2a88f626 282 $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
18b5df91 283
07cb6678
PS
284 if (!$dbman->field_exists($table, $field)) {
285 $dbman->add_field($table, $field);
286 }
18b5df91 287
07cb6678
PS
288 // conditionally migrate to html format in intro
289 if ($CFG->texteditors !== 'textarea') {
a9efae50 290 $rs = $DB->get_recordset('quiz', array('introformat' => FORMAT_MOODLE), '', 'id,intro,introformat');
07cb6678
PS
291 foreach ($rs as $q) {
292 $q->intro = text_to_html($q->intro, false, false, true);
293 $q->introformat = FORMAT_HTML;
294 $DB->update_record('quiz', $q);
295 upgrade_set_timeout();
296 }
297 $rs->close();
298 }
18b5df91 299
300 /// quiz savepoint reached
a4cdd6d2 301 upgrade_mod_savepoint(true, 2009042000, 'quiz');
18b5df91 302 }
303
a4cdd6d2 304 if ($oldversion < 2010030501) {
990650f9
TH
305 /// Define table quiz_overrides to be created
306 $table = new xmldb_table('quiz_overrides');
307
308 /// Adding fields to table quiz_overrides
309 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
310 $table->add_field('quiz', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
311 $table->add_field('groupid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
312 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
313 $table->add_field('timeopen', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
314 $table->add_field('timeclose', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
315 $table->add_field('timelimit', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
316 $table->add_field('attempts', XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, null, null, null);
317 $table->add_field('password', XMLDB_TYPE_CHAR, '255', null, null, null, null);
318
319 /// Adding keys to table quiz_overrides
320 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
321 $table->add_key('quiz', XMLDB_KEY_FOREIGN, array('quiz'), 'quiz', array('id'));
322 $table->add_key('groupid', XMLDB_KEY_FOREIGN, array('groupid'), 'groups', array('id'));
323 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
324
325 /// Conditionally launch create table for quiz_overrides
326 if (!$dbman->table_exists($table)) {
327 $dbman->create_table($table);
328 }
329
330 /// quiz savepoint reached
a4cdd6d2 331 upgrade_mod_savepoint(true, 2010030501, 'quiz');
990650f9
TH
332 }
333
a4cdd6d2 334 if ($oldversion < 2010051800) {
56ed242b 335
9bb6663e 336 // Define field showblocks to be added to quiz
56ed242b
SH
337 $table = new xmldb_table('quiz');
338 $field = new xmldb_field('showblocks', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'showuserpicture');
339
9bb6663e 340 // Conditionally launch add field showblocks
56ed242b
SH
341 if (!$dbman->field_exists($table, $field)) {
342 $dbman->add_field($table, $field);
343 }
344
9bb6663e 345 // quiz savepoint reached
a4cdd6d2 346 upgrade_mod_savepoint(true, 2010051800, 'quiz');
56ed242b
SH
347 }
348
fe6ce234
DC
349 if ($oldversion < 2010080600) {
350
351 // Define field feedbacktextformat to be added to quiz_feedback
352 $table = new xmldb_table('quiz_feedback');
353 $field = new xmldb_field('feedbacktextformat', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'feedbacktext');
354
355 // Conditionally launch add field feedbacktextformat
356 if (!$dbman->field_exists($table, $field)) {
357 $dbman->add_field($table, $field);
358 }
359
a9efae50
TH
360 // This column defaults to FORMAT_MOODLE, which is correct.
361
fe6ce234
DC
362 // quiz savepoint reached
363 upgrade_mod_savepoint(true, 2010080600, 'quiz');
364 }
365
9bb6663e
TH
366 if ($oldversion < 2010102000) {
367
368 // Define field showblocks to be added to quiz
369 // Repeat this step, because the column was missing from install.xml for a time.
370 $table = new xmldb_table('quiz');
371 $field = new xmldb_field('showblocks', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'showuserpicture');
372
373 // Conditionally launch add field showblocks
374 if (!$dbman->field_exists($table, $field)) {
375 $dbman->add_field($table, $field);
376 }
377
378 // quiz savepoint reached
379 upgrade_mod_savepoint(true, 2010102000, 'quiz');
380 }
0022ea36
SH
381
382 if ($oldversion < 2010122300) {
383 // Fix quiz in the post table after upgrade from 1.9
384 $table = new xmldb_table('quiz');
b3abfc46
SH
385 $columns = $DB->get_columns('quiz');
386
387 if (array_key_exists('questiondecimalpoints', $columns) && $columns['questiondecimalpoints']->default_value != '-2') {
388 // questiondecimalpoints should be default -2
389 // Fixed in earlier upgrade code
390 $field = new xmldb_field('questiondecimalpoints', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, -2, 'decimalpoints');
391 if ($dbman->field_exists($table, $field)) {
392 $dbman->change_field_default($table, $field);
393 }
0022ea36 394 }
b3abfc46
SH
395
396 if (array_key_exists('sumgrades', $columns) && empty($columns['sumgrades']->not_null)) {
397 // sumgrades should be NOT NULL DEFAULT '0.0000000',
398 // Fixed in earlier upgrade code
399 $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'questions');
400 if ($dbman->field_exists($table, $field)) {
401 $dbman->change_field_default($table, $field);
402 }
0022ea36 403 }
b3abfc46
SH
404
405 if (array_key_exists('grade', $columns) && empty($columns['grade']->not_null)) {
406 // grade should be NOT NULL DEFAULT '0.0000000',
407 // Fixed in earlier upgrade code
408 $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'sumgrades');
409 if ($dbman->field_exists($table, $field)) {
410 $dbman->change_field_default($table, $field);
411 }
0022ea36 412 }
b3abfc46 413
0022ea36
SH
414 upgrade_mod_savepoint(true, 2010122300, 'quiz');
415 }
416
417 if ($oldversion < 2010122301) {
418 // Fix quiz_attempts in the post table after upgrade from 1.9
419 $table = new xmldb_table('quiz_attempts');
b3abfc46
SH
420 $columns = $DB->get_columns('quiz_attempts');
421
422 if (array_key_exists('sumgrades', $columns) && empty($columns['sumgrades']->not_null)) {
423 // sumgrades should be NOT NULL DEFAULT '0.0000000',
424 // Fixed in earlier upgrade code
425 $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'attempt');
426 if ($dbman->field_exists($table, $field)) {
427 $dbman->change_field_default($table, $field);
428 }
0022ea36 429 }
b3abfc46 430
0022ea36
SH
431 upgrade_mod_savepoint(true, 2010122301, 'quiz');
432 }
433
434 if ($oldversion < 2010122302) {
435 // Fix quiz_feedback in the post table after upgrade from 1.9
436 $table = new xmldb_table('quiz_feedback');
b3abfc46
SH
437 $columns = $DB->get_columns('quiz_feedback');
438
439 if (array_key_exists('mingrade', $columns) && empty($columns['mingrade']->not_null)) {
440 // mingrade should be NOT NULL DEFAULT '0.0000000',
441 // Fixed in earlier upgrade code
442 $field = new xmldb_field('mingrade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'feedbacktextformat');
443 if ($dbman->field_exists($table, $field)) {
444 $dbman->change_field_default($table, $field);
445 }
0022ea36 446 }
b3abfc46
SH
447
448 if (array_key_exists('maxgrade', $columns) && empty($columns['maxgrade']->not_null)) {
449 // maxgrade should be NOT NULL DEFAULT '0.0000000',
450 // Fixed in earlier upgrade code
451 $field = new xmldb_field('maxgrade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'mingrade');
452 if ($dbman->field_exists($table, $field)) {
453 $dbman->change_field_default($table, $field);
454 }
0022ea36
SH
455 }
456
457 upgrade_mod_savepoint(true, 2010122302, 'quiz');
458 }
459
460 if ($oldversion < 2010122303) {
461 // Fix quiz_grades in the post table after upgrade from 1.9
462 $table = new xmldb_table('quiz_grades');
b3abfc46
SH
463 $columns = $DB->get_columns('quiz_grades');
464
465 if (array_key_exists('grade', $columns) && empty($columns['grade']->not_null)) {
466 // grade should be NOT NULL DEFAULT '0.0000000',
467 // Fixed in earlier upgrade code
468 $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'userid');
469 if ($dbman->field_exists($table, $field)) {
470 $dbman->change_field_default($table, $field);
471 }
0022ea36 472 }
b3abfc46 473
0022ea36
SH
474 upgrade_mod_savepoint(true, 2010122303, 'quiz');
475 }
476
477 if ($oldversion < 2010122304) {
478 // Fix quiz_question_instances in the post table after upgrade from 1.9
479 $table = new xmldb_table('quiz_question_instances');
b3abfc46
SH
480 $columns = $DB->get_columns('quiz_question_instances');
481
482 if (array_key_exists('grade', $columns) && empty($columns['grade']->not_null)) {
483 // grade should be NOT NULL DEFAULT '0.0000000',
484 // Fixed in earlier upgrade code
485 $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null, XMLDB_NOTNULL, null, '0', 'question');
486 if ($dbman->field_exists($table, $field)) {
487 $dbman->change_field_default($table, $field);
488 }
0022ea36 489 }
b3abfc46 490
0022ea36
SH
491 upgrade_mod_savepoint(true, 2010122304, 'quiz');
492 }
fe6ce234 493
a4cdd6d2 494 return true;
b8a342d7 495}
496