8000 [FrameworkBundle] Add `--exclude` option to the `cache:pool:clear` co… · symfony/symfony@a9a13cc · GitHub
[go: up one dir, main page]

Skip to content

Commit a9a13cc

Browse files
committed
[FrameworkBundle] Add --exclude option to the cache:pool:clear command
1 parent bd04cda commit a9a13cc

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CHANGELOG
66

77
* Add native return type to `Translator` and to `Application::reset()`
88
* Deprecate the integration of Doctrine annotations, either uninstall the `doctrine/annotations` package or disable the integration by setting `framework.annotations` to `false`
9+
* Add `--exclude` option to the `cache:pool:clear` command
910

1011
6.3
1112
---

src/Symfony/Bundle/FrameworkBundle/Command/CachePoolClearCommand.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ protected function configure(): void
5353
new InputArgument('pools', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, 'A list of cache pools or cache pool clearers'),
5454
])
5555
->addOption('all', null, InputOption::VALUE_NONE, 'Clear all cache pools')
56+
->addOption('exclude', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'A list of cache pools or cache pool clearers to exclude')
5657
->setHelp(<<<'EOF'
5758
The <info>%command.name%</info> command clears the given cache pools or cache pool clearers.
5859
@@ -70,12 +71,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7071
$clearers = [];
7172

7273
$poolNames = $input->getArgument('pools');
74+
$excludedPoolNames = $input->getOption('exclude');
7375
if ($input->getOption('all')) {
7476
if (!$this->poolNames) {
7577
throw new InvalidArgumentException('Could not clear all cache pools, try specifying a specific pool or cache clearer.');
7678
}
7779

78-
$io->comment('Clearing all cache pools...');
80+
if (!$excludedPoolNames) {
81+
$io->comment('Clearing all cache pools...');
82+
}
83+
7984
$poolNames = $this->poolNames;
8085
} elseif (!$poolNames) {
8186
throw new InvalidArgumentException('Either specify at least one pool name, or provide the --all option to clear all pools.');
@@ -97,6 +102,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
97102
}
98103
}
99104

105+
foreach ($excludedPoolNames as $id) {
106+
if (isset($pools[$id])) {
107+
unset($pools[$id]);
108+
} elseif (isset($clearers[$id])) {
109+
unset($clearers[$id]);
110+
}
111+
}
112+
100113
foreach ($clearers as $id => $clearer) {
101114
$io->comment(sprintf('Calling cache clearer: <info>%s</info>', $id));
102115
$clearer->clear($kernel->getContainer()->getParameter('kernel.cache_dir'));

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/CachePoolClearCommandTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,17 @@ public function testClearFailed()
132132
$this->assertStringContainsString('[WARNING] Cache pool "cache.public_pool" could not be cleared.', $tester->getDisplay());
133133
}
134134

135+
public function testExcludedPool()
136+
{
137+
$tester = $this->createCommandTester(['cache.app_clearer']);
138+
$tester->execute(['--all' => true, '--exclude' => ['cache.app_clearer']], ['decorated' => false]);
139+
140+
$tester->assertCommandIsSuccessful('cache:pool:clear exits with 0 in case of success');
141+
$this->assertStringNotContainsString('Clearing all cache pools...', $tester->getDisplay());
142+
$this->assertStringNotContainsString('Calling cache clearer: cache.app_clearer', $tester->getDisplay());
143+
$this->assertStringContainsString('[OK] Cache was successfully cleared.', $tester->getDisplay());
144+
}
145+
135146
private function createCommandTester(array $poolNames = null)
136147
{
137148
$application = new Application(static::$kernel);

0 commit comments

Comments
 (0)
0