MDL-77564 Quiz display options: Hide or show the grade information
[moodle.git] / mod / quiz / db / upgrade.php
blobdf41e5e297b616e79e2ef10d38666a7db4e10d2f
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_quiz
21 * @copyright 2006 Eloy Lafuente (stronk7)
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 /**
27 * Quiz module upgrade function.
28 * @param string $oldversion the version we are upgrading from.
30 function xmldb_quiz_upgrade($oldversion) {
31 global $CFG, $DB;
32 $dbman = $DB->get_manager();
34 // Automatically generated Moodle v3.9.0 release upgrade line.
35 // Put any upgrade step following this.
37 if ($oldversion < 2020061501) {
39 // Define field completionminattempts to be added to quiz.
40 $table = new xmldb_table('quiz');
41 $field = new xmldb_field('completionminattempts', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0',
42 'completionpass');
44 // Conditionally launch add field completionminattempts.
45 if (!$dbman->field_exists($table, $field)) {
46 $dbman->add_field($table, $field);
49 // Quiz savepoint reached.
50 upgrade_mod_savepoint(true, 2020061501, 'quiz');
53 if ($oldversion < 2021052503) {
54 $table = new xmldb_table('quiz');
55 $field = new xmldb_field('completionpass');
57 if ($dbman->field_exists($table, $field)) {
58 $sql = "SELECT q.id, m.id as quizid " .
59 "FROM {quiz} q " .
60 "INNER JOIN {course_modules} cm ON cm.instance = q.id " .
61 "INNER JOIN {modules} m ON m.id = cm.module " .
62 "WHERE m.name = :name AND q.completionpass = :completionpass";
64 /** @var moodle_recordset $records */
65 $records = $DB->get_recordset_sql($sql, ['name' => 'quiz', 'completionpass' => 1], 0, 1000);
66 while ($records->valid()) {
67 $quizmodule = null;
68 foreach ($records as $record) {
69 $ids[] = $record->id;
70 $quizmodule = $record->quizid;
73 if ($ids) {
74 list($insql, $params) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED);
75 $DB->set_field_select('course_modules', 'completionpassgrade', 1,
76 "module = :quiz AND instance $insql", $params + ['quiz' => $quizmodule]);
78 // Reset the value so it doesn't get picked on the next run. The field will be dropped later.
79 $DB->set_field_select('quiz', 'completionpass', 0, "id $insql", $params);
81 // Get the next batch of records.
82 $records = $DB->get_recordset_sql($sql, ['name' => 'quiz', 'completionpass' => 1], 0, 1000);
85 $records->close();
87 // We have completed our checks. Drop the field.
88 if ($dbman->field_exists($table, $field)) {
89 $dbman->drop_field($table, $field);
93 upgrade_mod_savepoint(true, 2021052503, 'quiz');
96 if ($oldversion < 2021101900) {
98 // Define field gradednotificationsenttime to be added to quiz_attempts.
99 $table = new xmldb_table('quiz_attempts');
100 $field = new xmldb_field('gradednotificationsenttime', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'sumgrades');
102 // Conditionally launch add field gradednotificationsenttime.
103 if (!$dbman->field_exists($table, $field)) {
104 $dbman->add_field($table, $field);
106 $DB->execute('UPDATE {quiz_attempts} SET gradednotificationsenttime = timefinish');
109 // Quiz savepoint reached.
110 upgrade_mod_savepoint(true, 2021101900, 'quiz');
113 if ($oldversion < 2022020300) {
114 // Define table quiz_slot_tags to be dropped.
115 $table = new xmldb_table('quiz_slot_tags');
117 // Conditionally launch drop table for quiz_slot_tags.
118 if ($dbman->table_exists($table)) {
119 $dbman->drop_table($table);
122 // Define fields to be dropped from quiz_slots.
123 $table = new xmldb_table('quiz_slots');
125 // Define key questionid (foreign) to be dropped form quiz_slots.
126 $key = new xmldb_key('questionid', XMLDB_KEY_FOREIGN, ['questionid'], 'question', ['id']);
128 // Launch drop key questionid.
129 $dbman->drop_key($table, $key);
131 // Define key questioncategoryid (foreign) to be dropped form quiz_slots.
132 $key = new xmldb_key('questioncategoryid', XMLDB_KEY_FOREIGN, ['questioncategoryid'], 'question_categories', ['id']);
134 // Launch drop key questioncategoryid.
135 $dbman->drop_key($table, $key);
137 $field = new xmldb_field('questionid');
138 // Conditionally launch drop field questionid.
139 if ($dbman->field_exists($table, $field)) {
140 $dbman->drop_field($table, $field);
143 $field = new xmldb_field('questioncategoryid');
144 // Conditionally launch drop field questioncategoryid.
145 if ($dbman->field_exists($table, $field)) {
146 $dbman->drop_field($table, $field);
149 $field = new xmldb_field('includingsubcategories');
150 // Conditionally launch drop field includingsubcategories.
151 if ($dbman->field_exists($table, $field)) {
152 $dbman->drop_field($table, $field);
155 // Quiz savepoint reached.
156 upgrade_mod_savepoint(true, 2022020300, 'quiz');
159 // Automatically generated Moodle v4.0.0 release upgrade line.
160 // Put any upgrade step following this.
162 // Automatically generated Moodle v4.1.0 release upgrade line.
163 // Put any upgrade step following this.
165 if ($oldversion < 2022120500) {
166 // Define field displaynumber to be added to quiz_slots.
167 $table = new xmldb_table('quiz_slots');
168 $field = new xmldb_field('displaynumber', XMLDB_TYPE_CHAR, '16', null, null, null, null, 'page');
170 // Conditionally launch add field displaynumber.
171 if (!$dbman->field_exists($table, $field)) {
172 $dbman->add_field($table, $field);
175 // Quiz savepoint reached.
176 upgrade_mod_savepoint(true, 2022120500, 'quiz');
179 // Automatically generated Moodle v4.2.0 release upgrade line.
180 // Put any upgrade step following this.
182 if ($oldversion < 2023042401) {
184 // Define field reviewmaxmarks to be added to quiz.
185 $table = new xmldb_table('quiz');
186 $field = new xmldb_field('reviewmaxmarks', XMLDB_TYPE_INTEGER, '6', null, XMLDB_NOTNULL, null, '0', 'reviewcorrectness');
188 // Conditionally launch add field reviewmaxmarks.
189 if (!$dbman->field_exists($table, $field)) {
190 $dbman->add_field($table, $field);
193 // Quiz savepoint reached.
194 upgrade_mod_savepoint(true, 2023042401, 'quiz');
197 return true;