Merge database-common.js and utility.js into run-tests.js.
[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.php');
5 require_once('../include/report-processor.php');
6
7 function main($post_data) {
8     set_exit_detail('failureStored', false);
9
10     $db = new Database;
11     if (!$db->connect())
12         exit_with_error('DatabaseConnectionFailure');
13
14     // Convert all floating points to strings to avoid parsing them in PHP.
15     // FIXME: Do this conversion in the submission scripts themselves.
16     $parsed_json = json_decode(preg_replace('/(?<=[\s,\[])(\d+(\.\d+)?)(\s*[,\]])/', '"$1"$3', $post_data), true);
17     if (!$parsed_json)
18         exit_with_error('FailedToParseJSON');
19
20     set_exit_detail('processedRuns', 0);
21     foreach ($parsed_json as $i => $report) {
22         $processor = new ReportProcessor($db);
23         $processor->process($report);
24         set_exit_detail('processedRuns', $i + 1);
25     }
26
27     $generator = new ManifestGenerator($db);
28     if (!$generator->generate())
29         exit_with_error('FailedToGenerateManifest');
30     else if (!$generator->store())
31         exit_with_error('FailedToStoreManifest');
32
33     exit_with_success();
34 }
35
36 main($HTTP_RAW_POST_DATA);
37
38 ?>