weekly release 3.4dev
[moodle.git] / lib / db / upgrade.php
CommitLineData
5b4a78e2 1<?php
5b4a78e2 2// This file is part of Moodle - http://moodle.org/
4e423cbf 3//
5b4a78e2
PS
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.
4e423cbf 8//
5b4a78e2
PS
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.
4e423cbf 13//
5b4a78e2
PS
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 * This file keeps track of upgrades to Moodle.
19 *
20 * Sometimes, changes between versions involve
21 * alterations to database structures and other
22 * major things that may break installations.
23 *
24 * The upgrade function in this file will attempt
25 * to perform all the necessary actions to upgrade
26 * your older installation to the current version.
27 *
28 * If there's something it cannot do itself, it
29 * will tell you what you need to do.
30 *
31 * The commands in here will all be database-neutral,
32 * using the methods of database_manager class
33 *
34 * Please do not forget to use upgrade_set_timeout()
35 * before any action that may take longer time to finish.
36 *
39b90b51
EL
37 * @package core_install
38 * @category upgrade
39 * @copyright 2006 onwards Martin Dougiamas http://dougiamas.com
40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
5b4a78e2
PS
41 */
42
43defined('MOODLE_INTERNAL') || die();
4e423cbf 44
3406acde 45/**
39b90b51
EL
46 * Main upgrade tasks to be executed on Moodle version bump
47 *
48 * This function is automatically executed after one bump in the Moodle core
f9488a6f 49 * version is detected. It's in charge of performing the required tasks
39b90b51
EL
50 * to raise core from the previous version to the next one.
51 *
52 * It's a collection of ordered blocks of code, named "upgrade steps",
f9488a6f 53 * each one performing one isolated (from the rest of steps) task. Usually
39b90b51
EL
54 * tasks involve creating new DB objects or performing manipulation of the
55 * information for cleanup/fixup purposes.
56 *
57 * Each upgrade step has a fixed structure, that can be summarised as follows:
58 *
59 * if ($oldversion < XXXXXXXXXX.XX) {
f9488a6f 60 * // Explanation of the update step, linking to issue in the Tracker if necessary
39b90b51
EL
61 * upgrade_set_timeout(XX); // Optional for big tasks
62 * // Code to execute goes here, usually the XMLDB Editor will
63 * // help you here. See {@link http://docs.moodle.org/dev/XMLDB_editor}.
64 * upgrade_main_savepoint(true, XXXXXXXXXX.XX);
65 * }
66 *
67 * All plugins within Moodle (modules, blocks, reports...) support the existence of
68 * their own upgrade.php file, using the "Frankenstyle" component name as
69 * defined at {@link http://docs.moodle.org/dev/Frankenstyle}, for example:
70 * - {@link xmldb_page_upgrade($oldversion)}. (modules don't require the plugintype ("mod_") to be used.
71 * - {@link xmldb_auth_manual_upgrade($oldversion)}.
72 * - {@link xmldb_workshopform_accumulative_upgrade($oldversion)}.
73 * - ....
74 *
75 * In order to keep the contents of this file reduced, it's allowed to create some helper
76 * functions to be used here in the {@link upgradelib.php} file at the same directory. Note
f9488a6f 77 * that such a file must be manually included from upgrade.php, and there are some restrictions
39b90b51
EL
78 * about what can be used within it.
79 *
80 * For more information, take a look to the documentation available:
81 * - Data definition API: {@link http://docs.moodle.org/dev/Data_definition_API}
82 * - Upgrade API: {@link http://docs.moodle.org/dev/Upgrade_API}
3406acde 83 *
3406acde 84 * @param int $oldversion
5b4a78e2 85 * @return bool always true
3406acde 86 */
775f811a 87function xmldb_main_upgrade($oldversion) {
e8c82aac 88 global $CFG, $DB;
4e423cbf 89
e8c82aac 90 require_once($CFG->libdir.'/db/upgradelib.php'); // Core Upgrade-related functions.
13a0d3d3 91
e8c82aac 92 $dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes.
f33e1ed4 93
e8c82aac
EL
94 // Always keep this upgrade step with version being the minimum
95 // allowed version to upgrade from (v2.7.0 right now).
96 if ($oldversion < 2014051200) {
97 // Just in case somebody hacks upgrade scripts or env, we really can not continue.
98 echo("You need to upgrade to 2.7.x or higher first!\n");
5c79b8ed 99 exit(1);
e8c82aac
EL
100 // Note this savepoint is 100% unreachable, but needed to pass the upgrade checks.
101 upgrade_main_savepoint(true, 2014051200);
5c79b8ed
PS
102 }
103
d277c441 104 // MDL-32543 Make sure that the log table has correct length for action and url fields.
9febfdc5 105 if ($oldversion < 2014051200.02) {
d277c441
DNA
106
107 $table = new xmldb_table('log');
108
109 $columns = $DB->get_columns('log');
110 if ($columns['action']->max_length < 40) {
111 $index1 = new xmldb_index('course-module-action', XMLDB_INDEX_NOTUNIQUE, array('course', 'module', 'action'));
112 if ($dbman->index_exists($table, $index1)) {
113 $dbman->drop_index($table, $index1);
114 }
115 $index2 = new xmldb_index('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
116 if ($dbman->index_exists($table, $index2)) {
117 $dbman->drop_index($table, $index2);
118 }
119 $field = new xmldb_field('action', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, 'cmid');
120 $dbman->change_field_precision($table, $field);
121 $dbman->add_index($table, $index1);
122 $dbman->add_index($table, $index2);
123 }
124
125 if ($columns['url']->max_length < 100) {
126 $field = new xmldb_field('url', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'action');
127 $dbman->change_field_precision($table, $field);
128 }
129
9febfdc5 130 upgrade_main_savepoint(true, 2014051200.02);
d277c441
DNA
131 }
132
1bce3a70
RT
133 if ($oldversion < 2014060300.00) {
134 $gspath = get_config('assignfeedback_editpdf', 'gspath');
135 if ($gspath !== false) {
136 set_config('pathtogs', $gspath);
137 unset_config('gspath', 'assignfeedback_editpdf');
138 }
139 upgrade_main_savepoint(true, 2014060300.00);
140 }
141
b5725a97
JF
142 if ($oldversion < 2014061000.00) {
143 // Fixing possible wrong MIME type for Publisher files.
144 $filetypes = array('%.pub'=>'application/x-mspublisher');
145 upgrade_mimetypes($filetypes);
146 upgrade_main_savepoint(true, 2014061000.00);
147 }
148
1170df12 149 if ($oldversion < 2014062600.01) {
e3e4ea97
MN
150 // We only want to delete DragMath if the directory no longer exists. If the directory
151 // is present then it means it has been restored, so do not perform the uninstall.
152 if (!check_dir_exists($CFG->libdir . '/editor/tinymce/plugins/dragmath', false)) {
153 // Purge DragMath plugin which is incompatible with GNU GPL license.
154 unset_all_config_for_plugin('tinymce_dragmath');
155 }
1170df12
PS
156
157 // Main savepoint reached.
158 upgrade_main_savepoint(true, 2014062600.01);
159 }
160
463882d0 161 // Switch the order of the fields in the files_reference index, to improve the performance of search_references.
9b192823 162 if ($oldversion < 2014070100.00) {
463882d0
DS
163 $table = new xmldb_table('files_reference');
164 $index = new xmldb_index('uq_external_file', XMLDB_INDEX_UNIQUE, array('repositoryid', 'referencehash'));
165 if ($dbman->index_exists($table, $index)) {
166 $dbman->drop_index($table, $index);
167 }
9b192823 168 upgrade_main_savepoint(true, 2014070100.00);
463882d0 169 }
9b192823
DP
170
171 if ($oldversion < 2014070101.00) {
463882d0
DS
172 $table = new xmldb_table('files_reference');
173 $index = new xmldb_index('uq_external_file', XMLDB_INDEX_UNIQUE, array('referencehash', 'repositoryid'));
174 if (!$dbman->index_exists($table, $index)) {
175 $dbman->add_index($table, $index);
176 }
9b192823 177 upgrade_main_savepoint(true, 2014070101.00);
463882d0
DS
178 }
179
a1bacaf1
JL
180 if ($oldversion < 2014072400.01) {
181 $table = new xmldb_table('user_devices');
182 $oldindex = new xmldb_index('pushid-platform', XMLDB_KEY_UNIQUE, array('pushid', 'platform'));
183 if ($dbman->index_exists($table, $oldindex)) {
184 $key = new xmldb_key('pushid-platform', XMLDB_KEY_UNIQUE, array('pushid', 'platform'));
185 $dbman->drop_key($table, $key);
186 }
187 upgrade_main_savepoint(true, 2014072400.01);
188 }
189
bbea9369
TH
190 if ($oldversion < 2014080801.00) {
191
192 // Define index behaviour (not unique) to be added to question_attempts.
193 $table = new xmldb_table('question_attempts');
194 $index = new xmldb_index('behaviour', XMLDB_INDEX_NOTUNIQUE, array('behaviour'));
195
196 // Conditionally launch add index behaviour.
197 if (!$dbman->index_exists($table, $index)) {
198 $dbman->add_index($table, $index);
199 }
200
201 // Main savepoint reached.
202 upgrade_main_savepoint(true, 2014080801.00);
203 }
204
cfa5bd1f
MS
205 if ($oldversion < 2014082900.01) {
206 // Fixing possible wrong MIME type for 7-zip and Rar files.
207 $filetypes = array(
208 '%.7z' => 'application/x-7z-compressed',
209 '%.rar' => 'application/x-rar-compressed');
210 upgrade_mimetypes($filetypes);
211 upgrade_main_savepoint(true, 2014082900.01);
212 }
213
061e6b28 214 if ($oldversion < 2014082900.02) {
215 // Replace groupmembersonly usage with new availability system.
216 $transaction = $DB->start_delegated_transaction();
217 if ($CFG->enablegroupmembersonly) {
218 // If it isn't already enabled, we need to enable availability.
219 if (!$CFG->enableavailability) {
220 set_config('enableavailability', 1);
221 }
222
223 // Count all course-modules with groupmembersonly set (for progress
224 // bar).
225 $total = $DB->count_records('course_modules', array('groupmembersonly' => 1));
226 $pbar = new progress_bar('upgradegroupmembersonly', 500, true);
227
228 // Get all these course-modules, one at a time.
229 $rs = $DB->get_recordset('course_modules', array('groupmembersonly' => 1),
230 'course, id');
231 $i = 0;
232 foreach ($rs as $cm) {
233 // Calculate and set new availability value.
234 $availability = upgrade_group_members_only($cm->groupingid, $cm->availability);
235 $DB->set_field('course_modules', 'availability', $availability,
236 array('id' => $cm->id));
237
238 // Update progress.
239 $i++;
240 $pbar->update($i, $total, "Upgrading groupmembersonly settings - $i/$total.");
241 }
242 $rs->close();
243 }
244
245 // Define field groupmembersonly to be dropped from course_modules.
246 $table = new xmldb_table('course_modules');
247 $field = new xmldb_field('groupmembersonly');
248
249 // Conditionally launch drop field groupmembersonly.
250 if ($dbman->field_exists($table, $field)) {
251 $dbman->drop_field($table, $field);
252 }
253
254 // Unset old config variable.
255 unset_config('enablegroupmembersonly');
256 $transaction->allow_commit();
257
258 upgrade_main_savepoint(true, 2014082900.02);
259 }
260
db34f8cb 261 if ($oldversion < 2014100100.00) {
6c0bfb14
AN
262
263 // Define table messageinbound_handlers to be created.
264 $table = new xmldb_table('messageinbound_handlers');
265
266 // Adding fields to table messageinbound_handlers.
267 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
268 $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
269 $table->add_field('classname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
270 $table->add_field('defaultexpiration', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '86400');
271 $table->add_field('validateaddress', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1');
272 $table->add_field('enabled', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
273
274 // Adding keys to table messageinbound_handlers.
275 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
276 $table->add_key('classname', XMLDB_KEY_UNIQUE, array('classname'));
277
278 // Conditionally launch create table for messageinbound_handlers.
279 if (!$dbman->table_exists($table)) {
280 $dbman->create_table($table);
281 }
282
283 // Define table messageinbound_datakeys to be created.
284 $table = new xmldb_table('messageinbound_datakeys');
285
286 // Adding fields to table messageinbound_datakeys.
287 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
288 $table->add_field('handler', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
289 $table->add_field('datavalue', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
290 $table->add_field('datakey', XMLDB_TYPE_CHAR, '64', null, null, null, null);
291 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
292 $table->add_field('expires', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
293
294 // Adding keys to table messageinbound_datakeys.
295 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
296 $table->add_key('handler_datavalue', XMLDB_KEY_UNIQUE, array('handler', 'datavalue'));
297 $table->add_key('handler', XMLDB_KEY_FOREIGN, array('handler'), 'messageinbound_handlers', array('id'));
298
299 // Conditionally launch create table for messageinbound_datakeys.
300 if (!$dbman->table_exists($table)) {
301 $dbman->create_table($table);
302 }
303
304 // Main savepoint reached.
db34f8cb 305 upgrade_main_savepoint(true, 2014100100.00);
6c0bfb14
AN
306 }
307
f5bacd65 308 if ($oldversion < 2014100600.01) {
a1740d7b
DW
309 // Define field aggregationstatus to be added to grade_grades.
310 $table = new xmldb_table('grade_grades');
311 $field = new xmldb_field('aggregationstatus', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, 'unknown', 'timemodified');
312
313 // Conditionally launch add field aggregationstatus.
314 if (!$dbman->field_exists($table, $field)) {
315 $dbman->add_field($table, $field);
316 }
317
318 $field = new xmldb_field('aggregationweight', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, 'aggregationstatus');
319
320 // Conditionally launch add field aggregationweight.
321 if (!$dbman->field_exists($table, $field)) {
322 $dbman->add_field($table, $field);
323 }
324
677bc073
JO
325 // Define field aggregationcoef2 to be added to grade_items.
326 $table = new xmldb_table('grade_items');
dcfc196a 327 $field = new xmldb_field('aggregationcoef2', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'aggregationcoef');
677bc073
JO
328
329 // Conditionally launch add field aggregationcoef2.
330 if (!$dbman->field_exists($table, $field)) {
331 $dbman->add_field($table, $field);
332 }
333
45da5361 334 $field = new xmldb_field('weightoverride', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'needsupdate');
dcfc196a
AG
335
336 // Conditionally launch add field weightoverride.
45da5361
AD
337 if (!$dbman->field_exists($table, $field)) {
338 $dbman->add_field($table, $field);
339 }
340
dcfc196a 341 // Main savepoint reached.
f5bacd65 342 upgrade_main_savepoint(true, 2014100600.01);
45da5361 343 }
677bc073 344
f5bacd65 345 if ($oldversion < 2014100600.02) {
e8e1d0a3
FM
346
347 // Define field aggregationcoef2 to be added to grade_items_history.
348 $table = new xmldb_table('grade_items_history');
349 $field = new xmldb_field('aggregationcoef2', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'aggregationcoef');
350
351 // Conditionally launch add field aggregationcoef2.
352 if (!$dbman->field_exists($table, $field)) {
353 $dbman->add_field($table, $field);
354 }
355
356 // Main savepoint reached.
f5bacd65 357 upgrade_main_savepoint(true, 2014100600.02);
e8e1d0a3
FM
358 }
359
f5bacd65 360 if ($oldversion < 2014100600.03) {
e8e1d0a3
FM
361
362 // Define field weightoverride to be added to grade_items_history.
363 $table = new xmldb_table('grade_items_history');
364 $field = new xmldb_field('weightoverride', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'decimals');
365
366 // Conditionally launch add field weightoverride.
367 if (!$dbman->field_exists($table, $field)) {
368 $dbman->add_field($table, $field);
369 }
370
371 // Main savepoint reached.
f5bacd65 372 upgrade_main_savepoint(true, 2014100600.03);
e8e1d0a3 373 }
f5bacd65 374 if ($oldversion < 2014100600.04) {
a9937aec
DW
375 // Set flags so we can display a notice on all courses that might
376 // be affected by the uprade to natural aggregation.
377 if (!get_config('grades_sumofgrades_upgrade_flagged', 'core')) {
378 // 13 == SUM_OF_GRADES.
379 $sql = 'SELECT DISTINCT courseid
380 FROM {grade_categories}
381 WHERE aggregation = ?';
382 $courses = $DB->get_records_sql($sql, array(13));
383
384 foreach ($courses as $course) {
385 set_config('show_sumofgrades_upgrade_' . $course->courseid, 1);
7970c217
AG
386 // Set each of the grade items to needing an update so that when the user visits the grade reports the
387 // figures will be updated.
388 $DB->set_field('grade_items', 'needsupdate', 1, array('courseid' => $course->courseid));
a9937aec
DW
389 }
390
391 set_config('grades_sumofgrades_upgrade_flagged', 1);
392 }
393
394 // Main savepoint reached.
f5bacd65 395 upgrade_main_savepoint(true, 2014100600.04);
a9937aec 396 }
e8e1d0a3 397
94cdabcd 398 if ($oldversion < 2014100700.00) {
77c0a68d
AN
399
400 // Define table messageinbound_messagelist to be created.
401 $table = new xmldb_table('messageinbound_messagelist');
402
403 // Adding fields to table messageinbound_messagelist.
404 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
405 $table->add_field('messageid', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
406 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
407 $table->add_field('address', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
408 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
409
410 // Adding keys to table messageinbound_messagelist.
411 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
412 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
413
414 // Conditionally launch create table for messageinbound_messagelist.
415 if (!$dbman->table_exists($table)) {
416 $dbman->create_table($table);
417 }
418
419 // Main savepoint reached.
94cdabcd 420 upgrade_main_savepoint(true, 2014100700.00);
77c0a68d
AN
421 }
422
4a813f39 423 if ($oldversion < 2014100700.01) {
80f98467
MG
424
425 // Define field visible to be added to cohort.
426 $table = new xmldb_table('cohort');
427 $field = new xmldb_field('visible', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'descriptionformat');
428
429 // Conditionally launch add field visible.
430 if (!$dbman->field_exists($table, $field)) {
431 $dbman->add_field($table, $field);
432 }
433
434 // Main savepoint reached.
4a813f39 435 upgrade_main_savepoint(true, 2014100700.01);
80f98467
MG
436 }
437
70b37098 438 if ($oldversion < 2014100800.00) {
a75fa4c0
TH
439 // Remove qformat_learnwise (unless it has manually been added back).
440 if (!file_exists($CFG->dirroot . '/question/format/learnwise/format.php')) {
441 unset_all_config_for_plugin('qformat_learnwise');
442 }
443
444 // Main savepoint reached.
70b37098 445 upgrade_main_savepoint(true, 2014100800.00);
a75fa4c0
TH
446 }
447
00fd3c1a
FM
448 if ($oldversion < 2014101001.00) {
449 // Some blocks added themselves to the my/ home page, but they did not declare the
450 // subpage of the default my home page. While the upgrade script has been fixed, this
451 // upgrade script will fix the data that was wrongly added.
452
453 // We only proceed if we can find the right entry from my_pages. Private => 1 refers to
454 // the constant value MY_PAGE_PRIVATE.
455 if ($systempage = $DB->get_record('my_pages', array('userid' => null, 'private' => 1))) {
456
457 // Select the blocks there could have been automatically added. showinsubcontexts is hardcoded to 0
458 // because it is possible for administrators to have forced it on the my/ page by adding it to the
459 // system directly rather than updating the default my/ page.
460 $blocks = array('course_overview', 'private_files', 'online_users', 'badges', 'calendar_month', 'calendar_upcoming');
461 list($blocksql, $blockparams) = $DB->get_in_or_equal($blocks, SQL_PARAMS_NAMED);
462 $select = "parentcontextid = :contextid
463 AND pagetypepattern = :page
464 AND showinsubcontexts = 0
465 AND subpagepattern IS NULL
466 AND blockname $blocksql";
467 $params = array(
468 'contextid' => context_system::instance()->id,
469 'page' => 'my-index'
470 );
471 $params = array_merge($params, $blockparams);
472
473 $DB->set_field_select(
474 'block_instances',
475 'subpagepattern',
476 $systempage->id,
477 $select,
478 $params
479 );
480 }
481
482 // Main savepoint reached.
483 upgrade_main_savepoint(true, 2014101001.00);
484 }
485
47d6e6a7
DW
486 if ($oldversion < 2014102000.00) {
487
488 // Define field aggregatesubcats to be dropped from grade_categories.
489 $table = new xmldb_table('grade_categories');
490 $field = new xmldb_field('aggregatesubcats');
491
492 // Conditionally launch drop field aggregatesubcats.
493 if ($dbman->field_exists($table, $field)) {
494
495 $sql = 'SELECT DISTINCT courseid
496 FROM {grade_categories}
497 WHERE aggregatesubcats = ?';
498 $courses = $DB->get_records_sql($sql, array(1));
499
500 foreach ($courses as $course) {
501 set_config('show_aggregatesubcats_upgrade_' . $course->courseid, 1);
502 // Set each of the grade items to needing an update so that when the user visits the grade reports the
503 // figures will be updated.
504 $DB->set_field('grade_items', 'needsupdate', 1, array('courseid' => $course->courseid));
505 }
506
507
508 $dbman->drop_field($table, $field);
509 }
510
511 // Main savepoint reached.
512 upgrade_main_savepoint(true, 2014102000.00);
513 }
514
219ebf9b 515 if ($oldversion < 2014110300.00) {
941de296
MG
516 // Run script restoring missing folder records for draft file areas.
517 upgrade_fix_missing_root_folders_draft();
518
519 // Main savepoint reached.
219ebf9b 520 upgrade_main_savepoint(true, 2014110300.00);
941de296
MG
521 }
522
147bae8f
EL
523 // Moodle v2.8.0 release upgrade line.
524 // Put any upgrade step following this.
525
ebea19cb
FM
526 if ($oldversion < 2014111000.00) {
527 // Coming from 2.7 or older, we need to flag the step minmaxgrade to be ignored.
528 set_config('upgrade_minmaxgradestepignored', 1);
316c560c
AG
529 // Coming from 2.7 or older, we need to flag the step for changing calculated grades to be regraded.
530 set_config('upgrade_calculatedgradeitemsonlyregrade', 1);
d8ee5712
DM
531
532 // Main savepoint reached.
533 upgrade_main_savepoint(true, 2014111000.00);
ebea19cb 534 }
6c4e70a6 535
91bae397 536 if ($oldversion < 2014120100.00) {
93539c44
FM
537
538 // Define field sslverification to be added to mnet_host.
539 $table = new xmldb_table('mnet_host');
540 $field = new xmldb_field('sslverification', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'applicationid');
541
542 // Conditionally launch add field sslverification.
543 if (!$dbman->field_exists($table, $field)) {
544 $dbman->add_field($table, $field);
545 }
546
547 // Main savepoint reached.
91bae397 548 upgrade_main_savepoint(true, 2014120100.00);
93539c44
FM
549 }
550
b2ab6cc3 551 if ($oldversion < 2014120101.00) {
93539c44 552
686d0561
SH
553 // Define field component to be added to comments.
554 $table = new xmldb_table('comments');
555 $field = new xmldb_field('component', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'contextid');
556
557 // Conditionally launch add field component.
558 if (!$dbman->field_exists($table, $field)) {
559 $dbman->add_field($table, $field);
560 }
561
562 // Main savepoint reached.
b2ab6cc3 563 upgrade_main_savepoint(true, 2014120101.00);
686d0561 564 }
6c4e70a6
SH
565
566 if ($oldversion < 2014120102.00) {
1d658535
PS
567
568 // Define table user_password_history to be created.
569 $table = new xmldb_table('user_password_history');
570
571 // Adding fields to table user_password_history.
572 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
573 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
574 $table->add_field('hash', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
575 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
576
577 // Adding keys to table user_password_history.
578 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
579 $table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
580
581 // Conditionally launch create table for user_password_history.
582 if (!$dbman->table_exists($table)) {
583 $dbman->create_table($table);
584 }
585
586 // Main savepoint reached.
6c4e70a6 587 upgrade_main_savepoint(true, 2014120102.00);
1d658535
PS
588 }
589
c93e6c5c
AA
590 if ($oldversion < 2015010800.01) {
591
592 // Make sure the private files handler is not set to expire.
593 $DB->set_field('messageinbound_handlers', 'defaultexpiration', 0,
594 array('classname' => '\core\message\inbound\private_files_handler'));
595
596 // Main savepoint reached.
597 upgrade_main_savepoint(true, 2015010800.01);
94b8c636
FM
598
599 }
600
e6b18165 601 if ($oldversion < 2015012600.00) {
94b8c636
FM
602
603 // If the site is using internal and external storage, or just external
604 // storage, and the external path specified is empty we change the setting
605 // to internal only. That is how the backup code is handling this
606 // misconfiguration.
6c855719
MN
607 $storage = (int) get_config('backup', 'backup_auto_storage');
608 $folder = get_config('backup', 'backup_auto_destination');
94b8c636
FM
609 if ($storage !== 0 && empty($folder)) {
610 set_config('backup_auto_storage', 0, 'backup');
611 }
612
613 // Main savepoint reached.
e6b18165 614 upgrade_main_savepoint(true, 2015012600.00);
c93e6c5c
AA
615 }
616
5bc12ca2
SB
617 if ($oldversion < 2015012600.01) {
618
619 // Convert calendar_lookahead to nearest new value.
620 $value = $DB->get_field('config', 'value', array('name' => 'calendar_lookahead'));
621 if ($value > 90) {
622 set_config('calendar_lookahead', '120');
623 } else if ($value > 60 and $value < 90) {
624 set_config('calendar_lookahead', '90');
625 } else if ($value > 30 and $value < 60) {
626 set_config('calendar_lookahead', '60');
627 } else if ($value > 21 and $value < 30) {
628 set_config('calendar_lookahead', '30');
629 } else if ($value > 14 and $value < 21) {
630 set_config('calendar_lookahead', '21');
631 } else if ($value > 7 and $value < 14) {
632 set_config('calendar_lookahead', '14');
633 }
634
635 // Main savepoint reached.
636 upgrade_main_savepoint(true, 2015012600.01);
637 }
806c06fc 638
d3dac400 639 if ($oldversion < 2015021100.00) {
806c06fc
AD
640
641 // Define field timemodified to be added to registration_hubs.
642 $table = new xmldb_table('registration_hubs');
d3dac400 643 $field = new xmldb_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'secret');
806c06fc
AD
644
645 // Conditionally launch add field timemodified.
646 if (!$dbman->field_exists($table, $field)) {
647 $dbman->add_field($table, $field);
648 }
649
650 // Main savepoint reached.
d3dac400 651 upgrade_main_savepoint(true, 2015021100.00);
806c06fc
AD
652 }
653
e6c453bb 654 if ($oldversion < 2015022401.00) {
8b52863f
AN
655
656 // Define index useridfromto (not unique) to be added to message.
657 $table = new xmldb_table('message');
658 $index = new xmldb_index('useridfromto', XMLDB_INDEX_NOTUNIQUE, array('useridfrom', 'useridto'));
659
660 // Conditionally launch add index useridfromto.
661 if (!$dbman->index_exists($table, $index)) {
662 $dbman->add_index($table, $index);
663 }
664
665 // Define index useridfromto (not unique) to be added to message_read.
666 $table = new xmldb_table('message_read');
667 $index = new xmldb_index('useridfromto', XMLDB_INDEX_NOTUNIQUE, array('useridfrom', 'useridto'));
668
669 // Conditionally launch add index useridfromto.
670 if (!$dbman->index_exists($table, $index)) {
671 $dbman->add_index($table, $index);
672 }
673
674 // Main savepoint reached.
e6c453bb 675 upgrade_main_savepoint(true, 2015022401.00);
8b52863f
AN
676 }
677
db23cd08 678 if ($oldversion < 2015022500.00) {
3221718e
JL
679 $table = new xmldb_table('user_devices');
680 $index = new xmldb_index('uuid-userid', XMLDB_INDEX_NOTUNIQUE, array('uuid', 'userid'));
681 if (!$dbman->index_exists($table, $index)) {
682 $dbman->add_index($table, $index);
683 }
db23cd08 684 upgrade_main_savepoint(true, 2015022500.00);
3221718e
JL
685 }
686
858e92fe
AD
687 if ($oldversion < 2015030400.00) {
688 // We have long since switched to storing timemodified per hub rather than a single 'registered' timestamp.
689 unset_config('registered');
690 upgrade_main_savepoint(true, 2015030400.00);
691 }
692
42d81ef7 693 if ($oldversion < 2015031100.00) {
c803fa68
EM
694 // Unset old config variable.
695 unset_config('enabletgzbackups');
696
42d81ef7 697 upgrade_main_savepoint(true, 2015031100.00);
c803fa68
EM
698 }
699
1f50bbf1
AN
700 if ($oldversion < 2015031400.00) {
701
702 // Define index useridfrom (not unique) to be dropped form message.
703 $table = new xmldb_table('message');
704 $index = new xmldb_index('useridfrom', XMLDB_INDEX_NOTUNIQUE, array('useridfrom'));
705
706 // Conditionally launch drop index useridfrom.
707 if ($dbman->index_exists($table, $index)) {
708 $dbman->drop_index($table, $index);
709 }
710
711 // Define index useridfrom (not unique) to be dropped form message_read.
712 $table = new xmldb_table('message_read');
713 $index = new xmldb_index('useridfrom', XMLDB_INDEX_NOTUNIQUE, array('useridfrom'));
714
715 // Conditionally launch drop index useridfrom.
716 if ($dbman->index_exists($table, $index)) {
717 $dbman->drop_index($table, $index);
718 }
719
720 // Main savepoint reached.
721 upgrade_main_savepoint(true, 2015031400.00);
722 }
723
24aac597
AD
724 if ($oldversion < 2015031900.01) {
725 unset_config('crontime', 'registration');
726 upgrade_main_savepoint(true, 2015031900.01);
727 }
728
3784d3be
YB
729 if ($oldversion < 2015032000.00) {
730 $table = new xmldb_table('badge_criteria');
3784d3be 731
fffeb03f 732 $field = new xmldb_field('description', XMLDB_TYPE_TEXT, null, null, null, null, null);
3784d3be
YB
733 // Conditionally add description field to the badge_criteria table.
734 if (!$dbman->field_exists($table, $field)) {
735 $dbman->add_field($table, $field);
736 }
737
fffeb03f
YB
738 $field = new xmldb_field('descriptionformat', XMLDB_TYPE_INTEGER, 2, null, XMLDB_NOTNULL, null, 0);
739 // Conditionally add description format field to the badge_criteria table.
740 if (!$dbman->field_exists($table, $field)) {
741 $dbman->add_field($table, $field);
742 }
743
3784d3be
YB
744 upgrade_main_savepoint(true, 2015032000.00);
745 }
746
d6e7a63d
PS
747 if ($oldversion < 2015040200.01) {
748 // Force uninstall of deleted tool.
749 if (!file_exists("$CFG->dirroot/$CFG->admin/tool/timezoneimport")) {
750 // Remove capabilities.
751 capabilities_cleanup('tool_timezoneimport');
752 // Remove all other associated config.
753 unset_all_config_for_plugin('tool_timezoneimport');
754 }
755 upgrade_main_savepoint(true, 2015040200.01);
756 }
757
758 if ($oldversion < 2015040200.02) {
759 // Define table timezone to be dropped.
760 $table = new xmldb_table('timezone');
761 // Conditionally launch drop table for timezone.
762 if ($dbman->table_exists($table)) {
763 $dbman->drop_table($table);
764 }
765 upgrade_main_savepoint(true, 2015040200.02);
766 }
767
768 if ($oldversion < 2015040200.03) {
769 if (isset($CFG->timezone) and $CFG->timezone == 99) {
770 // Migrate to real server timezone.
771 unset_config('timezone');
772 }
773 upgrade_main_savepoint(true, 2015040200.03);
774 }
775
75ece778 776 if ($oldversion < 2015040700.01) {
6398ff53 777 $DB->delete_records('config_plugins', array('name' => 'requiremodintro'));
75ece778 778 upgrade_main_savepoint(true, 2015040700.01);
6398ff53
AH
779 }
780
72324523 781 if ($oldversion < 2015040900.01) {
c9451960 782 // Add "My grades" to the user menu.
e4522f88
DW
783 $oldconfig = get_config('core', 'customusermenuitems');
784 if (strpos("mygrades,grades|/grade/report/mygrades.php|grades", $oldconfig) === false) {
2b7b0bae 785 $newconfig = "mygrades,grades|/grade/report/mygrades.php|grades\n" . $oldconfig;
e4522f88
DW
786 set_config('customusermenuitems', $newconfig);
787 }
c9451960 788
72324523 789 upgrade_main_savepoint(true, 2015040900.01);
c9451960
AG
790 }
791
72324523 792 if ($oldversion < 2015040900.02) {
e4522f88
DW
793 // Update the default user menu (add preferences, remove my files and my badges).
794 $oldconfig = get_config('core', 'customusermenuitems');
795
796 // Add "My preferences" at the end.
797 if (strpos($oldconfig, "mypreferences,moodle|/user/preference.php|preferences") === false) {
798 $newconfig = $oldconfig . "\nmypreferences,moodle|/user/preferences.php|preferences";
799 } else {
800 $newconfig = $oldconfig;
801 }
802 // Remove my files.
803 $newconfig = str_replace("myfiles,moodle|/user/files.php|download", "", $newconfig);
804 // Remove my badges.
805 $newconfig = str_replace("mybadges,badges|/badges/mybadges.php|award", "", $newconfig);
806 // Remove holes.
807 $newconfig = preg_replace('/\n+/', "\n", $newconfig);
808 $newconfig = preg_replace('/(\r\n)+/', "\n", $newconfig);
809 set_config('customusermenuitems', $newconfig);
810
72324523 811 upgrade_main_savepoint(true, 2015040900.02);
e4522f88
DW
812 }
813
4887d152
JO
814 if ($oldversion < 2015050400.00) {
815 $config = get_config('core', 'customusermenuitems');
816
817 // Change "My preferences" in the user menu to "Preferences".
818 $config = str_replace("mypreferences,moodle|/user/preferences.php|preferences",
819 "preferences,moodle|/user/preferences.php|preferences", $config);
820
821 // Change "My grades" in the user menu to "Grades".
822 $config = str_replace("mygrades,grades|/grade/report/mygrades.php|grades",
823 "grades,grades|/grade/report/mygrades.php|grades", $config);
824
825 set_config('customusermenuitems', $config);
826
827 upgrade_main_savepoint(true, 2015050400.00);
828 }
829
6df7f200 830 if ($oldversion < 2015050401.00) {
3c568cd3
DW
831 // Make sure we have messages in the user menu because it's no longer in the nav tree.
832 $oldconfig = get_config('core', 'customusermenuitems');
35ea78d2
JO
833 $messagesconfig = "messages,message|/message/index.php|message";
834 $preferencesconfig = "preferences,moodle|/user/preferences.php|preferences";
3c568cd3
DW
835
836 // See if it exists.
35ea78d2
JO
837 if (strpos($oldconfig, $messagesconfig) === false) {
838 // See if preferences exists.
839 if (strpos($oldconfig, "preferences,moodle|/user/preferences.php|preferences") !== false) {
840 // Insert it before preferences.
841 $newconfig = str_replace($preferencesconfig, $messagesconfig . "\n" . $preferencesconfig, $oldconfig);
3c568cd3
DW
842 } else {
843 // Custom config - we can only insert it at the end.
35ea78d2 844 $newconfig = $oldconfig . "\n" . $messagesconfig;
3c568cd3
DW
845 }
846 set_config('customusermenuitems', $newconfig);
847 }
848
d3f1cde5 849 upgrade_main_savepoint(true, 2015050401.00);
3c568cd3 850 }
6df7f200 851
b758ab30
EL
852 // Moodle v2.9.0 release upgrade line.
853 // Put any upgrade step following this.
854
408e3812 855 if ($oldversion < 2015060400.02) {
ebea19cb
FM
856
857 // Sites that were upgrading from 2.7 and older will ignore this step.
858 if (empty($CFG->upgrade_minmaxgradestepignored)) {
859
860 upgrade_minmaxgrade();
861
862 // Flags this upgrade step as already run to prevent it from running multiple times.
863 set_config('upgrade_minmaxgradestepignored', 1);
c07775df
EM
864 }
865
408e3812 866 upgrade_main_savepoint(true, 2015060400.02);
c07775df
EM
867 }
868
156d0486
MG
869 if ($oldversion < 2015061900.00) {
870 // MDL-49257. Changed the algorithm of calculating automatic weights of extra credit items.
871
872 // Before the change, in case when grade category (in "Natural" agg. method) had items with
873 // overridden weights, the automatic weight of extra credit items was illogical.
874 // In order to prevent grades changes after the upgrade we need to freeze gradebook calculation
875 // for the affected courses.
876
877 // This script in included in each major version upgrade process so make sure we don't run it twice.
878 if (empty($CFG->upgrade_extracreditweightsstepignored)) {
879 upgrade_extra_credit_weightoverride();
880
881 // To skip running the same script on the upgrade to the next major release.
882 set_config('upgrade_extracreditweightsstepignored', 1);
883 }
884
885 // Main savepoint reached.
886 upgrade_main_savepoint(true, 2015061900.00);
887 }
888
4d4dcc27
AG
889 if ($oldversion < 2015062500.01) {
890 // MDL-48239. Changed calculated grade items so that the maximum and minimum grade can be set.
891
892 // If the changes are accepted and a regrade is done on the gradebook then some grades may change significantly.
893 // This is here to freeze the gradebook in affected courses.
894
895 // This script is included in each major version upgrade process so make sure we don't run it twice.
896 if (empty($CFG->upgrade_calculatedgradeitemsignored)) {
897 upgrade_calculated_grade_items();
898
899 // To skip running the same script on the upgrade to the next major release.
900 set_config('upgrade_calculatedgradeitemsignored', 1);
4359caa2
DW
901 // This config value is never used again.
902 unset_config('upgrade_calculatedgradeitemsonlyregrade');
4d4dcc27
AG
903 }
904
905 // Main savepoint reached.
906 upgrade_main_savepoint(true, 2015062500.01);
907 }
908
0305798c
AG
909 if ($oldversion < 2015081300.01) {
910
911 // Define field importtype to be added to grade_import_values.
912 $table = new xmldb_table('grade_import_values');
913 $field = new xmldb_field('importonlyfeedback', XMLDB_TYPE_INTEGER, '1', null, null, null, '0', 'importer');
914
915 // Conditionally launch add field importtype.
916 if (!$dbman->field_exists($table, $field)) {
917 $dbman->add_field($table, $field);
918 }
919
920 // Main savepoint reached.
921 upgrade_main_savepoint(true, 2015081300.01);
922 }
923
482ebc17 924 if ($oldversion < 2015082400.00) {
04c24a55
AN
925
926 // Define table webdav_locks to be dropped.
927 $table = new xmldb_table('webdav_locks');
928
929 // Conditionally launch drop table for webdav_locks.
930 if ($dbman->table_exists($table)) {
931 $dbman->drop_table($table);
932 }
933
934 // Main savepoint reached.
482ebc17 935 upgrade_main_savepoint(true, 2015082400.00);
04c24a55
AN
936 }
937
e45f622b 938 if ($oldversion < 2015090200.00) {
1efd3238
MN
939 $table = new xmldb_table('message');
940
941 // Define the deleted fields to be added to the message tables.
942 $field1 = new xmldb_field('timeuserfromdeleted', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0',
943 'timecreated');
944 $field2 = new xmldb_field('timeusertodeleted', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0',
945 'timecreated');
946 $oldindex = new xmldb_index('useridfromto', XMLDB_INDEX_NOTUNIQUE,
947 array('useridfrom', 'useridto'));
948 $newindex = new xmldb_index('useridfromtodeleted', XMLDB_INDEX_NOTUNIQUE,
949 array('useridfrom', 'useridto', 'timeuserfromdeleted', 'timeusertodeleted'));
950
951 // Conditionally launch add field timeuserfromdeleted.
952 if (!$dbman->field_exists($table, $field1)) {
953 $dbman->add_field($table, $field1);
954 }
955
956 // Conditionally launch add field timeusertodeleted.
957 if (!$dbman->field_exists($table, $field2)) {
958 $dbman->add_field($table, $field2);
959 }
960
961 // Conditionally launch drop index useridfromto.
962 if ($dbman->index_exists($table, $oldindex)) {
963 $dbman->drop_index($table, $oldindex);
964 }
965
966 // Conditionally launch add index useridfromtodeleted.
967 if (!$dbman->index_exists($table, $newindex)) {
968 $dbman->add_index($table, $newindex);
969 }
970
971 // Now add them to the message_read table.
972 $table = new xmldb_table('message_read');
973
974 // Conditionally launch add field timeuserfromdeleted.
975 if (!$dbman->field_exists($table, $field1)) {
976 $dbman->add_field($table, $field1);
977 }
978
979 // Conditionally launch add field timeusertodeleted.
980 if (!$dbman->field_exists($table, $field2)) {
981 $dbman->add_field($table, $field2);
982 }
983
984 // Conditionally launch drop index useridfromto.
985 if ($dbman->index_exists($table, $oldindex)) {
986 $dbman->drop_index($table, $oldindex);
987 }
988
989 // Conditionally launch add index useridfromtodeleted.
990 if (!$dbman->index_exists($table, $newindex)) {
991 $dbman->add_index($table, $newindex);
992 }
993
994 // Main savepoint reached.
e45f622b 995 upgrade_main_savepoint(true, 2015090200.00);
1efd3238
MN
996 }
997
9e66dff0 998 if ($oldversion < 2015090801.00) {
0d1e5456
MG
999 // This upgrade script merges all tag instances pointing to the same course tag.
1000 // User id is no longer used for those tag instances.
1001 upgrade_course_tags();
1002
1003 // If configuration variable "Show course tags" is set, disable the block
1004 // 'tags' because it can not be used for tagging courses any more.
1005 if (!empty($CFG->block_tags_showcoursetags)) {
1006 if ($record = $DB->get_record('block', array('name' => 'tags'), 'id, visible')) {
1007 if ($record->visible) {
1008 $DB->update_record('block', array('id' => $record->id, 'visible' => 0));
1009 }
1010 }
1011 }
1012
1013 // Define index idname (unique) to be dropped form tag (it's really weird).
1014 $table = new xmldb_table('tag');
1015 $index = new xmldb_index('idname', XMLDB_INDEX_UNIQUE, array('id', 'name'));
1016
1017 // Conditionally launch drop index idname.
1018 if ($dbman->index_exists($table, $index)) {
1019 $dbman->drop_index($table, $index);
1020 }
1021
1022 // Main savepoint reached.
9e66dff0 1023 upgrade_main_savepoint(true, 2015090801.00);
0d1e5456
MG
1024 }
1025
16d08d46 1026 if ($oldversion < 2015092200.00) {
581e6637
DS
1027 // Define index qtype (not unique) to be added to question.
1028 $table = new xmldb_table('question');
1029 $index = new xmldb_index('qtype', XMLDB_INDEX_NOTUNIQUE, array('qtype'));
1030
1031 // Conditionally launch add index qtype.
1032 if (!$dbman->index_exists($table, $index)) {
1033 $dbman->add_index($table, $index);
1034 }
1035
1036 // Main savepoint reached.
16d08d46 1037 upgrade_main_savepoint(true, 2015092200.00);
581e6637
DS
1038 }
1039
a3b1172d 1040 if ($oldversion < 2015092900.00) {
2b7c85da
JPG
1041 // Rename backup_auto_keep setting to backup_auto_max_kept.
1042 $keep = get_config('backup', 'backup_auto_keep');
1043 if ($keep !== false) {
1044 set_config('backup_auto_max_kept', $keep, 'backup');
1045 unset_config('backup_auto_keep', 'backup');
1046 }
1047
1048 // Main savepoint reached.
a3b1172d 1049 upgrade_main_savepoint(true, 2015092900.00);
2b7c85da
JPG
1050 }
1051
05e6215c 1052 if ($oldversion < 2015100600.00) {
60b69e4d
PFO
1053
1054 // Define index notification (not unique) to be added to message_read.
1055 $table = new xmldb_table('message_read');
1056 $index = new xmldb_index('notificationtimeread', XMLDB_INDEX_NOTUNIQUE, array('notification', 'timeread'));
1057
1058 // Conditionally launch add index notification.
1059 if (!$dbman->index_exists($table, $index)) {
1060 $dbman->add_index($table, $index);
1061 }
1062
1063 // Main savepoint reached.
05e6215c 1064 upgrade_main_savepoint(true, 2015100600.00);
60b69e4d
PFO
1065 }
1066
b0fc7898
DM
1067 if ($oldversion < 2015100800.01) {
1068 // The only flag for preventing all plugins installation features is
1069 // now $CFG->disableupdateautodeploy in config.php.
1070 unset_config('updateautodeploy');
1071 upgrade_main_savepoint(true, 2015100800.01);
1072 }
1073
6d29c4ac
EL
1074 // Moodle v3.0.0 release upgrade line.
1075 // Put any upgrade step following this.
1076
67f68027 1077 if ($oldversion < 2016011300.01) {
c026a28d
MG
1078
1079 // This is a big upgrade script. We create new table tag_coll and the field
1080 // tag.tagcollid pointing to it.
1081
1082 // Define table tag_coll to be created.
1083 $table = new xmldb_table('tag_coll');
1084
1085 // Adding fields to table tagcloud.
1086 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1087 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, null);
1088 $table->add_field('isdefault', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0');
1089 $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, null, null, null);
1090 $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '5', null, XMLDB_NOTNULL, null, '0');
1091 $table->add_field('searchable', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '1');
1092 $table->add_field('customurl', XMLDB_TYPE_CHAR, '255', null, null, null, null);
1093
1094 // Adding keys to table tagcloud.
1095 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1096
1097 // Conditionally launch create table for tagcloud.
1098 if (!$dbman->table_exists($table)) {
1099 $dbman->create_table($table);
1100 }
1101
1102 // Table {tag}.
1103 // Define index name (unique) to be dropped form tag - we will replace it with index on (tagcollid,name) later.
1104 $table = new xmldb_table('tag');
1105 $index = new xmldb_index('name', XMLDB_INDEX_UNIQUE, array('name'));
1106
1107 // Conditionally launch drop index name.
1108 if ($dbman->index_exists($table, $index)) {
1109 $dbman->drop_index($table, $index);
1110 }
1111
1112 // Define field tagcollid to be added to tag, we create it as null first and will change to notnull later.
1113 $table = new xmldb_table('tag');
1114 $field = new xmldb_field('tagcollid', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'userid');
1115
1116 // Conditionally launch add field tagcloudid.
1117 if (!$dbman->field_exists($table, $field)) {
1118 $dbman->add_field($table, $field);
1119 }
1120
1121 // Main savepoint reached.
67f68027 1122 upgrade_main_savepoint(true, 2016011300.01);
c026a28d
MG
1123 }
1124
67f68027 1125 if ($oldversion < 2016011300.02) {
c026a28d
MG
1126 // Create a default tag collection if not exists and update the field tag.tagcollid to point to it.
1127 if (!$tcid = $DB->get_field_sql('SELECT id FROM {tag_coll} ORDER BY isdefault DESC, sortorder, id', null,
1128 IGNORE_MULTIPLE)) {
1129 $tcid = $DB->insert_record('tag_coll', array('isdefault' => 1, 'sortorder' => 0));
1130 }
1131 $DB->execute('UPDATE {tag} SET tagcollid = ? WHERE tagcollid IS NULL', array($tcid));
1132
1133 // Define index tagcollname (unique) to be added to tag.
1134 $table = new xmldb_table('tag');
1135 $index = new xmldb_index('tagcollname', XMLDB_INDEX_UNIQUE, array('tagcollid', 'name'));
1136 $field = new xmldb_field('tagcollid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null, 'userid');
1137
1138 // Conditionally launch add index tagcollname.
1139 if (!$dbman->index_exists($table, $index)) {
1140 // Launch change of nullability for field tagcollid.
1141 $dbman->change_field_notnull($table, $field);
1142 $dbman->add_index($table, $index);
1143 }
1144
1145 // Define key tagcollid (foreign) to be added to tag.
1146 $table = new xmldb_table('tag');
1147 $key = new xmldb_key('tagcollid', XMLDB_KEY_FOREIGN, array('tagcollid'), 'tag_coll', array('id'));
1148
1149 // Launch add key tagcloudid.
1150 $dbman->add_key($table, $key);
1151
c026a28d 1152 // Main savepoint reached.
67f68027 1153 upgrade_main_savepoint(true, 2016011300.02);
c026a28d
MG
1154 }
1155
67f68027 1156 if ($oldversion < 2016011300.03) {
c026a28d
MG
1157
1158 // Define table tag_area to be created.
1159 $table = new xmldb_table('tag_area');
1160
1161 // Adding fields to table tag_area.
1162 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1163 $table->add_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
1164 $table->add_field('itemtype', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
1165 $table->add_field('enabled', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '1');
1166 $table->add_field('tagcollid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1167 $table->add_field('callback', XMLDB_TYPE_CHAR, '100', null, null, null, null);
1168 $table->add_field('callbackfile', XMLDB_TYPE_CHAR, '100', null, null, null, null);
1169
1170 // Adding keys to table tag_area.
1171 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1172 $table->add_key('tagcollid', XMLDB_KEY_FOREIGN, array('tagcollid'), 'tag_coll', array('id'));
1173
1174 // Adding indexes to table tag_area.
1175 $table->add_index('compitemtype', XMLDB_INDEX_UNIQUE, array('component', 'itemtype'));
1176
1177 // Conditionally launch create table for tag_area.
1178 if (!$dbman->table_exists($table)) {
1179 $dbman->create_table($table);
1180 }
1181
1182 // Main savepoint reached.
67f68027 1183 upgrade_main_savepoint(true, 2016011300.03);
c026a28d
MG
1184 }
1185
67f68027 1186 if ($oldversion < 2016011300.04) {
c026a28d
MG
1187
1188 // Define index itemtype-itemid-tagid-tiuserid (unique) to be dropped form tag_instance.
1189 $table = new xmldb_table('tag_instance');
1190 $index = new xmldb_index('itemtype-itemid-tagid-tiuserid', XMLDB_INDEX_UNIQUE,
1191 array('itemtype', 'itemid', 'tagid', 'tiuserid'));
1192
1193 // Conditionally launch drop index itemtype-itemid-tagid-tiuserid.
1194 if ($dbman->index_exists($table, $index)) {
1195 $dbman->drop_index($table, $index);
1196 }
1197
1198 // Main savepoint reached.
67f68027 1199 upgrade_main_savepoint(true, 2016011300.04);
c026a28d
MG
1200 }
1201
67f68027 1202 if ($oldversion < 2016011300.05) {
c026a28d
MG
1203
1204 $DB->execute("UPDATE {tag_instance} SET component = ? WHERE component IS NULL", array(''));
1205
1206 // Changing nullability of field component on table tag_instance to not null.
1207 $table = new xmldb_table('tag_instance');
1208 $field = new xmldb_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'tagid');
1209
1210 // Launch change of nullability for field component.
1211 $dbman->change_field_notnull($table, $field);
1212
1213 // Changing type of field itemtype on table tag_instance to char.
1214 $table = new xmldb_table('tag_instance');
1215 $field = new xmldb_field('itemtype', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'component');
1216
1217 // Launch change of type for field itemtype.
1218 $dbman->change_field_type($table, $field);
1219
1220 // Main savepoint reached.
67f68027 1221 upgrade_main_savepoint(true, 2016011300.05);
c026a28d
MG
1222 }
1223
67f68027 1224 if ($oldversion < 2016011300.06) {
c026a28d
MG
1225
1226 // Define index taggeditem (unique) to be added to tag_instance.
1227 $table = new xmldb_table('tag_instance');
1228 $index = new xmldb_index('taggeditem', XMLDB_INDEX_UNIQUE, array('component', 'itemtype', 'itemid', 'tiuserid', 'tagid'));
1229
1230 // Conditionally launch add index taggeditem.
1231 if (!$dbman->index_exists($table, $index)) {
1232 $dbman->add_index($table, $index);
1233 }
1234
1235 // Main savepoint reached.
67f68027 1236 upgrade_main_savepoint(true, 2016011300.06);
c026a28d
MG
1237 }
1238
67f68027 1239 if ($oldversion < 2016011300.07) {
c026a28d
MG
1240
1241 // Define index taglookup (not unique) to be added to tag_instance.
1242 $table = new xmldb_table('tag_instance');
1243 $index = new xmldb_index('taglookup', XMLDB_INDEX_NOTUNIQUE, array('itemtype', 'component', 'tagid', 'contextid'));
1244
1245 // Conditionally launch add index taglookup.
1246 if (!$dbman->index_exists($table, $index)) {
1247 $dbman->add_index($table, $index);
1248 }
1249
1250 // Main savepoint reached.
67f68027 1251 upgrade_main_savepoint(true, 2016011300.07);
c026a28d
MG
1252 }
1253
67f68027 1254 if ($oldversion < 2016011301.00) {
a73409d3
CB
1255
1256 // Force uninstall of deleted tool.
1257 if (!file_exists("$CFG->dirroot/webservice/amf")) {
1258 // Remove capabilities.
1259 capabilities_cleanup('webservice_amf');
1260 // Remove all other associated config.
1261 unset_all_config_for_plugin('webservice_amf');
1262 }
67f68027 1263 upgrade_main_savepoint(true, 2016011301.00);
a73409d3
CB
1264 }
1265
d3220ca3 1266 if ($oldversion < 2016011901.00) {
a7213391
SB
1267
1268 // Convert calendar_lookahead to nearest new value.
1269 $transaction = $DB->start_delegated_transaction();
1270
1271 // Count all users who curretly have that preference set (for progress bar).
668aca18 1272 $total = $DB->count_records_select('user_preferences', "name = 'calendar_lookahead' AND value != '0'");
a7213391
SB
1273 $pbar = new progress_bar('upgradecalendarlookahead', 500, true);
1274
1275 // Get all these users, one at a time.
668aca18 1276 $rs = $DB->get_recordset_select('user_preferences', "name = 'calendar_lookahead' AND value != '0'");
a7213391
SB
1277 $i = 0;
1278 foreach ($rs as $userpref) {
1279
1280 // Calculate and set new lookahead value.
1281 if ($userpref->value > 90) {
1282 $newvalue = 120;
1283 } else if ($userpref->value > 60 and $userpref->value < 90) {
1284 $newvalue = 90;
1285 } else if ($userpref->value > 30 and $userpref->value < 60) {
1286 $newvalue = 60;
1287 } else if ($userpref->value > 21 and $userpref->value < 30) {
1288 $newvalue = 30;
1289 } else if ($userpref->value > 14 and $userpref->value < 21) {
1290 $newvalue = 21;
1291 } else if ($userpref->value > 7 and $userpref->value < 14) {
1292 $newvalue = 14;
1293 } else {
1294 $newvalue = $userpref->value;
1295 }
1296
1297 $DB->set_field('user_preferences', 'value', $newvalue, array('id' => $userpref->id));
1298
1299 // Update progress.
1300 $i++;
1301 $pbar->update($i, $total, "Upgrading user preference settings - $i/$total.");
1302 }
1303 $rs->close();
1304 $transaction->allow_commit();
1305
d3220ca3 1306 upgrade_main_savepoint(true, 2016011901.00);
a7213391 1307 }
e11d7380
MG
1308
1309 if ($oldversion < 2016020200.00) {
1310
1311 // Define field isstandard to be added to tag.
1312 $table = new xmldb_table('tag');
1313 $field = new xmldb_field('isstandard', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'rawname');
1314
1315 // Conditionally launch add field isstandard.
1316 if (!$dbman->field_exists($table, $field)) {
1317 $dbman->add_field($table, $field);
1318 }
1319
1320 // Define index tagcolltype (not unique) to be dropped form tag.
2b1c3e4d 1321 // This index is no longer created however it was present at some point and it's better to be safe and try to drop it.
e11d7380
MG
1322 $index = new xmldb_index('tagcolltype', XMLDB_INDEX_NOTUNIQUE, array('tagcollid', 'tagtype'));
1323
1324 // Conditionally launch drop index tagcolltype.
1325 if ($dbman->index_exists($table, $index)) {
1326 $dbman->drop_index($table, $index);
1327 }
1328
1329 // Define index tagcolltype (not unique) to be added to tag.
1330 $index = new xmldb_index('tagcolltype', XMLDB_INDEX_NOTUNIQUE, array('tagcollid', 'isstandard'));
1331
1332 // Conditionally launch add index tagcolltype.
1333 if (!$dbman->index_exists($table, $index)) {
1334 $dbman->add_index($table, $index);
1335 }
1336
1337 // Define field tagtype to be dropped from tag.
1338 $field = new xmldb_field('tagtype');
1339
1340 // Conditionally launch drop field tagtype and update isstandard.
1341 if ($dbman->field_exists($table, $field)) {
1342 $DB->execute("UPDATE {tag} SET isstandard=(CASE WHEN (tagtype = ?) THEN 1 ELSE 0 END)", array('official'));
1343 $dbman->drop_field($table, $field);
1344 }
1345
1346 // Main savepoint reached.
1347 upgrade_main_savepoint(true, 2016020200.00);
1348 }
1349
4be9c7ad
MG
1350 if ($oldversion < 2016020201.00) {
1351
1352 // Define field showstandard to be added to tag_area.
1353 $table = new xmldb_table('tag_area');
1354 $field = new xmldb_field('showstandard', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'callbackfile');
1355
1356 // Conditionally launch add field showstandard.
1357 if (!$dbman->field_exists($table, $field)) {
1358 $dbman->add_field($table, $field);
1359 }
1360
1361 // By default set user area to hide standard tags. 2 = core_tag_tag::HIDE_STANDARD (can not use constant here).
1362 $DB->execute("UPDATE {tag_area} SET showstandard = ? WHERE itemtype = ? AND component = ?",
1363 array(2, 'user', 'core'));
1364
1365 // Changing precision of field enabled on table tag_area to (1).
1366 $table = new xmldb_table('tag_area');
1367 $field = new xmldb_field('enabled', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'itemtype');
1368
1369 // Launch change of precision for field enabled.
1370 $dbman->change_field_precision($table, $field);
1371
1372 // Main savepoint reached.
1373 upgrade_main_savepoint(true, 2016020201.00);
1374 }
1375
a9e12347
AN
1376 if ($oldversion < 2016021500.00) {
1377 $root = $CFG->tempdir . '/download';
1378 if (is_dir($root)) {
1379 // Fetch each repository type - include all repos, not just enabled.
1380 $repositories = $DB->get_records('repository', array(), '', 'type');
1381
1382 foreach ($repositories as $id => $repository) {
1383 $directory = $root . '/repository_' . $repository->type;
1384 if (is_dir($directory)) {
1385 fulldelete($directory);
1386 }
1387 }
1388 }
1389
1390 // Main savepoint reached.
1391 upgrade_main_savepoint(true, 2016021500.00);
1392 }
1393
c06749bd 1394 if ($oldversion < 2016021501.00) {
201a9093
EM
1395 // This could take a long time. Unfortunately, no way to know how long, and no way to do progress, so setting for 1 hour.
1396 upgrade_set_timeout(3600);
1397
1398 // Define index userid-itemid (not unique) to be added to grade_grades_history.
1399 $table = new xmldb_table('grade_grades_history');
1400 $index = new xmldb_index('userid-itemid-timemodified', XMLDB_INDEX_NOTUNIQUE, array('userid', 'itemid', 'timemodified'));
1401
1402 // Conditionally launch add index userid-itemid.
1403 if (!$dbman->index_exists($table, $index)) {
1404 $dbman->add_index($table, $index);
1405 }
1406
1407 // Main savepoint reached.
c06749bd 1408 upgrade_main_savepoint(true, 2016021501.00);
201a9093
EM
1409 }
1410
73911de5 1411 if ($oldversion < 2016030103.00) {
7d19e0e3
RK
1412
1413 // MDL-50887. Implement plugins infrastructure for antivirus and create ClamAV plugin.
1414 // This routine moves core ClamAV configuration to plugin level.
1415
1416 // If clamav was configured and enabled, enable the plugin.
1417 if (!empty($CFG->runclamonupload) && !empty($CFG->pathtoclam)) {
1418 set_config('antiviruses', 'clamav');
1419 } else {
1420 set_config('antiviruses', '');
1421 }
1422
1423 if (isset($CFG->runclamonupload)) {
1424 // Just unset global configuration, we have already enabled the plugin
1425 // which implies that ClamAV will be used for scanning uploaded files.
1426 unset_config('runclamonupload');
1427 }
1428 // Move core ClamAV configuration settings to plugin.
1429 if (isset($CFG->pathtoclam)) {
1430 set_config('pathtoclam', $CFG->pathtoclam, 'antivirus_clamav');
1431 unset_config('pathtoclam');
1432 }
1433 if (isset($CFG->quarantinedir)) {
1434 set_config('quarantinedir', $CFG->quarantinedir, 'antivirus_clamav');
1435 unset_config('quarantinedir');
1436 }
1437 if (isset($CFG->clamfailureonupload)) {
1438 set_config('clamfailureonupload', $CFG->clamfailureonupload, 'antivirus_clamav');
1439 unset_config('clamfailureonupload');
1440 }
1441
1442 // Main savepoint reached.
73911de5 1443 upgrade_main_savepoint(true, 2016030103.00);
7d19e0e3
RK
1444 }
1445
186eba1b
JL
1446 if ($oldversion < 2016030400.01) {
1447 // Add the new services field.
1448 $table = new xmldb_table('external_functions');
1449 $field = new xmldb_field('services', XMLDB_TYPE_CHAR, '1333', null, null, null, null, 'capabilities');
1450
1451 // Conditionally launch add field services.
1452 if (!$dbman->field_exists($table, $field)) {
1453 $dbman->add_field($table, $field);
1454 }
1455 // Main savepoint reached.
1456 upgrade_main_savepoint(true, 2016030400.01);
1457 }
1458
a4e659c7
FM
1459 if ($oldversion < 2016041500.50) {
1460
1461 // Define table competency to be created.
1462 $table = new xmldb_table('competency');
1463
1464 // Adding fields to table competency.
1465 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1466 $table->add_field('shortname', XMLDB_TYPE_CHAR, '100', null, null, null, null);
1467 $table->add_field('description', XMLDB_TYPE_TEXT, null, null, null, null, null);
1468 $table->add_field('descriptionformat', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0');
1469 $table->add_field('idnumber', XMLDB_TYPE_CHAR, '100', null, null, null, null);
1470 $table->add_field('competencyframeworkid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1471 $table->add_field('parentid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
1472 $table->add_field('path', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
1473 $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1474 $table->add_field('ruletype', XMLDB_TYPE_CHAR, '100', null, null, null, null);
1475 $table->add_field('ruleoutcome', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0');
1476 $table->add_field('ruleconfig', XMLDB_TYPE_TEXT, null, null, null, null, null);
1477 $table->add_field('scaleid', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
1478 $table->add_field('scaleconfiguration', XMLDB_TYPE_TEXT, null, null, null, null, null);
1479 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1480 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1481 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
1482
1483 // Adding keys to table competency.
1484 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1485
1486 // Adding indexes to table competency.
1487 $table->add_index('idnumberframework', XMLDB_INDEX_UNIQUE, array('competencyframeworkid', 'idnumber'));
1488 $table->add_index('ruleoutcome', XMLDB_INDEX_NOTUNIQUE, array('ruleoutcome'));
1489
1490 // Conditionally launch create table for competency.
1491 if (!$dbman->table_exists($table)) {
1492 $dbman->create_table($table);
1493 }
1494
1495 // Main savepoint reached.
1496 upgrade_main_savepoint(true, 2016041500.50);
1497 }
1498
1499 if ($oldversion < 2016041500.51) {
1500
1501 // Define table competency_coursecompsetting to be created.
1502 $table = new xmldb_table('competency_coursecompsetting');
1503
1504 // Adding fields to table competency_coursecompsetting.
1505 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1506 $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1507 $table->add_field('pushratingstouserplans', XMLDB_TYPE_INTEGER, '2', null, null, null, null);
1508 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1509 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1510 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
1511
1512 // Adding keys to table competency_coursecompsetting.
1513 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1514 $table->add_key('courseidlink', XMLDB_KEY_FOREIGN_UNIQUE, array('courseid'), 'course', array('id'));
1515
1516 // Conditionally launch create table for competency_coursecompsetting.
1517 if (!$dbman->table_exists($table)) {
1518 $dbman->create_table($table);
1519 }
1520
1521 // Main savepoint reached.
1522 upgrade_main_savepoint(true, 2016041500.51);
1523 }
1524
1525 if ($oldversion < 2016041500.52) {
1526
1527 // Define table competency_framework to be created.
1528 $table = new xmldb_table('competency_framework');
1529
1530 // Adding fields to table competency_framework.
1531 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1532 $table->add_field('shortname', XMLDB_TYPE_CHAR, '100', null, null, null, null);
1533 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1534 $table->add_field('idnumber', XMLDB_TYPE_CHAR, '100', null, null, null, null);
1535 $table->add_field('description', XMLDB_TYPE_TEXT, null, null, null, null, null);
1536 $table->add_field('descriptionformat', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0');
1537 $table->add_field('scaleid', XMLDB_TYPE_INTEGER, '11', null, null, null, null);
1538 $table->add_field('scaleconfiguration', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
1539 $table->add_field('visible', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '1');
1540 $table->add_field('taxonomies', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
1541 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1542 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1543 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
1544
1545 // Adding keys to table competency_framework.
1546 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1547
1548 // Adding indexes to table competency_framework.
1549 $table->add_index('idnumber', XMLDB_INDEX_UNIQUE, array('idnumber'));
1550
1551 // Conditionally launch create table for competency_framework.
1552 if (!$dbman->table_exists($table)) {
1553 $dbman->create_table($table);
1554 }
1555
1556 // Main savepoint reached.
1557 upgrade_main_savepoint(true, 2016041500.52);
1558 }
1559
1560 if ($oldversion < 2016041500.53) {
1561
1562 // Define table competency_coursecomp to be created.
1563 $table = new xmldb_table('competency_coursecomp');
1564
1565 // Adding fields to table competency_coursecomp.
1566 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1567 $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1568 $table->add_field('competencyid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1569 $table->add_field('ruleoutcome', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, null);
1570 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1571 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1572 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1573 $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1574
1575 // Adding keys to table competency_coursecomp.
1576 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1577 $table->add_key('courseidlink', XMLDB_KEY_FOREIGN, array('courseid'), 'course', array('id'));
1578 $table->add_key('competencyid', XMLDB_KEY_FOREIGN, array('competencyid'), 'competency_competency', array('id'));
1579
1580 // Adding indexes to table competency_coursecomp.
1581 $table->add_index('courseidruleoutcome', XMLDB_INDEX_NOTUNIQUE, array('courseid', 'ruleoutcome'));
1582 $table->add_index('courseidcompetencyid', XMLDB_INDEX_UNIQUE, array('courseid', 'competencyid'));
1583
1584 // Conditionally launch create table for competency_coursecomp.
1585 if (!$dbman->table_exists($table)) {
1586 $dbman->create_table($table);
1587 }
1588
1589 // Main savepoint reached.
1590 upgrade_main_savepoint(true, 2016041500.53);
1591 }
1592
1593 if ($oldversion < 2016041500.54) {
1594
1595 // Define table competency_plan to be created.
1596 $table = new xmldb_table('competency_plan');
1597
1598 // Adding fields to table competency_plan.
1599 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1600 $table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
1601 $table->add_field('description', XMLDB_TYPE_TEXT, null, null, null, null, null);
1602 $table->add_field('descriptionformat', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0');
1603 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1604 $table->add_field('templateid', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
1605 $table->add_field('origtemplateid', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
1606 $table->add_field('status', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null);
1607 $table->add_field('duedate', XMLDB_TYPE_INTEGER, '10', null, null, null, '0');
1608 $table->add_field('reviewerid', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
1609 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1610 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
1611 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1612
1613 // Adding keys to table competency_plan.
1614 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1615
1616 // Adding indexes to table competency_plan.
1617 $table->add_index('useridstatus', XMLDB_INDEX_NOTUNIQUE, array('userid', 'status'));
1618 $table->add_index('templateid', XMLDB_INDEX_NOTUNIQUE, array('templateid'));
1619 $table->add_index('statusduedate', XMLDB_INDEX_NOTUNIQUE, array('status', 'duedate'));
1620
1621 // Conditionally launch create table for competency_plan.
1622 if (!$dbman->table_exists($table)) {
1623 $dbman->create_table($table);
1624 }
1625
1626 // Main savepoint reached.
1627 upgrade_main_savepoint(true, 2016041500.54);
1628 }
1629
1630 if ($oldversion < 2016041500.55) {
1631
1632 // Define table competency_template to be created.
1633 $table = new xmldb_table('competency_template');
1634
1635 // Adding fields to table competency_template.
1636 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1637 $table->add_field('shortname', XMLDB_TYPE_CHAR, '100', null, null, null, null);
1638 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1639 $table->add_field('description', XMLDB_TYPE_TEXT, null, null, null, null, null);
1640 $table->add_field('descriptionformat', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0');
1641 $table->add_field('visible', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '1');
1642 $table->add_field('duedate', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
1643 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1644 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1645 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
1646
1647 // Adding keys to table competency_template.
1648 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1649
1650 // Conditionally launch create table for competency_template.
1651 if (!$dbman->table_exists($table)) {
1652 $dbman->create_table($table);
1653 }
1654
1655 // Main savepoint reached.
1656 upgrade_main_savepoint(true, 2016041500.55);
1657 }
1658
1659 if ($oldversion < 2016041500.56) {
1660
1661 // Define table competency_templatecomp to be created.
1662 $table = new xmldb_table('competency_templatecomp');
1663
1664 // Adding fields to table competency_templatecomp.
1665 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1666 $table->add_field('templateid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1667 $table->add_field('competencyid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1668 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1669 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1670 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1671 $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
1672
1673 // Adding keys to table competency_templatecomp.
1674 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1675 $table->add_key('templateidlink', XMLDB_KEY_FOREIGN, array('templateid'), 'competency_template', array('id'));
1676 $table->add_key('competencyid', XMLDB_KEY_FOREIGN, array('competencyid'), 'competency_competency', array('id'));
1677
1678 // Conditionally launch create table for competency_templatecomp.
1679 if (!$dbman->table_exists($table)) {
1680 $dbman->create_table($table);
1681 }
1682
1683 // Main savepoint reached.
1684 upgrade_main_savepoint(true, 2016041500.56);
1685 }
1686
1687 if ($oldversion < 2016041500.57) {
1688
1689 // Define table competency_templatecohort to be created.
1690 $table = new xmldb_table('competency_templatecohort');
1691
1692 // Adding fields to table competency_templatecohort.
1693 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1694 $table->add_field('templateid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1695 $table->add_field('cohortid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1696 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1697 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1698 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1699
1700 // Adding keys to table competency_templatecohort.
1701 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1702
1703 // Adding indexes to table competency_templatecohort.
1704 $table->add_index('templateid', XMLDB_INDEX_NOTUNIQUE, array('templateid'));
1705 $table->add_index('templatecohortids', XMLDB_INDEX_UNIQUE, array('templateid', 'cohortid'));
1706
1707 // Conditionally launch create table for competency_templatecohort.
1708 if (!$dbman->table_exists($table)) {
1709 $dbman->create_table($table);
1710 }
1711
1712 // Main savepoint reached.
1713 upgrade_main_savepoint(true, 2016041500.57);
1714 }
1715
1716 if ($oldversion < 2016041500.58) {
1717
1718 // Define table competency_relatedcomp to be created.
1719 $table = new xmldb_table('competency_relatedcomp');
1720
1721 // Adding fields to table competency_relatedcomp.
1722 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1723 $table->add_field('competencyid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1724 $table->add_field('relatedcompetencyid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1725 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1726 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
1727 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1728
1729 // Adding keys to table competency_relatedcomp.
1730 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1731
1732 // Conditionally launch create table for competency_relatedcomp.
1733 if (!$dbman->table_exists($table)) {
1734 $dbman->create_table($table);
1735 }
1736
1737 // Main savepoint reached.
1738 upgrade_main_savepoint(true, 2016041500.58);
1739 }
1740
1741 if ($oldversion < 2016041500.59) {
1742
1743 // Define table competency_usercomp to be created.
1744 $table = new xmldb_table('competency_usercomp');
1745
1746 // Adding fields to table competency_usercomp.
1747 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1748 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1749 $table->add_field('competencyid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1750 $table->add_field('status', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0');
1751 $table->add_field('reviewerid', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
1752 $table->add_field('proficiency', XMLDB_TYPE_INTEGER, '2', null, null, null, null);
1753 $table->add_field('grade', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
1754 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1755 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
1756 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1757
1758 // Adding keys to table competency_usercomp.
1759 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1760
1761 // Adding indexes to table competency_usercomp.
1762 $table->add_index('useridcompetency', XMLDB_INDEX_UNIQUE, array('userid', 'competencyid'));
1763
1764 // Conditionally launch create table for competency_usercomp.
1765 if (!$dbman->table_exists($table)) {
1766 $dbman->create_table($table);
1767 }
1768
1769 // Main savepoint reached.
1770 upgrade_main_savepoint(true, 2016041500.59);
1771 }
1772
1773 if ($oldversion < 2016041500.60) {
1774
1775 // Define table competency_usercompcourse to be created.
1776 $table = new xmldb_table('competency_usercompcourse');
1777
1778 // Adding fields to table competency_usercompcourse.
1779 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1780 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1781 $table->add_field('courseid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1782 $table->add_field('competencyid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1783 $table->add_field('proficiency', XMLDB_TYPE_INTEGER, '2', null, null, null, null);
1784 $table->add_field('grade', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
1785 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1786 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
1787 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1788
1789 // Adding keys to table competency_usercompcourse.
1790 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1791
1792 // Adding indexes to table competency_usercompcourse.
1793 $table->add_index('useridcoursecomp', XMLDB_INDEX_UNIQUE, array('userid', 'courseid', 'competencyid'));
1794
1795 // Conditionally launch create table for competency_usercompcourse.
1796 if (!$dbman->table_exists($table)) {
1797 $dbman->create_table($table);
1798 }
1799
1800 // Main savepoint reached.
1801 upgrade_main_savepoint(true, 2016041500.60);
1802 }
1803
1804 if ($oldversion < 2016041500.61) {
1805
1806 // Define table competency_usercompplan to be created.
1807 $table = new xmldb_table('competency_usercompplan');
1808
1809 // Adding fields to table competency_usercompplan.
1810 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1811 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1812 $table->add_field('competencyid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1813 $table->add_field('planid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1814 $table->add_field('proficiency', XMLDB_TYPE_INTEGER, '2', null, null, null, null);
1815 $table->add_field('grade', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
1816 $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
1817 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1818 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
1819 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1820
1821 // Adding keys to table competency_usercompplan.
1822 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1823
1824 // Adding indexes to table competency_usercompplan.
1825 $table->add_index('usercompetencyplan', XMLDB_INDEX_UNIQUE, array('userid', 'competencyid', 'planid'));
1826
1827 // Conditionally launch create table for competency_usercompplan.
1828 if (!$dbman->table_exists($table)) {
1829 $dbman->create_table($table);
1830 }
1831
1832 // Main savepoint reached.
1833 upgrade_main_savepoint(true, 2016041500.61);
1834 }
1835
1836 if ($oldversion < 2016041500.62) {
1837
1838 // Define table competency_plancomp to be created.
1839 $table = new xmldb_table('competency_plancomp');
1840
1841 // Adding fields to table competency_plancomp.
1842 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1843 $table->add_field('planid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1844 $table->add_field('competencyid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1845 $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
1846 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1847 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
1848 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1849
1850 // Adding keys to table competency_plancomp.
1851 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1852
1853 // Adding indexes to table competency_plancomp.
1854 $table->add_index('planidcompetencyid', XMLDB_INDEX_UNIQUE, array('planid', 'competencyid'));
1855
1856 // Conditionally launch create table for competency_plancomp.
1857 if (!$dbman->table_exists($table)) {
1858 $dbman->create_table($table);
1859 }
1860
1861 // Main savepoint reached.
1862 upgrade_main_savepoint(true, 2016041500.62);
1863 }
1864
1865 if ($oldversion < 2016041500.63) {
1866
1867 // Define table competency_evidence to be created.
1868 $table = new xmldb_table('competency_evidence');
1869
1870 // Adding fields to table competency_evidence.
1871 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1872 $table->add_field('usercompetencyid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1873 $table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1874 $table->add_field('action', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, null);
1875 $table->add_field('actionuserid', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
1876 $table->add_field('descidentifier', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
1877 $table->add_field('desccomponent', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
1878 $table->add_field('desca', XMLDB_TYPE_TEXT, null, null, null, null, null);
1879 $table->add_field('url', XMLDB_TYPE_CHAR, '255', null, null, null, null);
1880 $table->add_field('grade', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
1881 $table->add_field('note', XMLDB_TYPE_TEXT, null, null, null, null, null);
1882 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1883 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1884 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1885
1886 // Adding keys to table competency_evidence.
1887 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1888
1889 // Adding indexes to table competency_evidence.
1890 $table->add_index('usercompetencyid', XMLDB_INDEX_NOTUNIQUE, array('usercompetencyid'));
1891
1892 // Conditionally launch create table for competency_evidence.
1893 if (!$dbman->table_exists($table)) {
1894 $dbman->create_table($table);
1895 }
1896
1897 // Main savepoint reached.
1898 upgrade_main_savepoint(true, 2016041500.63);
1899 }
1900
1901 if ($oldversion < 2016041500.64) {
1902
1903 // Define table competency_userevidence to be created.
1904 $table = new xmldb_table('competency_userevidence');
1905
1906 // Adding fields to table competency_userevidence.
1907 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1908 $table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1909 $table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
1910 $table->add_field('description', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
1911 $table->add_field('descriptionformat', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null);
1912 $table->add_field('url', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
1913 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1914 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1915 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1916
1917 // Adding keys to table competency_userevidence.
1918 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1919
1920 // Adding indexes to table competency_userevidence.
1921 $table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid'));
1922
1923 // Conditionally launch create table for competency_userevidence.
1924 if (!$dbman->table_exists($table)) {
1925 $dbman->create_table($table);
1926 }
1927
1928 // Main savepoint reached.
1929 upgrade_main_savepoint(true, 2016041500.64);
1930 }
1931
1932 if ($oldversion < 2016041500.65) {
1933
1934 // Define table competency_userevidencecomp to be created.
1935 $table = new xmldb_table('competency_userevidencecomp');
1936
1937 // Adding fields to table competency_userevidencecomp.
1938 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1939 $table->add_field('userevidenceid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1940 $table->add_field('competencyid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1941 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1942 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1943 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1944
1945 // Adding keys to table competency_userevidencecomp.
1946 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1947
1948 // Adding indexes to table competency_userevidencecomp.
1949 $table->add_index('userevidenceid', XMLDB_INDEX_NOTUNIQUE, array('userevidenceid'));
1950 $table->add_index('userevidencecompids', XMLDB_INDEX_UNIQUE, array('userevidenceid', 'competencyid'));
1951
1952 // Conditionally launch create table for competency_userevidencecomp.
1953 if (!$dbman->table_exists($table)) {
1954 $dbman->create_table($table);
1955 }
1956
1957 // Main savepoint reached.
1958 upgrade_main_savepoint(true, 2016041500.65);
1959 }
1960
1961 if ($oldversion < 2016041500.66) {
1962
1963 // Define table competency_modulecomp to be created.
1964 $table = new xmldb_table('competency_modulecomp');
1965
1966 // Adding fields to table competency_modulecomp.
1967 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
1968 $table->add_field('cmid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1969 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1970 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1971 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1972 $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1973 $table->add_field('competencyid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
1974 $table->add_field('ruleoutcome', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, null);
1975
1976 // Adding keys to table competency_modulecomp.
1977 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
1978 $table->add_key('cmidkey', XMLDB_KEY_FOREIGN, array('cmid'), 'course_modules', array('id'));
1979 $table->add_key('competencyidkey', XMLDB_KEY_FOREIGN, array('competencyid'), 'competency_competency', array('id'));
1980
1981 // Adding indexes to table competency_modulecomp.
1982 $table->add_index('cmidruleoutcome', XMLDB_INDEX_NOTUNIQUE, array('cmid', 'ruleoutcome'));
1983 $table->add_index('cmidcompetencyid', XMLDB_INDEX_UNIQUE, array('cmid', 'competencyid'));
1984
1985 // Conditionally launch create table for competency_modulecomp.
1986 if (!$dbman->table_exists($table)) {
1987 $dbman->create_table($table);
1988 }
1989
1990 // Main savepoint reached.
1991 upgrade_main_savepoint(true, 2016041500.66);
1992 }
1993
6ab41abd 1994 if ($oldversion < 2016042100.00) {
4ce09314
SL
1995 // Update all countries to upper case.
1996 $DB->execute("UPDATE {user} SET country = UPPER(country)");
1997 // Main savepoint reached.
6ab41abd 1998 upgrade_main_savepoint(true, 2016042100.00);
4ce09314 1999 }
f23e9b6b
CB
2000
2001 if ($oldversion < 2016042600.01) {
2002 $deprecatedwebservices = [
2003 'moodle_course_create_courses',
2004 'moodle_course_get_courses',
2005 'moodle_enrol_get_enrolled_users',
2006 'moodle_enrol_get_users_courses',
2007 'moodle_enrol_manual_enrol_users',
2008 'moodle_file_get_files',
2009 'moodle_file_upload',
2010 'moodle_group_add_groupmembers',
2011 'moodle_group_create_groups',
2012 'moodle_group_delete_groupmembers',
2013 'moodle_group_delete_groups',
2014 'moodle_group_get_course_groups',
2015 'moodle_group_get_groupmembers',
2016 'moodle_group_get_groups',
2017 'moodle_message_send_instantmessages',
2018 'moodle_notes_create_notes',
2019 'moodle_role_assign',
2020 'moodle_role_unassign',
2021 'moodle_user_create_users',
2022 'moodle_user_delete_users',
2023 'moodle_user_get_course_participants_by_id',
2024 'moodle_user_get_users_by_courseid',
2025 'moodle_user_get_users_by_id',
2026 'moodle_user_update_users',
2027 'core_grade_get_definitions',
2028 'core_user_get_users_by_id',
2029 'moodle_webservice_get_siteinfo',
2030 'mod_forum_get_forum_discussions'
2031 ];
2032
2033 list($insql, $params) = $DB->get_in_or_equal($deprecatedwebservices);
2034 $DB->delete_records_select('external_functions', "name $insql", $params);
2035 $DB->delete_records_select('external_services_functions', "functionname $insql", $params);
2036 // Main savepoint reached.
2037 upgrade_main_savepoint(true, 2016042600.01);
2038 }
2039
8de0b1ab
DW
2040 if ($oldversion < 2016051300.00) {
2041 // Add a default competency rating scale.
2042 make_competence_scale();
2043
2044 // Savepoint reached.
2045 upgrade_main_savepoint(true, 2016051300.00);
2046 }
2047
405b90bc
AG
2048 if ($oldversion < 2016051700.01) {
2049 // This script is included in each major version upgrade process (3.0, 3.1) so make sure we don't run it twice.
2050 if (empty($CFG->upgrade_letterboundarycourses)) {
41abbbbd 2051 // MDL-45390. If a grade is being displayed with letters and the grade boundaries are not being adhered to properly
405b90bc
AG
2052 // then this course will also be frozen.
2053 // If the changes are accepted then the display of some grades may change.
2054 // This is here to freeze the gradebook in affected courses.
2055 upgrade_course_letter_boundary();
2056
2057 // To skip running the same script on the upgrade to the next major version release.
2058 set_config('upgrade_letterboundarycourses', 1);
2059 }
2060 // Main savepoint reached.
2061 upgrade_main_savepoint(true, 2016051700.01);
2062 }
2063
4da854a6
EL
2064 // Moodle v3.1.0 release upgrade line.
2065 // Put any upgrade step following this.
2066
40a952bf 2067 if ($oldversion < 2016081700.00) {
6a4c2146
DM
2068
2069 // If someone is emotionally attached to it let's leave the config (basically the version) there.
2070 if (!file_exists($CFG->dirroot . '/report/search/classes/output/form.php')) {
2071 unset_all_config_for_plugin('report_search');
2072 }
2073
2074 // Savepoint reached.
40a952bf 2075 upgrade_main_savepoint(true, 2016081700.00);
6a4c2146
DM
2076 }
2077
4ae06911
AG
2078 if ($oldversion < 2016081700.02) {
2079 // Default schedule values.
2080 $hour = 0;
2081 $minute = 0;
2082
2083 // Get the old settings.
2084 if (isset($CFG->statsruntimestarthour)) {
2085 $hour = $CFG->statsruntimestarthour;
2086 }
2087 if (isset($CFG->statsruntimestartminute)) {
2088 $minute = $CFG->statsruntimestartminute;
2089 }
2090
2091 // Retrieve the scheduled task record first.
2092 $stattask = $DB->get_record('task_scheduled', array('component' => 'moodle', 'classname' => '\core\task\stats_cron_task'));
2093
2094 // Don't touch customised scheduling.
2095 if ($stattask && !$stattask->customised) {
2096
2097 $nextruntime = mktime($hour, $minute, 0, date('m'), date('d'), date('Y'));
2098 if ($nextruntime < $stattask->lastruntime) {
2099 // Add 24 hours to the next run time.
2100 $newtime = new DateTime();
2101 $newtime->setTimestamp($nextruntime);
2102 $newtime->add(new DateInterval('P1D'));
2103 $nextruntime = $newtime->getTimestamp();
2104 }
2105 $stattask->nextruntime = $nextruntime;
2106 $stattask->minute = $minute;
2107 $stattask->hour = $hour;
2108 $stattask->customised = 1;
2109 $DB->update_record('task_scheduled', $stattask);
2110 }
2111 // These settings are no longer used.
2112 unset_config('statsruntimestarthour');
2113 unset_config('statsruntimestartminute');
2114 unset_config('statslastexecution');
2115
2116 upgrade_main_savepoint(true, 2016081700.02);
2117 }
2118
cfbba4a9 2119 if ($oldversion < 2016082200.00) {
d7d4a097
JD
2120 // An upgrade step to remove any duplicate stamps, within the same context, in the question_categories table, and to
2121 // add a unique index to (contextid, stamp) to avoid future stamp duplication. See MDL-54864.
2122
2123 // Extend the execution time limit of the script to 2 hours.
2124 upgrade_set_timeout(7200);
2125
2126 // This SQL fetches the id of those records which have duplicate stamps within the same context.
2127 // This doesn't return the original record within the context, from which the duplicate stamps were likely created.
2128 $fromclause = "FROM (
2129 SELECT min(id) AS minid, contextid, stamp
2130 FROM {question_categories}
2131 GROUP BY contextid, stamp
2132 ) minid
2133 JOIN {question_categories} qc
2134 ON qc.contextid = minid.contextid AND qc.stamp = minid.stamp AND qc.id > minid.minid";
2135
2136 // Get the total record count - used for the progress bar.
2137 $countduplicatessql = "SELECT count(qc.id) $fromclause";
2138 $total = $DB->count_records_sql($countduplicatessql);
2139
2140 // Get the records themselves.
2141 $getduplicatessql = "SELECT qc.id $fromclause ORDER BY minid";
2142 $rs = $DB->get_recordset_sql($getduplicatessql);
2143
2144 // For each duplicate, update the stamp to a new random value.
2145 $i = 0;
2146 $pbar = new progress_bar('updatequestioncategorystamp', 500, true);
2147 foreach ($rs as $record) {
2148 // Generate a new, unique stamp and update the record.
2149 do {
2150 $newstamp = make_unique_id_code();
2151 } while (isset($usedstamps[$newstamp]));
2152 $usedstamps[$newstamp] = 1;
2153 $DB->set_field('question_categories', 'stamp', $newstamp, array('id' => $record->id));
2154
2155 // Update progress.
2156 $i++;
2157 $pbar->update($i, $total, "Updating duplicate question category stamp - $i/$total.");
2158 }
2159 unset($usedstamps);
2160
2161 // The uniqueness of each (contextid, stamp) pair is now guaranteed, so add the unique index to stop future duplicates.
2162 $table = new xmldb_table('question_categories');
2163 $index = new xmldb_index('contextidstamp', XMLDB_INDEX_UNIQUE, array('contextid', 'stamp'));
2164 if (!$dbman->index_exists($table, $index)) {
2165 $dbman->add_index($table, $index);
2166 }
2167
2168 // Savepoint reached.
cfbba4a9 2169 upgrade_main_savepoint(true, 2016082200.00);
d7d4a097
JD
2170 }
2171
644fcbb6
DW
2172 if ($oldversion < 2016091900.00) {
2173
2174 // Removing the themes from core.
2175 $themes = array('base', 'canvas');
2176
2177 foreach ($themes as $key => $theme) {
2178 if (check_dir_exists($CFG->dirroot . '/theme/' . $theme, false)) {
2179 // Ignore the themes that have been re-downloaded.
2180 unset($themes[$key]);
2181 }
2182 }
2183
2184 if (!empty($themes)) {
644fcbb6
DW
2185 // Hacky emulation of plugin uninstallation.
2186 foreach ($themes as $theme) {
2187 unset_all_config_for_plugin('theme_' . $theme);
2188 }
2189 }
2190
2191 // Main savepoint reached.
2192 upgrade_main_savepoint(true, 2016091900.00);
2193 }
2194
cecba1d9 2195 if ($oldversion < 2016091900.02) {
e7ba25f1
MG
2196
2197 // Define index attemptstepid-name (unique) to be dropped from question_attempt_step_data.
2198 $table = new xmldb_table('question_attempt_step_data');
2199 $index = new xmldb_index('attemptstepid-name', XMLDB_INDEX_UNIQUE, array('attemptstepid', 'name'));
2200
2201 // Conditionally launch drop index attemptstepid-name.
2202 if ($dbman->index_exists($table, $index)) {
2203 $dbman->drop_index($table, $index);
2204 }
2205
2206 // Main savepoint reached.
cecba1d9 2207 upgrade_main_savepoint(true, 2016091900.02);
e7ba25f1
MG
2208 }
2209
b8c241b1 2210 if ($oldversion < 2016100300.00) {
81c9e018
DP
2211 unset_config('enablecssoptimiser');
2212
b8c241b1 2213 upgrade_main_savepoint(true, 2016100300.00);
81c9e018
DP
2214 }
2215
adc77f07 2216 if ($oldversion < 2016100501.00) {
fbcdb0d7
DNA
2217
2218 // Define field enddate to be added to course.
2219 $table = new xmldb_table('course');
2220 $field = new xmldb_field('enddate', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'startdate');
2221
2222 // Conditionally launch add field enddate.
2223 if (!$dbman->field_exists($table, $field)) {
2224 $dbman->add_field($table, $field);
2225 }
2226
2227 // Main savepoint reached.
adc77f07 2228 upgrade_main_savepoint(true, 2016100501.00);
fbcdb0d7
DNA
2229 }
2230
c8303131 2231 if ($oldversion < 2016101100.00) {
3274d5ca
RW
2232 // Define field component to be added to message.
2233 $table = new xmldb_table('message');
f8e4145f 2234 $field = new xmldb_field('component', XMLDB_TYPE_CHAR, '100', null, null, null, null, 'timeusertodeleted');
3274d5ca
RW
2235
2236 // Conditionally launch add field component.
2237 if (!$dbman->field_exists($table, $field)) {
2238 $dbman->add_field($table, $field);
2239 }
2240
2241 // Define field eventtype to be added to message.
2242 $field = new xmldb_field('eventtype', XMLDB_TYPE_CHAR, '100', null, null, null, null, 'component');
2243
2244 // Conditionally launch add field eventtype.
2245 if (!$dbman->field_exists($table, $field)) {
2246 $dbman->add_field($table, $field);
2247 }
2248
f8e4145f 2249 // Main savepoint reached.
c8303131 2250 upgrade_main_savepoint(true, 2016101100.00);
f8e4145f
RW
2251 }
2252
69cbe359 2253
c8303131 2254 if ($oldversion < 2016101101.00) {
3274d5ca
RW
2255 // Define field component to be added to message_read.
2256 $table = new xmldb_table('message_read');
f8e4145f 2257 $field = new xmldb_field('component', XMLDB_TYPE_CHAR, '100', null, null, null, null, 'timeusertodeleted');
3274d5ca
RW
2258
2259 // Conditionally launch add field component.
2260 if (!$dbman->field_exists($table, $field)) {
2261 $dbman->add_field($table, $field);
2262 }
2263
2264 // Define field eventtype to be added to message_read.
2265 $field = new xmldb_field('eventtype', XMLDB_TYPE_CHAR, '100', null, null, null, null, 'component');
2266
2267 // Conditionally launch add field eventtype.
2268 if (!$dbman->field_exists($table, $field)) {
2269 $dbman->add_field($table, $field);
2270 }
2271
2272 // Main savepoint reached.
c8303131 2273 upgrade_main_savepoint(true, 2016101101.00);
3274d5ca
RW
2274 }
2275
0a51a209
DP
2276 if ($oldversion < 2016101401.00) {
2277 // Clean up repository_alfresco config unless plugin has been manually installed.
2278 if (!file_exists($CFG->dirroot . '/repository/alfresco/lib.php')) {
2279 // Remove capabilities.
2280 capabilities_cleanup('repository_alfresco');
2281 // Clean config.
2282 unset_all_config_for_plugin('repository_alfresco');
2283 }
2284
2285 // Savepoint reached.
2286 upgrade_main_savepoint(true, 2016101401.00);
2287 }
2288
4455ff2c 2289 if ($oldversion < 2016101401.02) {
69cbe359
JL
2290 $table = new xmldb_table('external_tokens');
2291 $field = new xmldb_field('privatetoken', XMLDB_TYPE_CHAR, '64', null, null, null, null);
2292
2293 // Conditionally add privatetoken field to the external_tokens table.
2294 if (!$dbman->field_exists($table, $field)) {
2295 $dbman->add_field($table, $field);
2296 }
326d8619 2297
69cbe359 2298 // Main savepoint reached.
4455ff2c 2299 upgrade_main_savepoint(true, 2016101401.02);
69cbe359
JL
2300 }
2301
4d27d62d 2302 if ($oldversion < 2016110202.00) {
159c2c91
AG
2303
2304 // Force uninstall of deleted authentication plugin.
2305 if (!file_exists("$CFG->dirroot/auth/radius")) {
2306 // Leave settings inplace if there are radius users.
2307 if (!$DB->record_exists('user', array('auth' => 'radius', 'deleted' => 0))) {
2308 // Remove all other associated config.
2309 unset_all_config_for_plugin('auth/radius');
2310 // The version number for radius is in this format.
2311 unset_all_config_for_plugin('auth_radius');
2312 }
2313 }
4d27d62d 2314 upgrade_main_savepoint(true, 2016110202.00);
159c2c91
AG
2315 }
2316
bc378b50 2317 if ($oldversion < 2016110300.00) {
9715f61a
AG
2318 // Remove unused admin email setting.
2319 unset_config('emailonlyfromreplyaddress');
2320
2321 // Main savepoint reached.
bc378b50 2322 upgrade_main_savepoint(true, 2016110300.00);
9715f61a
AG
2323 }
2324
b23b9a5b 2325 if ($oldversion < 2016110500.00) {
fab11235
MG
2326
2327 $oldplayers = [
2328 'vimeo' => null,
2329 'mp3' => ['.mp3'],
2330 'html5video' => ['.mov', '.mp4', '.m4v', '.mpeg', '.mpe', '.mpg', '.ogv', '.webm'],
2331 'flv' => ['.flv', '.f4v'],
2332 'html5audio' => ['.aac', '.flac', '.mp3', '.m4a', '.oga', '.ogg', '.wav'],
2333 'youtube' => null,
2334 'swf' => null,
2335 ];
2336
2337 // Convert hardcoded media players to the settings of the new media player plugin type.
2338 if (get_config('core', 'media_plugins_sortorder') === false) {
2339 $enabledplugins = [];
2340 $videoextensions = [];
2341 $audioextensions = [];
2342 foreach ($oldplayers as $oldplayer => $extensions) {
2343 $settingname = 'core_media_enable_'.$oldplayer;
2344 if (!empty($CFG->$settingname)) {
2345 if ($extensions) {
2346 // VideoJS will be used for all media files players that were used previously.
2347 $enabledplugins['videojs'] = 'videojs';
2348 if ($oldplayer === 'mp3' || $oldplayer === 'html5audio') {
2349 $audioextensions += array_combine($extensions, $extensions);
2350 } else {
2351 $videoextensions += array_combine($extensions, $extensions);
2352 }
2353 } else {
2354 // Enable youtube, vimeo and swf.
2355 $enabledplugins[$oldplayer] = $oldplayer;
2356 }
2357 }
2358 }
2359
2360 set_config('media_plugins_sortorder', join(',', $enabledplugins));
2361
2362 // Configure VideoJS to match the existing players set up.
2363 if ($enabledplugins['videojs']) {
2364 $enabledplugins[] = 'videojs';
2365 set_config('audioextensions', join(',', $audioextensions), 'media_videojs');
2366 set_config('videoextensions', join(',', $videoextensions), 'media_videojs');
2367 $useflash = !empty($CFG->core_media_enable_flv) || !empty($CFG->core_media_enable_mp3);
2368 set_config('useflash', $useflash, 'media_videojs');
2369 if (empty($CFG->core_media_enable_youtube)) {
2370 // Normally YouTube is enabled in videojs, but if youtube converter was disabled before upgrade
2371 // disable it in videojs as well.
2372 set_config('youtube', false, 'media_videojs');
2373 }
2374 }
2375 }
2376
2377 // Unset old settings.
2378 foreach ($oldplayers as $oldplayer => $extensions) {
2379 unset_config('core_media_enable_' . $oldplayer);
2380 }
2381
2382 // Preset defaults if CORE_MEDIA_VIDEO_WIDTH and CORE_MEDIA_VIDEO_HEIGHT are specified in config.php .
2383 // After this upgrade step these constants will not be used any more.
2384 if (defined('CORE_MEDIA_VIDEO_WIDTH')) {
2385 set_config('media_default_width', CORE_MEDIA_VIDEO_WIDTH);
2386 }
2387 if (defined('CORE_MEDIA_VIDEO_HEIGHT')) {
2388 set_config('media_default_height', CORE_MEDIA_VIDEO_HEIGHT);
2389 }
2390
2391 // Savepoint reached.
b23b9a5b 2392 upgrade_main_savepoint(true, 2016110500.00);
fab11235
MG
2393 }
2394
90abff01 2395 if ($oldversion < 2016110600.00) {
048f909b
JD
2396 // Define a field 'deletioninprogress' in the 'course_modules' table, to background deletion tasks.
2397 $table = new xmldb_table('course_modules');
2398 $field = new xmldb_field('deletioninprogress', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'availability');
2399
2400 // Conditionally launch add field 'deletioninprogress'.
2401 if (!$dbman->field_exists($table, $field)) {
2402 $dbman->add_field($table, $field);
2403 }
2404
2405 // Main savepoint reached.
90abff01 2406 upgrade_main_savepoint(true, 2016110600.00);
048f909b
JD
2407 }
2408
44c3d077 2409 if ($oldversion < 2016112200.01) {
51718b75
DW
2410
2411 // Define field requiredbytheme to be added to block_instances.
2412 $table = new xmldb_table('block_instances');
2413 $field = new xmldb_field('requiredbytheme', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, '0', 'showinsubcontexts');
2414
2415 // Conditionally launch add field requiredbytheme.
2416 if (!$dbman->field_exists($table, $field)) {
2417 $dbman->add_field($table, $field);
2418 }
2419
2420 // Main savepoint reached.
44c3d077 2421 upgrade_main_savepoint(true, 2016112200.01);
51718b75 2422 }
44c3d077 2423 if ($oldversion < 2016112200.02) {
45ed4271
DW
2424
2425 // Change the existing site level admin and settings blocks to be requiredbytheme which means they won't show in boost.
2426 $context = context_system::instance();
2427 $params = array('blockname' => 'settings', 'parentcontextid' => $context->id);
2428 $DB->set_field('block_instances', 'requiredbytheme', 1, $params);
2429
2430 $params = array('blockname' => 'navigation', 'parentcontextid' => $context->id);
2431 $DB->set_field('block_instances', 'requiredbytheme', 1, $params);
2432 // Main savepoint reached.
44c3d077 2433 upgrade_main_savepoint(true, 2016112200.02);
45ed4271 2434 }
51718b75 2435
75c57a08
EL
2436 // Automatically generated Moodle v3.2.0 release upgrade line.
2437 // Put any upgrade step following this.
2438
66b68d63 2439 if ($oldversion < 2016122800.00) {
b1eb88a4
AG
2440 // Find all roles with the coursecreator archetype.
2441 $coursecreatorroleids = $DB->get_records('role', array('archetype' => 'coursecreator'), '', 'id');
2442
2443 $context = context_system::instance();
2444 $capability = 'moodle/site:configview';
2445
2446 foreach ($coursecreatorroleids as $roleid => $notused) {
2447
2448 // Check that the capability has not already been assigned. If it has then it's either already set
2449 // to allow or specifically set to prohibit or prevent.
2450 if (!$DB->record_exists('role_capabilities', array('roleid' => $roleid, 'capability' => $capability))) {
2451 // Assign the capability.
2452 $cap = new stdClass();
2453 $cap->contextid = $context->id;
2454 $cap->roleid = $roleid;
2455 $cap->capability = $capability;
2456 $cap->permission = CAP_ALLOW;
2457 $cap->timemodified = time();
2458 $cap->modifierid = 0;
2459
2460 $DB->insert_record('role_capabilities', $cap);
2461 }
2462 }
b1eb88a4
AG
2463
2464 // Main savepoint reached.
66b68d63 2465 upgrade_main_savepoint(true, 2016122800.00);
b1eb88a4
AG
2466 }
2467
98be2d20
RW
2468 if ($oldversion < 2017020200.01) {
2469
2470 // Define index useridfrom_timeuserfromdeleted_notification (not unique) to be added to message.
2471 $table = new xmldb_table('message');
2472 $index = new xmldb_index('useridfrom_timeuserfromdeleted_notification', XMLDB_INDEX_NOTUNIQUE, array('useridfrom', 'timeuserfromdeleted', 'notification'));
2473
2474 // Conditionally launch add index useridfrom_timeuserfromdeleted_notification.
2475 if (!$dbman->index_exists($table, $index)) {
2476 $dbman->add_index($table, $index);
2477 }
2478
2479 // Define index useridto_timeusertodeleted_notification (not unique) to be added to message.
2480 $index = new xmldb_index('useridto_timeusertodeleted_notification', XMLDB_INDEX_NOTUNIQUE, array('useridto', 'timeusertodeleted', 'notification'));
2481
2482 // Conditionally launch add index useridto_timeusertodeleted_notification.
2483 if (!$dbman->index_exists($table, $index)) {
2484 $dbman->add_index($table, $index);
2485 }
2486
2487 $index = new xmldb_index('useridto', XMLDB_INDEX_NOTUNIQUE, array('useridto'));
2488
2489 // Conditionally launch drop index useridto.
2490 if ($dbman->index_exists($table, $index)) {
2491 $dbman->drop_index($table, $index);
2492 }
2493
2494 // Main savepoint reached.
2495 upgrade_main_savepoint(true, 2017020200.01);
2496 }
2497
2498 if ($oldversion < 2017020200.02) {
2499
2500 // Define index useridfrom_timeuserfromdeleted_notification (not unique) to be added to message_read.
2501 $table = new xmldb_table('message_read');
2502 $index = new xmldb_index('useridfrom_timeuserfromdeleted_notification', XMLDB_INDEX_NOTUNIQUE, array('useridfrom', 'timeuserfromdeleted', 'notification'));
2503
2504 // Conditionally launch add index useridfrom_timeuserfromdeleted_notification.
2505 if (!$dbman->index_exists($table, $index)) {
2506 $dbman->add_index($table, $index);
2507 }
2508
2509 // Define index useridto_timeusertodeleted_notification (not unique) to be added to message_read.
2510 $index = new xmldb_index('useridto_timeusertodeleted_notification', XMLDB_INDEX_NOTUNIQUE, array('useridto', 'timeusertodeleted', 'notification'));
2511
2512 // Conditionally launch add index useridto_timeusertodeleted_notification.
2513 if (!$dbman->index_exists($table, $index)) {
2514 $dbman->add_index($table, $index);
2515 }
2516
2517 $index = new xmldb_index('useridto', XMLDB_INDEX_NOTUNIQUE, array('useridto'));
2518
2519 // Conditionally launch drop index useridto.
2520 if ($dbman->index_exists($table, $index)) {
2521 $dbman->drop_index($table, $index);
2522 }
2523
2524 // Main savepoint reached.
2525 upgrade_main_savepoint(true, 2017020200.02);
2526 }
2527
a5722727
MG
2528 if ($oldversion < 2017020901.00) {
2529
2530 // Delete "orphaned" block positions. Note, the query does not use indexes (because there are none),
2531 // if it runs too long during upgrade you can comment this line - it will leave orphaned records
2532 // in the database but they won't bother you.
2533 upgrade_block_positions();
2534
2535 // Main savepoint reached.
2536 upgrade_main_savepoint(true, 2017020901.00);
2537 }
2538
f5af2e68 2539 if ($oldversion < 2017021300.00) {
83806582 2540 unset_config('loginpasswordautocomplete');
f5af2e68 2541 upgrade_main_savepoint(true, 2017021300.00);
83806582
JT
2542 }
2543
8341055e
MG
2544 if ($oldversion < 2017021400.00) {
2545 // Define field visibleoncoursepage to be added to course_modules.
2546 $table = new xmldb_table('course_modules');
2547 $field = new xmldb_field('visibleoncoursepage', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'visible');
2548
2549 // Conditionally launch add field visibleoncoursepage.
2550 if (!$dbman->field_exists($table, $field)) {
2551 $dbman->add_field($table, $field);
2552 }
2553
2554 // Main savepoint reached.
2555 upgrade_main_savepoint(true, 2017021400.00);
2556 }
2557
342af35a 2558 if ($oldversion < 2017030700.00) {
ca75ec4f
JP
2559
2560 // Define field priority to be added to event.
2561 $table = new xmldb_table('event');
2562 $field = new xmldb_field('priority', XMLDB_TYPE_INTEGER, '10', null, null, null, null, 'subscriptionid');
2563
2564 // Conditionally launch add field priority.
2565 if (!$dbman->field_exists($table, $field)) {
2566 $dbman->add_field($table, $field);
2567 }
2568
ca75ec4f 2569 // Main savepoint reached.
342af35a 2570 upgrade_main_savepoint(true, 2017030700.00);
ca75ec4f
JP
2571 }
2572
732bd131
DP
2573 if ($oldversion < 2017031400.00) {
2574
34df779a
AN
2575 // Define table file_conversion to be created.
2576 $table = new xmldb_table('file_conversion');
2577
2578 // Adding fields to table file_conversion.
2579 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2580 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
2581 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
2582 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
2583 $table->add_field('sourcefileid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
2584 $table->add_field('targetformat', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
2585 $table->add_field('status', XMLDB_TYPE_INTEGER, '10', null, null, null, '0');
2586 $table->add_field('statusmessage', XMLDB_TYPE_TEXT, null, null, null, null, null);
2587 $table->add_field('converter', XMLDB_TYPE_CHAR, '255', null, null, null, null);
2588 $table->add_field('destfileid', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
2589 $table->add_field('data', XMLDB_TYPE_TEXT, null, null, null, null, null);
2590
2591 // Adding keys to table file_conversion.
2592 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2593 $table->add_key('sourcefileid', XMLDB_KEY_FOREIGN, array('sourcefileid'), 'files', array('id'));
2594 $table->add_key('destfileid', XMLDB_KEY_FOREIGN, array('destfileid'), 'files', array('id'));
2595
2596 // Conditionally launch create table for file_conversion.
2597 if (!$dbman->table_exists($table)) {
2598 $dbman->create_table($table);
2599 }
2600
2601 // Main savepoint reached.
732bd131 2602 upgrade_main_savepoint(true, 2017031400.00);
34df779a
AN
2603 }
2604
2f090f46
EL
2605 if ($oldversion < 2017040400.00) {
2606
4671ae63 2607 // If block_course_overview is no longer present, replace with block_myoverview.
2f090f46
EL
2608 if (!file_exists($CFG->dirroot . '/blocks/course_overview/block_course_overview.php')) {
2609 $DB->set_field('block_instances', 'blockname', 'myoverview', array('blockname' => 'course_overview'));
2610 }
2611
2612 upgrade_main_savepoint(true, 2017040400.00);
2613 }
2614
2615 if ($oldversion < 2017040401.00) {
2616
4671ae63 2617 // If block_course_overview is no longer present, remove it.
2f090f46 2618 // Note - we do not need to completely remove the block context etc because we
4671ae63
RW
2619 // have replaced all occurrences of block_course_overview with block_myoverview
2620 // in the upgrade step above.
2f090f46
EL
2621 if (!file_exists($CFG->dirroot . '/blocks/course_overview/block_course_overview.php')) {
2622 // Delete the block from the block table.
2623 $DB->delete_records('block', array('name' => 'course_overview'));
2624 // Remove capabilities.
2625 capabilities_cleanup('block_course_overview');
2626 // Clean config.
2627 unset_all_config_for_plugin('block_course_overview');
2628 }
2629
2630 upgrade_main_savepoint(true, 2017040401.00);
2631 }
2632
2633 if ($oldversion < 2017040402.00) {
2634
2635 // Define fields to be added to the 'event' table.
2636 $table = new xmldb_table('event');
2637 $fieldtype = new xmldb_field('type', XMLDB_TYPE_INTEGER, '4', null, XMLDB_NOTNULL, null, 0, 'instance');
2638 $fieldtimesort = new xmldb_field('timesort', XMLDB_TYPE_INTEGER, '10', null, false, null, null, 'timeduration');
2639
2640 // Conditionally launch add field.
2641 if (!$dbman->field_exists($table, $fieldtype)) {
2642 $dbman->add_field($table, $fieldtype);
2643 }
2644
2645 // Conditionally launch add field.
2646 if (!$dbman->field_exists($table, $fieldtimesort)) {
2647 $dbman->add_field($table, $fieldtimesort);
2648 }
2649
2650 // Now, define the index we will be adding.
2651 $index = new xmldb_index('type-timesort', XMLDB_INDEX_NOTUNIQUE, array('type', 'timesort'));
2652
2653 // Conditionally launch add index.
2654 if (!$dbman->index_exists($table, $index)) {
2655 $dbman->add_index($table, $index);
2656 }
2657
2658 upgrade_main_savepoint(true, 2017040402.00);
2659 }
2660
2f090f46 2661 if ($oldversion < 2017040700.01) {
60237253 2662
2b09b2da 2663 // Define table oauth2_issuer to be created.
60237253
DW
2664 $table = new xmldb_table('oauth2_issuer');
2665
2666 // Adding fields to table oauth2_issuer.
2667 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2668 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
2669 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
2670 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
2671 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
2672 $table->add_field('image', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
2673 $table->add_field('baseurl', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
2674 $table->add_field('clientid', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
2675 $table->add_field('clientsecret', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
485a22fc
DW
2676 $table->add_field('loginscopes', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
2677 $table->add_field('loginscopesoffline', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
2678 $table->add_field('loginparams', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
2679 $table->add_field('loginparamsoffline', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
c21a66e4 2680 $table->add_field('alloweddomains', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
60237253
DW
2681 $table->add_field('scopessupported', XMLDB_TYPE_TEXT, null, null, null, null, null);
2682 $table->add_field('showonloginpage', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '1');
eca128bf 2683 $table->add_field('enabled', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '1');
60237253
DW
2684 $table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
2685
2686 // Adding keys to table oauth2_issuer.
2687 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2688
2689 // Conditionally launch create table for oauth2_issuer.
2690 if (!$dbman->table_exists($table)) {
2691 $dbman->create_table($table);
2692 }
2693
2694 // Main savepoint reached.
2f090f46 2695 upgrade_main_savepoint(true, 2017040700.01);
60237253
DW
2696 }
2697
2f090f46 2698 if ($oldversion < 2017040700.02) {
60237253
DW
2699
2700 // Define table oauth2_endpoint to be created.
2701 $table = new xmldb_table('oauth2_endpoint');
2702
2703 // Adding fields to table oauth2_endpoint.
2704 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2705 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
2706 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
2707 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
2708 $table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
2709 $table->add_field('url', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
2710 $table->add_field('issuerid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
2711
2712 // Adding keys to table oauth2_endpoint.
2713 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2714 $table->add_key('issuer_id_key', XMLDB_KEY_FOREIGN, array('issuerid'), 'oauth2_issuer', array('id'));
2715
2716 // Conditionally launch create table for oauth2_endpoint.
2717 if (!$dbman->table_exists($table)) {
2718 $dbman->create_table($table);
2719 }
2720
2721 // Main savepoint reached.
2f090f46 2722 upgrade_main_savepoint(true, 2017040700.02);
60237253
DW
2723 }
2724
2f090f46 2725 if ($oldversion < 2017040700.03) {
60237253
DW
2726
2727 // Define table oauth2_system_account to be created.
2728 $table = new xmldb_table('oauth2_system_account');
2729
2730 // Adding fields to table oauth2_system_account.
2731 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2732 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
2733 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
2734 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
2735 $table->add_field('issuerid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
2736 $table->add_field('refreshtoken', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
2737 $table->add_field('grantedscopes', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
28dddbc1
DW
2738 $table->add_field('username', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
2739 $table->add_field('email', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
60237253
DW
2740
2741 // Adding keys to table oauth2_system_account.
2742 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2743 $table->add_key('issueridkey', XMLDB_KEY_FOREIGN_UNIQUE, array('issuerid'), 'oauth2_issuer', array('id'));
2744
2745 // Conditionally launch create table for oauth2_system_account.
2746 if (!$dbman->table_exists($table)) {
2747 $dbman->create_table($table);
2748 }
2749
2750 // Main savepoint reached.
2f090f46 2751 upgrade_main_savepoint(true, 2017040700.03);
60237253
DW
2752 }
2753
2f090f46 2754 if ($oldversion < 2017040700.04) {
60237253 2755
2b09b2da 2756 // Define table oauth2_user_field_mapping to be created.
8445556b
DW
2757 $table = new xmldb_table('oauth2_user_field_mapping');
2758
2759 // Adding fields to table oauth2_user_field_mapping.
2760 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2761 $table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
2762 $table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
2763 $table->add_field('usermodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
2764 $table->add_field('issuerid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
2765 $table->add_field('externalfield', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null);
2766 $table->add_field('internalfield', XMLDB_TYPE_CHAR, '64', null, XMLDB_NOTNULL, null, null);
2767
2768 // Adding keys to table oauth2_user_field_mapping.
2769 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2770 $table->add_key('issuerkey', XMLDB_KEY_FOREIGN, array('issuerid'), 'oauth2_issuer', array('id'));
8445556b
DW
2771 $table->add_key('uniqinternal', XMLDB_KEY_UNIQUE, array('issuerid', 'internalfield'));
2772
2773 // Conditionally launch create table for oauth2_user_field_mapping.
2774 if (!$dbman->table_exists($table)) {
2775 $dbman->create_table($table);
2776 }
2777
60237253 2778 // Main savepoint reached.
2f090f46 2779 upgrade_main_savepoint(true, 2017040700.04);
e6661428
JP
2780 }
2781
7f53e8aa
MG
2782 if ($oldversion < 2017041801.00) {
2783
2784 // Define table course_completion_defaults to be created.
2785 $table = new xmldb_table('course_completion_defaults');
2786
2787 // Adding fields to table course_completion_defaults.
2788 $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
2789 $table->add_field('course', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
2790 $table->add_field('module', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
2791 $table->add_field('completion', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
2792 $table->add_field('completionview', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
2793 $table->add_field('completionusegrade', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
2794 $table->add_field('completionexpected', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
2795 $table->add_field('customrules', XMLDB_TYPE_TEXT, null, null, null, null, null);
2796
2797 // Adding keys to table course_completion_defaults.
2798 $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
2799 $table->add_key('module', XMLDB_KEY_FOREIGN, array('module'), 'modules', array('id'));
2800 $table->add_key('course', XMLDB_KEY_FOREIGN, array('course'), 'course', array('id'));
2801
2802 // Adding indexes to table course_completion_defaults.
2803 $table->add_index('coursemodule', XMLDB_INDEX_UNIQUE, array('course', 'module'));
2804
2805 // Conditionally launch create table for course_completion_defaults.
2806 if (!$dbman->table_exists($table)) {
2807 $dbman->create_table($table);
2808 }
2809
2810 upgrade_main_savepoint(true, 2017041801.00);
2811 }
2812
c3b1178d
JP
2813 if ($oldversion < 2017050500.01) {
2814 // Get the list of parent event IDs.
2815 $sql = "SELECT DISTINCT repeatid
2816 FROM {event}
2817 WHERE repeatid <> 0";
2818 $parentids = array_keys($DB->get_records_sql($sql));
2819 // Check if there are repeating events we need to process.
2820 if (!empty($parentids)) {
2821 // The repeat IDs of parent events should match their own ID.
2822 // So we need to update parent events that have non-matching IDs and repeat IDs.
2823 list($insql, $params) = $DB->get_in_or_equal($parentids);
2824 $updatesql = "UPDATE {event}
2825 SET repeatid = id
2826 WHERE id <> repeatid
2827 AND id $insql";
2828 $DB->execute($updatesql, $params);
2829 }
2830
2831 // Main savepoint reached.
2832 upgrade_main_savepoint(true, 2017050500.01);
2833 }
2834
021a1439
JD
2835 if ($oldversion < 2017050500.02) {
2836 // MDL-58684:
2837 // Remove all portfolio_tempdata records as these may contain serialized \file_system type objects, which are now unable to
2838 // be unserialized because of changes to the file storage API made in MDL-46375. Portfolio now stores an id reference to
2839 // files instead of the object.
2840 // These records are normally removed after a successful export, however, can be left behind if the user abandons the
2841 // export attempt (a stale record). Additionally, each stale record cannot be reused and is normally cleaned up by the cron
2842 // task core\task\portfolio_cron_task. Since the cron task tries to unserialize them, and generates a warning, we'll remove
2843 // all records here.
2844 $DB->delete_records_select('portfolio_tempdata', 'id > ?', [0]);
2845
2846 // Main savepoint reached.
2847 upgrade_main_savepoint(true, 2017050500.02);
2848 }
2849
79b80ee5
CB
2850 if ($oldversion < 2017050900.01) {
2851 // Create adhoc task for upgrading of existing calendar events.
2852 $record = new \stdClass();
2853 $record->classname = '\core\task\refresh_mod_calendar_events_task';
2854 $record->component = 'core';
2855
2856 // Next run time based from nextruntime computation in \core\task\manager::queue_adhoc_task().
2857 $nextruntime = time() - 1;
2858 $record->nextruntime = $nextruntime;
2859 $DB->insert_record('task_adhoc', $record);
2860
2861 // Main savepoint reached.
2862 upgrade_main_savepoint(true, 2017050900.01);
2863 }
2864
5e272283
EL
2865 // Automatically generated Moodle v3.3.0 release upgrade line.
2866 // Put any upgrade step following this.
2867
a52d3abb 2868 if ($oldversion < 2017061201.00) {
4ddf7c60
DG
2869 $table = new xmldb_table('course_sections');
2870 $field = new xmldb_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'availability');
2871
f25e2b1d 2872 // Define a field 'timemodified' in the 'course_sections' table.
4ddf7c60
DG
2873 if (!$dbman->field_exists($table, $field)) {
2874 $dbman->add_field($table, $field);
2875 }
2876
a52d3abb 2877 upgrade_main_savepoint(true, 2017061201.00);
4ddf7c60
DG
2878 }
2879
56990700 2880 if ($oldversion < 2017061301.00) {
c8f2e0e9
MN
2881 // Check if the value of 'navcourselimit' is set to the old default value, if so, change it to the new default.
2882 if ($CFG->navcourselimit == 20) {
2883 set_config('navcourselimit', 10);
2884 }
2885
2886 // Main savepoint reached.
56990700 2887 upgrade_main_savepoint(true, 2017061301.00);
c8f2e0e9
MN
2888 }
2889
a4cdd6d2 2890 return true;
51003653 2891}