From 11bdd68fffe1f9e52e8db499b92ce98738f77706 Mon Sep 17 00:00:00 2001 From: Vladimir Grigor Date: Mon, 28 Jul 2014 15:43:52 +0300 Subject: [PATCH] - factored constants out; - fixed bug: "releases list" command would die checking for unnecessary --release parameter; - console prints log file name if if logging is enabled --- Mage/Command/BuiltIn/DeployCommand.php | 30 +++++++---- Mage/Command/BuiltIn/ReleasesCommand.php | 65 +++++++++++++----------- Mage/Console.php | 5 ++ 3 files changed, 61 insertions(+), 39 deletions(-) diff --git a/Mage/Command/BuiltIn/DeployCommand.php b/Mage/Command/BuiltIn/DeployCommand.php index 3c48992..a4fa92b 100644 --- a/Mage/Command/BuiltIn/DeployCommand.php +++ b/Mage/Command/BuiltIn/DeployCommand.php @@ -30,7 +30,15 @@ use Exception; */ class DeployCommand extends AbstractCommand implements RequiresEnvironment { - /** + const DEFAULT_RELEASE_IS_ENABLED = false; + const DEPLOY_STRATEGY_DISABLED = 'disabled'; + const DEPLOY_STRATEGY_RSYNC = 'rsync'; + const DEPLOY_STRATEGY_TARGZ = 'targz'; + const DEPLOY_STRATEGY_GIT_REBASE = 'git-rebase'; + const DEPLOY_STRATEGY_GUESS = 'guess'; + const DEFAULT_DEPLOY_STRATEGY = self::DEPLOY_STRATEGY_GUESS; + + /** * Deploy has Failed * @var string */ @@ -523,24 +531,24 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment protected function chooseDeployStrategy() { // Guess a Deploy Strategy - switch ($this->getConfig()->deployment('strategy', 'guess')) { - case 'disabled': + switch ($this->getConfig()->deployment('strategy', self::DEFAULT_DEPLOY_STRATEGY)) { + case self::DEPLOY_STRATEGY_DISABLED: $deployStrategy = 'deployment/strategy/disabled'; break; - case 'rsync': + case self::DEPLOY_STRATEGY_RSYNC: $deployStrategy = 'deployment/strategy/rsync'; break; - case 'targz': + case self::DEPLOY_STRATEGY_TARGZ: $deployStrategy = 'deployment/strategy/tar-gz'; break; - case 'git-rebase': + case self::DEPLOY_STRATEGY_GIT_REBASE: $deployStrategy = 'deployment/strategy/git-rebase'; break; - case 'guess': + case self::DEPLOY_STRATEGY_GUESS: default: if ($this->getConfig()->release('enabled', false) == true) { $deployStrategy = 'deployment/strategy/tar-gz'; @@ -558,10 +566,12 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment protected function chooseReleaseStrategy() { - if ($this->getConfig()->release('enabled', false) === true) { - $strategy = 'deployment/strategy/disabled'; - } else { + if ($this->getConfig()->release('enabled', self::DEFAULT_RELEASE_IS_ENABLED) + && $this->getConfig()->deployment('strategy', self::DEFAULT_DEPLOY_STRATEGY) !== self::DEPLOY_STRATEGY_DISABLED + ) { $strategy = 'deployment/release'; + } else { + $strategy = 'deployment/strategy/disabled'; } return $strategy; diff --git a/Mage/Command/BuiltIn/ReleasesCommand.php b/Mage/Command/BuiltIn/ReleasesCommand.php index 293faaf..fadedfa 100644 --- a/Mage/Command/BuiltIn/ReleasesCommand.php +++ b/Mage/Command/BuiltIn/ReleasesCommand.php @@ -28,44 +28,51 @@ class ReleasesCommand extends AbstractCommand implements RequiresEnvironment */ public function run() { - if (!is_numeric($this->getConfig()->getParameter('release', ''))) { - Console::output('This release is mandatory.', 1, 2); - return false; - } - - $subcommand = $this->getConfig()->getArgument(1); - $lockFile = getcwd() . '/.mage/' . $this->getConfig()->getEnvironment() . '.lock'; - if (file_exists($lockFile) && ($subcommand == 'rollback')) { - Console::output('This environment is locked!', 1, 2); - echo file_get_contents($lockFile); - return null; - } + $subCommand = $this->getConfig()->getArgument(1); // Run Tasks for Deployment $hosts = $this->getConfig()->getHosts(); if (count($hosts) == 0) { - Console::output('Warning! No hosts defined, unable to get releases.', 1, 3); + Console::output( + 'Warning! No hosts defined, unable to get releases.', + 1, 3 + ); + + return false; + } + + foreach ($hosts as $host) { + $this->getConfig()->setHost($host); + + switch ($subCommand) { + case 'list': + $task = Factory::get('releases/list', $this->getConfig()); + $task->init(); + $result = $task->run(); + break; - } else { - foreach ($hosts as $host) { - $this->getConfig()->setHost($host); + case 'rollback': + if (!is_numeric($this->getConfig()->getParameter('release', ''))) { + Console::output('Missing required releaseid.', 1, 2); - switch ($subcommand) { - case 'list': - $task = Factory::get('releases/list', $this->getConfig()); - $task->init(); - $result = $task->run(); - break; + return false; + } + + $lockFile = getcwd() . '/.mage/' . $this->getConfig()->getEnvironment() . '.lock'; + if (file_exists($lockFile)) { + Console::output('This environment is locked!', 1, 2); + echo file_get_contents($lockFile); - case 'rollback': - $releaseId = $this->getConfig()->getParameter('release', ''); - $task = Factory::get('releases/rollback', $this->getConfig()); - $task->init(); - $task->setRelease($releaseId); - $result = $task->run(); - break; + return false; } + + $releaseId = $this->getConfig()->getParameter('release', ''); + $task = Factory::get('releases/rollback', $this->getConfig()); + $task->init(); + $task->setRelease($releaseId); + $result = $task->run(); + break; } } diff --git a/Mage/Console.php b/Mage/Console.php index 3aed87b..bd4c90b 100644 --- a/Mage/Console.php +++ b/Mage/Console.php @@ -106,6 +106,11 @@ class Console $showGreetings = false; } else { self::$logEnabled = $config->general('logging', false); + if(self::$logEnabled) + { + self::log("Logging enabled"); + self::output(' Logging enabled: ' . self::getLogFile() . '', 1, 1); + } } // Greetings