|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the project RMT |
| 5 | + * |
| 6 | + * Copyright (c) 2013, Liip AG, http://www.liip.ch |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Liip\RMT\Command; |
| 13 | + |
| 14 | +use Symfony\Component\Console\Input\InputInterface; |
| 15 | +use Symfony\Component\Console\Output\OutputInterface; |
| 16 | +use Liip\RMT\Context; |
| 17 | + |
| 18 | +/** |
| 19 | + * Rollback the last release |
| 20 | + */ |
| 21 | +class RollbackCommand extends BaseCommand |
| 22 | +{ |
| 23 | + /** |
| 24 | + * {@inheritdoc} |
| 25 | + */ |
| 26 | + protected function configure() |
| 27 | + { |
| 28 | + $this->setName('rollback'); |
| 29 | + $this->setDescription('Rollback the last release if there was no change since.'); |
| 30 | + $this->setHelp('The <comment>rollback</comment> should be used to cancel a previously done release.'); |
| 31 | + } |
| 32 | + |
| 33 | + protected function execute(InputInterface $input, OutputInterface $output) |
| 34 | + { |
| 35 | + if (count(Context::get('vcs')->getLocalModifications()) > 0) { |
| 36 | + Context::get('output')->writeln('<error>Local modifications found. Aborting.</error>'); |
| 37 | + return; |
| 38 | + } |
| 39 | + |
| 40 | + $tag = Context::get('version-persister')->getCurrentVersionTag(); |
| 41 | + $modifications = Context::get('vcs')->getAllModificationsSince($tag, false, false); |
| 42 | + if (count($modifications) > 0) { |
| 43 | + Context::get('output')->writeln('<error>There were commits since the last release. Aborting.</error>'); |
| 44 | + return; |
| 45 | + } |
| 46 | + |
| 47 | + $this->rollbackActionListIfExist('post-release-actions'); |
| 48 | + $this->rollbackActionListIfExist('pre-release-actions'); |
| 49 | + } |
| 50 | + |
| 51 | + protected function rollbackActionListIfExist($name) |
| 52 | + { |
| 53 | + $actions = Context::getInstance()->getList($name); |
| 54 | + $actions = array_reverse($actions); |
| 55 | + foreach ($actions as $num => $action) { |
| 56 | + $this->getOutput()->write(++$num.') '.$action->getTitle().' : '); |
| 57 | + $action->rollback(); |
| 58 | + } |
| 59 | + } |
| 60 | +} |
0 commit comments