lib/base/BaseDeploy.class.php
protected function collectPastDeployments($remote_host, $remote_dir)
	{
		$this->log('collectPastDeployments', LOG_DEBUG);

		$dirs = array();
		$return = null;
		$this->sshExec($remote_host, "ls -1 $remote_dir", $dirs, $return);

		if ($return !== 0) {
			throw new DeployException('ssh initialize failed');
		}

		if (!count($dirs))
            return null;

        $deployment_dirs = array();

        foreach ($dirs as $dirname)
        {
            if (preg_match('/'. preg_quote($this->project_name) .'_\d{4}-\d{2}-\d{2}_\d{6}/', $dirname))
            {
                $deployment_dirs[] = $dirname;
            }
        }

        // the two latest deployments always stay
        if (count($deployment_dirs) <= 2)
            return null;

        $dirs_to_delete = array();

        sort($deployment_dirs);

        $deployment_dirs = array_slice($deployment_dirs, 0, -2);

        foreach ($deployment_dirs as $key => $dirname)
        {
            $time = strtotime(str_replace(array($this->project_name .'_', '_'), array('', ' '), $dirname));

            // deployments older than a month can go
            if ($time < strtotime('-1 month')) {
                $this->log("$dirname is older than a month");

                $dirs_to_delete[] = $dirname;
            }
            // of deployments older than a week only the last one of the day stays
            elseif ($time < strtotime('-1 week'))
            {
                if (isset($deployment_dirs[$key+1]))
                {
                    $time_next = strtotime(str_replace(array($this->project_name .'_', '_'), array('', ' '), $deployment_dirs[$key+1]));

                    // if the next deployment was on the same day this one can go
                    if (date('j', $time_next) == date('j', $time))
                    {
                        $this->log("$dirname was replaced the same day");

                        $dirs_to_delete[] = $dirname;
                    }
                    else
                    {
                        $this->log("$dirname stays");
                    }
                }
            }
            else
            {
                $this->log("$dirname stays");
            }
        }

        return $dirs_to_delete;
	}
protected function collectPastDeployments($remote_host, $remote_dir)
	{
		$this->log('collectPastDeployments', LOG_DEBUG);

		$dirs = array();
		$return = null;
		$this->sshExec($remote_host, "ls -1 $remote_dir", $dirs, $return);

		if ($return !== 0) {
			throw new DeployException('ssh initialize failed');
		}

		if (!count($dirs))
            return null;

        $deployment_dirs = array();

        foreach ($dirs as $dirname)
        {
            if (preg_match('/'. preg_quote($this->project_name) .'_\d{4}-\d{2}-\d{2}_\d{6}/', $dirname))
            {
                $deployment_dirs[] = $dirname;
            }
        }

        // the two latest deployments always stay
        if (count($deployment_dirs) <= 2)
            return null;

        $dirs_to_delete = array();

        sort($deployment_dirs);

        $deployment_dirs = array_slice($deployment_dirs, 0, -2);

        foreach ($deployment_dirs as $key => $dirname)
        {
            $time = strtotime(str_replace(array($this->project_name .'_', '_'), array('', ' '), $dirname));

            // deployments older than a month can go
            if ($time < strtotime('-1 month')) {
                $this->log("$dirname is older than a month");

                $dirs_to_delete[] = $dirname;
            }
            // of deployments older than a week only the last one of the day stays
            elseif ($time < strtotime('-1 week'))
            {
                if (isset($deployment_dirs[$key+1]))
                {
                    $time_next = strtotime(str_replace(array($this->project_name .'_', '_'), array('', ' '), $deployment_dirs[$key+1]));

                    // if the next deployment was on the same day this one can go
                    if (date('j', $time_next) == date('j', $time))
                    {
                        $this->log("$dirname was replaced the same day");

                        $dirs_to_delete[] = $dirname;
                    }
                    else
                    {
                        $this->log("$dirname stays");
                    }
                }
            }
            else
            {
                $this->log("$dirname stays");
            }
        }

        return $dirs_to_delete;
	}
protected function collectPastDeployments ( $ remote_host , $ remote_dir ) { $ this -> log ( 'collectPastDeployments' , LOG_DEBUG ) ; $ dirs = array ( ) ; $ return = null ; $ this -> sshExec ( $ remote_host , "ls -1 $remote_dir" , $ dirs , $ return ) ; if ( $ return !== 0 ) { throw new DeployException ( 'ssh initialize failed' ) ; } if ( ! count ( $ dirs ) ) return null ; $ deployment_dirs = array ( ) ; foreach ( $ dirs as $ dirname ) { if ( preg_match ( '/' . preg_quote ( $ this -> project_name ) . '_\d{4}-\d{2}-\d{2}_\d{6}/' , $ dirname ) ) { $ deployment_dirs [ ] = $ dirname ; } } // the two latest deployments always stay if ( count ( $ deployment_dirs ) <= 2 ) return null ; $ dirs_to_delete = array ( ) ; sort ( $ deployment_dirs ) ; $ deployment_dirs = array_slice ( $ deployment_dirs , 0 , - 2 ) ; foreach ( $ deployment_dirs as $ key => $ dirname ) { $ time = strtotime ( str_replace ( array ( $ this -> project_name . '_' , '_' ) , array ( '' , ' ' ) , $ dirname ) ) ; // deployments older than a month can go if ( $ time < strtotime ( '-1 month' ) ) { $ this -> log ( "$dirname is older than a month" ) ; $ dirs_to_delete [ ] = $ dirname ; } // of deployments older than a week only the last one of the day stays elseif ( $ time < strtotime ( '-1 week' ) ) { if ( isset ( $ deployment_dirs [ $ key + 1 ] ) ) { $ time_next = strtotime ( str_replace ( array ( $ this -> project_name . '_' , '_' ) , array ( '' , ' ' ) , $ deployment_dirs [ $ key + 1 ] ) ) ; // if the next deployment was on the same day this one can go if ( date ( 'j' , $ time_next ) == date ( 'j' , $ time ) ) { $ this -> log ( "$dirname was replaced the same day" ) ; $ dirs_to_delete [ ] = $ dirname ; } else { $ this -> log ( "$dirname stays" ) ; } } } else { $ this -> log ( "$dirname stays" ) ; } } return $ dirs_to_delete ; }
Returns all obsolete deployments that can be deleted.

@param string $remote_host
@param string $remote_dir
@throws DeployException
@return array
Returns all obsolete deployments that can be deleted .