Update data/params after Bugzilla 4.2.11 upgrade
[WebKit-https.git] / Websites / perf.webkit.org / public / admin / tests.php
1 <?php
2
3 require_once('../include/admin-header.php');
4 require_once('../include/test-name-resolver.php');
5
6 if ($action == 'dashboard') {
7     if (array_key_exists('metric_id', $_POST)) {
8         $metric_id = intval($_POST['metric_id']);
9         $config_ids = array();
10         $succeeded = TRUE;
11         if (!$db->query_and_get_affected_rows("UPDATE test_configurations SET config_is_in_dashboard = false WHERE config_metric = $1", array($metric_id))) {
12             $succeeded = FALSE;
13             notice("Failed to remove some configurations from the dashboard.");
14         }
15
16         else if (array_key_exists('metric_platforms', $_POST)) {
17             foreach ($_POST['metric_platforms'] as $platform_id) {
18                 if (!$db->query_and_get_affected_rows("UPDATE test_configurations SET config_is_in_dashboard = true
19                     WHERE config_metric = $1 AND config_platform = $2", array($metric_id, $platform_id))) {
20                     $succeeded = FALSE;
21                     notice("Failed to add configurations for metric $metric_id and platform $platform_id to the dashboard.");
22                 }
23             }
24         }
25
26         if ($succeeded) {
27             notice("Updated the dashboard.");
28             regenerate_manifest();
29         }
30     } else
31         notice('Invalid parameters');
32 } else if ($action == 'update') {
33     if (!update_field('tests', 'test', 'url'))
34         notice('Invalid parameters');
35 } else if ($action == 'add') {
36     if (array_key_exists('test_id', $_POST) && array_key_exists('metric_name', $_POST)) {
37         $id = intval($_POST['test_id']);
38         $aggregator = intval($_POST['metric_aggregator']);
39         if (!$aggregator)
40             notice('Invalid aggregator. You must specify one.');
41         else {
42             $metric_id = $db->insert_row('test_metrics', 'metric',
43                 array('test' => $id, 'name' => $_POST['metric_name'], 'aggregator' => $aggregator));
44             if (!$metric_id)
45                 notice("Could not insert the new metric for test $id");
46             else
47                 notice("Inserted the metric for test $id. Aggregation for $metric_id is needed.");
48         }
49     } else if (array_key_exists('metric_id', $_POST))
50         regenerate_manifest();
51     else
52         notice('Invalid parameters');
53 }
54
55 if ($db) {
56     $aggregators = array();
57     if ($aggregators_table = $db->fetch_table('aggregators')) {
58         foreach ($aggregators_table as $aggregator_row)
59             $aggregators[$aggregator_row['aggregator_id']] = $aggregator_row['aggregator_name'];
60     }
61
62     $test_name_resolver = new TestNameResolver($db);
63     if ($test_name_resolver->tests()) {
64         $name_to_platform = array();
65
66         foreach ($db->fetch_table('platforms') as $platform)
67             $name_to_platform[$platform['platform_name']] = $platform;
68
69         $platform_names = array_keys($name_to_platform);
70         asort($platform_names);
71
72         $odd = false;
73         $selected_parent_full_name = trim(array_get($_SERVER, 'PATH_INFO', ''), '/');
74         $selected_parent = $test_name_resolver->test_id_for_full_name($selected_parent_full_name);
75         if ($selected_parent)
76             echo '<h2>' . htmlspecialchars($selected_parent_full_name) . '</h2>';
77
78 ?>
79 <table>
80 <thead>
81     <tr><td>Test ID</td><td>Full Name</td><td>Parent ID</td><td>URL</td>
82         <td>Metric ID</td><td>Metric Name</td><td>Aggregator</td><td>Dashboard</td>
83 </thead>
84 <tbody>
85 <?php
86
87         foreach ($test_name_resolver->tests() as $test) {
88             if ($test['test_parent'] != $selected_parent['test_id'])
89                 continue;
90
91             $test_id = $test['test_id'];
92             $test_metrics = $test_name_resolver->metrics_for_test_id($test_id);
93             $row_count = count($test_metrics);
94             $child_metrics = $test_name_resolver->child_metrics_for_test_id($test_id);
95             $linked_test_name = htmlspecialchars($test['full_name']);
96             if ($child_metrics) {
97                 $row_count++;
98                 $linked_test_name = '<a href="/admin/tests/' . htmlspecialchars($test['full_name']) . '">' . $linked_test_name . '</a>';
99             }
100
101             $tbody_class = $odd ? 'odd' : 'even';
102             $odd = !$odd;
103
104             $test_url = htmlspecialchars($test['test_url']);
105
106             echo <<<EOF
107     <tbody class="$tbody_class">
108     <tr>
109         <td rowspan="$row_count">$test_id</td>
110         <td rowspan="$row_count">$linked_test_name</td>
111         <td rowspan="$row_count">{$test['test_parent']}</td>
112         <td rowspan="$row_count">
113         <form method="POST"><input type="hidden" name="id" value="$test_id">
114         <input type="hidden" name="action" value="update">
115         <input type="url" name="url" value="$test_url" size="80"></form></td>
116 EOF;
117
118             if ($test_metrics) {
119                 $has_tr = true;
120                 foreach ($test_metrics as $metric) {
121                     $aggregator_name = array_get($aggregators, $metric['metric_aggregator'], '');
122                     if ($aggregator_name) {
123                         $aggregator_action = '<form method="POST"><input type="hidden" name="metric_id" value="'. $metric['metric_id']
124                             . '"><button type="submit" name="action" value="add">Regenerate</button></form>';
125                     } else
126                         $aggregator_action = '';
127
128                     if (!$has_tr)
129                         echo <<<EOF
130
131     <tr>
132 EOF;
133                     $has_tr = false;
134
135                     $metric_id = $metric['metric_id'];
136                     echo <<<EOF
137         <td><a href="/admin/test-configurations?metric=$metric_id">$metric_id</a></td>
138         <td>{$metric['metric_name']}</td>
139         <td>$aggregator_name $aggregator_action</td>
140         <td><form method="POST"><input type="hidden" name="metric_id" value="$metric_id">
141 EOF;
142
143                     foreach ($platform_names as $platform_name) {
144                         $platform_name = htmlspecialchars($platform_name);
145                         $platform = $name_to_platform[$platform_name];
146                         $configurations = $test_name_resolver->configurations_for_metric_and_platform($metric_id, $platform['platform_id']);
147                         if (!$configurations)
148                             continue;
149                         echo "<label><input type=\"checkbox\" name=\"metric_platforms[]\" value=\"{$platform['platform_id']}\"";
150                         if ($db->is_true($configurations[0]['config_is_in_dashboard']))
151                             echo ' checked';
152                         else if ($db->is_true($platform['platform_hidden']))
153                             echo 'disabled';
154                         echo ">$platform_name</label>";
155                     }
156
157                     echo <<<EOF
158         <button type="submit" name="action" value="dashboard">Save</button></form>
159         </td>
160     </tr>
161 EOF;
162                 }
163             }
164
165             if ($child_metrics) {
166                 echo <<<EOF
167         <td colspan="5"><form method="POST">
168         <input type="hidden" name="test_id" value="$test_id">
169         <label>Name<select name="metric_name">
170 EOF;
171
172                 foreach ($child_metrics as $metric_name) {
173                     $metric_name = htmlspecialchars($metric_name);
174                     echo "
175             <option>$metric_name</option>";
176                 }
177
178                 echo <<<EOF
179         </select></label>
180         <label>Aggregator
181         <select name="metric_aggregator">
182             <option value="">-</option>
183 EOF;
184             foreach ($aggregators as $id => $name) {
185                 $name = htmlspecialchars($name);
186                 echo "
187             <option value=\"$id\">$name</option>";
188             }
189             echo <<<EOF
190         </select></label>
191         <button type="submit" name="action" value="add">Add</button></form></td>
192     </tr>
193 EOF;
194             }
195             echo <<<EOF
196     </tbody>
197 EOF;
198         }
199
200         ?></tbody>
201 </table>
202
203 <?php
204
205     }
206
207 }
208
209 include('../include/admin-footer.php');
210
211 ?>