[!!!][TASK] Remove Cache helper class 00/40500/7
authorBenjamin Mack <benni@typo3.org>
Sat, 20 Jun 2015 20:01:20 +0000 (22:01 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 16 Jul 2015 11:06:30 +0000 (13:06 +0200)
The Cache class that acted as a central point when the caching
framework was optionally enabled for 4.3 is now moved
into separate methods.

The duplicate code for creating the database statement is now
moved from the Install Tool to EXT:core to be used in the Extension
Manager as well.

Resolves: #56319
Releases: master
Change-Id: I871a9a6ea506795335e2e8f5b6a410604feba506
Reviewed-on: http://review.typo3.org/40500
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/Cache/Cache.php [deleted file]
typo3/sysext/core/Classes/Cache/DatabaseSchemaService.php [new file with mode: 0644]
typo3/sysext/core/Classes/Core/Bootstrap.php
typo3/sysext/dbal/Classes/Database/DatabaseConnection.php
typo3/sysext/extensionmanager/ext_localconf.php
typo3/sysext/install/Classes/Controller/Action/Tool/UpgradeWizard.php
typo3/sysext/install/Classes/Service/CachingFrameworkDatabaseSchemaService.php [deleted file]
typo3/sysext/install/Classes/Service/ClearCacheService.php
typo3/sysext/install/ext_localconf.php

diff --git a/typo3/sysext/core/Classes/Cache/Cache.php b/typo3/sysext/core/Classes/Cache/Cache.php
deleted file mode 100644 (file)
index c8c3258..0000000
+++ /dev/null
@@ -1,116 +0,0 @@
-<?php
-namespace TYPO3\CMS\Core\Cache;
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-use TYPO3\CMS\Core\Utility\GeneralUtility;
-
-/**
- * A cache handling helper class
- */
-class Cache {
-
-       /**
-        * @var bool TRUE if caching framework was fully initialized
-        */
-       static protected $isCachingFrameworkInitialized = FALSE;
-
-       /**
-        * @var CacheManager
-        */
-       static protected $cacheManager;
-
-       /**
-        * @var CacheFactory
-        */
-       static protected $cacheFactory;
-
-       /**
-        * Initializes the caching framework by loading the cache manager and factory
-        * into the global context.
-        *
-        * @return CacheManager
-        */
-       static public function initializeCachingFramework() {
-               if (!self::isCachingFrameworkInitialized()) {
-                       // New operator used on purpose, makeInstance() is not ready to be used so early in bootstrap
-                       self::$cacheManager = new CacheManager();
-                       GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, self::$cacheManager);
-                       self::$cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
-                       // New operator used on purpose, makeInstance() is not ready to be used so early in bootstrap
-                       self::$cacheFactory = new CacheFactory('production', self::$cacheManager);
-                       GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheFactory::class, self::$cacheFactory);
-                       self::$isCachingFrameworkInitialized = TRUE;
-               }
-               return self::$cacheManager;
-       }
-
-       /**
-        * Determines whether the caching framework is initialized.
-        * The caching framework could be disabled for the core but used by an extension.
-        *
-        * @return bool True if caching framework is initialized
-        */
-       static public function isCachingFrameworkInitialized() {
-               return self::$isCachingFrameworkInitialized;
-       }
-
-       /**
-        * Resets the isCachingFrameworkInitialized state
-        * Beware! This is not public API and necessary for edge cases in the install tool.
-        *
-        * @return void
-        */
-       static public function flagCachingFrameworkForReinitialization() {
-               self::$isCachingFrameworkInitialized = FALSE;
-               GeneralUtility::removeSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, self::$cacheManager);
-               GeneralUtility::removeSingletonInstance(\TYPO3\CMS\Core\Cache\CacheFactory::class, self::$cacheFactory);
-               self::$cacheManager = NULL;
-               self::$cacheFactory = NULL;
-       }
-
-       /**
-        * Helper method for install tool and extension manager to determine
-        * required table structure of all caches that depend on it
-        *
-        * This is not a public API method!
-        *
-        * @return string Required table structure of all registered caches
-        */
-       static public function getDatabaseTableDefinitions() {
-               $tableDefinitions = '';
-               foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] as $cacheName => $_) {
-                       $backend = self::$cacheManager->getCache($cacheName)->getBackend();
-                       if (method_exists($backend, 'getTableDefinitions')) {
-                               $tableDefinitions .= LF . $backend->getTableDefinitions();
-                       }
-               }
-               return $tableDefinitions;
-       }
-
-       /**
-        * A slot method to inject the required caching framework database tables to the
-        * tables definitions string
-        *
-        * @param array $sqlString
-        * @param string $extensionKey
-        * @return array
-        */
-       public function addCachingFrameworkRequiredDatabaseSchemaToTablesDefinition(array $sqlString, $extensionKey) {
-               self::$cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
-               $sqlString[] = static::getDatabaseTableDefinitions();
-               return array('sqlString' => $sqlString, 'extensionKey' => $extensionKey);
-       }
-
-}
diff --git a/typo3/sysext/core/Classes/Cache/DatabaseSchemaService.php b/typo3/sysext/core/Classes/Cache/DatabaseSchemaService.php
new file mode 100644 (file)
index 0000000..66a87eb
--- /dev/null
@@ -0,0 +1,72 @@
+<?php
+namespace TYPO3\CMS\Core\Cache;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+/**
+ * This service provides the sql schema for the caching framework
+ */
+class DatabaseSchemaService {
+
+       /**
+        * Get schema SQL of required cache framework tables.
+        *
+        * This method needs ext_localconf and ext_tables loaded!
+        *
+        * @return string Cache framework SQL
+        */
+       public function getCachingFrameworkRequiredDatabaseSchema() {
+               // Use new to circumvent the singleton pattern of CacheManager
+               $cacheManager = new CacheManager;
+               $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
+               // Cache manager needs cache factory. cache factory injects itself to manager in __construct()
+               new CacheFactory('production', $cacheManager);
+
+               $tableDefinitions = '';
+               foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] as $cacheName => $_) {
+                       $backend = $cacheManager->getCache($cacheName)->getBackend();
+                       if (method_exists($backend, 'getTableDefinitions')) {
+                               $tableDefinitions .= LF . $backend->getTableDefinitions();
+                       }
+               }
+
+               return $tableDefinitions;
+       }
+
+       /**
+        * A slot method to inject the required caching framework database tables to the
+        * tables definitions string
+        *
+        * @param array $sqlString
+        * @param string $extensionKey
+        * @return array
+        */
+       public function addCachingFrameworkRequiredDatabaseSchemaForInstallUtility(array $sqlString, $extensionKey) {
+               $sqlString[] = $this->getCachingFrameworkRequiredDatabaseSchema();
+               return array($sqlString, $extensionKey);
+       }
+
+       /**
+        * A slot method to inject the required caching framework database tables to the
+        * tables definitions string
+        *
+        * @param array $sqlString
+        * @return array
+        */
+       public function addCachingFrameworkRequiredDatabaseSchemaForSqlExpectedSchemaService(array $sqlString) {
+               $sqlString[] = $this->getCachingFrameworkRequiredDatabaseSchema();
+               return array($sqlString);
+       }
+
+}
index 0bf6b2d..b05e141 100644 (file)
@@ -534,13 +534,21 @@ class Bootstrap {
        }
 
        /**
-        * Initialize caching framework
+        * 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() {
-               $this->setEarlyInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, \TYPO3\CMS\Core\Cache\Cache::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;
        }
 
index 08bf5ea..1c6b8da 100644 (file)
@@ -308,7 +308,8 @@ class DatabaseConnection extends \TYPO3\CMS\Core\Database\DatabaseConnection {
         * @return void
         */
        protected function analyzeCachingTables() {
-               $this->parseAndAnalyzeSql(\TYPO3\CMS\Core\Cache\Cache::getDatabaseTableDefinitions());
+               $schemaService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\DatabaseSchemaService::class);
+               $this->parseAndAnalyzeSql($schemaService->getCachingFrameworkRequiredDatabaseSchema());
        }
 
        /**
index cc53261..c08fb7a 100644 (file)
@@ -22,8 +22,8 @@ if (TYPO3_MODE === 'BE') {
                $signalSlotDispatcher->connect(
                        \TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class,
                        'tablesDefinitionIsBeingBuilt',
-                       \TYPO3\CMS\Core\Cache\Cache::class,
-                       'addCachingFrameworkRequiredDatabaseSchemaToTablesDefinition'
+                       \TYPO3\CMS\Core\Cache\DatabaseSchemaService::class,
+                       'addCachingFrameworkRequiredDatabaseSchemaForInstallUtility'
                );
                $signalSlotDispatcher->connect(
                        \TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class,
index 1b08b80..1e3a0af 100644 (file)
@@ -279,8 +279,8 @@ class UpgradeWizard extends Action\AbstractAction {
                /** @var $sqlHandler \TYPO3\CMS\Install\Service\SqlSchemaMigrationService */
                $sqlHandler = $this->objectManager->get(\TYPO3\CMS\Install\Service\SqlSchemaMigrationService::class);
 
-               /** @var \TYPO3\CMS\Install\Service\CachingFrameworkDatabaseSchemaService $cachingFrameworkDatabaseSchemaService */
-               $cachingFrameworkDatabaseSchemaService = $this->objectManager->get(\TYPO3\CMS\Install\Service\CachingFrameworkDatabaseSchemaService::class);
+               /** @var \TYPO3\CMS\Core\Cache\DatabaseSchemaService $cachingFrameworkDatabaseSchemaService */
+               $cachingFrameworkDatabaseSchemaService = $this->objectManager->get(\TYPO3\CMS\Core\Cache\DatabaseSchemaService::class);
                $expectedSchemaString = $cachingFrameworkDatabaseSchemaService->getCachingFrameworkRequiredDatabaseSchema();
                $cleanedExpectedSchemaString = implode(LF, $sqlHandler->getStatementArray($expectedSchemaString, TRUE, '^CREATE TABLE '));
                $neededTableDefinition = $sqlHandler->getFieldDefinitions_fileContent($cleanedExpectedSchemaString);
diff --git a/typo3/sysext/install/Classes/Service/CachingFrameworkDatabaseSchemaService.php b/typo3/sysext/install/Classes/Service/CachingFrameworkDatabaseSchemaService.php
deleted file mode 100644 (file)
index 687d20c..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-<?php
-namespace TYPO3\CMS\Install\Service;
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-use TYPO3\CMS\Core\Cache\CacheManager;
-use TYPO3\CMS\Core\Cache\CacheFactory;
-
-/**
- * This service provides the sql schema for the caching framework
- */
-class CachingFrameworkDatabaseSchemaService {
-
-       /**
-        * Get schema SQL of required cache framework tables.
-        *
-        * This method needs ext_localconf and ext_tables loaded!
-        *
-        * @return string Cache framework SQL
-        */
-       public function getCachingFrameworkRequiredDatabaseSchema() {
-               // Use new to circumvent the singleton pattern of CacheManager
-               $cacheManager = new CacheManager;
-               $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
-               // Cache manager needs cache factory. cache factory injects itself to manager in __construct()
-               new CacheFactory('production', $cacheManager);
-
-               $tableDefinitions = '';
-               foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] as $cacheName => $_) {
-                       $backend = $cacheManager->getCache($cacheName)->getBackend();
-                       if (method_exists($backend, 'getTableDefinitions')) {
-                               $tableDefinitions .= LF . $backend->getTableDefinitions();
-                       }
-               }
-
-               return $tableDefinitions;
-       }
-
-       /**
-        * A slot method to inject the required caching framework database tables to the
-        * tables definitions string
-        *
-        * @param array $sqlString
-        * @return array
-        */
-       public function addCachingFrameworkRequiredDatabaseSchemaToTablesDefinition(array $sqlString) {
-               $sqlString[] = $this->getCachingFrameworkRequiredDatabaseSchema();
-               return array('sqlString' => $sqlString);
-       }
-
-}
index 3d0848d..7fafa16 100644 (file)
@@ -48,9 +48,6 @@ class ClearCacheService {
                GeneralUtility::flushDirectory(PATH_site . 'typo3temp/Cache', TRUE, TRUE);
 
                $bootstrap = \TYPO3\CMS\Core\Core\Bootstrap::getInstance();
-
-               \TYPO3\CMS\Core\Cache\Cache::flagCachingFrameworkForReinitialization();
-
                $bootstrap
                        ->initializeCachingFramework()
                        ->initializePackageManagement(\TYPO3\CMS\Core\Package\PackageManager::class);
index a404b85..ef262cf 100644 (file)
@@ -14,8 +14,8 @@ $signalSlotDispatcher = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TY
 $signalSlotDispatcher->connect(
        \TYPO3\CMS\Install\Service\SqlExpectedSchemaService::class,
        'tablesDefinitionIsBeingBuilt',
-       \TYPO3\CMS\Install\Service\CachingFrameworkDatabaseSchemaService::class,
-       'addCachingFrameworkRequiredDatabaseSchemaToTablesDefinition'
+       \TYPO3\CMS\Core\Cache\DatabaseSchemaService::class,
+       'addCachingFrameworkRequiredDatabaseSchemaForSqlExpectedSchemaService'
 );
 $signalSlotDispatcher->connect(
        \TYPO3\CMS\Install\Service\SqlExpectedSchemaService::class,