Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/mod/quiz/db/upgrade.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00027 defined('MOODLE_INTERNAL') || die();
00028 
00029 
00034 function xmldb_quiz_upgrade($oldversion) {
00035     global $CFG, $DB;
00036 
00037     $dbman = $DB->get_manager();
00038 
00039     //===== 1.9.0 upgrade line ======//
00040 
00041     if ($oldversion < 2008062000) {
00042 
00043         // Define table quiz_report to be created
00044         $table = new xmldb_table('quiz_report');
00045 
00046         // Adding fields to table quiz_report
00047         $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
00048                 XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
00049         $table->add_field('name', XMLDB_TYPE_CHAR, '255', null,
00050                 null, null, null);
00051         $table->add_field('displayorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
00052                 XMLDB_NOTNULL, null, null);
00053 
00054         // Adding keys to table quiz_report
00055         $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
00056 
00057         // Conditionally launch create table for quiz_report
00058         if (!$dbman->table_exists($table)) {
00059             $dbman->create_table($table);
00060         }
00061 
00062         upgrade_mod_savepoint(true, 2008062000, 'quiz');
00063     }
00064 
00065     if ($oldversion < 2008062001) {
00066         $reporttoinsert = new stdClass();
00067         $reporttoinsert->name = 'overview';
00068         $reporttoinsert->displayorder = 10000;
00069         $DB->insert_record('quiz_report', $reporttoinsert);
00070 
00071         $reporttoinsert = new stdClass();
00072         $reporttoinsert->name = 'responses';
00073         $reporttoinsert->displayorder = 9000;
00074         $DB->insert_record('quiz_report', $reporttoinsert);
00075 
00076         $reporttoinsert = new stdClass();
00077         $reporttoinsert->name = 'regrade';
00078         $reporttoinsert->displayorder = 7000;
00079         $DB->insert_record('quiz_report', $reporttoinsert);
00080 
00081         $reporttoinsert = new stdClass();
00082         $reporttoinsert->name = 'grading';
00083         $reporttoinsert->displayorder = 6000;
00084         $DB->insert_record('quiz_report', $reporttoinsert);
00085 
00086         upgrade_mod_savepoint(true, 2008062001, 'quiz');
00087     }
00088 
00089     if ($oldversion < 2008072402) {
00090 
00091         // Define field lastcron to be added to quiz_report
00092         $table = new xmldb_table('quiz_report');
00093         $field = new xmldb_field('lastcron', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
00094                 XMLDB_NOTNULL, null, '0', 'displayorder');
00095 
00096         // Conditionally launch add field lastcron
00097         if (!$dbman->field_exists($table, $field)) {
00098             $dbman->add_field($table, $field);
00099         }
00100 
00101         // Define field cron to be added to quiz_report
00102         $field = new xmldb_field('cron', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
00103                 XMLDB_NOTNULL, null, '0', 'lastcron');
00104 
00105         // Conditionally launch add field cron
00106         if (!$dbman->field_exists($table, $field)) {
00107             $dbman->add_field($table, $field);
00108         }
00109 
00110         // quiz savepoint reached
00111         upgrade_mod_savepoint(true, 2008072402, 'quiz');
00112     }
00113 
00114     if ($oldversion < 2008072900) {
00115         // Delete the regrade report - it is now part of the overview report.
00116         $DB->delete_records('quiz_report', array('name' => 'regrade'));
00117 
00118         // quiz savepoint reached
00119         upgrade_mod_savepoint(true, 2008072900, 'quiz');
00120     }
00121 
00122     if ($oldversion < 2008081500) {
00123         // Define table quiz_question_versions to be dropped
00124         $table = new xmldb_table('quiz_question_versions');
00125 
00126         // Launch drop table for quiz_question_versions
00127         $dbman->drop_table($table);
00128 
00129         // quiz savepoint reached
00130         upgrade_mod_savepoint(true, 2008081500, 'quiz');
00131     }
00132 
00133     // Changing the type of all the columns that store grades to be NUMBER(10, 5) or similar.
00134     if ($oldversion < 2008081501) {
00135         // First set all quiz.sumgrades to 0 if they are null. This should never
00136         // happen however some users have encountered a null value there.
00137         $DB->execute('UPDATE {quiz} SET sumgrades=0 WHERE sumgrades IS NULL');
00138         $table = new xmldb_table('quiz');
00139         $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null,
00140                 XMLDB_NOTNULL, null, '0', 'questions');
00141         $dbman->change_field_type($table, $field);
00142         upgrade_mod_savepoint(true, 2008081501, 'quiz');
00143     }
00144 
00145     if ($oldversion < 2008081502) {
00146         $table = new xmldb_table('quiz');
00147         $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null,
00148                 XMLDB_NOTNULL, null, '0', 'sumgrades');
00149         $dbman->change_field_type($table, $field);
00150         upgrade_mod_savepoint(true, 2008081502, 'quiz');
00151     }
00152 
00153     if ($oldversion < 2008081503) {
00154         // First set all quiz.sumgrades to 0 if they are null. This should never
00155         // happen however some users have encountered a null value there.
00156         $DB->execute('UPDATE {quiz_attempts} SET sumgrades=0 WHERE sumgrades IS NULL');
00157         $table = new xmldb_table('quiz_attempts');
00158         $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null,
00159                 XMLDB_NOTNULL, null, '0', 'attempt');
00160         $dbman->change_field_type($table, $field);
00161         upgrade_mod_savepoint(true, 2008081503, 'quiz');
00162     }
00163 
00164     if ($oldversion < 2008081504) {
00165         $table = new xmldb_table('quiz_feedback');
00166         $field = new xmldb_field('mingrade', XMLDB_TYPE_NUMBER, '10, 5', null,
00167                 XMLDB_NOTNULL, null, '0', 'feedbacktext');
00168         $dbman->change_field_type($table, $field);
00169         upgrade_mod_savepoint(true, 2008081504, 'quiz');
00170     }
00171 
00172     if ($oldversion < 2008081505) {
00173         $table = new xmldb_table('quiz_feedback');
00174         $field = new xmldb_field('maxgrade', XMLDB_TYPE_NUMBER, '10, 5', null,
00175                 XMLDB_NOTNULL, null, '0', 'mingrade');
00176         $dbman->change_field_type($table, $field);
00177         upgrade_mod_savepoint(true, 2008081505, 'quiz');
00178     }
00179 
00180     if ($oldversion < 2008081506) {
00181         $table = new xmldb_table('quiz_grades');
00182         $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null,
00183                 XMLDB_NOTNULL, null, '0', 'userid');
00184         $dbman->change_field_type($table, $field);
00185         upgrade_mod_savepoint(true, 2008081506, 'quiz');
00186     }
00187 
00188     if ($oldversion < 2008081507) {
00189         $table = new xmldb_table('quiz_question_instances');
00190         $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null,
00191                 XMLDB_NOTNULL, null, '0', 'question');
00192         $dbman->change_field_type($table, $field);
00193         upgrade_mod_savepoint(true, 2008081507, 'quiz');
00194     }
00195 
00196     // Move all of the quiz config settings from $CFG to the config_plugins table.
00197     if ($oldversion < 2008082200) {
00198         foreach (get_object_vars($CFG) as $name => $value) {
00199             if (strpos($name, 'quiz_') === 0) {
00200                 $shortname = substr($name, 5);
00201                 if ($shortname == 'fix_adaptive') {
00202                     // Special case - remove old inconsistency.
00203                     $shortname == 'fix_optionflags';
00204                 }
00205                 set_config($shortname, $value, 'quiz');
00206                 unset_config($name);
00207             }
00208         }
00209         upgrade_mod_savepoint(true, 2008082200, 'quiz');
00210     }
00211 
00212     // Now that the quiz is no longer responsible for creating all the question
00213     // bank tables, and some of the tables are now the responsibility of the
00214     // datasetdependent question type, which did not have a version.php file before,
00215     // we need to say that these tables are already installed, otherwise XMLDB
00216     // will try to create them again and give an error.
00217     if ($oldversion < 2008082600) {
00218         // Since MDL-16505 was fixed, and we eliminated the datasetdependent
00219         // question type, this is now a no-op.
00220         upgrade_mod_savepoint(true, 2008082600, 'quiz');
00221     }
00222 
00223     if ($oldversion < 2008112101) {
00224 
00225         // Define field lastcron to be added to quiz_report
00226         $table = new xmldb_table('quiz_report');
00227         $field = new xmldb_field('capability', XMLDB_TYPE_CHAR, '255', null,
00228                 null, null, null, 'cron');
00229 
00230         // Conditionally launch add field lastcron
00231         if (!$dbman->field_exists($table, $field)) {
00232             $dbman->add_field($table, $field);
00233         }
00234 
00235         // quiz savepoint reached
00236         upgrade_mod_savepoint(true, 2008112101, 'quiz');
00237     }
00238 
00239     if ($oldversion < 2009010700) {
00240 
00241         // Define field showuserpicture to be added to quiz
00242         $table = new xmldb_table('quiz');
00243         $field = new xmldb_field('showuserpicture', XMLDB_TYPE_INTEGER, '4', null,
00244                 XMLDB_NOTNULL, null, '0', 'delay2');
00245 
00246         // Conditionally launch add field showuserpicture
00247         if (!$dbman->field_exists($table, $field)) {
00248             $dbman->add_field($table, $field);
00249         }
00250 
00251         // quiz savepoint reached
00252         upgrade_mod_savepoint(true, 2009010700, 'quiz');
00253     }
00254 
00255     if ($oldversion < 2009030900) {
00256         // If there are no quiz settings set to advanced yet, the set up the default
00257         // advanced fields from Moodle 2.0.
00258         $quizconfig = get_config('quiz');
00259         $arealreadyadvanced = false;
00260         foreach (array($quizconfig) as $name => $value) {
00261             if (strpos($name, 'fix_') === 0 && !empty($value)) {
00262                 $arealreadyadvanced = true;
00263                 break;
00264             }
00265         }
00266 
00267         if (!$arealreadyadvanced) {
00268             set_config('fix_penaltyscheme', 1, 'quiz');
00269             set_config('fix_attemptonlast', 1, 'quiz');
00270             set_config('fix_questiondecimalpoints', 1, 'quiz');
00271             set_config('fix_password', 1, 'quiz');
00272             set_config('fix_subnet', 1, 'quiz');
00273             set_config('fix_delay1', 1, 'quiz');
00274             set_config('fix_delay2', 1, 'quiz');
00275             set_config('fix_popup', 1, 'quiz');
00276         }
00277 
00278         // quiz savepoint reached
00279         upgrade_mod_savepoint(true, 2009030900, 'quiz');
00280     }
00281 
00282     if ($oldversion < 2009031000) {
00283         // Add new questiondecimaldigits setting, separate form the overall decimaldigits one.
00284         $table = new xmldb_table('quiz');
00285         $field = new xmldb_field('questiondecimalpoints', XMLDB_TYPE_INTEGER, '4', null,
00286                 XMLDB_NOTNULL, null, '-2', 'decimalpoints');
00287         if (!$dbman->field_exists($table, $field)) {
00288             $dbman->add_field($table, $field);
00289         }
00290 
00291         // quiz savepoint reached
00292         upgrade_mod_savepoint(true, 2009031000, 'quiz');
00293     }
00294 
00295     if ($oldversion < 2009031001) {
00296         // Convert quiz.timelimit from minutes to seconds.
00297         $DB->execute('UPDATE {quiz} SET timelimit = timelimit * 60');
00298         $default = get_config('quiz', 'timelimit');
00299         set_config('timelimit', 60 * $default, 'quiz');
00300 
00301         // quiz savepoint reached
00302         upgrade_mod_savepoint(true, 2009031001, 'quiz');
00303     }
00304 
00305     if ($oldversion < 2009042000) {
00306 
00307         // Define field introformat to be added to quiz
00308         $table = new xmldb_table('quiz');
00309         $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED,
00310                 XMLDB_NOTNULL, null, '0', 'intro');
00311 
00312         if (!$dbman->field_exists($table, $field)) {
00313             $dbman->add_field($table, $field);
00314         }
00315 
00316         // conditionally migrate to html format in intro
00317         if ($CFG->texteditors !== 'textarea') {
00318             $rs = $DB->get_recordset('quiz', array('introformat' => FORMAT_MOODLE),
00319                     '', 'id, intro, introformat');
00320             foreach ($rs as $q) {
00321                 $q->intro       = text_to_html($q->intro, false, false, true);
00322                 $q->introformat = FORMAT_HTML;
00323                 $DB->update_record('quiz', $q);
00324                 upgrade_set_timeout();
00325             }
00326             $rs->close();
00327         }
00328 
00329         // quiz savepoint reached
00330         upgrade_mod_savepoint(true, 2009042000, 'quiz');
00331     }
00332 
00333     if ($oldversion < 2010030501) {
00334         // Define table quiz_overrides to be created
00335         $table = new xmldb_table('quiz_overrides');
00336 
00337         // Adding fields to table quiz_overrides
00338         $table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
00339                 XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
00340         $table->add_field('quiz', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
00341                 XMLDB_NOTNULL, null, '0');
00342         $table->add_field('groupid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
00343                 null, null, null);
00344         $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
00345                 null, null, null);
00346         $table->add_field('timeopen', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
00347                 null, null, null);
00348         $table->add_field('timeclose', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
00349                 null, null, null);
00350         $table->add_field('timelimit', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED,
00351                 null, null, null);
00352         $table->add_field('attempts', XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED,
00353                 null, null, null);
00354         $table->add_field('password', XMLDB_TYPE_CHAR, '255', null, null, null, null);
00355 
00356         // Adding keys to table quiz_overrides
00357         $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
00358         $table->add_key('quiz', XMLDB_KEY_FOREIGN, array('quiz'), 'quiz', array('id'));
00359         $table->add_key('groupid', XMLDB_KEY_FOREIGN, array('groupid'), 'groups', array('id'));
00360         $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
00361 
00362         // Conditionally launch create table for quiz_overrides
00363         if (!$dbman->table_exists($table)) {
00364             $dbman->create_table($table);
00365         }
00366 
00367         // quiz savepoint reached
00368         upgrade_mod_savepoint(true, 2010030501, 'quiz');
00369     }
00370 
00371     if ($oldversion < 2010051800) {
00372 
00373         // Define field showblocks to be added to quiz
00374         $table = new xmldb_table('quiz');
00375         $field = new xmldb_field('showblocks', XMLDB_TYPE_INTEGER, '4', null,
00376                 XMLDB_NOTNULL, null, '0', 'showuserpicture');
00377 
00378         // Conditionally launch add field showblocks
00379         if (!$dbman->field_exists($table, $field)) {
00380             $dbman->add_field($table, $field);
00381         }
00382 
00383         // quiz savepoint reached
00384         upgrade_mod_savepoint(true, 2010051800, 'quiz');
00385     }
00386 
00387     if ($oldversion < 2010080600) {
00388 
00389         // Define field feedbacktextformat to be added to quiz_feedback
00390         $table = new xmldb_table('quiz_feedback');
00391         $field = new xmldb_field('feedbacktextformat', XMLDB_TYPE_INTEGER, '2', null,
00392                 XMLDB_NOTNULL, null, '0', 'feedbacktext');
00393 
00394         // Conditionally launch add field feedbacktextformat
00395         if (!$dbman->field_exists($table, $field)) {
00396             $dbman->add_field($table, $field);
00397         }
00398 
00399         // This column defaults to FORMAT_MOODLE, which is correct.
00400 
00401         // quiz savepoint reached
00402         upgrade_mod_savepoint(true, 2010080600, 'quiz');
00403     }
00404 
00405     if ($oldversion < 2010102000) {
00406 
00407         // Define field showblocks to be added to quiz
00408         // Repeat this step, because the column was missing from install.xml for a time.
00409         $table = new xmldb_table('quiz');
00410         $field = new xmldb_field('showblocks', XMLDB_TYPE_INTEGER, '4', null,
00411                 XMLDB_NOTNULL, null, '0', 'showuserpicture');
00412 
00413         // Conditionally launch add field showblocks
00414         if (!$dbman->field_exists($table, $field)) {
00415             $dbman->add_field($table, $field);
00416         }
00417 
00418         // quiz savepoint reached
00419         upgrade_mod_savepoint(true, 2010102000, 'quiz');
00420     }
00421 
00422     if ($oldversion < 2010122300) {
00423         // Fix quiz in the post table after upgrade from 1.9
00424         $table = new xmldb_table('quiz');
00425         $columns = $DB->get_columns('quiz');
00426 
00427         // quiz.questiondecimalpoints should be int (4) not null default -2
00428         if (array_key_exists('questiondecimalpoints', $columns) &&
00429                 $columns['questiondecimalpoints']->default_value != '-2') {
00430             $field = new xmldb_field('questiondecimalpoints', XMLDB_TYPE_INTEGER, '4', null,
00431                     XMLDB_NOTNULL, null, -2, 'decimalpoints');
00432             if ($dbman->field_exists($table, $field)) {
00433                 $dbman->change_field_default($table, $field);
00434             }
00435         }
00436 
00437         // quiz.sumgrades should be decimal(10, 5) not null default 0
00438         if (array_key_exists('sumgrades', $columns) && empty($columns['sumgrades']->not_null)) {
00439             // First set all quiz.sumgrades to 0 if they are null. This should never
00440             // happen however some users have encountered a null value there.
00441             $DB->execute('UPDATE {quiz} SET sumgrades=0 WHERE sumgrades IS NULL');
00442 
00443             $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null,
00444                     XMLDB_NOTNULL, null, '0', 'questions');
00445             if ($dbman->field_exists($table, $field)) {
00446                 $dbman->change_field_default($table, $field);
00447             }
00448         }
00449 
00450         // quiz.grade should be decimal(10, 5) not null default 0
00451         if (array_key_exists('grade', $columns) && empty($columns['grade']->not_null)) {
00452             $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null,
00453                     XMLDB_NOTNULL, null, '0', 'sumgrades');
00454             if ($dbman->field_exists($table, $field)) {
00455                 $dbman->change_field_default($table, $field);
00456             }
00457         }
00458 
00459         upgrade_mod_savepoint(true, 2010122300, 'quiz');
00460     }
00461 
00462     if ($oldversion < 2010122301) {
00463         // Fix quiz_attempts in the post table after upgrade from 1.9
00464         $table = new xmldb_table('quiz_attempts');
00465         $columns = $DB->get_columns('quiz_attempts');
00466 
00467         // quiz_attempts.sumgrades should be decimal(10, 5) not null default 0
00468         if (array_key_exists('sumgrades', $columns) && empty($columns['sumgrades']->not_null)) {
00469             // First set all quiz.sumgrades to 0 if they are null. This should never
00470             // happen however some users have encountered a null value there.
00471             $DB->execute('UPDATE {quiz_attempts} SET sumgrades=0 WHERE sumgrades IS NULL');
00472 
00473             $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null,
00474                     XMLDB_NOTNULL, null, '0', 'attempt');
00475             if ($dbman->field_exists($table, $field)) {
00476                 $dbman->change_field_default($table, $field);
00477             }
00478         }
00479 
00480         upgrade_mod_savepoint(true, 2010122301, 'quiz');
00481     }
00482 
00483     if ($oldversion < 2010122302) {
00484         // Fix quiz_feedback in the post table after upgrade from 1.9
00485         $table = new xmldb_table('quiz_feedback');
00486         $columns = $DB->get_columns('quiz_feedback');
00487 
00488         // quiz_feedback.mingrade should be decimal(10, 5) not null default 0
00489         if (array_key_exists('mingrade', $columns) && empty($columns['mingrade']->not_null)) {
00490             $field = new xmldb_field('mingrade', XMLDB_TYPE_NUMBER, '10, 5', null,
00491                     XMLDB_NOTNULL, null, '0', 'feedbacktextformat');
00492             if ($dbman->field_exists($table, $field)) {
00493                 $dbman->change_field_default($table, $field);
00494             }
00495         }
00496 
00497         // quiz_feedback.maxgrade should be decimal(10, 5) not null default 0
00498         if (array_key_exists('maxgrade', $columns) && empty($columns['maxgrade']->not_null)) {
00499             // Fixed in earlier upgrade code
00500             $field = new xmldb_field('maxgrade', XMLDB_TYPE_NUMBER, '10, 5', null,
00501                     XMLDB_NOTNULL, null, '0', 'mingrade');
00502             if ($dbman->field_exists($table, $field)) {
00503                 $dbman->change_field_default($table, $field);
00504             }
00505         }
00506 
00507         upgrade_mod_savepoint(true, 2010122302, 'quiz');
00508     }
00509 
00510     if ($oldversion < 2010122303) {
00511         // Fix quiz_grades in the post table after upgrade from 1.9
00512         $table = new xmldb_table('quiz_grades');
00513         $columns = $DB->get_columns('quiz_grades');
00514 
00515         // quiz_grades.grade should be decimal(10, 5) not null default 0
00516         if (array_key_exists('grade', $columns) && empty($columns['grade']->not_null)) {
00517             $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '10, 5', null,
00518                     XMLDB_NOTNULL, null, '0', 'userid');
00519             if ($dbman->field_exists($table, $field)) {
00520                 $dbman->change_field_default($table, $field);
00521             }
00522         }
00523 
00524         upgrade_mod_savepoint(true, 2010122303, 'quiz');
00525     }
00526 
00527     if ($oldversion < 2010122304) {
00528         // Fix quiz_question_instances in the post table after upgrade from 1.9
00529         $table = new xmldb_table('quiz_question_instances');
00530         $columns = $DB->get_columns('quiz_question_instances');
00531 
00532         // quiz_question_instances.grade should be decimal(12, 7) not null default 0
00533         if (array_key_exists('grade', $columns) && empty($columns['grade']->not_null)) {
00534             $field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null,
00535                     XMLDB_NOTNULL, null, '0', 'question');
00536             if ($dbman->field_exists($table, $field)) {
00537                 $dbman->change_field_default($table, $field);
00538             }
00539         }
00540 
00541         upgrade_mod_savepoint(true, 2010122304, 'quiz');
00542     }
00543 
00544     //===== 2.1.0 upgrade line ======//
00545 
00546     // Complete any old upgrade from 1.5 that was never finished.
00547     if ($oldversion < 2011051199) {
00548         $table = new xmldb_table('question_states');
00549         if ($dbman->table_exists($table)) {
00550             $transaction = $DB->start_delegated_transaction();
00551 
00552             $oldattempts = $DB->get_records_sql('
00553                 SELECT *
00554                   FROM {quiz_attempts} quiza
00555                  WHERE uniqueid IN (
00556                     SELECT DISTINCT qst.attempt
00557                       FROM {question_states} qst
00558                       LEFT JOIN {question_sessions} qsess ON
00559                             qst.question = qsess.questionid AND qst.attempt = qsess.attemptid
00560                      WHERE qsess.id IS NULL
00561                 )
00562             ');
00563 
00564             if ($oldattempts) {
00565                 require_once($CFG->dirroot . '/mod/quiz/db/upgradelib.php');
00566 
00567                 $pbar = new progress_bar('q15upgrade');
00568                 $pbar->create();
00569                 $a = new stdClass();
00570                 $a->outof = count($oldattempts);
00571                 $a->done = 0;
00572                 $pbar->update($a->done, $a->outof,
00573                         get_string('upgradingveryoldquizattempts', 'quiz', $a));
00574 
00575                 foreach ($oldattempts as $oldattempt) {
00576                     quiz_upgrade_very_old_question_sessions($oldattempt);
00577 
00578                     $a->done += 1;
00579                     $pbar->update($a->done, $a->outof,
00580                             get_string('upgradingveryoldquizattempts', 'quiz', $a));
00581                 }
00582             }
00583 
00584             $transaction->allow_commit();
00585         }
00586 
00587         // quiz savepoint reached
00588         upgrade_mod_savepoint(true, 2011051199, 'quiz');
00589     }
00590 
00591     // Add new preferredbehaviour column to the quiz table.
00592     if ($oldversion < 2011051200) {
00593         $table = new xmldb_table('quiz');
00594         $field = new xmldb_field('preferredbehaviour');
00595         $field->set_attributes(XMLDB_TYPE_CHAR, '32', null,
00596                 null, null, null, 'timeclose');
00597         if (!$dbman->field_exists($table, $field)) {
00598             $dbman->add_field($table, $field);
00599         }
00600 
00601         // quiz savepoint reached
00602         upgrade_mod_savepoint(true, 2011051200, 'quiz');
00603     }
00604 
00605     // Populate preferredbehaviour column based on old optionflags column.
00606     if ($oldversion < 2011051201) {
00607         if ($dbman->field_exists('quiz', 'optionflags')) {
00608             $DB->set_field_select('quiz', 'preferredbehaviour', 'deferredfeedback',
00609                     'optionflags = 0');
00610             $DB->set_field_select('quiz', 'preferredbehaviour', 'adaptive',
00611                     'optionflags <> 0 AND penaltyscheme <> 0');
00612             $DB->set_field_select('quiz', 'preferredbehaviour', 'adaptivenopenalty',
00613                     'optionflags <> 0 AND penaltyscheme = 0');
00614 
00615             set_config('preferredbehaviour', 'deferredfeedback', 'quiz');
00616             set_config('fix_preferredbehaviour', 0, 'quiz');
00617         }
00618 
00619         // quiz savepoint reached
00620         upgrade_mod_savepoint(true, 2011051201, 'quiz');
00621     }
00622 
00623     // Add a not-NULL constraint to the preferredmodel field now that it is populated.
00624     if ($oldversion < 2011051202) {
00625         $table = new xmldb_table('quiz');
00626         $field = new xmldb_field('preferredbehaviour');
00627         $field->set_attributes(XMLDB_TYPE_CHAR, '32', null,
00628                 XMLDB_NOTNULL, null, null, 'timeclose');
00629 
00630         $dbman->change_field_notnull($table, $field);
00631 
00632         // quiz savepoint reached
00633         upgrade_mod_savepoint(true, 2011051202, 'quiz');
00634     }
00635 
00636     // Drop the old optionflags field.
00637     if ($oldversion < 2011051203) {
00638         $table = new xmldb_table('quiz');
00639         $field = new xmldb_field('optionflags');
00640 
00641         if ($dbman->field_exists($table, $field)) {
00642             $dbman->drop_field($table, $field);
00643         }
00644 
00645         unset_config('optionflags', 'quiz');
00646         unset_config('fix_optionflags', 'quiz');
00647 
00648         // quiz savepoint reached
00649         upgrade_mod_savepoint(true, 2011051203, 'quiz');
00650     }
00651 
00652     // Drop the old penaltyscheme field.
00653     if ($oldversion < 2011051204) {
00654         $table = new xmldb_table('quiz');
00655         $field = new xmldb_field('penaltyscheme');
00656 
00657         if ($dbman->field_exists($table, $field)) {
00658             $dbman->drop_field($table, $field);
00659         }
00660 
00661         unset_config('penaltyscheme', 'quiz');
00662         unset_config('fix_penaltyscheme', 'quiz');
00663 
00664         // quiz savepoint reached
00665         upgrade_mod_savepoint(true, 2011051204, 'quiz');
00666     }
00667 
00668     if ($oldversion < 2011051205) {
00669 
00670         // Changing nullability of field sumgrades on table quiz_attempts to null
00671         $table = new xmldb_table('quiz_attempts');
00672         $field = new xmldb_field('sumgrades');
00673         $field->set_attributes(XMLDB_TYPE_NUMBER, '10, 5', null,
00674                 null, null, null, 'attempt');
00675 
00676         // Launch change of nullability for field sumgrades
00677         $dbman->change_field_notnull($table, $field);
00678 
00679         // Launch change of default for field sumgrades
00680         $dbman->change_field_default($table, $field);
00681 
00682         // quiz savepoint reached
00683         upgrade_mod_savepoint(true, 2011051205, 'quiz');
00684     }
00685 
00686     if ($oldversion < 2011051207) {
00687 
00688         // Define field reviewattempt to be added to quiz
00689         $table = new xmldb_table('quiz');
00690         $field = new xmldb_field('reviewattempt');
00691         $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED,
00692                 XMLDB_NOTNULL, null, '0', 'review');
00693 
00694         // Launch add field reviewattempt
00695         if (!$dbman->field_exists($table, $field)) {
00696             $dbman->add_field($table, $field);
00697         }
00698 
00699         // quiz savepoint reached
00700         upgrade_mod_savepoint(true, 2011051207, 'quiz');
00701     }
00702 
00703     if ($oldversion < 2011051208) {
00704 
00705         // Define field reviewattempt to be added to quiz
00706         $table = new xmldb_table('quiz');
00707         $field = new xmldb_field('reviewcorrectness');
00708         $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED,
00709                 XMLDB_NOTNULL, null, '0', 'reviewattempt');
00710 
00711         // Launch add field reviewattempt
00712         if (!$dbman->field_exists($table, $field)) {
00713             $dbman->add_field($table, $field);
00714         }
00715 
00716         // quiz savepoint reached
00717         upgrade_mod_savepoint(true, 2011051208, 'quiz');
00718     }
00719 
00720     if ($oldversion < 2011051209) {
00721 
00722         // Define field reviewattempt to be added to quiz
00723         $table = new xmldb_table('quiz');
00724         $field = new xmldb_field('reviewmarks');
00725         $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED,
00726                 XMLDB_NOTNULL, null, '0', 'reviewcorrectness');
00727 
00728         // Launch add field reviewattempt
00729         if (!$dbman->field_exists($table, $field)) {
00730             $dbman->add_field($table, $field);
00731         }
00732 
00733         // quiz savepoint reached
00734         upgrade_mod_savepoint(true, 2011051209, 'quiz');
00735     }
00736 
00737     if ($oldversion < 2011051210) {
00738 
00739         // Define field reviewattempt to be added to quiz
00740         $table = new xmldb_table('quiz');
00741         $field = new xmldb_field('reviewspecificfeedback');
00742         $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED,
00743                 XMLDB_NOTNULL, null, '0', 'reviewmarks');
00744 
00745         // Launch add field reviewattempt
00746         if (!$dbman->field_exists($table, $field)) {
00747             $dbman->add_field($table, $field);
00748         }
00749 
00750         // quiz savepoint reached
00751         upgrade_mod_savepoint(true, 2011051210, 'quiz');
00752     }
00753 
00754     if ($oldversion < 2011051211) {
00755 
00756         // Define field reviewattempt to be added to quiz
00757         $table = new xmldb_table('quiz');
00758         $field = new xmldb_field('reviewgeneralfeedback');
00759         $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED,
00760                 XMLDB_NOTNULL, null, '0', 'reviewspecificfeedback');
00761 
00762         // Launch add field reviewattempt
00763         if (!$dbman->field_exists($table, $field)) {
00764             $dbman->add_field($table, $field);
00765         }
00766 
00767         // quiz savepoint reached
00768         upgrade_mod_savepoint(true, 2011051211, 'quiz');
00769     }
00770 
00771     if ($oldversion < 2011051212) {
00772 
00773         // Define field reviewattempt to be added to quiz
00774         $table = new xmldb_table('quiz');
00775         $field = new xmldb_field('reviewrightanswer');
00776         $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED,
00777                 XMLDB_NOTNULL, null, '0', 'reviewgeneralfeedback');
00778 
00779         // Launch add field reviewattempt
00780         if (!$dbman->field_exists($table, $field)) {
00781             $dbman->add_field($table, $field);
00782         }
00783 
00784         // quiz savepoint reached
00785         upgrade_mod_savepoint(true, 2011051212, 'quiz');
00786     }
00787 
00788     if ($oldversion < 2011051213) {
00789 
00790         // Define field reviewattempt to be added to quiz
00791         $table = new xmldb_table('quiz');
00792         $field = new xmldb_field('reviewoverallfeedback');
00793         $field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED,
00794                 XMLDB_NOTNULL, null, '0', 'reviewrightanswer');
00795 
00796         // Launch add field reviewattempt
00797         if (!$dbman->field_exists($table, $field)) {
00798             $dbman->add_field($table, $field);
00799         }
00800 
00801         // quiz savepoint reached
00802         upgrade_mod_savepoint(true, 2011051213, 'quiz');
00803     }
00804 
00805     define('QUIZ_NEW_DURING',            0x10000);
00806     define('QUIZ_NEW_IMMEDIATELY_AFTER', 0x01000);
00807     define('QUIZ_NEW_LATER_WHILE_OPEN',  0x00100);
00808     define('QUIZ_NEW_AFTER_CLOSE',       0x00010);
00809 
00810     define('QUIZ_OLD_IMMEDIATELY', 0x3c003f);
00811     define('QUIZ_OLD_OPEN',        0x3c00fc0);
00812     define('QUIZ_OLD_CLOSED',      0x3c03f000);
00813 
00814     define('QUIZ_OLD_RESPONSES',        1*0x1041); // Show responses
00815     define('QUIZ_OLD_SCORES',           2*0x1041); // Show scores
00816     define('QUIZ_OLD_FEEDBACK',         4*0x1041); // Show question feedback
00817     define('QUIZ_OLD_ANSWERS',          8*0x1041); // Show correct answers
00818     define('QUIZ_OLD_SOLUTIONS',       16*0x1041); // Show solutions
00819     define('QUIZ_OLD_GENERALFEEDBACK', 32*0x1041); // Show question general feedback
00820     define('QUIZ_OLD_OVERALLFEEDBACK',  1*0x4440000); // Show quiz overall feedback
00821 
00822     // Copy the old review settings
00823     if ($oldversion < 2011051214) {
00824         if ($dbman->field_exists('quiz', 'review')) {
00825             $DB->execute("
00826             UPDATE {quiz}
00827             SET reviewattempt = " . $DB->sql_bitor($DB->sql_bitor(
00828                 QUIZ_NEW_DURING,
00829                 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_RESPONSES) .
00830                     ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor(
00831                 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_RESPONSES) .
00832                     ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END',
00833                 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_RESPONSES) .
00834                     ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . "
00835             ");
00836         }
00837 
00838         // quiz savepoint reached
00839         upgrade_mod_savepoint(true, 2011051214, 'quiz');
00840     }
00841 
00842     if ($oldversion < 2011051215) {
00843         if ($dbman->field_exists('quiz', 'review')) {
00844             $DB->execute("
00845             UPDATE {quiz}
00846             SET reviewcorrectness = " . $DB->sql_bitor($DB->sql_bitor(
00847                 QUIZ_NEW_DURING,
00848                 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_SCORES) .
00849                     ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor(
00850                 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_SCORES) .
00851                     ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END',
00852                 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_SCORES) .
00853                     ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . "
00854             ");
00855         }
00856 
00857         // quiz savepoint reached
00858         upgrade_mod_savepoint(true, 2011051215, 'quiz');
00859     }
00860 
00861     if ($oldversion < 2011051216) {
00862         if ($dbman->field_exists('quiz', 'review')) {
00863             $DB->execute("
00864             UPDATE {quiz}
00865             SET reviewmarks = " . $DB->sql_bitor($DB->sql_bitor(
00866                 QUIZ_NEW_DURING,
00867                 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_SCORES) .
00868                     ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor(
00869                 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_SCORES) .
00870                     ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END',
00871                 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_SCORES) .
00872                     ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . "
00873             ");
00874         }
00875 
00876         // quiz savepoint reached
00877         upgrade_mod_savepoint(true, 2011051216, 'quiz');
00878     }
00879 
00880     if ($oldversion < 2011051217) {
00881         if ($dbman->field_exists('quiz', 'review')) {
00882             $DB->execute("
00883             UPDATE {quiz}
00884             SET reviewspecificfeedback = " . $DB->sql_bitor($DB->sql_bitor(
00885                 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_FEEDBACK) .
00886                     ' <> 0 THEN ' . QUIZ_NEW_DURING . ' ELSE 0 END',
00887                 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_FEEDBACK) .
00888                     ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor(
00889                 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_FEEDBACK) .
00890                     ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END',
00891                 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_FEEDBACK) .
00892                     ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . "
00893             ");
00894         }
00895 
00896         // quiz savepoint reached
00897         upgrade_mod_savepoint(true, 2011051217, 'quiz');
00898     }
00899 
00900     if ($oldversion < 2011051218) {
00901         if ($dbman->field_exists('quiz', 'review')) {
00902             $DB->execute("
00903             UPDATE {quiz}
00904             SET reviewgeneralfeedback = " . $DB->sql_bitor($DB->sql_bitor(
00905                 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_GENERALFEEDBACK) .
00906                     ' <> 0 THEN ' . QUIZ_NEW_DURING . ' ELSE 0 END',
00907                 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_GENERALFEEDBACK) .
00908                     ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor(
00909                 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_GENERALFEEDBACK) .
00910                     ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END',
00911                 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_GENERALFEEDBACK) .
00912                     ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . "
00913             ");
00914         }
00915 
00916         // quiz savepoint reached
00917         upgrade_mod_savepoint(true, 2011051218, 'quiz');
00918     }
00919 
00920     if ($oldversion < 2011051219) {
00921         if ($dbman->field_exists('quiz', 'review')) {
00922             $DB->execute("
00923             UPDATE {quiz}
00924             SET reviewrightanswer = " . $DB->sql_bitor($DB->sql_bitor(
00925                 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_ANSWERS) .
00926                     ' <> 0 THEN ' . QUIZ_NEW_DURING . ' ELSE 0 END',
00927                 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_ANSWERS) .
00928                     ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor(
00929                 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_ANSWERS) .
00930                     ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END',
00931                 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_ANSWERS) .
00932                     ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . "
00933             ");
00934         }
00935 
00936         // quiz savepoint reached
00937         upgrade_mod_savepoint(true, 2011051219, 'quiz');
00938     }
00939 
00940     if ($oldversion < 2011051220) {
00941         if ($dbman->field_exists('quiz', 'review')) {
00942             $DB->execute("
00943             UPDATE {quiz}
00944             SET reviewoverallfeedback = " . $DB->sql_bitor($DB->sql_bitor(
00945                 0,
00946                 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_OVERALLFEEDBACK) .
00947                     ' <> 0 THEN ' . QUIZ_NEW_IMMEDIATELY_AFTER . ' ELSE 0 END'), $DB->sql_bitor(
00948                 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_OPEN & QUIZ_OLD_OVERALLFEEDBACK) .
00949                     ' <> 0 THEN ' . QUIZ_NEW_LATER_WHILE_OPEN . ' ELSE 0 END',
00950                 'CASE WHEN ' . $DB->sql_bitand('review', QUIZ_OLD_CLOSED & QUIZ_OLD_OVERALLFEEDBACK) .
00951                     ' <> 0 THEN ' . QUIZ_NEW_AFTER_CLOSE . ' ELSE 0 END')) . "
00952             ");
00953         }
00954 
00955         // quiz savepoint reached
00956         upgrade_mod_savepoint(true, 2011051220, 'quiz');
00957     }
00958 
00959     // And, do the same for the defaults
00960     if ($oldversion < 2011051221) {
00961         $quizrevew = get_config('quiz', 'review');
00962         if (!empty($quizrevew)) {
00963 
00964             set_config('reviewattempt',
00965                     QUIZ_NEW_DURING |
00966                     ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_RESPONSES ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) |
00967                     ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_RESPONSES ? QUIZ_NEW_LATER_WHILE_OPEN : 0) |
00968                     ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_RESPONSES ? QUIZ_NEW_AFTER_CLOSE : 0),
00969                     'quiz');
00970 
00971             set_config('reviewcorrectness',
00972                     QUIZ_NEW_DURING |
00973                     ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_SCORES ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) |
00974                     ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_SCORES ? QUIZ_NEW_LATER_WHILE_OPEN : 0) |
00975                     ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_SCORES ? QUIZ_NEW_AFTER_CLOSE : 0),
00976                     'quiz');
00977 
00978             set_config('reviewmarks',
00979                     QUIZ_NEW_DURING |
00980                     ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_SCORES ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) |
00981                     ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_SCORES ? QUIZ_NEW_LATER_WHILE_OPEN : 0) |
00982                     ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_SCORES ? QUIZ_NEW_AFTER_CLOSE : 0),
00983                     'quiz');
00984 
00985             set_config('reviewspecificfeedback',
00986                     ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_FEEDBACK ? QUIZ_NEW_DURING : 0) |
00987                     ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_FEEDBACK ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) |
00988                     ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_FEEDBACK ? QUIZ_NEW_LATER_WHILE_OPEN : 0) |
00989                     ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_FEEDBACK ? QUIZ_NEW_AFTER_CLOSE : 0),
00990                     'quiz');
00991 
00992             set_config('reviewgeneralfeedback',
00993                     ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_GENERALFEEDBACK ? QUIZ_NEW_DURING : 0) |
00994                     ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_GENERALFEEDBACK ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) |
00995                     ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_GENERALFEEDBACK ? QUIZ_NEW_LATER_WHILE_OPEN : 0) |
00996                     ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_GENERALFEEDBACK ? QUIZ_NEW_AFTER_CLOSE : 0),
00997                     'quiz');
00998 
00999             set_config('reviewrightanswer',
01000                     ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_ANSWERS ? QUIZ_NEW_DURING : 0) |
01001                     ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_ANSWERS ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) |
01002                     ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_ANSWERS ? QUIZ_NEW_LATER_WHILE_OPEN : 0) |
01003                     ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_ANSWERS ? QUIZ_NEW_AFTER_CLOSE : 0),
01004                     'quiz');
01005 
01006             set_config('reviewoverallfeedback',
01007                     0 |
01008                     ($quizrevew & QUIZ_OLD_IMMEDIATELY & QUIZ_OLD_OVERALLFEEDBACK ? QUIZ_NEW_IMMEDIATELY_AFTER : 0) |
01009                     ($quizrevew & QUIZ_OLD_OPEN & QUIZ_OLD_OVERALLFEEDBACK ? QUIZ_NEW_LATER_WHILE_OPEN : 0) |
01010                     ($quizrevew & QUIZ_OLD_CLOSED & QUIZ_OLD_OVERALLFEEDBACK ? QUIZ_NEW_AFTER_CLOSE : 0),
01011                     'quiz');
01012         }
01013 
01014         // quiz savepoint reached
01015         upgrade_mod_savepoint(true, 2011051221, 'quiz');
01016     }
01017 
01018     // Finally drop the old column
01019     if ($oldversion < 2011051222) {
01020         // Define field review to be dropped from quiz
01021         $table = new xmldb_table('quiz');
01022         $field = new xmldb_field('review');
01023 
01024         // Launch drop field review
01025         if ($dbman->field_exists($table, $field)) {
01026             $dbman->drop_field($table, $field);
01027         }
01028 
01029         // quiz savepoint reached
01030         upgrade_mod_savepoint(true, 2011051222, 'quiz');
01031     }
01032 
01033     if ($oldversion < 2011051223) {
01034         unset_config('review', 'quiz');
01035 
01036         // quiz savepoint reached
01037         upgrade_mod_savepoint(true, 2011051223, 'quiz');
01038     }
01039 
01040     if ($oldversion < 2011051225) {
01041         // Define table quiz_report to be renamed to quiz_reports
01042         $table = new xmldb_table('quiz_report');
01043 
01044         // Launch rename table for quiz_reports
01045         if ($dbman->table_exists($table)) {
01046             $dbman->rename_table($table, 'quiz_reports');
01047         }
01048 
01049         upgrade_mod_savepoint(true, 2011051225, 'quiz');
01050     }
01051 
01052     if ($oldversion < 2011051226) {
01053         // Define index name (unique) to be added to quiz_reports
01054         $table = new xmldb_table('quiz_reports');
01055         $index = new xmldb_index('name', XMLDB_INDEX_UNIQUE, array('name'));
01056 
01057         // Conditionally launch add index name
01058         if (!$dbman->index_exists($table, $index)) {
01059             $dbman->add_index($table, $index);
01060         }
01061 
01062         upgrade_mod_savepoint(true, 2011051226, 'quiz');
01063     }
01064 
01065     if ($oldversion < 2011051227) {
01066 
01067         // Changing nullability of field sumgrades on table quiz_attempts to null
01068         $table = new xmldb_table('quiz_attempts');
01069         $field = new xmldb_field('sumgrades', XMLDB_TYPE_NUMBER, '10, 5', null,
01070                 null, null, null, 'attempt');
01071 
01072         // Launch change of nullability for field sumgrades
01073         $dbman->change_field_notnull($table, $field);
01074 
01075         // quiz savepoint reached
01076         upgrade_mod_savepoint(true, 2011051227, 'quiz');
01077     }
01078 
01079     if ($oldversion < 2011051228) {
01080         // Define field needsupgradetonewqe to be added to quiz_attempts
01081         $table = new xmldb_table('quiz_attempts');
01082         $field = new xmldb_field('needsupgradetonewqe', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED,
01083                 XMLDB_NOTNULL, null, '0', 'preview');
01084 
01085         // Launch add field needsupgradetonewqe
01086         if (!$dbman->field_exists($table, $field)) {
01087             $dbman->add_field($table, $field);
01088         }
01089 
01090         $DB->set_field('quiz_attempts', 'needsupgradetonewqe', 1);
01091 
01092         // quiz savepoint reached
01093         upgrade_mod_savepoint(true, 2011051228, 'quiz');
01094     }
01095 
01096     if ($oldversion < 2011051229) {
01097         $table = new xmldb_table('question_states');
01098         if ($dbman->table_exists($table)) {
01099             // First delete all data from preview attempts.
01100             $DB->delete_records_select('question_states',
01101                     "attempt IN (SELECT uniqueid FROM {quiz_attempts} WHERE preview = 1)");
01102             $DB->delete_records_select('question_sessions',
01103                     "attemptid IN (SELECT uniqueid FROM {quiz_attempts} WHERE preview = 1)");
01104             $DB->delete_records('quiz_attempts', array('preview' => 1));
01105 
01106             // Now update all the old attempt data.
01107             $oldrcachesetting = $CFG->rcache;
01108             $CFG->rcache = false;
01109 
01110             require_once($CFG->dirroot . '/question/engine/upgrade/upgradelib.php');
01111             $upgrader = new question_engine_attempt_upgrader();
01112             $upgrader->convert_all_quiz_attempts();
01113 
01114             $CFG->rcache = $oldrcachesetting;
01115         }
01116 
01117         // quiz savepoint reached
01118         upgrade_mod_savepoint(true, 2011051229, 'quiz');
01119     }
01120 
01121     // Moodle v2.1.0 release upgrade line
01122     // Put any upgrade step following this
01123 
01124     if ($oldversion < 2011100600) {
01125 
01126         // Define field browsersecurity to be added to quiz
01127         $table = new xmldb_table('quiz');
01128         $field = new xmldb_field('browsersecurity', XMLDB_TYPE_CHAR, '32', null,
01129                 XMLDB_NOTNULL, null, '[unknownvalue]', 'subnet');
01130 
01131         // Conditionally launch add field browsersecurity
01132         if (!$dbman->field_exists($table, $field)) {
01133             $dbman->add_field($table, $field);
01134         }
01135 
01136         // quiz savepoint reached
01137         upgrade_mod_savepoint(true, 2011100600, 'quiz');
01138     }
01139 
01140     if ($oldversion < 2011100601) {
01141         $DB->set_field('quiz', 'browsersecurity', '-', array('popup' => 0));
01142         $DB->set_field('quiz', 'browsersecurity', 'securewindow', array('popup' => 1));
01143         $DB->set_field('quiz', 'browsersecurity', 'safebrowser', array('popup' => 2));
01144 
01145         upgrade_mod_savepoint(true, 2011100601, 'quiz');
01146     }
01147 
01148     if ($oldversion < 2011100602) {
01149 
01150         // Changing the default of field browsersecurity on table quiz to drop it
01151         $table = new xmldb_table('quiz');
01152         $field = new xmldb_field('browsersecurity', XMLDB_TYPE_CHAR, '32', null,
01153                 XMLDB_NOTNULL, null, null, 'subnet');
01154 
01155         // Launch change of default for field browsersecurity
01156         $dbman->change_field_default($table, $field);
01157 
01158         // quiz savepoint reached
01159         upgrade_mod_savepoint(true, 2011100602, 'quiz');
01160     }
01161 
01162     if ($oldversion < 2011100603) {
01163 
01164         // Define field popup to be dropped from quiz
01165         $table = new xmldb_table('quiz');
01166         $field = new xmldb_field('popup');
01167 
01168         // Conditionally launch drop field popup
01169         if ($dbman->field_exists($table, $field)) {
01170             $dbman->drop_field($table, $field);
01171         }
01172 
01173         // quiz savepoint reached
01174         upgrade_mod_savepoint(true, 2011100603, 'quiz');
01175     }
01176 
01177     if ($oldversion < 2011100604) {
01178         switch (get_config('quiz', 'popup')) {
01179             case 1:
01180                 set_config('browsersecurity', 'securewindow', 'quiz');
01181                 break;
01182             case 2:
01183                 set_config('browsersecurity', 'safebrowser', 'quiz');
01184                 break;
01185             default:
01186                 set_config('browsersecurity', '-', 'quiz');
01187         }
01188         unset_config('quiz', 'popup');
01189 
01190         set_config('browsersecurity_adv', get_config('quiz', 'popup_adv'), 'quiz');
01191         unset_config('quiz', 'popup_adv');
01192 
01193         upgrade_mod_savepoint(true, 2011100604, 'quiz');
01194     }
01195 
01196     // Moodle v2.2.0 release upgrade line
01197     // Put any upgrade step following this
01198 
01199     return true;
01200 }
01201 
 All Data Structures Namespaces Files Functions Variables Enumerations