Exemplo n.º 1
0
function main($post_data)
{
    set_exit_detail('failureStored', false);
    $db = new Database();
    if (!$db->connect()) {
        exit_with_error('DatabaseConnectionFailure');
    }
    // Convert all floating points to strings to avoid parsing them in PHP.
    // FIXME: Do this conversion in the submission scripts themselves.
    $parsed_json = json_decode(preg_replace('/(?<=[\\s,\\[])(\\d+(\\.\\d+)?)(\\s*[,\\]])/', '"$1"$3', $post_data), true);
    if (!$parsed_json) {
        exit_with_error('FailedToParseJSON');
    }
    set_exit_detail('processedRuns', 0);
    foreach ($parsed_json as $i => $report) {
        $processor = new ReportProcessor($db);
        $processor->process($report);
        set_exit_detail('processedRuns', $i + 1);
    }
    $generator = new ManifestGenerator($db);
    if (!$generator->generate()) {
        exit_with_error('FailedToGenerateManifest');
    } else {
        if (!$generator->store()) {
            exit_with_error('FailedToStoreManifest');
        }
    }
    exit_with_success();
}
Exemplo n.º 2
0
function regenerate_manifest()
{
    global $db;
    $generator = new ManifestGenerator($db);
    if (!$generator->generate()) {
        notice("Failed to generate the manifest (before trying to write into the filesystem).");
        return FALSE;
    }
    if (!$generator->store()) {
        notice("Failed to save the generated manifest into the filesystem");
        return FALSE;
    }
    return TRUE;
}
Exemplo n.º 3
0
function main()
{
    $db = new Database();
    if (!$db->connect()) {
        exit_with_error('DatabaseConnectionFailure');
    }
    $generator = new ManifestGenerator($db);
    if (!$generator->generate()) {
        exit_with_error('FailedToGenerateManifest');
    }
    if (!$generator->store()) {
        exit_with_error('FailedToStoreManifest');
    }
    exit_with_success($generator->manifest());
}
Exemplo n.º 4
0
function main($post_data)
{
    set_exit_detail('failureStored', false);
    $maintenance_mode = config('maintenanceMode');
    if ($maintenance_mode && !config('maintenanceDirectory')) {
        exit_with_error('MaintenanceDirectoryNotSet');
    }
    $db = new Database();
    if (!$maintenance_mode && !$db->connect()) {
        exit_with_error('DatabaseConnectionFailure');
    }
    // Convert all floating points to strings to avoid parsing them in PHP.
    // FIXME: Do this conversion in the submission scripts themselves.
    $parsed_json = json_decode(preg_replace('/(?<=[\\s,\\[])(\\d+(\\.\\d+)?)(\\s*[,\\]])/', '"$1"$3', $post_data), true);
    if (!$parsed_json) {
        exit_with_error('FailedToParseJSON');
    }
    set_exit_detail('processedRuns', 0);
    foreach ($parsed_json as $i => $report) {
        if (!$maintenance_mode) {
            $processor = new ReportProcessor($db);
            $processor->process($report);
        }
        set_exit_detail('processedRuns', $i + 1);
    }
    if ($maintenance_mode) {
        $files = scandir(config_path('maintenanceDirectory', ''));
        $i = 0;
        $filename = '';
        do {
            $i++;
            $filename = "{$i}.json";
        } while (in_array($filename, $files));
        file_put_contents(config_path('maintenanceDirectory', $filename), $post_data, LOCK_EX);
    } else {
        $generator = new ManifestGenerator($db);
        if (!$generator->generate()) {
            exit_with_error('FailedToGenerateManifest');
        } else {
            if (!$generator->store()) {
                exit_with_error('FailedToStoreManifest');
            }
        }
    }
    exit_with_success();
}
Exemplo n.º 5
0
require_once '../include/json-header.php';
require_once '../include/manifest.php';
require_once '../include/report-processor.php';
$db = new Database();
if (!$db->connect()) {
    exit_with_error('DatabaseConnectionFailure');
}
$report_id = array_get($_POST, 'report');
if (!$report_id) {
    $report_id = array_get($_GET, 'report');
}
$report_id = intval($report_id);
if (!$report_id) {
    exit_with_error('ReportIdNotSpecified');
}
$report_row = $db->select_first_row('reports', 'report', array('id' => $report_id));
if (!$report_row) {
    return exit_with_error('ReportNotFound', array('reportId', $report_id));
}
$processor = new ReportProcessor($db);
$processor->process(json_decode($report_row['report_content'], true), $report_id);
$generator = new ManifestGenerator($db);
if (!$generator->generate()) {
    exit_with_error('FailedToGenerateManifest');
} else {
    if (!$generator->store()) {
        exit_with_error('FailedToStoreManifest');
    }
}
exit_with_success();