Differences Between: [Versions 310 and 400] [Versions 311 and 400] [Versions 39 and 400] [Versions 400 and 401] [Versions 400 and 402] [Versions 400 and 403]
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 $dbman = $DB->get_manager(); 34 35 // Automatically generated Moodle v3.6.0 release upgrade line. 36 // Put any upgrade step following this. 37 38 // Automatically generated Moodle v3.7.0 release upgrade line. 39 // Put any upgrade step following this. 40 41 // Automatically generated Moodle v3.8.0 release upgrade line. 42 // Put any upgrade step following this. 43 44 // Automatically generated Moodle v3.9.0 release upgrade line. 45 // Put any upgrade step following this. 46 47 if ($oldversion < 2020061501) { 48 49 // Define field completionminattempts to be added to quiz. 50 $table = new xmldb_table('quiz'); 51 $field = new xmldb_field('completionminattempts', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 52 'completionpass'); 53 54 // Conditionally launch add field completionminattempts. 55 if (!$dbman->field_exists($table, $field)) { 56 $dbman->add_field($table, $field); 57 } 58 59 // Quiz savepoint reached. 60 upgrade_mod_savepoint(true, 2020061501, 'quiz'); 61 } 62 63 if ($oldversion < 2021052503) { 64 $table = new xmldb_table('quiz'); 65 $field = new xmldb_field('completionpass'); 66 67 if ($dbman->field_exists($table, $field)) { 68 $sql = "SELECT q.id, m.id as quizid " . 69 "FROM {quiz} q " . 70 "INNER JOIN {course_modules} cm ON cm.instance = q.id " . 71 "INNER JOIN {modules} m ON m.id = cm.module " . 72 "WHERE m.name = :name AND q.completionpass = :completionpass"; 73 74 /** @var moodle_recordset $records */ 75 $records = $DB->get_recordset_sql($sql, ['name' => 'quiz', 'completionpass' => 1], 0, 1000); 76 while ($records->valid()) { 77 $quizmodule = null; 78 foreach ($records as $record) { 79 $ids[] = $record->id; 80 $quizmodule = $record->quizid; 81 } 82 83 if ($ids) { 84 list($insql, $params) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED); 85 $DB->set_field_select('course_modules', 'completionpassgrade', 1, 86 "module = :quiz AND instance $insql", $params + ['quiz' => $quizmodule]); 87 88 // Reset the value so it doesn't get picked on the next run. The field will be dropped later. 89 $DB->set_field_select('quiz', 'completionpass', 0, "id $insql", $params); 90 91 // Get the next batch of records. 92 $records = $DB->get_recordset_sql($sql, ['name' => 'quiz', 'completionpass' => 1], 0, 1000); 93 } 94 } 95 $records->close(); 96 97 // We have completed our checks. Drop the field. 98 if ($dbman->field_exists($table, $field)) { 99 $dbman->drop_field($table, $field); 100 } 101 } 102 103 upgrade_mod_savepoint(true, 2021052503, 'quiz'); 104 } 105 106 if ($oldversion < 2021101900) { 107 108 // Define field gradednotificationsenttime to be added to quiz_attempts. 109 $table = new xmldb_table('quiz_attempts'); 110 $field = new xmldb_field('gradednotificationsenttime', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'sumgrades'); 111 112 // Conditionally launch add field gradednotificationsenttime. 113 if (!$dbman->field_exists($table, $field)) { 114 $dbman->add_field($table, $field); 115 116 $DB->execute('UPDATE {quiz_attempts} SET gradednotificationsenttime = timefinish'); 117 } 118 119 // Quiz savepoint reached. 120 upgrade_mod_savepoint(true, 2021101900, 'quiz'); 121 } 122 123 if ($oldversion < 2022020300) { 124 // Define table quiz_slot_tags to be dropped. 125 $table = new xmldb_table('quiz_slot_tags'); 126 127 // Conditionally launch drop table for quiz_slot_tags. 128 if ($dbman->table_exists($table)) { 129 $dbman->drop_table($table); 130 } 131 132 // Define fields to be dropped from quiz_slots. 133 $table = new xmldb_table('quiz_slots'); 134 135 // Define key questionid (foreign) to be dropped form quiz_slots. 136 $key = new xmldb_key('questionid', XMLDB_KEY_FOREIGN, ['questionid'], 'question', ['id']); 137 138 // Launch drop key questionid. 139 $dbman->drop_key($table, $key); 140 141 // Define key questioncategoryid (foreign) to be dropped form quiz_slots. 142 $key = new xmldb_key('questioncategoryid', XMLDB_KEY_FOREIGN, ['questioncategoryid'], 'question_categories', ['id']); 143 144 // Launch drop key questioncategoryid. 145 $dbman->drop_key($table, $key); 146 147 $field = new xmldb_field('questionid'); 148 // Conditionally launch drop field questionid. 149 if ($dbman->field_exists($table, $field)) { 150 $dbman->drop_field($table, $field); 151 } 152 153 $field = new xmldb_field('questioncategoryid'); 154 // Conditionally launch drop field questioncategoryid. 155 if ($dbman->field_exists($table, $field)) { 156 $dbman->drop_field($table, $field); 157 } 158 159 $field = new xmldb_field('includingsubcategories'); 160 // Conditionally launch drop field includingsubcategories. 161 if ($dbman->field_exists($table, $field)) { 162 $dbman->drop_field($table, $field); 163 } 164 165 // Quiz savepoint reached. 166 upgrade_mod_savepoint(true, 2022020300, 'quiz'); 167 } 168 169 // Automatically generated Moodle v4.0.0 release upgrade line. 170 // Put any upgrade step following this. 171 172 return true; 173 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body