Skip to content

Commit 21d0348

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

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ CHANGELOG
2929
* Add support for relative URLs in BrowserKit's redirect assertion
3030
* Change BrowserKitAssertionsTrait::getClient() to be protected
3131
* Deprecate the `framework.asset_mapper.provider` config option
32+
* Add `--exclude` option to the `cache:pool:clear` command
3233

3334
6.3
3435
---

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

Lines changed: 8 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,17 +71,23 @@ 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.');
8287
}
8388

89+
$poolNames = array_diff($poolNames, $excludedPoolNames);
90+
8491
foreach ($poolNames as $id) {
8592
if ($this->poolClearer->hasPool($id)) {
8693
$pools[$id] = $id;

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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy