TYPO3 CMS  TYPO3_8-7
ClearCacheService.php
Go to the documentation of this file.
1 <?php
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 
19 
25 {
39  public function clearAll()
40  {
41  // Delete typo3temp/Cache
42  GeneralUtility::flushDirectory(PATH_site . 'typo3temp/var/Cache', true, true);
43 
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  ->initializeTypo3DbGlobal()
77  ->loadBaseTca(false)
78  ->loadExtTables(false);
79 
80  // The cache manager is already instantiated in the install tool
81  // with some hacked settings to disable caching of extbase and fluid.
82  // We want a "fresh" object here to operate on a different cache setup.
83  // cacheManager implements SingletonInterface, so the only way to get a "fresh"
84  // instance is by circumventing makeInstance and/or the objectManager and
85  // using new directly!
86  $cacheManager = new \TYPO3\CMS\Core\Cache\CacheManager();
87  $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
88  $cacheManager->flushCaches();
89  }
90 }
static flushDirectory($directory, $keepOriginalDirectory=false, $flushOpcodeCache=false)
static makeInstance($className,... $constructorArguments)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']