[TASK] Stop monkey patching CacheManager configuration in InstallTool 71/55971/2
authorBenjamin Franzke <bfr@qbus.de>
Thu, 1 Mar 2018 15:51:27 +0000 (16:51 +0100)
committerFrank Naegler <frank.naegler@typo3.org>
Thu, 1 Mar 2018 17:21:58 +0000 (18:21 +0100)
Instead of creating the cacheManager and then disabling all cache
confiurations afterwards, the desired state is enforced inside the
CacheManager now (controlled through a constructor parameter).

Releases: master
Resolves: #84107
Change-Id: Ia3623a96246d97b74ee48eb2022ba35d5bcfcc04
Reviewed-on: https://review.typo3.org/55971
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/Cache/CacheManager.php
typo3/sysext/core/Classes/Core/Bootstrap.php
typo3/sysext/install/Classes/Http/Application.php

index 3fc34ef..3ce7552 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Core\Cache;
  */
 
 use TYPO3\CMS\Core\Cache\Backend\BackendInterface;
+use TYPO3\CMS\Core\Cache\Backend\NullBackend;
 use TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend;
 use TYPO3\CMS\Core\Cache\Exception\DuplicateIdentifierException;
 use TYPO3\CMS\Core\Cache\Exception\InvalidBackendException;
@@ -64,6 +65,19 @@ class CacheManager implements SingletonInterface
     ];
 
     /**
+     * @var bool
+     */
+    protected $disableCaching = false;
+
+    /**
+     * @param bool $disableCaching
+     */
+    public function __construct(bool $disableCaching = false)
+    {
+        $this->disableCaching = $disableCaching;
+    }
+
+    /**
      * Sets configurations for caches. The key of each entry specifies the
      * cache identifier and the value is an array of configuration options.
      * Possible options are:
@@ -285,6 +299,11 @@ class CacheManager implements SingletonInterface
             $backendOptions = $this->defaultCacheConfiguration['options'];
         }
 
+        if ($this->disableCaching) {
+            $backend = NullBackend::class;
+            $backendOptions = [];
+        }
+
         // Add the cache identifier to the groups that it should be attached to, or use the default ones.
         if (isset($this->cacheConfigurations[$identifier]['groups']) && is_array($this->cacheConfigurations[$identifier]['groups'])) {
             $assignedGroups = $this->cacheConfigurations[$identifier]['groups'];
index 7acbee8..0e8c570 100644 (file)
@@ -279,11 +279,8 @@ class Bootstrap
     public function loadConfigurationAndInitialize($allowCaching = true, $packageManagerClassName = \TYPO3\CMS\Core\Package\PackageManager::class)
     {
         $this->populateLocalConfiguration()
-            ->initializeErrorHandling();
-        if (!$allowCaching) {
-            $this->disableCoreCache();
-        }
-        $this->initializeCachingFramework()
+            ->initializeErrorHandling()
+            ->initializeCachingFramework($allowCaching)
             ->initializePackageManagement($packageManagerClassName)
             ->initializeRuntimeActivatedPackagesFromConfiguration()
             ->setDefaultTimezone()
@@ -367,6 +364,7 @@ class Bootstrap
 
     /**
      * Set cache_core to null backend, effectively disabling eg. the cache for ext_localconf and PackageManager etc.
+     * Used in unit tests.
      *
      * @return Bootstrap|null
      * @internal This is not a public API method, do not use in own extensions
@@ -383,12 +381,13 @@ class Bootstrap
      * Initialize caching framework, and re-initializes it (e.g. in the install tool) by recreating the instances
      * again despite the Singleton instance
      *
+     * @param bool $allowCaching
      * @return Bootstrap
      * @internal This is not a public API method, do not use in own extensions
      */
-    public function initializeCachingFramework()
+    public function initializeCachingFramework(bool $allowCaching = true)
     {
-        $cacheManager = new \TYPO3\CMS\Core\Cache\CacheManager();
+        $cacheManager = new \TYPO3\CMS\Core\Cache\CacheManager(!$allowCaching);
         $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']);
         GeneralUtility::setSingletonInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $cacheManager);
         $this->setEarlyInstance(\TYPO3\CMS\Core\Cache\CacheManager::class, $cacheManager);
index a751aa3..0b61814 100644 (file)
@@ -16,7 +16,6 @@ namespace TYPO3\CMS\Install\Http;
 
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
-use TYPO3\CMS\Core\Cache\Backend\NullBackend;
 use TYPO3\CMS\Core\Core\Bootstrap;
 use TYPO3\CMS\Core\Http\AbstractApplication;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -63,8 +62,6 @@ class Application extends AbstractApplication
         $this->bootstrap
             ->startOutputBuffering()
             ->loadConfigurationAndInitialize(false, \TYPO3\CMS\Core\Package\FailsafePackageManager::class);
-
-        $this->disableCachingFramework();
     }
 
     /**
@@ -84,26 +81,6 @@ class Application extends AbstractApplication
     }
 
     /**
-     * Set caching to NullBackend, install tool must not cache anything
-     */
-    protected function disableCachingFramework()
-    {
-        $cacheConfigurations = $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'];
-
-        $cacheConfigurationsWithCachesSetToNullBackend = [];
-        foreach ($cacheConfigurations as $cacheName => $cacheConfiguration) {
-            // cache_core is handled in bootstrap already
-            if (is_array($cacheConfiguration) && $cacheName !== 'cache_core') {
-                $cacheConfiguration['backend'] = NullBackend::class;
-                $cacheConfiguration['options'] = [];
-            }
-            $cacheConfigurationsWithCachesSetToNullBackend[$cacheName] = $cacheConfiguration;
-        }
-        $cacheManager = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class);
-        $cacheManager->setCacheConfigurations($cacheConfigurationsWithCachesSetToNullBackend);
-    }
-
-    /**
      * Define constants
      */
     protected function defineLegacyConstants()