TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
ClearCacheService.php
Go to the documentation of this file.
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 
19 
25 {
41  public function clearAll()
42  {
43  // Delete typo3temp/Cache
44  GeneralUtility::flushDirectory(PATH_site . 'typo3temp/var/Cache', true, true);
45 
47  $bootstrap
48  ->initializeCachingFramework()
49  ->initializePackageManagement(\TYPO3\CMS\Core\Package\PackageManager::class);
50 
51  // Get all table names from Default connection starting with 'cf_' and truncate them
52  $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
53  $connection = $connectionPool->getConnectionByName('Default');
54  $tables = $connection->getSchemaManager()->listTables();
55  foreach ($tables as $table) {
56  if (strpos($table->getName(), 'cf_') === 0 || $table->getName() === 'cache_treelist') {
57  $connection->truncate($table->getName());
58  }
59  }
60 
61  // check tables on other connections
62  $remappedTables = isset($GLOBALS['TYPO3_CONF_VARS']['DB']['TableMapping'])
63  ? array_keys((array)$GLOBALS['TYPO3_CONF_VARS']['DB']['TableMapping'])
64  : [];
65  foreach ($remappedTables as $tableName) {
66  if (strpos((string)$tableName, 'cf_') === 0 || $tableName === 'cache_treelist') {
67  $connectionPool->getConnectionForTable($tableName)->truncate($tableName);
68  }
69  }
70 
71  // From this point on, the code may fatal, if some broken extension is loaded.
72 
73  // Use bootstrap to load all ext_localconf and ext_tables
74  $bootstrap
75  ->loadTypo3LoadedExtAndExtLocalconf(false)
76  ->defineLoggingAndExceptionConstants()
77  ->unsetReservedGlobalVariables()
78  ->initializeTypo3DbGlobal()
79  ->loadExtensionTables(false);
80 
81  // The cache manager is already instantiated in the install tool
82  // with some hacked settings to disable caching of extbase and fluid.
83  // We want a "fresh" object here to operate on a different cache setup.
84  // cacheManager implements SingletonInterface, so the only way to get a "fresh"
85  // instance is by circumventing makeInstance and/or the objectManager and
86  // using new directly!
87  $cacheManager = new \TYPO3\CMS\Core\Cache\CacheManager();
88  $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
89  $cacheManager->flushCaches();
90  }
91 }
if(TYPO3_MODE=== 'BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static makeInstance($className,...$constructorArguments)
static flushDirectory($directory, $keepOriginalDirectory=false, $flushOpcodeCache=false)