MDL-47960 behat: Fixed message node navigation
[moodle.git] / mod / forum / db / upgrade.php
CommitLineData
1adbd2c3 1<?php
b8a342d7 2
8f685009 3// This file is part of Moodle - http://moodle.org/
b8a342d7 4//
8f685009
SH
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
b8a342d7 9//
8f685009
SH
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
b8a342d7 14//
8f685009
SH
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * This file keeps track of upgrades to
20 * the forum module
21 *
22 * Sometimes, changes between versions involve
23 * alterations to database structures and other
24 * major things that may break installations.
25 *
26 * The upgrade function in this file will attempt
27 * to perform all the necessary actions to upgrade
2e0406a5 28 * your older installation to the current version.
8f685009
SH
29 *
30 * If there's something it cannot do itself, it
31 * will tell you what you need to do.
32 *
33 * The commands in here will all be database-neutral,
34 * using the methods of database_manager class
35 *
36 * Please do not forget to use upgrade_set_timeout()
37 * before any action that may take longer time to finish.
38 *
01030f1b 39 * @package mod_forum
8f685009
SH
40 * @copyright 2003 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
41 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42 */
b8a342d7 43
775f811a 44function xmldb_forum_upgrade($oldversion) {
9146b979 45 global $CFG, $DB, $OUTPUT;
b8a342d7 46
506522d5 47 $dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes.
b8a342d7 48
506522d5
FM
49 // Moodle v2.2.0 release upgrade line.
50 // Put any upgrade step following this.
c5a8abfe 51
506522d5
FM
52 // Moodle v2.3.0 release upgrade line.
53 // Put any upgrade step following this.
46f2a936 54
506522d5
FM
55 // Moodle v2.4.0 release upgrade line.
56 // Put any upgrade step following this.
99c3c503 57
506522d5 58 if ($oldversion < 2013020500) {
99c3c503 59
506522d5
FM
60 // Define field displaywordcount to be added to forum.
61 $table = new xmldb_table('forum');
62 $field = new xmldb_field('displaywordcount', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'completionposts');
6b9dfe73 63
506522d5
FM
64 // Conditionally launch add field displaywordcount.
65 if (!$dbman->field_exists($table, $field)) {
66 $dbman->add_field($table, $field);
67 }
68
69 // Forum savepoint reached.
70 upgrade_mod_savepoint(true, 2013020500, 'forum');
71 }
6b9dfe73 72
afd5e85c
RT
73 // Forcefully assign mod/forum:allowforcesubscribe to frontpage role, as we missed that when
74 // capability was introduced.
6af8e417 75 if ($oldversion < 2013021200) {
afd5e85c
RT
76 // If capability mod/forum:allowforcesubscribe is defined then set it for frontpage role.
77 if (get_capability_info('mod/forum:allowforcesubscribe')) {
78 assign_legacy_capabilities('mod/forum:allowforcesubscribe', array('frontpage' => CAP_ALLOW));
79 }
80 // Forum savepoint reached.
6af8e417 81 upgrade_mod_savepoint(true, 2013021200, 'forum');
afd5e85c 82 }
6af8e417 83
c9e54743
EL
84
85 // Moodle v2.5.0 release upgrade line.
86 // Put any upgrade step following this.
8e08c731
AN
87 if ($oldversion < 2013071000) {
88 // Define table forum_digests to be created.
89 $table = new xmldb_table('forum_digests');
90
91 // Adding fields to table forum_digests.
92 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
93 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
94 $table->add_field('forum', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
95 $table->add_field('maildigest', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '-1');
96
97 // Adding keys to table forum_digests.
98 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
99 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
100 $table->add_key('forum', XMLDB_KEY_FOREIGN, array('forum'), 'forum', array('id'));
101 $table->add_key('forumdigest', XMLDB_KEY_UNIQUE, array('forum', 'userid', 'maildigest'));
102
103 // Conditionally launch create table for forum_digests.
104 if (!$dbman->table_exists($table)) {
105 $dbman->create_table($table);
106 }
c9e54743 107
8e08c731
AN
108 // Forum savepoint reached.
109 upgrade_mod_savepoint(true, 2013071000, 'forum');
110 }
c9e54743 111
47578dbf
DW
112 // Moodle v2.6.0 release upgrade line.
113 // Put any upgrade step following this.
114
f5c6e8db
MG
115 if ($oldversion < 2014040400) {
116
117 // Define index userid-postid (not unique) to be dropped form forum_read.
118 $table = new xmldb_table('forum_read');
119 $index = new xmldb_index('userid-postid', XMLDB_INDEX_NOTUNIQUE, array('userid', 'postid'));
120
121 // Conditionally launch drop index userid-postid.
122 if ($dbman->index_exists($table, $index)) {
123 $dbman->drop_index($table, $index);
124 }
125
126
127 // Define index postid-userid (not unique) to be added to forum_read.
128 $index = new xmldb_index('postid-userid', XMLDB_INDEX_NOTUNIQUE, array('postid', 'userid'));
129
130 // Conditionally launch add index postid-userid.
131 if (!$dbman->index_exists($table, $index)) {
132 $dbman->add_index($table, $index);
133 }
134
135 // Forum savepoint reached.
136 upgrade_mod_savepoint(true, 2014040400, 'forum');
137 }
138
f94891cc
EL
139 // Moodle v2.7.0 release upgrade line.
140 // Put any upgrade step following this.
141
7a98bbab
KW
142 if ($oldversion < 2014051201) {
143
144 // Incorrect values that need to be replaced.
145 $replacements = array(
146 11 => 20,
147 12 => 50,
148 13 => 100
149 );
150
151 // Run the replacements.
152 foreach ($replacements as $old => $new) {
153 $DB->set_field('forum', 'maxattachments', $new, array('maxattachments' => $old));
154 }
155
156 // Forum savepoint reached.
157 upgrade_mod_savepoint(true, 2014051201, 'forum');
158 }
159
ba774b42
DP
160 if ($oldversion < 2014081500) {
161
162 // Define index course (not unique) to be added to forum_discussions.
163 $table = new xmldb_table('forum_discussions');
164 $index = new xmldb_index('course', XMLDB_INDEX_NOTUNIQUE, array('course'));
165
166 // Conditionally launch add index course.
167 if (!$dbman->index_exists($table, $index)) {
168 $dbman->add_index($table, $index);
169 }
170
171 // Forum savepoint reached.
172 upgrade_mod_savepoint(true, 2014081500, 'forum');
173 }
174
175 if ($oldversion < 2014081900) {
361a41d3
AN
176
177 // Define table forum_discussion_subs to be created.
178 $table = new xmldb_table('forum_discussion_subs');
179
180 // Adding fields to table forum_discussion_subs.
181 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
182 $table->add_field('forum', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
183 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
184 $table->add_field('discussion', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
185 $table->add_field('preference', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1');
186
187 // Adding keys to table forum_discussion_subs.
188 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
189 $table->add_key('forum', XMLDB_KEY_FOREIGN, array('forum'), 'forum', array('id'));
190 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
191 $table->add_key('discussion', XMLDB_KEY_FOREIGN, array('discussion'), 'forum_discussions', array('id'));
192 $table->add_key('user_discussions', XMLDB_KEY_UNIQUE, array('userid', 'discussion'));
193
194 // Conditionally launch create table for forum_discussion_subs.
195 if (!$dbman->table_exists($table)) {
196 $dbman->create_table($table);
197 }
198
199 // Forum savepoint reached.
ba774b42 200 upgrade_mod_savepoint(true, 2014081900, 'forum');
73de21ff
MG
201 }
202
a4cdd6d2 203 return true;
b8a342d7 204}