|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * This file is part of Ymir command-line tool. |
| 7 | + * |
| 8 | + * (c) Carl Alexander <[email protected]> |
| 9 | + * |
| 10 | + * For the full copyright and license information, please view the LICENSE |
| 11 | + * file that was distributed with this source code. |
| 12 | + */ |
| 13 | + |
| 14 | +namespace Ymir\Cli\Command\Cache; |
| 15 | + |
| 16 | +use Symfony\Component\Console\Input\InputArgument; |
| 17 | +use Symfony\Component\Console\Input\InputOption; |
| 18 | +use Ymir\Cli\Console\Input; |
| 19 | +use Ymir\Cli\Console\Output; |
| 20 | +use Ymir\Cli\Exception\InvalidInputException; |
| 21 | + |
| 22 | +class ModifyCacheCommand extends AbstractCacheCommand |
| 23 | +{ |
| 24 | + /** |
| 25 | + * The name of the command. |
| 26 | + * |
| 27 | + * @var string |
| 28 | + */ |
| 29 | + public const NAME = 'cache:modify'; |
| 30 | + |
| 31 | + /** |
| 32 | + * {@inheritdoc} |
| 33 | + */ |
| 34 | + protected function configure() |
| 35 | + { |
| 36 | + $this |
| 37 | + ->setName(self::NAME) |
| 38 | + ->setDescription('Modify a cache cluster') |
| 39 | + ->addArgument('cache', InputArgument::OPTIONAL, 'The ID or name of the cache cluster to modify') |
| 40 | + ->addOption('type', null, InputOption::VALUE_REQUIRED, 'The cache cluster type'); |
| 41 | + } |
| 42 | + |
| 43 | + /** |
| 44 | + * {@inheritdoc} |
| 45 | + */ |
| 46 | + protected function perform(Input $input, Output $output) |
| 47 | + { |
| 48 | + $cache = $this->determineCache('Which cache cluster would you like to modify', $input, $output); |
| 49 | + $type = $input->getStringOption('type', true); |
| 50 | + $types = $this->apiClient->getCacheTypes($cache['provider']['id']); |
| 51 | + |
| 52 | + if (null === $type) { |
| 53 | + $type = $output->choice(sprintf('What should the cache cluster type be changed to? <fg=default>(Currently: <comment>%s</comment>)</>', $cache['type']), $types); |
| 54 | + } elseif (!$types->has($type)) { |
| 55 | + throw new InvalidInputException(sprintf('The type "%s" isn\'t a valid cache cluster type', $type)); |
| 56 | + } |
| 57 | + |
| 58 | + if (!$output->confirm('Modifying the cache cluster will cause your cache cluster to become unavailable for a few minutes. Do you want to proceed?', false)) { |
| 59 | + exit; |
| 60 | + } |
| 61 | + |
| 62 | + $this->apiClient->updateCache((int) $cache['id'], $type); |
| 63 | + |
| 64 | + $output->infoWithDelayWarning('Cache cluster modified'); |
| 65 | + } |
| 66 | +} |
0 commit comments