Fix the link noted 'contribute to features' in status.html
[WebKit-https.git] / Websites / perf.webkit.org / public / api / test-groups.php
1 <?php
2
3 require_once('../include/json-header.php');
4 require_once('../include/build-requests-fetcher.php');
5
6 function main($path) {
7     $db = new Database;
8     if (!$db->connect())
9         exit_with_error('DatabaseConnectionFailure');
10
11     if (count($path) > 1)
12         exit_with_error('InvalidRequest');
13
14     $build_requests_fetcher = new BuildRequestsFetcher($db);
15
16     if (count($path) > 0 && $path[0]) {
17         $group_id = intval($path[0]);
18         $group = $db->select_first_row('analysis_test_groups', 'testgroup', array('id' => $group_id));
19         if (!$group)
20             exit_with_error('GroupNotFound', array('id' => $group_id));
21         $test_groups = array($group);
22         $build_requests_fetcher->fetch_for_group($group_id);
23     } else {
24         $task_id = array_get($_GET, 'task');
25         if (!$task_id)
26             exit_with_error('TaskIdNotSpecified');
27
28         $test_groups = $db->select_rows('analysis_test_groups', 'testgroup', array('task' => $task_id));
29         if (!is_array($test_groups))
30             exit_with_error('FailedToFetchTestGroups');
31         $build_requests_fetcher->fetch_for_task($task_id);
32     }
33     if (!$build_requests_fetcher->has_results())
34         exit_with_error('FailedToFetchBuildRequests');
35
36     $test_groups = array_map("format_test_group", $test_groups);
37     $group_by_id = array();
38     foreach ($test_groups as &$group)
39         $group_by_id[$group['id']] = &$group;
40
41     $build_requests = $build_requests_fetcher->results();
42     foreach ($build_requests as $request) {
43         $request_group = &$group_by_id[$request['testGroup']];
44         array_push($request_group['buildRequests'], $request['id']);
45         array_push($request_group['rootSets'], $request['rootSet']);
46     }
47
48     exit_with_success(array('testGroups' => $test_groups,
49         'buildRequests' => $build_requests,
50         'rootSets' => $build_requests_fetcher->root_sets(),
51         'roots' => $build_requests_fetcher->roots()));
52 }
53
54 function format_test_group($group_row) {
55     return array(
56         'id' => $group_row['testgroup_id'],
57         'task' => $group_row['testgroup_task'],
58         'name' => $group_row['testgroup_name'],
59         'author' => $group_row['testgroup_author'],
60         'createdAt' => strtotime($group_row['testgroup_created_at']) * 1000,
61         'buildRequests' => array(),
62         'rootSets' => array(),
63     );
64 }
65
66 main(array_key_exists('PATH_INFO', $_SERVER) ? explode('/', trim($_SERVER['PATH_INFO'], '/')) : array());
67
68 ?>