|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @author hollodotme |
| 4 | + */ |
| 5 | + |
| 6 | +namespace CodeClimate\PhpTestReporter\ConsoleCommands; |
| 7 | + |
| 8 | +use CodeClimate\PhpTestReporter\Constants\PharTool; |
| 9 | +use Humbug\SelfUpdate\Strategy\GithubStrategy; |
| 10 | +use Humbug\SelfUpdate\Updater; |
| 11 | +use Symfony\Component\Console\Command\Command; |
| 12 | +use Symfony\Component\Console\Input\InputInterface; |
| 13 | +use Symfony\Component\Console\Logger\ConsoleLogger; |
| 14 | +use Symfony\Component\Console\Output\OutputInterface; |
| 15 | + |
| 16 | +/** |
| 17 | + * Class RollbackCommand |
| 18 | + * @package CodeClimate\PhpTestReporter\ConsoleCommands |
| 19 | + */ |
| 20 | +class RollbackCommand extends Command |
| 21 | +{ |
| 22 | + protected function configure() |
| 23 | + { |
| 24 | + $this->setDescription('Rolls back this PHAR to the previous version.'); |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * @param InputInterface $input |
| 29 | + * @param OutputInterface $output |
| 30 | + * |
| 31 | + * @return int |
| 32 | + */ |
| 33 | + protected function execute(InputInterface $input, OutputInterface $output) |
| 34 | + { |
| 35 | + $input->validate(); |
| 36 | + $logger = new ConsoleLogger($output); |
| 37 | + $updater = new Updater(null, false, Updater::STRATEGY_GITHUB); |
| 38 | + |
| 39 | + /** @var GithubStrategy $strategy */ |
| 40 | + $strategy = $updater->getStrategy(); |
| 41 | + |
| 42 | + $strategy->setPackageName(PharTool::PACKAGE_NAME); |
| 43 | + $strategy->setPharName(PharTool::PHAR_NAME); |
| 44 | + $strategy->setCurrentLocalVersion('@package_version@'); |
| 45 | + |
| 46 | + if ($updater->rollback()) { |
| 47 | + $logger->info('Roll back successful!'); |
| 48 | + } else { |
| 49 | + $logger->alert('Roll back failed.'); |
| 50 | + } |
| 51 | + |
| 52 | + return 0; |
| 53 | + } |
| 54 | +} |
0 commit comments