public function getJobsToRemove($projectPath, $keep = 1)
{
$currentJobs = $this->strategy->getJobs($projectPath);
$existingJobs = $this->getJobs($projectPath);
$uniqList = array();
$removes = array();
$ordered = array();
foreach ($currentJobs as $job) {
$uniqList[] = $job->getUniq();
}
// Remove not existant image (old build configuration)
foreach ($existingJobs as $job) {
if (!in_array($job->getUniq(), $uniqList)) {
$removes[] = $job;
} else {
$ordered[$job->getUniq()][$job->getCreated()->format('U')] = $job;
}
}
// Remove old image
foreach ($ordered as $jobs) {
ksort($jobs);
$keeped = count($jobs);
while ($keeped > $keep) {
$removes[] = array_shift($jobs);
$keeped--;
}
}
return $removes;
}