[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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. 13 // 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/>. 16 17 /** 18 * Upgrade script for the quiz module. 19 * 20 * @package mod_quiz 21 * @copyright 2006 Eloy Lafuente (stronk7) 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die(); 26 27 /** 28 * Quiz module upgrade function. 29 * @param string $oldversion the version we are upgrading from. 30 */ 31 function xmldb_quiz_upgrade($oldversion) { 32 global $CFG, $DB; 33 34 $dbman = $DB->get_manager(); 35 36 if ($oldversion < 2014052800) { 37 38 // Define field completionattemptsexhausted to be added to quiz. 39 $table = new xmldb_table('quiz'); 40 $field = new xmldb_field('completionattemptsexhausted', XMLDB_TYPE_INTEGER, '1', null, null, null, '0', 'showblocks'); 41 42 // Conditionally launch add field completionattemptsexhausted. 43 if (!$dbman->field_exists($table, $field)) { 44 $dbman->add_field($table, $field); 45 } 46 // Quiz savepoint reached. 47 upgrade_mod_savepoint(true, 2014052800, 'quiz'); 48 } 49 50 if ($oldversion < 2014052801) { 51 // Define field completionpass to be added to quiz. 52 $table = new xmldb_table('quiz'); 53 $field = new xmldb_field('completionpass', XMLDB_TYPE_INTEGER, '1', null, null, null, 0, 'completionattemptsexhausted'); 54 55 // Conditionally launch add field completionpass. 56 if (!$dbman->field_exists($table, $field)) { 57 $dbman->add_field($table, $field); 58 } 59 60 // Quiz savepoint reached. 61 upgrade_mod_savepoint(true, 2014052801, 'quiz'); 62 } 63 64 // Moodle v2.8.0 release upgrade line. 65 // Put any upgrade step following this. 66 67 if ($oldversion < 2015030500) { 68 // Define field requireprevious to be added to quiz_slots. 69 $table = new xmldb_table('quiz_slots'); 70 $field = new xmldb_field('requireprevious', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, 0, 'page'); 71 72 // Conditionally launch add field page. 73 if (!$dbman->field_exists($table, $field)) { 74 $dbman->add_field($table, $field); 75 } 76 77 // Quiz savepoint reached. 78 upgrade_mod_savepoint(true, 2015030500, 'quiz'); 79 } 80 81 if ($oldversion < 2015030900) { 82 // Define field canredoquestions to be added to quiz. 83 $table = new xmldb_table('quiz'); 84 $field = new xmldb_field('canredoquestions', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, 0, 'preferredbehaviour'); 85 86 // Conditionally launch add field completionpass. 87 if (!$dbman->field_exists($table, $field)) { 88 $dbman->add_field($table, $field); 89 } 90 91 // Quiz savepoint reached. 92 upgrade_mod_savepoint(true, 2015030900, 'quiz'); 93 } 94 95 if ($oldversion < 2015032300) { 96 97 // Define table quiz_sections to be created. 98 $table = new xmldb_table('quiz_sections'); 99 100 // Adding fields to table quiz_sections. 101 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); 102 $table->add_field('quizid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); 103 $table->add_field('firstslot', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); 104 $table->add_field('heading', XMLDB_TYPE_CHAR, '1333', null, null, null, null); 105 $table->add_field('shufflequestions', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0'); 106 107 // Adding keys to table quiz_sections. 108 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); 109 $table->add_key('quizid', XMLDB_KEY_FOREIGN, array('quizid'), 'quiz', array('id')); 110 111 // Adding indexes to table quiz_sections. 112 $table->add_index('quizid-firstslot', XMLDB_INDEX_UNIQUE, array('quizid', 'firstslot')); 113 114 // Conditionally launch create table for quiz_sections. 115 if (!$dbman->table_exists($table)) { 116 $dbman->create_table($table); 117 } 118 119 // Quiz savepoint reached. 120 upgrade_mod_savepoint(true, 2015032300, 'quiz'); 121 } 122 123 if ($oldversion < 2015032301) { 124 125 // Create a section for each quiz. 126 $DB->execute(" 127 INSERT INTO {quiz_sections} 128 (quizid, firstslot, heading, shufflequestions) 129 SELECT id, 1, ?, shufflequestions 130 FROM {quiz} 131 ", array('')); 132 133 // Quiz savepoint reached. 134 upgrade_mod_savepoint(true, 2015032301, 'quiz'); 135 } 136 137 if ($oldversion < 2015032302) { 138 139 // Define field shufflequestions to be dropped from quiz. 140 $table = new xmldb_table('quiz'); 141 $field = new xmldb_field('shufflequestions'); 142 143 // Conditionally launch drop field shufflequestions. 144 if ($dbman->field_exists($table, $field)) { 145 $dbman->drop_field($table, $field); 146 } 147 148 // Quiz savepoint reached. 149 upgrade_mod_savepoint(true, 2015032302, 'quiz'); 150 } 151 152 if ($oldversion < 2015032303) { 153 154 // Drop corresponding admin settings. 155 unset_config('shufflequestions', 'quiz'); 156 unset_config('shufflequestions_adv', 'quiz'); 157 158 // Quiz savepoint reached. 159 upgrade_mod_savepoint(true, 2015032303, 'quiz'); 160 } 161 162 // Moodle v2.9.0 release upgrade line. 163 // Put any upgrade step following this. 164 165 // Moodle v3.0.0 release upgrade line. 166 // Put any upgrade step following this. 167 168 if ($oldversion < 2016032600) { 169 // Update quiz_sections to repair quizzes what were broken by MDL-53507. 170 $problemquizzes = $DB->get_records_sql(" 171 SELECT quizid, MIN(firstslot) AS firstsectionfirstslot 172 FROM {quiz_sections} 173 GROUP BY quizid 174 HAVING MIN(firstslot) > 1"); 175 176 if ($problemquizzes) { 177 $pbar = new progress_bar('upgradequizfirstsection', 500, true); 178 $total = count($problemquizzes); 179 $done = 0; 180 foreach ($problemquizzes as $problemquiz) { 181 $DB->set_field('quiz_sections', 'firstslot', 1, 182 array('quizid' => $problemquiz->quizid, 183 'firstslot' => $problemquiz->firstsectionfirstslot)); 184 $done += 1; 185 $pbar->update($done, $total, "Fixing quiz layouts - {$done}/{$total}."); 186 } 187 } 188 189 // Quiz savepoint reached. 190 upgrade_mod_savepoint(true, 2016032600, 'quiz'); 191 } 192 193 // Moodle v3.1.0 release upgrade line. 194 // Put any upgrade step following this. 195 196 return true; 197 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |