forked from TYPO3-Console/TYPO3-Console
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGIFX] Simplify and harden cache:flush command
This command needs to be as resilient as possible, therefore many dependencies from the classes have been removed, especially the dependency to Extbase DI API, which requires caching and lead to chicken/egg issues, when we changed our API. Additionally we now removed the --force flag, as in practice this options is used all the time, so we make it default and non optional to low level remove files and truncate db tables. Fixes: TYPO3-Console#770
- Loading branch information
Showing
8 changed files
with
155 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<?php | ||
declare(strict_types=1); | ||
namespace Helhum\Typo3Console\Command\Cache; | ||
|
||
/* | ||
* This file is part of the TYPO3 Console project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read | ||
* LICENSE file that was distributed with this source code. | ||
* | ||
*/ | ||
|
||
use Helhum\Typo3Console\Command\AbstractConvertedCommand; | ||
use Helhum\Typo3Console\Core\Booting\RunLevel; | ||
use Helhum\Typo3Console\Mvc\Cli\Symfony\Application; | ||
use Helhum\Typo3Console\Service\CacheLowLevelCleaner; | ||
use Helhum\Typo3Console\Service\CacheService; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
class CacheFlushCommand extends AbstractConvertedCommand | ||
{ | ||
protected function configure() | ||
{ | ||
$this->setDescription('Flush all caches'); | ||
$this->setHelp( | ||
<<<'EOH' | ||
Flushes TYPO3 core caches first and after that, flushes caches from extensions. | ||
EOH | ||
); | ||
|
||
$this->setDefinition($this->createCompleteInputDefinition()); | ||
} | ||
|
||
protected function createNativeDefinition(): array | ||
{ | ||
return [ | ||
new InputOption( | ||
'files-only', | ||
null, | ||
InputOption::VALUE_NONE, | ||
'Only file caches are flushed' | ||
), | ||
]; | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$filesOnly = $input->getOption('files-only'); | ||
$application = $this->getApplication(); | ||
if (!$application instanceof Application) { | ||
throw new \RuntimeException('Fatal error. Application is not properly initialized.', 1546617606); | ||
} | ||
$filesOnly = $filesOnly || !$application->isFullyCapable(); | ||
|
||
$io = new SymfonyStyle($input, $output); | ||
|
||
$lowLevelCleaner = new CacheLowLevelCleaner(); | ||
$lowLevelCleaner->forceFlushCachesFiles(); | ||
if ($filesOnly) { | ||
$io->writeln('Flushed all file caches.'); | ||
// No need to proceed, as files only flush is requested | ||
return; | ||
} | ||
|
||
$lowLevelCleaner->forceFlushDatabaseCacheTables(); | ||
$application->boot(RunLevel::LEVEL_FULL); | ||
|
||
$cacheService = new CacheService(); | ||
$cacheService->flush(); | ||
$cacheService->flushCachesWithDataHandler(); | ||
|
||
$io->writeln('Flushed all caches.'); | ||
} | ||
|
||
/** | ||
* @deprecated will be removed with 6.0 | ||
* | ||
* @return array | ||
*/ | ||
protected function createDeprecatedDefinition(): array | ||
{ | ||
return [ | ||
new InputOption( | ||
'force', | ||
null, | ||
InputOption::VALUE_NONE, | ||
'Cache is forcibly flushed (low level operations are performed)' | ||
), | ||
new InputArgument( | ||
'force', | ||
null, | ||
'Cache is forcibly flushed (low level operations are performed)', | ||
false | ||
), | ||
new InputArgument( | ||
'filesOnly', | ||
null, | ||
'Only file caches are flushed', | ||
false | ||
), | ||
]; | ||
} | ||
|
||
/** | ||
* @deprecated will be removed with 6.0 | ||
*/ | ||
protected function handleDeprecatedArgumentsAndOptions(InputInterface $input, OutputInterface $output) | ||
{ | ||
if ($input->getArgument('force') | ||
|| $input->getArgument('filesOnly') | ||
|| $input->getOption('files-only') | ||
|| $input->getOption('force') | ||
) { | ||
$io = new SymfonyStyle($input, $output); | ||
$io->getErrorStyle()->writeln('<warning>All options and arguments are deprecated and have no effect any more.</warning>'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.