-
Notifications
You must be signed in to change notification settings - Fork 99
/
upgrade.php
1876 lines (1818 loc) · 73.9 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
//Database and data storage upgrade script
//Call this script via the web as an admin each time you update the code
require_once 'migrator.php';
//don't use this anymore: create files in the /migrations/ directory
//old approach: change counter; increase by 1 each time a change is made
$latest_oldstyle = 119;
ini_set("max_execution_time", "6000");
if (isset($dbsetup) && $dbsetup==true) { //initial setup run from setupdb.php
//create dbscheme entry for DB ver
//store in the $latest_oldstyle, which matches the version in dbsetup
$stm = $DBH->prepare("INSERT INTO imas_dbschema (id,ver) VALUES (:id, :ver)");
$stm->execute(array(':id'=>1, ':ver'=>$latest_oldstyle));
$last = $latest_oldstyle;
//now we'll run the new-style migration stuff
} else { //called from web or cli - doing upgrade
$c = file_get_contents("config.php");
if (strpos($c, '$DBH')===false) {
echo '<p>The database connection mechanism has been updated to PDO. You will
need to revise your config.php before continuing to use the system.
In your existing config.php, remove everything below the line
<code>//no need to change anything from here on</code> and replace it
with the following code</p>
<pre>
/* Connecting, selecting database */
// MySQL with PDO_MYSQL
try {
$DBH = new PDO("mysql:host=$dbserver;dbname=$dbname", $dbusername, $dbpassword);
$DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
$GLOBALS["DBH"] = $DBH;
} catch(PDOException $e) {
die("Could not connect to database: " . $e->getMessage());
}
$DBH->query("set session sql_mode=\'\'");
unset($dbserver);
unset($dbusername);
unset($dbpassword);
</pre>
<p>On a production server, you may wish to set the PDO::ATTR_ERRMODE to PDO::ERRMODE_SILENT to hide database errors from users.</p>
<p>Run upgrade.php again after making those changes</p>';
exit;
}
//$use_local_sessions = true;
if (php_sapi_name() == 'cli') { //allow direct calling from command line
$init_skip_csrfp = true;
require_once "init_without_validate.php";
} else {
$init_skip_csrfp = true;
require_once "init.php";
if ($myrights<100) {
echo "No rights, aborting";
exit;
}
}
$stm = $DBH->query("SELECT ver FROM imas_dbschema WHERE id=1");
if ($stm===false || $stm->rowCount()==0) {//for upgrading older versions
$handle = @fopen("upgradecounter.txt",'r');
if ($handle===false) {
$last = 0;
} else if (isset($_GET['last'])) {
$last = floatval($_GET['last']);
fclose($handle);
} else {
$last = intval(trim(fgets($handle)));
fclose($handle);
}
} else {
$last = $stm->fetchColumn(0);
}
}
$DBH->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
/***
start older DB update stuff
***/
if ($last < 1) {
$query = "ALTER TABLE `imas_forums` CHANGE `settings` `settings` TINYINT( 2 ) UNSIGNED NOT NULL DEFAULT '0';";
$DBH->query($query);
$query = "ALTER TABLE `imas_forums` ADD `sortby` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';";
$DBH->query($query);
}
if ($last < 2) {
$query = " ALTER TABLE `imas_gbcats` CHANGE `chop` `chop` DECIMAL( 3, 2 ) UNSIGNED NOT NULL DEFAULT '1'";
$DBH->query($query);
}
if ($last < 3) {
$sql = 'CREATE TABLE `imas_forum_threads` (`id` INT(10) UNSIGNED NOT NULL, `forumid` INT(10) UNSIGNED NOT NULL, ';
$sql .= '`lastposttime` INT(10) UNSIGNED NOT NULL, `lastpostuser` INT(10) UNSIGNED NOT NULL, `views` INT(10) UNSIGNED NOT NULL, ';
$sql .= 'PRIMARY KEY (`id`), INDEX (`forumid`), INDEX(`lastposttime`)) COMMENT = \'Forum threads\'';
$DBH->query($sql);
$query = "INSERT INTO imas_forum_threads (id,forumid,lastpostuser,lastposttime) SELECT threadid,forumid,userid,max(postdate) FROM imas_forum_posts GROUP BY threadid";
$result = $DBH->query($query);
$query = "UPDATE imas_forum_threads ift, imas_forum_posts ifp SET ift.views=ifp.views WHERE ift.id=ifp.threadid AND ifp.parent=0";
$DBH->query($query);
$query = "ALTER TABLE `imas_exceptions` ADD `islatepass` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';";
$DBH->query($query);
}
if ($last < 4) {
$query = "ALTER TABLE `imas_assessments` ADD `endmsg` TEXT NOT NULL ;";
$DBH->query($query);
}
if ($last < 5) {
$query = "ALTER TABLE `imas_gbcats` ADD `hidden` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';";
$DBH->query($query);
$query = "UPDATE imas_gbscheme SET defaultcat=CONCAT(defaultcat,',0');";
$DBH->query($query);
$query = "ALTER TABLE `imas_gbscheme` CHANGE `defaultcat` `defaultcat` VARCHAR( 254 ) NOT NULL DEFAULT '0,0,1,0,-1,0'";
$DBH->query($query);
}
if ($last < 6) {
//add imas_tutors table
$query = 'CREATE TABLE `imas_tutors` (`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, `userid` INT(10) UNSIGNED NOT NULL, `courseid` INT(10) UNSIGNED NOT NULL, `section` VARCHAR(40) NOT NULL, INDEX (`userid`, `courseid`)) COMMENT = \'course tutors\'';
$DBH->query($query);
$query = 'ALTER TABLE `imas_students` CHANGE `section` `section` VARCHAR( 40 ) NULL DEFAULT NULL';
$DBH->query($query);
}
if ($last < 7) {
//for existing diag, put level2 selector as section
$query = "SELECT imas_students.id,imas_users.email FROM imas_students JOIN imas_users ON imas_users.id=imas_students.userid AND imas_users.SID LIKE '%~%~%'";
$stm = $DBH->query($query);
$stm2 = $DBH->prepare("UPDATE imas_students SET section=:section WHERE id=:id");
while ($row = $stm->fetch(PDO::FETCH_NUM)) {
$epts = explode('@',$row[1]);
$stm2->execute(array(':section'=>$epts[1], ':id'=>$row[0]));
}
}
if ($last < 8) {
//move existing tutors to new system
$query = "SELECT u.id,t.id,t.courseid FROM imas_users as u JOIN imas_teachers as t ON u.id=t.userid AND u.rights=15";
$stm = $DBH->query($query);
$lastuser = -1;
$stm2 = $DBH->prepare("UPDATE imas_users SET rights=10 WHERE id=:id");
$stm3 = $DBH->prepare("DELETE FROM imas_teachers WHERE id=:id");
$stm4 = $DBH->prepare("INSERT INTO imas_tutors (userid,courseid,section) VALUES (:userid, :courseid, '')");
while ($row = $stm->fetch(PDO::FETCH_NUM)) {
if ($row[0]!=$lastuser) {
$stm2->execute(array(':id'=>$row[0]));
$lastuser = $row[0];
}
$stm3->execute(array(':id'=>$row[1]));
$stm4->execute(array(':userid'=>$row[0], ':courseid'=>$row[2]));
}
}
if ($last < 9) {
//if postback
if (isset($_POST['diag'])) {
foreach ($_POST['diag'] as $did=>$uid) {
$stm = $DBH->prepare("UPDATE imas_diags SET ownerid=:ownerid WHERE id=:id");
$stm->execute(array(':ownerid'=>$uid, ':id'=>$did));
}
} else {
//change diag owner to userid from groupid
$ambig = false;
$out = '';
$query = "SELECT id,ownerid,name FROM imas_diags";
$stm = $DBH->query($query);
if ($stm->rowCount()>0) {
$owners = array();
$dnames = array();
while ($row = $stm->fetch(PDO::FETCH_NUM)) {
$owners[$row[1]][] = $row[0];
$dnames[$row[0]] = $row[2];
}
$ow = array_keys($owners);
$users = array();
$stm = $DBH->prepare("SELECT id,LastName,FirstName FROM imas_users WHERE groupid=:groupid AND rights>59 ORDER BY id");
foreach ($ow as $ogrp) {
$stm->execute(array(':groupid'=>$ogrp));
if ($stm->rowCount()==0) {
echo "Orphaned Diags: ".implode(',',$owners[$ogrp]).'<br/>';
} else if ($stm->rowCount()==1) {
$uid = $stm->fetchColumn(0);
$query = "UPDATE imas_diags SET ownerid=$uid WHERE id IN (".implode(',',$owners[$ogrp]).")";
$DBH->query($query);
} else {
$ops = '';
while ($row = $stm->fetch(PDO::FETCH_NUM)) {
$ops .= sprintf('<option value="%d">%s, %s</option>', $row[0],
Sanitize::encodeStringForDisplay($row[1]), Sanitize::encodeStringForDisplay($row[2]));
}
foreach ($owners[$ogrp] as $did) {
$out .= "Diag <b>".$dnames[$did]."</b> Owner: <select name=\"diag[$did]\">";
$out .= $ops;
$out .= "</select><br/>";
}
$ambig = true;
}
}
if ($ambig) {
echo "<form method=\"post\" action=\"upgrade.php\">";
echo "<p>Converting diagnostic ownership to userid. Ambiguous situations exist. Please select the ";
echo "appropriate owner for each diagnostic</p><p>";
echo $out;
echo '</p><input type="submit" value="Submit"/></form>';
//exit - will continue on postback
//update counter to 8, so will continue at 9 on submit, but won't redo earlier ones
$handle = fopen("upgradecounter.txt",'w');
fwrite($handle,8);
fclose($handle);
exit;
}
}
}
}
if ($last < 10) {
$query = "ALTER TABLE `imas_gbitems` ADD `tutoredit` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';";
$DBH->query($query);
}
if ($last < 11) {
$query = "ALTER TABLE `imas_assessments` ADD `tutoredit` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';";
$DBH->query($query);
$query = "ALTER TABLE `imas_students` ADD `locked` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';";
$DBH->query($query);
}
if ($last < 12) {
$query = "ALTER TABLE `imas_diags` ADD `reentrytime` SMALLINT( 5 ) UNSIGNED NOT NULL DEFAULT '0';";
$DBH->query($query);
}
if ($last < 13) {
$query = "CREATE TABLE `imas_diag_onetime` (
`id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`diag` INT( 10 ) UNSIGNED NOT NULL ,
`time` INT( 10 ) UNSIGNED NOT NULL ,
`code` VARCHAR( 9 ) NOT NULL ,
INDEX (`diag`), INDEX(`time`), INDEX(`code`)
) ENGINE = InnoDB ROW_FORMAT=DYNAMIC;";
$DBH->query($query);
}
if ($last < 14) {
$query = "ALTER TABLE `imas_forums` ADD `cntingb` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '1';";
$DBH->query($query);
}
if ($last < 15) {
$query = "ALTER TABLE `imas_linkedtext` ADD `target` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last < 16) {
$query = "ALTER TABLE `imas_forum_posts` CHANGE `points` `points` DECIMAL( 5, 1 ) UNSIGNED NULL DEFAULT NULL";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
echo "<p>SimpleLTI has been deprecated and replaced with BasicLTI. If you have enablesimplelti in your config.php, change it to enablebasiclti. ";
echo "If you do not have either currently in your config.php and want to allow imathas to act as a BasicLTI producer, add \$enablebasiclti = true to config.php</p>";
}
if ($last < 17) {
$query = "ALTER TABLE `imas_assessments` ADD `eqnhelper` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last < 18) {
$query = "ALTER TABLE `imas_courses` ADD `newflag` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last < 19) {
$query = "ALTER TABLE `imas_students` ADD `timelimitmult` DECIMAL(3,2) UNSIGNED NOT NULL DEFAULT '1.0';";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last < 20) {
$query = "ALTER TABLE `imas_assessments` ADD `caltag` CHAR( 2 ) NOT NULL DEFAULT '?R';";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last < 21) {
$query = "ALTER TABLE `imas_courses` ADD `showlatepass` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last < 22) {
$query = "ALTER TABLE `imas_assessments` ADD `showtips` TINYINT( 1 ) NOT NULL DEFAULT '1';";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last < 23) {
$query = 'CREATE TABLE `imas_stugroupset` ('
. ' `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, '
. ' `courseid` INT(10) UNSIGNED NOT NULL, '
. ' `name` VARCHAR(254) NOT NULL, '
. ' INDEX (`courseid`)'
. ' )'
. ' ENGINE = InnoDB ROW_FORMAT=DYNAMIC'
. ' COMMENT = \'Student Group Sets\';';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
echo '<p>imas_stugroupset created<br/>';
$query = 'CREATE TABLE `imas_stugroups` ('
. ' `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, '
. ' `groupsetid` INT(10) UNSIGNED NOT NULL, '
. ' `name` VARCHAR(254) NOT NULL, '
. ' INDEX (`groupsetid`)'
. ' )'
. ' ENGINE = InnoDB ROW_FORMAT=DYNAMIC'
. ' COMMENT = \'Student Groups\';';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
echo 'imas_stugroups created<br/>';
$query = 'CREATE TABLE `imas_stugroupmembers` ('
. ' `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, '
. ' `stugroupid` INT(10) UNSIGNED NOT NULL, '
. ' `userid` INT(10) UNSIGNED NOT NULL, '
. ' INDEX (`stugroupid`), INDEX (`userid`)'
. ' )'
. ' ENGINE = InnoDB ROW_FORMAT=DYNAMIC'
. ' COMMENT = \'Student Group Members\';';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
echo 'imas_stugroupmembers created<br/></p>';
echo '<p>It is now possible to specify a default course theme by setting $defaultcoursetheme = "theme.css"; in config.php</p>';
}
if ($last < 24) {
$query = "ALTER TABLE `imas_assessments` ADD `groupsetid` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0';";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = "ALTER TABLE `imas_forums` ADD `groupsetid` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0';";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
/*later (once groups are done)
$query = "ALTER TABLE `imas_forums` DROP COLUMN `grpaid`";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
*/
$query = "ALTER TABLE `imas_forum_threads` ADD `stugroupid` INT( 10 ) UNSIGNED NOT NULL DEFAULT '0';";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = "ALTER TABLE `imas_forum_threads` ADD INDEX(`stugroupid`);";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last < 25) {
$query = "ALTER TABLE `imas_libraries` ADD `sortorder` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '0';";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last < 26) {
$query = "ALTER TABLE `imas_users` ADD `homelayout` VARCHAR(32) NOT NULL DEFAULT '|0,1,2||0,1'";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last < 27) {
$query = "ALTER TABLE `imas_diag_onetime` ADD `goodfor` INT(10) NOT NULL DEFAULT '0'";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last < 28) {
$sql = 'CREATE TABLE `imas_wikis` ('
. ' `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, '
. ' `name` VARCHAR(50) NOT NULL, '
. ' `description` TEXT NOT NULL, '
. ' `courseid` INT(10) UNSIGNED NOT NULL, '
. ' `startdate` INT(10) UNSIGNED NOT NULL, '
. ' `editbydate` INT(10) UNSIGNED NOT NULL, '
. ' `enddate` INT(10) UNSIGNED NOT NULL, '
. ' `settings` TINYINT(2) UNSIGNED NOT NULL DEFAULT \'0\', '
. ' `groupsetid` INT(10) UNSIGNED NOT NULL DEFAULT \'0\', '
. ' `avail` TINYINT(1) UNSIGNED NOT NULL DEFAULT \'1\','
. ' INDEX (`courseid`), '
. ' INDEX(`avail`), INDEX(`startdate`), INDEX(`enddate`), INDEX(`editbydate`) '
. ' )'
. ' ENGINE = InnoDB ROW_FORMAT=DYNAMIC'
. ' COMMENT = \'Wikis\';';
$res = $DBH->query($sql);
if ($res===false) {
echo "<p>Query failed: ($sql) : ".$DBH->errorInfo()."</p>";
}
$sql = 'CREATE TABLE `imas_wiki_revisions` ('
. ' `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, '
. ' `wikiid` INT(10) UNSIGNED NOT NULL, '
. ' `stugroupid` INT(10) UNSIGNED NOT NULL DEFAULT \'0\', '
. ' `userid` INT(10) UNSIGNED NOT NULL, '
. ' `time` INT(10) UNSIGNED NOT NULL,'
. ' `revision` TEXT NOT NULL, '
. ' INDEX (`wikiid`), INDEX(`stugroupid`), INDEX(`time`) '
. ' )'
. ' ENGINE = InnoDB ROW_FORMAT=DYNAMIC'
. ' COMMENT = \'Wiki revisions\';';
$res = $DBH->query($sql);
if ($res===false) {
echo "<p>Query failed: ($sql) : ".$DBH->errorInfo()."</p>";
}
$sql = 'CREATE TABLE `imas_wiki_views` ('
. ' `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, '
. ' `userid` INT(10) UNSIGNED NOT NULL, '
. ' `wikiid` INT(10) UNSIGNED NOT NULL, '
. ' `lastview` INT(10) UNSIGNED NOT NULL,'
. ' INDEX (`userid`), INDEX(`wikiid`)'
. ' )'
. ' ENGINE = InnoDB ROW_FORMAT=DYNAMIC'
. ' COMMENT = \'Wiki last viewings\';';
$res = $DBH->query($sql);
if ($res===false) {
echo "<p>Query failed: ($sql) : ".$DBH->errorInfo()."</p>";
}
}
if ($last<29) {
//this is a bug fix for a typo in the homelayout default
$query = 'ALTER TABLE `imas_users` CHANGE `homelayout` `homelayout` VARCHAR( 32 ) NOT NULL DEFAULT \'|0,1,2||0,1\'';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = 'UPDATE `imas_users` SET homelayout = CONCAT(\'|0,1,2\',SUBSTR(homelayout,7))';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last<30) {
$query = "ALTER TABLE `imas_assessments` ADD `calrtag` VARCHAR(254) NOT NULL DEFAULT 'R';";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = "UPDATE imas_assessments SET calrtag=substring(caltag,2,1),caltag=substring(caltag,1,1)";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = 'ALTER TABLE `imas_assessments` CHANGE `caltag` `caltag` VARCHAR( 254 ) NOT NULL DEFAULT \'?\'';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = 'ALTER TABLE `imas_inlinetext` CHANGE `caltag` `caltag` VARCHAR( 254 ) NOT NULL DEFAULT \'!\'';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = 'ALTER TABLE `imas_linkedtext` CHANGE `caltag` `caltag` VARCHAR( 254 ) NOT NULL DEFAULT \'!\'';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = 'ALTER TABLE `imas_calitems` CHANGE `tag` `tag` VARCHAR( 254 ) NOT NULL';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last < 30.5) {
if (isset($GLOBALS['AWSkey'])) {
//update files. Need to update before changinge agroupids so we will know the curs3asid
$query = "SELECT id,agroupid,lastanswers,bestlastanswers,reviewlastanswers,assessmentid FROM imas_assessment_sessions ";
$query .= "WHERE lastanswers LIKE '%@FILE:%' OR bestlastanswers LIKE '%@FILE:%' OR reviewlastanswers LIKE '%@FILE:%'";
$stm = $DBH->query($query);
require_once "./includes/filehandler.php";
$s3 = new S3($GLOBALS['AWSkey'],$GLOBALS['AWSsecret']);
$doneagroups = array();
$stm2 = $DBH->prepare("UPDATE imas_assessment_sessions SET lastanswers=:lastanswers,bestlastanswers=:bestlastanswers,reviewlastanswers=:reviewlastanswers WHERE id=:id");
while ($row = $stm->fetch(PDO::FETCH_NUM)) {
//set path to aid/asid/ or aid/agroupid/ - won't interefere with random values, and easier to do.
if ($row[1]==0) {
$path = $row[5].'/'.$row[0];
$curs3asid = $row[0];
} else {
$path = $row[5].'/'.$row[1];
$curs3asid = $row[1];
}
if ($row[1]==0 || !in_array($row[1],$doneagroups)) {
preg_match_all('/@FILE:(.*?)@/',$row[2].$row[3].$row[4],$matches);
$tomove = array_unique($matches[1]);
foreach ($tomove as $file) {
if (@$s3->copyObject($GLOBALS['AWSbucket'],"adata/$curs3asid/$file",$GLOBALS['AWSbucket'],"adata/$path/$file")) {
@$s3->deleteObject($GLOBALS['AWSbucket'],"adata/$curs3asid/$file");
}
}
if ($row[1]>0) {
$doneagroups[] = $row[1];
}
}
$la = preg_replace('/@FILE:/',"@FILE:$path/",$row[2]);
$bla = preg_replace('/@FILE:/',"@FILE:$path/",$row[3]);
$rla = preg_replace('/@FILE:/',"@FILE:$path/",$row[4]);
$stm2->execute(array(':lastanswers'=>$la, ':bestlastanswers'=>$bla, ':reviewlastanswers'=>$rla, ':id'=>$row[0]));
}
echo 'Done up through s3 file change. <a href="upgrade.php?last=30.5">Continue</a>';
exit;
}
}
if ($last < 31) {
//implement groups changes
$stm = $DBH->query("SELECT courseid,id,name FROM imas_assessments WHERE isgroup>0");
$assessgrpset = array();
$stm2 = $DBH->prepare("INSERT INTO imas_stugroupset (courseid,name) VALUES (:courseid, :name)");
$stm3 = $DBH->prepare("UPDATE imas_assessments SET groupsetid=:groupsetid WHERE id=:id");
while ($row = $stm->fetch(PDO::FETCH_NUM)) {
$stm2->execute(array(':courseid'=>$row[0], ':name'=>"Group set for $row[2]"));
$assessgrpset[$row[1]] = $DBH->lastInsertId();
$stm3->execute(array(':groupsetid'=>$assessgrpset[$row[1]], ':id'=>$row[1]));
}
//identify student group relations
$stm = $DBH->query("SELECT userid,id,agroupid,assessmentid FROM imas_assessment_sessions WHERE agroupid>0");
$agroupusers = array();
$agroupaids = array();
while ($row = $stm->fetch(PDO::FETCH_NUM)) {
if (!isset($assessgrpset[$row[3]])) { //why would agroupid>0 and not isgroup>0?
continue;
}
if (!isset($agroupusers[$row[2]])) {
$agroupusers[$row[2]] = array();
}
$agroupusers[$row[2]][] = $row[0];
$agroupaids[$row[2]] = $row[3];
}
//create new student groups
$agroups = array_keys($agroupaids);
$agroupstugrp = array();
$userref = array();
foreach($agroups as $agroup) {
$stm = $DBH->prepare("INSERT INTO imas_stugroups (groupsetid,name) VALUES (:groupsetid,'Unnamed group')");
$stm->execute(array(':groupsetid'=>$assessgrpset[$agroupaids[$agroup]]));
$stugrp = $DBH->lastInsertId();
if (count($agroupusers[$agroup])>0) {
foreach ($agroupusers[$agroup] as $k=>$v) {
$agroupusers[$agroup][$k] = "($stugrp,$v)";
$userref[$v.'-'.$agroupaids[$agroup]] = $stugrp; //$userref[userid-aid] = stugrp
}
$query = "INSERT INTO imas_stugroupmembers (stugroupid,userid) VALUES ".implode(',',$agroupusers[$agroup]);
$DBH->query($query); //is DB INTs - safe
}
$stm = $DBH->prepare("UPDATE imas_assessment_sessions SET agroupid=:agroupid WHERE agroupid=:agroupid");
$stm->execute(array(':agroupid'=>$stugrp, ':agroupid'=>$agroup));
}
//update forums and forum posts for groups
$forumaid = array();
$stm = $DBH->query("SELECT id,grpaid FROM imas_forums WHERE grpaid>0");
$stm2 = $DBH->prepare("UPDATE imas_forums SET groupsetid=:groupsetid WHERE id=:id");
while ($row = $stm->fetch(PDO::FETCH_NUM)) {
$forumaid[$row[0]] = $row[1];
$stm2->execute(array(':groupsetid'=>$assessgrpset[$row[1]], ':id'=>$row[0]));
}
if (count($forumaid)>0) {
$forumlist = implode(',',array_keys($forumaid));
$query = "SELECT forumid,threadid,userid FROM imas_forum_posts WHERE forumid IN ($forumlist) AND parent=0";
$stm = $DBH->query($query); //is DB INTs - safe
$stm2 = $DBH->prepare("UPDATE imas_forum_threads SET stugroupid=:stugroupid WHERE id=:id");
while ($row = $stm->fetch(PDO::FETCH_NUM)) {
if (!isset($userref[$row[2].'-'.$forumaid[$row[0]]])) {
continue;
}
$stugrp = $userref[$row[2].'-'.$forumaid[$row[0]]];
$stm2->execute(array(':stugroupid'=>$stugrp, ':id'=>$row[1]));
}
}
}
if ($last<32) {
$query = "ALTER TABLE `imas_stugroupset` ADD `delempty` TINYINT( 1 ) UNSIGNED NOT NULL DEFAULT '1';";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = 'ALTER TABLE `imas_forums` CHANGE `name` `name` VARCHAR( 254 ) NOT NULL';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = 'ALTER TABLE `imas_wikis` CHANGE `name` `name` VARCHAR( 254 ) NOT NULL';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = 'ALTER TABLE `imas_gbitems` CHANGE `name` `name` VARCHAR( 254 ) NOT NULL';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last<33) {
$query = 'ALTER TABLE `imas_questionset` ADD `extref` TEXT NOT NULL DEFAULT \'\'';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last<34) {
$query = 'ALTER TABLE `imas_assessments` ADD `deffeedbacktext` VARCHAR( 512 ) NOT NULL DEFAULT \'\'';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last<35) {
$query = 'ALTER TABLE `imas_users` ADD `listperpage` TINYINT(3) UNSIGNED NOT NULL DEFAULT \'20\'';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last<36) {
$query = 'ALTER TABLE `imas_library_items` ADD `junkflag` TINYINT(1) UNSIGNED NOT NULL DEFAULT \'0\'';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last<37) {
$query = 'ALTER TABLE `imas_questionset` ADD `deleted` TINYINT(1) UNSIGNED NOT NULL DEFAULT \'0\'';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last<38) {
$query = 'ALTER TABLE `imas_forums` ADD `caltag` VARCHAR( 254 ) NOT NULL DEFAULT \'FP--FR\'';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last<39) {
$sql = 'CREATE TABLE `imas_rubrics` ('
. ' `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, '
. ' `ownerid` INT(10) UNSIGNED NOT NULL, '
. ' `groupid` INT(10) NOT NULL DEFAULT \'-1\', '
. ' `name` VARCHAR(254) NOT NULL, '
. ' `rubrictype` TINYINT(1) UNSIGNED NOT NULL DEFAULT \'0\', '
. ' `rubric` TEXT NOT NULL, '
. ' INDEX(`ownerid`), INDEX(`groupid`)'
. ' )'
. ' ENGINE = InnoDB ROW_FORMAT=DYNAMIC'
. ' COMMENT = \'Rubrics\';';
$res = $DBH->query($sql);
if ($res===false) {
echo "<p>Query failed: ($sql) : ".$DBH->errorInfo()."</p>";
}
$query = 'ALTER TABLE `imas_questions` ADD `rubric` INT(10) UNSIGNED NOT NULL DEFAULT \'0\'';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = 'ALTER TABLE `imas_gbitems` ADD `rubric` INT(10) UNSIGNED NOT NULL DEFAULT \'0\'';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last<40) {
$query = 'ALTER TABLE `imas_gbscheme` ADD `stugbmode` TINYINT(2) UNSIGNED NOT NULL DEFAULT \'5\'';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last<41) {
$query = 'ALTER TABLE `imas_grades` CHANGE `gbitemid` `gradetypeid` INT(10) NOT NULL';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = 'ALTER TABLE `imas_grades` ADD `refid` INT(10) UNSIGNED NOT NULL DEFAULT \'0\'';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = 'ALTER TABLE `imas_grades` ADD `gradetype` VARCHAR(15) NOT NULL DEFAULT \'offline\'';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = "ALTER TABLE `imas_grades` ADD INDEX(`gradetypeid`);";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = "ALTER TABLE `imas_grades` ADD INDEX(`gradetype`);";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = "ALTER TABLE `imas_grades` ADD INDEX(`refid`);";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = "SELECT id,forumid,userid,points FROM imas_forum_posts WHERE points IS NOT NULL";
$stm = $DBH->query($query);
$i = 0;
while ($row = $stm->fetch(PDO::FETCH_NUM)) {
if ($i%500==0) {
if ($i>0) {
$DBH->query($ins);
}
$ins = "INSERT INTO imas_grades (gradetype,gradetypeid,refid,userid,score) VALUES ";
} else {
$ins .= ",";
}
$ins .= "('forum',{$row[1]},{$row[0]},{$row[2]},{$row[3]})"; //is INTs - safe
$i++;
}
if ($i>0) {
$DBH->query($ins);
}
}
if ($last<42) {
$query = "ALTER TABLE `imas_questionset` ADD INDEX(`deleted`);";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last<43) {
$query = 'CREATE TABLE `imas_drillassess` (
`id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`courseid` INT( 10 ) UNSIGNED NOT NULL ,
`itemdescr` TEXT NOT NULL ,
`itemids` TEXT NOT NULL ,
`scoretype` CHAR( 3 ) NOT NULL ,
`showtype` TINYINT( 1 ) UNSIGNED NOT NULL ,
`n` SMALLINT( 5 ) UNSIGNED NOT NULL ,
`classbests` TEXT NOT NULL ,
`showtostu` TINYINT( 1 ) UNSIGNED NOT NULL ,
INDEX ( `courseid` )
) ENGINE = InnoDB ROW_FORMAT=DYNAMIC;';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = 'CREATE TABLE `imas_drillassess_sessions` (
`id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`drillassessid` INT( 10 ) UNSIGNED NOT NULL ,
`userid` INT( 10 ) UNSIGNED NOT NULL ,
`curitem` TINYINT( 3 ) NOT NULL ,
`seed` SMALLINT( 5 ) UNSIGNED NOT NULL ,
`curscores` TEXT NOT NULL ,
`starttime` INT( 10 ) UNSIGNED NOT NULL ,
`scorerec` TEXT NOT NULL ,
INDEX ( `drillassessid`), INDEX(`userid` )
) ENGINE = InnoDB ROW_FORMAT=DYNAMIC;';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last<44) {
//bug fix for wrong userid being recorded on forum grades
$query = "SELECT ig.id,ifp.userid FROM imas_grades AS ig JOIN imas_forum_posts AS ifp ";
$query .= "ON ig.gradetype='forum' AND ig.refid=ifp.id AND ifp.userid<>ig.userid";
$stm = $DBH->query($query);
$stm2 = $DBH->prepare("UPDATE imas_grades SET userid=:userid WHERE id=:id");
while ($row = $stm->fetch(PDO::FETCH_NUM)) {
$stm2->execute(array(':userid'=>$row[1], ':id'=>$row[0]));
}
}
if ($last < 45) {
$query = 'ALTER TABLE `imas_assessment_sessions` ADD `timeontask` TEXT NOT NULL';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = 'CREATE TABLE `imas_login_log` (
`id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`userid` INT( 10 ) UNSIGNED NOT NULL ,
`courseid` INT( 10 ) UNSIGNED NOT NULL ,
`logintime` INT( 10 ) UNSIGNED NOT NULL ,
INDEX(`userid` ), INDEX(`courseid`)
) ENGINE = InnoDB ROW_FORMAT=DYNAMIC;';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last < 46) {
$query = 'ALTER TABLE `imas_questionset` ADD `avgtime` SMALLINT(5) UNSIGNED NOT NULL DEFAULT \'0\'';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last < 47) {
$query = 'CREATE TABLE `imas_lti_courses` (
`id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`org` VARCHAR( 255 ) NOT NULL ,
`contextid` VARCHAR( 255 ) NOT NULL ,
`courseid` INT( 10 ) UNSIGNED NOT NULL ,
INDEX(`org`,`contextid`)
) ENGINE = InnoDB ROW_FORMAT=DYNAMIC;';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = 'CREATE TABLE `imas_lti_placements` (
`id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`org` VARCHAR( 255 ) NOT NULL ,
`contextid` VARCHAR( 255 ) NOT NULL ,
`linkid` VARCHAR( 255 ) NOT NULL ,
`typeid` INT( 10 ) UNSIGNED NOT NULL ,
`placementtype` VARCHAR( 10 ) NOT NULL ,
INDEX(`org`, `contextid`, `linkid`)
) ENGINE = InnoDB ROW_FORMAT=DYNAMIC;';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = 'ALTER TABLE `imas_assessment_sessions` ADD `lti_sourcedid` TEXT NOT NULL';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last < 48) {
$query = 'ALTER TABLE `imas_ltiusers` CHANGE `org` `org` VARCHAR( 254 ) NOT NULL';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = 'ALTER TABLE `imas_ltiusers` CHANGE `ltiuserid` `ltiuserid` VARCHAR( 254 ) NOT NULL';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last<49) {
$query = "ALTER TABLE `imas_login_log` ADD `lastaction` INT(10) UNSIGNED NOT NULL";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last<50) {
$query = "ALTER TABLE `imas_students` CHANGE `locked` `locked` INT(10) UNSIGNED NOT NULL";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = "ALTER TABLE `imas_gbscheme` ADD `colorize` VARCHAR (20) NOT NULL";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last < 51) {
$query = 'CREATE TABLE `imas_external_tools` (
`id` INT( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 255 ) NOT NULL ,
`url` VARCHAR( 255 ) NOT NULL ,
`ltikey` VARCHAR( 255 ) NOT NULL ,
`secret` VARCHAR( 255 ) NOT NULL ,
`custom` VARCHAR( 255 ) NOT NULL ,
`privacy` TINYINT( 1 ) UNSIGNED NOT NULL ,
`courseid` INT( 10 ) UNSIGNED NOT NULL ,
`groupid` INT( 10 ) UNSIGNED NOT NULL ,
INDEX ( `url` ), INDEX( `courseid` ), INDEX( `groupid` )
) ENGINE = InnoDB COMMENT = \'LTI external tools\'';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last < 52) {
$query = 'ALTER TABLE `imas_assessments` ADD `posttoforum` INT(10) UNSIGNED NOT NULL DEFAULT \'0\'';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = 'ALTER TABLE `imas_assessments` ADD `msgtoinstr` TINYINT(1) UNSIGNED NOT NULL DEFAULT \'0\'';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
//grab msg to instr settings and move to asssessments
$query = "SELECT id,msgset FROM imas_courses WHERE msgset>9";
$res = $DBH->query($query);
$stm = $DBH->prepare("UPDATE imas_assessments SET msgtoinstr=1 WHERE courseid=:courseid");
while ($row = $res->fetch(PDO::FETCH_NUM)) {
$stm->execute(array(':courseid'=>$row[0]));
}
$stm = $DBH->query("UPDATE imas_courses SET msgset=msgset-10 WHERE msgset>9");
}
if ($last<53) {
$query = "ALTER TABLE `imas_forums` ADD `forumtype` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0'";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = "ALTER TABLE `imas_forums` ADD `taglist` TEXT NOT NULL";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = "ALTER TABLE `imas_forum_posts` ADD `files` TEXT NOT NULL";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = "ALTER TABLE `imas_forum_posts` ADD `tag` VARCHAR(255) NOT NULL";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = "ALTER TABLE `imas_forum_posts` ADD INDEX(`tag`)";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last<54) {
$query = "UPDATE `imas_questionset` SET userights=4 WHERE userights=3";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last<55) {
$query = 'ALTER TABLE `imas_questionset` ADD `broken` TINYINT(1) UNSIGNED NOT NULL DEFAULT \'0\'';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last<56) {
$query = 'ALTER TABLE `imas_wiki_views` ADD `stugroupid` INT(10) UNSIGNED NOT NULL DEFAULT \'0\'';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
$query = "ALTER TABLE `imas_wiki_views` ADD INDEX(`stugroupid`);";
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}
}
if ($last<57) {
$query = 'ALTER TABLE `imas_questions` ADD `showhints` TINYINT(1) UNSIGNED NOT NULL DEFAULT \'0\'';
$res = $DBH->query($query);
if ($res===false) {
echo "<p>Query failed: ($query) : ".$DBH->errorInfo()."</p>";
}