Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Don't try to flush DB caches after install #520

Merged
merged 1 commit into from
Jun 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions Classes/Command/CacheCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,16 @@ public function __construct(CacheService $cacheService, CommandDispatcher $comma
* Flushes TYPO3 core caches first and after that, flushes caches from extensions.
*
* @param bool $force Cache is forcibly flushed (low level operations are performed)
* @param bool $filesOnly Only file caches are flushed (low level operations are performed)
* @throws \Helhum\Typo3Console\Mvc\Cli\FailedSubProcessCommandException
*/
public function flushCommand($force = false)
public function flushCommand($force = false, $filesOnly = false)
{
$this->cacheService->flush($force);
$this->cacheService->flush($force, $filesOnly);
if ($filesOnly) {
$this->outputLine('Force flushed file caches.');
return;
}
$this->commandDispatcher->executeCommand('cache:flushcomplete');
$this->outputLine(sprintf('%slushed all caches.', $force ? 'Force f' : 'F'));
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Install/CliSetupRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function setup($interactiveSetup, array $givenRequestArguments)
$this->output->outputLine('<warning>The error message was "%s"</warning>', [$e->getPrevious()->getMessage()]);
}
// Flush caches, as the extension list has changed
$this->commandDispatcher->executeCommand('cache:flush', ['--force' => true]);
$this->commandDispatcher->executeCommand('cache:flush', ['--files-only' => true]);
$this->commandDispatcher->executeCommand('extension:setupactive');
}

Expand Down
29 changes: 21 additions & 8 deletions Classes/Service/CacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ public function __construct(CacheManager $cacheManager, ConfigurationService $co
* Flushes all caches
*
* @param bool $force
* @param bool $onlyFileCaches
*/
public function flush($force = false)
public function flush($force = false, $onlyFileCaches = false)
{
if ($force) {
$this->forceFlushCoreFileAndDatabaseCaches();
if ($force || $onlyFileCaches) {
$this->forceFlushCoreFileAndDatabaseCaches($onlyFileCaches);
}
$this->cacheManager->flushCaches();
}
Expand Down Expand Up @@ -167,23 +168,30 @@ protected function ensureCacheGroupsExist($groups)

/**
* Recursively delete cache directory and truncate all DB tables prefixed with 'cf_'
*
* @param bool $onlyFileCaches
*/
protected function forceFlushCoreFileAndDatabaseCaches()
protected function forceFlushCoreFileAndDatabaseCaches($onlyFileCaches)
{
if (class_exists(ConnectionPool::class)) {
$this->_forceFlushCoreFileAndDatabaseCaches();
$this->_forceFlushCoreFileAndDatabaseCaches($onlyFileCaches);
} else {
$this->_legacyForceFlushCoreFileAndDatabaseCaches();
$this->_legacyForceFlushCoreFileAndDatabaseCaches($onlyFileCaches);
}
}

/**
* Recursively delete cache directory and truncate all DB tables prefixed with 'cf_'
*
* @deprecated Will be removed once TYPO3 7.6 support is removed
* @param bool $onlyFileCaches
*/
private function _legacyForceFlushCoreFileAndDatabaseCaches()
private function _legacyForceFlushCoreFileAndDatabaseCaches($onlyFileCaches)
{
GeneralUtility::flushDirectory(PATH_site . 'typo3temp/Cache', true);
if ($onlyFileCaches) {
return;
}
// Get all table names starting with 'cf_' and truncate them
/** @var DatabaseConnection $db */
$db = $GLOBALS['TYPO3_DB'];
Expand All @@ -198,11 +206,16 @@ private function _legacyForceFlushCoreFileAndDatabaseCaches()

/**
* Recursively delete cache directory and truncate all DB tables prefixed with 'cf_'
*
* @param bool $onlyFileCaches
*/
private function _forceFlushCoreFileAndDatabaseCaches()
private function _forceFlushCoreFileAndDatabaseCaches($onlyFileCaches)
{
// Delete typo3temp/Cache
GeneralUtility::flushDirectory(PATH_site . 'typo3temp/var/Cache', true);
if ($onlyFileCaches) {
return;
}
// Get all table names from Default connection starting with 'cf_' and truncate them
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
$connection = $connectionPool->getConnectionByName('Default');
Expand Down
2 changes: 2 additions & 0 deletions Documentation/CommandReference/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ Options

``--force``
Cache is forcibly flushed (low level operations are performed)
``--files-only``
Only file caches are flushed (low level operations are performed)



Expand Down
9 changes: 9 additions & 0 deletions Tests/Functional/Command/CacheCommandControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ public function cacheCanBeForceFlushedFlushed()
$this->assertSame('Force flushed all caches.', $output);
}

/**
* @test
*/
public function fileCachesCanBeForceFlushedFlushed()
{
$output = $this->commandDispatcher->executeCommand('cache:flush', ['--files-only' => true]);
$this->assertSame('Force flushed file caches.', $output);
}

/**
* @test
*/
Expand Down