diff --git a/typo3/sysext/install/Classes/Service/ClearCacheService.php b/typo3/sysext/install/Classes/Service/ClearCacheService.php index 7ce5f79fc4f18439c62cdbd193d34a5424fd36e9..0be3c7b7d5a9161f3549dac8a84695bec776a639 100644 --- a/typo3/sysext/install/Classes/Service/ClearCacheService.php +++ b/typo3/sysext/install/Classes/Service/ClearCacheService.php @@ -48,21 +48,23 @@ class ClearCacheService ->initializeCachingFramework() ->initializePackageManagement(\TYPO3\CMS\Core\Package\PackageManager::class); - // Get all table names starting with 'cf_' and truncate them - $database = $this->getDatabaseConnection(); - $tables = $database->admin_get_tables(); + // Get all table names from Default connection starting with 'cf_' and truncate them + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); + $connection = $connectionPool->getConnectionByName('Default'); + $tables = $connection->getSchemaManager()->listTables(); foreach ($tables as $table) { - $tableName = $table['Name']; - if (substr($tableName, 0, 3) === 'cf_') { - GeneralUtility::makeInstance(ConnectionPool::class) - ->getConnectionForTable($tableName) - ->truncate($tableName); - } elseif ($tableName === 'cache_treelist') { - // cache_treelist is not implemented in the caching framework. - // clear this table manually - GeneralUtility::makeInstance(ConnectionPool::class) - ->getConnectionForTable('cache_treelist') - ->truncate('cache_treelist'); + if (strpos($table->getName(), 'cf_') === 0 || $table->getName() === 'cache_treelist') { + $connection->truncate($table->getName()); + } + } + + // check tables on other connections + $remappedTables = isset($GLOBALS['TYPO3_CONF_VARS']['DB']['TableMapping']) + ? array_keys((array)$GLOBALS['TYPO3_CONF_VARS']['DB']['TableMapping']) + : []; + foreach ($remappedTables as $tableName) { + if (strpos((string)$tableName, 'cf_') === 0 || $tableName === 'cache_treelist') { + $connectionPool->getConnectionForTable($tableName)->truncate($tableName); } } @@ -86,28 +88,4 @@ class ClearCacheService $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']); $cacheManager->flushCaches(); } - - /** - * Get a database instance. - * - * @TODO: This method is a copy from AbstractAction. Review them and extract to service - * @return \TYPO3\CMS\Core\Database\DatabaseConnection - */ - protected function getDatabaseConnection() - { - static $database; - if (!is_object($database)) { - /** @var \TYPO3\CMS\Core\Database\DatabaseConnection $database */ - $database = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\DatabaseConnection::class); - $database->setDatabaseUsername($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['user']); - $database->setDatabasePassword($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['password']); - $database->setDatabaseHost($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['host']); - $database->setDatabasePort($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['port']); - $database->setDatabaseSocket($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['unix_socket']); - $database->setDatabaseName($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default']['dbname']); - $database->initialize(); - $database->connectDB(); - } - return $database; - } }