function main($id, $path, $post_data) { if (!$id && (count($path) < 1 || count($path) > 2)) { exit_with_error('InvalidRequest'); } $db = new Database(); if (!$db->connect()) { exit_with_error('DatabaseConnectionFailure'); } $report = $post_data ? json_decode($post_data, true) : array(); $updates = array_get($report, 'buildRequestUpdates'); if ($updates) { verify_slave($db, $report); update_builds($db, $updates); } $requests_fetcher = new BuildRequestsFetcher($db); if ($id) { $requests_fetcher->fetch_request($id); } else { $triggerable_query = array('name' => array_get($path, 0)); $triggerable = $db->select_first_row('build_triggerables', 'triggerable', $triggerable_query); if (!$triggerable) { exit_with_error('TriggerableNotFound', $triggerable_query); } $requests_fetcher->fetch_incomplete_requests_for_triggerable($triggerable['triggerable_id']); } exit_with_success(array('buildRequests' => $requests_fetcher->results_with_resolved_ids(), 'rootSets' => $requests_fetcher->root_sets(), 'roots' => $requests_fetcher->roots(), 'updates' => $updates)); }