Skip to content

Commit 9271bcc

Browse files
committed
Added an option to exclude cache type while clearing or flushing
1 parent cbca039 commit 9271bcc

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

app/code/Magento/Backend/Console/Command/AbstractCacheManageCommand.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Symfony\Component\Console\Input\InputArgument;
1010
use Symfony\Component\Console\Input\InputInterface;
11+
use Symfony\Component\Console\Input\InputOption;
1112

1213
/**
1314
* @api
@@ -20,6 +21,8 @@ abstract class AbstractCacheManageCommand extends AbstractCacheCommand
2021
*/
2122
const INPUT_KEY_TYPES = 'types';
2223

24+
const EXCLUDE_KEY_TYPES = 'exclude';
25+
2326
/**
2427
* {@inheritdoc}
2528
*/
@@ -30,6 +33,12 @@ protected function configure()
3033
InputArgument::IS_ARRAY,
3134
'Space-separated list of cache types or omit to apply to all cache types.'
3235
);
36+
$this->addOption(
37+
self::EXCLUDE_KEY_TYPES,
38+
'e',
39+
InputOption::VALUE_OPTIONAL,
40+
'Comma separated list of cache types to omit'
41+
);
3342
parent::configure();
3443
}
3544

@@ -46,8 +55,16 @@ protected function getRequestedTypes(InputInterface $input)
4655
$requestedTypes = $input->getArgument(self::INPUT_KEY_TYPES);
4756
$requestedTypes = array_filter(array_map('trim', $requestedTypes), 'strlen');
4857
}
58+
$excludeTypes = $input->getOption(self::EXCLUDE_KEY_TYPES);
4959
if (empty($requestedTypes)) {
50-
return $this->cacheManager->getAvailableTypes();
60+
$cacheTypes = $this->cacheManager->getAvailableTypes();
61+
if (!empty($excludeTypes)) {
62+
foreach (explode(',', $excludeTypes) as $item) {
63+
unset($cacheTypes[array_search($item, $cacheTypes)]);
64+
}
65+
$cacheTypes = array_values($cacheTypes);
66+
}
67+
return $cacheTypes;
5168
} else {
5269
$availableTypes = $this->cacheManager->getAvailableTypes();
5370
$unsupportedTypes = array_diff($requestedTypes, $availableTypes);
@@ -57,6 +74,12 @@ protected function getRequestedTypes(InputInterface $input)
5774
. "'." . PHP_EOL . 'Supported types: ' . join(", ", $availableTypes)
5875
);
5976
}
77+
if (!empty($excludeTypes)) {
78+
foreach (explode(',', $excludeTypes) as $item) {
79+
unset($availableTypes[array_search($item, $availableTypes)]);
80+
}
81+
$availableTypes = array_values($availableTypes);
82+
}
6083
return array_values(array_intersect($availableTypes, $requestedTypes));
6184
}
6285
}

app/code/Magento/Backend/Console/Command/AbstractCacheTypeManageCommand.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
6464
$this->performAction($types);
6565
$output->writeln($this->getDisplayMessage());
6666
$output->writeln(join(PHP_EOL, $types));
67+
$excludeTypes = $input->getOption(self::EXCLUDE_KEY_TYPES);
68+
if (!empty($excludeTypes)) {
69+
$output->writeln('Excluded Cache Type');
70+
foreach (explode(',', $excludeTypes) as $type) {
71+
$output->writeln($type);
72+
}
73+
}
6774

6875
return Cli::RETURN_SUCCESS;
6976
}

0 commit comments

Comments
 (0)