Example #1
0
 /**
  * This clear cache implementation follows a pretty brutal approach.
  * Goal is to reliably get rid of cache entries, even if some broken
  * extension is loaded that would kill the backend 'clear cache' action.
  *
  * Therefor this method "knows" implementation details of the cache
  * framework and uses them to clear all file based cache (typo3temp/Cache)
  * and database caches (tables prefixed with cf_) manually.
  *
  * After that ext_tables and ext_localconf of extensions are loaded, those
  * may register additional caches in the caching framework with different
  * backend, and will then clear them with the usual flush() method.
  *
  * @return void
  */
 public function clearAll()
 {
     // Delete typo3temp/Cache
     GeneralUtility::flushDirectory(PATH_site . 'typo3temp/var/Cache', true, true);
     $bootstrap = \TYPO3\CMS\Core\Core\Bootstrap::getInstance();
     $bootstrap->initializeCachingFramework()->initializePackageManagement(\TYPO3\CMS\Core\Package\PackageManager::class);
     // 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) {
         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);
         }
     }
     // From this point on, the code may fatal, if some broken extension is loaded.
     // Use bootstrap to load all ext_localconf and ext_tables
     $bootstrap->loadTypo3LoadedExtAndExtLocalconf(false)->defineLoggingAndExceptionConstants()->unsetReservedGlobalVariables()->initializeTypo3DbGlobal()->loadExtensionTables(false);
     // The cache manager is already instantiated in the install tool
     // with some hacked settings to disable caching of extbase and fluid.
     // We want a "fresh" object here to operate on a different cache setup.
     // cacheManager implements SingletonInterface, so the only way to get a "fresh"
     // instance is by circumventing makeInstance and/or the objectManager and
     // using new directly!
     $cacheManager = new \TYPO3\CMS\Core\Cache\CacheManager();
     $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
     $cacheManager->flushCaches();
 }
 /**
  * This clear cache implementation follows a pretty brutal approach.
  * Goal is to reliably get rid of cache entries, even if some broken
  * extension is loaded that would kill the backend 'clear cache' action.
  *
  * Therefor this method "knows" implementation details of the cache
  * framework and uses them to clear all file based cache (typo3temp/Cache)
  * and database caches (tables prefixed with cf_) manually.
  *
  * After that ext_tables and ext_localconf of extensions are loaded, those
  * may register additional caches in the caching framework with different
  * backend, and will then clear them with the usual flush() method.
  *
  * @return void
  */
 public function clearAll()
 {
     // Delete typo3temp/Cache
     GeneralUtility::flushDirectory(PATH_site . 'typo3temp/var/Cache', true, true);
     $bootstrap = \TYPO3\CMS\Core\Core\Bootstrap::getInstance();
     $bootstrap->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();
     foreach ($tables as $table) {
         $tableName = $table['Name'];
         if (substr($tableName, 0, 3) === 'cf_') {
             $database->exec_TRUNCATEquery($tableName);
         } elseif ($tableName === 'cache_treelist') {
             // cache_treelist is not implemented in the caching framework.
             // clear this table manually
             $database->exec_TRUNCATEquery('cache_treelist');
         }
     }
     // From this point on, the code may fatal, if some broken extension is loaded.
     // Use bootstrap to load all ext_localconf and ext_tables
     $bootstrap->loadTypo3LoadedExtAndExtLocalconf(false)->defineLoggingAndExceptionConstants()->unsetReservedGlobalVariables()->initializeTypo3DbGlobal()->loadExtensionTables(false);
     // The cache manager is already instantiated in the install tool
     // with some hacked settings to disable caching of extbase and fluid.
     // We want a "fresh" object here to operate on a different cache setup.
     // cacheManager implements SingletonInterface, so the only way to get a "fresh"
     // instance is by circumventing makeInstance and/or the objectManager and
     // using new directly!
     $cacheManager = new \TYPO3\CMS\Core\Cache\CacheManager();
     $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
     // Cache manager needs cache factory. cache factory injects itself to manager in __construct()
     new \TYPO3\CMS\Core\Cache\CacheFactory('production', $cacheManager);
     $cacheManager->flushCaches();
 }
 /**
  * Clear all caches.
  *
  * @param bool $hard
  * @return void
  */
 public function clearAllCaches($hard = FALSE)
 {
     if (!$hard) {
         $this->dataHandler->clear_cacheCmd('all');
     } else {
         GeneralUtility::rmdir(PATH_site . 'typo3temp/Cache', TRUE);
         $cacheManager = new \TYPO3\CMS\Core\Cache\CacheManager();
         $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
         new \TYPO3\CMS\Core\Cache\CacheFactory('production', $cacheManager);
         $cacheManager->flushCaches();
     }
 }
Example #4
0
 /**
  * @test
  */
 public function flushCachesCallsTheFlushMethodOfAllRegisteredCaches()
 {
     $manager = new \TYPO3\CMS\Core\Cache\CacheManager();
     $cache1 = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE);
     $cache1->expects($this->atLeastOnce())->method('getIdentifier')->will($this->returnValue('cache1'));
     $cache1->expects($this->once())->method('flush');
     $manager->registerCache($cache1);
     $cache2 = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend', array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag'), array(), '', FALSE);
     $cache2->expects($this->once())->method('flush');
     $manager->registerCache($cache2);
     $manager->flushCaches();
 }