mirrored from git://git.moodle.org/moodle.git
/
upgrade.php
2980 lines (2377 loc) · 131 KB
/
upgrade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file keeps track of upgrades to Moodle.
*
* Sometimes, changes between versions involve
* alterations to database structures and other
* major things that may break installations.
*
* The upgrade function in this file will attempt
* to perform all the necessary actions to upgrade
* your older installation to the current version.
*
* If there's something it cannot do itself, it
* will tell you what you need to do.
*
* The commands in here will all be database-neutral,
* using the methods of database_manager class
*
* Please do not forget to use upgrade_set_timeout()
* before any action that may take longer time to finish.
*
* @package core_install
* @category upgrade
* @copyright 2006 onwards Martin Dougiamas http://dougiamas.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Main upgrade tasks to be executed on Moodle version bump
*
* This function is automatically executed after one bump in the Moodle core
* version is detected. It's in charge of performing the required tasks
* to raise core from the previous version to the next one.
*
* It's a collection of ordered blocks of code, named "upgrade steps",
* each one performing one isolated (from the rest of steps) task. Usually
* tasks involve creating new DB objects or performing manipulation of the
* information for cleanup/fixup purposes.
*
* Each upgrade step has a fixed structure, that can be summarised as follows:
*
* if ($oldversion < XXXXXXXXXX.XX) {
* // Explanation of the update step, linking to issue in the Tracker if necessary
* upgrade_set_timeout(XX); // Optional for big tasks
* // Code to execute goes here, usually the XMLDB Editor will
* // help you here. See {@link http://docs.moodle.org/dev/XMLDB_editor}.
* upgrade_main_savepoint(true, XXXXXXXXXX.XX);
* }
*
* All plugins within Moodle (modules, blocks, reports...) support the existence of
* their own upgrade.php file, using the "Frankenstyle" component name as
* defined at {@link http://docs.moodle.org/dev/Frankenstyle}, for example:
* - {@link xmldb_page_upgrade($oldversion)}. (modules don't require the plugintype ("mod_") to be used.
* - {@link xmldb_auth_manual_upgrade($oldversion)}.
* - {@link xmldb_workshopform_accumulative_upgrade($oldversion)}.
* - ....
*
* In order to keep the contents of this file reduced, it's allowed to create some helper
* functions to be used here in the {@link upgradelib.php} file at the same directory. Note
* that such a file must be manually included from upgrade.php, and there are some restrictions
* about what can be used within it.
*
* For more information, take a look to the documentation available:
* - Data definition API: {@link http://docs.moodle.org/dev/Data_definition_API}
* - Upgrade API: {@link http://docs.moodle.org/dev/Upgrade_API}
*
* @param int $oldversion
* @return bool always true
*/
function xmldb_main_upgrade($oldversion) {
global $CFG, $DB;
require_once($CFG->libdir.'/db/upgradelib.php'); // Core Upgrade-related functions.
$dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes.
// Always keep this upgrade step with version being the minimum
// allowed version to upgrade from (v2.7.0 right now).
if ($oldversion < 2014051200) {
// Just in case somebody hacks upgrade scripts or env, we really can not continue.
echo("You need to upgrade to 2.7.x or higher first!\n");
exit(1);
// Note this savepoint is 100% unreachable, but needed to pass the upgrade checks.
upgrade_main_savepoint(true, 2014051200);
}
// MDL-32543 Make sure that the log table has correct length for action and url fields.
if ($oldversion < 2014051200.02) {
$table = new xmldb_table('log');
$columns = $DB->get_columns('log');
if ($columns['action']->max_length < 40) {
$index1 = new xmldb_index('course-module-action', XMLDB_INDEX_NOTUNIQUE, array('course', 'module', 'action'));
if ($dbman->index_exists($table, $index1)) {
$dbman->drop_index($table, $index1);
}
$index2 = new xmldb_index('action', XMLDB_INDEX_NOTUNIQUE, array('action'));
if ($dbman->index_exists($table, $index2)) {
$dbman->drop_index($table, $index2);
}
$field = new xmldb_field('action', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null, 'cmid');
$dbman->change_field_precision($table, $field);
$dbman->add_index($table, $index1);
$dbman->add_index($table, $index2);
}
if ($columns['url']->max_length < 100) {
$field = new xmldb_field('url', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'action');
$dbman->change_field_precision($table, $field);
}
upgrade_main_savepoint(true, 2014051200.02);
}
if ($oldversion < 2014060300.00) {
$gspath = get_config('assignfeedback_editpdf', 'gspath');
if ($gspath !== false) {
set_config('pathtogs', $gspath);
unset_config('gspath', 'assignfeedback_editpdf');
}
upgrade_main_savepoint(true, 2014060300.00);
}
if ($oldversion < 2014061000.00) {
// Fixing possible wrong MIME type for Publisher files.
$filetypes = array('%.pub'=>'application/x-mspublisher');
upgrade_mimetypes($filetypes);
upgrade_main_savepoint(true, 2014061000.00);
}
if ($oldversion < 2014062600.01) {
// We only want to delete DragMath if the directory no longer exists. If the directory
// is present then it means it has been restored, so do not perform the uninstall.
if (!check_dir_exists($CFG->libdir . '/editor/tinymce/plugins/dragmath', false)) {
// Purge DragMath plugin which is incompatible with GNU GPL license.
unset_all_config_for_plugin('tinymce_dragmath');
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2014062600.01);
}
// Switch the order of the fields in the files_reference index, to improve the performance of search_references.
if ($oldversion < 2014070100.00) {
$table = new xmldb_table('files_reference');
$index = new xmldb_index('uq_external_file', XMLDB_INDEX_UNIQUE, array('repositoryid', 'referencehash'));
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}
upgrade_main_savepoint(true, 2014070100.00);
}
if ($oldversion < 2014070101.00) {
$table = new xmldb_table('files_reference');
$index = new xmldb_index('uq_external_file', XMLDB_INDEX_UNIQUE, array('referencehash', 'repositoryid'));
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
upgrade_main_savepoint(true, 2014070101.00);
}
if ($oldversion < 2014072400.01) {
$table = new xmldb_table('user_devices');
$oldindex = new xmldb_index('pushid-platform', XMLDB_KEY_UNIQUE, array('pushid', 'platform'));
if ($dbman->index_exists($table, $oldindex)) {
$key = new xmldb_key('pushid-platform', XMLDB_KEY_UNIQUE, array('pushid', 'platform'));
$dbman->drop_key($table, $key);
}
upgrade_main_savepoint(true, 2014072400.01);
}
if ($oldversion < 2014080801.00) {
// Define index behaviour (not unique) to be added to question_attempts.
$table = new xmldb_table('question_attempts');
$index = new xmldb_index('behaviour', XMLDB_INDEX_NOTUNIQUE, array('behaviour'));
// Conditionally launch add index behaviour.
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2014080801.00);
}
if ($oldversion < 2014082900.01) {
// Fixing possible wrong MIME type for 7-zip and Rar files.
$filetypes = array(
'%.7z' => 'application/x-7z-compressed',
'%.rar' => 'application/x-rar-compressed');
upgrade_mimetypes($filetypes);
upgrade_main_savepoint(true, 2014082900.01);
}
if ($oldversion < 2014082900.02) {
// Replace groupmembersonly usage with new availability system.
$transaction = $DB->start_delegated_transaction();
if ($CFG->enablegroupmembersonly) {
// If it isn't already enabled, we need to enable availability.
if (!$CFG->enableavailability) {
set_config('enableavailability', 1);
}
// Count all course-modules with groupmembersonly set (for progress
// bar).
$total = $DB->count_records('course_modules', array('groupmembersonly' => 1));
$pbar = new progress_bar('upgradegroupmembersonly', 500, true);
// Get all these course-modules, one at a time.
$rs = $DB->get_recordset('course_modules', array('groupmembersonly' => 1),
'course, id');
$i = 0;
foreach ($rs as $cm) {
// Calculate and set new availability value.
$availability = upgrade_group_members_only($cm->groupingid, $cm->availability);
$DB->set_field('course_modules', 'availability', $availability,
array('id' => $cm->id));
// Update progress.
$i++;
$pbar->update($i, $total, "Upgrading groupmembersonly settings - $i/$total.");
}
$rs->close();
}
// Define field groupmembersonly to be dropped from course_modules.
$table = new xmldb_table('course_modules');
$field = new xmldb_field('groupmembersonly');
// Conditionally launch drop field groupmembersonly.
if ($dbman->field_exists($table, $field)) {
$dbman->drop_field($table, $field);
}
// Unset old config variable.
unset_config('enablegroupmembersonly');
$transaction->allow_commit();
upgrade_main_savepoint(true, 2014082900.02);
}
if ($oldversion < 2014100100.00) {
// Define table messageinbound_handlers to be created.
$table = new xmldb_table('messageinbound_handlers');
// Adding fields to table messageinbound_handlers.
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
$table->add_field('classname', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('defaultexpiration', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '86400');
$table->add_field('validateaddress', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1');
$table->add_field('enabled', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0');
// Adding keys to table messageinbound_handlers.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('classname', XMLDB_KEY_UNIQUE, array('classname'));
// Conditionally launch create table for messageinbound_handlers.
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
// Define table messageinbound_datakeys to be created.
$table = new xmldb_table('messageinbound_datakeys');
// Adding fields to table messageinbound_datakeys.
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('handler', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('datavalue', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('datakey', XMLDB_TYPE_CHAR, '64', null, null, null, null);
$table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('expires', XMLDB_TYPE_INTEGER, '10', null, null, null, null);
// Adding keys to table messageinbound_datakeys.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('handler_datavalue', XMLDB_KEY_UNIQUE, array('handler', 'datavalue'));
$table->add_key('handler', XMLDB_KEY_FOREIGN, array('handler'), 'messageinbound_handlers', array('id'));
// Conditionally launch create table for messageinbound_datakeys.
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2014100100.00);
}
if ($oldversion < 2014100600.01) {
// Define field aggregationstatus to be added to grade_grades.
$table = new xmldb_table('grade_grades');
$field = new xmldb_field('aggregationstatus', XMLDB_TYPE_CHAR, '10', null, XMLDB_NOTNULL, null, 'unknown', 'timemodified');
// Conditionally launch add field aggregationstatus.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
$field = new xmldb_field('aggregationweight', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null, 'aggregationstatus');
// Conditionally launch add field aggregationweight.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Define field aggregationcoef2 to be added to grade_items.
$table = new xmldb_table('grade_items');
$field = new xmldb_field('aggregationcoef2', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'aggregationcoef');
// Conditionally launch add field aggregationcoef2.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
$field = new xmldb_field('weightoverride', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'needsupdate');
// Conditionally launch add field weightoverride.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2014100600.01);
}
if ($oldversion < 2014100600.02) {
// Define field aggregationcoef2 to be added to grade_items_history.
$table = new xmldb_table('grade_items_history');
$field = new xmldb_field('aggregationcoef2', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, '0', 'aggregationcoef');
// Conditionally launch add field aggregationcoef2.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2014100600.02);
}
if ($oldversion < 2014100600.03) {
// Define field weightoverride to be added to grade_items_history.
$table = new xmldb_table('grade_items_history');
$field = new xmldb_field('weightoverride', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'decimals');
// Conditionally launch add field weightoverride.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2014100600.03);
}
if ($oldversion < 2014100600.04) {
// Set flags so we can display a notice on all courses that might
// be affected by the uprade to natural aggregation.
if (!get_config('grades_sumofgrades_upgrade_flagged', 'core')) {
// 13 == SUM_OF_GRADES.
$sql = 'SELECT DISTINCT courseid
FROM {grade_categories}
WHERE aggregation = ?';
$courses = $DB->get_records_sql($sql, array(13));
foreach ($courses as $course) {
set_config('show_sumofgrades_upgrade_' . $course->courseid, 1);
// Set each of the grade items to needing an update so that when the user visits the grade reports the
// figures will be updated.
$DB->set_field('grade_items', 'needsupdate', 1, array('courseid' => $course->courseid));
}
set_config('grades_sumofgrades_upgrade_flagged', 1);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2014100600.04);
}
if ($oldversion < 2014100700.00) {
// Define table messageinbound_messagelist to be created.
$table = new xmldb_table('messageinbound_messagelist');
// Adding fields to table messageinbound_messagelist.
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('messageid', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('address', XMLDB_TYPE_TEXT, null, null, XMLDB_NOTNULL, null, null);
$table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
// Adding keys to table messageinbound_messagelist.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
// Conditionally launch create table for messageinbound_messagelist.
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2014100700.00);
}
if ($oldversion < 2014100700.01) {
// Define field visible to be added to cohort.
$table = new xmldb_table('cohort');
$field = new xmldb_field('visible', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'descriptionformat');
// Conditionally launch add field visible.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2014100700.01);
}
if ($oldversion < 2014100800.00) {
// Remove qformat_learnwise (unless it has manually been added back).
if (!file_exists($CFG->dirroot . '/question/format/learnwise/format.php')) {
unset_all_config_for_plugin('qformat_learnwise');
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2014100800.00);
}
if ($oldversion < 2014101001.00) {
// Some blocks added themselves to the my/ home page, but they did not declare the
// subpage of the default my home page. While the upgrade script has been fixed, this
// upgrade script will fix the data that was wrongly added.
// We only proceed if we can find the right entry from my_pages. Private => 1 refers to
// the constant value MY_PAGE_PRIVATE.
if ($systempage = $DB->get_record('my_pages', array('userid' => null, 'private' => 1))) {
// Select the blocks there could have been automatically added. showinsubcontexts is hardcoded to 0
// because it is possible for administrators to have forced it on the my/ page by adding it to the
// system directly rather than updating the default my/ page.
$blocks = array('course_overview', 'private_files', 'online_users', 'badges', 'calendar_month', 'calendar_upcoming');
list($blocksql, $blockparams) = $DB->get_in_or_equal($blocks, SQL_PARAMS_NAMED);
$select = "parentcontextid = :contextid
AND pagetypepattern = :page
AND showinsubcontexts = 0
AND subpagepattern IS NULL
AND blockname $blocksql";
$params = array(
'contextid' => context_system::instance()->id,
'page' => 'my-index'
);
$params = array_merge($params, $blockparams);
$DB->set_field_select(
'block_instances',
'subpagepattern',
$systempage->id,
$select,
$params
);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2014101001.00);
}
if ($oldversion < 2014102000.00) {
// Define field aggregatesubcats to be dropped from grade_categories.
$table = new xmldb_table('grade_categories');
$field = new xmldb_field('aggregatesubcats');
// Conditionally launch drop field aggregatesubcats.
if ($dbman->field_exists($table, $field)) {
$sql = 'SELECT DISTINCT courseid
FROM {grade_categories}
WHERE aggregatesubcats = ?';
$courses = $DB->get_records_sql($sql, array(1));
foreach ($courses as $course) {
set_config('show_aggregatesubcats_upgrade_' . $course->courseid, 1);
// Set each of the grade items to needing an update so that when the user visits the grade reports the
// figures will be updated.
$DB->set_field('grade_items', 'needsupdate', 1, array('courseid' => $course->courseid));
}
$dbman->drop_field($table, $field);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2014102000.00);
}
if ($oldversion < 2014110300.00) {
// Run script restoring missing folder records for draft file areas.
upgrade_fix_missing_root_folders_draft();
// Main savepoint reached.
upgrade_main_savepoint(true, 2014110300.00);
}
// Moodle v2.8.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2014111000.00) {
// Coming from 2.7 or older, we need to flag the step minmaxgrade to be ignored.
set_config('upgrade_minmaxgradestepignored', 1);
// Coming from 2.7 or older, we need to flag the step for changing calculated grades to be regraded.
set_config('upgrade_calculatedgradeitemsonlyregrade', 1);
// Main savepoint reached.
upgrade_main_savepoint(true, 2014111000.00);
}
if ($oldversion < 2014120100.00) {
// Define field sslverification to be added to mnet_host.
$table = new xmldb_table('mnet_host');
$field = new xmldb_field('sslverification', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'applicationid');
// Conditionally launch add field sslverification.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2014120100.00);
}
if ($oldversion < 2014120101.00) {
// Define field component to be added to comments.
$table = new xmldb_table('comments');
$field = new xmldb_field('component', XMLDB_TYPE_CHAR, '255', null, null, null, null, 'contextid');
// Conditionally launch add field component.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2014120101.00);
}
if ($oldversion < 2014120102.00) {
// Define table user_password_history to be created.
$table = new xmldb_table('user_password_history');
// Adding fields to table user_password_history.
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('hash', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
// Adding keys to table user_password_history.
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
// Conditionally launch create table for user_password_history.
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2014120102.00);
}
if ($oldversion < 2015010800.01) {
// Make sure the private files handler is not set to expire.
$DB->set_field('messageinbound_handlers', 'defaultexpiration', 0,
array('classname' => '\core\message\inbound\private_files_handler'));
// Main savepoint reached.
upgrade_main_savepoint(true, 2015010800.01);
}
if ($oldversion < 2015012600.00) {
// If the site is using internal and external storage, or just external
// storage, and the external path specified is empty we change the setting
// to internal only. That is how the backup code is handling this
// misconfiguration.
$storage = (int) get_config('backup', 'backup_auto_storage');
$folder = get_config('backup', 'backup_auto_destination');
if ($storage !== 0 && empty($folder)) {
set_config('backup_auto_storage', 0, 'backup');
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015012600.00);
}
if ($oldversion < 2015012600.01) {
// Convert calendar_lookahead to nearest new value.
$value = $DB->get_field('config', 'value', array('name' => 'calendar_lookahead'));
if ($value > 90) {
set_config('calendar_lookahead', '120');
} else if ($value > 60 and $value < 90) {
set_config('calendar_lookahead', '90');
} else if ($value > 30 and $value < 60) {
set_config('calendar_lookahead', '60');
} else if ($value > 21 and $value < 30) {
set_config('calendar_lookahead', '30');
} else if ($value > 14 and $value < 21) {
set_config('calendar_lookahead', '21');
} else if ($value > 7 and $value < 14) {
set_config('calendar_lookahead', '14');
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015012600.01);
}
if ($oldversion < 2015021100.00) {
// Define field timemodified to be added to registration_hubs.
$table = new xmldb_table('registration_hubs');
$field = new xmldb_field('timemodified', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'secret');
// Conditionally launch add field timemodified.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015021100.00);
}
if ($oldversion < 2015022401.00) {
// Define index useridfromto (not unique) to be added to message.
$table = new xmldb_table('message');
$index = new xmldb_index('useridfromto', XMLDB_INDEX_NOTUNIQUE, array('useridfrom', 'useridto'));
// Conditionally launch add index useridfromto.
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
// Define index useridfromto (not unique) to be added to message_read.
$table = new xmldb_table('message_read');
$index = new xmldb_index('useridfromto', XMLDB_INDEX_NOTUNIQUE, array('useridfrom', 'useridto'));
// Conditionally launch add index useridfromto.
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015022401.00);
}
if ($oldversion < 2015022500.00) {
$table = new xmldb_table('user_devices');
$index = new xmldb_index('uuid-userid', XMLDB_INDEX_NOTUNIQUE, array('uuid', 'userid'));
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
upgrade_main_savepoint(true, 2015022500.00);
}
if ($oldversion < 2015030400.00) {
// We have long since switched to storing timemodified per hub rather than a single 'registered' timestamp.
unset_config('registered');
upgrade_main_savepoint(true, 2015030400.00);
}
if ($oldversion < 2015031100.00) {
// Unset old config variable.
unset_config('enabletgzbackups');
upgrade_main_savepoint(true, 2015031100.00);
}
if ($oldversion < 2015031400.00) {
// Define index useridfrom (not unique) to be dropped form message.
$table = new xmldb_table('message');
$index = new xmldb_index('useridfrom', XMLDB_INDEX_NOTUNIQUE, array('useridfrom'));
// Conditionally launch drop index useridfrom.
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}
// Define index useridfrom (not unique) to be dropped form message_read.
$table = new xmldb_table('message_read');
$index = new xmldb_index('useridfrom', XMLDB_INDEX_NOTUNIQUE, array('useridfrom'));
// Conditionally launch drop index useridfrom.
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015031400.00);
}
if ($oldversion < 2015031900.01) {
unset_config('crontime', 'registration');
upgrade_main_savepoint(true, 2015031900.01);
}
if ($oldversion < 2015032000.00) {
$table = new xmldb_table('badge_criteria');
$field = new xmldb_field('description', XMLDB_TYPE_TEXT, null, null, null, null, null);
// Conditionally add description field to the badge_criteria table.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
$field = new xmldb_field('descriptionformat', XMLDB_TYPE_INTEGER, 2, null, XMLDB_NOTNULL, null, 0);
// Conditionally add description format field to the badge_criteria table.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
upgrade_main_savepoint(true, 2015032000.00);
}
if ($oldversion < 2015040200.01) {
// Force uninstall of deleted tool.
if (!file_exists("$CFG->dirroot/$CFG->admin/tool/timezoneimport")) {
// Remove capabilities.
capabilities_cleanup('tool_timezoneimport');
// Remove all other associated config.
unset_all_config_for_plugin('tool_timezoneimport');
}
upgrade_main_savepoint(true, 2015040200.01);
}
if ($oldversion < 2015040200.02) {
// Define table timezone to be dropped.
$table = new xmldb_table('timezone');
// Conditionally launch drop table for timezone.
if ($dbman->table_exists($table)) {
$dbman->drop_table($table);
}
upgrade_main_savepoint(true, 2015040200.02);
}
if ($oldversion < 2015040200.03) {
if (isset($CFG->timezone) and $CFG->timezone == 99) {
// Migrate to real server timezone.
unset_config('timezone');
}
upgrade_main_savepoint(true, 2015040200.03);
}
if ($oldversion < 2015040700.01) {
$DB->delete_records('config_plugins', array('name' => 'requiremodintro'));
upgrade_main_savepoint(true, 2015040700.01);
}
if ($oldversion < 2015040900.01) {
// Add "My grades" to the user menu.
$oldconfig = get_config('core', 'customusermenuitems');
if (strpos("mygrades,grades|/grade/report/mygrades.php|grades", $oldconfig) === false) {
$newconfig = "mygrades,grades|/grade/report/mygrades.php|grades\n" . $oldconfig;
set_config('customusermenuitems', $newconfig);
}
upgrade_main_savepoint(true, 2015040900.01);
}
if ($oldversion < 2015040900.02) {
// Update the default user menu (add preferences, remove my files and my badges).
$oldconfig = get_config('core', 'customusermenuitems');
// Add "My preferences" at the end.
if (strpos($oldconfig, "mypreferences,moodle|/user/preference.php|preferences") === false) {
$newconfig = $oldconfig . "\nmypreferences,moodle|/user/preferences.php|preferences";
} else {
$newconfig = $oldconfig;
}
// Remove my files.
$newconfig = str_replace("myfiles,moodle|/user/files.php|download", "", $newconfig);
// Remove my badges.
$newconfig = str_replace("mybadges,badges|/badges/mybadges.php|award", "", $newconfig);
// Remove holes.
$newconfig = preg_replace('/\n+/', "\n", $newconfig);
$newconfig = preg_replace('/(\r\n)+/', "\n", $newconfig);
set_config('customusermenuitems', $newconfig);
upgrade_main_savepoint(true, 2015040900.02);
}
if ($oldversion < 2015050400.00) {
$config = get_config('core', 'customusermenuitems');
// Change "My preferences" in the user menu to "Preferences".
$config = str_replace("mypreferences,moodle|/user/preferences.php|preferences",
"preferences,moodle|/user/preferences.php|preferences", $config);
// Change "My grades" in the user menu to "Grades".
$config = str_replace("mygrades,grades|/grade/report/mygrades.php|grades",
"grades,grades|/grade/report/mygrades.php|grades", $config);
set_config('customusermenuitems', $config);
upgrade_main_savepoint(true, 2015050400.00);
}
if ($oldversion < 2015050401.00) {
// Make sure we have messages in the user menu because it's no longer in the nav tree.
$oldconfig = get_config('core', 'customusermenuitems');
$messagesconfig = "messages,message|/message/index.php|message";
$preferencesconfig = "preferences,moodle|/user/preferences.php|preferences";
// See if it exists.
if (strpos($oldconfig, $messagesconfig) === false) {
// See if preferences exists.
if (strpos($oldconfig, "preferences,moodle|/user/preferences.php|preferences") !== false) {
// Insert it before preferences.
$newconfig = str_replace($preferencesconfig, $messagesconfig . "\n" . $preferencesconfig, $oldconfig);
} else {
// Custom config - we can only insert it at the end.
$newconfig = $oldconfig . "\n" . $messagesconfig;
}
set_config('customusermenuitems', $newconfig);
}
upgrade_main_savepoint(true, 2015050401.00);
}
// Moodle v2.9.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2015060400.02) {
// Sites that were upgrading from 2.7 and older will ignore this step.
if (empty($CFG->upgrade_minmaxgradestepignored)) {
upgrade_minmaxgrade();
// Flags this upgrade step as already run to prevent it from running multiple times.
set_config('upgrade_minmaxgradestepignored', 1);
}
upgrade_main_savepoint(true, 2015060400.02);
}
if ($oldversion < 2015061900.00) {
// MDL-49257. Changed the algorithm of calculating automatic weights of extra credit items.
// Before the change, in case when grade category (in "Natural" agg. method) had items with
// overridden weights, the automatic weight of extra credit items was illogical.
// In order to prevent grades changes after the upgrade we need to freeze gradebook calculation
// for the affected courses.
// This script in included in each major version upgrade process so make sure we don't run it twice.
if (empty($CFG->upgrade_extracreditweightsstepignored)) {
upgrade_extra_credit_weightoverride();
// To skip running the same script on the upgrade to the next major release.
set_config('upgrade_extracreditweightsstepignored', 1);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015061900.00);
}
if ($oldversion < 2015062500.01) {
// MDL-48239. Changed calculated grade items so that the maximum and minimum grade can be set.
// If the changes are accepted and a regrade is done on the gradebook then some grades may change significantly.
// This is here to freeze the gradebook in affected courses.
// This script is included in each major version upgrade process so make sure we don't run it twice.
if (empty($CFG->upgrade_calculatedgradeitemsignored)) {
upgrade_calculated_grade_items();
// To skip running the same script on the upgrade to the next major release.
set_config('upgrade_calculatedgradeitemsignored', 1);
// This config value is never used again.
unset_config('upgrade_calculatedgradeitemsonlyregrade');
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015062500.01);
}
if ($oldversion < 2015081300.01) {
// Define field importtype to be added to grade_import_values.
$table = new xmldb_table('grade_import_values');
$field = new xmldb_field('importonlyfeedback', XMLDB_TYPE_INTEGER, '1', null, null, null, '0', 'importer');
// Conditionally launch add field importtype.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015081300.01);
}
if ($oldversion < 2015082400.00) {
// Define table webdav_locks to be dropped.
$table = new xmldb_table('webdav_locks');
// Conditionally launch drop table for webdav_locks.
if ($dbman->table_exists($table)) {
$dbman->drop_table($table);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015082400.00);
}
if ($oldversion < 2015090200.00) {
$table = new xmldb_table('message');
// Define the deleted fields to be added to the message tables.
$field1 = new xmldb_field('timeuserfromdeleted', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0',
'timecreated');
$field2 = new xmldb_field('timeusertodeleted', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0',
'timecreated');
$oldindex = new xmldb_index('useridfromto', XMLDB_INDEX_NOTUNIQUE,
array('useridfrom', 'useridto'));
$newindex = new xmldb_index('useridfromtodeleted', XMLDB_INDEX_NOTUNIQUE,
array('useridfrom', 'useridto', 'timeuserfromdeleted', 'timeusertodeleted'));
// Conditionally launch add field timeuserfromdeleted.
if (!$dbman->field_exists($table, $field1)) {
$dbman->add_field($table, $field1);
}
// Conditionally launch add field timeusertodeleted.
if (!$dbman->field_exists($table, $field2)) {
$dbman->add_field($table, $field2);
}
// Conditionally launch drop index useridfromto.
if ($dbman->index_exists($table, $oldindex)) {
$dbman->drop_index($table, $oldindex);
}
// Conditionally launch add index useridfromtodeleted.
if (!$dbman->index_exists($table, $newindex)) {
$dbman->add_index($table, $newindex);
}
// Now add them to the message_read table.
$table = new xmldb_table('message_read');
// Conditionally launch add field timeuserfromdeleted.
if (!$dbman->field_exists($table, $field1)) {
$dbman->add_field($table, $field1);
}
// Conditionally launch add field timeusertodeleted.
if (!$dbman->field_exists($table, $field2)) {
$dbman->add_field($table, $field2);
}
// Conditionally launch drop index useridfromto.
if ($dbman->index_exists($table, $oldindex)) {
$dbman->drop_index($table, $oldindex);
}
// Conditionally launch add index useridfromtodeleted.
if (!$dbman->index_exists($table, $newindex)) {
$dbman->add_index($table, $newindex);
}
// Main savepoint reached.
upgrade_main_savepoint(true, 2015090200.00);
}
if ($oldversion < 2015090801.00) {
// This upgrade script merges all tag instances pointing to the same course tag.
// User id is no longer used for those tag instances.