From 50dfd4423d884753868ed3a4711778ec1e7b10b9 Mon Sep 17 00:00:00 2001 From: Carl Alexander Date: Tue, 6 Feb 2024 16:22:23 -0500 Subject: [PATCH] feat: add `cache:modify` command --- composer.json | 2 +- src/ApiClient.php | 8 +++ src/Command/Cache/ModifyCacheCommand.php | 66 ++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/Command/Cache/ModifyCacheCommand.php diff --git a/composer.json b/composer.json index 494f21c..266d8c5 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "symfony/polyfill-php80": "^1.27", "symfony/process": "^5.4|^6.0", "symfony/yaml": "^5.4|^6.0", - "ymirapp/ymir-sdk-php": "^1.0.0" + "ymirapp/ymir-sdk-php": "^1.1.0" }, "require-dev": { "fakerphp/faker": "^1.17", diff --git a/src/ApiClient.php b/src/ApiClient.php index 6746c8c..4b4d3ad 100644 --- a/src/ApiClient.php +++ b/src/ApiClient.php @@ -777,6 +777,14 @@ public function startDeployment(int $deploymentId) $this->client->startDeployment($deploymentId); } + /** + * Update the given cache cluster. + */ + public function updateCache(int $cacheId, string $type) + { + $this->client->updateCache($cacheId, $type); + } + /** * Update the given database server. */ diff --git a/src/Command/Cache/ModifyCacheCommand.php b/src/Command/Cache/ModifyCacheCommand.php new file mode 100644 index 0000000..741dc1d --- /dev/null +++ b/src/Command/Cache/ModifyCacheCommand.php @@ -0,0 +1,66 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Ymir\Cli\Command\Cache; + +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputOption; +use Ymir\Cli\Console\Input; +use Ymir\Cli\Console\Output; +use Ymir\Cli\Exception\InvalidInputException; + +class ModifyCacheCommand extends AbstractCacheCommand +{ + /** + * The name of the command. + * + * @var string + */ + public const NAME = 'cache:modify'; + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName(self::NAME) + ->setDescription('Modify a cache cluster') + ->addArgument('cache', InputArgument::OPTIONAL, 'The ID or name of the cache cluster to modify') + ->addOption('type', null, InputOption::VALUE_REQUIRED, 'The cache cluster type'); + } + + /** + * {@inheritdoc} + */ + protected function perform(Input $input, Output $output) + { + $cache = $this->determineCache('Which cache cluster would you like to modify', $input, $output); + $type = $input->getStringOption('type', true); + $types = $this->apiClient->getCacheTypes($cache['provider']['id']); + + if (null === $type) { + $type = $output->choice(sprintf('What should the cache cluster type be changed to? (Currently: %s)', $cache['type']), $types); + } elseif (!$types->has($type)) { + throw new InvalidInputException(sprintf('The type "%s" isn\'t a valid cache cluster type', $type)); + } + + 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)) { + exit; + } + + $this->apiClient->updateCache((int) $cache['id'], $type); + + $output->infoWithDelayWarning('Cache cluster modified'); + } +}