/** Function to deal with the external tool mechanism */ function post_submit() { include "models/buildfile.php"; // We expect POST to contain the following values. $vars = array('project', 'build', 'stamp', 'site', 'track', 'type', 'starttime', 'endtime', 'datafilesmd5'); foreach ($vars as $var) { if (!isset($_POST[$var]) || empty($_POST[$var])) { $response_array['status'] = 1; $response_array['description'] = 'Variable \'' . $var . '\' not set but required.'; echo json_encode($response_array); return; } } $projectname = htmlspecialchars(pdo_real_escape_string($_POST['project'])); $buildname = htmlspecialchars(pdo_real_escape_string($_POST['build'])); $buildstamp = htmlspecialchars(pdo_real_escape_string($_POST['stamp'])); $sitename = htmlspecialchars(pdo_real_escape_string($_POST['site'])); $track = htmlspecialchars(pdo_real_escape_string($_POST['track'])); $type = htmlspecialchars(pdo_real_escape_string($_POST['type'])); $starttime = htmlspecialchars(pdo_real_escape_string($_POST['starttime'])); $endtime = htmlspecialchars(pdo_real_escape_string($_POST['endtime'])); // Check if we have the CDash@Home scheduleid $scheduleid = 0; if (isset($_POST["clientscheduleid"])) { $scheduleid = pdo_real_escape_numeric($_POST["clientscheduleid"]); } // Add the build $build = new Build(); $build->ProjectId = get_project_id($projectname); $build->StartTime = gmdate(FMT_DATETIME, $starttime); $build->EndTime = gmdate(FMT_DATETIME, $endtime); $build->SubmitTime = gmdate(FMT_DATETIME); $build->Name = $buildname; $build->InsertErrors = false; // we have no idea if we have errors at this point $build->SetStamp($buildstamp); // Get the site id $site = new Site(); $site->Name = $sitename; $site->Insert(); $build->SiteId = $site->Id; // Make this an "append" build, so that it doesn't result in a separate row // from the rest of the "normal" submission. $build->Append = true; // TODO: Check the labels and generator and other optional if (isset($_POST["generator"])) { $build->Generator = htmlspecialchars(pdo_real_escape_string($_POST['generator'])); } $subprojectname = ""; if (isset($_POST["subproject"])) { $subprojectname = htmlspecialchars(pdo_real_escape_string($_POST['subproject'])); $build->SetSubProject($subprojectname); } // Check if this build already exists. $buildid = $build->GetIdFromName($subprojectname); // If not, add a new one. if ($buildid === 0) { $buildid = add_build($build, $scheduleid); } // Returns the OK submission $response_array['status'] = 0; $response_array['buildid'] = $buildid; $buildfile = new BuildFile(); // Check if the files exists foreach ($_POST['datafilesmd5'] as $md5) { $buildfile->md5 = $md5; $old_buildid = $buildfile->MD5Exists(); if (!$old_buildid) { $response_array['datafilesmd5'][] = 0; } else { $response_array['datafilesmd5'][] = 1; // Associate this build file with the new build if it has been previously // uploaded. require_once "copy_build_data.php"; copy_build_data($old_buildid, $buildid, $type); } } echo json_encode($response_array); }