MDL-62698 quiz_overview: new index should not be unique
[moodle.git] / mod / quiz / report / overview / db / upgrade.php
CommitLineData
aeb15530 1<?php
e24ee794
TH
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 * Quiz overview report upgrade script.
19 *
8d76124c
TH
20 * @package quiz_overview
21 * @copyright 2008 Jamie Pratt
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
e24ee794
TH
23 */
24
a17b297d
TH
25defined('MOODLE_INTERNAL') || die();
26
e24ee794
TH
27/**
28 * Quiz overview report upgrade function.
29 * @param number $oldversion
a17b297d
TH
30 */
31function xmldb_quiz_overview_upgrade($oldversion) {
d9b80a5e
TH
32 global $DB;
33
34 $dbman = $DB->get_manager();
f94891cc 35
75c57a08
EL
36 // Automatically generated Moodle v3.2.0 release upgrade line.
37 // Put any upgrade step following this.
38
5e272283
EL
39 // Automatically generated Moodle v3.3.0 release upgrade line.
40 // Put any upgrade step following this.
41
6499085f
EL
42 // Automatically generated Moodle v3.4.0 release upgrade line.
43 // Put any upgrade step following this.
44
bc6687ba
TH
45 // Automatically generated Moodle v3.5.0 release upgrade line.
46 // Put any upgrade step following this.
47
48 // Upgrade 2018021800 (now removed) incorrectly added this key
49 // with a unique constraint, which breaks things because those
50 // columns are not, in fact, unique. So drop (if it exists) then recreate.
51 if ($oldversion < 2018061800) {
52
53 // Define key questionusageid-slot (foreign) to be dropped form quiz_overview_regrades.
54 $table = new xmldb_table('quiz_overview_regrades');
55
56 // There is no key_exists, so test the equivalent index.
57 $oldindex = new xmldb_index('questionusageid-slot', XMLDB_KEY_UNIQUE, array('questionusageid', 'slot'));
58
59 // Launch drop key questionusageid-slot.
60 if ($dbman->index_exists($table, $oldindex)) {
61 $key = new xmldb_key('questionusageid-slot', XMLDB_KEY_FOREIGN, array('questionusageid', 'slot'), 'question_attempts', array('questionusageid', 'slot'));
62 $dbman->drop_key($table, $key);
63 }
d9b80a5e 64
bc6687ba
TH
65 // Overview savepoint reached.
66 upgrade_plugin_savepoint(true, 2018061800, 'quiz', 'overview');
67 }
68
69 if ($oldversion < 2018061801) {
70
71 // Define key questionusageid-slot (foreign) to be added to quiz_overview_regrades.
d9b80a5e 72 $table = new xmldb_table('quiz_overview_regrades');
bc6687ba 73 $key = new xmldb_key('questionusageid-slot', XMLDB_KEY_FOREIGN, array('questionusageid', 'slot'), 'question_attempts', array('questionusageid', 'slot'));
d9b80a5e
TH
74
75 // Launch add key questionusageid-slot.
76 $dbman->add_key($table, $key);
77
78 // Overview savepoint reached.
bc6687ba 79 upgrade_plugin_savepoint(true, 2018061801, 'quiz', 'overview');
d9b80a5e
TH
80 }
81
e24ee794
TH
82 return true;
83}