forked from Kitware/CDash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
1950 lines (1715 loc) · 66.2 KB
/
index.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("cdash/common.php");
include('cdash/version.php');
require_once("models/project.php");
require_once("models/buildfailure.php");
require_once("filterdataFunctions.php");
set_time_limit(0);
/** Generate the index table */
function generate_index_table()
{
$noforcelogin = 1;
include("cdash/config.php");
require_once("cdash/pdo.php");
include('login.php');
include_once('models/banner.php');
$xml = begin_XML_for_XSLT();
$xml .= add_XML_value("title","CDash - Continuous Integration Made Easy");
$Banner = new Banner;
$Banner->SetProjectId(0);
$text = $Banner->GetText();
if($text !== false)
{
$xml .= "<banner>";
$xml .= add_XML_value("text",$text);
$xml .= "</banner>";
}
$xml .= "<hostname>".$_SERVER['SERVER_NAME']."</hostname>";
$xml .= "<date>".date("r")."</date>";
// Check if the database is up to date
$dbField = "TABLE_SCHEMA";
if($CDASH_DB_TYPE == 'pgsql')
{
$dbField = "TABLE_CATALOG";
}
$query =
"SELECT is_nullable FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'build' AND column_name = 'command' AND
$dbField='$CDASH_DB_NAME'";
$dbTest = pdo_single_row_query($query);
if ($dbTest['is_nullable'] != "NO")
{
$xml .= "<upgradewarning>1</upgradewarning>";
}
$xml .= "<dashboard>
<title>".$CDASH_MAININDEX_TITLE."</title>
<subtitle>".$CDASH_MAININDEX_SUBTITLE."</subtitle>
<googletracker>".$CDASH_DEFAULT_GOOGLE_ANALYTICS."</googletracker>";
if(isset($CDASH_NO_REGISTRATION) && $CDASH_NO_REGISTRATION==1)
{
$xml .= add_XML_value("noregister","1");
}
$xml .= "</dashboard> ";
// User
$userid = 0;
if(isset($_SESSION['cdash']) && isset($_SESSION['cdash']['loginid']))
{
$xml .= "<user>";
$userid = $_SESSION['cdash']['loginid'];
$user = pdo_query("SELECT admin FROM ".qid("user")." WHERE id='$userid'");
$user_array = pdo_fetch_array($user);
$xml .= add_XML_value("id",$userid);
$xml .= add_XML_value("admin",$user_array["admin"]);
$xml .= "</user>";
}
$showallprojects = 0;
if(isset($_GET['allprojects']) && $_GET['allprojects'] == 1)
{
$showallprojects = 1;
}
$projects = get_projects(!$showallprojects);
$row=0;
foreach($projects as $project)
{
$xml .= "<project>";
$xml .= add_XML_value("name",$project['name']);
$xml .= add_XML_value("name_encoded",urlencode($project['name']));
$xml .= add_XML_value("description",$project['description']);
if($project['last_build'] == "NA")
{
$xml .= "<lastbuild>NA</lastbuild>";
$xml .= "<activitylevel>none</activitylevel>";
}
else
{
$lastbuild = strtotime($project['last_build']. "UTC");
$xml .= "<lastbuild>".date(FMT_DATETIMEDISPLAY,$lastbuild)."</lastbuild>";
$xml .= "<lastbuilddate>".date(FMT_DATE,$lastbuild)."</lastbuilddate>";
$xml .= "<lastbuild_elapsed>".time_difference(time()-$lastbuild,false,'ago')."</lastbuild_elapsed>";
$xml .= "<lastbuilddatefull>".$lastbuild."</lastbuilddatefull>";
$xml .= "<activitylevel>high</activitylevel>";
}
$xml .= "<activity>";
if(!isset($project['nbuilds']) || $project['nbuilds'] == 0)
{
$xml .= "none";
}
else if($project['nbuilds'] < 20) // 2 builds day
{
$xml .= "low";
}
else if($project['nbuilds'] < 70) // 10 builds a day
{
$xml .= "medium";
}
else if($project['nbuilds'] >= 70)
{
$xml .= "high";
}
$xml .= "</activity>";
//$uploadsizeGB = round($project['uploadsize'] / (1024.0*1024.0*1024.0), 2);
//$xml .= '<uploadsize>'.$uploadsizeGB.'</uploadsize>';
$xml .= "<row>".$row."</row>";
$xml .= "</project>";
if($row == 0)
{
$row = 1;
}
else
{
$row = 0;
}
}
$xml .= '<allprojects>'.$showallprojects.'</allprojects>';
$xml .= '<nprojects>'.get_number_public_projects().'</nprojects>';
$xml .= "</cdash>";
return $xml;
}
function add_buildgroup_sortlist($groupname)
{
// This function defines how the build group tables should be sorted.
// This information can be provided as a query string, otherwise we apply
// some default ordering here. Default sort ordering for a group is based
// on the groupname.
//
// Sort settings should probably be definable/overrideable by the user as wel
// on the users page, or perhaps by the project admin on the project page.
//
$st = '';
$xml = '';
if(isset($_GET["sort"]))
{
$xml .= add_XML_value("sortlist", "{sortlist: " . $_GET["sort"] . "}");
return $xml;
}
$gn = strtolower($groupname);
if (strpos($gn, 'nightly') !== FALSE)
{
$st = 'SortAsNightly';
}
else if ((strpos($gn, 'continuous') !== FALSE) || (strpos($gn, 'experimental') !== FALSE))
{
$st = 'SortByTime';
}
switch($st)
{
case 'SortAsNightly':
$xml .= add_XML_value("sortlist", "{sortlist: [[4,1],[7,1],[11,1],[10,1],[5,1],[8,1]]}");
// Theoretically, most important to least important:
// configure errors DESC, build errors DESC, tests failed DESC, tests not run DESC,
// configure warnings DESC, build warnings DESC
break;
case 'SortByTime':
$xml .= add_XML_value("sortlist", "{sortlist: [[14,1]]}");
// build time DESC
break;
// By default, no javascript-based sorting. Accept the ordering naturally as it came from
// MySQL and the php processing code...
}
return $xml;
}
/** Get a link to a page showing the children of a given parent build. */
function get_child_builds_hyperlink($parentid, $filterdata)
{
$baseurl = $_SERVER['REQUEST_URI'];
// If the current REQUEST_URI already has a &filtercount=... (and other
// filter stuff), trim it off and just use part that comes before that:
//
$idx = strpos($baseurl, "&filtercount=");
if ($idx !== FALSE)
{
$baseurl = substr($baseurl, 0, $idx);
}
// Similarly trim off &display=..., as that parameter is implied
// when viewing the results of a single (parent) build.
$idx = strpos($baseurl, "&display=");
if ($idx !== FALSE)
{
$baseurl = substr($baseurl, 0, $idx);
}
// Preserve any filters the user had specified.
$existing_filter_params = '';
$n = 0;
$count = count($filterdata['filters']);
for ($i = 0; $i<$count; $i++)
{
$filter = $filterdata['filters'][$i];
if ($filter['field'] != 'buildname' &&
$filter['field'] != 'site' &&
$filter['field'] != 'stamp' &&
$filter['compare'] != 0 &&
$filter['compare'] != 20 &&
$filter['compare'] != 40 &&
$filter['compare'] != 60 &&
$filter['compare'] != 80)
{
$n++;
$existing_filter_params .=
'&field' . $n . '=' . $filter['field'] . '/' . $filter['fieldtype'] .
'&compare' . $n . '=' . $filter['compare'] .
'&value' . $n . '=' . htmlspecialchars($filter['value']);
}
}
// Construct & return our URL.
$url = "$baseurl&parentid=$parentid";
$url .= $existing_filter_params;
return $url;
}
/** Generate the main dashboard XML */
function generate_main_dashboard_XML($project_instance, $date)
{
$start = microtime_float();
$noforcelogin = 1;
include_once("cdash/config.php");
require_once("cdash/pdo.php");
include('login.php');
include_once("models/banner.php");
include_once("models/subproject.php");
$db = pdo_connect("$CDASH_DB_HOST", "$CDASH_DB_LOGIN","$CDASH_DB_PASS");
if(!$db)
{
echo "Error connecting to CDash database server<br>\n";
return;
}
if(!pdo_select_db("$CDASH_DB_NAME",$db))
{
echo "Error selecting CDash database<br>\n";
return;
}
$projectid = $project_instance->Id;
$project = pdo_query("SELECT * FROM project WHERE id='$projectid'");
if(pdo_num_rows($project)>0)
{
$project_array = pdo_fetch_array($project);
$svnurl = make_cdash_url(htmlentities($project_array["cvsurl"]));
$homeurl = make_cdash_url(htmlentities($project_array["homeurl"]));
$bugurl = make_cdash_url(htmlentities($project_array["bugtrackerurl"]));
$googletracker = htmlentities($project_array["googletracker"]);
$docurl = make_cdash_url(htmlentities($project_array["documentationurl"]));
$projectpublic = $project_array["public"];
$projectname = $project_array["name"];
if(isset($project_array['testingdataurl']) && $project_array['testingdataurl'] != '')
{
$testingdataurl = make_cdash_url(htmlentities($project_array['testingdataurl']));
}
}
else
{
redirect_error('This project doesn\'t exist. Maybe the URL you are trying to access is wrong.');
return false;
}
checkUserPolicy(@$_SESSION['cdash']['loginid'],$project_array["id"]);
$xml = begin_XML_for_XSLT();
$xml .= "<title>CDash - ".$projectname."</title>";
$Banner = new Banner;
$Banner->SetProjectId(0);
$text = $Banner->GetText();
if($text !== false)
{
$xml .= "<banner>";
$xml .= add_XML_value("text",$text);
$xml .= "</banner>";
}
$Banner->SetProjectId($projectid);
$text = $Banner->GetText();
if($text !== false)
{
$xml .= "<banner>";
$xml .= add_XML_value("text",$text);
$xml .= "</banner>";
}
list ($previousdate, $currentstarttime, $nextdate) = get_dates($date,$project_array["nightlytime"]);
$logoid = getLogoID($projectid);
// Main dashboard section
$xml .=
"<dashboard>
<datetime>".date("l, F d Y H:i:s T",time())."</datetime>
<date>".$date."</date>
<unixtimestamp>".$currentstarttime."</unixtimestamp>
<svn>".$svnurl."</svn>
<bugtracker>".$bugurl."</bugtracker>
<googletracker>".$googletracker."</googletracker>
<documentation>".$docurl."</documentation>
<logoid>".$logoid."</logoid>
<projectid>".$projectid."</projectid>
<projectname>".$projectname."</projectname>
<projectname_encoded>".urlencode($projectname)."</projectname_encoded>
<previousdate>".$previousdate."</previousdate>
<projectpublic>".$projectpublic."</projectpublic>
<displaylabels>".$project_array["displaylabels"]."</displaylabels>
<nextdate>".$nextdate."</nextdate>";
if(empty($project_array["homeurl"]))
{
$xml .= "<home>index.php?project=".urlencode($projectname)."</home>";
}
else
{
$xml .= "<home>".$homeurl."</home>";
}
if($CDASH_USE_LOCAL_DIRECTORY&&file_exists("local/models/proProject.php"))
{
include_once("local/models/proProject.php");
$pro= new proProject;
$pro->ProjectId=$projectid;
$xml.="<proedition>".$pro->GetEdition(1)."</proedition>";
}
if($currentstarttime>time())
{
$xml .= "<future>1</future>";
}
else
{
$xml .= "<future>0</future>";
}
$xml .= "</dashboard>";
// Menu definition
$xml .= "<menu>";
if(!has_next_date($date, $currentstarttime))
{
$xml .= add_XML_value("nonext","1");
}
$xml .= "</menu>";
// Check the builds
$beginning_timestamp = $currentstarttime;
$end_timestamp = $currentstarttime+3600*24;
$beginning_UTCDate = gmdate(FMT_DATETIME,$beginning_timestamp);
$end_UTCDate = gmdate(FMT_DATETIME,$end_timestamp);
// Add the extra url if necessary
if(isset($_GET["display"]) && $_GET["display"]=="project")
{
$xml .= add_XML_value("extraurl","&display=project");
}
// If we have a subproject
$subproject_name = @$_GET["subproject"];
$subprojectid = false;
if($subproject_name)
{
$SubProject = new SubProject();
$subproject_name = htmlspecialchars(pdo_real_escape_string($subproject_name));
$SubProject->Name = $subproject_name;
$SubProject->ProjectId = $projectid;
$subprojectid = $SubProject->GetIdFromName();
if($subprojectid)
{
// Add an extra URL argument for the menu
$xml .= add_XML_value("extraurl", "&subproject=".urlencode($subproject_name));
$xml .= add_XML_value("subprojectname", $subproject_name);
$xml .= "<subproject>";
$xml .= add_XML_value("name", $SubProject->Name);
$rowparity = 0;
$dependencies = $SubProject->GetDependencies();
if($dependencies)
{
foreach($dependencies as $dependency)
{
$xml .= "<dependency>";
$DependProject = new SubProject();
$DependProject->Id = $dependency;
$xml .= add_XML_value("rowparity",$rowparity);
$xml .= add_XML_value("name",$DependProject->GetName());
$xml .= add_XML_value("name_encoded",urlencode($DependProject->GetName()));
$xml .= add_XML_value("nbuilderror",$DependProject->GetNumberOfErrorBuilds($beginning_UTCDate,$end_UTCDate));
$xml .= add_XML_value("nbuildwarning",$DependProject->GetNumberOfWarningBuilds($beginning_UTCDate,$end_UTCDate));
$xml .= add_XML_value("nbuildpass",$DependProject->GetNumberOfPassingBuilds($beginning_UTCDate,$end_UTCDate));
$xml .= add_XML_value("nconfigureerror",$DependProject->GetNumberOfErrorConfigures($beginning_UTCDate,$end_UTCDate));
$xml .= add_XML_value("nconfigurewarning",$DependProject->GetNumberOfWarningConfigures($beginning_UTCDate,$end_UTCDate));
$xml .= add_XML_value("nconfigurepass",$DependProject->GetNumberOfPassingConfigures($beginning_UTCDate,$end_UTCDate));
$xml .= add_XML_value("ntestpass",$DependProject->GetNumberOfPassingTests($beginning_UTCDate,$end_UTCDate));
$xml .= add_XML_value("ntestfail",$DependProject->GetNumberOfFailingTests($beginning_UTCDate,$end_UTCDate));
$xml .= add_XML_value("ntestnotrun",$DependProject->GetNumberOfNotRunTests($beginning_UTCDate,$end_UTCDate));
if(strlen($DependProject->GetLastSubmission()) == 0)
{
$xml .= add_XML_value("lastsubmission","NA");
}
else
{
$xml .= add_XML_value("lastsubmission",$DependProject->GetLastSubmission());
}
$rowparity = ($rowparity==1) ? 0:1;
$xml .= "</dependency>";
}
}
$xml .= "</subproject>";
}
else
{
add_log("Subproject '$subproject_name' does not exist",
__FILE__ . ':' . __LINE__ . ' - ' . __FUNCTION__,
LOG_WARNING);
}
}
if(isset($testingdataurl))
{
$xml .= add_XML_value("testingdataurl",$testingdataurl);
}
// updates
$xml .= "<updates>";
$gmdate = gmdate(FMT_DATE, $currentstarttime);
$xml .= "<url>viewChanges.php?project=".urlencode($projectname)."&date=".$gmdate."</url>";
$dailyupdate = pdo_query("SELECT count(ds.dailyupdateid),count(distinct ds.author)
FROM dailyupdate AS d LEFT JOIN dailyupdatefile AS ds ON (ds.dailyupdateid = d.id)
WHERE d.date='$gmdate' and d.projectid='$projectid' GROUP BY ds.dailyupdateid");
if(pdo_num_rows($dailyupdate)>0)
{
$dailupdate_array = pdo_fetch_array($dailyupdate);
$xml .= "<nchanges>".$dailupdate_array[0]."</nchanges>";
$xml .= "<nauthors>".$dailupdate_array[1]."</nauthors>";
}
else
{
$xml .= "<nchanges>-1</nchanges>";
}
$xml .= add_XML_value("timestamp",date("l, F d Y - H:i T",$currentstarttime));
$xml .= "</updates>";
// User
if(isset($_SESSION['cdash']))
{
$xml .= "<user>";
$userid = $_SESSION['cdash']['loginid'];
$user2project = pdo_query("SELECT role FROM user2project WHERE userid='$userid' and projectid='$projectid'");
$user2project_array = pdo_fetch_array($user2project);
$user = pdo_query("SELECT admin FROM ".qid("user")." WHERE id='$userid'");
$user_array = pdo_fetch_array($user);
$xml .= add_XML_value("id",$userid);
$isadmin=0;
if($user2project_array["role"]>1 || $user_array["admin"])
{
$isadmin=1;
}
$xml .= add_XML_value("admin",$isadmin);
$xml .= add_XML_value("projectrole",$user2project_array['role']);
$xml .= "</user>";
}
// Filters:
//
$filterdata = get_filterdata_from_request();
$filter_sql = $filterdata['sql'];
$limit_sql = '';
if ($filterdata['limit']>0)
{
$limit_sql = ' LIMIT '.$filterdata['limit'];
}
$xml .= $filterdata['xml'];
// Local function to add expected builds
function add_expected_builds($groupid,$currentstarttime,$received_builds)
{
include('cdash/config.php');
$currentUTCTime = gmdate(FMT_DATETIME,$currentstarttime+3600*24);
$xml = "";
$build2grouprule = pdo_query("SELECT g.siteid,g.buildname,g.buildtype,s.name,s.outoforder FROM build2grouprule AS g,site as s
WHERE g.expected='1' AND g.groupid='$groupid' AND s.id=g.siteid
AND g.starttime<'$currentUTCTime' AND (g.endtime>'$currentUTCTime' OR g.endtime='1980-01-01 00:00:00')
");
while($build2grouprule_array = pdo_fetch_array($build2grouprule))
{
$key = $build2grouprule_array["name"]."_".$build2grouprule_array["buildname"];
if(array_search($key,$received_builds) === FALSE) // add only if not found
{
$site = $build2grouprule_array["name"];
$siteid = $build2grouprule_array["siteid"];
$siteoutoforder = $build2grouprule_array["outoforder"];
$buildtype = $build2grouprule_array["buildtype"];
$buildname = $build2grouprule_array["buildname"];
$xml .= "<build>";
$xml .= add_XML_value("site",$site);
$xml .= add_XML_value("siteoutoforder",$siteoutoforder);
$xml .= add_XML_value("siteid",$siteid);
$xml .= add_XML_value("buildname",$buildname);
$xml .= add_XML_value("buildtype",$buildtype);
$xml .= add_XML_value("buildgroupid",$groupid);
$xml .= add_XML_value("expected","1");
// compute historical average to get approximate expected time
// PostgreSQL doesn't have the necessary functions for this
if($CDASH_DB_TYPE == 'pgsql')
{
$query = pdo_query("SELECT submittime FROM build,build2group
WHERE build2group.buildid=build.id AND siteid='$siteid' AND name='$buildname'
AND type='$buildtype' AND build2group.groupid='$groupid'
ORDER BY id DESC LIMIT 5");
$time = 0;
while($query_array = pdo_fetch_array($query))
{
$time += strtotime(date("H:i:s",strtotime($query_array['submittime'])));
}
if(pdo_num_rows($query)>0)
{
$time /= pdo_num_rows($query);
}
$nextExpected = strtotime(date("H:i:s",$time)." UTC");
}
else
{
$query = pdo_query("SELECT AVG(TIME_TO_SEC(TIME(submittime))) FROM (SELECT submittime FROM build,build2group
WHERE build2group.buildid=build.id AND siteid='$siteid' AND name='$buildname'
AND type='$buildtype' AND build2group.groupid='$groupid'
ORDER BY id DESC LIMIT 5) as t");
$query_array = pdo_fetch_array($query);
$time = $query_array[0];
$hours = floor($time/3600);
$time = ($time%3600);
$minutes = floor($time/60);
$seconds = ($time%60);
$nextExpected = strtotime($hours.":".$minutes.":".$seconds." UTC");
}
$divname = $build2grouprule_array["siteid"]."_".$build2grouprule_array["buildname"];
$divname = str_replace("+","_",$divname);
$divname = str_replace(".","_",$divname);
$divname = str_replace(':',"_",$divname);
$divname = str_replace(' ',"_",$divname);
$xml .= add_XML_value("expecteddivname",$divname);
$xml .= add_XML_value("submitdate","No Submission");
$xml .= add_XML_value("expectedstarttime",date(FMT_TIME,$nextExpected));
$xml .= "</build>";
}
}
return $xml;
}
// add a request for the subproject
$subprojectsql = "";
$subprojecttablesql = "";
if($subproject_name && is_numeric($subprojectid))
{
$subprojectsql = " AND sp2b.subprojectid=".$subprojectid;
}
// Use this as the default date clause, but if $filterdata has a date clause,
// then cancel this one out:
//
$date_clause = "AND b.starttime<'$end_UTCDate' AND b.starttime>='$beginning_UTCDate' ";
if($filterdata['hasdateclause'])
{
$date_clause = '';
}
if(isset($_GET["parentid"]))
{
// If we have a parentid, then we should only show children of that build.
// Date becomes irrelevant in this case.
$parent_clause ="AND (b.parentid = " . qnum($_GET["parentid"]) . ") ";
$date_clause = "";
}
else
{
// Otherwise, we should only show builds that are not children.
$parent_clause ="AND (b.parentid = -1 OR b.parentid = 0) ";
}
$build_rows = array();
// If the user is logged in we display if the build has some changes for him
$userupdatesql = "";
if(isset($_SESSION['cdash']))
{
$userupdatesql = "(SELECT count(updatefile.updateid) FROM updatefile,build2update,user2project,
user2repository
WHERE build2update.buildid=b.id
AND build2update.updateid=updatefile.updateid
AND user2project.projectid=b.projectid
AND user2project.userid='".$_SESSION['cdash']['loginid']."'
AND user2repository.userid=user2project.userid
AND (user2repository.projectid=0 OR user2repository.projectid=b.projectid)
AND user2repository.credential=updatefile.author) AS userupdates,";
}
// Postgres differs from MySQL on how to aggregate results
// into a single column.
$label_sql = "";
$groupby_sql = "";
if($CDASH_DB_TYPE != 'pgsql')
{
$label_sql = "GROUP_CONCAT(l.text SEPARATOR ', ') AS labels,";
$groupby_sql = " GROUP BY b.id";
}
$sql = "SELECT b.id,b.siteid,b.parentid,
bu.status AS updatestatus,
i.osname AS osname,
bu.starttime AS updatestarttime,
bu.endtime AS updateendtime,
bu.nfiles AS countupdatefiles,
bu.warnings AS countupdatewarnings,
c.status AS configurestatus,
c.starttime AS configurestarttime,
c.endtime AS configureendtime,
be_diff.difference_positive AS countbuilderrordiffp,
be_diff.difference_negative AS countbuilderrordiffn,
bw_diff.difference_positive AS countbuildwarningdiffp,
bw_diff.difference_negative AS countbuildwarningdiffn,
ce_diff.difference AS countconfigurewarningdiff,
btt.time AS testsduration,
tnotrun_diff.difference_positive AS counttestsnotrundiffp,
tnotrun_diff.difference_negative AS counttestsnotrundiffn,
tfailed_diff.difference_positive AS counttestsfaileddiffp,
tfailed_diff.difference_negative AS counttestsfaileddiffn,
tpassed_diff.difference_positive AS counttestspasseddiffp,
tpassed_diff.difference_negative AS counttestspasseddiffn,
tstatusfailed_diff.difference_positive AS countteststimestatusfaileddiffp,
tstatusfailed_diff.difference_negative AS countteststimestatusfaileddiffn,
(SELECT count(buildid) FROM build2note WHERE buildid=b.id) AS countnotes,
(SELECT count(buildid) FROM buildnote WHERE buildid=b.id) AS countbuildnotes,"
.$userupdatesql."
s.name AS sitename,
s.outoforder AS siteoutoforder,
b.stamp,b.name,b.type,b.generator,b.starttime,b.endtime,b.submittime,
b.configureerrors AS countconfigureerrors,
b.configurewarnings AS countconfigurewarnings,
b.builderrors AS countbuilderrors,
b.buildwarnings AS countbuildwarnings,
b.testnotrun AS counttestsnotrun,
b.testfailed AS counttestsfailed,
b.testpassed AS counttestspassed,
b.testtimestatusfailed AS countteststimestatusfailed,
sp.id AS subprojectid,
sp.core AS subprojectcore,
g.name as groupname,gp.position,g.id as groupid,
$label_sql
(SELECT count(buildid) FROM errorlog WHERE buildid=b.id) AS nerrorlog,
(SELECT count(buildid) FROM build2uploadfile WHERE buildid=b.id) AS builduploadfiles
FROM build AS b
LEFT JOIN build2group AS b2g ON (b2g.buildid=b.id)
LEFT JOIN buildgroup AS g ON (g.id=b2g.groupid)
LEFT JOIN buildgroupposition AS gp ON (gp.buildgroupid=g.id)
LEFT JOIN site AS s ON (s.id=b.siteid)
LEFT JOIN build2update AS b2u ON (b2u.buildid=b.id)
LEFT JOIN buildupdate AS bu ON (b2u.updateid=bu.id)
LEFT JOIN configure AS c ON (c.buildid=b.id)
LEFT JOIN buildinformation AS i ON (i.buildid=b.id)
LEFT JOIN builderrordiff AS be_diff ON (be_diff.buildid=b.id AND be_diff.type=0)
LEFT JOIN builderrordiff AS bw_diff ON (bw_diff.buildid=b.id AND bw_diff.type=1)
LEFT JOIN configureerrordiff AS ce_diff ON (ce_diff.buildid=b.id AND ce_diff.type=1)
LEFT JOIN buildtesttime AS btt ON (btt.buildid=b.id)
LEFT JOIN testdiff AS tnotrun_diff ON (tnotrun_diff.buildid=b.id AND tnotrun_diff.type=0)
LEFT JOIN testdiff AS tfailed_diff ON (tfailed_diff.buildid=b.id AND tfailed_diff.type=1)
LEFT JOIN testdiff AS tpassed_diff ON (tpassed_diff.buildid=b.id AND tpassed_diff.type=2)
LEFT JOIN testdiff AS tstatusfailed_diff ON (tstatusfailed_diff.buildid=b.id AND tstatusfailed_diff.type=3)
LEFT JOIN subproject2build AS sp2b ON (sp2b.buildid = b.id)
LEFT JOIN subproject as sp ON (sp2b.subprojectid = sp.id)
LEFT JOIN label2build AS l2b ON (l2b.buildid = b.id)
LEFT JOIN label AS l ON (l.id = l2b.labelid)
WHERE b.projectid='$projectid' $parent_clause $date_clause
".$subprojectsql." ".$filter_sql." ".$limit_sql
.$groupby_sql;
// We shouldn't get any builds for group that have been deleted (otherwise something is wrong)
$builds = pdo_query($sql);
echo pdo_error();
// Sort results from this query.
// We used to do this in MySQL with the following directive:
// ORDER BY gp.position ASC,b.name ASC,b.siteid ASC,b.stamp DESC
// But this dramatically impacted performance when the number of rows was
// relatively large (in the thousands). So now we accomplish the same
// sorting within PHP instead.
$build_data = array();
while($build_row = pdo_fetch_array($builds))
{
$build_data[] = $build_row;
}
$positions = array();
$names = array();
$siteids = array();
$stamps = array();
foreach ($build_data as $key => $row)
{
$positions[$key] = $row['position'];
$names[$key] = $row['name'];
$siteids[$key] = $row['siteid'];
$stamps[$key] = $row['stamp'];
}
array_multisort($positions, SORT_ASC, $names, SORT_ASC, $siteids, SORT_ASC,
$stamps, SORT_DESC, $build_data);
// The SQL results are ordered by group so this should work
// Group position have to be continuous
$previousgroupposition = -1;
$received_builds = array();
// Find the last position of the group
$groupposition_array = pdo_fetch_array(pdo_query("SELECT gp.position FROM buildgroupposition AS gp,buildgroup AS g
WHERE g.projectid='$projectid' AND g.id=gp.buildgroupid
AND gp.starttime<'$end_UTCDate' AND (gp.endtime>'$end_UTCDate' OR gp.endtime='1980-01-01 00:00:00')
ORDER BY gp.position DESC LIMIT 1"));
$lastGroupPosition = $groupposition_array["position"];
// Check if we need to summarize core & non-core subproject covearge
// This happens when (1) we have subprojects, (2) we're looking at the children
// of a specific build, and (3) some subprojects are categorized as core,
// and others are categorized as non-core.
$summarizeCoreCoverage = false;
if ( isset($_GET["parentid"]) && $_GET["parentid"] > 0 &&
$project_instance->GetNumberOfSubProjects($end_UTCDate) > 0)
{
$core_array = pdo_fetch_array(pdo_query(
"SELECT COUNT(IF(core=1, core, NULL)) AS core,
COUNT(IF(core=0, core, NULL)) AS noncore FROM subproject"));
if ($core_array && $core_array["core"] > 0 && $core_array["noncore"] > 0)
{
$summarizeCoreCoverage = true;
}
}
$nonCoreTested = 0;
$nonCoreUntested = 0;
$coreTested = 0;
$coreUntested = 0;
// Fetch all the rows of builds into a php array.
// Compute additional fields for each row that we'll need to generate the xml.
//
$build_rows = array();
foreach ($build_data as $build_row)
{
// Fields that come from the initial query:
// id
// sitename
// stamp
// name
// siteid
// type
// generator
// starttime
// endtime
// submittime
// groupname
// position
// groupid
// countupdatefiles
// updatestatus
// countupdatewarnings
// countbuildwarnings
// countbuilderrors
// countbuilderrordiff
// countbuildwarningdiff
// configurestatus
// countconfigureerrors
// countconfigurewarnings
// countconfigurewarningdiff
// counttestsnotrun
// counttestsnotrundiff
// counttestsfailed
// counttestsfaileddiff
// counttestspassed
// counttestspasseddiff
// countteststimestatusfailed
// countteststimestatusfaileddiff
// testsduration
//
// Fields that we add within this loop:
// maxstarttime
// buildids (array of buildids for summary rows)
// countbuildnotes (added by users)
// labels
// updateduration
// countupdateerrors
// buildduration
// hasconfigurestatus
// configureduration
// test
//
$buildid = $build_row['id'];
$groupid = $build_row['groupid'];
$siteid = $build_row['siteid'];
$parentid = $build_row['parentid'];
$build_row['buildids'][] = $buildid;
$build_row['maxstarttime'] = $build_row['starttime'];
// Split out labels
if (empty($build_row['labels']))
{
$build_row['labels'] = array();
}
else
{
$build_row['labels'] = explode(",", $build_row['labels']);
}
// If this is a parent build get the labels from all the children too.
if ($parentid == -1)
{
$query = "SELECT l.text FROM build AS b
INNER JOIN label2build AS l2b ON l2b.buildid = b.id
INNER JOIN label AS l ON l.id = l2b.labelid
WHERE b.parentid='$buildid'";
$childLabelsResult = pdo_query($query);
while($childLabelsArray = pdo_fetch_array($childLabelsResult))
{
$build_row['labels'][] = $childLabelsArray['text'];
}
}
// Updates
if(!empty($build_row['updatestarttime']))
{
$build_row['updateduration'] = round((strtotime($build_row['updateendtime'])-strtotime($build_row['updatestarttime']))/60,1);
}
else
{
$build_row['updateduration'] = 0;
}
if(strlen($build_row["updatestatus"]) > 0 &&
$build_row["updatestatus"]!="0")
{
$build_row['countupdateerrors'] = 1;
}
else
{
$build_row['countupdateerrors'] = 0;
}
$build_row['buildduration'] = round((strtotime($build_row['endtime'])-strtotime($build_row['starttime']))/60,1);
// Error/Warnings differences
if(empty($build_row['countbuilderrordiffp']))
{
$build_row['countbuilderrordiffp'] = 0;
}
if(empty($build_row['countbuilderrordiffn']))
{
$build_row['countbuilderrordiffn'] = 0;
}
if(empty($build_row['countbuildwarningdiffp']))
{
$build_row['countbuildwarningdiffp'] = 0;
}
if(empty($build_row['countbuildwarningdiffn']))
{
$build_row['countbuildwarningdiffn'] = 0;
}
if ($build_row['countconfigureerrors'] < 0)
{
$build_row['countconfigureerrors'] = 0;
}
if ($build_row['countconfigurewarnings'] < 0)
{
$build_row['countconfigurewarnings'] = 0;
}
$build_row['hasconfigurestatus'] = 0;
$build_row['configureduration'] = 0;
if(strlen($build_row['configurestatus'])>0)
{
$build_row['hasconfigurestatus'] = 1;
$build_row['configureduration'] = round((strtotime($build_row["configureendtime"])-strtotime($build_row["configurestarttime"]))/60, 1);
}
if(empty($build_row['countconfigurewarningdiff']))
{
$build_row['countconfigurewarningdiff'] = 0;
}
$build_row['hastest'] = 0;
if($build_row['counttestsfailed']!=-1)
{
$build_row['hastest'] = 1;
}
if(empty($build_row['testsduration']))
{
$time_array = pdo_fetch_array(pdo_query("SELECT SUM(time) FROM build2test WHERE buildid='$buildid'"));
$build_row['testsduration'] = round($time_array[0]/60,1);
}
else
{
$build_row['testsduration'] = round($build_row['testsduration'],1); //already in minutes
}
$build_rows[] = $build_row;
}
// Generate the xml from the rows of builds:
//
$totalUpdatedFiles = 0;
$totalUpdateError = 0;
$totalUpdateWarning = 0;
$totalUpdateDuration = 0;
$totalConfigureError = 0;
$totalConfigureWarning = 0;
$totalConfigureDuration = 0;
$totalerrors = 0;
$totalwarnings = 0;
$totalBuildDuration = 0;
$totalnotrun = 0;
$totalfail= 0;
$totalpass = 0;
$totalTestsDuration = 0;
foreach($build_rows as $build_array)
{
$groupposition = $build_array["position"];