if (!$CDASH_MANAGE_CLIENTS) { echo 'CDash has not been setup to allow client management'; return; } $userid = $_SESSION['cdash']['loginid']; $User = new User(); $User->Id = $userid; /* If we should remove a job */ if (isset($_GET['removeschedule'])) { $ClientJobSchedule = new ClientJobSchedule(); $ClientJobSchedule->Id = pdo_real_escape_numeric($_GET['removeschedule']); if (!$User->IsAdmin() && $ClientJobSchedule->GetOwner() != $userid) { echo 'You cannot access this job'; return; } $ClientJobSchedule->Remove(); echo "<script language=\"javascript\">window.location='user.php'</script>"; } if (!isset($_GET['projectid']) && !isset($_GET['scheduleid'])) { echo 'Projectid or Schedule id not set'; return; } if (isset($_GET['projectid'])) { $projectid = pdo_real_escape_numeric($_GET['projectid']); } else { $scheduleid = pdo_real_escape_numeric($_GET['scheduleid']); $ClientJobSchedule = new ClientJobSchedule(); $ClientJobSchedule->Id = $scheduleid; $projectid = $ClientJobSchedule->GetProjectId(); } if (!$User->IsAdmin()) {
/** 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(); } }