Joli\JoliCi\Vacuum::getJobsToRemove PHP Method

getJobsToRemove() public method

Get all jobs to remove given a project and how many versions to keep
public getJobsToRemove ( string $projectPath, integer $keep = 1 ) : Joli\JoliCi\Job[]
$projectPath string The project path
$keep integer Number of project to keep
return Joli\JoliCi\Job[] A list of jobs to remove
    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;
    }