diff --git a/app/code/Magento/Backend/Console/Command/AbstractCacheManageCommand.php b/app/code/Magento/Backend/Console/Command/AbstractCacheManageCommand.php index ac7e9976c5715..86762afa51444 100644 --- a/app/code/Magento/Backend/Console/Command/AbstractCacheManageCommand.php +++ b/app/code/Magento/Backend/Console/Command/AbstractCacheManageCommand.php @@ -8,20 +8,19 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; -/** - * @api - * @since 100.0.2 - */ abstract class AbstractCacheManageCommand extends AbstractCacheCommand { /** * Input argument types */ - const INPUT_KEY_TYPES = 'types'; + public const INPUT_KEY_TYPES = 'types'; + + public const EXCLUDE_KEY_TYPES = 'exclude'; /** - * {@inheritdoc} + * @inheritdoc */ protected function configure() { @@ -30,6 +29,12 @@ protected function configure() InputArgument::IS_ARRAY, 'Space-separated list of cache types or omit to apply to all cache types.' ); + $this->addOption( + self::EXCLUDE_KEY_TYPES, + 'e', + InputOption::VALUE_OPTIONAL, + 'Comma separated list of cache types to omit' + ); parent::configure(); } @@ -46,8 +51,16 @@ protected function getRequestedTypes(InputInterface $input) $requestedTypes = $input->getArgument(self::INPUT_KEY_TYPES); $requestedTypes = array_filter(array_map('trim', $requestedTypes), 'strlen'); } + $excludeTypes = $input->getOption(self::EXCLUDE_KEY_TYPES); if (empty($requestedTypes)) { - return $this->cacheManager->getAvailableTypes(); + $cacheTypes = $this->cacheManager->getAvailableTypes(); + if (!empty($excludeTypes)) { + foreach (explode(',', $excludeTypes) as $item) { + unset($cacheTypes[array_search($item, $cacheTypes)]); + } + $cacheTypes = array_values($cacheTypes); + } + return $cacheTypes; } else { $availableTypes = $this->cacheManager->getAvailableTypes(); $unsupportedTypes = array_diff($requestedTypes, $availableTypes); @@ -57,6 +70,12 @@ protected function getRequestedTypes(InputInterface $input) . "'." . PHP_EOL . 'Supported types: ' . join(", ", $availableTypes) ); } + if (!empty($excludeTypes)) { + foreach (explode(',', $excludeTypes) as $item) { + unset($availableTypes[array_search($item, $availableTypes)]); + } + $availableTypes = array_values($availableTypes); + } return array_values(array_intersect($availableTypes, $requestedTypes)); } } diff --git a/app/code/Magento/Backend/Console/Command/AbstractCacheTypeManageCommand.php b/app/code/Magento/Backend/Console/Command/AbstractCacheTypeManageCommand.php index ba24dcc49b6bc..700715816e6be 100644 --- a/app/code/Magento/Backend/Console/Command/AbstractCacheTypeManageCommand.php +++ b/app/code/Magento/Backend/Console/Command/AbstractCacheTypeManageCommand.php @@ -64,6 +64,13 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->performAction($types); $output->writeln($this->getDisplayMessage()); $output->writeln(join(PHP_EOL, $types)); + $excludeTypes = $input->getOption(self::EXCLUDE_KEY_TYPES); + if (!empty($excludeTypes)) { + $output->writeln('Excluded Cache Type'); + foreach (explode(',', $excludeTypes) as $type) { + $output->writeln($type); + } + } return Cli::RETURN_SUCCESS; }