mirror of
				https://github.com/hauke68/Magallanes.git
				synced 2025-11-04 00:50:18 +01:00 
			
		
		
		
	PHPStorm refactoring.
This commit is contained in:
		
							parent
							
								
									4c584b2634
								
							
						
					
					
						commit
						fddeebe59a
					
				@ -17,21 +17,20 @@ namespace Mage;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class Autoload
 | 
					class Autoload
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Autoload a Class by it's Class Name
 | 
					     * Autoload a Class by it's Class Name
 | 
				
			||||||
	 * @param string $className
 | 
					     * @param string $className
 | 
				
			||||||
     * @return boolean
 | 
					     * @return boolean
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    public function autoLoad($className)
 | 
					    public function autoLoad($className)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $className = ltrim($className, '/');
 | 
					        $className = ltrim($className, '/');
 | 
				
			||||||
        $postfix             = '/' . str_replace(array('_', '\\'), '/', $className . '.php');
 | 
					        $postfix = '/' . str_replace(array('_', '\\'), '/', $className . '.php');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Try to load a normal Mage class (or Task). Think that Mage component is compiled to .phar
 | 
					        //Try to load a normal Mage class (or Task). Think that Mage component is compiled to .phar
 | 
				
			||||||
        $baseDir = dirname(dirname(__FILE__));
 | 
					        $baseDir = dirname(dirname(__FILE__));
 | 
				
			||||||
        $classFileWithinPhar = $baseDir . $postfix;
 | 
					        $classFileWithinPhar = $baseDir . $postfix;
 | 
				
			||||||
        if($this->isReadable($classFileWithinPhar))
 | 
					        if ($this->isReadable($classFileWithinPhar)) {
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            /** @noinspection PhpIncludeInspection */
 | 
					            /** @noinspection PhpIncludeInspection */
 | 
				
			||||||
            require_once $classFileWithinPhar;
 | 
					            require_once $classFileWithinPhar;
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
@ -39,7 +38,7 @@ class Autoload
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        //Try to load a custom Task or Class. Notice that the path is absolute to CWD
 | 
					        //Try to load a custom Task or Class. Notice that the path is absolute to CWD
 | 
				
			||||||
        $classFileOutsidePhar = getcwd() . '/.mage/tasks' . $postfix;
 | 
					        $classFileOutsidePhar = getcwd() . '/.mage/tasks' . $postfix;
 | 
				
			||||||
        if($this->isReadable($classFileOutsidePhar)){
 | 
					        if ($this->isReadable($classFileOutsidePhar)) {
 | 
				
			||||||
            /** @noinspection PhpIncludeInspection */
 | 
					            /** @noinspection PhpIncludeInspection */
 | 
				
			||||||
            require_once $classFileOutsidePhar;
 | 
					            require_once $classFileOutsidePhar;
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
 | 
				
			|||||||
@ -19,11 +19,11 @@ use Mage\Config;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
abstract class AbstractCommand
 | 
					abstract class AbstractCommand
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Instance of the loaded Configuration.
 | 
					     * Instance of the loaded Configuration.
 | 
				
			||||||
	 *
 | 
					     *
 | 
				
			||||||
	 * @var \Mage\Config
 | 
					     * @var \Mage\Config
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    protected $config = null;
 | 
					    protected $config = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 | 
				
			|||||||
@ -24,11 +24,11 @@ use Exception;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class AddCommand extends AbstractCommand
 | 
					class AddCommand extends AbstractCommand
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Adds new Configuration Elements
 | 
					     * Adds new Configuration Elements
 | 
				
			||||||
	 * @see \Mage\Command\AbstractCommand::run()
 | 
					     * @see \Mage\Command\AbstractCommand::run()
 | 
				
			||||||
	 * @throws Exception
 | 
					     * @throws Exception
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    public function run()
 | 
					    public function run()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $subCommand = $this->getConfig()->getArgument(1);
 | 
					        $subCommand = $this->getConfig()->getArgument(1);
 | 
				
			||||||
@ -71,24 +71,24 @@ class AddCommand extends AbstractCommand
 | 
				
			|||||||
        Console::output('Adding new environment: <dark_gray>' . $environmentName . '</dark_gray>');
 | 
					        Console::output('Adding new environment: <dark_gray>' . $environmentName . '</dark_gray>');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $releasesConfig = 'releases:' . PHP_EOL
 | 
					        $releasesConfig = 'releases:' . PHP_EOL
 | 
				
			||||||
                        . '  enabled: true' . PHP_EOL
 | 
					            . '  enabled: true' . PHP_EOL
 | 
				
			||||||
                        . '  max: 10' . PHP_EOL
 | 
					            . '  max: 10' . PHP_EOL
 | 
				
			||||||
                        . '  symlink: current' . PHP_EOL
 | 
					            . '  symlink: current' . PHP_EOL
 | 
				
			||||||
                        . '  directory: releases' . PHP_EOL;
 | 
					            . '  directory: releases' . PHP_EOL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $baseConfig = '#' . $environmentName . PHP_EOL
 | 
					        $baseConfig = '#' . $environmentName . PHP_EOL
 | 
				
			||||||
                    . 'deployment:' . PHP_EOL
 | 
					            . 'deployment:' . PHP_EOL
 | 
				
			||||||
                    . '  user: dummy' . PHP_EOL
 | 
					            . '  user: dummy' . PHP_EOL
 | 
				
			||||||
                    . '  from: ./' . PHP_EOL
 | 
					            . '  from: ./' . PHP_EOL
 | 
				
			||||||
                    . '  to: /var/www/vhosts/example.com/www' . PHP_EOL
 | 
					            . '  to: /var/www/vhosts/example.com/www' . PHP_EOL
 | 
				
			||||||
                    . '  excludes:' . PHP_EOL
 | 
					            . '  excludes:' . PHP_EOL
 | 
				
			||||||
                    . ($withReleases ? $releasesConfig : '')
 | 
					            . ($withReleases ? $releasesConfig : '')
 | 
				
			||||||
                    . 'hosts:' . PHP_EOL
 | 
					            . 'hosts:' . PHP_EOL
 | 
				
			||||||
                    . 'tasks:' . PHP_EOL
 | 
					            . 'tasks:' . PHP_EOL
 | 
				
			||||||
                    . '  pre-deploy:' . PHP_EOL
 | 
					            . '  pre-deploy:' . PHP_EOL
 | 
				
			||||||
                    . '  on-deploy:' . PHP_EOL
 | 
					            . '  on-deploy:' . PHP_EOL
 | 
				
			||||||
                    . ($withReleases ? ('  post-release:' . PHP_EOL) : '')
 | 
					            . ($withReleases ? ('  post-release:' . PHP_EOL) : '')
 | 
				
			||||||
                    . '  post-deploy:' . PHP_EOL;
 | 
					            . '  post-deploy:' . PHP_EOL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $result = file_put_contents($environmentConfigFile, $baseConfig);
 | 
					        $result = file_put_contents($environmentConfigFile, $baseConfig);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -24,12 +24,12 @@ class CompileCommand extends AbstractCommand
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * @see \Mage\Compile::compile()
 | 
					     * @see \Mage\Compile::compile()
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function run ()
 | 
					    public function run()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	if (ini_get('phar.readonly')) {
 | 
					        if (ini_get('phar.readonly')) {
 | 
				
			||||||
	    	Console::output('The <purple>php.ini</purple> variable <light_red>phar.readonly</light_red> must be <yellow>Off</yellow>.', 1, 2);
 | 
					            Console::output('The <purple>php.ini</purple> variable <light_red>phar.readonly</light_red> must be <yellow>Off</yellow>.', 1, 2);
 | 
				
			||||||
    		return;
 | 
					            return;
 | 
				
			||||||
    	}
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $compiler = new Compiler;
 | 
					        $compiler = new Compiler;
 | 
				
			||||||
        $compiler->compile();
 | 
					        $compiler->compile();
 | 
				
			||||||
 | 
				
			|||||||
@ -35,31 +35,31 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
 | 
				
			|||||||
    const DEPLOY_STRATEGY_RSYNC = 'rsync';
 | 
					    const DEPLOY_STRATEGY_RSYNC = 'rsync';
 | 
				
			||||||
    const DEPLOY_STRATEGY_TARGZ = 'targz';
 | 
					    const DEPLOY_STRATEGY_TARGZ = 'targz';
 | 
				
			||||||
    const DEPLOY_STRATEGY_GIT_REBASE = 'git-rebase';
 | 
					    const DEPLOY_STRATEGY_GIT_REBASE = 'git-rebase';
 | 
				
			||||||
    const DEPLOY_STRATEGY_GUESS   = 'guess';
 | 
					    const DEPLOY_STRATEGY_GUESS = 'guess';
 | 
				
			||||||
    const DEFAULT_DEPLOY_STRATEGY = self::DEPLOY_STRATEGY_GUESS;
 | 
					    const DEFAULT_DEPLOY_STRATEGY = self::DEPLOY_STRATEGY_GUESS;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
	 * Deploy has Failed
 | 
					     * Deploy has Failed
 | 
				
			||||||
	 * @var string
 | 
					     * @var string
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	const FAILED      = 'failed';
 | 
					    const FAILED = 'failed';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Deploy has Succeded
 | 
					     * Deploy has Succeded
 | 
				
			||||||
	 * @var string
 | 
					     * @var string
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	const SUCCEDED    = 'succeded';
 | 
					    const SUCCEDED = 'succeded';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Deploy is in progress
 | 
					     * Deploy is in progress
 | 
				
			||||||
	 * @var string
 | 
					     * @var string
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	const IN_PROGRESS = 'in_progress';
 | 
					    const IN_PROGRESS = 'in_progress';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Time the Deployment has Started
 | 
					     * Time the Deployment has Started
 | 
				
			||||||
	 * @var integer
 | 
					     * @var integer
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    protected $startTime = null;
 | 
					    protected $startTime = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -99,7 +99,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public static function getStatus()
 | 
					    public static function getStatus()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	return self::$deployStatus;
 | 
					        return self::$deployStatus;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -109,20 +109,20 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
 | 
				
			|||||||
    public function run()
 | 
					    public function run()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        // Check if Environment is not Locked
 | 
					        // Check if Environment is not Locked
 | 
				
			||||||
    	$lockFile = getcwd() . '/.mage/' . $this->getConfig()->getEnvironment() . '.lock';
 | 
					        $lockFile = getcwd() . '/.mage/' . $this->getConfig()->getEnvironment() . '.lock';
 | 
				
			||||||
    	if (file_exists($lockFile)) {
 | 
					        if (file_exists($lockFile)) {
 | 
				
			||||||
    		Console::output('<red>This environment is locked!</red>', 1, 2);
 | 
					            Console::output('<red>This environment is locked!</red>', 1, 2);
 | 
				
			||||||
                echo file_get_contents($lockFile);
 | 
					            echo file_get_contents($lockFile);
 | 
				
			||||||
    		return;
 | 
					            return;
 | 
				
			||||||
    	}
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    	// Check for running instance and Lock
 | 
					        // Check for running instance and Lock
 | 
				
			||||||
    	if (file_exists(getcwd() . '/.mage/~working.lock')) {
 | 
					        if (file_exists(getcwd() . '/.mage/~working.lock')) {
 | 
				
			||||||
    		Console::output('<red>There is already an instance of Magallanes running!</red>', 1, 2);
 | 
					            Console::output('<red>There is already an instance of Magallanes running!</red>', 1, 2);
 | 
				
			||||||
    		return;
 | 
					            return;
 | 
				
			||||||
    	} else {
 | 
					        } else {
 | 
				
			||||||
    		touch(getcwd() . '/.mage/~working.lock');
 | 
					            touch(getcwd() . '/.mage/~working.lock');
 | 
				
			||||||
    	}
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Release ID
 | 
					        // Release ID
 | 
				
			||||||
        $this->getConfig()->setReleaseId(date('YmdHis'));
 | 
					        $this->getConfig()->setReleaseId(date('YmdHis'));
 | 
				
			||||||
@ -135,15 +135,15 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // Deploy Summary - Releases
 | 
					        // Deploy Summary - Releases
 | 
				
			||||||
        if ($this->getConfig()->release('enabled', false)) {
 | 
					        if ($this->getConfig()->release('enabled', false)) {
 | 
				
			||||||
        	Console::output('<dark_gray>Release ID:</dark_gray>  <purple>' . $this->getConfig()->getReleaseId() . '</purple>', 2, 1);
 | 
					            Console::output('<dark_gray>Release ID:</dark_gray>  <purple>' . $this->getConfig()->getReleaseId() . '</purple>', 2, 1);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Deploy Summary - SCM
 | 
					        // Deploy Summary - SCM
 | 
				
			||||||
        if ($this->getConfig()->deployment('scm', false)) {
 | 
					        if ($this->getConfig()->deployment('scm', false)) {
 | 
				
			||||||
        	$scmConfig = $this->getConfig()->deployment('scm');
 | 
					            $scmConfig = $this->getConfig()->deployment('scm');
 | 
				
			||||||
        	if (isset($scmConfig['branch'])) {
 | 
					            if (isset($scmConfig['branch'])) {
 | 
				
			||||||
        		Console::output('<dark_gray>SCM Branch:</dark_gray>  <purple>' . $scmConfig['branch'] . '</purple>', 2, 1);
 | 
					                Console::output('<dark_gray>SCM Branch:</dark_gray>  <purple>' . $scmConfig['branch'] . '</purple>', 2, 1);
 | 
				
			||||||
        	}
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Deploy Summary - Separator Line
 | 
					        // Deploy Summary - Separator Line
 | 
				
			||||||
@ -156,21 +156,21 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // Check Status
 | 
					        // Check Status
 | 
				
			||||||
        if (self::$failedTasks > 0) {
 | 
					        if (self::$failedTasks > 0) {
 | 
				
			||||||
        	self::$deployStatus = self::FAILED;
 | 
					            self::$deployStatus = self::FAILED;
 | 
				
			||||||
        	Console::output('A total of <dark_gray>' . self::$failedTasks . '</dark_gray> deployment tasks failed: <red>ABORTING</red>', 1, 2);
 | 
					            Console::output('A total of <dark_gray>' . self::$failedTasks . '</dark_gray> deployment tasks failed: <red>ABORTING</red>', 1, 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
        	// Run Deployment Tasks
 | 
					            // Run Deployment Tasks
 | 
				
			||||||
        	$this->runDeploymentTasks();
 | 
					            $this->runDeploymentTasks();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        	// Check Status
 | 
					            // Check Status
 | 
				
			||||||
        	if (self::$failedTasks > 0) {
 | 
					            if (self::$failedTasks > 0) {
 | 
				
			||||||
        		self::$deployStatus = self::FAILED;
 | 
					                self::$deployStatus = self::FAILED;
 | 
				
			||||||
        		Console::output('A total of <dark_gray>' . self::$failedTasks . '</dark_gray> deployment tasks failed: <red>ABORTING</red>', 1, 2);
 | 
					                Console::output('A total of <dark_gray>' . self::$failedTasks . '</dark_gray> deployment tasks failed: <red>ABORTING</red>', 1, 2);
 | 
				
			||||||
        	}
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        	// Run Post-Deployment Tasks
 | 
					            // Run Post-Deployment Tasks
 | 
				
			||||||
        	$this->runNonDeploymentTasks(AbstractTask::STAGE_POST_DEPLOY, $this->getConfig(), 'Post-Deployment');
 | 
					            $this->runNonDeploymentTasks(AbstractTask::STAGE_POST_DEPLOY, $this->getConfig(), 'Post-Deployment');
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Time Information Hosts
 | 
					        // Time Information Hosts
 | 
				
			||||||
@ -191,7 +191,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // Unlock
 | 
					        // Unlock
 | 
				
			||||||
        if (file_exists(getcwd() . '/.mage/~working.lock')) {
 | 
					        if (file_exists(getcwd() . '/.mage/~working.lock')) {
 | 
				
			||||||
        	unlink(getcwd() . '/.mage/~working.lock');
 | 
					            unlink(getcwd() . '/.mage/~working.lock');
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -209,33 +209,33 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        // PreDeployment Hook
 | 
					        // PreDeployment Hook
 | 
				
			||||||
        if ($stage == AbstractTask::STAGE_PRE_DEPLOY) {
 | 
					        if ($stage == AbstractTask::STAGE_PRE_DEPLOY) {
 | 
				
			||||||
        	// Look for Remote Source
 | 
					            // Look for Remote Source
 | 
				
			||||||
        	if (is_array($config->deployment('source', null))) {
 | 
					            if (is_array($config->deployment('source', null))) {
 | 
				
			||||||
        		array_unshift($tasksToRun, 'scm/clone');
 | 
					                array_unshift($tasksToRun, 'scm/clone');
 | 
				
			||||||
        	}
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        	// Change Branch
 | 
					            // Change Branch
 | 
				
			||||||
        	if ($config->deployment('scm', false)) {
 | 
					            if ($config->deployment('scm', false)) {
 | 
				
			||||||
        		array_unshift($tasksToRun, 'scm/change-branch');
 | 
					                array_unshift($tasksToRun, 'scm/change-branch');
 | 
				
			||||||
        	}
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // PostDeployment Hook
 | 
					        // PostDeployment Hook
 | 
				
			||||||
        if ($stage == AbstractTask::STAGE_POST_DEPLOY) {
 | 
					        if ($stage == AbstractTask::STAGE_POST_DEPLOY) {
 | 
				
			||||||
        	// If Deploy failed, clear post deploy tasks
 | 
					            // If Deploy failed, clear post deploy tasks
 | 
				
			||||||
        	if (self::$deployStatus == self::FAILED) {
 | 
					            if (self::$deployStatus == self::FAILED) {
 | 
				
			||||||
        		$tasksToRun = array();
 | 
					                $tasksToRun = array();
 | 
				
			||||||
        	}
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        	// Change Branch Back
 | 
					            // Change Branch Back
 | 
				
			||||||
        	if ($config->deployment('scm', false)) {
 | 
					            if ($config->deployment('scm', false)) {
 | 
				
			||||||
        		array_unshift($tasksToRun, 'scm/change-branch');
 | 
					                array_unshift($tasksToRun, 'scm/change-branch');
 | 
				
			||||||
        		$config->addParameter('_changeBranchRevert');
 | 
					                $config->addParameter('_changeBranchRevert');
 | 
				
			||||||
        	}
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        	// Remove Remote Source
 | 
					            // Remove Remote Source
 | 
				
			||||||
        	if (is_array($config->deployment('source', null))) {
 | 
					            if (is_array($config->deployment('source', null))) {
 | 
				
			||||||
        		 array_push($tasksToRun, 'scm/remove-clone');
 | 
					                array_push($tasksToRun, 'scm/remove-clone');
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -255,7 +255,7 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
 | 
				
			|||||||
                if ($this->runTask($task)) {
 | 
					                if ($this->runTask($task)) {
 | 
				
			||||||
                    $completedTasks++;
 | 
					                    $completedTasks++;
 | 
				
			||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
                	self::$failedTasks++;
 | 
					                    self::$failedTasks++;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -271,151 +271,151 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    protected function runDeploymentTasks()
 | 
					    protected function runDeploymentTasks()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	if (self::$deployStatus == self::FAILED) {
 | 
					        if (self::$deployStatus == self::FAILED) {
 | 
				
			||||||
    		return;
 | 
					            return;
 | 
				
			||||||
    	}
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    	// Run Tasks for Deployment
 | 
					        // Run Tasks for Deployment
 | 
				
			||||||
    	$hosts = $this->getConfig()->getHosts();
 | 
					        $hosts = $this->getConfig()->getHosts();
 | 
				
			||||||
    	$this->hostsCount = count($hosts);
 | 
					        $this->hostsCount = count($hosts);
 | 
				
			||||||
    	self::$failedTasks = 0;
 | 
					        self::$failedTasks = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    	if ($this->hostsCount == 0) {
 | 
					        if ($this->hostsCount == 0) {
 | 
				
			||||||
    		Console::output('<light_purple>Warning!</light_purple> <dark_gray>No hosts defined, skipping deployment tasks.</dark_gray>', 1, 3);
 | 
					            Console::output('<light_purple>Warning!</light_purple> <dark_gray>No hosts defined, skipping deployment tasks.</dark_gray>', 1, 3);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    	} else {
 | 
					        } else {
 | 
				
			||||||
    		$this->startTimeHosts = time();
 | 
					            $this->startTimeHosts = time();
 | 
				
			||||||
    		foreach ($hosts as $hostKey => $host) {
 | 
					            foreach ($hosts as $hostKey => $host) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    			// Check if Host has specific configuration
 | 
					                // Check if Host has specific configuration
 | 
				
			||||||
    			$hostConfig = null;
 | 
					                $hostConfig = null;
 | 
				
			||||||
    			if (is_array($host)) {
 | 
					                if (is_array($host)) {
 | 
				
			||||||
    				$hostConfig = $host;
 | 
					                    $hostConfig = $host;
 | 
				
			||||||
    				$host = $hostKey;
 | 
					                    $host = $hostKey;
 | 
				
			||||||
    			}
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    			// Set Host and Host Specific Config
 | 
					                // Set Host and Host Specific Config
 | 
				
			||||||
    			$this->getConfig()->setHost($host);
 | 
					                $this->getConfig()->setHost($host);
 | 
				
			||||||
    			$this->getConfig()->setHostConfig($hostConfig);
 | 
					                $this->getConfig()->setHostConfig($hostConfig);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    			// Prepare Tasks
 | 
					                // Prepare Tasks
 | 
				
			||||||
    			$tasks = 0;
 | 
					                $tasks = 0;
 | 
				
			||||||
    			$completedTasks = 0;
 | 
					                $completedTasks = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    			Console::output('Deploying to <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray>');
 | 
					                Console::output('Deploying to <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray>');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    			$tasksToRun = $this->getConfig()->getTasks();
 | 
					                $tasksToRun = $this->getConfig()->getTasks();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                $deployStrategy = $this->chooseDeployStrategy();
 | 
					                $deployStrategy = $this->chooseDeployStrategy();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                array_unshift($tasksToRun, $deployStrategy);
 | 
					                array_unshift($tasksToRun, $deployStrategy);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    			if (count($tasksToRun) == 0) {
 | 
					                if (count($tasksToRun) == 0) {
 | 
				
			||||||
    				Console::output('<light_purple>Warning!</light_purple> <dark_gray>No </dark_gray><light_cyan>Deployment</light_cyan> <dark_gray>tasks defined.</dark_gray>', 2);
 | 
					                    Console::output('<light_purple>Warning!</light_purple> <dark_gray>No </dark_gray><light_cyan>Deployment</light_cyan> <dark_gray>tasks defined.</dark_gray>', 2);
 | 
				
			||||||
    				Console::output('Deployment to <dark_gray>' . $host . '</dark_gray> skipped!', 1, 3);
 | 
					                    Console::output('Deployment to <dark_gray>' . $host . '</dark_gray> skipped!', 1, 3);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    			} else {
 | 
					                } else {
 | 
				
			||||||
    				foreach ($tasksToRun as $taskData) {
 | 
					                    foreach ($tasksToRun as $taskData) {
 | 
				
			||||||
    					$tasks++;
 | 
					                        $tasks++;
 | 
				
			||||||
    					$task = Factory::get($taskData, $this->getConfig(), false, AbstractTask::STAGE_DEPLOY);
 | 
					                        $task = Factory::get($taskData, $this->getConfig(), false, AbstractTask::STAGE_DEPLOY);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    					if ($this->runTask($task)) {
 | 
					                        if ($this->runTask($task)) {
 | 
				
			||||||
    						$completedTasks++;
 | 
					                            $completedTasks++;
 | 
				
			||||||
    					} else {
 | 
					                        } else {
 | 
				
			||||||
    						self::$failedTasks++;
 | 
					                            self::$failedTasks++;
 | 
				
			||||||
    					}
 | 
					                        }
 | 
				
			||||||
    				}
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    				if ($completedTasks == $tasks) {
 | 
					                    if ($completedTasks == $tasks) {
 | 
				
			||||||
    					$tasksColor = 'green';
 | 
					                        $tasksColor = 'green';
 | 
				
			||||||
    				} else {
 | 
					                    } else {
 | 
				
			||||||
    					$tasksColor = 'red';
 | 
					                        $tasksColor = 'red';
 | 
				
			||||||
    				}
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    				Console::output('Deployment to <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray> completed: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
 | 
					                    Console::output('Deployment to <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray> completed: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
 | 
				
			||||||
    			}
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    			// Reset Host Config
 | 
					                // Reset Host Config
 | 
				
			||||||
    			$this->getConfig()->setHostConfig(null);
 | 
					                $this->getConfig()->setHostConfig(null);
 | 
				
			||||||
    		}
 | 
					            }
 | 
				
			||||||
    		$this->endTimeHosts = time();
 | 
					            $this->endTimeHosts = time();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    		if (self::$failedTasks > 0) {
 | 
					            if (self::$failedTasks > 0) {
 | 
				
			||||||
    			self::$deployStatus = self::FAILED;
 | 
					                self::$deployStatus = self::FAILED;
 | 
				
			||||||
    		} else {
 | 
					            } else {
 | 
				
			||||||
    			self::$deployStatus = self::SUCCEDED;
 | 
					                self::$deployStatus = self::SUCCEDED;
 | 
				
			||||||
    		}
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    		// Releasing
 | 
					            // Releasing
 | 
				
			||||||
    		if (self::$deployStatus == self::SUCCEDED && $this->getConfig()->release('enabled', false) == true) {
 | 
					            if (self::$deployStatus == self::SUCCEDED && $this->getConfig()->release('enabled', false) == true) {
 | 
				
			||||||
    			// Execute the Releases
 | 
					                // Execute the Releases
 | 
				
			||||||
    			Console::output('Starting the <dark_gray>Releasing</dark_gray>');
 | 
					                Console::output('Starting the <dark_gray>Releasing</dark_gray>');
 | 
				
			||||||
    			foreach ($hosts as $hostKey => $host) {
 | 
					                foreach ($hosts as $hostKey => $host) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    				// Check if Host has specific configuration
 | 
					                    // Check if Host has specific configuration
 | 
				
			||||||
    				$hostConfig = null;
 | 
					                    $hostConfig = null;
 | 
				
			||||||
    				if (is_array($host)) {
 | 
					                    if (is_array($host)) {
 | 
				
			||||||
    					$hostConfig = $host;
 | 
					                        $hostConfig = $host;
 | 
				
			||||||
    					$host = $hostKey;
 | 
					                        $host = $hostKey;
 | 
				
			||||||
    				}
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    				// Set Host
 | 
					                    // Set Host
 | 
				
			||||||
    				$this->getConfig()->setHost($host);
 | 
					                    $this->getConfig()->setHost($host);
 | 
				
			||||||
    				$this->getConfig()->setHostConfig($hostConfig);
 | 
					                    $this->getConfig()->setHostConfig($hostConfig);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    				$task = Factory::get($this->chooseReleaseStrategy(), $this->getConfig(), false, AbstractTask::STAGE_DEPLOY);
 | 
					                    $task = Factory::get($this->chooseReleaseStrategy(), $this->getConfig(), false, AbstractTask::STAGE_DEPLOY);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    				if ($this->runTask($task, 'Releasing on host <purple>' . $host . '</purple> ... ')) {
 | 
					                    if ($this->runTask($task, 'Releasing on host <purple>' . $host . '</purple> ... ')) {
 | 
				
			||||||
    					$completedTasks++;
 | 
					                        $completedTasks++;
 | 
				
			||||||
    				}
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    				// Reset Host Config
 | 
					                    // Reset Host Config
 | 
				
			||||||
    				$this->getConfig()->setHostConfig(null);
 | 
					                    $this->getConfig()->setHostConfig(null);
 | 
				
			||||||
    			}
 | 
					                }
 | 
				
			||||||
    			Console::output('Finished the <dark_gray>Releasing</dark_gray>', 1, 3);
 | 
					                Console::output('Finished the <dark_gray>Releasing</dark_gray>', 1, 3);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    			// Execute the Post-Release Tasks
 | 
					                // Execute the Post-Release Tasks
 | 
				
			||||||
    			foreach ($hosts as $hostKey => $host) {
 | 
					                foreach ($hosts as $hostKey => $host) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    				// Check if Host has specific configuration
 | 
					                    // Check if Host has specific configuration
 | 
				
			||||||
    				$hostConfig = null;
 | 
					                    $hostConfig = null;
 | 
				
			||||||
    				if (is_array($host)) {
 | 
					                    if (is_array($host)) {
 | 
				
			||||||
    					$hostConfig = $host;
 | 
					                        $hostConfig = $host;
 | 
				
			||||||
    					$host = $hostKey;
 | 
					                        $host = $hostKey;
 | 
				
			||||||
    				}
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    				// Set Host
 | 
					                    // Set Host
 | 
				
			||||||
    				$this->getConfig()->setHost($host);
 | 
					                    $this->getConfig()->setHost($host);
 | 
				
			||||||
    				$this->getConfig()->setHostConfig($hostConfig);
 | 
					                    $this->getConfig()->setHostConfig($hostConfig);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    				$tasksToRun = $this->getConfig()->getTasks(AbstractTask::STAGE_POST_RELEASE);
 | 
					                    $tasksToRun = $this->getConfig()->getTasks(AbstractTask::STAGE_POST_RELEASE);
 | 
				
			||||||
    				$tasks = count($tasksToRun);
 | 
					                    $tasks = count($tasksToRun);
 | 
				
			||||||
    				$completedTasks = 0;
 | 
					                    $completedTasks = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    				if (count($tasksToRun) > 0) {
 | 
					                    if (count($tasksToRun) > 0) {
 | 
				
			||||||
    					Console::output('Starting <dark_gray>Post-Release</dark_gray> tasks for <dark_gray>' . $host . '</dark_gray>:');
 | 
					                        Console::output('Starting <dark_gray>Post-Release</dark_gray> tasks for <dark_gray>' . $host . '</dark_gray>:');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    					foreach ($tasksToRun as $task) {
 | 
					                        foreach ($tasksToRun as $task) {
 | 
				
			||||||
    						$task = Factory::get($task, $this->getConfig(), false, AbstractTask::STAGE_POST_RELEASE);
 | 
					                            $task = Factory::get($task, $this->getConfig(), false, AbstractTask::STAGE_POST_RELEASE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    						if ($this->runTask($task)) {
 | 
					                            if ($this->runTask($task)) {
 | 
				
			||||||
    							$completedTasks++;
 | 
					                                $completedTasks++;
 | 
				
			||||||
    						}
 | 
					                            }
 | 
				
			||||||
    					}
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    					if ($completedTasks == $tasks) {
 | 
					                        if ($completedTasks == $tasks) {
 | 
				
			||||||
    						$tasksColor = 'green';
 | 
					                            $tasksColor = 'green';
 | 
				
			||||||
    					} else {
 | 
					                        } else {
 | 
				
			||||||
    						$tasksColor = 'red';
 | 
					                            $tasksColor = 'red';
 | 
				
			||||||
    					}
 | 
					                        }
 | 
				
			||||||
    					Console::output('Finished <dark_gray>Post-Release</dark_gray> tasks for <dark_gray>' . $host . '</dark_gray>: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
 | 
					                        Console::output('Finished <dark_gray>Post-Release</dark_gray> tasks for <dark_gray>' . $host . '</dark_gray>: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
 | 
				
			||||||
    				}
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    				// Reset Host Config
 | 
					                    // Reset Host Config
 | 
				
			||||||
    				$this->getConfig()->setHostConfig(null);
 | 
					                    $this->getConfig()->setHostConfig(null);
 | 
				
			||||||
    			}
 | 
					                }
 | 
				
			||||||
    		}
 | 
					            }
 | 
				
			||||||
    	}
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -452,8 +452,8 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
 | 
				
			|||||||
                    $result = false;
 | 
					                    $result = false;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            } catch (ErrorWithMessageException $e) {
 | 
					            } catch (ErrorWithMessageException $e) {
 | 
				
			||||||
            	Console::output('<red>FAIL</red> [Message: ' . $e->getMessage() . ']', 0);
 | 
					                Console::output('<red>FAIL</red> [Message: ' . $e->getMessage() . ']', 0);
 | 
				
			||||||
            	$result = false;
 | 
					                $result = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            } catch (SkipException $e) {
 | 
					            } catch (SkipException $e) {
 | 
				
			||||||
                Console::output('<yellow>SKIPPED</yellow>', 0);
 | 
					                Console::output('<yellow>SKIPPED</yellow>', 0);
 | 
				
			||||||
@ -506,21 +506,21 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    protected function sendNotification($result)
 | 
					    protected function sendNotification($result)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	$projectName = $this->getConfig()->general('name', false);
 | 
					        $projectName = $this->getConfig()->general('name', false);
 | 
				
			||||||
    	$projectEmail = $this->getConfig()->general('email', false);
 | 
					        $projectEmail = $this->getConfig()->general('email', false);
 | 
				
			||||||
    	$notificationsEnabled = $this->getConfig()->general('notifications', false);
 | 
					        $notificationsEnabled = $this->getConfig()->general('notifications', false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    	// We need notifications enabled, and a project name and email to send the notification
 | 
					        // We need notifications enabled, and a project name and email to send the notification
 | 
				
			||||||
        if (!$projectName || !$projectEmail || !$notificationsEnabled) {
 | 
					        if (!$projectName || !$projectEmail || !$notificationsEnabled) {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $mailer = new Mailer;
 | 
					        $mailer = new Mailer;
 | 
				
			||||||
        $mailer->setAddress($projectEmail)
 | 
					        $mailer->setAddress($projectEmail)
 | 
				
			||||||
               ->setProject($projectName)
 | 
					            ->setProject($projectName)
 | 
				
			||||||
               ->setLogFile(Console::getLogFile())
 | 
					            ->setLogFile(Console::getLogFile())
 | 
				
			||||||
               ->setEnvironment($this->getConfig()->getEnvironment())
 | 
					            ->setEnvironment($this->getConfig()->getEnvironment())
 | 
				
			||||||
               ->send($result);
 | 
					            ->send($result);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -532,30 +532,30 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        // Guess a Deploy Strategy
 | 
					        // Guess a Deploy Strategy
 | 
				
			||||||
        switch ($this->getConfig()->deployment('strategy', self::DEFAULT_DEPLOY_STRATEGY)) {
 | 
					        switch ($this->getConfig()->deployment('strategy', self::DEFAULT_DEPLOY_STRATEGY)) {
 | 
				
			||||||
        case self::DEPLOY_STRATEGY_DISABLED:
 | 
					            case self::DEPLOY_STRATEGY_DISABLED:
 | 
				
			||||||
            $deployStrategy = 'deployment/strategy/disabled';
 | 
					                $deployStrategy = 'deployment/strategy/disabled';
 | 
				
			||||||
            break;
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        case self::DEPLOY_STRATEGY_RSYNC:
 | 
					            case self::DEPLOY_STRATEGY_RSYNC:
 | 
				
			||||||
            $deployStrategy = 'deployment/strategy/rsync';
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        case self::DEPLOY_STRATEGY_TARGZ:
 | 
					 | 
				
			||||||
            $deployStrategy = 'deployment/strategy/tar-gz';
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        case self::DEPLOY_STRATEGY_GIT_REBASE:
 | 
					 | 
				
			||||||
            $deployStrategy = 'deployment/strategy/git-rebase';
 | 
					 | 
				
			||||||
            break;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        case self::DEPLOY_STRATEGY_GUESS:
 | 
					 | 
				
			||||||
        default:
 | 
					 | 
				
			||||||
            if ($this->getConfig()->release('enabled', false) == true) {
 | 
					 | 
				
			||||||
                $deployStrategy = 'deployment/strategy/tar-gz';
 | 
					 | 
				
			||||||
            } else {
 | 
					 | 
				
			||||||
                $deployStrategy = 'deployment/strategy/rsync';
 | 
					                $deployStrategy = 'deployment/strategy/rsync';
 | 
				
			||||||
            }
 | 
					                break;
 | 
				
			||||||
            break;
 | 
					
 | 
				
			||||||
 | 
					            case self::DEPLOY_STRATEGY_TARGZ:
 | 
				
			||||||
 | 
					                $deployStrategy = 'deployment/strategy/tar-gz';
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            case self::DEPLOY_STRATEGY_GIT_REBASE:
 | 
				
			||||||
 | 
					                $deployStrategy = 'deployment/strategy/git-rebase';
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            case self::DEPLOY_STRATEGY_GUESS:
 | 
				
			||||||
 | 
					            default:
 | 
				
			||||||
 | 
					                if ($this->getConfig()->release('enabled', false) == true) {
 | 
				
			||||||
 | 
					                    $deployStrategy = 'deployment/strategy/tar-gz';
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    $deployStrategy = 'deployment/strategy/rsync';
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return $deployStrategy;
 | 
					        return $deployStrategy;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -21,10 +21,10 @@ use Mage\Console;
 | 
				
			|||||||
class InitCommand extends AbstractCommand
 | 
					class InitCommand extends AbstractCommand
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Command for Initalize a new Configuration Proyect
 | 
					     * Command for Initalize a new Configuration Proyect
 | 
				
			||||||
	 * @see \Mage\Command\AbstractCommand::run()
 | 
					     * @see \Mage\Command\AbstractCommand::run()
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    public function run()
 | 
					    public function run()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $configDir = getcwd() . '/.mage';
 | 
					        $configDir = getcwd() . '/.mage';
 | 
				
			||||||
@ -61,32 +61,32 @@ class InitCommand extends AbstractCommand
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    protected function getGeneralConfig()
 | 
					    protected function getGeneralConfig()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	// Assamble Global Settings
 | 
					        // Assamble Global Settings
 | 
				
			||||||
    	$projectName = $this->getConfig()->getParameter('name', '');
 | 
					        $projectName = $this->getConfig()->getParameter('name', '');
 | 
				
			||||||
    	$notificationEmail = $this->getConfig()->getParameter('email', '');
 | 
					        $notificationEmail = $this->getConfig()->getParameter('email', '');
 | 
				
			||||||
    	$notificationEnabled = ($notificationEmail != '') ? 'true' : 'false';
 | 
					        $notificationEnabled = ($notificationEmail != '') ? 'true' : 'false';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    	$globalSettings = str_replace(
 | 
					        $globalSettings = str_replace(
 | 
				
			||||||
			array(
 | 
					            array(
 | 
				
			||||||
				'%projectName%',
 | 
					                '%projectName%',
 | 
				
			||||||
				'%notificationEmail%',
 | 
					                '%notificationEmail%',
 | 
				
			||||||
				'%notificationEnabled%',
 | 
					                '%notificationEnabled%',
 | 
				
			||||||
				'%loggingEnabled%',
 | 
					                '%loggingEnabled%',
 | 
				
			||||||
				'%maxlogs%',
 | 
					                '%maxlogs%',
 | 
				
			||||||
				'%ssh_needs_tty%',
 | 
					                '%ssh_needs_tty%',
 | 
				
			||||||
			),
 | 
					            ),
 | 
				
			||||||
			array(
 | 
					            array(
 | 
				
			||||||
				$projectName,
 | 
					                $projectName,
 | 
				
			||||||
				$notificationEmail,
 | 
					                $notificationEmail,
 | 
				
			||||||
				$notificationEnabled,
 | 
					                $notificationEnabled,
 | 
				
			||||||
				'true',
 | 
					                'true',
 | 
				
			||||||
				30,
 | 
					                30,
 | 
				
			||||||
				'false'
 | 
					                'false'
 | 
				
			||||||
			),
 | 
					            ),
 | 
				
			||||||
			$this->getGeneralConfigTemplate()
 | 
					            $this->getGeneralConfigTemplate()
 | 
				
			||||||
    	);
 | 
					        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    	return $globalSettings;
 | 
					        return $globalSettings;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -95,14 +95,14 @@ class InitCommand extends AbstractCommand
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    protected function getGeneralConfigTemplate()
 | 
					    protected function getGeneralConfigTemplate()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	$template = '# global settings' . PHP_EOL
 | 
					        $template = '# global settings' . PHP_EOL
 | 
				
			||||||
                  . 'name: %projectName%' . PHP_EOL
 | 
					            . 'name: %projectName%' . PHP_EOL
 | 
				
			||||||
                  . 'email: %notificationEmail%' . PHP_EOL
 | 
					            . 'email: %notificationEmail%' . PHP_EOL
 | 
				
			||||||
                  . 'notifications: %notificationEnabled%' . PHP_EOL
 | 
					            . 'notifications: %notificationEnabled%' . PHP_EOL
 | 
				
			||||||
                  . 'logging: %loggingEnabled%' . PHP_EOL
 | 
					            . 'logging: %loggingEnabled%' . PHP_EOL
 | 
				
			||||||
                  . 'maxlogs: %maxlogs%' . PHP_EOL
 | 
					            . 'maxlogs: %maxlogs%' . PHP_EOL
 | 
				
			||||||
                  . 'ssh_needs_tty: %ssh_needs_tty%' . PHP_EOL;
 | 
					            . 'ssh_needs_tty: %ssh_needs_tty%' . PHP_EOL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    	return $template;
 | 
					        return $template;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -20,60 +20,61 @@ use Mage\Console;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class InstallCommand extends AbstractCommand
 | 
					class InstallCommand extends AbstractCommand
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Installs Magallanes
 | 
					     * Installs Magallanes
 | 
				
			||||||
	 * @see \Mage\Command\AbstractCommand::run()
 | 
					     * @see \Mage\Command\AbstractCommand::run()
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    public function run()
 | 
					    public function run()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	Console::output('Installing <dark_gray>Magallanes</dark_gray>... ', 1, 0);
 | 
					        Console::output('Installing <dark_gray>Magallanes</dark_gray>... ', 1, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    	// Vars
 | 
					        // Vars
 | 
				
			||||||
    	$installDir = $this->getConfig()->getParameter('installDir', '/opt/magallanes');
 | 
					        $installDir = $this->getConfig()->getParameter('installDir', '/opt/magallanes');
 | 
				
			||||||
    	$systemWide = $this->getConfig()->getParameter('systemWide', false);
 | 
					        $systemWide = $this->getConfig()->getParameter('systemWide', false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    	// Clean vars
 | 
					        // Clean vars
 | 
				
			||||||
    	$baseDir = realpath(dirname($installDir));
 | 
					        $baseDir = realpath(dirname($installDir));
 | 
				
			||||||
    	$installDir = basename($installDir);
 | 
					        $installDir = basename($installDir);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    	// Check if install dir is available
 | 
					        // Check if install dir is available
 | 
				
			||||||
    	if (!is_dir($baseDir) || !is_writable($baseDir)) {
 | 
					        if (!is_dir($baseDir) || !is_writable($baseDir)) {
 | 
				
			||||||
    		Console::output('<red>Failure: install directory is invalid.</red>', 0, 2);
 | 
					            Console::output('<red>Failure: install directory is invalid.</red>', 0, 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Chck if it is a system wide install the user is root
 | 
					            // Chck if it is a system wide install the user is root
 | 
				
			||||||
    	} else if ($systemWide && (getenv('LOGNAME') != 'root')) {
 | 
					        } else if ($systemWide && (getenv('LOGNAME') != 'root')) {
 | 
				
			||||||
    			Console::output('<red>Failure: you have to be root to perform a system wide install.</red>', 0, 2);
 | 
					            Console::output('<red>Failure: you have to be root to perform a system wide install.</red>', 0, 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    	} else {
 | 
					        } else {
 | 
				
			||||||
    		$destinationDir = $baseDir . '/' . $installDir;
 | 
					            $destinationDir = $baseDir . '/' . $installDir;
 | 
				
			||||||
    		if (!is_dir($destinationDir)) {
 | 
					            if (!is_dir($destinationDir)) {
 | 
				
			||||||
    			mkdir($destinationDir);
 | 
					                mkdir($destinationDir);
 | 
				
			||||||
    		}
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    		// Copy
 | 
					            // Copy
 | 
				
			||||||
    		$this->recursiveCopy('./', $destinationDir . '/' . MAGALLANES_VERSION);
 | 
					            $this->recursiveCopy('./', $destinationDir . '/' . MAGALLANES_VERSION);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    		// Check if there is already a symlink
 | 
					            // Check if there is already a symlink
 | 
				
			||||||
    		if (file_exists($destinationDir . '/' . 'latest')
 | 
					            if (file_exists($destinationDir . '/' . 'latest')
 | 
				
			||||||
				    && is_link($destinationDir . '/' . 'latest')) {
 | 
					                && is_link($destinationDir . '/' . 'latest')
 | 
				
			||||||
    			unlink($destinationDir . '/' . 'latest');
 | 
					            ) {
 | 
				
			||||||
    		}
 | 
					                unlink($destinationDir . '/' . 'latest');
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    		// Create "latest" symlink
 | 
					            // Create "latest" symlink
 | 
				
			||||||
    		symlink(
 | 
					            symlink(
 | 
				
			||||||
    		    $destinationDir . '/' . MAGALLANES_VERSION,
 | 
					                $destinationDir . '/' . MAGALLANES_VERSION,
 | 
				
			||||||
    		    $destinationDir . '/' . 'latest'
 | 
					                $destinationDir . '/' . 'latest'
 | 
				
			||||||
    		);
 | 
					            );
 | 
				
			||||||
    		chmod($destinationDir . '/' . MAGALLANES_VERSION . '/bin/mage', 0755);
 | 
					            chmod($destinationDir . '/' . MAGALLANES_VERSION . '/bin/mage', 0755);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    		if ($systemWide) {
 | 
					            if ($systemWide) {
 | 
				
			||||||
    			if (!file_exists('/usr/bin/mage')) {
 | 
					                if (!file_exists('/usr/bin/mage')) {
 | 
				
			||||||
    				symlink($destinationDir . '/latest/bin/mage', '/usr/bin/mage');
 | 
					                    symlink($destinationDir . '/latest/bin/mage', '/usr/bin/mage');
 | 
				
			||||||
    			}
 | 
					                }
 | 
				
			||||||
    		}
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    		Console::output('<light_green>Success!</light_green>', 0, 2);
 | 
					            Console::output('<light_green>Success!</light_green>', 0, 2);
 | 
				
			||||||
    	}
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 | 
				
			|||||||
@ -24,11 +24,11 @@ use Exception;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class ListCommand extends AbstractCommand
 | 
					class ListCommand extends AbstractCommand
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Command for Listing Configuration Elements
 | 
					     * Command for Listing Configuration Elements
 | 
				
			||||||
	 * @see \Mage\Command\AbstractCommand::run()
 | 
					     * @see \Mage\Command\AbstractCommand::run()
 | 
				
			||||||
	 * @throws Exception
 | 
					     * @throws Exception
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    public function run()
 | 
					    public function run()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $subCommand = $this->getConfig()->getArgument(1);
 | 
					        $subCommand = $this->getConfig()->getArgument(1);
 | 
				
			||||||
@ -53,24 +53,24 @@ class ListCommand extends AbstractCommand
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    protected function listEnvironments()
 | 
					    protected function listEnvironments()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	$environments = array();
 | 
					        $environments = array();
 | 
				
			||||||
        $content = scandir(getcwd() . '/.mage/config/environment/');
 | 
					        $content = scandir(getcwd() . '/.mage/config/environment/');
 | 
				
			||||||
        foreach ($content as $file) {
 | 
					        foreach ($content as $file) {
 | 
				
			||||||
            if (strpos($file, '.yml') !== false) {
 | 
					            if (strpos($file, '.yml') !== false) {
 | 
				
			||||||
            	$environments[] = str_replace('.yml', '', $file);
 | 
					                $environments[] = str_replace('.yml', '', $file);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        sort($environments);
 | 
					        sort($environments);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (count($environments) > 0) {
 | 
					        if (count($environments) > 0) {
 | 
				
			||||||
        	Console::output('<dark_gray>These are your configured environments:</dark_gray>', 1, 1);
 | 
					            Console::output('<dark_gray>These are your configured environments:</dark_gray>', 1, 1);
 | 
				
			||||||
        	foreach ($environments as $environment) {
 | 
					            foreach ($environments as $environment) {
 | 
				
			||||||
        		Console::output('* <light_red>' . $environment . '</light_red>', 2, 1);
 | 
					                Console::output('* <light_red>' . $environment . '</light_red>', 2, 1);
 | 
				
			||||||
        	}
 | 
					            }
 | 
				
			||||||
        	Console::output('', 1, 1);
 | 
					            Console::output('', 1, 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
        	Console::output('<dark_gray>You don\'t have any environment configured.</dark_gray>', 1, 2);
 | 
					            Console::output('<dark_gray>You don\'t have any environment configured.</dark_gray>', 1, 2);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -21,10 +21,10 @@ use Mage\Console;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class LockCommand extends AbstractCommand implements RequiresEnvironment
 | 
					class LockCommand extends AbstractCommand implements RequiresEnvironment
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Locks the Deployment to a Environment
 | 
					     * Locks the Deployment to a Environment
 | 
				
			||||||
	 * @see \Mage\Command\AbstractCommand::run()
 | 
					     * @see \Mage\Command\AbstractCommand::run()
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    public function run()
 | 
					    public function run()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        Console::output('Your name (enter to leave blank): ', 0, 0);
 | 
					        Console::output('Your name (enter to leave blank): ', 0, 0);
 | 
				
			||||||
 | 
				
			|||||||
@ -46,33 +46,33 @@ class ReleasesCommand extends AbstractCommand implements RequiresEnvironment
 | 
				
			|||||||
            $this->getConfig()->setHost($host);
 | 
					            $this->getConfig()->setHost($host);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            switch ($subCommand) {
 | 
					            switch ($subCommand) {
 | 
				
			||||||
            case 'list':
 | 
					                case 'list':
 | 
				
			||||||
                $task = Factory::get('releases/list', $this->getConfig());
 | 
					                    $task = Factory::get('releases/list', $this->getConfig());
 | 
				
			||||||
                $task->init();
 | 
					                    $task->init();
 | 
				
			||||||
                $result = $task->run();
 | 
					                    $result = $task->run();
 | 
				
			||||||
                break;
 | 
					                    break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            case 'rollback':
 | 
					                case 'rollback':
 | 
				
			||||||
                if (!is_numeric($this->getConfig()->getParameter('release', ''))) {
 | 
					                    if (!is_numeric($this->getConfig()->getParameter('release', ''))) {
 | 
				
			||||||
                    Console::output('<red>Missing required releaseid.</red>', 1, 2);
 | 
					                        Console::output('<red>Missing required releaseid.</red>', 1, 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    return false;
 | 
					                        return false;
 | 
				
			||||||
                }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                $lockFile = getcwd() . '/.mage/' . $this->getConfig()->getEnvironment() . '.lock';
 | 
					                    $lockFile = getcwd() . '/.mage/' . $this->getConfig()->getEnvironment() . '.lock';
 | 
				
			||||||
                if (file_exists($lockFile)) {
 | 
					                    if (file_exists($lockFile)) {
 | 
				
			||||||
                    Console::output('<red>This environment is locked!</red>', 1, 2);
 | 
					                        Console::output('<red>This environment is locked!</red>', 1, 2);
 | 
				
			||||||
                    echo file_get_contents($lockFile);
 | 
					                        echo file_get_contents($lockFile);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    return false;
 | 
					                        return false;
 | 
				
			||||||
                }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                $releaseId = $this->getConfig()->getParameter('release', '');
 | 
					                    $releaseId = $this->getConfig()->getParameter('release', '');
 | 
				
			||||||
                $task      = Factory::get('releases/rollback', $this->getConfig());
 | 
					                    $task = Factory::get('releases/rollback', $this->getConfig());
 | 
				
			||||||
                $task->init();
 | 
					                    $task->init();
 | 
				
			||||||
                $task->setRelease($releaseId);
 | 
					                    $task->setRelease($releaseId);
 | 
				
			||||||
                $result = $task->run();
 | 
					                    $result = $task->run();
 | 
				
			||||||
                break;
 | 
					                    break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -22,10 +22,10 @@ use Mage\Console;
 | 
				
			|||||||
class UnlockCommand
 | 
					class UnlockCommand
 | 
				
			||||||
    extends AbstractCommand implements RequiresEnvironment
 | 
					    extends AbstractCommand implements RequiresEnvironment
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Unlocks an Environment
 | 
					     * Unlocks an Environment
 | 
				
			||||||
	 * @see \Mage\Command\AbstractCommand::run()
 | 
					     * @see \Mage\Command\AbstractCommand::run()
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    public function run()
 | 
					    public function run()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $lockFile = getcwd() . '/.mage/' . $this->getConfig()->getEnvironment() . '.lock';
 | 
					        $lockFile = getcwd() . '/.mage/' . $this->getConfig()->getEnvironment() . '.lock';
 | 
				
			||||||
 | 
				
			|||||||
@ -21,10 +21,10 @@ use Mage\Console;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class UpdateCommand extends AbstractCommand
 | 
					class UpdateCommand extends AbstractCommand
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Updates the SCM Base Code
 | 
					     * Updates the SCM Base Code
 | 
				
			||||||
	 * @see \Mage\Command\AbstractCommand::run()
 | 
					     * @see \Mage\Command\AbstractCommand::run()
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    public function run()
 | 
					    public function run()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $task = Factory::get('scm/update', $this->getConfig());
 | 
					        $task = Factory::get('scm/update', $this->getConfig());
 | 
				
			||||||
 | 
				
			|||||||
@ -20,10 +20,10 @@ use Mage\Console;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class UpgradeCommand extends AbstractCommand
 | 
					class UpgradeCommand extends AbstractCommand
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Source for downloading
 | 
					     * Source for downloading
 | 
				
			||||||
	 * @var string
 | 
					     * @var string
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    const DOWNLOAD = 'http://download.magephp.com/magallanes.{version}.tar.gz';
 | 
					    const DOWNLOAD = 'http://download.magephp.com/magallanes.{version}.tar.gz';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -51,47 +51,47 @@ class UpgradeCommand extends AbstractCommand
 | 
				
			|||||||
            Console::output('You need to be the <dark_gray>' . $owner . '</dark_gray> user to perform the upgrade, or <dark_gray>root</dark_gray>.', 2);
 | 
					            Console::output('You need to be the <dark_gray>' . $owner . '</dark_gray> user to perform the upgrade, or <dark_gray>root</dark_gray>.', 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
        	// Check version
 | 
					            // Check version
 | 
				
			||||||
        	$version = json_decode(file_get_contents(self::UPGRADE));
 | 
					            $version = json_decode(file_get_contents(self::UPGRADE));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        	if ($version !== false && $version !== null) {
 | 
					            if ($version !== false && $version !== null) {
 | 
				
			||||||
        		$versionCompare = version_compare(MAGALLANES_VERSION, $version->latest);
 | 
					                $versionCompare = version_compare(MAGALLANES_VERSION, $version->latest);
 | 
				
			||||||
        		if ($versionCompare == 0) {
 | 
					                if ($versionCompare == 0) {
 | 
				
			||||||
        			Console::output('<yellow>SKIP</yellow>', 0, 1);
 | 
					                    Console::output('<yellow>SKIP</yellow>', 0, 1);
 | 
				
			||||||
        			Console::output('Your current version is up to date.', 2);
 | 
					                    Console::output('Your current version is up to date.', 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        		} else if ($versionCompare == 1) {
 | 
					                } else if ($versionCompare == 1) {
 | 
				
			||||||
        			Console::output('<yellow>SKIP</yellow>', 0, 1);
 | 
					                    Console::output('<yellow>SKIP</yellow>', 0, 1);
 | 
				
			||||||
        			Console::output('Your current version is newer.', 2);
 | 
					                    Console::output('Your current version is newer.', 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        		} else if ($versionCompare == -1) {
 | 
					                } else if ($versionCompare == -1) {
 | 
				
			||||||
        			// Download Package
 | 
					                    // Download Package
 | 
				
			||||||
        			$tarball = file_get_contents(str_replace('{version}', $version->latest, self::DOWNLOAD));
 | 
					                    $tarball = file_get_contents(str_replace('{version}', $version->latest, self::DOWNLOAD));
 | 
				
			||||||
        			if ($tarball === false) {
 | 
					                    if ($tarball === false) {
 | 
				
			||||||
        				Console::output('<red>FAIL</red>', 0, 1);
 | 
					                        Console::output('<red>FAIL</red>', 0, 1);
 | 
				
			||||||
        				Console::output('Corrupted download.', 2);
 | 
					                        Console::output('Corrupted download.', 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        			} else {
 | 
					                    } else {
 | 
				
			||||||
        				$tarballFile = tempnam('/tmp', 'magallanes_download');
 | 
					                        $tarballFile = tempnam('/tmp', 'magallanes_download');
 | 
				
			||||||
        				rename($tarballFile, $tarballFile . '.tar.gz');
 | 
					                        rename($tarballFile, $tarballFile . '.tar.gz');
 | 
				
			||||||
        				$tarballFile .= '.tar.gz';
 | 
					                        $tarballFile .= '.tar.gz';
 | 
				
			||||||
        				file_put_contents($tarballFile, $tarball);
 | 
					                        file_put_contents($tarballFile, $tarball);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        				Console::executeCommand('rm -rf ' . MAGALLANES_DIRECTORY);
 | 
					                        Console::executeCommand('rm -rf ' . MAGALLANES_DIRECTORY);
 | 
				
			||||||
        				Console::executeCommand('cd ' . dirname($tarballFile) . ' && tar xfz ' . $tarballFile);
 | 
					                        Console::executeCommand('cd ' . dirname($tarballFile) . ' && tar xfz ' . $tarballFile);
 | 
				
			||||||
        				Console::executeCommand('mv ' . dirname($tarballFile) . '/magallanes ' . MAGALLANES_DIRECTORY);
 | 
					                        Console::executeCommand('mv ' . dirname($tarballFile) . '/magallanes ' . MAGALLANES_DIRECTORY);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        				Console::output('<green>OK</green>', 0, 1);
 | 
					                        Console::output('<green>OK</green>', 0, 1);
 | 
				
			||||||
        			}
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        		} else {
 | 
					                } else {
 | 
				
			||||||
        			Console::output('<red>FAIL</red>', 0, 1);
 | 
					                    Console::output('<red>FAIL</red>', 0, 1);
 | 
				
			||||||
        			Console::output('Invalid version.', 2);
 | 
					                    Console::output('Invalid version.', 2);
 | 
				
			||||||
        		}
 | 
					                }
 | 
				
			||||||
        	} else {
 | 
					            } else {
 | 
				
			||||||
        		Console::output('<red>FAIL</red>', 0, 1);
 | 
					                Console::output('<red>FAIL</red>', 0, 1);
 | 
				
			||||||
        		Console::output('Invalid version.', 2);
 | 
					                Console::output('Invalid version.', 2);
 | 
				
			||||||
        	}
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -20,13 +20,13 @@ use Mage\Console;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class VersionCommand extends AbstractCommand
 | 
					class VersionCommand extends AbstractCommand
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Display the Magallanes Version
 | 
					     * Display the Magallanes Version
 | 
				
			||||||
	 * @see \Mage\Command\AbstractCommand::run()
 | 
					     * @see \Mage\Command\AbstractCommand::run()
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    public function run()
 | 
					    public function run()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        Console::output('Running <blue>Magallanes</blue> version <dark_gray>' . MAGALLANES_VERSION .'</dark_gray>', 0, 2);
 | 
					        Console::output('Running <blue>Magallanes</blue> version <dark_gray>' . MAGALLANES_VERSION . '</dark_gray>', 0, 2);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -40,7 +40,7 @@ class Factory
 | 
				
			|||||||
        $className = 'Mage\\Command\\BuiltIn\\' . $commandName . 'Command';
 | 
					        $className = 'Mage\\Command\\BuiltIn\\' . $commandName . 'Command';
 | 
				
			||||||
        /** @var AbstractCommand $instance */
 | 
					        /** @var AbstractCommand $instance */
 | 
				
			||||||
        $instance = new $className;
 | 
					        $instance = new $className;
 | 
				
			||||||
        if(!is_a($instance, "Mage\Command\AbstractCommand")) {
 | 
					        if (!is_a($instance, "Mage\Command\AbstractCommand")) {
 | 
				
			||||||
            throw new Exception('The command ' . $commandName . ' must be an instance of Mage\Command\AbstractCommand.');
 | 
					            throw new Exception('The command ' . $commandName . ' must be an instance of Mage\Command\AbstractCommand.');
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -42,18 +42,18 @@ class Compiler
 | 
				
			|||||||
        /** @var \SplFileInfo $path */
 | 
					        /** @var \SplFileInfo $path */
 | 
				
			||||||
        foreach ($iterator as $path) {
 | 
					        foreach ($iterator as $path) {
 | 
				
			||||||
            if ($path->isFile()) {
 | 
					            if ($path->isFile()) {
 | 
				
			||||||
                $phar->addFromString(str_replace(dirname(__DIR__).'/', '', $path->getPathname()), file_get_contents($path));
 | 
					                $phar->addFromString(str_replace(dirname(__DIR__) . '/', '', $path->getPathname()), file_get_contents($path));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $binary = file(__DIR__.'/../bin/mage');
 | 
					        $binary = file(__DIR__ . '/../bin/mage');
 | 
				
			||||||
        unset($binary[0]);
 | 
					        unset($binary[0]);
 | 
				
			||||||
        $binary = implode(PHP_EOL, $binary);
 | 
					        $binary = implode(PHP_EOL, $binary);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $phar->addFromString('mage', str_replace(
 | 
					        $phar->addFromString('mage', str_replace(
 | 
				
			||||||
            '$baseDir = dirname(dirname(__FILE__));',
 | 
					            '$baseDir = dirname(dirname(__FILE__));',
 | 
				
			||||||
            '$baseDir = __DIR__;',
 | 
					            '$baseDir = __DIR__;',
 | 
				
			||||||
    		$binary
 | 
					            $binary
 | 
				
			||||||
        ));
 | 
					        ));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $phar->setStub("#!/usr/bin/env php\n<?php Phar::mapPhar('mage.phar'); require 'phar://mage.phar/mage'; __HALT_COMPILER();");
 | 
					        $phar->setStub("#!/usr/bin/env php\n<?php Phar::mapPhar('mage.phar'); require 'phar://mage.phar/mage'; __HALT_COMPILER();");
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										132
									
								
								Mage/Config.php
									
									
									
									
									
								
							
							
						
						
									
										132
									
								
								Mage/Config.php
									
									
									
									
									
								
							@ -26,9 +26,9 @@ class Config
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    const HOST_NAME_LENGTH = 1000;
 | 
					    const HOST_NAME_LENGTH = 1000;
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
	 * Arguments loaded
 | 
					     * Arguments loaded
 | 
				
			||||||
	 * @var array
 | 
					     * @var array
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    private $arguments = array();
 | 
					    private $arguments = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -73,27 +73,27 @@ class Config
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    protected function parse($arguments)
 | 
					    protected function parse($arguments)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	foreach ($arguments as $argument) {
 | 
					        foreach ($arguments as $argument) {
 | 
				
			||||||
    		if (preg_match('/to:[\w]+/i', $argument)) {
 | 
					            if (preg_match('/to:[\w]+/i', $argument)) {
 | 
				
			||||||
    			$this->environment = str_replace('to:', '', $argument);
 | 
					                $this->environment = str_replace('to:', '', $argument);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    		} else if (preg_match('/--[\w]+/i', $argument)) {
 | 
					            } else if (preg_match('/--[\w]+/i', $argument)) {
 | 
				
			||||||
    			$optionValue = explode('=', substr($argument, 2));
 | 
					                $optionValue = explode('=', substr($argument, 2));
 | 
				
			||||||
    			if (count($optionValue) == 1) {
 | 
					                if (count($optionValue) == 1) {
 | 
				
			||||||
    				$this->parameters[$optionValue[0]] = true;
 | 
					                    $this->parameters[$optionValue[0]] = true;
 | 
				
			||||||
    			} else if (count($optionValue) == 2) {
 | 
					                } else if (count($optionValue) == 2) {
 | 
				
			||||||
    				if (strtolower($optionValue[1]) == 'true') {
 | 
					                    if (strtolower($optionValue[1]) == 'true') {
 | 
				
			||||||
    					$this->parameters[$optionValue[0]] = true;
 | 
					                        $this->parameters[$optionValue[0]] = true;
 | 
				
			||||||
    				} else if (strtolower($optionValue[1]) == 'false') {
 | 
					                    } else if (strtolower($optionValue[1]) == 'false') {
 | 
				
			||||||
    					$this->parameters[$optionValue[0]] = false;
 | 
					                        $this->parameters[$optionValue[0]] = false;
 | 
				
			||||||
    				} else {
 | 
					                    } else {
 | 
				
			||||||
    					$this->parameters[$optionValue[0]] = $optionValue[1];
 | 
					                        $this->parameters[$optionValue[0]] = $optionValue[1];
 | 
				
			||||||
    				}
 | 
					                    }
 | 
				
			||||||
    			}
 | 
					                }
 | 
				
			||||||
    		} else {
 | 
					            } else {
 | 
				
			||||||
    			$this->arguments[] = $argument;
 | 
					                $this->arguments[] = $argument;
 | 
				
			||||||
    		}
 | 
					            }
 | 
				
			||||||
    	}
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -102,7 +102,7 @@ class Config
 | 
				
			|||||||
    protected function initGeneral()
 | 
					    protected function initGeneral()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            $this->generalConfig =  $this->loadGeneral(getcwd() . '/.mage/config/general.yml');
 | 
					            $this->generalConfig = $this->loadGeneral(getcwd() . '/.mage/config/general.yml');
 | 
				
			||||||
        } catch (ConfigNotFoundException $e) {
 | 
					        } catch (ConfigNotFoundException $e) {
 | 
				
			||||||
            // normal situation
 | 
					            // normal situation
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -116,7 +116,8 @@ class Config
 | 
				
			|||||||
     * @return array
 | 
					     * @return array
 | 
				
			||||||
     * @throws Config\ConfigNotFoundException
 | 
					     * @throws Config\ConfigNotFoundException
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    protected function loadGeneral($filePath){
 | 
					    protected function loadGeneral($filePath)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        return $this->parseConfigFile($filePath);
 | 
					        return $this->parseConfigFile($filePath);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -142,6 +143,7 @@ class Config
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        return $settings;
 | 
					        return $settings;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Loads the Environment configuration
 | 
					     * Loads the Environment configuration
 | 
				
			||||||
     * @param $filePath string
 | 
					     * @param $filePath string
 | 
				
			||||||
@ -169,16 +171,15 @@ class Config
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    protected function initEnvironment()
 | 
					    protected function initEnvironment()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	$environment = $this->getEnvironment();
 | 
					        $environment = $this->getEnvironment();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if(!empty($environment))
 | 
					        if (!empty($environment)) {
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            $configFilePath = getcwd() . '/.mage/config/environment/' . $environment . '.yml';
 | 
					            $configFilePath = getcwd() . '/.mage/config/environment/' . $environment . '.yml';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                $this->environmentConfig =  $this->loadEnvironment($configFilePath);
 | 
					                $this->environmentConfig = $this->loadEnvironment($configFilePath);
 | 
				
			||||||
            } catch (ConfigNotFoundException $e) {
 | 
					            } catch (ConfigNotFoundException $e) {
 | 
				
			||||||
                throw new RequiredConfigNotFoundException("Not found required config $configFilePath for environment $environment", 0 , $e);
 | 
					                throw new RequiredConfigNotFoundException("Not found required config $configFilePath for environment $environment", 0, $e);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -191,18 +192,17 @@ class Config
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    protected function isRunInSpecialMode(array $parameters)
 | 
					    protected function isRunInSpecialMode(array $parameters)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if(empty($parameters))
 | 
					        if (empty($parameters))
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        foreach($parameters as $parameter)
 | 
					        foreach ($parameters as $parameter) {
 | 
				
			||||||
        {
 | 
					            if (isset(Console::$paramsNotRequiringEnvironment[$parameter])) {
 | 
				
			||||||
            if(isset(Console::$paramsNotRequiringEnvironment[$parameter]))
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                return true;
 | 
					                return true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return false;
 | 
					        return false;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Load the Configuration and parses the Arguments
 | 
					     * Load the Configuration and parses the Arguments
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
@ -220,8 +220,8 @@ class Config
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function reload()
 | 
					    public function reload()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	$this->initGeneral();
 | 
					        $this->initGeneral();
 | 
				
			||||||
    	$this->initEnvironment();
 | 
					        $this->initEnvironment();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -286,7 +286,7 @@ class Config
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function addParameter($name, $value = true)
 | 
					    public function addParameter($name, $value = true)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	$this->parameters[$name] = $value;
 | 
					        $this->parameters[$name] = $value;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -307,24 +307,24 @@ class Config
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function getTasks($stage = 'deploy')
 | 
					    public function getTasks($stage = 'deploy')
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	if ($stage == 'deploy') {
 | 
					        if ($stage == 'deploy') {
 | 
				
			||||||
    		$configStage = 'on-deploy';
 | 
					            $configStage = 'on-deploy';
 | 
				
			||||||
    	} else {
 | 
					        } else {
 | 
				
			||||||
    		$configStage = $stage;
 | 
					            $configStage = $stage;
 | 
				
			||||||
    	}
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $tasks = array();
 | 
					        $tasks = array();
 | 
				
			||||||
        $config = $this->getEnvironmentOption('tasks', array());
 | 
					        $config = $this->getEnvironmentOption('tasks', array());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Host Config
 | 
					        // Host Config
 | 
				
			||||||
        if (is_array($this->hostConfig) && isset($this->hostConfig['tasks'])) {
 | 
					        if (is_array($this->hostConfig) && isset($this->hostConfig['tasks'])) {
 | 
				
			||||||
        	if (isset($this->hostConfig['tasks'][$configStage])) {
 | 
					            if (isset($this->hostConfig['tasks'][$configStage])) {
 | 
				
			||||||
        		$config[$configStage] = $this->hostConfig['tasks'][$configStage];
 | 
					                $config[$configStage] = $this->hostConfig['tasks'][$configStage];
 | 
				
			||||||
        	}
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (isset($config[$configStage])) {
 | 
					        if (isset($config[$configStage])) {
 | 
				
			||||||
            $tasksData = ($config[$configStage] ? (array) $config[$configStage] : array());
 | 
					            $tasksData = ($config[$configStage] ? (array)$config[$configStage] : array());
 | 
				
			||||||
            foreach ($tasksData as $taskData) {
 | 
					            foreach ($tasksData as $taskData) {
 | 
				
			||||||
                if (is_array($taskData)) {
 | 
					                if (is_array($taskData)) {
 | 
				
			||||||
                    $tasks[] = array(
 | 
					                    $tasks[] = array(
 | 
				
			||||||
@ -352,7 +352,7 @@ class Config
 | 
				
			|||||||
        $envConfig = $this->getEnvironmentConfig();
 | 
					        $envConfig = $this->getEnvironmentConfig();
 | 
				
			||||||
        if (isset($envConfig['hosts'])) {
 | 
					        if (isset($envConfig['hosts'])) {
 | 
				
			||||||
            if (is_array($envConfig['hosts'])) {
 | 
					            if (is_array($envConfig['hosts'])) {
 | 
				
			||||||
                $hosts = (array) $envConfig['hosts'];
 | 
					                $hosts = (array)$envConfig['hosts'];
 | 
				
			||||||
            } else if (is_string($envConfig['hosts']) && file_exists($envConfig['hosts']) && is_readable($envConfig['hosts'])) {
 | 
					            } else if (is_string($envConfig['hosts']) && file_exists($envConfig['hosts']) && is_readable($envConfig['hosts'])) {
 | 
				
			||||||
                $hosts = $this->getHostsFromFile($envConfig['hosts']);
 | 
					                $hosts = $this->getHostsFromFile($envConfig['hosts']);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@ -381,8 +381,8 @@ class Config
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function setHostConfig($hostConfig = null)
 | 
					    public function setHostConfig($hostConfig = null)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	$this->hostConfig = $hostConfig;
 | 
					        $this->hostConfig = $hostConfig;
 | 
				
			||||||
    	return $this;
 | 
					        return $this;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -458,7 +458,7 @@ class Config
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function environmentConfig($option, $default = false)
 | 
					    public function environmentConfig($option, $default = false)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	return $this->getEnvironmentOption($option, $default);
 | 
					        return $this->getEnvironmentOption($option, $default);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -470,14 +470,14 @@ class Config
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function deployment($option, $default = false)
 | 
					    public function deployment($option, $default = false)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	// Host Config
 | 
					        // Host Config
 | 
				
			||||||
    	if (is_array($this->hostConfig) && isset($this->hostConfig['deployment'])) {
 | 
					        if (is_array($this->hostConfig) && isset($this->hostConfig['deployment'])) {
 | 
				
			||||||
    		if (isset($this->hostConfig['deployment'][$option])) {
 | 
					            if (isset($this->hostConfig['deployment'][$option])) {
 | 
				
			||||||
    			return $this->hostConfig['deployment'][$option];
 | 
					                return $this->hostConfig['deployment'][$option];
 | 
				
			||||||
    		}
 | 
					            }
 | 
				
			||||||
    	}
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    	// Global Config
 | 
					        // Global Config
 | 
				
			||||||
        $config = $this->getEnvironmentOption('deployment', array());
 | 
					        $config = $this->getEnvironmentOption('deployment', array());
 | 
				
			||||||
        if (isset($config[$option])) {
 | 
					        if (isset($config[$option])) {
 | 
				
			||||||
            if (is_array($default) && ($config[$option] == '')) {
 | 
					            if (is_array($default) && ($config[$option] == '')) {
 | 
				
			||||||
@ -499,12 +499,12 @@ class Config
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function release($option, $default = false)
 | 
					    public function release($option, $default = false)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	// Host Config
 | 
					        // Host Config
 | 
				
			||||||
    	if (is_array($this->hostConfig) && isset($this->hostConfig['releases'])) {
 | 
					        if (is_array($this->hostConfig) && isset($this->hostConfig['releases'])) {
 | 
				
			||||||
    		if (isset($this->hostConfig['releases'][$option])) {
 | 
					            if (isset($this->hostConfig['releases'][$option])) {
 | 
				
			||||||
    			return $this->hostConfig['releases'][$option];
 | 
					                return $this->hostConfig['releases'][$option];
 | 
				
			||||||
    		}
 | 
					            }
 | 
				
			||||||
    	}
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $config = $this->getEnvironmentOption('releases', array());
 | 
					        $config = $this->getEnvironmentOption('releases', array());
 | 
				
			||||||
        if (isset($config[$option])) {
 | 
					        if (isset($config[$option])) {
 | 
				
			||||||
@ -575,13 +575,13 @@ class Config
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function parseConfigFile($filePath)
 | 
					    public function parseConfigFile($filePath)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if(!file_exists($filePath))
 | 
					        if (!file_exists($filePath)) {
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            throw new ConfigNotFoundException("Cannot find the file at path $filePath");
 | 
					            throw new ConfigNotFoundException("Cannot find the file at path $filePath");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $this->parseConfigText(file_get_contents($filePath));
 | 
					        return $this->parseConfigText(file_get_contents($filePath));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function parseConfigText($input)
 | 
					    public function parseConfigText($input)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return Yaml::parse($input);
 | 
					        return Yaml::parse($input);
 | 
				
			||||||
 | 
				
			|||||||
@ -28,12 +28,12 @@ class Console
 | 
				
			|||||||
     * TODO refactor into own static class
 | 
					     * TODO refactor into own static class
 | 
				
			||||||
     * @var array
 | 
					     * @var array
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public static $paramsNotRequiringEnvironment = array('install'=>'install', 'upgrade'=>'upgrade', 'version'=>'version');
 | 
					    public static $paramsNotRequiringEnvironment = array('install' => 'install', 'upgrade' => 'upgrade', 'version' => 'version');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Handler to the current Log File.
 | 
					     * Handler to the current Log File.
 | 
				
			||||||
	 * @var mixed
 | 
					     * @var mixed
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    private static $log = null;
 | 
					    private static $log = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -72,19 +72,19 @@ class Console
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function run($arguments)
 | 
					    public function run($arguments)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	$exitCode = 10;
 | 
					        $exitCode = 10;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    	// Declare a Shutdown Closure
 | 
					        // Declare a Shutdown Closure
 | 
				
			||||||
    	register_shutdown_function(function() {
 | 
					        register_shutdown_function(function () {
 | 
				
			||||||
    		// Only Unlock if there was an error
 | 
					            // Only Unlock if there was an error
 | 
				
			||||||
            if (error_get_last() !== null) {
 | 
					            if (error_get_last() !== null) {
 | 
				
			||||||
            	if (file_exists(getcwd() . '/.mage/~working.lock')) {
 | 
					                if (file_exists(getcwd() . '/.mage/~working.lock')) {
 | 
				
			||||||
            		unlink(getcwd() . '/.mage/~working.lock');
 | 
					                    unlink(getcwd() . '/.mage/~working.lock');
 | 
				
			||||||
            	}
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
    	});
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    	// Load configuration
 | 
					        // Load configuration
 | 
				
			||||||
        $configError = false;
 | 
					        $configError = false;
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            // Load Config
 | 
					            // Load Config
 | 
				
			||||||
@ -126,7 +126,7 @@ class Console
 | 
				
			|||||||
            self::output('<red>' . $configError . '</red>', 1, 2);
 | 
					            self::output('<red>' . $configError . '</red>', 1, 2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
        	// Run Command and check for Command Requirements
 | 
					            // Run Command and check for Command Requirements
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                $command = Factory::get($commandName, $config);
 | 
					                $command = Factory::get($commandName, $config);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -146,7 +146,7 @@ class Console
 | 
				
			|||||||
        if ($showGreetings) {
 | 
					        if ($showGreetings) {
 | 
				
			||||||
            self::output('Finished <blue>Magallanes</blue>', 0, 2);
 | 
					            self::output('Finished <blue>Magallanes</blue>', 0, 2);
 | 
				
			||||||
            if (file_exists(getcwd() . '/.mage/~working.lock')) {
 | 
					            if (file_exists(getcwd() . '/.mage/~working.lock')) {
 | 
				
			||||||
            	unlink(getcwd() . '/.mage/~working.lock');
 | 
					                unlink(getcwd() . '/.mage/~working.lock');
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -168,12 +168,12 @@ class Console
 | 
				
			|||||||
        self::log(strip_tags($message));
 | 
					        self::log(strip_tags($message));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self::$screenBuffer .= str_repeat("\t", $tabs)
 | 
					        self::$screenBuffer .= str_repeat("\t", $tabs)
 | 
				
			||||||
                              . strip_tags($message)
 | 
					            . strip_tags($message)
 | 
				
			||||||
                              . str_repeat(PHP_EOL, $newLine);
 | 
					            . str_repeat(PHP_EOL, $newLine);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $output = str_repeat("\t", $tabs)
 | 
					        $output = str_repeat("\t", $tabs)
 | 
				
			||||||
                . Colors::color($message, self::$config)
 | 
					            . Colors::color($message, self::$config)
 | 
				
			||||||
                . str_repeat(PHP_EOL, $newLine);
 | 
					            . str_repeat(PHP_EOL, $newLine);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        echo $output;
 | 
					        echo $output;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -215,7 +215,7 @@ class Console
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        if (self::$logEnabled) {
 | 
					        if (self::$logEnabled) {
 | 
				
			||||||
            if (self::$log == null) {
 | 
					            if (self::$log == null) {
 | 
				
			||||||
            	self::$logFile = realpath(getcwd() . '/.mage/logs') . '/log-' . date('Ymd-His') . '.log';
 | 
					                self::$logFile = realpath(getcwd() . '/.mage/logs') . '/log-' . date('Ymd-His') . '.log';
 | 
				
			||||||
                self::$log = fopen(self::$logFile, 'w');
 | 
					                self::$log = fopen(self::$logFile, 'w');
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -230,7 +230,7 @@ class Console
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public static function getOutput()
 | 
					    public static function getOutput()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	return self::$screenBuffer;
 | 
					        return self::$screenBuffer;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -239,7 +239,7 @@ class Console
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public static function getLogFile()
 | 
					    public static function getLogFile()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	return self::$logFile;
 | 
					        return self::$logFile;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -247,7 +247,7 @@ class Console
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public static function readInput()
 | 
					    public static function readInput()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $fp = fopen("php://stdin","r");
 | 
					        $fp = fopen("php://stdin", "r");
 | 
				
			||||||
        $line = '';
 | 
					        $line = '';
 | 
				
			||||||
        $line = fgets($fp);
 | 
					        $line = fgets($fp);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -261,22 +261,22 @@ class Console
 | 
				
			|||||||
    private static function checkLogs(Config $config)
 | 
					    private static function checkLogs(Config $config)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (self::$logEnabled) {
 | 
					        if (self::$logEnabled) {
 | 
				
			||||||
        	$maxLogs = $config->general('maxlogs', 30);
 | 
					            $maxLogs = $config->general('maxlogs', 30);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        	$logs = array();
 | 
					            $logs = array();
 | 
				
			||||||
        	foreach (new RecursiveDirectoryIterator(getcwd() . '/.mage/logs', RecursiveDirectoryIterator::SKIP_DOTS) as $log) {
 | 
					            foreach (new RecursiveDirectoryIterator(getcwd() . '/.mage/logs', RecursiveDirectoryIterator::SKIP_DOTS) as $log) {
 | 
				
			||||||
        		if (strpos($log->getFilename(), 'log-') === 0) {
 | 
					                if (strpos($log->getFilename(), 'log-') === 0) {
 | 
				
			||||||
        			$logs[] = $log->getFilename();
 | 
					                    $logs[] = $log->getFilename();
 | 
				
			||||||
        		}
 | 
					                }
 | 
				
			||||||
        	}
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        	sort($logs);
 | 
					            sort($logs);
 | 
				
			||||||
        	if (count($logs) > $maxLogs) {
 | 
					            if (count($logs) > $maxLogs) {
 | 
				
			||||||
                $logsToDelete = array_slice($logs, 0, count($logs) - $maxLogs);
 | 
					                $logsToDelete = array_slice($logs, 0, count($logs) - $maxLogs);
 | 
				
			||||||
                foreach ($logsToDelete as $logToDeelte) {
 | 
					                foreach ($logsToDelete as $logToDeelte) {
 | 
				
			||||||
                	unlink(getcwd() . '/.mage/logs/' . $logToDeelte);
 | 
					                    unlink(getcwd() . '/.mage/logs/' . $logToDeelte);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
        	}
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -19,27 +19,27 @@ use Mage\Config;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class Colors
 | 
					class Colors
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * List of Colors and they Terminal/Console representation.
 | 
					     * List of Colors and they Terminal/Console representation.
 | 
				
			||||||
	 * @var array
 | 
					     * @var array
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    private static $foregroundColors = array(
 | 
					    private static $foregroundColors = array(
 | 
				
			||||||
        'black'        => '0;30',
 | 
					        'black' => '0;30',
 | 
				
			||||||
        'dark_gray'    => '1;30',
 | 
					        'dark_gray' => '1;30',
 | 
				
			||||||
        'blue'         => '0;34',
 | 
					        'blue' => '0;34',
 | 
				
			||||||
        'light_blue'   => '1;34',
 | 
					        'light_blue' => '1;34',
 | 
				
			||||||
        'green'        => '0;32',
 | 
					        'green' => '0;32',
 | 
				
			||||||
        'light_green'  => '1;32',
 | 
					        'light_green' => '1;32',
 | 
				
			||||||
        'cyan'         => '0;36',
 | 
					        'cyan' => '0;36',
 | 
				
			||||||
        'light_cyan'   => '1;36',
 | 
					        'light_cyan' => '1;36',
 | 
				
			||||||
        'red'          => '0;31',
 | 
					        'red' => '0;31',
 | 
				
			||||||
        'light_red'    => '1;31',
 | 
					        'light_red' => '1;31',
 | 
				
			||||||
        'purple'       => '0;35',
 | 
					        'purple' => '0;35',
 | 
				
			||||||
        'light_purple' => '1;35',
 | 
					        'light_purple' => '1;35',
 | 
				
			||||||
        'brown'        => '0;33',
 | 
					        'brown' => '0;33',
 | 
				
			||||||
        'yellow'       => '1;33',
 | 
					        'yellow' => '1;33',
 | 
				
			||||||
        'light_gray'   => '0;37',
 | 
					        'light_gray' => '0;37',
 | 
				
			||||||
        'white'        => '1;37'
 | 
					        'white' => '1;37'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -52,17 +52,17 @@ class Colors
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public static function color($string, Config $config)
 | 
					    public static function color($string, Config $config)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	$disabled = $config->getParameter('no-color', !$config->general('colors', true));
 | 
					        $disabled = $config->getParameter('no-color', !$config->general('colors', true));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    	if ($disabled) {
 | 
					        if ($disabled) {
 | 
				
			||||||
    		$string = strip_tags($string);
 | 
					            $string = strip_tags($string);
 | 
				
			||||||
    		return $string;
 | 
					            return $string;
 | 
				
			||||||
    	}
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        foreach (self::$foregroundColors as $key => $code) {
 | 
					        foreach (self::$foregroundColors as $key => $code) {
 | 
				
			||||||
            $replaceFrom = array(
 | 
					            $replaceFrom = array(
 | 
				
			||||||
                '<' . $key . '>',
 | 
					                '<' . $key . '>',
 | 
				
			||||||
            	'</' . $key . '>'
 | 
					                '</' . $key . '>'
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $replaceTo = array(
 | 
					            $replaceTo = array(
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										108
									
								
								Mage/Mailer.php
									
									
									
									
									
								
							
							
						
						
									
										108
									
								
								Mage/Mailer.php
									
									
									
									
									
								
							@ -18,74 +18,72 @@ namespace Mage;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class Mailer
 | 
					class Mailer
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	const EOL = "\r\n";
 | 
					    const EOL = "\r\n";
 | 
				
			||||||
	const SUBJECT = '[Magallanes] Deployment of {project} to {environment}: {result}';
 | 
					    const SUBJECT = '[Magallanes] Deployment of {project} to {environment}: {result}';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	protected $address;
 | 
					    protected $address;
 | 
				
			||||||
	protected $project;
 | 
					    protected $project;
 | 
				
			||||||
	protected $environment;
 | 
					    protected $environment;
 | 
				
			||||||
	protected $logFile;
 | 
					    protected $logFile;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function setAddress($address)
 | 
					    public function setAddress($address)
 | 
				
			||||||
	{
 | 
					    {
 | 
				
			||||||
        $this->address = $address;
 | 
					        $this->address = $address;
 | 
				
			||||||
        return $this;
 | 
					        return $this;
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function setProject($project)
 | 
					    public function setProject($project)
 | 
				
			||||||
	{
 | 
					    {
 | 
				
			||||||
		$this->project = $project;
 | 
					        $this->project = $project;
 | 
				
			||||||
		return $this;
 | 
					        return $this;
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function setEnvironment($environment)
 | 
					    public function setEnvironment($environment)
 | 
				
			||||||
	{
 | 
					    {
 | 
				
			||||||
		$this->environment = $environment;
 | 
					        $this->environment = $environment;
 | 
				
			||||||
		return $this;
 | 
					        return $this;
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	public function setLogFile($logFile)
 | 
					    public function setLogFile($logFile)
 | 
				
			||||||
	{
 | 
					    {
 | 
				
			||||||
		$this->logFile = $logFile;
 | 
					        $this->logFile = $logFile;
 | 
				
			||||||
		return $this;
 | 
					        return $this;
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public function send($result)
 | 
					    public function send($result)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	$boundary = md5(date('r', time()));
 | 
					        $boundary = md5(date('r', time()));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    	$headers = 'From: ' . $this->address
 | 
					        $headers = 'From: ' . $this->address
 | 
				
			||||||
    			 . self::EOL
 | 
					            . self::EOL
 | 
				
			||||||
    			 . 'Reply-To: ' . $this->address
 | 
					            . 'Reply-To: ' . $this->address
 | 
				
			||||||
    			 . self::EOL
 | 
					            . self::EOL
 | 
				
			||||||
    			 . 'MIME-Version: 1.0'
 | 
					            . 'MIME-Version: 1.0'
 | 
				
			||||||
		 		 . self::EOL
 | 
					            . self::EOL
 | 
				
			||||||
    	         . 'Content-Type: multipart/mixed; boundary=Mage-mixed-' . $boundary;
 | 
					            . 'Content-Type: multipart/mixed; boundary=Mage-mixed-' . $boundary;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    	$subject = str_replace(
 | 
					        $subject = str_replace(
 | 
				
			||||||
			array('{project}', '{environment}', '{result}'),
 | 
					            array('{project}', '{environment}', '{result}'),
 | 
				
			||||||
			array($this->project, $this->environment, $result ? 'SUCCESS' : 'FAILURE'),
 | 
					            array($this->project, $this->environment, $result ? 'SUCCESS' : 'FAILURE'),
 | 
				
			||||||
			self::SUBJECT
 | 
					            self::SUBJECT
 | 
				
			||||||
		)
 | 
					        );
 | 
				
			||||||
    	;
 | 
					        $attachment = chunk_split(base64_encode(file_get_contents($this->logFile)));
 | 
				
			||||||
    	$attachment = chunk_split(base64_encode(file_get_contents($this->logFile)));
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    	$message = 'This is a multi-part message in MIME format.' . self::EOL
 | 
					        $message = 'This is a multi-part message in MIME format.' . self::EOL
 | 
				
			||||||
    	         . '--Mage-mixed-' . $boundary . self::EOL
 | 
					            . '--Mage-mixed-' . $boundary . self::EOL
 | 
				
			||||||
    	         . 'Content-Type: text/plain; charset=iso-8859-1' . self::EOL
 | 
					            . 'Content-Type: text/plain; charset=iso-8859-1' . self::EOL
 | 
				
			||||||
    	         . 'Content-Transfer-Encoding: quoted-printable' . self::EOL
 | 
					            . 'Content-Transfer-Encoding: quoted-printable' . self::EOL
 | 
				
			||||||
    	         . self::EOL
 | 
					            . self::EOL
 | 
				
			||||||
    	         . strip_tags(Console::getOutput()) . self::EOL
 | 
					            . strip_tags(Console::getOutput()) . self::EOL
 | 
				
			||||||
    	         . self::EOL
 | 
					            . self::EOL
 | 
				
			||||||
    	         . '--Mage-mixed-' . $boundary . self::EOL
 | 
					            . '--Mage-mixed-' . $boundary . self::EOL
 | 
				
			||||||
    	         . 'Content-Type: text/plain; name="log.txt"' . self::EOL
 | 
					            . 'Content-Type: text/plain; name="log.txt"' . self::EOL
 | 
				
			||||||
    	         . 'Content-Transfer-Encoding: base64' . self::EOL
 | 
					            . 'Content-Transfer-Encoding: base64' . self::EOL
 | 
				
			||||||
    	         . 'Content-Disposition: attachment' . self::EOL
 | 
					            . 'Content-Disposition: attachment' . self::EOL
 | 
				
			||||||
    	         . self::EOL
 | 
					            . self::EOL
 | 
				
			||||||
    	         . $attachment . self::EOL
 | 
					            . $attachment . self::EOL
 | 
				
			||||||
    	         . '--Mage-mixed-' . $boundary . '--' . self::EOL
 | 
					            . '--Mage-mixed-' . $boundary . '--' . self::EOL;
 | 
				
			||||||
    	         ;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    	@mail($this->address, $subject, $message, $headers);
 | 
					        @mail($this->address, $subject, $message, $headers);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -23,287 +23,287 @@ use Exception;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
abstract class AbstractTask
 | 
					abstract class AbstractTask
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Stage Constant for Pre Deployment
 | 
					     * Stage Constant for Pre Deployment
 | 
				
			||||||
	 * @var string
 | 
					     * @var string
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	const STAGE_PRE_DEPLOY = 'pre-deploy';
 | 
					    const STAGE_PRE_DEPLOY = 'pre-deploy';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Stage Constant for Deployment
 | 
					     * Stage Constant for Deployment
 | 
				
			||||||
	 * @var string
 | 
					     * @var string
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	const STAGE_DEPLOY = 'deploy';
 | 
					    const STAGE_DEPLOY = 'deploy';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Stage Constant for Post Deployment
 | 
					     * Stage Constant for Post Deployment
 | 
				
			||||||
	 * @var string
 | 
					     * @var string
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	const STAGE_POST_DEPLOY = 'post-deploy';
 | 
					    const STAGE_POST_DEPLOY = 'post-deploy';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Stage Constant for Post Release
 | 
					     * Stage Constant for Post Release
 | 
				
			||||||
	 * @var string
 | 
					     * @var string
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	const STAGE_POST_RELEASE = 'post-release';
 | 
					    const STAGE_POST_RELEASE = 'post-release';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Configuration
 | 
					     * Configuration
 | 
				
			||||||
	 * @var Config;
 | 
					     * @var Config;
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	protected $config = null;
 | 
					    protected $config = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Indicates if the Task is running in a Rollback
 | 
					     * Indicates if the Task is running in a Rollback
 | 
				
			||||||
	 * @var boolean
 | 
					     * @var boolean
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	protected $inRollback = false;
 | 
					    protected $inRollback = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Indicates the Stage the Task is running ing
 | 
					     * Indicates the Stage the Task is running ing
 | 
				
			||||||
	 * @var string
 | 
					     * @var string
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	protected $stage = null;
 | 
					    protected $stage = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Extra parameters
 | 
					     * Extra parameters
 | 
				
			||||||
	 * @var array
 | 
					     * @var array
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	protected $parameters = array();
 | 
					    protected $parameters = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Returns the Title of the Task
 | 
					     * Returns the Title of the Task
 | 
				
			||||||
	 * @return string
 | 
					     * @return string
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	public abstract function getName();
 | 
					    public abstract function getName();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Runs the task
 | 
					     * Runs the task
 | 
				
			||||||
	 *
 | 
					     *
 | 
				
			||||||
	 * @return boolean
 | 
					     * @return boolean
 | 
				
			||||||
	 * @throws Exception
 | 
					     * @throws Exception
 | 
				
			||||||
	 * @throws ErrorWithMessageException
 | 
					     * @throws ErrorWithMessageException
 | 
				
			||||||
	 * @throws SkipException
 | 
					     * @throws SkipException
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	public abstract function run();
 | 
					    public abstract function run();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Task Constructor
 | 
					     * Task Constructor
 | 
				
			||||||
	 *
 | 
					     *
 | 
				
			||||||
	 * @param Config $config
 | 
					     * @param Config $config
 | 
				
			||||||
	 * @param boolean $inRollback
 | 
					     * @param boolean $inRollback
 | 
				
			||||||
	 * @param string $stage
 | 
					     * @param string $stage
 | 
				
			||||||
	 * @param array $parameters
 | 
					     * @param array $parameters
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	public final function __construct(Config $config, $inRollback = false, $stage = null, $parameters = array())
 | 
					    public final function __construct(Config $config, $inRollback = false, $stage = null, $parameters = array())
 | 
				
			||||||
	{
 | 
					    {
 | 
				
			||||||
		$this->config     = $config;
 | 
					        $this->config = $config;
 | 
				
			||||||
		$this->inRollback = $inRollback;
 | 
					        $this->inRollback = $inRollback;
 | 
				
			||||||
		$this->stage      = $stage;
 | 
					        $this->stage = $stage;
 | 
				
			||||||
		$this->parameters = $parameters;
 | 
					        $this->parameters = $parameters;
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Indicates if the Task is running in a Rollback operation
 | 
					     * Indicates if the Task is running in a Rollback operation
 | 
				
			||||||
	 * @return boolean
 | 
					     * @return boolean
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	public function inRollback()
 | 
					    public function inRollback()
 | 
				
			||||||
	{
 | 
					    {
 | 
				
			||||||
		return $this->inRollback;
 | 
					        return $this->inRollback;
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Gets the Stage of the Deployment:
 | 
					     * Gets the Stage of the Deployment:
 | 
				
			||||||
	 *     - pre-deploy
 | 
					     *     - pre-deploy
 | 
				
			||||||
	 *     - deploy
 | 
					     *     - deploy
 | 
				
			||||||
	 *     - post-deploy
 | 
					     *     - post-deploy
 | 
				
			||||||
	 *     - post-release
 | 
					     *     - post-release
 | 
				
			||||||
	 * @return string
 | 
					     * @return string
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	public function getStage()
 | 
					    public function getStage()
 | 
				
			||||||
	{
 | 
					    {
 | 
				
			||||||
		return $this->stage;
 | 
					        return $this->stage;
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Gets the Configuration
 | 
					     * Gets the Configuration
 | 
				
			||||||
	 * @return Config;
 | 
					     * @return Config;
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	public function getConfig()
 | 
					    public function getConfig()
 | 
				
			||||||
	{
 | 
					    {
 | 
				
			||||||
		return $this->config;
 | 
					        return $this->config;
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Initializes the Task, optional to implement
 | 
					     * Initializes the Task, optional to implement
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	public function init()
 | 
					    public function init()
 | 
				
			||||||
	{
 | 
					    {
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Returns a Parameter, or a default if not found
 | 
					     * Returns a Parameter, or a default if not found
 | 
				
			||||||
	 *
 | 
					     *
 | 
				
			||||||
	 * @param string $name
 | 
					     * @param string $name
 | 
				
			||||||
	 * @param mixed $default
 | 
					     * @param mixed $default
 | 
				
			||||||
	 * @return mixed
 | 
					     * @return mixed
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	public function getParameter($name, $default = null)
 | 
					    public function getParameter($name, $default = null)
 | 
				
			||||||
	{
 | 
					    {
 | 
				
			||||||
		return $this->getConfig()->getParameter($name, $default, $this->getParameters());
 | 
					        return $this->getConfig()->getParameter($name, $default, $this->getParameters());
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * @return array
 | 
					     * @return array
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	protected function getParameters()
 | 
					    protected function getParameters()
 | 
				
			||||||
	{
 | 
					    {
 | 
				
			||||||
		return $this->parameters;
 | 
					        return $this->parameters;
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Runs a Shell Command Localy
 | 
					     * Runs a Shell Command Localy
 | 
				
			||||||
	 * @param string $command
 | 
					     * @param string $command
 | 
				
			||||||
	 * @param string $output
 | 
					     * @param string $output
 | 
				
			||||||
	 * @return boolean
 | 
					     * @return boolean
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	protected final function runCommandLocal($command, &$output = null)
 | 
					    protected final function runCommandLocal($command, &$output = null)
 | 
				
			||||||
	{
 | 
					    {
 | 
				
			||||||
		return Console::executeCommand($command, $output);
 | 
					        return Console::executeCommand($command, $output);
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Runs a Shell Command on the Remote Host
 | 
					     * Runs a Shell Command on the Remote Host
 | 
				
			||||||
	 * @param string $command
 | 
					     * @param string $command
 | 
				
			||||||
	 * @param string $output
 | 
					     * @param string $output
 | 
				
			||||||
	 * @param boolean $cdToDirectoryFirst
 | 
					     * @param boolean $cdToDirectoryFirst
 | 
				
			||||||
	 * @return boolean
 | 
					     * @return boolean
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	protected final function runCommandRemote($command, &$output = null, $cdToDirectoryFirst = true)
 | 
					    protected final function runCommandRemote($command, &$output = null, $cdToDirectoryFirst = true)
 | 
				
			||||||
	{
 | 
					    {
 | 
				
			||||||
		if ($this->getConfig()->release('enabled', false) == true) {
 | 
					        if ($this->getConfig()->release('enabled', false) == true) {
 | 
				
			||||||
			if ($this instanceOf IsReleaseAware) {
 | 
					            if ($this instanceOf IsReleaseAware) {
 | 
				
			||||||
				$releasesDirectory = '';
 | 
					                $releasesDirectory = '';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			} else {
 | 
					            } else {
 | 
				
			||||||
				$releasesDirectory = '/'
 | 
					                $releasesDirectory = '/'
 | 
				
			||||||
					. $this->getConfig()->release('directory', 'releases')
 | 
					                    . $this->getConfig()->release('directory', 'releases')
 | 
				
			||||||
					. '/'
 | 
					                    . '/'
 | 
				
			||||||
					. $this->getConfig()->getReleaseId();
 | 
					                    . $this->getConfig()->getReleaseId();
 | 
				
			||||||
			}
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		} else {
 | 
					        } else {
 | 
				
			||||||
			$releasesDirectory = '';
 | 
					            $releasesDirectory = '';
 | 
				
			||||||
		}
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// if general.yml includes "ssy_needs_tty: true", then add "-t" to the ssh command
 | 
					        // if general.yml includes "ssy_needs_tty: true", then add "-t" to the ssh command
 | 
				
			||||||
		$needs_tty = ($this->getConfig()->general('ssh_needs_tty',false) ? '-t' : '');
 | 
					        $needs_tty = ($this->getConfig()->general('ssh_needs_tty', false) ? '-t' : '');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$localCommand = 'ssh ' . $this->getConfig()->getHostIdentityFileOption() . $needs_tty . ' -p ' . $this->getConfig()->getHostPort() . ' '
 | 
					        $localCommand = 'ssh ' . $this->getConfig()->getHostIdentityFileOption() . $needs_tty . ' -p ' . $this->getConfig()->getHostPort() . ' '
 | 
				
			||||||
			. '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no '
 | 
					            . '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no '
 | 
				
			||||||
			. $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName();
 | 
					            . $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$remoteCommand = str_replace('"', '\"', $command);
 | 
					        $remoteCommand = str_replace('"', '\"', $command);
 | 
				
			||||||
		if($cdToDirectoryFirst){
 | 
					        if ($cdToDirectoryFirst) {
 | 
				
			||||||
			$remoteCommand = 'cd ' . rtrim($this->getConfig()->deployment('to'), '/') . $releasesDirectory . ' && ' . $remoteCommand;
 | 
					            $remoteCommand = 'cd ' . rtrim($this->getConfig()->deployment('to'), '/') . $releasesDirectory . ' && ' . $remoteCommand;
 | 
				
			||||||
		}
 | 
					        }
 | 
				
			||||||
		$localCommand .= ' ' . '"sh -c \"' .  $remoteCommand . '\""';
 | 
					        $localCommand .= ' ' . '"sh -c \"' . $remoteCommand . '\""';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Console::log('Run remote command ' . $remoteCommand);
 | 
					        Console::log('Run remote command ' . $remoteCommand);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return $this->runCommandLocal($localCommand, $output);
 | 
					        return $this->runCommandLocal($localCommand, $output);
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Runs a Shell Command Localy or in the Remote Host based on the Task Stage.
 | 
					     * Runs a Shell Command Localy or in the Remote Host based on the Task Stage.
 | 
				
			||||||
	 * If the stage is "deploy" then it will be executed in the remote host.
 | 
					     * If the stage is "deploy" then it will be executed in the remote host.
 | 
				
			||||||
	 * @param string $command
 | 
					     * @param string $command
 | 
				
			||||||
	 * @param string $output
 | 
					     * @param string $output
 | 
				
			||||||
	 * @return boolean
 | 
					     * @return boolean
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	protected final function runCommand($command, &$output = null)
 | 
					    protected final function runCommand($command, &$output = null)
 | 
				
			||||||
	{
 | 
					    {
 | 
				
			||||||
		if ($this->getStage() == self::STAGE_DEPLOY) {
 | 
					        if ($this->getStage() == self::STAGE_DEPLOY) {
 | 
				
			||||||
			return $this->runCommandRemote($command, $output);
 | 
					            return $this->runCommandRemote($command, $output);
 | 
				
			||||||
		} else {
 | 
					        } else {
 | 
				
			||||||
			return $this->runCommandLocal($command, $output);
 | 
					            return $this->runCommandLocal($command, $output);
 | 
				
			||||||
		}
 | 
					        }
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * adds a cd to the needed release if we work with releases.
 | 
					     * adds a cd to the needed release if we work with releases.
 | 
				
			||||||
	 *
 | 
					     *
 | 
				
			||||||
	 * @param string $command
 | 
					     * @param string $command
 | 
				
			||||||
	 * @return string
 | 
					     * @return string
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	protected function getReleasesAwareCommand($command)
 | 
					    protected function getReleasesAwareCommand($command)
 | 
				
			||||||
	{
 | 
					    {
 | 
				
			||||||
		if ($this->getConfig()->release('enabled', false) == true) {
 | 
					        if ($this->getConfig()->release('enabled', false) == true) {
 | 
				
			||||||
			$releasesDirectory = $this->getConfig()->release('directory', 'releases');
 | 
					            $releasesDirectory = $this->getConfig()->release('directory', 'releases');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			$deployToDirectory = $releasesDirectory . '/' . $this->getConfig()->getReleaseId();
 | 
					            $deployToDirectory = $releasesDirectory . '/' . $this->getConfig()->getReleaseId();
 | 
				
			||||||
			return 'cd ' . $deployToDirectory . ' && ' . $command;
 | 
					            return 'cd ' . $deployToDirectory . ' && ' . $command;
 | 
				
			||||||
		}
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return $command;
 | 
					        return $command;
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * @param integer $releaseId
 | 
					     * @param integer $releaseId
 | 
				
			||||||
     * @return bool
 | 
					     * @return bool
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
	protected function tarRelease($releaseId)
 | 
					    protected function tarRelease($releaseId)
 | 
				
			||||||
	{
 | 
					    {
 | 
				
			||||||
		$result = true;
 | 
					        $result = true;
 | 
				
			||||||
		// for given release, check if tarred
 | 
					        // for given release, check if tarred
 | 
				
			||||||
		$output = '';
 | 
					        $output = '';
 | 
				
			||||||
		$releasesDirectory = $this->getConfig()->release('directory', 'releases');
 | 
					        $releasesDirectory = $this->getConfig()->release('directory', 'releases');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$currentReleaseDirectory = $releasesDirectory . '/' . $releaseId;
 | 
					        $currentReleaseDirectory = $releasesDirectory . '/' . $releaseId;
 | 
				
			||||||
		$currentReleaseDirectoryTemp = $currentReleaseDirectory . '_tmp/';
 | 
					        $currentReleaseDirectoryTemp = $currentReleaseDirectory . '_tmp/';
 | 
				
			||||||
		$currentRelease = $currentReleaseDirectory . '/' . $releaseId . '.tar.gz';
 | 
					        $currentRelease = $currentReleaseDirectory . '/' . $releaseId . '.tar.gz';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$command = 'test -e ' . $currentRelease . ' && echo "true" || echo ""';
 | 
					        $command = 'test -e ' . $currentRelease . ' && echo "true" || echo ""';
 | 
				
			||||||
		$this->runCommandRemote($command, $output);
 | 
					        $this->runCommandRemote($command, $output);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// if not, do so
 | 
					        // if not, do so
 | 
				
			||||||
		if (!$output) {
 | 
					        if (!$output) {
 | 
				
			||||||
			$commands = array();
 | 
					            $commands = array();
 | 
				
			||||||
			$commands[] = 'mv ' . $currentReleaseDirectory . ' ' . $currentReleaseDirectoryTemp;
 | 
					            $commands[] = 'mv ' . $currentReleaseDirectory . ' ' . $currentReleaseDirectoryTemp;
 | 
				
			||||||
			$commands[] = 'mkdir ' . $currentReleaseDirectory;
 | 
					            $commands[] = 'mkdir ' . $currentReleaseDirectory;
 | 
				
			||||||
			$commands[] = 'tar cfz ' . $currentRelease . ' ' . $currentReleaseDirectoryTemp;
 | 
					            $commands[] = 'tar cfz ' . $currentRelease . ' ' . $currentReleaseDirectoryTemp;
 | 
				
			||||||
			$commands[] = 'rm -rf ' . $currentReleaseDirectoryTemp;
 | 
					            $commands[] = 'rm -rf ' . $currentReleaseDirectoryTemp;
 | 
				
			||||||
			$command = implode(' && ', $commands);
 | 
					            $command = implode(' && ', $commands);
 | 
				
			||||||
			$result = $this->runCommandRemote($command, $output);
 | 
					            $result = $this->runCommandRemote($command, $output);
 | 
				
			||||||
			return $result;
 | 
					            return $result;
 | 
				
			||||||
		}
 | 
					        }
 | 
				
			||||||
		return $result;
 | 
					        return $result;
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	protected function untarRelease($releaseId)
 | 
					    protected function untarRelease($releaseId)
 | 
				
			||||||
	{
 | 
					    {
 | 
				
			||||||
		$result = true;
 | 
					        $result = true;
 | 
				
			||||||
		// for given release, check if tarred
 | 
					        // for given release, check if tarred
 | 
				
			||||||
		$output = '';
 | 
					        $output = '';
 | 
				
			||||||
		$releasesDirectory = $this->getConfig()->release('directory', 'releases');
 | 
					        $releasesDirectory = $this->getConfig()->release('directory', 'releases');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$currentReleaseDirectory = $releasesDirectory . '/' . $releaseId;
 | 
					        $currentReleaseDirectory = $releasesDirectory . '/' . $releaseId;
 | 
				
			||||||
		$currentReleaseDirectoryTemp = $currentReleaseDirectory . '_tmp/';
 | 
					        $currentReleaseDirectoryTemp = $currentReleaseDirectory . '_tmp/';
 | 
				
			||||||
		$currentRelease = $currentReleaseDirectory . '/' . $releaseId . '.tar.gz';
 | 
					        $currentRelease = $currentReleaseDirectory . '/' . $releaseId . '.tar.gz';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		$command = 'test -e ' . $currentRelease . ' && echo "true" || echo ""';
 | 
					        $command = 'test -e ' . $currentRelease . ' && echo "true" || echo ""';
 | 
				
			||||||
		$this->runCommandRemote($command, $output);
 | 
					        $this->runCommandRemote($command, $output);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// if tarred, untar now
 | 
					        // if tarred, untar now
 | 
				
			||||||
		if ($output) {
 | 
					        if ($output) {
 | 
				
			||||||
			$commands = array();
 | 
					            $commands = array();
 | 
				
			||||||
			$commands[] = 'tar xfz ' . $currentRelease;
 | 
					            $commands[] = 'tar xfz ' . $currentRelease;
 | 
				
			||||||
			$commands[] = 'rm -rf ' . $currentReleaseDirectory;
 | 
					            $commands[] = 'rm -rf ' . $currentReleaseDirectory;
 | 
				
			||||||
			$commands[] = 'mv ' .$currentReleaseDirectoryTemp . ' ' . $currentReleaseDirectory;
 | 
					            $commands[] = 'mv ' . $currentReleaseDirectoryTemp . ' ' . $currentReleaseDirectory;
 | 
				
			||||||
			$command = implode(' && ', $commands);
 | 
					            $command = implode(' && ', $commands);
 | 
				
			||||||
			$result = $this->runCommandRemote($command, $output);
 | 
					            $result = $this->runCommandRemote($command, $output);
 | 
				
			||||||
			return $result;
 | 
					            return $result;
 | 
				
			||||||
		}
 | 
					        }
 | 
				
			||||||
		return $result;
 | 
					        return $result;
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -21,86 +21,86 @@ use Mage\Task\Releases\SkipOnOverride;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride
 | 
					class ReleaseTask extends AbstractTask implements IsReleaseAware, SkipOnOverride
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * (non-PHPdoc)
 | 
					     * (non-PHPdoc)
 | 
				
			||||||
	 * @see \Mage\Task\AbstractTask::getName()
 | 
					     * @see \Mage\Task\AbstractTask::getName()
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	public function getName()
 | 
					    public function getName()
 | 
				
			||||||
	{
 | 
					    {
 | 
				
			||||||
		return 'Releasing [built-in]';
 | 
					        return 'Releasing [built-in]';
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Releases a Deployment: points the current symbolic link to the release directory
 | 
					     * Releases a Deployment: points the current symbolic link to the release directory
 | 
				
			||||||
	 * @see \Mage\Task\AbstractTask::run()
 | 
					     * @see \Mage\Task\AbstractTask::run()
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	public function run()
 | 
					    public function run()
 | 
				
			||||||
	{
 | 
					    {
 | 
				
			||||||
		if ($this->getConfig()->release('enabled', false) == true) {
 | 
					        if ($this->getConfig()->release('enabled', false) == true) {
 | 
				
			||||||
			$releasesDirectory = $this->getConfig()->release('directory', 'releases');
 | 
					            $releasesDirectory = $this->getConfig()->release('directory', 'releases');
 | 
				
			||||||
			$symlink = $this->getConfig()->release('symlink', 'current');
 | 
					            $symlink = $this->getConfig()->release('symlink', 'current');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (substr($symlink, 0, 1) == '/') {
 | 
					            if (substr($symlink, 0, 1) == '/') {
 | 
				
			||||||
				$releasesDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory;
 | 
					                $releasesDirectory = rtrim($this->getConfig()->deployment('to'), '/') . '/' . $releasesDirectory;
 | 
				
			||||||
			}
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			$releaseId = $this->getConfig()->getReleaseId();
 | 
					            $releaseId = $this->getConfig()->getReleaseId();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if ($this->getConfig()->release('compressreleases', false) == true) {
 | 
					            if ($this->getConfig()->release('compressreleases', false) == true) {
 | 
				
			||||||
				// Tar.gz releases
 | 
					                // Tar.gz releases
 | 
				
			||||||
				$result = $this->tarReleases() && $result;
 | 
					                $result = $this->tarReleases() && $result;
 | 
				
			||||||
				// Untar new release
 | 
					                // Untar new release
 | 
				
			||||||
				$result = $this->untarRelease($releaseId) && $result;
 | 
					                $result = $this->untarRelease($releaseId) && $result;
 | 
				
			||||||
			}
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			$currentCopy = $releasesDirectory . '/' . $releaseId;
 | 
					            $currentCopy = $releasesDirectory . '/' . $releaseId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			//Check if target user:group is specified
 | 
					            //Check if target user:group is specified
 | 
				
			||||||
			$userGroup = $this->getConfig()->deployment('owner');
 | 
					            $userGroup = $this->getConfig()->deployment('owner');
 | 
				
			||||||
			// Fetch the user and group from base directory; defaults usergroup to 33:33
 | 
					            // Fetch the user and group from base directory; defaults usergroup to 33:33
 | 
				
			||||||
			if(empty($userGroup)){
 | 
					            if (empty($userGroup)) {
 | 
				
			||||||
				$user = '33';
 | 
					                $user = '33';
 | 
				
			||||||
				$group = '33';
 | 
					                $group = '33';
 | 
				
			||||||
				$directoryInfos = '';
 | 
					                $directoryInfos = '';
 | 
				
			||||||
				// Get raw directory info and parse it in php.
 | 
					                // Get raw directory info and parse it in php.
 | 
				
			||||||
				// "stat" command don't behave the same on different systems, ls output format also varies
 | 
					                // "stat" command don't behave the same on different systems, ls output format also varies
 | 
				
			||||||
				// and awk parameters need special care depending on the executing shell
 | 
					                // and awk parameters need special care depending on the executing shell
 | 
				
			||||||
				$resultFetch = $this->runCommandRemote("ls -ld .", $directoryInfos);
 | 
					                $resultFetch = $this->runCommandRemote("ls -ld .", $directoryInfos);
 | 
				
			||||||
				if(!empty($directoryInfos)){
 | 
					                if (!empty($directoryInfos)) {
 | 
				
			||||||
					//uniformize format as it depends on the system deployed on
 | 
					                    //uniformize format as it depends on the system deployed on
 | 
				
			||||||
					$directoryInfos = trim(str_replace(array("  ", "\t"), ' ', $directoryInfos));
 | 
					                    $directoryInfos = trim(str_replace(array("  ", "\t"), ' ', $directoryInfos));
 | 
				
			||||||
					$infoArray = explode(' ', $directoryInfos);
 | 
					                    $infoArray = explode(' ', $directoryInfos);
 | 
				
			||||||
					if(!empty($infoArray[2])) {
 | 
					                    if (!empty($infoArray[2])) {
 | 
				
			||||||
						$user = $infoArray[2];
 | 
					                        $user = $infoArray[2];
 | 
				
			||||||
					}
 | 
					                    }
 | 
				
			||||||
					if(!empty($infoArray[3])) {
 | 
					                    if (!empty($infoArray[3])) {
 | 
				
			||||||
						$group = $infoArray[3];
 | 
					                        $group = $infoArray[3];
 | 
				
			||||||
					}
 | 
					                    }
 | 
				
			||||||
					$userGroup = $user . ':' . $group;
 | 
					                    $userGroup = $user . ':' . $group;
 | 
				
			||||||
				}
 | 
					                }
 | 
				
			||||||
			}
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			// Remove symlink if exists; create new symlink and change owners
 | 
					            // Remove symlink if exists; create new symlink and change owners
 | 
				
			||||||
			$command = 'rm -f ' . $symlink
 | 
					            $command = 'rm -f ' . $symlink
 | 
				
			||||||
				. ' ; '
 | 
					                . ' ; '
 | 
				
			||||||
				. 'ln -sf ' . $currentCopy . ' ' . $symlink;
 | 
					                . 'ln -sf ' . $currentCopy . ' ' . $symlink;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if ($resultFetch && $userGroup != '') {
 | 
					            if ($resultFetch && $userGroup != '') {
 | 
				
			||||||
				$command .= ' && '
 | 
					                $command .= ' && '
 | 
				
			||||||
					. 'chown -h ' . $userGroup . ' ' . $symlink
 | 
					                    . 'chown -h ' . $userGroup . ' ' . $symlink
 | 
				
			||||||
					. ' && '
 | 
					                    . ' && '
 | 
				
			||||||
					. 'chown -R ' . $userGroup . ' ' . $currentCopy
 | 
					                    . 'chown -R ' . $userGroup . ' ' . $currentCopy
 | 
				
			||||||
					. ' && '
 | 
					                    . ' && '
 | 
				
			||||||
					. 'chown ' . $userGroup . ' ' . $releasesDirectory;
 | 
					                    . 'chown ' . $userGroup . ' ' . $releasesDirectory;
 | 
				
			||||||
			}
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			$result = $this->runCommandRemote($command);
 | 
					            $result = $this->runCommandRemote($command);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			return $result;
 | 
					            return $result;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		} else {
 | 
					        } else {
 | 
				
			||||||
			return false;
 | 
					            return false;
 | 
				
			||||||
		}
 | 
					        }
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -32,7 +32,7 @@ abstract class BaseStrategyTaskAbstract extends AbstractTask implements IsReleas
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        if ($overrideRelease == true) {
 | 
					        if ($overrideRelease == true) {
 | 
				
			||||||
            $releaseToOverride = false;
 | 
					            $releaseToOverride = false;
 | 
				
			||||||
            $resultFetch = $this->runCommandRemote('ls -ld '.$symlink.' | cut -d"/" -f2', $releaseToOverride);
 | 
					            $resultFetch = $this->runCommandRemote('ls -ld ' . $symlink . ' | cut -d"/" -f2', $releaseToOverride);
 | 
				
			||||||
            if ($resultFetch && is_numeric($releaseToOverride)) {
 | 
					            if ($resultFetch && is_numeric($releaseToOverride)) {
 | 
				
			||||||
                $this->getConfig()->setReleaseId($releaseToOverride);
 | 
					                $this->getConfig()->setReleaseId($releaseToOverride);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
				
			|||||||
@ -21,10 +21,10 @@ use Mage\Task\SkipException;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class DisabledTask extends AbstractTask implements IsReleaseAware
 | 
					class DisabledTask extends AbstractTask implements IsReleaseAware
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * (non-PHPdoc)
 | 
					     * (non-PHPdoc)
 | 
				
			||||||
	 * @see \Mage\Task\AbstractTask::getName()
 | 
					     * @see \Mage\Task\AbstractTask::getName()
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    public function getName()
 | 
					    public function getName()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return 'Disabled Deployment [built-in]';
 | 
					        return 'Disabled Deployment [built-in]';
 | 
				
			||||||
 | 
				
			|||||||
@ -44,8 +44,8 @@ class GitRebaseTask extends BaseStrategyTaskAbstract implements IsReleaseAware
 | 
				
			|||||||
            $releasesDirectory = $this->getConfig()->release('directory', 'releases');
 | 
					            $releasesDirectory = $this->getConfig()->release('directory', 'releases');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $deployToDirectory = rtrim($this->getConfig()->deployment('to'), '/')
 | 
					            $deployToDirectory = rtrim($this->getConfig()->deployment('to'), '/')
 | 
				
			||||||
                               . '/' . $releasesDirectory
 | 
					                . '/' . $releasesDirectory
 | 
				
			||||||
                               . '/' . $this->getConfig()->getReleaseId();
 | 
					                . '/' . $this->getConfig()->getReleaseId();
 | 
				
			||||||
            $this->runCommandRemote('mkdir -p ' . $releasesDirectory . '/' . $this->getConfig()->getReleaseId());
 | 
					            $this->runCommandRemote('mkdir -p ' . $releasesDirectory . '/' . $this->getConfig()->getReleaseId());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -78,11 +78,11 @@ class GitRebaseTask extends BaseStrategyTaskAbstract implements IsReleaseAware
 | 
				
			|||||||
        $result = $this->runCommandRemote($command) && $result;
 | 
					        $result = $this->runCommandRemote($command) && $result;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Stash if Working Copy is not clean
 | 
					        // Stash if Working Copy is not clean
 | 
				
			||||||
        if(!$status) {
 | 
					        if (!$status) {
 | 
				
			||||||
            $stashResult = '';
 | 
					            $stashResult = '';
 | 
				
			||||||
            $command = $this->getReleasesAwareCommand('git stash');
 | 
					            $command = $this->getReleasesAwareCommand('git stash');
 | 
				
			||||||
            $result = $this->runCommandRemote($command, $stashResult) && $result;
 | 
					            $result = $this->runCommandRemote($command, $stashResult) && $result;
 | 
				
			||||||
            if($stashResult != "No local changes to save") {
 | 
					            if ($stashResult != "No local changes to save") {
 | 
				
			||||||
                $stashed = true;
 | 
					                $stashed = true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
@ -21,10 +21,10 @@ use Mage\Task\Releases\IsReleaseAware;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class RsyncTask extends BaseStrategyTaskAbstract implements IsReleaseAware
 | 
					class RsyncTask extends BaseStrategyTaskAbstract implements IsReleaseAware
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * (non-PHPdoc)
 | 
					     * (non-PHPdoc)
 | 
				
			||||||
	 * @see \Mage\Task\AbstractTask::getName()
 | 
					     * @see \Mage\Task\AbstractTask::getName()
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    public function getName()
 | 
					    public function getName()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if ($this->getConfig()->release('enabled', false) == true) {
 | 
					        if ($this->getConfig()->release('enabled', false) == true) {
 | 
				
			||||||
@ -32,14 +32,14 @@ class RsyncTask extends BaseStrategyTaskAbstract implements IsReleaseAware
 | 
				
			|||||||
                return 'Deploy via Rsync (with Releases override) [built-in]';
 | 
					                return 'Deploy via Rsync (with Releases override) [built-in]';
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                $rsync_copy = $this->getConfig()->deployment("rsync");
 | 
					                $rsync_copy = $this->getConfig()->deployment("rsync");
 | 
				
			||||||
                if ( $rsync_copy && is_array($rsync_copy) && $rsync_copy['copy'] ) {
 | 
					                if ($rsync_copy && is_array($rsync_copy) && $rsync_copy['copy']) {
 | 
				
			||||||
                    return 'Deploy via Rsync (with Releases) [built-in, incremental]';
 | 
					                    return 'Deploy via Rsync (with Releases) [built-in, incremental]';
 | 
				
			||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
                    return 'Deploy via Rsync (with Releases) [built-in]';
 | 
					                    return 'Deploy via Rsync (with Releases) [built-in]';
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
                return 'Deploy via Rsync [built-in]';
 | 
					            return 'Deploy via Rsync [built-in]';
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -61,8 +61,8 @@ class RsyncTask extends BaseStrategyTaskAbstract implements IsReleaseAware
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            $currentRelease = false;
 | 
					            $currentRelease = false;
 | 
				
			||||||
            $deployToDirectory = rtrim($this->getConfig()->deployment('to'), '/')
 | 
					            $deployToDirectory = rtrim($this->getConfig()->deployment('to'), '/')
 | 
				
			||||||
                               . '/' . $releasesDirectory
 | 
					                . '/' . $releasesDirectory
 | 
				
			||||||
                               . '/' . $this->getConfig()->getReleaseId();
 | 
					                . '/' . $this->getConfig()->getReleaseId();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            Console::log('Deploy to ' . $deployToDirectory);
 | 
					            Console::log('Deploy to ' . $deployToDirectory);
 | 
				
			||||||
            $resultFetch = $this->runCommandRemote('ls -ld ' . $symlink . ' | cut -d"/" -f2', $currentRelease);
 | 
					            $resultFetch = $this->runCommandRemote('ls -ld ' . $symlink . ' | cut -d"/" -f2', $currentRelease);
 | 
				
			||||||
@ -72,10 +72,10 @@ class RsyncTask extends BaseStrategyTaskAbstract implements IsReleaseAware
 | 
				
			|||||||
                // rsync: { copy: yes }
 | 
					                // rsync: { copy: yes }
 | 
				
			||||||
                $rsync_copy = $this->getConfig()->deployment('rsync');
 | 
					                $rsync_copy = $this->getConfig()->deployment('rsync');
 | 
				
			||||||
                // If copy_tool_rsync, use rsync rather than cp for finer control of what is copied
 | 
					                // If copy_tool_rsync, use rsync rather than cp for finer control of what is copied
 | 
				
			||||||
                if ( $rsync_copy && is_array($rsync_copy) && $rsync_copy['copy'] && isset($rsync_copy['copy_tool_rsync']) ) {
 | 
					                if ($rsync_copy && is_array($rsync_copy) && $rsync_copy['copy'] && isset($rsync_copy['copy_tool_rsync'])) {
 | 
				
			||||||
                    $this->runCommandRemote("rsync -a {$this->excludes(array_merge($excludes, $rsync_copy['rsync_excludes']))} "
 | 
					                    $this->runCommandRemote("rsync -a {$this->excludes(array_merge($excludes, $rsync_copy['rsync_excludes']))} "
 | 
				
			||||||
                    . "$releasesDirectory/$currentRelease/ $releasesDirectory/{$this->getConfig()->getReleaseId()}");
 | 
					                        . "$releasesDirectory/$currentRelease/ $releasesDirectory/{$this->getConfig()->getReleaseId()}");
 | 
				
			||||||
                } elseif ( $rsync_copy && is_array($rsync_copy) && $rsync_copy['copy'] ) {
 | 
					                } elseif ($rsync_copy && is_array($rsync_copy) && $rsync_copy['copy']) {
 | 
				
			||||||
                    $this->runCommandRemote('cp -R ' . $releasesDirectory . '/' . $currentRelease . ' ' . $releasesDirectory . '/' . $this->getConfig()->getReleaseId());
 | 
					                    $this->runCommandRemote('cp -R ' . $releasesDirectory . '/' . $currentRelease . ' ' . $releasesDirectory . '/' . $this->getConfig()->getReleaseId());
 | 
				
			||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
                    $this->runCommandRemote('mkdir -p ' . $releasesDirectory . '/' . $this->getConfig()->getReleaseId());
 | 
					                    $this->runCommandRemote('mkdir -p ' . $releasesDirectory . '/' . $this->getConfig()->getReleaseId());
 | 
				
			||||||
@ -84,10 +84,10 @@ class RsyncTask extends BaseStrategyTaskAbstract implements IsReleaseAware
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $command = 'rsync -avz '
 | 
					        $command = 'rsync -avz '
 | 
				
			||||||
                 . '--rsh="ssh ' . $this->getConfig()->getHostIdentityFileOption() . '-p' . $this->getConfig()->getHostPort() . '" '
 | 
					            . '--rsh="ssh ' . $this->getConfig()->getHostIdentityFileOption() . '-p' . $this->getConfig()->getHostPort() . '" '
 | 
				
			||||||
                 . $this->excludes($excludes) . ' '
 | 
					            . $this->excludes($excludes) . ' '
 | 
				
			||||||
                 . $this->getConfig()->deployment('from') . ' '
 | 
					            . $this->getConfig()->deployment('from') . ' '
 | 
				
			||||||
                 . $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName() . ':' . $deployToDirectory;
 | 
					            . $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName() . ':' . $deployToDirectory;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $result = $this->runCommandLocal($command);
 | 
					        $result = $this->runCommandLocal($command);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -21,10 +21,10 @@ use Mage\Task\Releases\IsReleaseAware;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware
 | 
					class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * (non-PHPdoc)
 | 
					     * (non-PHPdoc)
 | 
				
			||||||
	 * @see \Mage\Task\AbstractTask::getName()
 | 
					     * @see \Mage\Task\AbstractTask::getName()
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    public function getName()
 | 
					    public function getName()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if ($this->getConfig()->release('enabled', false) == true) {
 | 
					        if ($this->getConfig()->release('enabled', false) == true) {
 | 
				
			||||||
@ -34,7 +34,7 @@ class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware
 | 
				
			|||||||
                return 'Deploy via TarGz (with Releases) [built-in]';
 | 
					                return 'Deploy via TarGz (with Releases) [built-in]';
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
                return 'Deploy via TarGz [built-in]';
 | 
					            return 'Deploy via TarGz [built-in]';
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -53,10 +53,10 @@ class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware
 | 
				
			|||||||
        if ($this->getConfig()->release('enabled', false) == true) {
 | 
					        if ($this->getConfig()->release('enabled', false) == true) {
 | 
				
			||||||
            $releasesDirectory = $this->getConfig()->release('directory', 'releases');
 | 
					            $releasesDirectory = $this->getConfig()->release('directory', 'releases');
 | 
				
			||||||
            $deployToDirectory = rtrim($this->getConfig()->deployment('to'), '/')
 | 
					            $deployToDirectory = rtrim($this->getConfig()->deployment('to'), '/')
 | 
				
			||||||
                               . '/' . $releasesDirectory
 | 
					                . '/' . $releasesDirectory
 | 
				
			||||||
                               . '/' . $this->getConfig()->getReleaseId();
 | 
					                . '/' . $this->getConfig()->getReleaseId();
 | 
				
			||||||
            $output = null;
 | 
					            $output = null;
 | 
				
			||||||
            $this->runCommandRemote('mkdir -p ' . $deployToDirectory, $output , false);
 | 
					            $this->runCommandRemote('mkdir -p ' . $deployToDirectory, $output, false);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Create Tar Gz
 | 
					        // Create Tar Gz
 | 
				
			||||||
@ -68,19 +68,19 @@ class TarGzTask extends BaseStrategyTaskAbstract implements IsReleaseAware
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $command = 'tar cfz ' . $localTarGz . '.tar.gz ' . $excludeCmd . ' -C ' . $this->getConfig()->deployment('from') . ' .';
 | 
					        $command = 'tar cfz ' . $localTarGz . '.tar.gz ' . $excludeCmd . ' -C ' . $this->getConfig()->deployment('from') . ' .';
 | 
				
			||||||
		$result = $this->runCommandLocal($command);
 | 
					        $result = $this->runCommandLocal($command);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Copy Tar Gz  to Remote Host
 | 
					        // Copy Tar Gz  to Remote Host
 | 
				
			||||||
		$command = 'scp ' . $this->getConfig()->getHostIdentityFileOption() . '-P ' . $this->getConfig()->getHostPort() . ' ' . $localTarGz . '.tar.gz '
 | 
					        $command = 'scp ' . $this->getConfig()->getHostIdentityFileOption() . '-P ' . $this->getConfig()->getHostPort() . ' ' . $localTarGz . '.tar.gz '
 | 
				
			||||||
                 . $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName() . ':' . $deployToDirectory;
 | 
					            . $this->getConfig()->deployment('user') . '@' . $this->getConfig()->getHostName() . ':' . $deployToDirectory;
 | 
				
			||||||
		$result = $this->runCommandLocal($command) && $result;
 | 
					        $result = $this->runCommandLocal($command) && $result;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Extract Tar Gz
 | 
					        // Extract Tar Gz
 | 
				
			||||||
		$command = $this->getReleasesAwareCommand('tar xfz ' . $remoteTarGz . '.tar.gz');
 | 
					        $command = $this->getReleasesAwareCommand('tar xfz ' . $remoteTarGz . '.tar.gz');
 | 
				
			||||||
        $result = $this->runCommandRemote($command) && $result;
 | 
					        $result = $this->runCommandRemote($command) && $result;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Delete Tar Gz from Remote Host
 | 
					        // Delete Tar Gz from Remote Host
 | 
				
			||||||
		$command = $this->getReleasesAwareCommand('rm ' . $remoteTarGz . '.tar.gz');
 | 
					        $command = $this->getReleasesAwareCommand('rm ' . $remoteTarGz . '.tar.gz');
 | 
				
			||||||
        $result = $this->runCommandRemote($command) && $result;
 | 
					        $result = $this->runCommandRemote($command) && $result;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Delete Tar Gz from Local
 | 
					        // Delete Tar Gz from Local
 | 
				
			||||||
 | 
				
			|||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@ -19,10 +19,10 @@ use Mage\Task\AbstractTask;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class ClearCacheTask extends AbstractTask
 | 
					class ClearCacheTask extends AbstractTask
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * (non-PHPdoc)
 | 
					     * (non-PHPdoc)
 | 
				
			||||||
	 * @see \Mage\Task\AbstractTask::getName()
 | 
					     * @see \Mage\Task\AbstractTask::getName()
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    public function getName()
 | 
					    public function getName()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return 'Magento - Clean Cache [built-in]';
 | 
					        return 'Magento - Clean Cache [built-in]';
 | 
				
			||||||
 | 
				
			|||||||
@ -19,10 +19,10 @@ use Mage\Task\AbstractTask;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class ClearFullPageCacheTask extends AbstractTask
 | 
					class ClearFullPageCacheTask extends AbstractTask
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * (non-PHPdoc)
 | 
					     * (non-PHPdoc)
 | 
				
			||||||
	 * @see \Mage\Task\AbstractTask::getName()
 | 
					     * @see \Mage\Task\AbstractTask::getName()
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    public function getName()
 | 
					    public function getName()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return 'Magento - Clean Full Page Cache [built-in]';
 | 
					        return 'Magento - Clean Full Page Cache [built-in]';
 | 
				
			||||||
 | 
				
			|||||||
@ -54,22 +54,22 @@ class ListTask extends AbstractTask implements IsReleaseAware
 | 
				
			|||||||
                Console::output('<dark_gray>No releases available</dark_gray> ... ', 2);
 | 
					                Console::output('<dark_gray>No releases available</dark_gray> ... ', 2);
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                rsort($releases);
 | 
					                rsort($releases);
 | 
				
			||||||
                $releases  = array_slice($releases, 0, 10);
 | 
					                $releases = array_slice($releases, 0, 10);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                foreach ($releases as $releaseIndex => $release) {
 | 
					                foreach ($releases as $releaseIndex => $release) {
 | 
				
			||||||
                    $release = trim($release);
 | 
					                    $release = trim($release);
 | 
				
			||||||
                    $releaseIndex = str_pad($releaseIndex * -1, 2, ' ', STR_PAD_LEFT);
 | 
					                    $releaseIndex = str_pad($releaseIndex * -1, 2, ' ', STR_PAD_LEFT);
 | 
				
			||||||
                    $releaseDate = $release[0] . $release[1] . $release[2] .$release[3]
 | 
					                    $releaseDate = $release[0] . $release[1] . $release[2] . $release[3]
 | 
				
			||||||
                                 . '-'
 | 
					                        . '-'
 | 
				
			||||||
                                 . $release[4] . $release[5]
 | 
					                        . $release[4] . $release[5]
 | 
				
			||||||
                                 . '-'
 | 
					                        . '-'
 | 
				
			||||||
                                 . $release[6] . $release[7]
 | 
					                        . $release[6] . $release[7]
 | 
				
			||||||
                                 . ' '
 | 
					                        . ' '
 | 
				
			||||||
                                 . $release[8] . $release[9]
 | 
					                        . $release[8] . $release[9]
 | 
				
			||||||
                                 . ':'
 | 
					                        . ':'
 | 
				
			||||||
                                 . $release[10] . $release[11]
 | 
					                        . $release[10] . $release[11]
 | 
				
			||||||
                                 . ':'
 | 
					                        . ':'
 | 
				
			||||||
                                 . $release[12] . $release[13];
 | 
					                        . $release[12] . $release[13];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    $isCurrent = '';
 | 
					                    $isCurrent = '';
 | 
				
			||||||
                    if ($currentRelease == $release) {
 | 
					                    if ($currentRelease == $release) {
 | 
				
			||||||
@ -80,8 +80,8 @@ class ListTask extends AbstractTask implements IsReleaseAware
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                    Console::output(
 | 
					                    Console::output(
 | 
				
			||||||
                        'Release: <purple>' . $release . '</purple> '
 | 
					                        'Release: <purple>' . $release . '</purple> '
 | 
				
			||||||
                      . '- Date: <dark_gray>' . $releaseDate . '</dark_gray> '
 | 
					                        . '- Date: <dark_gray>' . $releaseDate . '</dark_gray> '
 | 
				
			||||||
                      . '- Index: <dark_gray>' . $releaseIndex . '</dark_gray>' . $dateDiff . $isCurrent, 2);
 | 
					                        . '- Index: <dark_gray>' . $releaseIndex . '</dark_gray>' . $dateDiff . $isCurrent, 2);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -23,179 +23,179 @@ use Mage\Task\Releases\RollbackAware;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class RollbackTask extends AbstractTask implements IsReleaseAware
 | 
					class RollbackTask extends AbstractTask implements IsReleaseAware
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * The Relase ID to Rollback To
 | 
					     * The Relase ID to Rollback To
 | 
				
			||||||
	 * @var integer
 | 
					     * @var integer
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	protected $release = null;
 | 
					    protected $release = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * (non-PHPdoc)
 | 
					     * (non-PHPdoc)
 | 
				
			||||||
	 * @see \Mage\Task\AbstractTask::getName()
 | 
					     * @see \Mage\Task\AbstractTask::getName()
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	public function getName()
 | 
					    public function getName()
 | 
				
			||||||
	{
 | 
					    {
 | 
				
			||||||
		return 'Rollback release [built-in]';
 | 
					        return 'Rollback release [built-in]';
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Sets the Release ID to Rollback To
 | 
					     * Sets the Release ID to Rollback To
 | 
				
			||||||
	 * @param integer $releaseId
 | 
					     * @param integer $releaseId
 | 
				
			||||||
	 * @return \Mage\Task\BuiltIn\Releases\RollbackTask
 | 
					     * @return \Mage\Task\BuiltIn\Releases\RollbackTask
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	public function setRelease($releaseId)
 | 
					    public function setRelease($releaseId)
 | 
				
			||||||
	{
 | 
					    {
 | 
				
			||||||
		$this->release = $releaseId;
 | 
					        $this->release = $releaseId;
 | 
				
			||||||
		return $this;
 | 
					        return $this;
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Gets the Release ID to Rollback To
 | 
					     * Gets the Release ID to Rollback To
 | 
				
			||||||
	 * @return integer
 | 
					     * @return integer
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	public function getRelease()
 | 
					    public function getRelease()
 | 
				
			||||||
	{
 | 
					    {
 | 
				
			||||||
		return $this->release;
 | 
					        return $this->release;
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Performs a Rollback Operation
 | 
					     * Performs a Rollback Operation
 | 
				
			||||||
	 * @see \Mage\Task\AbstractTask::run()
 | 
					     * @see \Mage\Task\AbstractTask::run()
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	public function run()
 | 
					    public function run()
 | 
				
			||||||
	{
 | 
					    {
 | 
				
			||||||
		if ($this->getConfig()->release('enabled', false) == true) {
 | 
					        if ($this->getConfig()->release('enabled', false) == true) {
 | 
				
			||||||
			$releasesDirectory = $this->getConfig()->release('directory', 'releases');
 | 
					            $releasesDirectory = $this->getConfig()->release('directory', 'releases');
 | 
				
			||||||
			$symlink = $this->getConfig()->release('symlink', 'current');
 | 
					            $symlink = $this->getConfig()->release('symlink', 'current');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			$output = '';
 | 
					            $output = '';
 | 
				
			||||||
			$result = $this->runCommandRemote('ls -1 ' . $releasesDirectory, $output);
 | 
					            $result = $this->runCommandRemote('ls -1 ' . $releasesDirectory, $output);
 | 
				
			||||||
			$releases = ($output == '') ? array() : explode(PHP_EOL, $output);
 | 
					            $releases = ($output == '') ? array() : explode(PHP_EOL, $output);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if (count($releases) == 0) {
 | 
					            if (count($releases) == 0) {
 | 
				
			||||||
				Console::output('Release are not available for <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray> ... <red>FAIL</red>');
 | 
					                Console::output('Release are not available for <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray> ... <red>FAIL</red>');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			} else {
 | 
					            } else {
 | 
				
			||||||
				rsort($releases);
 | 
					                rsort($releases);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				$releaseIsAvailable = false;
 | 
					                $releaseIsAvailable = false;
 | 
				
			||||||
				if ($this->getRelease() == '') {
 | 
					                if ($this->getRelease() == '') {
 | 
				
			||||||
					$releaseId = $releases[0];
 | 
					                    $releaseId = $releases[0];
 | 
				
			||||||
					$releaseIsAvailable = true;
 | 
					                    $releaseIsAvailable = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				} else if ($this->getRelease() <= 0) {
 | 
					                } else if ($this->getRelease() <= 0) {
 | 
				
			||||||
					$index = $this->getRelease() * -1;
 | 
					                    $index = $this->getRelease() * -1;
 | 
				
			||||||
					if (isset($releases[$index])) {
 | 
					                    if (isset($releases[$index])) {
 | 
				
			||||||
						$releaseId = $releases[$index];
 | 
					                        $releaseId = $releases[$index];
 | 
				
			||||||
						$releaseIsAvailable = true;
 | 
					                        $releaseIsAvailable = true;
 | 
				
			||||||
					}
 | 
					                    }
 | 
				
			||||||
				} else {
 | 
					                } else {
 | 
				
			||||||
					if (in_array($this->getRelease(), $releases)) {
 | 
					                    if (in_array($this->getRelease(), $releases)) {
 | 
				
			||||||
						$releaseId = $this->getRelease();
 | 
					                        $releaseId = $this->getRelease();
 | 
				
			||||||
						$releaseIsAvailable = true;
 | 
					                        $releaseIsAvailable = true;
 | 
				
			||||||
					}
 | 
					                    }
 | 
				
			||||||
				}
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if (!$releaseIsAvailable) {
 | 
					                if (!$releaseIsAvailable) {
 | 
				
			||||||
					Console::output('Release <dark_gray>' . $this->getRelease() . '</dark_gray> is invalid or unavailable for <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray> ... <red>FAIL</red>');
 | 
					                    Console::output('Release <dark_gray>' . $this->getRelease() . '</dark_gray> is invalid or unavailable for <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray> ... <red>FAIL</red>');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				} else {
 | 
					                } else {
 | 
				
			||||||
					Console::output('Rollback release on <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray>');
 | 
					                    Console::output('Rollback release on <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray>');
 | 
				
			||||||
					$rollbackTo = $releasesDirectory . '/' . $releaseId;
 | 
					                    $rollbackTo = $releasesDirectory . '/' . $releaseId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					// Tasks
 | 
					                    // Tasks
 | 
				
			||||||
					$tasks = 1;
 | 
					                    $tasks = 1;
 | 
				
			||||||
					$completedTasks = 0;
 | 
					                    $completedTasks = 0;
 | 
				
			||||||
					$tasksToRun = $this->getConfig()->getTasks();
 | 
					                    $tasksToRun = $this->getConfig()->getTasks();
 | 
				
			||||||
					$this->getConfig()->setReleaseId($releaseId);
 | 
					                    $this->getConfig()->setReleaseId($releaseId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					// Run Deploy Tasks
 | 
					                    // Run Deploy Tasks
 | 
				
			||||||
					foreach ($tasksToRun as $taskData) {
 | 
					                    foreach ($tasksToRun as $taskData) {
 | 
				
			||||||
						$task = Factory::get($taskData, $this->getConfig(), true, self::STAGE_DEPLOY);
 | 
					                        $task = Factory::get($taskData, $this->getConfig(), true, self::STAGE_DEPLOY);
 | 
				
			||||||
						$task->init();
 | 
					                        $task->init();
 | 
				
			||||||
						Console::output('Running <purple>' . $task->getName() . '</purple> ... ', 2, false);
 | 
					                        Console::output('Running <purple>' . $task->getName() . '</purple> ... ', 2, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
						if ($task instanceOf RollbackAware) {
 | 
					                        if ($task instanceOf RollbackAware) {
 | 
				
			||||||
							$tasks++;
 | 
					                            $tasks++;
 | 
				
			||||||
							$result = $task->run();
 | 
					                            $result = $task->run();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							if ($result == true) {
 | 
					                            if ($result == true) {
 | 
				
			||||||
								Console::output('<green>OK</green>', 0);
 | 
					                                Console::output('<green>OK</green>', 0);
 | 
				
			||||||
								$completedTasks++;
 | 
					                                $completedTasks++;
 | 
				
			||||||
							} else {
 | 
					                            } else {
 | 
				
			||||||
								Console::output('<red>FAIL</red>', 0);
 | 
					                                Console::output('<red>FAIL</red>', 0);
 | 
				
			||||||
							}
 | 
					                            }
 | 
				
			||||||
						} else {
 | 
					                        } else {
 | 
				
			||||||
							Console::output('<yellow>SKIPPED</yellow>', 0);
 | 
					                            Console::output('<yellow>SKIPPED</yellow>', 0);
 | 
				
			||||||
						}
 | 
					                        }
 | 
				
			||||||
					}
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					if ($this->getConfig()->release('compressreleases', false) == true) {
 | 
					                    if ($this->getConfig()->release('compressreleases', false) == true) {
 | 
				
			||||||
						// Tar the current
 | 
					                        // Tar the current
 | 
				
			||||||
						$result = $this->tarReleases() && $result;
 | 
					                        $result = $this->tarReleases() && $result;
 | 
				
			||||||
						// Untar the rollbackto
 | 
					                        // Untar the rollbackto
 | 
				
			||||||
						$result = $this->untarRelease($releaseId) && $result;
 | 
					                        $result = $this->untarRelease($releaseId) && $result;
 | 
				
			||||||
					}
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					// Changing Release
 | 
					                    // Changing Release
 | 
				
			||||||
					Console::output('Running <purple>Rollback Release [id=' . $releaseId . ']</purple> ... ', 2, false);
 | 
					                    Console::output('Running <purple>Rollback Release [id=' . $releaseId . ']</purple> ... ', 2, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					$userGroup = '';
 | 
					                    $userGroup = '';
 | 
				
			||||||
					$resultFetch = $this->runCommandRemote('ls -ld ' . $rollbackTo . ' | awk \'{print \$3":"\$4}\'', $userGroup);
 | 
					                    $resultFetch = $this->runCommandRemote('ls -ld ' . $rollbackTo . ' | awk \'{print \$3":"\$4}\'', $userGroup);
 | 
				
			||||||
					$command = 'rm -f ' . $symlink
 | 
					                    $command = 'rm -f ' . $symlink
 | 
				
			||||||
						. ' && '
 | 
					                        . ' && '
 | 
				
			||||||
						. 'ln -sf ' . $rollbackTo . ' ' . $symlink;
 | 
					                        . 'ln -sf ' . $rollbackTo . ' ' . $symlink;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					if ($resultFetch) {
 | 
					                    if ($resultFetch) {
 | 
				
			||||||
						$command .= ' && chown -h ' . $userGroup . ' ' . $symlink;
 | 
					                        $command .= ' && chown -h ' . $userGroup . ' ' . $symlink;
 | 
				
			||||||
					}
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					$result = $this->runCommandRemote($command);
 | 
					                    $result = $this->runCommandRemote($command);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					if ($result) {
 | 
					                    if ($result) {
 | 
				
			||||||
						Console::output('<green>OK</green>', 0);
 | 
					                        Console::output('<green>OK</green>', 0);
 | 
				
			||||||
						$completedTasks++;
 | 
					                        $completedTasks++;
 | 
				
			||||||
					} else {
 | 
					                    } else {
 | 
				
			||||||
						Console::output('<red>FAIL</red>', 0);
 | 
					                        Console::output('<red>FAIL</red>', 0);
 | 
				
			||||||
					}
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					// Run Post Release Tasks
 | 
					                    // Run Post Release Tasks
 | 
				
			||||||
					$tasksToRun = $this->getConfig()->getTasks(AbstractTask::STAGE_POST_DEPLOY);
 | 
					                    $tasksToRun = $this->getConfig()->getTasks(AbstractTask::STAGE_POST_DEPLOY);
 | 
				
			||||||
					foreach ($tasksToRun as $taskData) {
 | 
					                    foreach ($tasksToRun as $taskData) {
 | 
				
			||||||
						$task = Factory::get($taskData, $this->getConfig(), true, self::STAGE_POST_DEPLOY);
 | 
					                        $task = Factory::get($taskData, $this->getConfig(), true, self::STAGE_POST_DEPLOY);
 | 
				
			||||||
						$task->init();
 | 
					                        $task->init();
 | 
				
			||||||
						Console::output('Running <purple>' . $task->getName() . '</purple> ... ', 2, false);
 | 
					                        Console::output('Running <purple>' . $task->getName() . '</purple> ... ', 2, false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
						if ($task instanceOf RollbackAware) {
 | 
					                        if ($task instanceOf RollbackAware) {
 | 
				
			||||||
							$tasks++;
 | 
					                            $tasks++;
 | 
				
			||||||
							$result = $task->run();
 | 
					                            $result = $task->run();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							if ($result == true) {
 | 
					                            if ($result == true) {
 | 
				
			||||||
								Console::output('<green>OK</green>', 0);
 | 
					                                Console::output('<green>OK</green>', 0);
 | 
				
			||||||
								$completedTasks++;
 | 
					                                $completedTasks++;
 | 
				
			||||||
							} else {
 | 
					                            } else {
 | 
				
			||||||
								Console::output('<red>FAIL</red>', 0);
 | 
					                                Console::output('<red>FAIL</red>', 0);
 | 
				
			||||||
							}
 | 
					                            }
 | 
				
			||||||
						} else {
 | 
					                        } else {
 | 
				
			||||||
							Console::output('<yellow>SKIPPED</yellow>', 0);
 | 
					                            Console::output('<yellow>SKIPPED</yellow>', 0);
 | 
				
			||||||
						}
 | 
					                        }
 | 
				
			||||||
					}
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					if ($completedTasks == $tasks) {
 | 
					                    if ($completedTasks == $tasks) {
 | 
				
			||||||
						$tasksColor = 'green';
 | 
					                        $tasksColor = 'green';
 | 
				
			||||||
					} else {
 | 
					                    } else {
 | 
				
			||||||
						$tasksColor = 'red';
 | 
					                        $tasksColor = 'red';
 | 
				
			||||||
					}
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
					Console::output('Release rollback on <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray> compted: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
 | 
					                    Console::output('Release rollback on <dark_gray>' . $this->getConfig()->getHost() . '</dark_gray> compted: <' . $tasksColor . '>' . $completedTasks . '/' . $tasks . '</' . $tasksColor . '> tasks done.', 1, 3);
 | 
				
			||||||
				}
 | 
					                }
 | 
				
			||||||
			}
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			return $result;
 | 
					            return $result;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		} else {
 | 
					        } else {
 | 
				
			||||||
			return false;
 | 
					            return false;
 | 
				
			||||||
		}
 | 
					        }
 | 
				
			||||||
	}
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -21,16 +21,16 @@ use Mage\Task\ErrorWithMessageException;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class ChangeBranchTask extends AbstractTask
 | 
					class ChangeBranchTask extends AbstractTask
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Branch the executiong began with
 | 
					     * Branch the executiong began with
 | 
				
			||||||
	 * @var string
 | 
					     * @var string
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
	protected static $startingBranch = 'master';
 | 
					    protected static $startingBranch = 'master';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Name of the Task
 | 
					     * Name of the Task
 | 
				
			||||||
	 * @var string
 | 
					     * @var string
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    private $name = 'SCM Changing branch [built-in]';
 | 
					    private $name = 'SCM Changing branch [built-in]';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -48,7 +48,7 @@ class ChangeBranchTask extends AbstractTask
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function init()
 | 
					    public function init()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	$scmType = $this->getConfig()->general('scm');
 | 
					        $scmType = $this->getConfig()->general('scm');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        switch ($scmType) {
 | 
					        switch ($scmType) {
 | 
				
			||||||
            case 'git':
 | 
					            case 'git':
 | 
				
			||||||
@ -65,35 +65,35 @@ class ChangeBranchTask extends AbstractTask
 | 
				
			|||||||
    {
 | 
					    {
 | 
				
			||||||
        switch ($this->getConfig()->general('scm')) {
 | 
					        switch ($this->getConfig()->general('scm')) {
 | 
				
			||||||
            case 'git':
 | 
					            case 'git':
 | 
				
			||||||
            	if ($this->getParameter('_changeBranchRevert', false)) {
 | 
					                if ($this->getParameter('_changeBranchRevert', false)) {
 | 
				
			||||||
            		$command = 'git checkout ' . self::$startingBranch;
 | 
					                    $command = 'git checkout ' . self::$startingBranch;
 | 
				
			||||||
            		$result = $this->runCommandLocal($command);
 | 
					                    $result = $this->runCommandLocal($command);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            	} else {
 | 
					                } else {
 | 
				
			||||||
            		$command = 'git branch | grep \'*\' | cut -d\' \' -f 2';
 | 
					                    $command = 'git branch | grep \'*\' | cut -d\' \' -f 2';
 | 
				
			||||||
            		$currentBranch = 'master';
 | 
					                    $currentBranch = 'master';
 | 
				
			||||||
            		$result = $this->runCommandLocal($command, $currentBranch);
 | 
					                    $result = $this->runCommandLocal($command, $currentBranch);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            		$scmData = $this->getConfig()->deployment('scm', false);
 | 
					                    $scmData = $this->getConfig()->deployment('scm', false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            		if ($result && is_array($scmData) && isset($scmData['branch']) && $scmData['branch'] != $currentBranch) {
 | 
					                    if ($result && is_array($scmData) && isset($scmData['branch']) && $scmData['branch'] != $currentBranch) {
 | 
				
			||||||
        				$command = 'git branch | grep \'' . $scmData['branch'] . '\' | tr -s \' \' | sed \'s/^[ ]//g\'';
 | 
					                        $command = 'git branch | grep \'' . $scmData['branch'] . '\' | tr -s \' \' | sed \'s/^[ ]//g\'';
 | 
				
			||||||
        				$isBranchTracked = '';
 | 
					                        $isBranchTracked = '';
 | 
				
			||||||
        				$result = $this->runCommandLocal($command, $isBranchTracked);
 | 
					                        $result = $this->runCommandLocal($command, $isBranchTracked);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        				if ($isBranchTracked == '') {
 | 
					                        if ($isBranchTracked == '') {
 | 
				
			||||||
        					throw new ErrorWithMessageException('The branch <purple>' . $scmData['branch'] . '</purple> must be tracked.');
 | 
					                            throw new ErrorWithMessageException('The branch <purple>' . $scmData['branch'] . '</purple> must be tracked.');
 | 
				
			||||||
        				}
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        				$branch = $this->getParameter('branch', $scmData['branch']);
 | 
					                        $branch = $this->getParameter('branch', $scmData['branch']);
 | 
				
			||||||
        				$command = 'git checkout ' . $branch;
 | 
					                        $command = 'git checkout ' . $branch;
 | 
				
			||||||
        				$result = $this->runCommandLocal($command) && $result;
 | 
					                        $result = $this->runCommandLocal($command) && $result;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        				self::$startingBranch = $currentBranch;
 | 
					                        self::$startingBranch = $currentBranch;
 | 
				
			||||||
            		} else {
 | 
					                    } else {
 | 
				
			||||||
            			throw new SkipException;
 | 
					                        throw new SkipException;
 | 
				
			||||||
            		}
 | 
					                    }
 | 
				
			||||||
            	}
 | 
					                }
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            default:
 | 
					            default:
 | 
				
			||||||
 | 
				
			|||||||
@ -20,10 +20,10 @@ use Mage\Task\SkipException;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class CloneTask extends AbstractTask
 | 
					class CloneTask extends AbstractTask
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Name of the Task
 | 
					     * Name of the Task
 | 
				
			||||||
	 * @var string
 | 
					     * @var string
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    private $name = 'SCM Clone [built-in]';
 | 
					    private $name = 'SCM Clone [built-in]';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -66,12 +66,12 @@ class CloneTask extends AbstractTask
 | 
				
			|||||||
            case 'git':
 | 
					            case 'git':
 | 
				
			||||||
                // Clone Repo
 | 
					                // Clone Repo
 | 
				
			||||||
                $command = 'cd ' . $this->source['temporal'] . ' ; '
 | 
					                $command = 'cd ' . $this->source['temporal'] . ' ; '
 | 
				
			||||||
                         . 'git clone ' . $this->source['repository'] . ' . ';
 | 
					                    . 'git clone ' . $this->source['repository'] . ' . ';
 | 
				
			||||||
                $result = $this->runCommandLocal($command);
 | 
					                $result = $this->runCommandLocal($command);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                // Checkout Branch
 | 
					                // Checkout Branch
 | 
				
			||||||
                $command = 'cd ' . $this->source['temporal'] . ' ; '
 | 
					                $command = 'cd ' . $this->source['temporal'] . ' ; '
 | 
				
			||||||
                         . 'git checkout ' . $this->source['from'];
 | 
					                    . 'git checkout ' . $this->source['from'];
 | 
				
			||||||
                $result = $result && $this->runCommandLocal($command);
 | 
					                $result = $result && $this->runCommandLocal($command);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                $this->getConfig()->setFrom($this->source['temporal']);
 | 
					                $this->getConfig()->setFrom($this->source['temporal']);
 | 
				
			||||||
 | 
				
			|||||||
@ -19,10 +19,10 @@ use Mage\Task\AbstractTask;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class RemoveCloneTask extends AbstractTask
 | 
					class RemoveCloneTask extends AbstractTask
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Name of the Task
 | 
					     * Name of the Task
 | 
				
			||||||
	 * @var string
 | 
					     * @var string
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    private $name = 'SCM Remove Clone [built-in]';
 | 
					    private $name = 'SCM Remove Clone [built-in]';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -49,8 +49,8 @@ class RemoveCloneTask extends AbstractTask
 | 
				
			|||||||
        $this->source = $this->getConfig()->deployment('source');
 | 
					        $this->source = $this->getConfig()->deployment('source');
 | 
				
			||||||
        switch ($this->source['type']) {
 | 
					        switch ($this->source['type']) {
 | 
				
			||||||
            case 'git':
 | 
					            case 'git':
 | 
				
			||||||
            	$this->name = 'SCM Remove Clone (GIT) [built-in]';
 | 
					                $this->name = 'SCM Remove Clone (GIT) [built-in]';
 | 
				
			||||||
            	break;
 | 
					                break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -20,10 +20,10 @@ use Mage\Task\SkipException;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class UpdateTask extends AbstractTask
 | 
					class UpdateTask extends AbstractTask
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * Name of the Task
 | 
					     * Name of the Task
 | 
				
			||||||
	 * @var string
 | 
					     * @var string
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    private $name = 'SCM Update [built-in]';
 | 
					    private $name = 'SCM Update [built-in]';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 | 
				
			|||||||
@ -19,10 +19,10 @@ use Mage\Task\AbstractTask;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class AsseticDumpTask extends AbstractTask
 | 
					class AsseticDumpTask extends AbstractTask
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * (non-PHPdoc)
 | 
					     * (non-PHPdoc)
 | 
				
			||||||
	 * @see \Mage\Task\AbstractTask::getName()
 | 
					     * @see \Mage\Task\AbstractTask::getName()
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    public function getName()
 | 
					    public function getName()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return 'Symfony v2 - Assetic Dump [built-in]';
 | 
					        return 'Symfony v2 - Assetic Dump [built-in]';
 | 
				
			||||||
@ -34,8 +34,8 @@ class AsseticDumpTask extends AbstractTask
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function run()
 | 
					    public function run()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	// Options
 | 
					        // Options
 | 
				
			||||||
    	$env = $this->getParameter('env', 'dev');
 | 
					        $env = $this->getParameter('env', 'dev');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $command = 'app/console assetic:dump --env=' . $env;
 | 
					        $command = 'app/console assetic:dump --env=' . $env;
 | 
				
			||||||
        $result = $this->runCommand($command);
 | 
					        $result = $this->runCommand($command);
 | 
				
			||||||
 | 
				
			|||||||
@ -19,10 +19,10 @@ use Mage\Task\AbstractTask;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class AssetsInstallTask extends AbstractTask
 | 
					class AssetsInstallTask extends AbstractTask
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * (non-PHPdoc)
 | 
					     * (non-PHPdoc)
 | 
				
			||||||
	 * @see \Mage\Task\AbstractTask::getName()
 | 
					     * @see \Mage\Task\AbstractTask::getName()
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    public function getName()
 | 
					    public function getName()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return 'Symfony v2 - Assets Install [built-in]';
 | 
					        return 'Symfony v2 - Assets Install [built-in]';
 | 
				
			||||||
@ -34,17 +34,17 @@ class AssetsInstallTask extends AbstractTask
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function run()
 | 
					    public function run()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	// Options
 | 
					        // Options
 | 
				
			||||||
    	$target = $this->getParameter('target', 'web');
 | 
					        $target = $this->getParameter('target', 'web');
 | 
				
			||||||
    	$symlink = $this->getParameter('symlink', false);
 | 
					        $symlink = $this->getParameter('symlink', false);
 | 
				
			||||||
    	$relative = $this->getParameter('relative', false);
 | 
					        $relative = $this->getParameter('relative', false);
 | 
				
			||||||
    	$env = $this->getParameter('env', 'dev');
 | 
					        $env = $this->getParameter('env', 'dev');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    	if ($relative) {
 | 
					        if ($relative) {
 | 
				
			||||||
    		$symlink = true;
 | 
					            $symlink = true;
 | 
				
			||||||
    	}
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $command = 'app/console assets:install ' . ($symlink ? '--symlink' : '') .  ' ' . ($relative ? '--relative' : '') .  ' --env=' . $env . ' ' . $target;
 | 
					        $command = 'app/console assets:install ' . ($symlink ? '--symlink' : '') . ' ' . ($relative ? '--relative' : '') . ' --env=' . $env . ' ' . $target;
 | 
				
			||||||
        $result = $this->runCommand($command);
 | 
					        $result = $this->runCommand($command);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $result;
 | 
					        return $result;
 | 
				
			||||||
 | 
				
			|||||||
@ -19,10 +19,10 @@ use Mage\Task\AbstractTask;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class CacheClearTask extends AbstractTask
 | 
					class CacheClearTask extends AbstractTask
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * (non-PHPdoc)
 | 
					     * (non-PHPdoc)
 | 
				
			||||||
	 * @see \Mage\Task\AbstractTask::getName()
 | 
					     * @see \Mage\Task\AbstractTask::getName()
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    public function getName()
 | 
					    public function getName()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return 'Symfony v2 - Cache Clear [built-in]';
 | 
					        return 'Symfony v2 - Cache Clear [built-in]';
 | 
				
			||||||
@ -34,8 +34,8 @@ class CacheClearTask extends AbstractTask
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function run()
 | 
					    public function run()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	// Options
 | 
					        // Options
 | 
				
			||||||
    	$env = $this->getParameter('env', 'dev');
 | 
					        $env = $this->getParameter('env', 'dev');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $command = 'app/console cache:clear --env=' . $env;
 | 
					        $command = 'app/console cache:clear --env=' . $env;
 | 
				
			||||||
        $result = $this->runCommand($command);
 | 
					        $result = $this->runCommand($command);
 | 
				
			||||||
 | 
				
			|||||||
@ -19,10 +19,10 @@ use Mage\Task\AbstractTask;
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
class CacheWarmupTask extends AbstractTask
 | 
					class CacheWarmupTask extends AbstractTask
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	/**
 | 
					    /**
 | 
				
			||||||
	 * (non-PHPdoc)
 | 
					     * (non-PHPdoc)
 | 
				
			||||||
	 * @see \Mage\Task\AbstractTask::getName()
 | 
					     * @see \Mage\Task\AbstractTask::getName()
 | 
				
			||||||
	 */
 | 
					     */
 | 
				
			||||||
    public function getName()
 | 
					    public function getName()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return 'Symfony v2 - Cache Warmup [built-in]';
 | 
					        return 'Symfony v2 - Cache Warmup [built-in]';
 | 
				
			||||||
@ -34,8 +34,8 @@ class CacheWarmupTask extends AbstractTask
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public function run()
 | 
					    public function run()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
    	// Options
 | 
					        // Options
 | 
				
			||||||
    	$env = $this->getParameter('env', 'dev');
 | 
					        $env = $this->getParameter('env', 'dev');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $command = 'app/console cache:warmup --env=' . $env;
 | 
					        $command = 'app/console cache:warmup --env=' . $env;
 | 
				
			||||||
        $result = $this->runCommand($command);
 | 
					        $result = $this->runCommand($command);
 | 
				
			||||||
 | 
				
			|||||||
@ -56,8 +56,8 @@ class Factory
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        $instance = new $className($taskConfig, $inRollback, $stage, $taskParameters);
 | 
					        $instance = new $className($taskConfig, $inRollback, $stage, $taskParameters);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (!is_a($instance,'Mage\Task\AbstractTask')) {
 | 
					        if (!is_a($instance, 'Mage\Task\AbstractTask')) {
 | 
				
			||||||
        	throw new Exception('The Task ' . $taskName . ' must be an instance of Mage\Task\AbstractTask.');
 | 
					            throw new Exception('The Task ' . $taskName . ' must be an instance of Mage\Task\AbstractTask.');
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return $instance;
 | 
					        return $instance;
 | 
				
			||||||
 | 
				
			|||||||
@ -30,21 +30,21 @@ class Dumper
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Sets the indentation.
 | 
					     * Sets the indentation.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param int     $num The amount of spaces to use for indentation of nested nodes.
 | 
					     * @param int $num The amount of spaces to use for indentation of nested nodes.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function setIndentation($num)
 | 
					    public function setIndentation($num)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->indentation = (int) $num;
 | 
					        $this->indentation = (int)$num;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Dumps a PHP value to YAML.
 | 
					     * Dumps a PHP value to YAML.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param mixed   $input                  The PHP value
 | 
					     * @param mixed $input The PHP value
 | 
				
			||||||
     * @param int     $inline                 The level where you switch to inline YAML
 | 
					     * @param int $inline The level where you switch to inline YAML
 | 
				
			||||||
     * @param int     $indent                 The level of indentation (used internally)
 | 
					     * @param int $indent The level of indentation (used internally)
 | 
				
			||||||
     * @param bool    $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
 | 
					     * @param bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
 | 
				
			||||||
     * @param bool    $objectSupport          true if object support is enabled, false otherwise
 | 
					     * @param bool $objectSupport true if object support is enabled, false otherwise
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return string  The YAML representation of the PHP value
 | 
					     * @return string  The YAML representation of the PHP value
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
@ -54,7 +54,7 @@ class Dumper
 | 
				
			|||||||
        $prefix = $indent ? str_repeat(' ', $indent) : '';
 | 
					        $prefix = $indent ? str_repeat(' ', $indent) : '';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ($inline <= 0 || !is_array($input) || empty($input)) {
 | 
					        if ($inline <= 0 || !is_array($input) || empty($input)) {
 | 
				
			||||||
            $output .= $prefix.Inline::dump($input, $exceptionOnInvalidType, $objectSupport);
 | 
					            $output .= $prefix . Inline::dump($input, $exceptionOnInvalidType, $objectSupport);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            $isAHash = array_keys($input) !== range(0, count($input) - 1);
 | 
					            $isAHash = array_keys($input) !== range(0, count($input) - 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -63,10 +63,10 @@ class Dumper
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                $output .= sprintf('%s%s%s%s',
 | 
					                $output .= sprintf('%s%s%s%s',
 | 
				
			||||||
                        $prefix,
 | 
					                        $prefix,
 | 
				
			||||||
                        $isAHash ? Inline::dump($key, $exceptionOnInvalidType, $objectSupport).':' : '-',
 | 
					                        $isAHash ? Inline::dump($key, $exceptionOnInvalidType, $objectSupport) . ':' : '-',
 | 
				
			||||||
                        $willBeInlined ? ' ' : "\n",
 | 
					                        $willBeInlined ? ' ' : "\n",
 | 
				
			||||||
                        $this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + $this->indentation, $exceptionOnInvalidType, $objectSupport)
 | 
					                        $this->dump($value, $inline - 1, $willBeInlined ? 0 : $indent + $this->indentation, $exceptionOnInvalidType, $objectSupport)
 | 
				
			||||||
                    ).($willBeInlined ? "\n" : '');
 | 
					                    ) . ($willBeInlined ? "\n" : '');
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -27,16 +27,16 @@ class Escaper
 | 
				
			|||||||
    // on the input arrays. This ordering of the characters avoids the use of strtr,
 | 
					    // on the input arrays. This ordering of the characters avoids the use of strtr,
 | 
				
			||||||
    // which performs more slowly.
 | 
					    // which performs more slowly.
 | 
				
			||||||
    private static $escapees = array('\\\\', '\\"', '"',
 | 
					    private static $escapees = array('\\\\', '\\"', '"',
 | 
				
			||||||
        "\x00",  "\x01",  "\x02",  "\x03",  "\x04",  "\x05",  "\x06",  "\x07",
 | 
					        "\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07",
 | 
				
			||||||
        "\x08",  "\x09",  "\x0a",  "\x0b",  "\x0c",  "\x0d",  "\x0e",  "\x0f",
 | 
					        "\x08", "\x09", "\x0a", "\x0b", "\x0c", "\x0d", "\x0e", "\x0f",
 | 
				
			||||||
        "\x10",  "\x11",  "\x12",  "\x13",  "\x14",  "\x15",  "\x16",  "\x17",
 | 
					        "\x10", "\x11", "\x12", "\x13", "\x14", "\x15", "\x16", "\x17",
 | 
				
			||||||
        "\x18",  "\x19",  "\x1a",  "\x1b",  "\x1c",  "\x1d",  "\x1e",  "\x1f",
 | 
					        "\x18", "\x19", "\x1a", "\x1b", "\x1c", "\x1d", "\x1e", "\x1f",
 | 
				
			||||||
        "\xc2\x85", "\xc2\xa0", "\xe2\x80\xa8", "\xe2\x80\xa9");
 | 
					        "\xc2\x85", "\xc2\xa0", "\xe2\x80\xa8", "\xe2\x80\xa9");
 | 
				
			||||||
    private static $escaped  = array('\\"', '\\\\', '\\"',
 | 
					    private static $escaped = array('\\"', '\\\\', '\\"',
 | 
				
			||||||
        "\\0",   "\\x01", "\\x02", "\\x03", "\\x04", "\\x05", "\\x06", "\\a",
 | 
					        "\\0", "\\x01", "\\x02", "\\x03", "\\x04", "\\x05", "\\x06", "\\a",
 | 
				
			||||||
        "\\b",   "\\t",   "\\n",   "\\v",   "\\f",   "\\r",   "\\x0e", "\\x0f",
 | 
					        "\\b", "\\t", "\\n", "\\v", "\\f", "\\r", "\\x0e", "\\x0f",
 | 
				
			||||||
        "\\x10", "\\x11", "\\x12", "\\x13", "\\x14", "\\x15", "\\x16", "\\x17",
 | 
					        "\\x10", "\\x11", "\\x12", "\\x13", "\\x14", "\\x15", "\\x16", "\\x17",
 | 
				
			||||||
        "\\x18", "\\x19", "\\x1a", "\\e",   "\\x1c", "\\x1d", "\\x1e", "\\x1f",
 | 
					        "\\x18", "\\x19", "\\x1a", "\\e", "\\x1c", "\\x1d", "\\x1e", "\\x1f",
 | 
				
			||||||
        "\\N", "\\_", "\\L", "\\P");
 | 
					        "\\N", "\\_", "\\L", "\\P");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -48,7 +48,7 @@ class Escaper
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    public static function requiresDoubleQuoting($value)
 | 
					    public static function requiresDoubleQuoting($value)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        return preg_match('/'.self::REGEX_CHARACTER_TO_ESCAPE.'/u', $value);
 | 
					        return preg_match('/' . self::REGEX_CHARACTER_TO_ESCAPE . '/u', $value);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 | 
				
			|||||||
@ -35,11 +35,11 @@ class ParseException extends RuntimeException
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Constructor.
 | 
					     * Constructor.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param string    $message    The error message
 | 
					     * @param string $message The error message
 | 
				
			||||||
     * @param int       $parsedLine The line where the error occurred
 | 
					     * @param int $parsedLine The line where the error occurred
 | 
				
			||||||
     * @param int       $snippet    The snippet of code near the problem
 | 
					     * @param int $snippet The snippet of code near the problem
 | 
				
			||||||
     * @param string    $parsedFile The file name where the error occurred
 | 
					     * @param string $parsedFile The file name where the error occurred
 | 
				
			||||||
     * @param \Exception $previous   The previous exception
 | 
					     * @param \Exception $previous The previous exception
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function __construct($message, $parsedLine = -1, $snippet = null, $parsedFile = null, \Exception $previous = null)
 | 
					    public function __construct($message, $parsedLine = -1, $snippet = null, $parsedFile = null, \Exception $previous = null)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@ -112,7 +112,7 @@ class ParseException extends RuntimeException
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Sets the line where the error occurred.
 | 
					     * Sets the line where the error occurred.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param int     $parsedLine The file line
 | 
					     * @param int $parsedLine The file line
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function setParsedLine($parsedLine)
 | 
					    public function setParsedLine($parsedLine)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
				
			|||||||
@ -34,10 +34,10 @@ class Inline
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Converts a YAML string to a PHP array.
 | 
					     * Converts a YAML string to a PHP array.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param string $value                  A YAML string
 | 
					     * @param string $value A YAML string
 | 
				
			||||||
     * @param bool   $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
 | 
					     * @param bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
 | 
				
			||||||
     * @param bool   $objectSupport          true if object support is enabled, false otherwise
 | 
					     * @param bool $objectSupport true if object support is enabled, false otherwise
 | 
				
			||||||
     * @param bool   $objectForMap           true if maps should return a stdClass instead of array()
 | 
					     * @param bool $objectForMap true if maps should return a stdClass instead of array()
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return array A PHP array representing the YAML string
 | 
					     * @return array A PHP array representing the YAML string
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
@ -55,7 +55,7 @@ class Inline
 | 
				
			|||||||
            return '';
 | 
					            return '';
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
 | 
					        if (function_exists('mb_internal_encoding') && ((int)ini_get('mbstring.func_overload')) & 2) {
 | 
				
			||||||
            $mbEncoding = mb_internal_encoding();
 | 
					            $mbEncoding = mb_internal_encoding();
 | 
				
			||||||
            mb_internal_encoding('ASCII');
 | 
					            mb_internal_encoding('ASCII');
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -89,9 +89,9 @@ class Inline
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Dumps a given PHP variable to a YAML string.
 | 
					     * Dumps a given PHP variable to a YAML string.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param mixed   $value                  The PHP variable to convert
 | 
					     * @param mixed $value The PHP variable to convert
 | 
				
			||||||
     * @param bool    $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
 | 
					     * @param bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
 | 
				
			||||||
     * @param bool    $objectSupport          true if object support is enabled, false otherwise
 | 
					     * @param bool $objectSupport true if object support is enabled, false otherwise
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return string The YAML string representing the PHP array
 | 
					     * @return string The YAML string representing the PHP array
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
@ -108,7 +108,7 @@ class Inline
 | 
				
			|||||||
                return 'null';
 | 
					                return 'null';
 | 
				
			||||||
            case is_object($value):
 | 
					            case is_object($value):
 | 
				
			||||||
                if ($objectSupport) {
 | 
					                if ($objectSupport) {
 | 
				
			||||||
                    return '!!php/object:'.serialize($value);
 | 
					                    return '!!php/object:' . serialize($value);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if ($exceptionOnInvalidType) {
 | 
					                if ($exceptionOnInvalidType) {
 | 
				
			||||||
@ -125,7 +125,7 @@ class Inline
 | 
				
			|||||||
            case false === $value:
 | 
					            case false === $value:
 | 
				
			||||||
                return 'false';
 | 
					                return 'false';
 | 
				
			||||||
            case ctype_digit($value):
 | 
					            case ctype_digit($value):
 | 
				
			||||||
                return is_string($value) ? "'$value'" : (int) $value;
 | 
					                return is_string($value) ? "'$value'" : (int)$value;
 | 
				
			||||||
            case is_numeric($value):
 | 
					            case is_numeric($value):
 | 
				
			||||||
                $locale = setlocale(LC_NUMERIC, 0);
 | 
					                $locale = setlocale(LC_NUMERIC, 0);
 | 
				
			||||||
                if (false !== $locale) {
 | 
					                if (false !== $locale) {
 | 
				
			||||||
@ -155,9 +155,9 @@ class Inline
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Dumps a PHP array to a YAML string.
 | 
					     * Dumps a PHP array to a YAML string.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param array   $value                  The PHP array to dump
 | 
					     * @param array $value The PHP array to dump
 | 
				
			||||||
     * @param bool    $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
 | 
					     * @param bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
 | 
				
			||||||
     * @param bool    $objectSupport          true if object support is enabled, false otherwise
 | 
					     * @param bool $objectSupport true if object support is enabled, false otherwise
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return string The YAML string representing the PHP array
 | 
					     * @return string The YAML string representing the PHP array
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
@ -166,7 +166,9 @@ class Inline
 | 
				
			|||||||
        // array
 | 
					        // array
 | 
				
			||||||
        $keys = array_keys($value);
 | 
					        $keys = array_keys($value);
 | 
				
			||||||
        if ((1 == count($keys) && '0' == $keys[0])
 | 
					        if ((1 == count($keys) && '0' == $keys[0])
 | 
				
			||||||
            || (count($keys) > 1 && array_reduce($keys, function ($v, $w) { return (int) $v + $w; }, 0) == count($keys) * (count($keys) - 1) / 2)
 | 
					            || (count($keys) > 1 && array_reduce($keys, function ($v, $w) {
 | 
				
			||||||
 | 
					                    return (int)$v + $w;
 | 
				
			||||||
 | 
					                }, 0) == count($keys) * (count($keys) - 1) / 2)
 | 
				
			||||||
        ) {
 | 
					        ) {
 | 
				
			||||||
            $output = array();
 | 
					            $output = array();
 | 
				
			||||||
            foreach ($value as $val) {
 | 
					            foreach ($value as $val) {
 | 
				
			||||||
@ -188,11 +190,11 @@ class Inline
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Parses a scalar to a YAML string.
 | 
					     * Parses a scalar to a YAML string.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param scalar  $scalar
 | 
					     * @param scalar $scalar
 | 
				
			||||||
     * @param string  $delimiters
 | 
					     * @param string $delimiters
 | 
				
			||||||
     * @param array   $stringDelimiters
 | 
					     * @param array $stringDelimiters
 | 
				
			||||||
     * @param int     &$i
 | 
					     * @param int &$i
 | 
				
			||||||
     * @param bool    $evaluate
 | 
					     * @param bool $evaluate
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return string A YAML string
 | 
					     * @return string A YAML string
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
@ -220,7 +222,7 @@ class Inline
 | 
				
			|||||||
                if (false !== $strpos = strpos($output, ' #')) {
 | 
					                if (false !== $strpos = strpos($output, ' #')) {
 | 
				
			||||||
                    $output = rtrim(substr($output, 0, $strpos));
 | 
					                    $output = rtrim(substr($output, 0, $strpos));
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            } elseif (preg_match('/^(.+?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) {
 | 
					            } elseif (preg_match('/^(.+?)(' . implode('|', $delimiters) . ')/', substr($scalar, $i), $match)) {
 | 
				
			||||||
                $output = $match[1];
 | 
					                $output = $match[1];
 | 
				
			||||||
                $i += strlen($output);
 | 
					                $i += strlen($output);
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
@ -239,7 +241,7 @@ class Inline
 | 
				
			|||||||
     * Parses a quoted scalar to YAML.
 | 
					     * Parses a quoted scalar to YAML.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param string $scalar
 | 
					     * @param string $scalar
 | 
				
			||||||
     * @param int    &$i
 | 
					     * @param int &$i
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return string A YAML string
 | 
					     * @return string A YAML string
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
@ -247,7 +249,7 @@ class Inline
 | 
				
			|||||||
     */
 | 
					     */
 | 
				
			||||||
    private static function parseQuotedScalar($scalar, &$i)
 | 
					    private static function parseQuotedScalar($scalar, &$i)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (!preg_match('/'.self::REGEX_QUOTED_STRING.'/Au', substr($scalar, $i), $match)) {
 | 
					        if (!preg_match('/' . self::REGEX_QUOTED_STRING . '/Au', substr($scalar, $i), $match)) {
 | 
				
			||||||
            throw new ParseException(sprintf('Malformed inline YAML string (%s).', substr($scalar, $i)));
 | 
					            throw new ParseException(sprintf('Malformed inline YAML string (%s).', substr($scalar, $i)));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -268,8 +270,8 @@ class Inline
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Parses a sequence to a YAML string.
 | 
					     * Parses a sequence to a YAML string.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param string  $sequence
 | 
					     * @param string $sequence
 | 
				
			||||||
     * @param int     &$i
 | 
					     * @param int &$i
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return string A YAML string
 | 
					     * @return string A YAML string
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
@ -304,7 +306,7 @@ class Inline
 | 
				
			|||||||
                    if (!$isQuoted && false !== strpos($value, ': ')) {
 | 
					                    if (!$isQuoted && false !== strpos($value, ': ')) {
 | 
				
			||||||
                        // embedded mapping?
 | 
					                        // embedded mapping?
 | 
				
			||||||
                        try {
 | 
					                        try {
 | 
				
			||||||
                            $value = self::parseMapping('{'.$value.'}');
 | 
					                            $value = self::parseMapping('{' . $value . '}');
 | 
				
			||||||
                        } catch (\InvalidArgumentException $e) {
 | 
					                        } catch (\InvalidArgumentException $e) {
 | 
				
			||||||
                            // no, it's not
 | 
					                            // no, it's not
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
@ -324,8 +326,8 @@ class Inline
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Parses a mapping to a YAML string.
 | 
					     * Parses a mapping to a YAML string.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param string  $mapping
 | 
					     * @param string $mapping
 | 
				
			||||||
     * @param int     &$i
 | 
					     * @param int &$i
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return string A YAML string
 | 
					     * @return string A YAML string
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
@ -346,7 +348,7 @@ class Inline
 | 
				
			|||||||
                    continue 2;
 | 
					                    continue 2;
 | 
				
			||||||
                case '}':
 | 
					                case '}':
 | 
				
			||||||
                    if (self::$objectForMap) {
 | 
					                    if (self::$objectForMap) {
 | 
				
			||||||
                        return (object) $output;
 | 
					                        return (object)$output;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    return $output;
 | 
					                    return $output;
 | 
				
			||||||
@ -425,7 +427,7 @@ class Inline
 | 
				
			|||||||
            case '' === $scalar:
 | 
					            case '' === $scalar:
 | 
				
			||||||
            case '~' === $scalar:
 | 
					            case '~' === $scalar:
 | 
				
			||||||
                /** @noinspection PhpInconsistentReturnPointsInspection */
 | 
					                /** @noinspection PhpInconsistentReturnPointsInspection */
 | 
				
			||||||
            return;
 | 
					                return;
 | 
				
			||||||
            case 'true' === $scalarLower:
 | 
					            case 'true' === $scalarLower:
 | 
				
			||||||
                return true;
 | 
					                return true;
 | 
				
			||||||
            case 'false' === $scalarLower:
 | 
					            case 'false' === $scalarLower:
 | 
				
			||||||
@ -435,7 +437,7 @@ class Inline
 | 
				
			|||||||
            case $scalar[0] === '+' || $scalar[0] === '-' || $scalar[0] === '.' || $scalar[0] === '!' || is_numeric($scalar[0]):
 | 
					            case $scalar[0] === '+' || $scalar[0] === '-' || $scalar[0] === '.' || $scalar[0] === '!' || is_numeric($scalar[0]):
 | 
				
			||||||
                switch (true) {
 | 
					                switch (true) {
 | 
				
			||||||
                    case 0 === strpos($scalar, '!str'):
 | 
					                    case 0 === strpos($scalar, '!str'):
 | 
				
			||||||
                        return (string) substr($scalar, 5);
 | 
					                        return (string)substr($scalar, 5);
 | 
				
			||||||
                    case 0 === strpos($scalar, '! '):
 | 
					                    case 0 === strpos($scalar, '! '):
 | 
				
			||||||
                        return intval(self::parseScalar(substr($scalar, 2)));
 | 
					                        return intval(self::parseScalar(substr($scalar, 2)));
 | 
				
			||||||
                    case 0 === strpos($scalar, '!!php/object:'):
 | 
					                    case 0 === strpos($scalar, '!!php/object:'):
 | 
				
			||||||
@ -453,14 +455,14 @@ class Inline
 | 
				
			|||||||
                        $raw = $scalar;
 | 
					                        $raw = $scalar;
 | 
				
			||||||
                        $cast = intval($scalar);
 | 
					                        $cast = intval($scalar);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        return '0' == $scalar[0] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw);
 | 
					                        return '0' == $scalar[0] ? octdec($scalar) : (((string)$raw == (string)$cast) ? $cast : $raw);
 | 
				
			||||||
                    case '-' === $scalar[0] && ctype_digit(substr($scalar, 1)):
 | 
					                    case '-' === $scalar[0] && ctype_digit(substr($scalar, 1)):
 | 
				
			||||||
                        $raw = $scalar;
 | 
					                        $raw = $scalar;
 | 
				
			||||||
                        $cast = intval($scalar);
 | 
					                        $cast = intval($scalar);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        return '0' == $scalar[1] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw);
 | 
					                        return '0' == $scalar[1] ? octdec($scalar) : (((string)$raw == (string)$cast) ? $cast : $raw);
 | 
				
			||||||
                    case is_numeric($scalar):
 | 
					                    case is_numeric($scalar):
 | 
				
			||||||
                        return '0x' == $scalar[0].$scalar[1] ? hexdec($scalar) : floatval($scalar);
 | 
					                        return '0x' == $scalar[0] . $scalar[1] ? hexdec($scalar) : floatval($scalar);
 | 
				
			||||||
                    case '.inf' === $scalarLower:
 | 
					                    case '.inf' === $scalarLower:
 | 
				
			||||||
                    case '.nan' === $scalarLower:
 | 
					                    case '.nan' === $scalarLower:
 | 
				
			||||||
                        return -log(0);
 | 
					                        return -log(0);
 | 
				
			||||||
@ -472,7 +474,7 @@ class Inline
 | 
				
			|||||||
                        return strtotime($scalar);
 | 
					                        return strtotime($scalar);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            default:
 | 
					            default:
 | 
				
			||||||
                return (string) $scalar;
 | 
					                return (string)$scalar;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -23,16 +23,16 @@ class Parser
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    const FOLDED_SCALAR_PATTERN = '(?P<separator>\||>)(?P<modifiers>\+|\-|\d+|\+\d+|\-\d+|\d+\+|\d+\-)?(?P<comments> +#.*)?';
 | 
					    const FOLDED_SCALAR_PATTERN = '(?P<separator>\||>)(?P<modifiers>\+|\-|\d+|\+\d+|\-\d+|\d+\+|\d+\-)?(?P<comments> +#.*)?';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private $offset         = 0;
 | 
					    private $offset = 0;
 | 
				
			||||||
    private $lines          = array();
 | 
					    private $lines = array();
 | 
				
			||||||
    private $currentLineNb  = -1;
 | 
					    private $currentLineNb = -1;
 | 
				
			||||||
    private $currentLine    = '';
 | 
					    private $currentLine = '';
 | 
				
			||||||
    private $refs           = array();
 | 
					    private $refs = array();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Constructor
 | 
					     * Constructor
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param int     $offset The offset of YAML document (used for line numbers in error messages)
 | 
					     * @param int $offset The offset of YAML document (used for line numbers in error messages)
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function __construct($offset = 0)
 | 
					    public function __construct($offset = 0)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@ -42,10 +42,10 @@ class Parser
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Parses a YAML string to a PHP value.
 | 
					     * Parses a YAML string to a PHP value.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param string  $value                  A YAML string
 | 
					     * @param string $value A YAML string
 | 
				
			||||||
     * @param bool    $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
 | 
					     * @param bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
 | 
				
			||||||
     * @param bool    $objectSupport          true if object support is enabled, false otherwise
 | 
					     * @param bool $objectSupport true if object support is enabled, false otherwise
 | 
				
			||||||
     * @param bool    $objectForMap           true if maps should return a stdClass instead of array()
 | 
					     * @param bool $objectForMap true if maps should return a stdClass instead of array()
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return mixed  A PHP value
 | 
					     * @return mixed  A PHP value
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
@ -61,7 +61,7 @@ class Parser
 | 
				
			|||||||
            throw new ParseException('The YAML value does not appear to be valid UTF-8.');
 | 
					            throw new ParseException('The YAML value does not appear to be valid UTF-8.');
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
 | 
					        if (function_exists('mb_internal_encoding') && ((int)ini_get('mbstring.func_overload')) & 2) {
 | 
				
			||||||
            $mbEncoding = mb_internal_encoding();
 | 
					            $mbEncoding = mb_internal_encoding();
 | 
				
			||||||
            mb_internal_encoding('UTF-8');
 | 
					            mb_internal_encoding('UTF-8');
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@ -99,7 +99,7 @@ class Parser
 | 
				
			|||||||
                } else {
 | 
					                } else {
 | 
				
			||||||
                    if (isset($values['leadspaces'])
 | 
					                    if (isset($values['leadspaces'])
 | 
				
			||||||
                        && ' ' == $values['leadspaces']
 | 
					                        && ' ' == $values['leadspaces']
 | 
				
			||||||
                        && preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\{\[].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $values['value'], $matches)
 | 
					                        && preg_match('#^(?P<key>' . Inline::REGEX_QUOTED_STRING . '|[^ \'"\{\[].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $values['value'], $matches)
 | 
				
			||||||
                    ) {
 | 
					                    ) {
 | 
				
			||||||
                        // this is a compact notation element, add to next block and parse
 | 
					                        // this is a compact notation element, add to next block and parse
 | 
				
			||||||
                        $c = $this->getRealCurrentLineNb();
 | 
					                        $c = $this->getRealCurrentLineNb();
 | 
				
			||||||
@ -108,7 +108,7 @@ class Parser
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                        $block = $values['value'];
 | 
					                        $block = $values['value'];
 | 
				
			||||||
                        if ($this->isNextLineIndented()) {
 | 
					                        if ($this->isNextLineIndented()) {
 | 
				
			||||||
                            $block .= "\n".$this->getNextEmbedBlock($this->getCurrentLineIndentation() + 2);
 | 
					                            $block .= "\n" . $this->getNextEmbedBlock($this->getCurrentLineIndentation() + 2);
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        $data[] = $parser->parse($block, $exceptionOnInvalidType, $objectSupport, $objectForMap);
 | 
					                        $data[] = $parser->parse($block, $exceptionOnInvalidType, $objectSupport, $objectForMap);
 | 
				
			||||||
@ -116,7 +116,7 @@ class Parser
 | 
				
			|||||||
                        $data[] = $this->parseValue($values['value'], $exceptionOnInvalidType, $objectSupport, $objectForMap);
 | 
					                        $data[] = $this->parseValue($values['value'], $exceptionOnInvalidType, $objectSupport, $objectForMap);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            } elseif (preg_match('#^(?P<key>'.Inline::REGEX_QUOTED_STRING.'|[^ \'"\[\{].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $this->currentLine, $values) && false === strpos($values['key'],' #')) {
 | 
					            } elseif (preg_match('#^(?P<key>' . Inline::REGEX_QUOTED_STRING . '|[^ \'"\[\{].*?) *\:(\s+(?P<value>.+?))?\s*$#u', $this->currentLine, $values) && false === strpos($values['key'], ' #')) {
 | 
				
			||||||
                if ($context && 'sequence' == $context) {
 | 
					                if ($context && 'sequence' == $context) {
 | 
				
			||||||
                    throw new ParseException('You cannot define a mapping item when in a sequence');
 | 
					                    throw new ParseException('You cannot define a mapping item when in a sequence');
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
@ -300,7 +300,7 @@ class Parser
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Returns the next embed block of YAML.
 | 
					     * Returns the next embed block of YAML.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param int     $indentation The indent level at which the block is to be read, or null for default
 | 
					     * @param int $indentation The indent level at which the block is to be read, or null for default
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return string A YAML string
 | 
					     * @return string A YAML string
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
@ -327,7 +327,7 @@ class Parser
 | 
				
			|||||||
        $isItUnindentedCollection = $this->isStringUnIndentedCollectionItem($this->currentLine);
 | 
					        $isItUnindentedCollection = $this->isStringUnIndentedCollectionItem($this->currentLine);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Comments must not be removed inside a string block (ie. after a line ending with "|")
 | 
					        // Comments must not be removed inside a string block (ie. after a line ending with "|")
 | 
				
			||||||
        $removeCommentsPattern = '~'.self::FOLDED_SCALAR_PATTERN.'$~';
 | 
					        $removeCommentsPattern = '~' . self::FOLDED_SCALAR_PATTERN . '$~';
 | 
				
			||||||
        $removeComments = !preg_match($removeCommentsPattern, $this->currentLine);
 | 
					        $removeComments = !preg_match($removeCommentsPattern, $this->currentLine);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        while ($this->moveToNextLine()) {
 | 
					        while ($this->moveToNextLine()) {
 | 
				
			||||||
@ -392,10 +392,10 @@ class Parser
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Parses a YAML value.
 | 
					     * Parses a YAML value.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param string $value                  A YAML value
 | 
					     * @param string $value A YAML value
 | 
				
			||||||
     * @param bool   $exceptionOnInvalidType True if an exception must be thrown on invalid types false otherwise
 | 
					     * @param bool $exceptionOnInvalidType True if an exception must be thrown on invalid types false otherwise
 | 
				
			||||||
     * @param bool   $objectSupport          True if object support is enabled, false otherwise
 | 
					     * @param bool $objectSupport True if object support is enabled, false otherwise
 | 
				
			||||||
     * @param bool   $objectForMap           true if maps should return a stdClass instead of array()
 | 
					     * @param bool $objectForMap true if maps should return a stdClass instead of array()
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return mixed A PHP value
 | 
					     * @return mixed A PHP value
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
@ -417,7 +417,7 @@ class Parser
 | 
				
			|||||||
            return $this->refs[$value];
 | 
					            return $this->refs[$value];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (preg_match('/^'.self::FOLDED_SCALAR_PATTERN.'$/', $value, $matches)) {
 | 
					        if (preg_match('/^' . self::FOLDED_SCALAR_PATTERN . '$/', $value, $matches)) {
 | 
				
			||||||
            $modifiers = isset($matches['modifiers']) ? $matches['modifiers'] : '';
 | 
					            $modifiers = isset($matches['modifiers']) ? $matches['modifiers'] : '';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return $this->parseFoldedScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), intval(abs($modifiers)));
 | 
					            return $this->parseFoldedScalar($matches['separator'], preg_replace('#\d+#', '', $modifiers), intval(abs($modifiers)));
 | 
				
			||||||
@ -436,9 +436,9 @@ class Parser
 | 
				
			|||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Parses a folded scalar.
 | 
					     * Parses a folded scalar.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param string  $separator   The separator that was used to begin this folded scalar (| or >)
 | 
					     * @param string $separator The separator that was used to begin this folded scalar (| or >)
 | 
				
			||||||
     * @param string  $indicator   The indicator that was used to begin this folded scalar (+ or -)
 | 
					     * @param string $indicator The indicator that was used to begin this folded scalar (+ or -)
 | 
				
			||||||
     * @param int     $indentation The indentation that was used to begin this folded scalar
 | 
					     * @param int $indentation The indentation that was used to begin this folded scalar
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return string  The text value
 | 
					     * @return string  The text value
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
 | 
				
			|||||||
@ -55,7 +55,7 @@ class Unescaper
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // evaluate the string
 | 
					        // evaluate the string
 | 
				
			||||||
        return preg_replace_callback('/'.self::REGEX_ESCAPED_CHARACTER.'/u', $callback, $value);
 | 
					        return preg_replace_callback('/' . self::REGEX_ESCAPED_CHARACTER . '/u', $callback, $value);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
@ -131,12 +131,12 @@ class Unescaper
 | 
				
			|||||||
            return chr($c);
 | 
					            return chr($c);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (0x800 > $c) {
 | 
					        if (0x800 > $c) {
 | 
				
			||||||
            return chr(0xC0 | $c>>6).chr(0x80 | $c & 0x3F);
 | 
					            return chr(0xC0 | $c >> 6) . chr(0x80 | $c & 0x3F);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (0x10000 > $c) {
 | 
					        if (0x10000 > $c) {
 | 
				
			||||||
            return chr(0xE0 | $c>>12).chr(0x80 | $c>>6 & 0x3F).chr(0x80 | $c & 0x3F);
 | 
					            return chr(0xE0 | $c >> 12) . chr(0x80 | $c >> 6 & 0x3F) . chr(0x80 | $c & 0x3F);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return chr(0xF0 | $c>>18).chr(0x80 | $c>>12 & 0x3F).chr(0x80 | $c>>6 & 0x3F).chr(0x80 | $c & 0x3F);
 | 
					        return chr(0xF0 | $c >> 18) . chr(0x80 | $c >> 12 & 0x3F) . chr(0x80 | $c >> 6 & 0x3F) . chr(0x80 | $c & 0x3F);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -40,9 +40,9 @@ class Yaml
 | 
				
			|||||||
     * you must validate the input before calling this method. Passing a file
 | 
					     * you must validate the input before calling this method. Passing a file
 | 
				
			||||||
     * as an input is a deprecated feature and will be removed in 3.0.
 | 
					     * as an input is a deprecated feature and will be removed in 3.0.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param string  $input                  Path to a YAML file or a string containing YAML
 | 
					     * @param string $input Path to a YAML file or a string containing YAML
 | 
				
			||||||
     * @param bool    $exceptionOnInvalidType True if an exception must be thrown on invalid types false otherwise
 | 
					     * @param bool $exceptionOnInvalidType True if an exception must be thrown on invalid types false otherwise
 | 
				
			||||||
     * @param bool    $objectSupport          True if object support is enabled, false otherwise
 | 
					     * @param bool $objectSupport True if object support is enabled, false otherwise
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return array The YAML converted to a PHP array
 | 
					     * @return array The YAML converted to a PHP array
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
@ -82,11 +82,11 @@ class Yaml
 | 
				
			|||||||
     * The dump method, when supplied with an array, will do its best
 | 
					     * The dump method, when supplied with an array, will do its best
 | 
				
			||||||
     * to convert the array into friendly YAML.
 | 
					     * to convert the array into friendly YAML.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param array   $array                  PHP array
 | 
					     * @param array $array PHP array
 | 
				
			||||||
     * @param int     $inline                 The level where you switch to inline YAML
 | 
					     * @param int $inline The level where you switch to inline YAML
 | 
				
			||||||
     * @param int     $indent                 The amount of spaces to use for indentation of nested nodes.
 | 
					     * @param int $indent The amount of spaces to use for indentation of nested nodes.
 | 
				
			||||||
     * @param bool    $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
 | 
					     * @param bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
 | 
				
			||||||
     * @param bool    $objectSupport          true if object support is enabled, false otherwise
 | 
					     * @param bool $objectSupport true if object support is enabled, false otherwise
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @return string A YAML string representing the original PHP array
 | 
					     * @return string A YAML string representing the original PHP array
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user