forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupgrade.php
4871 lines (3958 loc) · 219 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 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.
/**
*
* @global stdClass $CFG
* @global stdClass $USER
* @global moodle_database $DB
* @global core_renderer $OUTPUT
* @param int $oldversion
* @return bool
*/
function xmldb_main_upgrade($oldversion) {
global $CFG, $USER, $DB, $OUTPUT;
require_once($CFG->libdir.'/db/upgradelib.php'); // Core Upgrade-related functions
$dbman = $DB->get_manager(); // loads ddl manager and xmldb classes
////////////////////////////////////////
///upgrade supported only from 1.9.x ///
////////////////////////////////////////
if ($oldversion < 2008030600) {
//NOTE: this table was added much later later in dev cycle, but we need it here, upgrades from pre PR1 not supported
/// Define table upgrade_log to be created
$table = new xmldb_table('upgrade_log');
/// Adding fields to table upgrade_log
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('type', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null);
$table->add_field('plugin', XMLDB_TYPE_CHAR, '100', null, null, null, null);
$table->add_field('version', XMLDB_TYPE_CHAR, '100', null, null, null, null);
$table->add_field('info', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('details', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
$table->add_field('backtrace', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
/// Adding keys to table upgrade_log
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
/// Adding indexes to table upgrade_log
$table->add_index('timemodified', XMLDB_INDEX_NOTUNIQUE, array('timemodified'));
$table->add_index('type-timemodified', XMLDB_INDEX_NOTUNIQUE, array('type', 'timemodified'));
/// Create table for upgrade_log
$dbman->create_table($table);
/// Main savepoint reached
upgrade_main_savepoint(true, 2008030600);
}
if ($oldversion < 2008030601) {
//NOTE: this table was added much later later in dev cycle, but we need it here, upgrades from pre PR1 not supported
/// Define table log_queries to be created
$table = new xmldb_table('log_queries');
/// Adding fields to table log_queries
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('qtype', XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('sqltext', XMLDB_TYPE_TEXT, 'medium', null, XMLDB_NOTNULL, null, null);
$table->add_field('sqlparams', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
$table->add_field('error', XMLDB_TYPE_INTEGER, '5', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
$table->add_field('info', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
$table->add_field('backtrace', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
$table->add_field('exectime', XMLDB_TYPE_NUMBER, '10, 5', null, XMLDB_NOTNULL, null, null);
$table->add_field('timelogged', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
/// Adding keys to table log_queries
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
/// Conditionally launch create table for log_queries
$dbman->create_table($table);
/// Main savepoint reached
upgrade_main_savepoint(true, 2008030601);
}
if ($oldversion < 2008030602) {
@unlink($CFG->dataroot.'/cache/languages');
if (file_exists("$CFG->dataroot/lang")) {
// rename old lang directory so that the new and old langs do not mix
if (rename("$CFG->dataroot/lang", "$CFG->dataroot/oldlang")) {
$oldlang = "$CFG->dataroot/oldlang";
} else {
$oldlang = "$CFG->dataroot/lang";
}
} else {
$oldlang = '';
}
// TODO: fetch previously installed languages ("*_utf8") found in $oldlang from moodle.org
upgrade_set_timeout(60*20); // this may take a while
// TODO: add some info file to $oldlang describing what to do with "$oldlang/*_utf8_local" dirs
// Main savepoint reached
upgrade_main_savepoint(true, 2008030602);
}
if ($oldversion < 2008030700) {
upgrade_set_timeout(60*20); // this may take a while
/// Define index contextid-lowerboundary (not unique) to be dropped form grade_letters
$table = new xmldb_table('grade_letters');
$index = new xmldb_index('contextid-lowerboundary', XMLDB_INDEX_NOTUNIQUE, array('contextid', 'lowerboundary'));
/// Launch drop index contextid-lowerboundary
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}
/// Define index contextid-lowerboundary-letter (unique) to be added to grade_letters
$table = new xmldb_table('grade_letters');
$index = new xmldb_index('contextid-lowerboundary-letter', XMLDB_INDEX_UNIQUE, array('contextid', 'lowerboundary', 'letter'));
/// Launch add index contextid-lowerboundary-letter
$dbman->add_index($table, $index);
/// Main savepoint reached
upgrade_main_savepoint(true, 2008030700);
}
if ($oldversion < 2008050100) {
// Update courses that used weekscss to weeks
$DB->set_field('course', 'format', 'weeks', array('format' => 'weekscss'));
upgrade_main_savepoint(true, 2008050100);
}
if ($oldversion < 2008050200) {
// remove unused config options
unset_config('statsrolesupgraded');
upgrade_main_savepoint(true, 2008050200);
}
if ($oldversion < 2008050700) {
upgrade_set_timeout(60*20); // this may take a while
/// Fix minor problem caused by MDL-5482.
require_once($CFG->dirroot . '/question/upgrade.php');
question_fix_random_question_parents();
upgrade_main_savepoint(true, 2008050700);
}
if ($oldversion < 2008051201) {
echo $OUTPUT->notification('Increasing size of user idnumber field, this may take a while...', 'notifysuccess');
upgrade_set_timeout(60*20); // this may take a while
/// Under MySQL and Postgres... detect old NULL contents and change them by correct empty string. MDL-14859
$dbfamily = $DB->get_dbfamily();
if ($dbfamily === 'mysql' || $dbfamily === 'postgres') {
$DB->execute("UPDATE {user} SET idnumber = '' WHERE idnumber IS NULL");
}
/// Define index idnumber (not unique) to be dropped form user
$table = new xmldb_table('user');
$index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
/// Launch drop index idnumber
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}
/// Changing precision of field idnumber on table user to (255)
$table = new xmldb_table('user');
$field = new xmldb_field('idnumber', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, 'password');
/// Launch change of precision for field idnumber
$dbman->change_field_precision($table, $field);
/// Launch add index idnumber again
$index = new xmldb_index('idnumber', XMLDB_INDEX_NOTUNIQUE, array('idnumber'));
$dbman->add_index($table, $index);
/// Main savepoint reached
upgrade_main_savepoint(true, 2008051201);
}
if ($oldversion < 2008051202) {
$log_action = new object();
$log_action->module = 'course';
$log_action->action = 'unenrol';
$log_action->mtable = 'course';
$log_action->field = 'fullname';
if (!$DB->record_exists('log_display', array('action'=>'unenrol', 'module'=>'course'))) {
$DB->insert_record('log_display', $log_action);
}
upgrade_main_savepoint(true, 2008051202);
}
if ($oldversion < 2008051203) {
$table = new xmldb_table('mnet_enrol_course');
$field = new xmldb_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0);
$dbman->change_field_precision($table, $field);
upgrade_main_savepoint(true, 2008051203);
}
if ($oldversion < 2008063001) {
upgrade_set_timeout(60*20); // this may take a while
// table to be modified
$table = new xmldb_table('tag_instance');
// add field
$field = new xmldb_field('tiuserid');
if (!$dbman->field_exists($table, $field)) {
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, 0, 'itemid');
$dbman->add_field($table, $field);
}
// modify index
$index = new xmldb_index('itemtype-itemid-tagid');
$index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid'));
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}
$index = new xmldb_index('itemtype-itemid-tagid-tiuserid');
$index->set_attributes(XMLDB_INDEX_UNIQUE, array('itemtype', 'itemid', 'tagid', 'tiuserid'));
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
/// Main savepoint reached
upgrade_main_savepoint(true, 2008063001);
}
if ($oldversion < 2008070300) {
$DB->delete_records_select('role_names', $DB->sql_isempty('role_names', 'name', false, false));
upgrade_main_savepoint(true, 2008070300);
}
if ($oldversion < 2008070701) {
/// Define table portfolio_instance to be created
$table = new xmldb_table('portfolio_instance');
/// Adding fields to table portfolio_instance
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('plugin', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null);
$table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '1');
/// Adding keys to table portfolio_instance
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
/// Conditionally launch create table for portfolio_instance
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
/// Define table portfolio_instance_config to be created
$table = new xmldb_table('portfolio_instance_config');
/// Adding fields to table portfolio_instance_config
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
/// Adding keys to table portfolio_instance_config
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('instance', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id'));
/// Adding indexes to table portfolio_instance_config
$table->add_index('name', XMLDB_INDEX_NOTUNIQUE, array('name'));
/// Conditionally launch create table for portfolio_instance_config
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
/// Define table portfolio_instance_user to be created
$table = new xmldb_table('portfolio_instance_user');
/// Adding fields to table portfolio_instance_user
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null);
$table->add_field('instance', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
/// Adding keys to table portfolio_instance_user
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('instancefk', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id'));
$table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
/// Conditionally launch create table for portfolio_instance_user
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
/// Main savepoint reached
upgrade_main_savepoint(true, 2008070701);
}
if ($oldversion < 2008072400) {
/// Create the database tables for message_processors
$table = new xmldb_table('message_processors');
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('name', XMLDB_TYPE_CHAR, '166', null, XMLDB_NOTNULL, null, null);
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$dbman->create_table($table);
/// delete old and create new fields
$table = new xmldb_table('message');
$field = new xmldb_field('messagetype');
$dbman->drop_field($table, $field);
/// fields to rename
$field = new xmldb_field('message');
$field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
$dbman->rename_field($table, $field, 'fullmessage');
$field = new xmldb_field('format');
$field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, '0', null);
$dbman->rename_field($table, $field, 'fullmessageformat');
/// new message fields
$field = new xmldb_field('subject');
$field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
$dbman->add_field($table, $field);
$field = new xmldb_field('fullmessagehtml');
$field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null);
$dbman->add_field($table, $field);
$field = new xmldb_field('smallmessage');
$field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
$dbman->add_field($table, $field);
$table = new xmldb_table('message_read');
$field = new xmldb_field('messagetype');
$dbman->drop_field($table, $field);
$field = new xmldb_field('mailed');
$dbman->drop_field($table, $field);
/// fields to rename
$field = new xmldb_field('message');
$field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
$dbman->rename_field($table, $field, 'fullmessage');
$field = new xmldb_field('format');
$field->set_attributes(XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, null, null, '0', null);
$dbman->rename_field($table, $field, 'fullmessageformat');
/// new message fields
$field = new xmldb_field('subject');
$field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
$dbman->add_field($table, $field);
$field = new xmldb_field('fullmessagehtml');
$field->set_attributes(XMLDB_TYPE_TEXT, 'medium', null, null, null, null, null);
$dbman->add_field($table, $field);
$field = new xmldb_field('smallmessage');
$field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, null, null, null, null);
$dbman->add_field($table, $field);
/// new table
$table = new xmldb_table('message_working');
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('unreadmessageid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('processorid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$dbman->create_table($table);
upgrade_main_savepoint(true, 2008072400);
}
if ($oldversion < 2008072800) {
/// Define field enablecompletion to be added to course
$table = new xmldb_table('course');
$field = new xmldb_field('enablecompletion');
$field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'defaultrole');
/// Launch add field enablecompletion
if (!$dbman->field_exists($table,$field)) {
$dbman->add_field($table, $field);
}
/// Define field completion to be added to course_modules
$table = new xmldb_table('course_modules');
$field = new xmldb_field('completion');
$field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'groupmembersonly');
/// Launch add field completion
if (!$dbman->field_exists($table,$field)) {
$dbman->add_field($table, $field);
}
/// Define field completiongradeitemnumber to be added to course_modules
$field = new xmldb_field('completiongradeitemnumber');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null, 'completion');
/// Launch add field completiongradeitemnumber
if (!$dbman->field_exists($table,$field)) {
$dbman->add_field($table, $field);
}
/// Define field completionview to be added to course_modules
$field = new xmldb_field('completionview');
$field->set_attributes(XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completiongradeitemnumber');
/// Launch add field completionview
if (!$dbman->field_exists($table,$field)) {
$dbman->add_field($table, $field);
}
/// Define field completionexpected to be added to course_modules
$field = new xmldb_field('completionexpected');
$field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completionview');
/// Launch add field completionexpected
if (!$dbman->field_exists($table,$field)) {
$dbman->add_field($table, $field);
}
/// Define table course_modules_completion to be created
$table = new xmldb_table('course_modules_completion');
if (!$dbman->table_exists($table)) {
/// Adding fields to table course_modules_completion
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('coursemoduleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('completionstate', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('viewed', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null);
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
/// Adding keys to table course_modules_completion
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
/// Adding indexes to table course_modules_completion
$table->add_index('coursemoduleid', XMLDB_INDEX_NOTUNIQUE, array('coursemoduleid'));
$table->add_index('userid', XMLDB_INDEX_NOTUNIQUE, array('userid'));
/// Launch create table for course_modules_completion
$dbman->create_table($table);
}
/// Main savepoint reached
upgrade_main_savepoint(true, 2008072800);
}
if ($oldversion < 2008073000) {
/// Define table portfolio_log to be created
$table = new xmldb_table('portfolio_log');
/// Adding fields to table portfolio_log
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('time', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('portfolio', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('caller_class', XMLDB_TYPE_CHAR, '150', null, XMLDB_NOTNULL, null, null);
$table->add_field('caller_file', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('caller_sha1', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('tempdataid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
$table->add_field('returnurl', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('continueurl', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
/// Adding keys to table portfolio_log
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
$table->add_key('portfoliofk', XMLDB_KEY_FOREIGN, array('portfolio'), 'portfolio_instance', array('id'));
/// Conditionally launch create table for portfolio_log
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
/// Main savepoint reached
upgrade_main_savepoint(true, 2008073000);
}
if ($oldversion < 2008073104) {
/// Drop old table that might exist for some people
$table = new xmldb_table('message_providers');
if ($dbman->table_exists($table)) {
$dbman->drop_table($table);
}
/// Define table message_providers to be created
$table = new xmldb_table('message_providers');
/// Adding fields to table message_providers
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('name', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
$table->add_field('component', XMLDB_TYPE_CHAR, '200', null, XMLDB_NOTNULL, null, null);
$table->add_field('capability', XMLDB_TYPE_CHAR, '255', null, null, null, null);
/// Adding keys to table message_providers
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
/// Adding indexes to table message_providers
$table->add_index('componentname', XMLDB_INDEX_UNIQUE, array('component', 'name'));
/// Create table for message_providers
$dbman->create_table($table);
upgrade_main_savepoint(true, 2008073104);
}
if ($oldversion < 2008073111) {
/// Define table files to be created
$table = new xmldb_table('files');
/// Adding fields to table files
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('contenthash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null);
$table->add_field('pathnamehash', XMLDB_TYPE_CHAR, '40', null, XMLDB_NOTNULL, null, null);
$table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('component', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null);
$table->add_field('filearea', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, null);
$table->add_field('itemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('filepath', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('filename', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
$table->add_field('filesize', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('mimetype', XMLDB_TYPE_CHAR, '100', null, null, null, null);
$table->add_field('status', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
$table->add_field('source', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
$table->add_field('author', XMLDB_TYPE_CHAR, '255', null, null, null, null);
$table->add_field('license', XMLDB_TYPE_CHAR, '255', null, null, null, null);
$table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
/// Adding keys to table files
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('contextid', XMLDB_KEY_FOREIGN, array('contextid'), 'context', array('id'));
$table->add_key('userid', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
/// Adding indexes to table files
$table->add_index('component-filearea-contextid-itemid', XMLDB_INDEX_NOTUNIQUE, array('component', 'filearea', 'contextid', 'itemid'));
$table->add_index('contenthash', XMLDB_INDEX_NOTUNIQUE, array('contenthash'));
$table->add_index('pathnamehash', XMLDB_INDEX_UNIQUE, array('pathnamehash'));
/// Conditionally launch create table for files
$dbman->create_table($table);
/// Main savepoint reached
upgrade_main_savepoint(true, 2008073111);
}
if ($oldversion < 2008073112) {
// Define field legacyfiles to be added to course
$table = new xmldb_table('course');
$field = new xmldb_field('legacyfiles', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'maxbytes');
// Launch add field legacyfiles
$dbman->add_field($table, $field);
// enable legacy files in all courses
$DB->execute("UPDATE {course} SET legacyfiles = 2");
// Main savepoint reached
upgrade_main_savepoint(true, 2008073112);
}
if ($oldversion < 2008073113) {
/// move all course, backup and other files to new filepool based storage
upgrade_migrate_files_courses();
/// Main savepoint reached
upgrade_main_savepoint(true, 2008073113);
}
if ($oldversion < 2008073114) {
/// move all course, backup and other files to new filepool based storage
upgrade_migrate_files_blog();
/// Main savepoint reached
upgrade_main_savepoint(true, 2008073114);
}
if ($oldversion < 2008080400) {
// Add field ssl_jump_url to mnet application, and populate existing default applications
$table = new xmldb_table('mnet_application');
$field = new xmldb_field('sso_jump_url');
if (!$dbman->field_exists($table, $field)) {
$field->set_attributes(XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$dbman->add_field($table, $field);
$DB->set_field('mnet_application', 'sso_jump_url', '/auth/mnet/jump.php', array('name' => 'moodle'));
$DB->set_field('mnet_application', 'sso_jump_url', '/auth/xmlrpc/jump.php', array('name' => 'mahara'));
}
/// Main savepoint reached
upgrade_main_savepoint(true, 2008080400);
}
if ($oldversion < 2008080500) {
/// Define table portfolio_tempdata to be created
$table = new xmldb_table('portfolio_tempdata');
/// Adding fields to table portfolio_tempdata
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('data', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
$table->add_field('expirytime', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('instance', XMLDB_TYPE_INTEGER, '10', null, null, null, '0');
/// Adding keys to table portfolio_tempdata
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('userfk', XMLDB_KEY_FOREIGN, array('userid'), 'user', array('id'));
$table->add_key('instance', XMLDB_KEY_FOREIGN, array('instance'), 'portfolio_instance', array('id'));
/// Conditionally launch create table for portfolio_tempdata
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
/// Main savepoint reached
upgrade_main_savepoint(true, 2008080500);
}
if ($oldversion < 2008081500) {
/// Changing the type of all the columns that the question bank uses to store grades to be NUMBER(12, 7).
$table = new xmldb_table('question');
$field = new xmldb_field('defaultgrade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'generalfeedback');
$dbman->change_field_type($table, $field);
upgrade_main_savepoint(true, 2008081500);
}
if ($oldversion < 2008081501) {
$table = new xmldb_table('question');
$field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'defaultgrade');
$dbman->change_field_type($table, $field);
upgrade_main_savepoint(true, 2008081501);
}
if ($oldversion < 2008081502) {
$table = new xmldb_table('question_answers');
$field = new xmldb_field('fraction', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'answer');
$dbman->change_field_type($table, $field);
upgrade_main_savepoint(true, 2008081502);
}
if ($oldversion < 2008081503) {
$table = new xmldb_table('question_sessions');
$field = new xmldb_field('sumpenalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'newgraded');
$dbman->change_field_type($table, $field);
upgrade_main_savepoint(true, 2008081503);
}
if ($oldversion < 2008081504) {
$table = new xmldb_table('question_states');
$field = new xmldb_field('grade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'event');
$dbman->change_field_type($table, $field);
upgrade_main_savepoint(true, 2008081504);
}
if ($oldversion < 2008081505) {
$table = new xmldb_table('question_states');
$field = new xmldb_field('raw_grade', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'grade');
$dbman->change_field_type($table, $field);
upgrade_main_savepoint(true, 2008081505);
}
if ($oldversion < 2008081506) {
$table = new xmldb_table('question_states');
$field = new xmldb_field('penalty', XMLDB_TYPE_NUMBER, '12, 7', null, null, null, null, 'raw_grade');
$dbman->change_field_type($table, $field);
upgrade_main_savepoint(true, 2008081506);
}
if ($oldversion < 2008081600) {
/// all 1.9 sites and fresh installs must already be unicode, not needed anymore
unset_config('unicodedb');
/// Main savepoint reached
upgrade_main_savepoint(true, 2008081600);
}
if ($oldversion < 2008082602) {
/// Define table repository to be dropped
$table = new xmldb_table('repository');
/// Conditionally launch drop table for repository
if ($dbman->table_exists($table)) {
$dbman->drop_table($table);
}
/// Define table repository to be created
$table = new xmldb_table('repository');
/// Adding fields to table repository
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('type', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('visible', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, '1');
$table->add_field('sortorder', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
/// Adding keys to table repository
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
/// Conditionally launch create table for repository
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
/// Define table repository_instances to be created
$table = new xmldb_table('repository_instances');
/// Adding fields to table repository_instances
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('typeid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('userid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
$table->add_field('contextid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('username', XMLDB_TYPE_CHAR, '255', null, null, null, null);
$table->add_field('password', XMLDB_TYPE_CHAR, '255', null, null, null, null);
$table->add_field('timecreated', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
$table->add_field('timemodified', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
$table->add_field('readonly', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
/// Adding keys to table repository_instances
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
/// Conditionally launch create table for repository_instances
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
/// Define table repository_instance_config to be created
$table = new xmldb_table('repository_instance_config');
/// Adding fields to table repository_instance_config
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('instanceid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null);
$table->add_field('value', XMLDB_TYPE_TEXT, 'big', null, null, null, null);
/// Adding keys to table repository_instance_config
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
/// Conditionally launch create table for repository_instance_config
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
/// Main savepoint reached
upgrade_main_savepoint(true, 2008082602);
}
if ($oldversion < 2008082700) {
/// Add a new column to the question sessions table to record whether a
/// question has been flagged.
/// Define field flagged to be added to question_sessions
$table = new xmldb_table('question_sessions');
$field = new xmldb_field('flagged', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'manualcomment');
/// Conditionally launch add field flagged
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
/// Main savepoint reached
upgrade_main_savepoint(true, 2008082700);
}
if ($oldversion < 2008082900) {
/// Changing precision of field parent_type on table mnet_rpc to (20)
$table = new xmldb_table('mnet_rpc');
$field = new xmldb_field('parent_type', XMLDB_TYPE_CHAR, '20', null, XMLDB_NOTNULL, null, null, 'xmlrpc_path');
/// Launch change of precision for field parent_type
$dbman->change_field_precision($table, $field);
/// Main savepoint reached
upgrade_main_savepoint(true, 2008082900);
}
// MDL-16411 Move all plugintype_pluginname_version values from config to config_plugins.
if ($oldversion < 2008091000) {
foreach (get_object_vars($CFG) as $name => $value) {
if (substr($name, strlen($name) - 8) !== '_version') {
continue;
}
$pluginname = substr($name, 0, strlen($name) - 8);
if (!strpos($pluginname, '_')) {
// Skip things like backup_version that don't contain an extra _
continue;
}
if ($pluginname == 'enrol_ldap_version') {
// Special case - this is something different from a plugin version number.
continue;
}
if (!preg_match('/^\d{10}$/', $value)) {
// Extra safety check, skip anything that does not look like a Moodle
// version number (10 digits).
continue;
}
set_config('version', $value, $pluginname);
unset_config($name);
}
upgrade_main_savepoint(true, 2008091000);
}
if ($oldversion < 2008092300) {
unset_config('editorspelling');
unset_config('editordictionary');
/// Main savepoint reached
upgrade_main_savepoint(true, 2008092300);
}
if ($oldversion < 2008101300) {
if (!get_config(NULL, 'statsruntimedays')) {
set_config('statsruntimedays', '31');
}
/// Main savepoint reached
upgrade_main_savepoint(true, 2008101300);
}
/// Drop the deprecated teacher, teachers, student and students columns from the course table.
if ($oldversion < 2008111200) {
$table = new xmldb_table('course');
/// Conditionally launch drop field teacher
$field = new xmldb_field('teacher');
if ($dbman->field_exists($table, $field)) {
$dbman->drop_field($table, $field);
}
/// Conditionally launch drop field teacher
$field = new xmldb_field('teachers');
if ($dbman->field_exists($table, $field)) {
$dbman->drop_field($table, $field);
}
/// Conditionally launch drop field teacher
$field = new xmldb_field('student');
if ($dbman->field_exists($table, $field)) {
$dbman->drop_field($table, $field);
}
/// Conditionally launch drop field teacher
$field = new xmldb_field('students');
if ($dbman->field_exists($table, $field)) {
$dbman->drop_field($table, $field);
}
/// Main savepoint reached
upgrade_main_savepoint(true, 2008111200);
}
/// Add a unique index to the role.name column.
if ($oldversion < 2008111800) {
/// Define index name (unique) to be added to role
$table = new xmldb_table('role');
$index = new xmldb_index('name', XMLDB_INDEX_UNIQUE, array('name'));
/// Conditionally launch add index name
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
/// Main savepoint reached
upgrade_main_savepoint(true, 2008111800);
}
/// Add a unique index to the role.shortname column.
if ($oldversion < 2008111801) {
/// Define index shortname (unique) to be added to role
$table = new xmldb_table('role');
$index = new xmldb_index('shortname', XMLDB_INDEX_UNIQUE, array('shortname'));
/// Conditionally launch add index shortname
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
/// Main savepoint reached
upgrade_main_savepoint(true, 2008111801);
}
if ($oldversion < 2008120700) {
/// Changing precision of field shortname on table course_request to (100)
$table = new xmldb_table('course_request');
$field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'fullname');
/// Before changing the field, drop dependent indexes
/// Define index shortname (not unique) to be dropped form course_request
$index = new xmldb_index('shortname', XMLDB_INDEX_NOTUNIQUE, array('shortname'));
/// Conditionally launch drop index shortname
if ($dbman->index_exists($table, $index)) {
$dbman->drop_index($table, $index);
}
/// Launch change of precision for field shortname
$dbman->change_field_precision($table, $field);
/// After changing the field, recreate dependent indexes
/// Define index shortname (not unique) to be added to course_request
$index = new xmldb_index('shortname', XMLDB_INDEX_NOTUNIQUE, array('shortname'));
/// Conditionally launch add index shortname
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}
/// Main savepoint reached
upgrade_main_savepoint(true, 2008120700);
}
if ($oldversion < 2008120801) {
/// Changing precision of field shortname on table mnet_enrol_course to (100)
$table = new xmldb_table('mnet_enrol_course');
$field = new xmldb_field('shortname', XMLDB_TYPE_CHAR, '100', null, XMLDB_NOTNULL, null, null, 'fullname');
/// Launch change of precision for field shortname
$dbman->change_field_precision($table, $field);
/// Main savepoint reached
upgrade_main_savepoint(true, 2008120801);
}
if ($oldversion < 2008121701) {
/// Define field availablefrom to be added to course_modules
$table = new xmldb_table('course_modules');
$field = new xmldb_field('availablefrom', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'completionexpected');
/// Conditionally launch add field availablefrom
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
/// Define field availableuntil to be added to course_modules
$field = new xmldb_field('availableuntil', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'availablefrom');
/// Conditionally launch add field availableuntil
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
/// Define field showavailability to be added to course_modules
$field = new xmldb_field('showavailability', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'availableuntil');
/// Conditionally launch add field showavailability
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
/// Define table course_modules_availability to be created
$table = new xmldb_table('course_modules_availability');
/// Adding fields to table course_modules_availability
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('coursemoduleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null);
$table->add_field('sourcecmid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
$table->add_field('requiredcompletion', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null);
$table->add_field('gradeitemid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, null);
$table->add_field('grademin', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null);
$table->add_field('grademax', XMLDB_TYPE_NUMBER, '10, 5', null, null, null, null);
/// Adding keys to table course_modules_availability
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('coursemoduleid', XMLDB_KEY_FOREIGN, array('coursemoduleid'), 'course_modules', array('id'));
$table->add_key('sourcecmid', XMLDB_KEY_FOREIGN, array('sourcecmid'), 'course_modules', array('id'));
$table->add_key('gradeitemid', XMLDB_KEY_FOREIGN, array('gradeitemid'), 'grade_items', array('id'));
/// Conditionally launch create table for course_modules_availability
if (!$dbman->table_exists($table)) {
$dbman->create_table($table);
}
/// Changes to modinfo mean we need to rebuild course cache
require_once($CFG->dirroot . '/course/lib.php');
rebuild_course_cache(0, true);
/// Main savepoint reached
upgrade_main_savepoint(true, 2008121701);
}
if ($oldversion < 2009010500) {