[BUGFIX] Avoid DBAL\Exception on unknown data type in Install Tool
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Service / ClearCacheService.php
1 <?php
2 namespace TYPO3\CMS\Install\Service;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Database\ConnectionPool;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * Basic service to clear caches within the install tool.
22 * This is NOT an API class, it is for internal use in the install tool only.
23 */
24 class ClearCacheService
25 {
26 /**
27 * This clear cache implementation follows a pretty brutal approach.
28 * Goal is to reliably get rid of cache entries, even if some broken
29 * extension is loaded that would kill the backend 'clear cache' action.
30 *
31 * Therefor this method "knows" implementation details of the cache
32 * framework and uses them to clear all file based cache (typo3temp/Cache)
33 * and database caches (tables prefixed with cf_) manually.
34 *
35 * After that ext_tables and ext_localconf of extensions are loaded, those
36 * may register additional caches in the caching framework with different
37 * backend, and will then clear them with the usual flush() method.
38 */
39 public function clearAll()
40 {
41 // Delete typo3temp/Cache
42 GeneralUtility::flushDirectory(PATH_site . 'typo3temp/var/Cache', true, true);
43
44 $bootstrap = \TYPO3\CMS\Core\Core\Bootstrap::getInstance();
45 $bootstrap
46 ->initializeCachingFramework()
47 ->initializePackageManagement(\TYPO3\CMS\Core\Package\PackageManager::class);
48
49 // Get all table names from Default connection starting with 'cf_' and truncate them
50 $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
51 $connection = $connectionPool->getConnectionByName('Default');
52 $tableNames = $connection->getSchemaManager()->listTableNames();
53 foreach ($tableNames as $tableName) {
54 if (strpos($tableName, 'cf_') === 0 || $tableName === 'cache_treelist') {
55 $connection->truncate($tableName);
56 }
57 }
58
59 // check tables on other connections
60 $remappedTables = isset($GLOBALS['TYPO3_CONF_VARS']['DB']['TableMapping'])
61 ? array_keys((array)$GLOBALS['TYPO3_CONF_VARS']['DB']['TableMapping'])
62 : [];
63 foreach ($remappedTables as $tableName) {
64 if (strpos((string)$tableName, 'cf_') === 0 || $tableName === 'cache_treelist') {
65 $connectionPool->getConnectionForTable($tableName)->truncate($tableName);
66 }
67 }
68
69 // From this point on, the code may fatal, if some broken extension is loaded.
70
71 // Use bootstrap to load all ext_localconf and ext_tables
72 $bootstrap
73 ->loadTypo3LoadedExtAndExtLocalconf(false)
74 ->defineLoggingAndExceptionConstants()
75 ->unsetReservedGlobalVariables()
76 ->loadBaseTca(false)
77 ->loadExtTables(false);
78
79 // The cache manager is already instantiated in the install tool
80 // with some hacked settings to disable caching of extbase and fluid.
81 // We want a "fresh" object here to operate on a different cache setup.
82 // cacheManager implements SingletonInterface, so the only way to get a "fresh"
83 // instance is by circumventing makeInstance and/or the objectManager and
84 // using new directly!
85 $cacheManager = new \TYPO3\CMS\Core\Cache\CacheManager();
86 $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
87 $cacheManager->flushCaches();
88 }
89 }