/** Add a new build */ function add_build($build, $clientscheduleid = 0) { require_once 'models/buildgroup.php'; if (!is_numeric($build->ProjectId) || !is_numeric($build->SiteId)) { return; } //add_log('subprojectname: '.$build->SubProjectName, 'add_build'); $buildid = $build->GetIdFromName($build->SubProjectName); if ($buildid > 0 && !$build->Append) { remove_build($buildid); } // Move this into a Build::SetAppend($append, $buildid) method: // if (!$build->Exists() && $build->Append && empty($build->Id)) { $build->Id = $buildid; } // Find the groupid $buildGroup = new BuildGroup(); $build->GroupId = $buildGroup->GetGroupIdFromRule($build); $build->Save(); // If the build is part of a subproject we link the update file if (isset($build->SubProjectName) && $build->SubProjectName != '') { require_once 'models/buildupdate.php'; $BuildUpdate = new BuildUpdate(); $BuildUpdate->BuildId = $build->Id; $BuildUpdate->AssociateBuild($build->SiteId, $build->Name, $build->GetStamp()); } if ($clientscheduleid != 0) { require_once 'models/clientjobschedule.php'; $ClientJobSchedule = new ClientJobSchedule(); $ClientJobSchedule->Id = $clientscheduleid; $ClientJobSchedule->AssociateBuild($build->Id); } return $build->Id; }
require_once "cdash/pdo.php"; include_once 'cdash/common.php'; include "cdash/version.php"; include_once 'models/project.php'; include_once "models/clientjobschedule.php"; if (!$CDASH_MANAGE_CLIENTS) { echo "CDash has not been setup to allow client management"; return; } $userid = $_SESSION['cdash']['loginid']; if (!isset($_GET['scheduleid'])) { echo "Schedule id not set"; return; } $scheduleid = $_GET['scheduleid']; $ClientJobSchedule = new ClientJobSchedule(); $ClientJobSchedule->Id = $scheduleid; $projectid = $ClientJobSchedule->GetProjectId(); $xml = begin_XML_for_XSLT(); $xml .= add_XML_value("manageclient", $CDASH_MANAGE_CLIENTS); $db = pdo_connect("{$CDASH_DB_HOST}", "{$CDASH_DB_LOGIN}", "{$CDASH_DB_PASS}"); pdo_select_db("{$CDASH_DB_NAME}", $db); $xml .= add_XML_value("title", "CDash - Scheduled Build Submissions"); $xml .= add_XML_value("menutitle", "CDash"); $xml .= add_XML_value("menusubtitle", "Submitted Builds"); $xml .= "<hostname>" . $_SERVER['SERVER_NAME'] . "</hostname>"; $xml .= "<date>" . date("r") . "</date>"; $xml .= "<backurl>user.php</backurl>"; $builds = $ClientJobSchedule->GetAssociatedBuilds(); foreach ($builds as $buildid) { $xml .= '<build>';
function client_submit() { include 'config/config.php'; if (!$CDASH_MANAGE_CLIENTS) { return 0; } include_once 'models/clientsite.php'; include_once 'models/clientos.php'; include_once 'models/clientjob.php'; include_once 'models/clientjobschedule.php'; include_once 'models/clientcmake.php'; include_once 'models/clientcompiler.php'; include_once 'models/clientlibrary.php'; include 'config/config.php'; require_once 'include/common.php'; // Client asks for the site id if (isset($_GET['getsiteid'])) { if (!isset($_GET['sitename']) || !isset($_GET['systemname'])) { echo 'ERROR: sitename or systemname not set'; return 0; } $sitename = htmlspecialchars(pdo_real_escape_string($_GET['sitename'])); $systemname = htmlspecialchars(pdo_real_escape_string($_GET['systemname'])); // Should get the site id $ClientSite = new ClientSite(); $siteid = $ClientSite->GetId($sitename, $systemname); echo $siteid; return 1; } elseif (isset($_GET['getjob'])) { if (!isset($_GET['siteid'])) { echo '0'; return 1; } if (!$_GET['siteid']) { echo '0'; return 1; } $ClientJobSchedule = new ClientJobSchedule(); $ClientJobSchedule->SiteId = pdo_real_escape_numeric($_GET['siteid']); $jobid = $ClientJobSchedule->HasJob(); if ($jobid > 0) { // if we have something to do echo $ClientJobSchedule->GetCTestScript(); } else { echo '0'; // send zero to let the client know that nothing is there } return 1; } elseif (isset($_GET['submitinfo'])) { if (!isset($_GET['sitename']) || !isset($_GET['systemname'])) { echo '0'; return 1; } $filehandle = 'php://input'; $contents = file_get_contents($filehandle); $xml = new SimpleXMLElement($contents); // Add/Update the OS $ClientOS = new ClientOS(); $ClientOS->Name = $ClientOS->GetPlatformFromName($xml->system->platform); $ClientOS->Version = $ClientOS->GetVersionFromName($xml->system->version); $ClientOS->Bits = $xml->system->bits; $ClientOS->Save(); // Add/Update the site $ClientSite = new ClientSite(); $ClientSite->Name = htmlspecialchars(pdo_real_escape_string($_GET['sitename'])); $ClientSite->SystemName = htmlspecialchars(pdo_real_escape_string($_GET['systemname'])); $ClientSite->Host = 'none'; $ClientSite->OsId = $ClientOS->Id; $ClientSite->BaseDirectory = $xml->system->basedirectory; $ClientSite->Save(); $siteid = $ClientSite->Id; // Add/Update the compiler(s) $compilers = array(); foreach ($xml->compiler as $compiler) { $ClientCompiler = new ClientCompiler(); $ClientCompiler->Name = $compiler->name; $ClientCompiler->Version = $compiler->version; $ClientCompiler->Command = $compiler->command; $ClientCompiler->Generator = $compiler->generator; $ClientCompiler->SiteId = $siteid; $ClientCompiler->Save(); $comp = array(); $comp['name'] = $compiler->name; $comp['version'] = $compiler->version; $comp['command'] = $compiler->command; $comp['generator'] = $compiler->generator; $compilers[] = $comp; } $ClientCompiler = new ClientCompiler(); $ClientCompiler->SiteId = $siteid; $ClientCompiler->DeleteUnused($compilers); // Add/Update CMake(s) $cmakes = array(); foreach ($xml->cmake as $cmake) { $ClientCMake = new ClientCMake(); $ClientCMake->Version = $cmake->version; $ClientCMake->Path = $cmake->path; $ClientCMake->SiteId = $siteid; $ClientCMake->Save(); $cm = array(); $cm['path'] = $cmake->path; $cm['version'] = $cmake->version; $cmakes[] = $cm; } $ClientCMake = new ClientCMake(); $ClientCMake->SiteId = $siteid; $ClientCMake->DeleteUnused($cmakes); // Add/Update Libraries $libraries = array(); foreach ($xml->library as $library) { $ClientLibrary = new ClientLibrary(); $ClientLibrary->Name = $library->name; $ClientLibrary->Path = $library->path; $ClientLibrary->Include = $library->include; $ClientLibrary->Version = $library->version; $ClientLibrary->SiteId = $siteid; $ClientLibrary->Save(); $lib = array(); $lib['name'] = $library->name; $lib['path'] = $library->path; $lib['version'] = $library->version; $lib['include'] = $library->include; $libraries[] = $lib; } $ClientLibrary = new ClientLibrary(); $ClientLibrary->SiteId = $siteid; $ClientLibrary->DeleteUnused($libraries); // Add/Update Programs $programs = array(); foreach ($xml->program as $program) { $prog = array(); $prog['name'] = $program->name; $prog['path'] = $program->path; $prog['version'] = $program->version; $programs[] = $prog; } $ClientSite->UpdatePrograms($programs); // Add/Update the list of allowed projects $allowedProjects = array(); foreach ($xml->allowedproject as $allowedProject) { $allowedProjects[] = $allowedProject; } $ClientSite->UpdateAllowedProjects($allowedProjects); return 1; } elseif (isset($_GET['jobdone'])) { // Mark the job has finished if (!isset($_GET['siteid'])) { echo '0'; return 1; } if (!$_GET['siteid']) { echo '0'; return 1; } $ClientJob = new ClientJob(); $ClientJob->SiteId = pdo_real_escape_numeric($_GET['siteid']); $ClientJob->SetFinished(); return 1; } elseif (isset($_GET['jobfailed'])) { // Mark the job has failed if (!isset($_GET['siteid'])) { echo '0'; return 1; } if (!$_GET['siteid']) { echo '0'; return 1; } $ClientJob = new ClientJob(); $ClientJob->SiteId = pdo_real_escape_numeric($_GET['siteid']); $ClientJob->SetFailed(); return 1; } return 0; }
$xml .= add_XML_value("name", $projectname); $xml .= add_XML_value("name_encoded", urlencode($projectname)); $xml .= add_XML_value("nbuilds", $Project->GetTotalNumberOfBuilds()); $xml .= add_XML_value("nerrorlogs", $project2user_array["errors"]); $xml .= add_XML_value("average_builds", round($Project->GetBuildsDailyAverage(gmdate(FMT_DATETIME, time() - 3600 * 24 * 7), gmdate(FMT_DATETIME), 2))); $xml .= add_XML_value("success", $Project->GetNumberOfPassingBuilds($start, gmdate(FMT_DATETIME))); $xml .= add_XML_value("error", $Project->GetNumberOfErrorBuilds($start, gmdate(FMT_DATETIME))); $xml .= add_XML_value("warning", $Project->GetNumberOfWarningBuilds($start, gmdate(FMT_DATETIME))); $xml .= "</project>"; } // Go through the jobs if ($CDASH_MANAGE_CLIENTS) { $ClientJobSchedule = new ClientJobSchedule(); $userJobSchedules = $ClientJobSchedule->getAll($userid, 1000); foreach ($userJobSchedules as $scheduleid) { $ClientJobSchedule = new ClientJobSchedule(); $ClientJobSchedule->Id = $scheduleid; $projectid = $ClientJobSchedule->GetProjectId(); $Project = new Project(); $Project->Id = $projectid; $status = "Scheduled"; $lastrun = "NA"; $lastjobid = $ClientJobSchedule->GetLastJobId(); if ($lastjobid) { $ClientJob = new ClientJob(); $ClientJob->Id = $lastjobid; switch ($ClientJob->GetStatus()) { case CDASH_JOB_RUNNING: $status = "Running"; $ClientSite = new ClientSite(); $ClientSite->Id = $ClientJob->GetSite();
/** Return the status of a scheduled build */ private function ScheduleStatus() { include "cdash/config.php"; include_once 'cdash/common.php'; include_once "models/clientjobschedule.php"; include_once "models/clientos.php"; include_once "models/clientcmake.php"; include_once "models/clientcompiler.php"; include_once "models/clientlibrary.php"; $status = array(); $status['scheduled'] = 0; if (!isset($this->Parameters['project'])) { echo "Project name should be set"; return; } $projectid = get_project_id($this->Parameters['project']); if (!is_numeric($projectid) || $projectid <= 0) { echo "Project not found"; return; } $scheduleid = $this->Parameters['scheduleid']; if (!is_numeric($scheduleid) || $scheduleid <= 0) { echo "ScheduleId not set"; return; } $clientJobSchedule = new ClientJobSchedule(); $clientJobSchedule->Id = $scheduleid; $clientJobSchedule->ProjectId = $projectid; $status['status'] = $clientJobSchedule->GetStatus(); switch ($status['status']) { case -1: $status['statusstring'] = "not found"; break; case 0: $status['statusstring'] = "scheduled"; break; case 2: $status['statusstring'] = "running"; break; case 3: $status['statusstring'] = "finished"; break; case 4: $status['statusstring'] = "aborted"; break; case 5: $status['statusstring'] = "failed"; break; } $status['scheduleid'] = $clientJobSchedule->Id; $status['builds'] = $clientJobSchedule->GetAssociatedBuilds(); $status['scheduled'] = 0; if ($status['status'] > 0) { $status['scheduled'] = 1; } return $status; }
$Library = new ClientLibrary(); $libraryids = $Library->getAll(); foreach ($libraryids as $libraryid) { $xml .= '<library>'; $Library->Id = $libraryid; $xml .= add_XML_value('name', $Library->GetName() . '-' . $Library->GetVersion()); $xml .= add_XML_value('id', $libraryid); if (isset($libraries) && array_search($libraryid, $libraries) !== false) { $xml .= add_XML_value('selected', '1'); } $xml .= '</library>'; } $xml .= '</cdash>'; // Schedule the build if (!empty($_POST['submit']) || !empty($_POST['update'])) { $clientJobSchedule = new ClientJobSchedule(); $clientJobSchedule->UserId = $userid; $clientJobSchedule->ProjectId = $Project->Id; $clientJobSchedule->BuildNameSuffix = htmlspecialchars(pdo_real_escape_string($_POST['buildnamesuffix'])); $clientJobSchedule->BuildConfiguration = htmlspecialchars(pdo_real_escape_string($_POST['buildconfiguration'])); $clientJobSchedule->Tag = htmlspecialchars(pdo_real_escape_string($_POST['tag'])); $clientJobSchedule->Enable = 1; if (strlen($_POST['module']) > 0) { $clientJobSchedule->Module = htmlspecialchars(pdo_real_escape_string($_POST['module'])); } if (strlen($_POST['otherrepository']) > 0) { $clientJobSchedule->Repository = htmlspecialchars(pdo_real_escape_string($_POST['otherrepository'])); } else { $clientJobSchedule->Repository = htmlspecialchars(pdo_real_escape_string($_POST['repository'])); } if (!isset($_POST['enable'])) {
/** Remove the first builds that are at the beginning of the queue */ function removeFirstBuilds($projectid, $days, $maxbuilds, $force = false) { require 'config/config.php'; require_once 'include/pdo.php'; require_once 'include/common.php'; @set_time_limit(0); if (!$force && !isset($CDASH_AUTOREMOVE_BUILDS)) { return; } if (!$force && $CDASH_AUTOREMOVE_BUILDS != '1') { return; } if ($days < 2) { return; } // First remove the builds with the wrong date $currentdate = time() - 3600 * 24 * $days; $startdate = date(FMT_DATETIME, $currentdate); add_log('about to query for builds to remove', 'removeFirstBuilds'); $builds = pdo_query("SELECT id FROM build\n WHERE parentid IN (0, -1) AND\n starttime<'{$startdate}' AND\n projectid=" . qnum($projectid) . "\n ORDER BY starttime ASC LIMIT {$maxbuilds}"); add_last_sql_error('dailyupdates::removeFirstBuilds'); $buildids = array(); while ($builds_array = pdo_fetch_array($builds)) { $buildids[] = $builds_array['id']; } $s = 'removing old buildids for projectid: ' . $projectid; add_log($s, 'removeFirstBuilds'); echo ' -- ' . $s . "\n"; // for "interactive" command line feedback remove_build($buildids); // Remove any job schedules that are older than our cutoff date // and not due to repeat again. require_once 'models/constants.php'; require_once 'models/clientjobschedule.php'; $sql = 'SELECT scheduleid FROM client_job AS cj LEFT JOIN client_jobschedule AS cjs ON cj.scheduleid = cjs.id WHERE cj.status > ' . CDASH_JOB_RUNNING . "\n AND cjs.projectid={$projectid} AND cj.startdate < '{$startdate}'\n AND (cjs.repeattime = 0.00 OR\n (cjs.enddate < '{$startdate}' AND cjs.enddate != '1980-01-01 00:00:00'))"; $job_schedules = pdo_query($sql); while ($job_schedule = pdo_fetch_array($job_schedules)) { $ClientJobSchedule = new ClientJobSchedule(); $ClientJobSchedule->Id = $job_schedule['scheduleid']; $ClientJobSchedule->Remove(); } // Remove any jobs that are older than our cutoff date. // This occurs when a job schedule is set to continue repeating, but // some of its past runs are older than our autoremove threshold. require_once 'models/clientjob.php'; $sql = 'SELECT cj.id FROM client_job AS cj LEFT JOIN client_jobschedule AS cjs ON cj.scheduleid = cjs.id WHERE cj.status > ' . CDASH_JOB_RUNNING . "\n AND cjs.projectid={$projectid} AND cj.startdate < '{$startdate}'"; $jobs = pdo_query($sql); while ($job = pdo_fetch_array($jobs)) { $ClientJob = new ClientJob(); $ClientJob->Id = $job['id']; $ClientJob->Remove(); } }