AX: AXIsolatedTree::updateChildren sometimes fails to update isolated subtrees when...
[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)) {
17         $task_id = array_get($_GET, 'task');
18         if (!$task_id)
19             exit_with_error('TaskIdNotSpecified');
20
21         $test_groups = $db->select_rows('analysis_test_groups', 'testgroup', array('task' => $task_id));
22         if (!is_array($test_groups))
23             exit_with_error('FailedToFetchTestGroups');
24         $build_requests_fetcher->fetch_for_task($task_id);
25     } elseif ($path[0] == 'ready-for-notification') {
26         $test_groups = $db->query_and_fetch_all("SELECT * FROM analysis_test_groups
27             WHERE EXISTS(SELECT 1 FROM build_requests
28                 WHERE request_group = testgroup_id
29                     AND request_status IN ('pending', 'scheduled', 'running', 'canceled')) IS FALSE
30                     AND testgroup_needs_notification IS TRUE AND testgroup_hidden IS FALSE");
31
32         if (!count($test_groups)) {
33             exit_with_success(array('testGroups' => array(),
34                 'buildRequests' => array(),
35                 'commitSets' => array(),
36                 'commits' => array(),
37                 'uploadedFiles' => array()));
38         }
39         $build_requests_fetcher->fetch_requests_for_groups($test_groups);
40     } elseif ($path[0] == 'need-more-requests') {
41         $test_groups = $db->select_rows('analysis_test_groups', 'testgroup', array("hidden" => FALSE, "may_need_more_requests" => TRUE));
42         if (!count($test_groups)) {
43             exit_with_success(array('testGroups' => array(),
44                 'buildRequests' => array(),
45                 'commitSets' => array(),
46                 'commits' => array(),
47                 'uploadedFiles' => array()));
48         }
49         $build_requests_fetcher->fetch_requests_for_groups($test_groups);
50     } else {
51         $group_id = intval($path[0]);
52         $group = $db->select_first_row('analysis_test_groups', 'testgroup', array('id' => $group_id));
53         if (!$group)
54             exit_with_error('GroupNotFound', array('id' => $group_id));
55         $test_groups = array($group);
56         $build_requests_fetcher->fetch_for_group($group['testgroup_task'], $group_id);
57     }
58     if (!$build_requests_fetcher->has_results())
59         exit_with_error('FailedToFetchBuildRequests');
60
61     $test_groups = array_map("format_test_group", $test_groups);
62     $group_by_id = array();
63     foreach ($test_groups as &$group) {
64         $group_id = $group['id'];
65         $group_by_id[$group_id] = &$group;
66         $first_request = $db->select_first_row('build_requests', 'request', array('group' => $group_id), 'order');
67         if ($first_request)
68             $group['platform'] = $first_request['request_platform'];
69     }
70
71     $build_requests = $build_requests_fetcher->results();
72     foreach ($build_requests as $request) {
73         $request_group = &$group_by_id[$request['testGroup']];
74         array_push($request_group['buildRequests'], $request['id']);
75         array_push($request_group['commitSets'], $request['commitSet']);
76     }
77
78     exit_with_success(array('testGroups' => $test_groups,
79         'buildRequests' => $build_requests,
80         'commitSets' => $build_requests_fetcher->commit_sets(),
81         'commits' => $build_requests_fetcher->commits(),
82         'uploadedFiles' => $build_requests_fetcher->uploaded_files()));
83 }
84
85 function format_test_group($group_row) {
86     return array(
87         'id' => $group_row['testgroup_id'],
88         'task' => $group_row['testgroup_task'],
89         'name' => $group_row['testgroup_name'],
90         'author' => $group_row['testgroup_author'],
91         'createdAt' => Database::to_js_time($group_row['testgroup_created_at']),
92         'notificationSentAt' => Database::to_js_time($group_row['testgroup_notification_sent_at']),
93         'hidden' => Database::is_true($group_row['testgroup_hidden']),
94         'needsNotification' => Database::is_true($group_row['testgroup_needs_notification']),
95         'mayNeedMoreRequests' => Database::is_true($group_row['testgroup_may_need_more_requests']),
96         'initialRepetitionCount' => $group_row['testgroup_initial_repetition_count'],
97         'repetitionType' => $group_row['testgroup_repetition_type'],
98         'buildRequests' => array(),
99         'commitSets' => array(),
100     );
101 }
102
103 main(array_key_exists('PATH_INFO', $_SERVER) ? explode('/', trim($_SERVER['PATH_INFO'], '/')) : array());
104
105 ?>