Eliminate the margin on timeline elements so multiple timelines can touch.
[WebKit-https.git] / Websites / test-results / public / admin / index.php
1 <?php
2
3 include('../include/admin-header.php');
4 include('../include/test-results.php');
5
6 notice("FIXME: This page is broken!");
7
8 define('MAX_FETCH_COUNT', 10);
9
10 function fetch_builders($db, $master) {
11     flush();
12     $builders_json = fetch_and_parse_test_results_json("http://$master/json/builders/");
13     if (!$builders_json)
14         return notice("Failed to fetch or decode /json/builders from $master");
15
16     echo "<h2>Fetching builds from $master</h2>\n";
17     echo "<ul>\n";
18
19     foreach ($builders_json as $builder_name => $builder_data) {
20         if (!stristr($builder_name, 'Test') || stristr($builder_name, 'Apple Win'))
21             continue;
22         $builder_id = $db->select_or_insert_row('builders', NULL, array('master' => $master, 'name' => $builder_name));
23         $escaped_builder_name = htmlspecialchars($builder_name);
24         echo "<li><em>$escaped_builder_name</em> (id: $builder_id) - ";
25
26         $fetchCount = 0;
27         $builds = $builder_data['cachedBuilds'];
28         foreach (array_reverse($builds) as $build_number) {
29             $build_number = intval($build_number);
30             $build = $db->select_or_insert_row('builds', NULL, array('builder' => $builder_id, 'number' => $build_number), NULL, '*');
31             if ($db->is_true($build['fetched']))
32                 $class = 'fetched';
33             else if ($fetchCount >= MAX_FETCH_COUNT)
34                 $class = 'unfetched';
35             else {
36                 $class = fetch_build($db, $master, $builder_name, $build['id'], $build_number) ? 'fetched' : 'unfetched';
37                 $fetchCount++;
38             }
39             echo "<span class=\"$class\">$build_number</a> ";
40         }
41         echo "</li>\n";
42     }
43     echo "<ul>\n";
44
45     return TRUE;
46 }
47
48 function urlencode_without_plus($url) {
49     return str_replace('+', '%20', urlencode($url));
50 }
51
52 function fetch_build($db, $master, $builder_name, $build_id, $build_number) {
53     flush();
54     $builder_name = urlencode_without_plus($builder_name);
55     $build_json = fetch_and_parse_test_results_json("http://$master/json/builders/$builder_name/builds/$build_number");
56     if (!$build_json || !array_key_exists('times', $build_json) || count($build_json['times']) != 2)
57         return FALSE;
58
59     $revision = NULL;
60     $slavename = NULL;
61     foreach ($build_json['properties'] as $property) {
62         if ($property[0] == 'got_revision')
63             $revision = $property[1];
64         if ($property[0] == 'slavename')
65             $slavename = $property[2];
66     }
67     if (!$revision || !$slavename)
68         return FALSE;
69
70     $start_time = float_to_time($build_json['times'][0]);
71     $end_time = float_to_time($build_json['times'][1]);
72
73     flush();
74     $full_results = fetch_and_parse_test_results_json("http://$master/results/$builder_name/r$revision%20($build_number)/full_results.json", TRUE);
75     return store_test_results($db, $full_results, $build_id, $revision, $start_time, $end_time, $slavename);
76 }
77
78 $db = new Database;
79 if (!$db->connect())
80     notice('Failed to connect to the database');
81 else if (array_key_exists('master', $_GET)) {
82     $master = htmlspecialchars($_GET['master']); // Okay since hostname shoudln't contain any HTML special characters.
83     if (in_array($master, config('masters')))
84         fetch_builders($db, $master);
85     else
86         notice("The master $master not found");
87 } else {
88     echo "<ul>\n";
89     foreach (config('masters') as $master)
90         echo "<li><a href=\"?master=$master\">$master</a></li>\n";
91     echo "</ul>\n";
92 }
93
94 ?></div>
95
96 </body>
97 </html>