TYPO3 CMS  TYPO3_6-2
ClearCacheService.php
Go to the documentation of this file.
1 <?php
3 
18 
24 
29  protected $objectManager = NULL;
30 
46  public function clearAll() {
47  // Delete typo3temp/Cache
48  GeneralUtility::flushDirectory(PATH_site . 'typo3temp/Cache', TRUE, TRUE);
49 
51  $bootstrap->unregisterClassLoader();
52 
54 
56  ->initializeClassLoader()
57  ->initializeCachingFramework()
58  ->initializeClassLoaderCaches()
59  ->initializePackageManagement('TYPO3\\CMS\\Core\\Package\\PackageManager');
60 
61  // Get all table names starting with 'cf_' and truncate them
62  $database = $this->getDatabaseConnection();
63  $tables = $database->admin_get_tables();
64  foreach ($tables as $table) {
65  $tableName = $table['Name'];
66  if (substr($tableName, 0, 3) === 'cf_') {
67  $database->exec_TRUNCATEquery($tableName);
68  } elseif ($tableName === 'cache_treelist') {
69  // cache_treelist is not implemented in the caching framework.
70  // clear this table manually
71  $database->exec_TRUNCATEquery('cache_treelist');
72  }
73  }
74 
75  // From this point on, the code may fatal, if some broken extension is loaded.
76 
77  // Use bootstrap to load all ext_localconf and ext_tables
79  ->loadTypo3LoadedExtAndExtLocalconf(FALSE)
80  ->applyAdditionalConfigurationSettings()
81  ->initializeTypo3DbGlobal()
82  ->loadExtensionTables(FALSE);
83 
84  // The cache manager is already instantiated in the install tool
85  // with some hacked settings to disable caching of extbase and fluid.
86  // We want a "fresh" object here to operate on a different cache setup.
87  // cacheManager implements SingletonInterface, so the only way to get a "fresh"
88  // instance is by circumventing makeInstance and/or the objectManager and
89  // using new directly!
90  $cacheManager = new \TYPO3\CMS\Core\Cache\CacheManager();
91  $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
92  // Cache manager needs cache factory. cache factory injects itself to manager in __construct()
93  new \TYPO3\CMS\Core\Cache\CacheFactory('production', $cacheManager);
94 
95  $cacheManager->flushCaches();
96  }
97 
104  protected function getDatabaseConnection() {
105  static $database;
106  if (!is_object($database)) {
108  $database = $this->objectManager->get('TYPO3\\CMS\\Core\\Database\\DatabaseConnection');
109  $database->setDatabaseUsername($GLOBALS['TYPO3_CONF_VARS']['DB']['username']);
110  $database->setDatabasePassword($GLOBALS['TYPO3_CONF_VARS']['DB']['password']);
111  $database->setDatabaseHost($GLOBALS['TYPO3_CONF_VARS']['DB']['host']);
112  $database->setDatabasePort($GLOBALS['TYPO3_CONF_VARS']['DB']['port']);
113  $database->setDatabaseSocket($GLOBALS['TYPO3_CONF_VARS']['DB']['socket']);
114  $database->setDatabaseName($GLOBALS['TYPO3_CONF_VARS']['DB']['database']);
115  $database->initialize();
116  $database->connectDB();
117  }
118  return $database;
119  }
120 }
static flushDirectory($directory, $keepOriginalDirectory=FALSE, $flushOpcodeCache=FALSE)
static flagCachingFrameworkForReinitialization()
Definition: Cache.php:76
$database
Definition: server.php:38
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]