UI to associate bugs with an analysis task is crappy
[WebKit-https.git] / Websites / perf.webkit.org / public / privileged-api / create-analysis-task.php
index cb8e5224b34e59bb65b5ece719b5705b91fd9d35..0a9d32f750c1fc2647092fbd55b387e55ef4023e 100644 (file)
@@ -3,26 +3,48 @@
 require_once('../include/json-header.php');
 
 function main() {
-    $data = ensure_privileged_api_data_and_token();
+    $db = connect();
+    $data = ensure_privileged_api_data_and_token_or_slave($db);
 
-    $author = remote_user_name();
+    $author = remote_user_name($data);
     $name = array_get($data, 'name');
     $start_run_id = array_get($data, 'startRun');
     $end_run_id = array_get($data, 'endRun');
 
+    $segmentation_name = array_get($data, 'segmentationStrategy');
+    $test_range_name = array_get($data, 'testRangeStrategy');
+
     if (!$name)
         exit_with_error('MissingName', array('name' => $name));
     $range = array('startRunId' => $start_run_id, 'endRunId' => $end_run_id);
     if (!$start_run_id || !$end_run_id)
         exit_with_error('MissingRange', $range);
 
-    $db = connect();
     $start_run = ensure_row_by_id($db, 'test_runs', 'run', $start_run_id, 'InvalidStartRun', $range);
     $end_run = ensure_row_by_id($db, 'test_runs', 'run', $end_run_id, 'InvalidEndRun', $range);
 
     $config = ensure_config_from_runs($db, $start_run, $end_run);
 
     $db->begin_transaction();
+
+    $segmentation_id = NULL;
+    if ($segmentation_name) {
+        $segmentation_id = $db->select_or_insert_row('analysis_strategies', 'strategy', array('name' => $segmentation_name));
+        if (!$segmentation_id) {
+            $db->rollback_transaction();
+            exit_with_error('CannotFindOrInsertSegmentationStrategy', array('segmentationStrategy' => $segmentation_name));
+        }
+    }
+
+    $test_range_id = NULL;
+    if ($test_range_name) {
+        $test_range_id = $db->select_or_insert_row('analysis_strategies', 'strategy', array('name' => $test_range_name));
+        if (!$test_range_id) {
+            $db->rollback_transaction();
+            exit_with_error('CannotFindOrInsertTestRangeStrategy', array('testRangeStrategy' => $test_range_name));
+        }
+    }
+
     $duplicate = $db->select_first_row('analysis_tasks', 'task', array('start_run' => $start_run_id, 'end_run' => $end_run_id));
     if ($duplicate) {
         $db->rollback_transaction();
@@ -35,7 +57,9 @@ function main() {
         'platform' => $config['config_platform'],
         'metric' => $config['config_metric'],
         'start_run' => $start_run_id,
-        'end_run' => $end_run_id));
+        'end_run' => $end_run_id,
+        'segmentation' => $segmentation_id,
+        'test_range' => $test_range_id));
     $db->commit_transaction();
 
     exit_with_success(array('taskId' => $task_id));