[Mac] inform media session of all state changes
[WebKit-https.git] / Websites / perf.webkit.org / public / include / build-requests-fetcher.php
1 <?php
2
3 require_once('test-path-resolver.php');
4
5 class BuildRequestsFetcher {
6     function __construct($db) {
7         $this->db = $db;
8         $this->rows = null;
9         $this->root_sets = array();
10         $this->roots = array();
11         $this->root_sets_by_id = array();
12     }
13
14     function fetch_for_task($task_id) {
15         $this->rows = $this->db->query_and_fetch_all('SELECT *
16             FROM build_requests LEFT OUTER JOIN builds ON request_build = build_id, analysis_test_groups
17             WHERE request_group = testgroup_id AND testgroup_task = $1
18             ORDER BY request_group, request_order', array($task_id));
19     }
20
21     function fetch_for_group($test_group_id) {
22         $this->rows = $this->db->query_and_fetch_all('SELECT *
23             FROM build_requests LEFT OUTER JOIN builds ON request_build = build_id
24             WHERE request_group = $1 ORDER BY request_order', array($test_group_id));
25     }
26
27     function fetch_incomplete_requests_for_triggerable($triggerable_id) {
28         $this->rows = $this->db->query_and_fetch_all('SELECT * FROM build_requests
29             WHERE request_triggerable = $1 AND request_status != \'completed\'
30             ORDER BY request_created_at, request_group, request_order', array($triggerable_id));
31     }
32
33     function has_results() { return is_array($this->rows); }
34     function results() { return $this->results_internal(false); }
35     function results_with_resolved_ids() { return $this->results_internal(true); }
36
37     private function results_internal($resolve_ids) {
38         if (!$this->rows)
39             return array();
40
41         $id_to_platform_name = array();
42         if ($resolve_ids) {
43             foreach ($this->db->select_rows('platforms', 'platform', array()) as $platform)
44                 $id_to_platform_name[$platform['platform_id']] = $platform['platform_name'];
45         }
46         $test_path_resolver = new TestPathResolver($this->db);
47
48         $requests = array();
49         foreach ($this->rows as $row) {
50             $test_id = $row['request_test'];
51             $platform_id = $row['request_platform'];
52             $root_set_id = $row['request_root_set'];
53
54             if (!array_key_exists($root_set_id, $this->root_sets_by_id))
55                 $this->root_sets_by_id[$root_set_id] = $this->fetch_roots_for_set($root_set_id, $resolve_ids);
56
57             array_push($requests, array(
58                 'id' => $row['request_id'],
59                 'triggerable' => $row['request_triggerable'],
60                 'test' => $resolve_ids ? $test_path_resolver->path_for_test($test_id) : $test_id,
61                 'platform' => $resolve_ids ? $id_to_platform_name[$platform_id] : $platform_id,
62                 'testGroup' => $row['request_group'],
63                 'order' => $row['request_order'],
64                 'rootSet' => $root_set_id,
65                 'status' => $row['request_status'],
66                 'url' => $row['request_url'],
67                 'build' => $row['request_build'],
68                 'createdAt' => $row['request_created_at'] ? strtotime($row['request_created_at']) * 1000 : NULL,
69             ));
70         }
71         return $requests;
72     }
73
74     function root_sets_by_id() {
75         return $this->root_sets_by_id;
76     }
77
78     function root_sets() {
79         return $this->root_sets;
80     }
81
82     function roots() {
83         return $this->roots;
84     }
85
86     private function fetch_roots_for_set($root_set_id, $resolve_ids) {
87         $root_rows = $this->db->query_and_fetch_all('SELECT *
88             FROM roots, commits LEFT OUTER JOIN repositories ON commit_repository = repository_id
89             WHERE root_commit = commit_id AND root_set = $1', array($root_set_id));
90
91         $roots = array();
92         $root_ids = array();
93         foreach ($root_rows as $row) {
94             $repository = $row['repository_id'];
95             $revision = $row['commit_revision'];
96             $commit_time = $row['commit_time'];
97             $root_id = $root_set_id . '-' . $repository;
98             array_push($root_ids, $root_id);
99             array_push($this->roots, array('id' => $root_id, 'repository' => $repository, 'revision' => $revision));
100             $roots[$resolve_ids ? $row['repository_name'] : $row['repository_id']] = array('revision' => $revision, 'time' => $commit_time);
101         }
102         array_push($this->root_sets, array('id' => $root_set_id, 'roots' => $root_ids));
103
104         return $roots;
105     }
106 }
107
108 ?>