‪TYPO3CMS  9.5
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 
21 
27 {
41  public function ‪clearAll()
42  {
43  // Delete typo3temp/Cache
44  GeneralUtility::flushDirectory(‪Environment::getVarPath() . '/cache', true, true);
45 
46  // Get all table names from Default connection starting with 'cf_' and truncate them
47  $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
48  $connection = $connectionPool->getConnectionByName('Default');
49  $tableNames = $connection->getSchemaManager()->listTableNames();
50  foreach ($tableNames as $tableName) {
51  if (strpos($tableName, 'cf_') === 0 || $tableName === 'cache_treelist') {
52  $connection->truncate($tableName);
53  }
54  }
55 
56  // check tables on other connections
57  $remappedTables = isset(‪$GLOBALS['TYPO3_CONF_VARS']['DB']['TableMapping'])
58  ? array_keys((array)‪$GLOBALS['TYPO3_CONF_VARS']['DB']['TableMapping'])
59  : [];
60  foreach ($remappedTables as $tableName) {
61  if (strpos((string)$tableName, 'cf_') === 0 || $tableName === 'cache_treelist') {
62  $connectionPool->getConnectionForTable($tableName)->truncate($tableName);
63  }
64  }
65 
66  // From this point on, the code may fatal, if some broken extension is loaded.
67 
68  // Use bootstrap to load all ext_localconf and ext_tables
73 
74  // The cache manager is already instantiated in the install tool
75  // with some hacked settings to disable caching of extbase and fluid.
76  // We want a "fresh" object here to operate on a different cache setup.
77  // cacheManager implements SingletonInterface, so the only way to get a "fresh"
78  // instance is by circumventing makeInstance and/or the objectManager and
79  // using new directly!
80  $cacheManager = new \TYPO3\CMS\Core\Cache\CacheManager();
81  $cacheManager->setCacheConfigurations(‪$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
82  $cacheManager->flushCaches();
83  }
84 }
‪TYPO3\CMS\Core\Core\Bootstrap\loadBaseTca
‪static Bootstrap null loadBaseTca(bool $allowCaching=true, FrontendInterface $coreCache=null)
Definition: Bootstrap.php:832
‪TYPO3\CMS\Core\Core\Bootstrap\unsetReservedGlobalVariables
‪static Bootstrap null unsetReservedGlobalVariables()
Definition: Bootstrap.php:808
‪TYPO3\CMS\Core\Core\Bootstrap\loadTypo3LoadedExtAndExtLocalconf
‪static Bootstrap null loadTypo3LoadedExtAndExtLocalconf($allowCaching=true, FrontendInterface $coreCache=null)
Definition: Bootstrap.php:551
‪TYPO3\CMS\Core\Core\Bootstrap\loadExtTables
‪static Bootstrap null loadExtTables(bool $allowCaching=true)
Definition: Bootstrap.php:864
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Core\Environment
Definition: Environment.php:39
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:50
‪TYPO3\CMS\Install\Service\ClearCacheService\clearAll
‪clearAll()
Definition: ClearCacheService.php:41
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Install\Service\ClearCacheService
Definition: ClearCacheService.php:27
‪TYPO3\CMS\Install\Service
Definition: ClearCacheService.php:2
‪TYPO3\CMS\Core\Core\Environment\getVarPath
‪static string getVarPath()
Definition: Environment.php:165