From 438a81542e99124e54253810dfa98216a7fd2b91 Mon Sep 17 00:00:00 2001 From: Alex V Kotelnikov Date: Thu, 30 Oct 2014 23:49:01 +0400 Subject: [PATCH] changes @ deploy command. added rollback exception functionality. --- Mage/Command/BuiltIn/DeployCommand.php | 28 ++++++++++++++++++++++++++ Mage/Task/RollbackException.php | 23 +++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 Mage/Task/RollbackException.php diff --git a/Mage/Command/BuiltIn/DeployCommand.php b/Mage/Command/BuiltIn/DeployCommand.php index 3719c49..e412d92 100644 --- a/Mage/Command/BuiltIn/DeployCommand.php +++ b/Mage/Command/BuiltIn/DeployCommand.php @@ -3,6 +3,7 @@ * This file is part of the Magallanes package. * * (c) Andrés Montañez +* (c) Alex V Kotelnikov * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. @@ -16,6 +17,7 @@ use Mage\Task\Factory; use Mage\Task\AbstractTask; use Mage\Task\Releases\SkipOnOverride; use Mage\Task\ErrorWithMessageException; +use Mage\Task\RollbackException; use Mage\Task\SkipException; use Mage\Console; use Mage\Config; @@ -428,6 +430,27 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment } } + protected function runRollbackTask(){ + $hosts = $this->getConfig()->getHosts(); + + if (count($hosts) == 0) { + Console::output('Warning! No hosts defined, unable to get releases.', 1, 3); + + } else { + $result = true; + foreach ($hosts as $host) { + $this->getConfig()->setHost($host); + + $this->getConfig()->setReleaseId(-1); + $task = Factory::get('releases/rollback', $this->getConfig()); + $task->init(); + $result = $task->run() && $result; + } + return $result; + } + return false; + } + /** * Runs a Task * @@ -461,6 +484,11 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment Console::output('FAIL', 0); $result = false; } + } catch (RollbackException $e) { + Console::output('FAIL, Rollback started [Message: ' . $e->getMessage() . ']', 0); + $this->runRollbackTask(); + $result = false; + } catch (ErrorWithMessageException $e) { Console::output('FAIL [Message: ' . $e->getMessage() . ']', 0); $result = false; diff --git a/Mage/Task/RollbackException.php b/Mage/Task/RollbackException.php new file mode 100644 index 0000000..d2e56df --- /dev/null +++ b/Mage/Task/RollbackException.php @@ -0,0 +1,23 @@ + +* +* For the full copyright and license information, please view the LICENSE +* file that was distributed with this source code. +*/ + +namespace Mage\Task; + +use Exception; + +/** + * Exception that indicates that the Task was Failed and rollback needed + * + * @author Alex V Kotelnikov + */ +class RollbackException extends Exception +{ + +} \ No newline at end of file