MDL-27408 Moved the question engine install/upgrade code into the proper place.
[moodle.git] / mod / quiz / db / upgrade.php
blob258d14b74d5050c653c65b93cf3c35a2dbeeb81c
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 * Upgrade script for the quiz module.
20 * @package mod
21 * @subpackage quiz
22 * @copyright 2006 Eloy Lafuente (stronk7)
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') || die();
30 /**
31 * Quiz module upgrade function.
32 * @param string $oldversion the version we are upgrading from.
34 function xmldb_quiz_upgrade($oldversion) {
35 global $CFG, $DB;
37 $dbman = $DB->get_manager();
39 //===== 1.9.0 upgrade line ======//
41 if ($oldversion < 2008062000) {
43 // Define table quiz_report to be created
44 $table = new xmldb_table('quiz_report');
46 // Adding fields to table quiz_report
47 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
48 XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
49 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null,
50 null, null, null);
51 $table->add_field('displayorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
52 XMLDB_NOTNULL, null, null);
54 // Adding keys to table quiz_report
55 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
57 // Conditionally launch create table for quiz_report
58 if (!$dbman->table_exists($table)) {
59 $dbman->create_table($table);
62 upgrade_mod_savepoint(true, 2008062000, 'quiz');
65 if ($oldversion < 2008062001) {
66 $reporttoinsert = new stdClass();
67 $reporttoinsert->name = 'overview';
68 $reporttoinsert->displayorder = 10000;
69 $DB->insert_record('quiz_report', $reporttoinsert);
71 $reporttoinsert = new stdClass();
72 $reporttoinsert->name = 'responses';
73 $reporttoinsert->displayorder = 9000;
74 $DB->insert_record('quiz_report', $reporttoinsert);
76 $reporttoinsert = new stdClass();
77 $reporttoinsert->name = 'regrade';
78 $reporttoinsert->displayorder = 7000;
79 $DB->insert_record('quiz_report', $reporttoinsert);
81 $reporttoinsert = new stdClass();
82 $reporttoinsert->name = 'grading';
83 $reporttoinsert->displayorder = 6000;
84 $DB->insert_record('quiz_report', $reporttoinsert);
86 upgrade_mod_savepoint(true, 2008062001, 'quiz');
89 if ($oldversion < 2008072402) {
91 // Define field lastcron to be added to quiz_report
92 $table = new xmldb_table('quiz_report');
93 $field = new xmldb_field('lastcron', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
94 XMLDB_NOTNULL, null, '0', 'displayorder');
96 // Conditionally launch add field lastcron
97 if (!$dbman->field_exists($table, $field)) {
98 $dbman->add_field($table, $field);
101 // Define field cron to be added to quiz_report
102 $field = new xmldb_field('cron', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
103 XMLDB_NOTNULL, null, '0', 'lastcron');
105 // Conditionally launch add field cron
106 if (!$dbman->field_exists($table, $field)) {
107 $dbman->add_field($table, $field);
110 // quiz savepoint reached
111 upgrade_mod_savepoint(true, 2008072402, 'quiz');
114 if ($oldversion < 2008072900) {
115 // Delete the regrade report - it is now part of the overview report.
116 $DB->delete_records('quiz_report', array('name' => 'regrade'));
118 // quiz savepoint reached
119 upgrade_mod_savepoint(true, 2008072900, 'quiz');
122 if ($oldversion < 2008081500) {
123 // Define table quiz_question_versions to be dropped
124 $table = new xmldb_table('quiz_question_versions');
126 // Launch drop table for quiz_question_versions
127 $dbman->drop_table($table);
129 // quiz savepoint reached
130 upgrade_mod_savepoint(true, 2008081500, 'quiz');
133 // Changing the type of all the columns that store grades to be NUMBER(10, 5) or similar.
134 if ($oldversion < 2008081501) {
135 // First set all quiz.sumgrades to 0 if they are null. This should never
136 // happen however some users have encountered a null value there.
137 $DB->execute('UPDATE {quiz} SET sumgrades=0 WHERE sumgrades IS NULL');
138 $table = new xmldb_table('quiz');
139 $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null,
140 XMLDB_NOTNULL, null, '0', 'questions');
141 $dbman->change_field_type($table, $field);
142 upgrade_mod_savepoint(true, 2008081501, 'quiz');
145 if ($oldversion < 2008081502) {
146 $table = new xmldb_table('quiz');
147 $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null,
148 XMLDB_NOTNULL, null, '0', 'sumgrades');
149 $dbman->change_field_type($table, $field);
150 upgrade_mod_savepoint(true, 2008081502, 'quiz');
153 if ($oldversion < 2008081503) {
154 // First set all quiz.sumgrades to 0 if they are null. This should never
155 // happen however some users have encountered a null value there.
156 $DB->execute('UPDATE {quiz_attempts} SET sumgrades=0 WHERE sumgrades IS NULL');
157 $table = new xmldb_table('quiz_attempts');
158 $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null,
159 XMLDB_NOTNULL, null, '0', 'attempt');
160 $dbman->change_field_type($table, $field);
161 upgrade_mod_savepoint(true, 2008081503, 'quiz');
164 if ($oldversion < 2008081504) {
165 $table = new xmldb_table('quiz_feedback');
166 $field = new xmldb_field('mingrade', XMLDB_TYPE_NUMBER, '10, 5', null,
167 XMLDB_NOTNULL, null, '0', 'feedbacktext');
168 $dbman->change_field_type($table, $field);
169 upgrade_mod_savepoint(true, 2008081504, 'quiz');
172 if ($oldversion < 2008081505) {
173 $table = new xmldb_table('quiz_feedback');
174 $field = new xmldb_field('maxgrade', XMLDB_TYPE_NUMBER, '10, 5', null,
175 XMLDB_NOTNULL, null, '0', 'mingrade');
176 $dbman->change_field_type($table, $field);
177 upgrade_mod_savepoint(true, 2008081505, 'quiz');
180 if ($oldversion < 2008081506) {
181 $table = new xmldb_table('quiz_grades');
182 $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null,
183 XMLDB_NOTNULL, null, '0', 'userid');
184 $dbman->change_field_type($table, $field);
185 upgrade_mod_savepoint(true, 2008081506, 'quiz');
188 if ($oldversion < 2008081507) {
189 $table = new xmldb_table('quiz_question_instances');
190 $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null,
191 XMLDB_NOTNULL, null, '0', 'question');
192 $dbman->change_field_type($table, $field);
193 upgrade_mod_savepoint(true, 2008081507, 'quiz');
196 // Move all of the quiz config settings from $CFG to the config_plugins table.
197 if ($oldversion < 2008082200) {
198 foreach (get_object_vars($CFG) as $name => $value) {
199 if (strpos($name, 'quiz_') === 0) {
200 $shortname = substr($name, 5);
201 if ($shortname == 'fix_adaptive') {
202 // Special case - remove old inconsistency.
203 $shortname == 'fix_optionflags';
205 set_config($shortname, $value, 'quiz');
206 unset_config($name);
209 upgrade_mod_savepoint(true, 2008082200, 'quiz');
212 // Now that the quiz is no longer responsible for creating all the question
213 // bank tables, and some of the tables are now the responsibility of the
214 // datasetdependent question type, which did not have a version.php file before,
215 // we need to say that these tables are already installed, otherwise XMLDB
216 // will try to create them again and give an error.
217 if ($oldversion < 2008082600) {
218 // Since MDL-16505 was fixed, and we eliminated the datasetdependent
219 // question type, this is now a no-op.
220 upgrade_mod_savepoint(true, 2008082600, 'quiz');
223 if ($oldversion < 2008112101) {
225 // Define field lastcron to be added to quiz_report
226 $table = new xmldb_table('quiz_report');
227 $field = new xmldb_field('capability', XMLDB_TYPE_CHAR, '255', null,
228 null, null, null, 'cron');
230 // Conditionally launch add field lastcron
231 if (!$dbman->field_exists($table, $field)) {
232 $dbman->add_field($table, $field);
235 // quiz savepoint reached
236 upgrade_mod_savepoint(true, 2008112101, 'quiz');
239 if ($oldversion < 2009010700) {
241 // Define field showuserpicture to be added to quiz
242 $table = new xmldb_table('quiz');
243 $field = new xmldb_field('showuserpicture', XMLDB_TYPE_INTEGER, '4', null,
244 XMLDB_NOTNULL, null, '0', 'delay2');
246 // Conditionally launch add field showuserpicture
247 if (!$dbman->field_exists($table, $field)) {
248 $dbman->add_field($table, $field);
251 // quiz savepoint reached
252 upgrade_mod_savepoint(true, 2009010700, 'quiz');
255 if ($oldversion < 2009030900) {
256 // If there are no quiz settings set to advanced yet, the set up the default
257 // advanced fields from Moodle 2.0.
258 $quizconfig = get_config('quiz');
259 $arealreadyadvanced = false;
260 foreach (array($quizconfig) as $name => $value) {
261 if (strpos($name, 'fix_') === 0 && !empty($value)) {
262 $arealreadyadvanced = true;
263 break;
267 if (!$arealreadyadvanced) {
268 set_config('fix_penaltyscheme', 1, 'quiz');
269 set_config('fix_attemptonlast', 1, 'quiz');
270 set_config('fix_questiondecimalpoints', 1, 'quiz');
271 set_config('fix_password', 1, 'quiz');
272 set_config('fix_subnet', 1, 'quiz');
273 set_config('fix_delay1', 1, 'quiz');
274 set_config('fix_delay2', 1, 'quiz');
275 set_config('fix_popup', 1, 'quiz');
278 // quiz savepoint reached
279 upgrade_mod_savepoint(true, 2009030900, 'quiz');
282 if ($oldversion < 2009031000) {
283 // Add new questiondecimaldigits setting, separate form the overall decimaldigits one.
284 $table = new xmldb_table('quiz');
285 $field = new xmldb_field('questiondecimalpoints', XMLDB_TYPE_INTEGER, '4', null,
286 XMLDB_NOTNULL, null, '-2', 'decimalpoints');
287 if (!$dbman->field_exists($table, $field)) {
288 $dbman->add_field($table, $field);
291 // quiz savepoint reached
292 upgrade_mod_savepoint(true, 2009031000, 'quiz');
295 if ($oldversion < 2009031001) {
296 // Convert quiz.timelimit from minutes to seconds.
297 $DB->execute('UPDATE {quiz} SET timelimit = timelimit * 60');
298 $default = get_config('quiz', 'timelimit');
299 set_config('timelimit', 60 * $default, 'quiz');
301 // quiz savepoint reached
302 upgrade_mod_savepoint(true, 2009031001, 'quiz');
305 if ($oldversion < 2009042000) {
307 // Define field introformat to be added to quiz
308 $table = new xmldb_table('quiz');
309 $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED,
310 XMLDB_NOTNULL, null, '0', 'intro');
312 if (!$dbman->field_exists($table, $field)) {
313 $dbman->add_field($table, $field);
316 // conditionally migrate to html format in intro
317 if ($CFG->texteditors !== 'textarea') {
318 $rs = $DB->get_recordset('quiz', array('introformat' => FORMAT_MOODLE),
319 '', 'id, intro, introformat');
320 foreach ($rs as $q) {
321 $q->intro = text_to_html($q->intro, false, false, true);
322 $q->introformat = FORMAT_HTML;
323 $DB->update_record('quiz', $q);
324 upgrade_set_timeout();
326 $rs->close();
329 // quiz savepoint reached
330 upgrade_mod_savepoint(true, 2009042000, 'quiz');
333 if ($oldversion < 2010030501) {
334 // Define table quiz_overrides to be created
335 $table = new xmldb_table('quiz_overrides');
337 // Adding fields to table quiz_overrides
338 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
339 XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
340 $table->add_field('quiz', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
341 XMLDB_NOTNULL, null, '0');
342 $table->add_field('groupid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
343 null, null, null);
344 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
345 null, null, null);
346 $table->add_field('timeopen', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
347 null, null, null);
348 $table->add_field('timeclose', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
349 null, null, null);
350 $table->add_field('timelimit', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
351 null, null, null);
352 $table->add_field('attempts', XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED,
353 null, null, null);
354 $table->add_field('password', XMLDB_TYPE_CHAR, '255', null, null, null, null);
356 // Adding keys to table quiz_overrides
357 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
358 $table->add_key('quiz', XMLDB_KEY_FOREIGN, array('quiz'), 'quiz', array('id'));
359 $table->add_key('groupid', XMLDB_KEY_FOREIGN, array('groupid'), 'groups', array('id'));
360 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
362 // Conditionally launch create table for quiz_overrides
363 if (!$dbman->table_exists($table)) {
364 $dbman->create_table($table);
367 // quiz savepoint reached
368 upgrade_mod_savepoint(true, 2010030501, 'quiz');
371 if ($oldversion < 2010051800) {
373 // Define field showblocks to be added to quiz
374 $table = new xmldb_table('quiz');
375 $field = new xmldb_field('showblocks', XMLDB_TYPE_INTEGER, '4', null,
376 XMLDB_NOTNULL, null, '0', 'showuserpicture');
378 // Conditionally launch add field showblocks
379 if (!$dbman->field_exists($table, $field)) {
380 $dbman->add_field($table, $field);
383 // quiz savepoint reached
384 upgrade_mod_savepoint(true, 2010051800, 'quiz');
387 if ($oldversion < 2010080600) {
389 // Define field feedbacktextformat to be added to quiz_feedback
390 $table = new xmldb_table('quiz_feedback');
391 $field = new xmldb_field('feedbacktextformat', XMLDB_TYPE_INTEGER, '2', null,
392 XMLDB_NOTNULL, null, '0', 'feedbacktext');
394 // Conditionally launch add field feedbacktextformat
395 if (!$dbman->field_exists($table, $field)) {
396 $dbman->add_field($table, $field);
399 // This column defaults to FORMAT_MOODLE, which is correct.
401 // quiz savepoint reached
402 upgrade_mod_savepoint(true, 2010080600, 'quiz');
405 if ($oldversion < 2010102000) {
407 // Define field showblocks to be added to quiz
408 // Repeat this step, because the column was missing from install.xml for a time.
409 $table = new xmldb_table('quiz');
410 $field = new xmldb_field('showblocks', XMLDB_TYPE_INTEGER, '4', null,
411 XMLDB_NOTNULL, null, '0', 'showuserpicture');
413 // Conditionally launch add field showblocks
414 if (!$dbman->field_exists($table, $field)) {
415 $dbman->add_field($table, $field);
418 // quiz savepoint reached
419 upgrade_mod_savepoint(true, 2010102000, 'quiz');
422 if ($oldversion < 2010122300) {
423 // Fix quiz in the post table after upgrade from 1.9
424 $table = new xmldb_table('quiz');
425 $columns = $DB->get_columns('quiz');
427 // quiz.questiondecimalpoints should be int (4) not null default -2
428 if (array_key_exists('questiondecimalpoints', $columns) &&
429 $columns['questiondecimalpoints']->default_value != '-2') {
430 $field = new xmldb_field('questiondecimalpoints', XMLDB_TYPE_INTEGER, '4', null,
431 XMLDB_NOTNULL, null, -2, 'decimalpoints');
432 if ($dbman->field_exists($table, $field)) {
433 $dbman->change_field_default($table, $field);
437 // quiz.sumgrades should be decimal(10, 5) not null default 0
438 if (array_key_exists('sumgrades', $columns) && empty($columns['sumgrades']->not_null)) {
439 // First set all quiz.sumgrades to 0 if they are null. This should never
440 // happen however some users have encountered a null value there.
441 $DB->execute('UPDATE {quiz} SET sumgrades=0 WHERE sumgrades IS NULL');
443 $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null,
444 XMLDB_NOTNULL, null, '0', 'questions');
445 if ($dbman->field_exists($table, $field)) {
446 $dbman->change_field_default($table, $field);
450 // quiz.grade should be decimal(10, 5) not null default 0
451 if (array_key_exists('grade', $columns) && empty($columns['grade']->not_null)) {
452 $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null,
453 XMLDB_NOTNULL, null, '0', 'sumgrades');
454 if ($dbman->field_exists($table, $field)) {
455 $dbman->change_field_default($table, $field);
459 upgrade_mod_savepoint(true, 2010122300, 'quiz');
462 if ($oldversion < 2010122301) {
463 // Fix quiz_attempts in the post table after upgrade from 1.9
464 $table = new xmldb_table('quiz_attempts');
465 $columns = $DB->get_columns('quiz_attempts');
467 // quiz_attempts.sumgrades should be decimal(10, 5) not null default 0
468 if (array_key_exists('sumgrades', $columns) && empty($columns['sumgrades']->not_null)) {
469 // First set all quiz.sumgrades to 0 if they are null. This should never
470 // happen however some users have encountered a null value there.
471 $DB->execute('UPDATE {quiz_attempts} SET sumgrades=0 WHERE sumgrades IS NULL');
473 $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null,
474 XMLDB_NOTNULL, null, '0', 'attempt');
475 if ($dbman->field_exists($table, $field)) {
476 $dbman->change_field_default($table, $field);
480 upgrade_mod_savepoint(true, 2010122301, 'quiz');
483 if ($oldversion < 2010122302) {
484 // Fix quiz_feedback in the post table after upgrade from 1.9
485 $table = new xmldb_table('quiz_feedback');
486 $columns = $DB->get_columns('quiz_feedback');
488 // quiz_feedback.mingrade should be decimal(10, 5) not null default 0
489 if (array_key_exists('mingrade', $columns) && empty($columns['mingrade']->not_null)) {
490 $field = new xmldb_field('mingrade', XMLDB_TYPE_NUMBER, '10, 5', null,
491 XMLDB_NOTNULL, null, '0', 'feedbacktextformat');
492 if ($dbman->field_exists($table, $field)) {
493 $dbman->change_field_default($table, $field);
497 // quiz_feedback.maxgrade should be decimal(10, 5) not null default 0
498 if (array_key_exists('maxgrade', $columns) && empty($columns['maxgrade']->not_null)) {
499 // Fixed in earlier upgrade code
500 $field = new xmldb_field('maxgrade', XMLDB_TYPE_NUMBER, '10, 5', null,
501 XMLDB_NOTNULL, null, '0', 'mingrade');
502 if ($dbman->field_exists($table, $field)) {
503 $dbman->change_field_default($table, $field);
507 upgrade_mod_savepoint(true, 2010122302, 'quiz');
510 if ($oldversion < 2010122303) {
511 // Fix quiz_grades in the post table after upgrade from 1.9
512 $table = new xmldb_table('quiz_grades');
513 $columns = $DB->get_columns('quiz_grades');
515 // quiz_grades.grade should be decimal(10, 5) not null default 0
516 if (array_key_exists('grade', $columns) && empty($columns['grade']->not_null)) {
517 $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null,
518 XMLDB_NOTNULL, null, '0', 'userid');
519 if ($dbman->field_exists($table, $field)) {
520 $dbman->change_field_default($table, $field);
524 upgrade_mod_savepoint(true, 2010122303, 'quiz');
527 if ($oldversion < 2010122304) {
528 // Fix quiz_question_instances in the post table after upgrade from 1.9
529 $table = new xmldb_table('quiz_question_instances');
530 $columns = $DB->get_columns('quiz_question_instances');
532 // quiz_question_instances.grade should be decimal(12, 7) not null default 0
533 if (array_key_exists('grade', $columns) && empty($columns['grade']->not_null)) {
534 $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null,
535 XMLDB_NOTNULL, null, '0', 'question');
536 if ($dbman->field_exists($table, $field)) {
537 $dbman->change_field_default($table, $field);
541 upgrade_mod_savepoint(true, 2010122304, 'quiz');
544 // Complete any old upgrade from 1.5 that was never finished.
545 if ($oldversion < 2011051199) {
546 $table = new xmldb_table('question_states');
547 if ($dbman->table_exists($table)) {
548 $transaction = $DB->start_delegated_transaction();
550 $oldattempts = $DB->get_records_sql('
551 SELECT quiza
552 FROM {quiz_attempts} quiza
553 WHERE uniqueid IN (
554 SELECT DISTINCT qst.attempt
555 FROM {question_states} qst
556 LEFT JOIN {question_sessions} qsess ON
557 qst.question = qsess.questionid AND qst.attempt = qsess.attemptid
558 WHERE qsess.id IS NULL
562 if ($oldattempts) {
563 $pbar = new progress_bar('q15upgrade');
564 $a = new stdClass();
565 $a->todo = count($oldattempts);
566 $a->done = 0;
567 $pbar->update($a->done, $a->todo,
568 get_string('upgradingveryoldquizattempts', 'quiz', $a));
570 foreach ($oldattempts as $oldattempt) {
571 quiz_upgrade_very_old_question_sessions($oldattempt);
573 $a->done += 1;
574 $pbar->update($a->done, $a->todo,
575 get_string('upgradingveryoldquizattempts', 'quiz', $a));
579 $transaction->allow_commit();
582 // quiz savepoint reached
583 upgrade_mod_savepoint(true, 2011051199, 'quiz');
586 // Add new preferredbehaviour column to the quiz table.
587 if ($oldversion < 2011051200) {
588 $table = new xmldb_table('quiz');
589 $field = new xmldb_field('preferredbehaviour');
590 $field->set_attributes(XMLDB_TYPE_CHAR, '32', null,
591 null, null, null, 'timeclose');
592 if (!$dbman->field_exists($table, $field)) {
593 $dbman->add_field($table, $field);
596 // quiz savepoint reached
597 upgrade_mod_savepoint(true, 2011051200, 'quiz');
600 // Populate preferredbehaviour column based on old optionflags column.
601 if ($oldversion < 2011051201) {
602 if ($dbman->field_exists('quiz', 'optionflags')) {
603 $DB->set_field_select('quiz', 'preferredbehaviour', 'deferredfeedback',
604 'optionflags = 0');
605 $DB->set_field_select('quiz', 'preferredbehaviour', 'adaptive',
606 'optionflags <> 0 AND penaltyscheme <> 0');
607 $DB->set_field_select('quiz', 'preferredbehaviour', 'adaptivenopenalty',
608 'optionflags <> 0 AND penaltyscheme = 0');
610 set_config('preferredbehaviour', 'deferredfeedback', 'quiz');
611 set_config('fix_preferredbehaviour', 0, 'quiz');
614 // quiz savepoint reached
615 upgrade_mod_savepoint(true, 2011051201, 'quiz');
618 // Add a not-NULL constraint to the preferredmodel field now that it is populated.
619 if ($oldversion < 2011051202) {
620 $table = new xmldb_table('quiz');
621 $field = new xmldb_field('preferredbehaviour');
622 $field->set_attributes(XMLDB_TYPE_CHAR, '32', null,
623 XMLDB_NOTNULL, null, null, 'timeclose');
625 $dbman->change_field_notnull($table, $field);
627 // quiz savepoint reached
628 upgrade_mod_savepoint(true, 2011051202, 'quiz');
631 // Drop the old optionflags field.
632 if ($oldversion < 2011051203) {
633 $table = new xmldb_table('quiz');
634 $field = new xmldb_field('optionflags');
636 if ($dbman->field_exists($table, $field)) {
637 $dbman->drop_field($table, $field);
640 unset_config('optionflags', 'quiz');
641 unset_config('fix_optionflags', 'quiz');
643 // quiz savepoint reached
644 upgrade_mod_savepoint(true, 2011051203, 'quiz');
647 // Drop the old penaltyscheme field.
648 if ($oldversion < 2011051204) {
649 $table = new xmldb_table('quiz');
650 $field = new xmldb_field('penaltyscheme');
652 if ($dbman->field_exists($table, $field)) {
653 $dbman->drop_field($table, $field);
656 unset_config('penaltyscheme', 'quiz');
657 unset_config('fix_penaltyscheme', 'quiz');
659 // quiz savepoint reached
660 upgrade_mod_savepoint(true, 2011051204, 'quiz');
663 if ($oldversion < 2011051205) {
665 // Changing nullability of field sumgrades on table quiz_attempts to null
666 $table = new xmldb_table('quiz_attempts');
667 $field = new xmldb_field('sumgrades');
668 $field->set_attributes(XMLDB_TYPE_NUMBER, '10, 5', null,
669 null, null, null, 'attempt');
671 // Launch change of nullability for field sumgrades
672 $dbman->change_field_notnull($table, $field);
674 // Launch change of default for field sumgrades
675 $dbman->change_field_default($table, $field);
677 // quiz savepoint reached
678 upgrade_mod_savepoint(true, 2011051205, 'quiz');
681 if ($oldversion < 2011051206) {
683 // Changing the default of field penalty on table question to 0.3333333
684 $table = new xmldb_table('question');
685 $field = new xmldb_field('penalty');
686 $field->set_attributes(XMLDB_TYPE_FLOAT, null, null,
687 XMLDB_NOTNULL, null, '0.3333333', 'defaultgrade');
689 // Launch change of default for field penalty
690 $dbman->change_field_default($table, $field);
692 // quiz savepoint reached
693 upgrade_mod_savepoint(true, 2011051206, 'quiz');
696 // Update the quiz from the old single review column to seven new columns.
698 if ($oldversion < 2011051207) {
700 // Define field reviewattempt to be added to quiz
701 $table = new xmldb_table('quiz');
702 $field = new xmldb_field('reviewattempt');
703 $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED,
704 XMLDB_NOTNULL, null, '0', 'review');
706 // Launch add field reviewattempt
707 if (!$dbman->field_exists($table, $field)) {
708 $dbman->add_field($table, $field);
711 // quiz savepoint reached
712 upgrade_mod_savepoint(true, 2011051207, 'quiz');
715 if ($oldversion < 2011051208) {
717 // Define field reviewattempt to be added to quiz
718 $table = new xmldb_table('quiz');
719 $field = new xmldb_field('reviewcorrectness');
720 $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED,
721 XMLDB_NOTNULL, null, '0', 'reviewattempt');
723 // Launch add field reviewattempt
724 if (!$dbman->field_exists($table, $field)) {
725 $dbman->add_field($table, $field);
728 // quiz savepoint reached
729 upgrade_mod_savepoint(true, 2011051208, 'quiz');
732 if ($oldversion < 2011051209) {
734 // Define field reviewattempt to be added to quiz
735 $table = new xmldb_table('quiz');
736 $field = new xmldb_field('reviewmarks');
737 $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED,
738 XMLDB_NOTNULL, null, '0', 'reviewcorrectness');
740 // Launch add field reviewattempt
741 if (!$dbman->field_exists($table, $field)) {
742 $dbman->add_field($table, $field);
745 // quiz savepoint reached
746 upgrade_mod_savepoint(true, 2011051209, 'quiz');
749 if ($oldversion < 2011051210) {
751 // Define field reviewattempt to be added to quiz
752 $table = new xmldb_table('quiz');
753 $field = new xmldb_field('reviewspecificfeedback');
754 $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED,
755 XMLDB_NOTNULL, null, '0', 'reviewmarks');
757 // Launch add field reviewattempt
758 if (!$dbman->field_exists($table, $field)) {
759 $dbman->add_field($table, $field);
762 // quiz savepoint reached
763 upgrade_mod_savepoint(true, 2011051210, 'quiz');
766 if ($oldversion < 2011051211) {
768 // Define field reviewattempt to be added to quiz
769 $table = new xmldb_table('quiz');
770 $field = new xmldb_field('reviewgeneralfeedback');
771 $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED,
772 XMLDB_NOTNULL, null, '0', 'reviewspecificfeedback');
774 // Launch add field reviewattempt
775 if (!$dbman->field_exists($table, $field)) {
776 $dbman->add_field($table, $field);
779 // quiz savepoint reached
780 upgrade_mod_savepoint(true, 2011051211, 'quiz');
783 if ($oldversion < 2011051212) {
785 // Define field reviewattempt to be added to quiz
786 $table = new xmldb_table('quiz');
787 $field = new xmldb_field('reviewrightanswer');
788 $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED,
789 XMLDB_NOTNULL, null, '0', 'reviewgeneralfeedback');
791 // Launch add field reviewattempt
792 if (!$dbman->field_exists($table, $field)) {
793 $dbman->add_field($table, $field);
796 // quiz savepoint reached
797 upgrade_mod_savepoint(true, 2011051212, 'quiz');
800 if ($oldversion < 2011051213) {
802 // Define field reviewattempt to be added to quiz
803 $table = new xmldb_table('quiz');
804 $field = new xmldb_field('reviewoverallfeedback');
805 $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED,
806 XMLDB_NOTNULL, null, '0', 'reviewrightanswer');
808 // Launch add field reviewattempt
809 if (!$dbman->field_exists($table, $field)) {
810 $dbman->add_field($table, $field);
813 // quiz savepoint reached
814 upgrade_mod_savepoint(true, 2011051213, 'quiz');
817 define('QUIZ_NEW_DURING', 0x10000);
818 define('QUIZ_NEW_IMMEDIATELY_AFTER', 0x01000);
819 define('QUIZ_NEW_LATER_WHILE_OPEN', 0x00100);
820 define('QUIZ_NEW_AFTER_CLOSE', 0x00010);
822 define('QUIZ_OLD_IMMEDIATELY', 0x3c003f);
823 define('QUIZ_OLD_OPEN', 0x3c00fc0);
824 define('QUIZ_OLD_CLOSED', 0x3c03f000);
826 define('QUIZ_OLD_RESPONSES', 1*0x1041); // Show responses
827 define('QUIZ_OLD_SCORES', 2*0x1041); // Show scores
828 define('QUIZ_OLD_FEEDBACK', 4*0x1041); // Show question feedback
829 define('QUIZ_OLD_ANSWERS', 8*0x1041); // Show correct answers
830 define('QUIZ_OLD_SOLUTIONS', 16*0x1041); // Show solutions
831 define('QUIZ_OLD_GENERALFEEDBACK',32*0x1041); // Show question general feedback
832 define('QUIZ_OLD_OVERALLFEEDBACK', 1*0x4440000); // Show quiz overall feedback
834 // Copy the old review settings
835 if ($oldversion < 2011051214) {
836 if ($dbman->field_exists('quiz', 'review')) {
837 $DB->execute("
838 UPDATE {quiz}
839 SET reviewattempt = " . $DB->sql_bitor($DB->sql_bitor(
840 QUIZ_NEW_DURING,
841 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_RESPONSES) .
842 ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor(
843 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_RESPONSES) .
844 ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END',
845 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_RESPONSES) .
846 ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . "
850 // quiz savepoint reached
851 upgrade_mod_savepoint(true, 2011051214, 'quiz');
854 if ($oldversion < 2011051215) {
855 if ($dbman->field_exists('quiz', 'review')) {
856 $DB->execute("
857 UPDATE {quiz}
858 SET reviewcorrectness = " . $DB->sql_bitor($DB->sql_bitor(
859 QUIZ_NEW_DURING,
860 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_SCORES) .
861 ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor(
862 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_SCORES) .
863 ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END',
864 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_SCORES) .
865 ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . "
869 // quiz savepoint reached
870 upgrade_mod_savepoint(true, 2011051215, 'quiz');
873 if ($oldversion < 2011051216) {
874 if ($dbman->field_exists('quiz', 'review')) {
875 $DB->execute("
876 UPDATE {quiz}
877 SET reviewmarks = " . $DB->sql_bitor($DB->sql_bitor(
878 QUIZ_NEW_DURING,
879 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_SCORES) .
880 ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor(
881 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_SCORES) .
882 ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END',
883 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_SCORES) .
884 ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . "
888 // quiz savepoint reached
889 upgrade_mod_savepoint(true, 2011051216, 'quiz');
892 if ($oldversion < 2011051217) {
893 if ($dbman->field_exists('quiz', 'review')) {
894 $DB->execute("
895 UPDATE {quiz}
896 SET reviewspecificfeedback = " . $DB->sql_bitor($DB->sql_bitor(
897 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_FEEDBACK) .
898 ' <> 0 THEN ' . QUIZ_NEW_DURING . ' ELSE 0 END',
899 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_FEEDBACK) .
900 ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor(
901 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_FEEDBACK) .
902 ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END',
903 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_FEEDBACK) .
904 ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . "
908 // quiz savepoint reached
909 upgrade_mod_savepoint(true, 2011051217, 'quiz');
912 if ($oldversion < 2011051218) {
913 if ($dbman->field_exists('quiz', 'review')) {
914 $DB->execute("
915 UPDATE {quiz}
916 SET reviewgeneralfeedback = " . $DB->sql_bitor($DB->sql_bitor(
917 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_GENERALFEEDBACK) .
918 ' <> 0 THEN ' . QUIZ_NEW_DURING . ' ELSE 0 END',
919 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_GENERALFEEDBACK) .
920 ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor(
921 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_GENERALFEEDBACK) .
922 ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END',
923 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_GENERALFEEDBACK) .
924 ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . "
928 // quiz savepoint reached
929 upgrade_mod_savepoint(true, 2011051218, 'quiz');
932 if ($oldversion < 2011051219) {
933 if ($dbman->field_exists('quiz', 'review')) {
934 $DB->execute("
935 UPDATE {quiz}
936 SET reviewrightanswer = " . $DB->sql_bitor($DB->sql_bitor(
937 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_ANSWERS) .
938 ' <> 0 THEN ' . QUIZ_NEW_DURING . ' ELSE 0 END',
939 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_ANSWERS) .
940 ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor(
941 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_ANSWERS) .
942 ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END',
943 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_ANSWERS) .
944 ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . "
948 // quiz savepoint reached
949 upgrade_mod_savepoint(true, 2011051219, 'quiz');
952 if ($oldversion < 2011051220) {
953 if ($dbman->field_exists('quiz', 'review')) {
954 $DB->execute("
955 UPDATE {quiz}
956 SET reviewoverallfeedback = " . $DB->sql_bitor($DB->sql_bitor(
958 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_OVERALLFEEDBACK) .
959 ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor(
960 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_OVERALLFEEDBACK) .
961 ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END',
962 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_OVERALLFEEDBACK) .
963 ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . "
967 // quiz savepoint reached
968 upgrade_mod_savepoint(true, 2011051220, 'quiz');
971 // And, do the same for the defaults
972 if ($oldversion < 2011051221) {
973 $quizrevew = get_config('quiz', 'review');
974 if (!empty($quizrevew)) {
976 set_config('reviewattempt',
977 QUIZ_NEW_DURING |
978 ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_RESPONSES ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) |
979 ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_RESPONSES ? QUIZ_NEW_LATER_WHILE_OPEN : 0) |
980 ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_RESPONSES ? QUIZ_NEW_AFTER_CLOSE : 0),
981 'quiz');
983 set_config('reviewcorrectness',
984 QUIZ_NEW_DURING |
985 ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_SCORES ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) |
986 ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_SCORES ? QUIZ_NEW_LATER_WHILE_OPEN : 0) |
987 ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_SCORES ? QUIZ_NEW_AFTER_CLOSE : 0),
988 'quiz');
990 set_config('reviewmarks',
991 QUIZ_NEW_DURING |
992 ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_SCORES ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) |
993 ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_SCORES ? QUIZ_NEW_LATER_WHILE_OPEN : 0) |
994 ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_SCORES ? QUIZ_NEW_AFTER_CLOSE : 0),
995 'quiz');
997 set_config('reviewspecificfeedback',
998 ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_FEEDBACK ? QUIZ_NEW_DURING : 0) |
999 ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_FEEDBACK ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) |
1000 ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_FEEDBACK ? QUIZ_NEW_LATER_WHILE_OPEN : 0) |
1001 ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_FEEDBACK ? QUIZ_NEW_AFTER_CLOSE : 0),
1002 'quiz');
1004 set_config('reviewgeneralfeedback',
1005 ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_GENERALFEEDBACK ? QUIZ_NEW_DURING : 0) |
1006 ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_GENERALFEEDBACK ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) |
1007 ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_GENERALFEEDBACK ? QUIZ_NEW_LATER_WHILE_OPEN : 0) |
1008 ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_GENERALFEEDBACK ? QUIZ_NEW_AFTER_CLOSE : 0),
1009 'quiz');
1011 set_config('reviewrightanswer',
1012 ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_ANSWERS ? QUIZ_NEW_DURING : 0) |
1013 ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_ANSWERS ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) |
1014 ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_ANSWERS ? QUIZ_NEW_LATER_WHILE_OPEN : 0) |
1015 ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_ANSWERS ? QUIZ_NEW_AFTER_CLOSE : 0),
1016 'quiz');
1018 set_config('reviewoverallfeedback',
1020 ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_OVERALLFEEDBACK ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) |
1021 ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_OVERALLFEEDBACK ? QUIZ_NEW_LATER_WHILE_OPEN : 0) |
1022 ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_OVERALLFEEDBACK ? QUIZ_NEW_AFTER_CLOSE : 0),
1023 'quiz');
1026 // quiz savepoint reached
1027 upgrade_mod_savepoint(true, 2011051221, 'quiz');
1030 // Finally drop the old column
1031 if ($oldversion < 2011051222) {
1032 // Define field review to be dropped from quiz
1033 $table = new xmldb_table('quiz');
1034 $field = new xmldb_field('review');
1036 // Launch drop field review
1037 if ($dbman->field_exists($table, $field)) {
1038 $dbman->drop_field($table, $field);
1041 // quiz savepoint reached
1042 upgrade_mod_savepoint(true, 2011051222, 'quiz');
1045 if ($oldversion < 2011051223) {
1046 unset_config('review', 'quiz');
1048 // quiz savepoint reached
1049 upgrade_mod_savepoint(true, 2011051223, 'quiz');
1052 if ($oldversion < 2011051224) {
1054 // Define field hintformat to be added to question_hints table.
1055 $table = new xmldb_table('question_hints');
1056 $field = new xmldb_field('hintformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED,
1057 XMLDB_NOTNULL, null, '0');
1059 // Conditionally launch add field partiallycorrectfeedbackformat
1060 if (!$dbman->field_exists($table, $field)) {
1061 $dbman->add_field($table, $field);
1064 upgrade_mod_savepoint(true, 2011051224, 'quiz');
1067 if ($oldversion < 2011051225) {
1068 // Define table quiz_report to be renamed to quiz_reports
1069 $table = new xmldb_table('quiz_report');
1071 // Launch rename table for quiz_reports
1072 if ($dbman->table_exists($table)) {
1073 $dbman->rename_table($table, 'quiz_reports');
1076 upgrade_mod_savepoint(true, 2011051225, 'quiz');
1079 if ($oldversion < 2011051226) {
1080 // Define index name (unique) to be added to quiz_reports
1081 $table = new xmldb_table('quiz_reports');
1082 $index = new xmldb_index('name', XMLDB_INDEX_UNIQUE, array('name'));
1084 // Conditionally launch add index name
1085 if (!$dbman->index_exists($table, $index)) {
1086 $dbman->add_index($table, $index);
1089 upgrade_mod_savepoint(true, 2011051226, 'quiz');
1092 if ($oldversion < 2011051227) {
1094 // Changing nullability of field sumgrades on table quiz_attempts to null
1095 $table = new xmldb_table('quiz_attempts');
1096 $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null,
1097 null, null, null, 'attempt');
1099 // Launch change of nullability for field sumgrades
1100 $dbman->change_field_notnull($table, $field);
1102 // quiz savepoint reached
1103 upgrade_mod_savepoint(true, 2011051227, 'quiz');
1106 if ($oldversion < 2011051228) {
1107 // Define field needsupgradetonewqe to be added to quiz_attempts
1108 $table = new xmldb_table('quiz_attempts');
1109 $field = new xmldb_field('needsupgradetonewqe', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED,
1110 XMLDB_NOTNULL, null, '0', 'preview');
1112 // Launch add field needsupgradetonewqe
1113 if (!$dbman->field_exists($table, $field)) {
1114 $dbman->add_field($table, $field);
1117 $DB->set_field('quiz_attempts', 'needsupgradetonewqe', 1);
1119 // quiz savepoint reached
1120 upgrade_mod_savepoint(true, 2011051228, 'quiz');
1123 if ($oldversion < 2011051229) {
1124 $table = new xmldb_table('question_states');
1125 if ($dbman->table_exists($table)) {
1126 // First delete all data from preview attempts.
1127 $DB->delete_records_select('question_states',
1128 "attempt IN (SELECT uniqueid FROM {quiz_attempts} WHERE preview = 1)");
1129 $DB->delete_records_select('question_sessions',
1130 "attemptid IN (SELECT uniqueid FROM {quiz_attempts} WHERE preview = 1)");
1131 $DB->delete_records('quiz_attempts', array('preview' => 1));
1133 // Now update all the old attempt data.
1134 $oldrcachesetting = $CFG->rcache;
1135 $CFG->rcache = false;
1137 require_once($CFG->dirroot . '/question/engine/upgrade/upgradelib.php');
1138 $upgrader = new question_engine_attempt_upgrader();
1139 $upgrader->convert_all_quiz_attempts();
1141 $CFG->rcache = $oldrcachesetting;
1144 // quiz savepoint reached
1145 upgrade_mod_savepoint(true, 2011051229, 'quiz');
1148 return true;