Skip to content

Commit d651874

Browse files
committed
feature #51058 [FrameworkBundle] Add --exclude option to the cache:pool:clear command (MatTheCat)
This PR was merged into the 6.4 branch. Discussion ---------- [FrameworkBundle] Add `--exclude` option to the `cache:pool:clear` command | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #51023 | License | MIT | Doc PR | symfony/symfony-docs#18595 For now this PR just ignores excluded pools/clearers when they don’t exist or wouldn’t be cleared/run anyways. Not sure what the best DX would be 🤔 Commits ------- 21d0348376 [FrameworkBundle] Add `--exclude` option to the `cache:pool:clear` command
2 parents f6d319d + 1865362 commit d651874

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

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
---

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;

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)