Add a bisect button to automatically schedule bisecting A/B tasks.
[WebKit-https.git] / Websites / perf.webkit.org / public / api / report.php
1 <?php
2
3 require_once('../include/json-header.php');
4 require_once('../include/manifest-generator.php');
5 require_once('../include/report-processor.php');
6
7 function main($post_data) {
8     set_exit_detail('failureStored', false);
9
10     $maintenance_mode = config('maintenanceMode');
11     if ($maintenance_mode && !config('maintenanceDirectory'))
12         exit_with_error('MaintenanceDirectoryNotSet');
13
14     $db = new Database;
15     if (!$maintenance_mode && !$db->connect())
16         exit_with_error('DatabaseConnectionFailure');
17
18     // Convert all floating points to strings to avoid parsing them in PHP.
19     // FIXME: Do this conversion in the submission scripts themselves.
20     $parsed_json = json_decode(preg_replace('/(?<=[\s,\[])(\d+(\.\d+)?)(\s*[,\]])/', '"$1"$3', $post_data), true);
21     if (!$parsed_json)
22         exit_with_error('FailedToParseJSON');
23
24     set_exit_detail('processedRuns', 0);
25     foreach ($parsed_json as $i => $report) {
26         if (!$maintenance_mode) {
27             $processor = new ReportProcessor($db);
28             $processor->process($report);
29         }
30         set_exit_detail('processedRuns', $i + 1);
31     }
32
33     if ($maintenance_mode) {
34         $files = scandir(config_path('maintenanceDirectory', ''));
35         $i = 0;
36         $filename = '';
37         do {
38             $i++;
39             $filename = "$i.json";
40         } while (in_array($filename, $files));
41         file_put_contents(config_path('maintenanceDirectory', $filename), $post_data, LOCK_EX);
42     } else {
43         $generator = new ManifestGenerator($db);
44         if (!$generator->generate())
45             exit_with_error('FailedToGenerateManifest');
46         else if (!$generator->store())
47             exit_with_error('FailedToStoreManifest');
48     }
49
50     exit_with_success();
51 }
52
53 main(file_get_contents('php://input'));
54
55 ?>