forked from Kitware/CDash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupgrade.php
1582 lines (1373 loc) · 57.5 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
/*=========================================================================
Program: CDash - Cross-Platform Dashboard System
Module: $Id$
Language: PHP
Date: $Date$
Version: $Revision$
Copyright (c) 2002 Kitware, Inc. All rights reserved.
See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
include("cdash/config.php");
require_once("cdash/pdo.php");
include('login.php');
include_once("cdash/common.php");
include("cdash/version.php");
set_time_limit(0);
checkUserPolicy(@$_SESSION['cdash']['loginid'],0); // only admin
$xml = begin_XML_for_XSLT();
$xml .= "<backurl>user.php</backurl>";
$xml .= "<title>CDash - Maintenance</title>";
$xml .= "<menutitle>CDash</menutitle>";
$xml .= "<menusubtitle>Maintenance</menusubtitle>";
// Should be the database version not the current on
$version = pdo_query("SELECT major,minor FROM version");
$version_array = pdo_fetch_array($version);
$xml .= "<minversion>".$version_array['major'].".".$version_array['minor']."</minversion>";
@$CreateDefaultGroups = $_POST["CreateDefaultGroups"];
@$AssignBuildToDefaultGroups = $_POST["AssignBuildToDefaultGroups"];
@$FixBuildBasedOnRule = $_POST["FixBuildBasedOnRule"];
@$DeleteBuildsWrongDate = $_POST["DeleteBuildsWrongDate"];
@$CheckBuildsWrongDate = $_POST["CheckBuildsWrongDate"];
@$ComputeTestTiming = $_POST["ComputeTestTiming"];
@$ComputeUpdateStatistics = $_POST["ComputeUpdateStatistics"];
@$Upgrade = $_POST["Upgrade"];
@$Cleanup = $_POST["Cleanup"];
if(!isset($CDASH_DB_TYPE))
{
$db_type = 'mysql';
}
else
{
$db_type = $CDASH_DB_TYPE;
}
if(isset($_GET['upgrade-tables']))
{
// Apply all the patches
foreach(glob("sql/".$db_type."/cdash-upgrade-*.sql") as $filename)
{
$file_content = file($filename);
$query = "";
foreach($file_content as $sql_line)
{
$tsl = trim($sql_line);
if (($sql_line != "") && (substr($tsl, 0, 2) != "--") && (substr($tsl, 0, 1) != "#"))
{
$query .= $sql_line;
if(preg_match("/;\s*$/", $sql_line))
{
$query = str_replace(";", "", "$query");
$result = pdo_query($query);
if (!$result)
{
if($db_type != "pgsql") // postgresql < 9.1 doesn't know CREATE TABLE IF NOT EXISTS so we don't die
{
die(pdo_error());
}
}
$query = "";
}
}
} // end for each line
} // end for each upgrade file
return;
}
if(isset($_GET['upgrade-0-8']))
{
// Add the index if they don't exist
$querycrc32 = pdo_query("SELECT crc32 FROM coveragefile LIMIT 1");
if(!$querycrc32)
{
pdo_query("ALTER TABLE coveragefile ADD crc32 int(11)");
pdo_query("ALTER TABLE coveragefile ADD INDEX (crc32)");
}
// Compression the coverage
CompressCoverage();
return;
}
if(isset($_GET['upgrade-1-0']))
{
$description = pdo_query("SELECT description FROM buildgroup LIMIT 1");
if(!$description)
{
pdo_query("ALTER TABLE buildgroup ADD description text");
}
$cvsviewertype = pdo_query("SELECT cvsviewertype FROM project LIMIT 1");
if(!$cvsviewertype)
{
pdo_query("ALTER TABLE project ADD cvsviewertype varchar(10)");
}
if(pdo_query("ALTER TABLE site2user DROP PRIMARY KEY"))
{
pdo_query("ALTER TABLE site2user ADD INDEX (siteid)");
pdo_query("ALTER TABLE build ADD INDEX (starttime)");
}
// Add test timing as well as key 'name' for test
$timestatus = pdo_query("SELECT timestatus FROM build2test LIMIT 1");
if(!$timestatus)
{
pdo_query("ALTER TABLE build2test ADD timemean float(7,2) default '0.00'");
pdo_query("ALTER TABLE build2test ADD timestd float(7,2) default '0.00'");
pdo_query("ALTER TABLE build2test ADD timestatus tinyint(4) default '0'");
pdo_query("ALTER TABLE build2test ADD INDEX (timestatus)");
// Add timing test fields in the table project
pdo_query("ALTER TABLE project ADD testtimestd float(3,1) default '4.0'");
// Add the index name in the table test
pdo_query("ALTER TABLE test ADD INDEX (name)");
}
// Add the testtimethreshold
if(!pdo_query("SELECT testtimestdthreshold FROM project LIMIT 1"))
{
pdo_query("ALTER TABLE project ADD testtimestdthreshold float(3,1) default '1.0'");
}
// Add an option to show the testtime or not
if(!pdo_query("SELECT showtesttime FROM project LIMIT 1"))
{
pdo_query("ALTER TABLE project ADD showtesttime tinyint(4) default '0'");
}
return;
}
if(isset($_GET['upgrade-1-2']))
{
// Replace the field 'output' in the table test from 'text' to 'mediumtext'
$result = pdo_query("SELECT output FROM test LIMIT 1");
$type = pdo_field_type($result,0);
if($type == "blob" || $type == "text")
{
$result = pdo_query("ALTER TABLE test CHANGE output output MEDIUMTEXT");
}
// Change the file from blob to longblob
$result = pdo_query("SELECT file FROM coveragefile LIMIT 1");
$length = mysql_field_len($result, 0);
if($length == 65535)
{
$result = pdo_query("ALTER TABLE coveragefile CHANGE file file LONGBLOB");
}
// Compress the notes
if(!pdo_query("SELECT crc32 FROM note LIMIT 1"))
{
CompressNotes();
}
// Change the dates for the groups from 0000-00-00 to 1000-01-01
// This is for mySQL
pdo_query("UPDATE buildgroup SET starttime='1980-01-01 00:00:00' WHERE starttime='0000-00-00 00:00:00'");
pdo_query("UPDATE buildgroup SET endtime='1980-01-01 00:00:00' WHERE endtime='0000-00-00 00:00:00'");
pdo_query("UPDATE build2grouprule SET starttime='1980-01-01 00:00:00' WHERE starttime='0000-00-00 00:00:00'");
pdo_query("UPDATE build2grouprule SET endtime='1980-01-01 00:00:00' WHERE endtime='0000-00-00 00:00:00'");
pdo_query("UPDATE buildgroupposition SET starttime='1980-01-01 00:00:00' WHERE starttime='0000-00-00 00:00:00'");
pdo_query("UPDATE buildgroupposition SET endtime='1980-01-01 00:00:00' WHERE endtime='0000-00-00 00:00:00'");
pdo_query("ALTER TABLE buildgroup MODIFY starttime timestamp NOT NULL default '1980-01-01 00:00:00'");
pdo_query("ALTER TABLE buildgroup MODIFY endtime timestamp NOT NULL default '1980-01-01 00:00:00'");
pdo_query("ALTER TABLE build2grouprule MODIFY starttime timestamp NOT NULL default '1980-01-01 00:00:00'");
pdo_query("ALTER TABLE build2grouprule MODIFY endtime timestamp NOT NULL default '1980-01-01 00:00:00'");
pdo_query("ALTER TABLE buildgroupposition MODIFY starttime timestamp NOT NULL default '1980-01-01 00:00:00'");
pdo_query("ALTER TABLE buildgroupposition MODIFY endtime timestamp NOT NULL default '1980-01-01 00:00:00'");
// Add fields in the project table
$timestatus = pdo_query("SELECT testtimemaxstatus FROM project LIMIT 1");
if(!$timestatus)
{
pdo_query("ALTER TABLE project ADD testtimemaxstatus tinyint(4) default '3'");
pdo_query("ALTER TABLE project ADD emailmaxitems tinyint(4) default '5'");
pdo_query("ALTER TABLE project ADD emailmaxchars int(11) default '255'");
}
// Add summary email
$summaryemail = pdo_query("SELECT summaryemail FROM buildgroup LIMIT 1");
if(!$summaryemail)
{
if($CDASH_DB_TYPE == "pgsql")
{
pdo_query("ALTER TABLE \"buildgroup\" ADD \"summaryemail\" smallint DEFAULT '0'");
}
else
{
pdo_query("ALTER TABLE buildgroup ADD summaryemail tinyint(4) default '0'");
}
}
// Add emailcategory
$emailcategory = pdo_query("SELECT emailcategory FROM user2project LIMIT 1");
if(!$emailcategory)
{
if($CDASH_DB_TYPE == "pgsql")
{
pdo_query("ALTER TABLE \"user2project\" ADD \"emailcategory\" smallint DEFAULT '62'");
}
else
{
pdo_query("ALTER TABLE user2project ADD emailcategory tinyint(4) default '62'");
}
}
return;
}
// Helper function to alter a table
function AddTableField($table,$field,$mySQLType,$pgSqlType,$default)
{
include("cdash/config.php");
$sql = '';
if($default !== false)
{
$sql = " DEFAULT '".$default."'";
}
$query = pdo_query("SELECT ".$field." FROM ".$table." LIMIT 1");
if(!$query)
{
add_log("Adding $field to $table","AddTableField");
if($CDASH_DB_TYPE == "pgsql")
{
pdo_query("ALTER TABLE \"".$table."\" ADD \"".$field."\" ".$pgSqlType.$sql);
}
else
{
pdo_query("ALTER TABLE ".$table." ADD ".$field." ".$mySQLType.$sql);
}
add_last_sql_error("AddTableField");
add_log("Done adding $field to $table","AddTableField");
}
}
/** Remove a table field */
function RemoveTableField($table,$field)
{
include("cdash/config.php");
$query = pdo_query("SELECT ".$field." FROM ".$table." LIMIT 1");
if($query)
{
add_log("Droping $field from $table","DropTableField");
if($CDASH_DB_TYPE == "pgsql")
{
pdo_query("ALTER TABLE \"".$table."\" DROP COLUMN \"".$field."\"");
}
else
{
pdo_query("ALTER TABLE ".$table." DROP ".$field);
}
add_last_sql_error("DropTableField");
add_log("Done droping $field from $table","DropTableField");
}
}
// Rename a table vield
function RenameTableField($table,$field,$newfield,$mySQLType,$pgSqlType,$default)
{
include("cdash/config.php");
$query = pdo_query("SELECT ".$field." FROM ".$table." LIMIT 1");
if($query)
{
add_log("Changing $field to $newfield for $table","RenameTableField");
if($CDASH_DB_TYPE == "pgsql")
{
pdo_query("ALTER TABLE \"".$table."\" RENAME \"".$field."\" TO \"".$newfield."\"");
pdo_query("ALTER TABLE \"".$table."\" ALTER COLUMN \"".$newfield."\" TYPE ".$pgSqlType);
pdo_query("ALTER TABLE \"".$table."\" ALTER COLUMN \"".$newfield."\" SET DEFAULT ".$default);
}
else
{
pdo_query("ALTER TABLE ".$table." CHANGE ".$field." ".$newfield." ".$mySQLType." DEFAULT '".$default."'");
add_last_sql_error("RenameTableField");
}
add_log("Done renaming $field to $newfield for $table","RenameTableField");
}
}
// Helper function to add an index to a table
function AddTableIndex($table,$field)
{
include("cdash/config.php");
if(!pdo_check_index_exists($table,$field))
{
add_log("Adding index $field to $table","AddTableIndex");
if($CDASH_DB_TYPE == "pgsql")
{
@pdo_query("CREATE INDEX ".$table."_".$field."_idx ON \"".$table."\" (\"".$field."\")");
}
else
{
pdo_query("ALTER TABLE ".$table." ADD INDEX ( ".$field." )");
add_last_sql_error("AddTableIndex");
}
add_log("Done adding index $field to $table","AddTableIndex");
}
}
// Helper function to remove an index to a table
function RemoveTableIndex($table,$field)
{
include("cdash/config.php");
if(pdo_check_index_exists($table,$field))
{
add_log("Removing index $field from $table","RemoveTableIndex");
if($CDASH_DB_TYPE == "pgsql")
{
pdo_query("DROP INDEX ".$table."_".$field."_idx");
}
else
{
pdo_query("ALTER TABLE ".$table." DROP INDEX ".$field);
}
add_log("Done removing index $field from $table","RemoveTableIndex");
add_last_sql_error("RemoveTableIndex");
}
}
// Helper function to modify a table
function ModifyTableField($table,$field,$mySQLType,$pgSqlType,$default,$notnull,$autoincrement)
{
include("cdash/config.php");
//$check = pdo_query("SELECT ".$field." FROM ".$table." LIMIT 1");
//$type = pdo_field_type($check,0);
//add_log($type,"ModifyTableField");
if(1)
{
add_log("Modifying $field to $table","ModifyTableField");
if($CDASH_DB_TYPE == "pgsql")
{
// ALTER TABLE "buildfailureargument" ALTER COLUMN "argument" TYPE VARCHAR( 255 );
// ALTER TABLE "buildfailureargument" ALTER COLUMN "argument" SET NOT NULL;
// ALTER TABLE "dynamicanalysisdefect" ALTER COLUMN "value" SET DEFAULT 0;
pdo_query("ALTER TABLE \"".$table."\" ALTER COLUMN \"".$field."\" TYPE ".$pgSqlType);
if($notnull)
{
pdo_query("ALTER TABLE \"".$table."\" ALTER COLUMN \"".$field."\" SET NOT NULL");
}
if(strlen($default)>0)
{
pdo_query("ALTER TABLE \"".$table."\" ALTER COLUMN \"".$field."\" SET DEFAULT ".$default);
}
if($autoincrement)
{
pdo_query("DROP INDEX \"".$table."_".$field."_idx\"");
pdo_query("ALTER TABLE \"".$table."\" ADD PRIMARY KEY (\"".$field."\")");
pdo_query("CREATE SEQUENCE \"".$table."_".$field."_seq\"");
pdo_query("ALTER TABLE \"".$table."\" ALTER COLUMN \"".$field."\" SET DEFAULT nextval('".$table."_".$field."_seq')");
pdo_query("ALTER SEQUENCE \"".$table."_".$field."_seq\" OWNED BY \"".$table."\".\"".$field."\"");
}
}
else
{
//ALTER TABLE dynamicanalysisdefect MODIFY value INT NOT NULL DEFAULT 0;
$sql = "ALTER TABLE ".$table." MODIFY ".$field." ".$mySQLType;
if($notnull)
{
$sql .= " NOT NULL";
}
if(strlen($default)>0)
{
$sql .= " DEFAULT '".$default."'";
}
if($autoincrement)
{
$sql .= " AUTO_INCREMENT";
}
pdo_query($sql);
}
add_last_sql_error("ModifyTableField");
add_log("Done modifying $field to $table","ModifyTableField");
}
}
// Helper function to add an index to a table
function AddTablePrimaryKey($table,$field)
{
include("cdash/config.php");
add_log("Adding primarykey $field to $table","AddTablePrimaryKey");
if($CDASH_DB_TYPE == "pgsql")
{
pdo_query("ALTER TABLE \"".$table."\" ADD PRIMARY KEY (\"".$field."\")");
}
else
{
pdo_query("ALTER IGNORE TABLE ".$table." ADD PRIMARY KEY ( ".$field." )");
}
//add_last_sql_error("AddTablePrimaryKey");
add_log("Done adding primarykey $field to $table","AddTablePrimaryKey");
}
// Helper function to add an index to a table
function RemoveTablePrimaryKey($table)
{
include("cdash/config.php");
add_log("Removing primarykey from $table","RemoveTablePrimaryKey");
if($CDASH_DB_TYPE == "pgsql")
{
pdo_query("ALTER TABLE \"".$table."\" DROP CONSTRAINT \"value_pkey\"");
pdo_query("ALTER TABLE \"".$table."\" DROP CONSTRAINT \"".$table."_pkey\"");
}
else
{
pdo_query("ALTER TABLE ".$table." DROP PRIMARY KEY");
}
//add_last_sql_error("RemoveTablePrimaryKey");
add_log("Done removing primarykey from $table","RemoveTablePrimaryKey");
}
// 1.4 Upgrade
if(isset($_GET['upgrade-1-4']))
{
// Add fields in the project table
$starttime = pdo_query("SELECT starttime FROM subproject LIMIT 1");
if(!$starttime)
{
pdo_query("ALTER TABLE subproject ADD starttime TIMESTAMP NOT NULL default '1980-01-01 00:00:00'");
pdo_query("ALTER TABLE subproject ADD endtime TIMESTAMP NOT NULL default '1980-01-01 00:00:00'");
}
// Create the right indexes if necessary
AddTableIndex('buildfailure','buildid');
AddTableIndex('buildfailure','type');
// Create the new table buildfailure arguments if the old one is still there
if(pdo_query("SELECT buildfailureid FROM buildfailureargument"))
{
pdo_query("DROP TABLE IF EXISTS buildfailureargument");
pdo_query("CREATE TABLE IF NOT EXISTS `buildfailureargument` (
`id` bigint(20) NOT NULL auto_increment,
`argument` varchar(60) NOT NULL,
PRIMARY KEY (`id`),
KEY `argument` (`argument`))");
}
AddTableIndex('buildfailureargument','argument');
// Add fields in the buildgroup table
AddTableField("project","emailadministrator","tinyint(4)","smallint","1");
AddTableField("project","showipaddresses","tinyint(4)","smallint","1");
AddTableField("buildgroup","includesubprojectotal","tinyint(4)","smallint","1");
AddTableField("project","emailredundantfailures","tinyint(4)","smallint","0");
AddTableField("buildfailure2argument","place","int(11)","bigint","0");
if($CDASH_DB_TYPE != "pgsql")
{
pdo_query("ALTER TABLE `builderror` CHANGE `precontext` `precontext` TEXT NULL");
pdo_query("ALTER TABLE `builderror` CHANGE `postcontext` `postcontext` TEXT NULL");
}
ModifyTableField("buildfailureargument","argument","VARCHAR( 255 )","VARCHAR( 255 )","",true,false);
ModifyTableField("buildfailure","exitcondition","VARCHAR( 255 )","VARCHAR( 255 )","",true,false);
ModifyTableField("buildfailure","language","VARCHAR( 64 )","VARCHAR( 64 )","",true,false);
ModifyTableField("buildfailure","sourcefile","VARCHAR( 512)","VARCHAR( 512 )","",true,false);
RemoveTableField("buildfailure","arguments");
ModifyTableField("configure","log","MEDIUMTEXT","TEXT","",true,false);
AddTableIndex('coverage','covered');
AddTableIndex('build2grouprule','starttime');
AddTableIndex('build2grouprule','endtime');
AddTableIndex('build2grouprule','buildtype');
AddTableIndex('build2grouprule','buildname');
AddTableIndex('build2grouprule','expected');
AddTableIndex('build2grouprule','siteid');
RemoveTableIndex("build2note","buildid");
AddTableIndex('build2note','buildid');
AddTableIndex('build2note','noteid');
AddTableIndex('user2project','cvslogin');
AddTableIndex('user2project','emailtype');
AddTableIndex('user','email');
AddTableIndex('project','public');
AddTableIndex('buildgroup','starttime');
AddTableIndex('buildgroup','endtime');
AddTableIndex('buildgroupposition','position');
AddTableIndex('buildgroupposition','starttime');
AddTableIndex('buildgroupposition','endtime');
AddTableIndex('dailyupdate','date');
AddTableIndex('dailyupdate','projectid');
AddTableIndex('builderror','type');
AddTableIndex('build','starttime');
AddTableIndex('build','submittime');
RemoveTableIndex('build','siteid');
AddTableIndex('build','siteid');
AddTableIndex('build','name');
AddTableIndex('build','stamp');
AddTableIndex('build','type');
AddTableIndex('project','name');
AddTableIndex('site','name');
ModifyTableField("image","id","BIGINT( 11 )","BIGINT","",true,false);
RemoveTableIndex("image"," id");
RemoveTablePrimaryKey("image");
AddTablePrimaryKey("image","id");
ModifyTableField("image","id","BIGINT( 11 )","BIGINT","",true,true);
ModifyTableField("dailyupdate","id","BIGINT( 11 )","BIGINT","",true,false);
RemoveTableIndex("dailyupdate"," buildid");
RemoveTablePrimaryKey("dailyupdate");
AddTablePrimaryKey("dailyupdate","id");
ModifyTableField("dailyupdate","id","BIGINT( 11 )","BIGINT","",true,true);
ModifyTableField("dynamicanalysisdefect","value","INT","INT","0",true,false);
RemoveTablePrimaryKey("test2image");
AddTableIndex('test2image','imgid');
AddTableIndex('test2image','testid');
ModifyTableField("image","checksum","BIGINT( 20 )","BIGINT","",true,false);
ModifyTableField("note ","crc32","BIGINT( 20 )","BIGINT","",true,false);
ModifyTableField("test ","crc32","BIGINT( 20 )","BIGINT","",true,false);
ModifyTableField("coveragefile ","crc32","BIGINT( 20 )","BIGINT","",true,false);
// Remove duplicates in buildfailureargument
//pdo_query("DELETE FROM buildfailureargument WHERE id NOT IN (SELECT buildfailureid as id FROM buildfailure2argument)");
AddTableField("project","displaylabels","tinyint(4)","smallint","1");
AddTableField("project","autoremovetimeframe","int(11)","bigint","0");
AddTableField("project","autoremovemaxbuilds","int(11)","bigint","300");
AddTableIndex('coveragefilelog','line');
// Set the database version
setVersion();
// Put that the upgrade is done in the log
add_log("Upgrade done.","upgrade-1-4");
return;
}
// 1.6 Upgrade
if(isset($_GET['upgrade-1-6']))
{
if($CDASH_DB_TYPE != "pgsql")
{
pdo_query("ALTER TABLE configure CHANGE starttime starttime TIMESTAMP NOT NULL DEFAULT '1980-01-01 00:00:00' ");
pdo_query("ALTER TABLE buildupdate CHANGE starttime starttime TIMESTAMP NOT NULL DEFAULT '1980-01-01 00:00:00' ");
pdo_query("ALTER TABLE test CHANGE output output MEDIUMBLOB NOT NULL "); // change it to blob (cannot do that in PGSQL)
pdo_query("ALTER TABLE updatefile CHANGE checkindate checkindate TIMESTAMP NOT NULL DEFAULT '1980-01-01 00:00:00' ");
pdo_query("ALTER TABLE build2note CHANGE time time TIMESTAMP NOT NULL DEFAULT '1980-01-01 00:00:00' ");
pdo_query("ALTER TABLE buildemail CHANGE time time TIMESTAMP NOT NULL DEFAULT '1980-01-01 00:00:00' ");
}
RemoveTableField("project","emailbuildmissing");
AddTableField("project","displaylabels","tinyint(4)","smallint","1");
AddTableField("project","autoremovetimeframe","int(11)","bigint","0");
AddTableField("project","autoremovemaxbuilds","int(11)","bigint","300");
AddTableField("updatefile","status","VARCHAR(12)","VARCHAR( 12 )","");
AddTableField("project","bugtrackerfileurl","VARCHAR(255)","VARCHAR( 255 )","");
AddTableField("repositories","username","VARCHAR(50)","VARCHAR( 50 )","");
AddTableField("repositories","password","VARCHAR(50)","VARCHAR( 50 )","");
AddTableIndex('coveragefilelog','line');
AddTableIndex('dailyupdatefile','author');
RenameTableField("testdiff","difference","difference_positive","int(11)","bigint","0");
AddTableField("testdiff","difference_negative","int(11)","bigint","0");
AddTableIndex('testdiff','difference_positive');
AddTableIndex('testdiff','difference_negative');
AddTableField("build2test","newstatus","tinyint(4)","smallint","0");
AddTableIndex('build2test','newstatus');
RenameTableField("builderrordiff","difference","difference_positive","int(11)","bigint","0");
AddTableField("builderrordiff","difference_negative","int(11)","bigint","0");
AddTableIndex('builderrordiff','difference_positive');
AddTableIndex('builderrordiff','difference_negative');
AddTableField("builderror","crc32","bigint(20)","BIGINT","0");
AddTableField("builderror","newstatus","tinyint(4)","smallint","0");
AddTableIndex('builderror','crc32');
AddTableIndex('builderror','newstatus');
AddTableField("buildfailure","crc32","bigint(20)","BIGINT","0");
AddTableField("buildfailure","newstatus","tinyint(4)","smallint","0");
AddTableIndex('buildfailure','crc32');
AddTableIndex('buildfailure','newstatus');
AddTableField("client_jobschedule","repository","VARCHAR(512)","VARCHAR(512)","");
AddTableField("client_jobschedule","module","VARCHAR(255)","VARCHAR(255)","");
AddTableField("client_jobschedule","buildnamesuffix","VARCHAR(255)","VARCHAR(255)","");
AddTableField("client_jobschedule","tag","VARCHAR(255)","VARCHAR(255)","");
ModifyTableField("updatefile","revision","VARCHAR(60)","VARCHAR(60)","",true,false);
ModifyTableField("updatefile","priorrevision","VARCHAR(60)","VARCHAR(60)","",true,false);
AddTableField("buildupdate","revision","VARCHAR(60)","VARCHAR(60)","0");
AddTableField("buildupdate","priorrevision","VARCHAR(60)","VARCHAR(60)","0");
AddTableField("buildupdate","path","VARCHAR(255)","VARCHAR(255)","");
AddTableField("user2project","emailsuccess","tinyint(4)","smallint","0");
AddTableIndex('user2project','emailsuccess');
AddTableField("user2project","emailmissingsites","tinyint(4)","smallint","0");
AddTableIndex('user2project','emailmissingsites');
if(!pdo_query("SELECT projectid FROM test LIMIT 1"))
{
AddTableField("test","projectid","int(11)","bigint","0");
AddTableIndex('test','projectid');
// Set the project id
pdo_query("UPDATE test SET projectid=(SELECT projectid FROM build,build2test
WHERE build2test.testid=test.id AND build2test.buildid=build.id LIMIT 1)");
echo pdo_error();
}
// Add the cookiekey field
AddTableField("user","cookiekey","VARCHAR(40)","VARCHAR( 40 )","");
ModifyTableField("dynamicanalysis","log","MEDIUMTEXT","TEXT","",true,false);
// New build, buildupdate and configure fields to speedup reading
if(!pdo_query("SELECT builderrors FROM build LIMIT 1") )
{
AddTableField("build","builderrors","smallint(6)","smallint","-1");
AddTableField("build","buildwarnings","smallint(6)","smallint","-1");
AddTableField("build","testnotrun","smallint(6)","smallint","-1");
AddTableField("build","testfailed","smallint(6)","smallint","-1");
AddTableField("build","testpassed","smallint(6)","smallint","-1");
AddTableField("build","testtimestatusfailed","smallint(6)","smallint","-1");
AddTableField("buildupdate","nfiles","smallint(6)","smallint","-1");
AddTableField("buildupdate","warnings","smallint(6)","smallint","-1");
AddTableField("configure","warnings","smallint(6)","smallint","-1");
pdo_query("UPDATE configure SET warnings=(SELECT count(buildid) FROM configureerror WHERE buildid=configure.buildid AND type='1')
WHERE warnings=-1");
pdo_query("UPDATE buildupdate SET
warnings=(SELECT count(buildid) FROM updatefile WHERE buildid=buildupdate.buildid AND revision='-1' AND author='Local User'),
nfiles=(SELECT count(buildid) FROM updatefile WHERE buildid=buildupdate.buildid)
WHERE warnings=-1");
pdo_query("UPDATE build SET
builderrors=(SELECT count(buildid) FROM builderror WHERE buildid=build.id AND type='0'),
buildwarnings=(SELECT count(buildid) FROM builderror WHERE buildid=build.id AND type='1'),
builderrors=builderrors+(SELECT count(buildid) FROM buildfailure WHERE buildid=build.id AND type='0'),
buildwarnings=buildwarnings+(SELECT count(buildid) FROM buildfailure WHERE buildid=build.id AND type='1'),
testpassed=(SELECT count(buildid) FROM build2test WHERE buildid=build.id AND status='passed'),
testfailed=(SELECT count(buildid) FROM build2test WHERE buildid=build.id AND status='failed'),
testnotrun=(SELECT count(buildid) FROM build2test WHERE buildid=build.id AND status='notrun'),
testtimestatusfailed=(SELECT count(buildid) FROM build2test,project WHERE project.id=build.id
AND buildid=build.id AND timestatus>=project.testtimemaxstatus)
WHERE builderrors=-1");
echo pdo_error();
} // end new table build
// Set the database version
setVersion();
// Put that the upgrade is done in the log
add_log("Upgrade done.","upgrade-1-6");
return;
}
// 1.8 Upgrade
if(isset($_GET['upgrade-1-8']))
{
// If the new coveragefilelog is not set
if(!pdo_query("SELECT log FROM coveragefilelog LIMIT 1"))
{
AddTableField("coveragefilelog","log","LONGBLOB","bytea",false);
// Get the lines for each buildid/fileid
$query = pdo_query("SELECT DISTINCT buildid,fileid FROM coveragefilelog ORDER BY buildid,fileid");
while($query_array = pdo_fetch_array($query))
{
$buildid = $query_array['buildid'];
$fileid = $query_array['fileid'];
// Get the lines
$firstline = false;
$log = '';
$lines = pdo_query("SELECT line,code FROM coveragefilelog WHERE buildid='".$buildid."' AND fileid='".$fileid."' ORDER BY line");
while($lines_array = pdo_fetch_array($lines))
{
$line = $lines_array['line'];
$code = $lines_array['code'];
if($firstline === false)
{
$firstline = $line;
}
$log .= $line.':'.$code.';';
}
// Update the first line
pdo_query("UPDATE coveragefilelog SET log='".$log."'
WHERE buildid='".$buildid."' AND fileid='".$fileid."' AND line='".$firstline."'");
// Delete the other lines
pdo_query("DELETE FROM coveragefilelog
WHERE buildid='".$buildid."' AND fileid='".$fileid."' AND line!='".$firstline."'");
} // end looping through buildid/fileid
RemoveTableField("coveragefilelog","line");
RemoveTableField("coveragefilelog","code");
}
// Missing fields in the client_jobschedule table
if(!pdo_query("SELECT repository FROM client_jobschedule LIMIT 1"))
{
AddTableField("client_jobschedule","repository","varchar(512)","character varying(512)","");
AddTableField("client_jobschedule","module","varchar(255)","character varying(255)","");
AddTableField("client_jobschedule","buildnamesuffix","varchar(255)","character varying(255)","");
AddTableField("client_jobschedule","tag","varchar(255)","character varying(255)","");
}
AddTableField("project", "testingdataurl","varchar(255)","character varying(255)","");
AddTableField('buildgroup', 'autoremovetimeframe','int(11)','bigint','0');
ModifyTableField("dailyupdatefile","revision","VARCHAR(60)","VARCHAR(60)","",true,false);
ModifyTableField("dailyupdatefile","priorrevision","VARCHAR(60)","VARCHAR(60)","",true,false);
AddTableField("dailyupdatefile","email","VARCHAR(255)","character varying(255)","");
AddTableIndex('dailyupdatefile','email');
AddTableField("client_jobschedule","buildconfiguration","tinyint(4)","smallint","0");
// Remove the toolkits tables
pdo_query("DROP TABLE IF EXISTS client_toolkit");
pdo_query("DROP TABLE IF EXISTS client_toolkitconfiguration");
pdo_query("DROP TABLE IF EXISTS client_toolkitconfiguration2os");
pdo_query("DROP TABLE IF EXISTS client_toolkitversion");
pdo_query("DROP TABLE IF EXISTS client_jobschedule2toolkit");
// Add lastping to the client_site table
AddTableField("client_site","lastping","timestamp","timestamp(0)","1980-01-01 00:00:00");
AddTableIndex('client_site','lastping');
// Remove img index for table test2image
RenameTableField('test2image','imgid','imgid',"int(11)","bigint","0");
RemoveTablePrimaryKey('test2image');
AddTableIndex('test2image','imgid');
ModifyTableField("buildfailure","stdoutput","MEDIUMTEXT","TEXT","",true,false);
ModifyTableField("buildfailure","stderror","MEDIUMTEXT","TEXT","",true,false);
AddTableIndex('builderrordiff','type');
AddTableField("dailyupdate","revision","varchar(60)","character varying(60)","");
AddTableField("repositories","branch","varchar(60)","character varying(60)","");
// New fields for the submission table to make asynchronous submission
// processing more robust:
//
AddTableField("submission", "attempts", "int(11)", "bigint", "0");
AddTableField("submission", "filesize", "int(11)", "bigint", "0");
AddTableField("submission", "filemd5sum", "varchar(32)", "character varying(32)", "");
AddTableField("submission", "lastupdated", "timestamp", "timestamp(0)", "1980-01-01 00:00:00");
AddTableField("submission", "created", "timestamp", "timestamp(0)", "1980-01-01 00:00:00");
AddTableField("submission", "started", "timestamp", "timestamp(0)", "1980-01-01 00:00:00");
AddTableField("submission", "finished", "timestamp", "timestamp(0)", "1980-01-01 00:00:00");
AddTableIndex("submission", "finished");
AddTableField("client_jobschedule", "clientscript", "text", "text", "");
AddTableField("project", "webapikey", "varchar(40)", "character varying(40)", "");
AddTableField("project", "tokenduration", "int(11)", "bigint", "0");
// Add the users' cvslogin to the user2repository table (by default all projects)
if(pdo_query("SELECT cvslogin FROM user2project"))
{
// Add all the user's email to the user2repository table
$emailarray = array();
$query = pdo_query("SELECT id,email FROM user");
while($query_array = pdo_fetch_array($query))
{
$userid = $query_array['id'];
$email = $query_array['email'];
$emailarray[] = $email;
pdo_query("INSERT INTO user2repository (userid,credential) VALUES ('".$userid."','".$email."')");
}
// Add the repository login
$query = pdo_query("SELECT userid,projectid,cvslogin FROM user2project GROUP BY userid,cvslogin");
while($query_array = pdo_fetch_array($query))
{
$userid = $query_array['userid'];
$cvslogin = $query_array['cvslogin'];
if(!empty($cvslogin) && !in_array($cvslogin,$emailarray))
{
pdo_query("INSERT INTO user2repository (userid,projectid,credential)
VALUES ('".$userid."','".$projectid."','".$cvslogin."')");
}
}
RemoveTableField("user2project","cvslogin");
}
// Set the database version
setVersion();
// Put that the upgrade is done in the log
add_log("Upgrade done.","upgrade-1-8");
return;
}
// 2.0 Upgrade
if(isset($_GET['upgrade-2-0']))
{
// Add column id to test2image and testmeasurement
if(!pdo_query("SELECT id FROM test2image LIMIT 1"))
{
include("cdash/config.php");
if($CDASH_DB_TYPE != "pgsql")
{
pdo_query("ALTER TABLE testmeasurement ADD id BIGINT NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (id)");
pdo_query("ALTER TABLE test2image ADD id BIGINT NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (id)");
}
else
{
pdo_query("ALTER TABLE testmeasurement ADD id SERIAL NOT NULL, ADD PRIMARY KEY (id)");
pdo_query("ALTER TABLE test2image ADD id SERIAL NOT NULL, ADD PRIMARY KEY (id)");
}
}
AddTableField('project', 'webapikey', 'varchar(40)', 'character varying(40)', '');
AddTableField('project', 'tokenduration', 'int(11)', 'bigint', '0');
AddTableField('project', 'uploadquota', 'bigint(20)', 'bigint', '0');
AddTableField('updatefile', 'committer', 'varchar(255)', 'character varying(255)', '');
AddTableField('updatefile', 'committeremail', 'varchar(255)', 'character varying(255)', '');
AddTableField('buildgroup', 'emailcommitters', 'tinyint(4)', 'smallint', '0');
AddTableField('uploadfile', 'isurl', 'tinyint(1)', 'smallint', '0');
// Add indexes for the label2... tables
AddTableIndex('label2build','buildid');
AddTableIndex('label2buildfailure','buildfailureid');
AddTableIndex('label2coveragefile','buildid');
AddTableIndex('label2dynamicanalysis','dynamicanalysisid');
AddTableIndex('label2test','buildid');
AddTableIndex('label2update','updateid');
ModifyTableField("client_jobschedule","repeattime","decimal(6,2)","decimal(6,2)","0.00",true,false);
AddTableField('client_jobschedule', 'description', 'text', 'text', '');
AddTableField('project', 'showcoveragecode', 'tinyint(1)', 'smallint', '1');
AddTableIndex('updatefile','author');
// Set the database version
setVersion();
// Put that the upgrade is done in the log
add_log("Upgrade done.","upgrade-2-0");
return;
}
// 2.2 Upgrade
if(isset($_GET['upgrade-2-2']))
{
AddTableIndex('updatefile','author');
// We need to move the buildupdate build ids to the build2update table
$query = pdo_query("SELECT buildid FROM buildupdate");
while($query_array = pdo_fetch_array($query))
{
pdo_query("INSERT INTO build2update (buildid,updateid) VALUES ('".$query_array['buildid']."','".$query_array['buildid']."')");
}
RemoveTableIndex("buildupdate","buildid");
RenameTableField("buildupdate","buildid","id","int(11)","bigint","0");
AddTablePrimaryKey("buildupdate","id");
ModifyTableField("buildupdate","id","int(11)","bigint","",true,true);
RenameTableField("updatefile","buildid","updateid","int(11)","bigint","0");
AddTableField('site', 'outoforder', 'tinyint(1)', 'smallint', '0');
// Set the database version
setVersion();
// Put that the upgrade is done in the log
add_log("Upgrade done.","upgrade-2-2");
return;
}
// 2.4 Upgrade
if(isset($_GET['upgrade-2-4']))
{
// Support for core vs. non-core subprojects
AddTableField('subproject', 'core', 'tinyint(1)', 'smallint', '1');
// Support for separate non-core coverage threshold
AddTableField('project', 'coveragethreshold2', 'smallint(6)', 'smallint', '70');
// Support for larger types
ModifyTableField("buildfailure","workingdirectory","VARCHAR( 512)","VARCHAR( 512 )","",true,false);
ModifyTableField("buildfailure","outputfile","VARCHAR( 512)","VARCHAR( 512 )","",true,false);
// Set the database version
setVersion();
// Put that the upgrade is done in the log
add_log("Upgrade done.","upgrade-2-4");
return;
}
// When adding new tables they should be added to the SQL installation file
// and here as well
if($Upgrade)
{
// check if the backup directory is writable
if(!is_writable($CDASH_BACKUP_DIRECTORY))
{
$xml .= "<backupwritable>0</backupwritable>";
}
else
{
$xml .= "<backupwritable>1</backupwritable>";
}
// check if the upload directory is writable
if(!is_writable($CDASH_UPLOAD_DIRECTORY))
{
$xml .= "<uploadwritable>0</uploadwritable>";
}
else
{
$xml .= "<uploadwritable>1</uploadwritable>";
}
// check if the rss directory is writable
if(!is_writable("rss"))
{
$xml .= "<rsswritable>0</rsswritable>";
}
else
{
$xml .= "<rsswritable>1</rsswritable>";
}
$xml .= "<upgrade>1</upgrade>";
}
// Compress the test output
if(isset($_POST["CompressTestOutput"]))
{
// Do it slowly so we don't take all the memory
$query = pdo_query("SELECT count(*) FROM test");
$query_array = pdo_fetch_array($query);
$ntests = $query_array[0];
$ngroup = 1024;
for($i=0;$i<$ntests;$i+=$ngroup)
{
$query = pdo_query("SELECT id,output FROM test ORDER BY id ASC LIMIT ".$ngroup." OFFSET ".$i);
while($query_array = pdo_fetch_array($query))
{
// Try uncompressing to see if it's already compressed
if(@gzuncompress($query_array['output']) === false)
{
$compressed = pdo_real_escape_string(gzcompress($query_array['output']));
pdo_query("UPDATE test SET output='".$compressed."' WHERE id=".$query_array['id']);
echo pdo_error();
}
}
}
}
// Compute the testtime
if($ComputeTestTiming)
{
@$TestTimingDays = $_POST["TestTimingDays"];
if ($TestTimingDays != NULL)
{
$TestTimingDays = pdo_real_escape_numeric($TestTimingDays);
}
if(is_numeric($TestTimingDays) && $TestTimingDays>0)
{
ComputeTestTiming($TestTimingDays);
$xml .= add_XML_value("alert","Timing for tests has been computed successfully.");
}
else
{
$xml .= add_XML_value("alert","Wrong number of days.");
}
}