예제 #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();
     }
 }
 /**
  * @test
  */
 public function executeDoesNotCallCollectGarbageOfNotConfiguredBackend()
 {
     $cache = $this->getMock(\TYPO3\CMS\Core\Cache\Frontend\StringFrontend::class, array(), array(), '', false);
     $cache->expects($this->any())->method('getIdentifier')->will($this->returnValue('cache'));
     $cache->expects($this->never())->method('collectGarbage');
     $mockCacheManager = new \TYPO3\CMS\Core\Cache\CacheManager();
     $mockCacheManager->registerCache($cache);
     GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $mockCacheManager);
     $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] = array('cache' => array('frontend' => \TYPO3\CMS\Core\Cache\Frontend\StringFrontend::class, 'backend' => \TYPO3\CMS\Core\Cache\Backend\AbstractBackend::class));
     /** @var \TYPO3\CMS\Scheduler\Task\CachingFrameworkGarbageCollectionTask|\PHPUnit_Framework_MockObject_MockObject $subject */
     $subject = $this->getMock(\TYPO3\CMS\Scheduler\Task\CachingFrameworkGarbageCollectionTask::class, array('dummy'), array(), '', false);
     $subject->selectedBackends = array(\TYPO3\CMS\Core\Cache\Backend\NullBackend::class);
     $subject->execute();
 }
예제 #5
0
 /**
  * Initialize caching framework, and re-initializes it (e.g. in the install tool) by recreating the instances
  * again despite the Singleton instance
  *
  * @return Bootstrap
  * @internal This is not a public API method, do not use in own extensions
  */
 public function initializeCachingFramework()
 {
     $cacheManager = new \TYPO3\CMS\Core\Cache\CacheManager();
     $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
     GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $cacheManager);
     $cacheFactory = new \TYPO3\CMS\Core\Cache\CacheFactory('production', $cacheManager);
     GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheFactory::class, $cacheFactory);
     $this->setEarlyInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $cacheManager);
     return $this;
 }
예제 #6
0
 /**
  * @test
  */
 public function getCacheCreatesCacheInstanceWithFallbackToDefaultBackenOptions()
 {
     $manager = new \TYPO3\CMS\Core\Cache\CacheManager();
     $cacheIdentifier = $this->getUniqueId('Test');
     $cacheObjectName = 'testCache';
     $backendObjectName = 'testBackend';
     $configuration = array($cacheIdentifier => array('frontend' => $cacheObjectName, 'backend' => $backendObjectName));
     $factory = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheFactory', array('create'), array(), '', FALSE);
     $factory->expects($this->once())->method('create')->with($cacheIdentifier, $cacheObjectName, $backendObjectName, array());
     $manager->injectCacheFactory($factory);
     $manager->setCacheConfigurations($configuration);
     $manager->getCache($cacheIdentifier);
 }
예제 #7
0
파일: index.php 프로젝트: spidgorny/t3mock
 function renderTimeTracking()
 {
     $mainFunction = $this->getMainFunction();
     t3lib_befunc::setMainFunction($mainFunction);
     $pageByMenu = array_flip($this->pi1->menuByPage);
     $activeMenuID = $pageByMenu[$this->getActiveMenu()];
     $this->pi1->tsfe->id = $activeMenuID;
     $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/cache/frontend/class.t3lib_Cache\\Frontend\\VariableFrontend.php']['set'] = NULL;
     $GLOBALS['LANG'] = NULL;
     $GLOBALS['TYPO3_CONF_VARS']['SYS']['lang']['parser']['xml'] = \TYPO3\CMS\Core\Localization\Parser\LocallangXmlParser::class;
     $be = new \TYPO3\CMS\Core\Cache\Backend\NullBackend('context');
     $fe = new \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend('t3lib_l10n', $be);
     $cm = new \TYPO3\CMS\Core\Cache\CacheManager();
     $cm->registerCache($fe);
     $GLOBALS['typo3CacheManager'] = $cm;
     $content[] = $this->pi1->main('', array());
     $html = new View('template/template.phtml');
     $html->title = 'Rechnung+ 2.0';
     $html->headerData = implode("\n", $this->pi1->tsfe->additionalHeaderData);
     $html->content = implode("\n", $content);
     $html->h1 = $this->pi1->menuOptions[$this->getActiveMenu()];
     $html->h2 = $mainFunction;
     $html->activeMenu = $this->pi1->tsfe->id;
     $html->userSelection = $this->getUserSelection();
     $html->countUsers = sizeof($this->pi1->getFEUserChoice());
     $html->clientCount = $this->pi1->clients;
     $html->projectCount = $this->pi1->projects;
     $html->invoiceCount = $this->pi1->invoices;
     $html->workCount = $this->pi1->works;
     $html->groupCount = 0;
     return $html;
 }