[BUGFIX] Revert "Improve performance of Fluid TemplatePaths" 46/54146/2
authorBenni Mack <benni@typo3.org>
Thu, 14 Sep 2017 14:51:43 +0000 (16:51 +0200)
committerBenni Mack <benni@typo3.org>
Thu, 14 Sep 2017 15:22:24 +0000 (17:22 +0200)
This reverts commit 8d355f5479af72fcc716f29d69ac765b2beab733
due to side-effects introduced with this commit.

Change-Id: I51a4241c5d08021415f7300bb6e81489b4dd7fd9
Resolves: #82487
Reverts: #82232
Releases: master, 8.7
Reviewed-on: https://review.typo3.org/54146
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/fluid/Classes/View/TemplatePaths.php
typo3/sysext/fluid/Tests/Unit/View/TemplatePathsTest.php

index 1a61b56..274bf47 100644 (file)
@@ -82,20 +82,10 @@ class TemplatePaths extends \TYPO3Fluid\Fluid\View\TemplatePaths
         $cache = $this->getRuntimeCache();
         $cacheIdentifier = 'viewpaths_' . $extensionKey;
         $configuration = $cache->get($cacheIdentifier);
-        if (is_array($configuration)) {
+        if (!empty($configuration)) {
             return $configuration;
         }
 
-        $configuredPaths = [];
-        if (!empty($this->templateRootPaths) || !empty($this->partialRootPaths) || !empty($this->layoutRootPaths)) {
-            // The view was manually configured - early return to avoid caching this configuration.
-            return [
-                self::CONFIG_TEMPLATEROOTPATHS => $this->templateRootPaths,
-                self::CONFIG_PARTIALROOTPATHS => $this->partialRootPaths,
-                self::CONFIG_LAYOUTROOTPATHS => $this->layoutRootPaths,
-            ];
-        }
-
         $resources = $this->getExtensionPrivateResourcesPath($extensionKey);
         $paths = [
             self::CONFIG_TEMPLATEROOTPATHS => [$resources . 'Templates/'],
@@ -103,17 +93,31 @@ class TemplatePaths extends \TYPO3Fluid\Fluid\View\TemplatePaths
             self::CONFIG_LAYOUTROOTPATHS => [$resources . 'Layouts/']
         ];
 
-        if (empty($this->typoScript)) {
-            $this->typoScript = (array)$this->getConfigurationManager()->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
+        $configuredPaths = [];
+        if (!empty($this->templateRootPaths) || !empty($this->partialRootPaths) || !empty($this->layoutRootPaths)) {
+            // The view was configured already
+            $configuredPaths = [
+                self::CONFIG_TEMPLATEROOTPATHS => $this->templateRootPaths,
+                self::CONFIG_PARTIALROOTPATHS => $this->partialRootPaths,
+                self::CONFIG_LAYOUTROOTPATHS => $this->layoutRootPaths,
+            ];
+        } else {
+            if (empty($this->typoScript)) {
+                $this->typoScript = GeneralUtility::removeDotsFromTS(
+                    (array)$this->getConfigurationManager()->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT)
+                );
+            }
+            $signature = str_replace('_', '', $extensionKey);
+            if ($this->isBackendMode() && isset($this->typoScript['module']['tx_' . $signature]['view'])) {
+                $configuredPaths = (array)$this->typoScript['module']['tx_' . $signature]['view'];
+            } elseif ($this->isFrontendMode() && isset($this->typoScript['plugin']['tx_' . $signature]['view'])) {
+                $configuredPaths = (array)$this->typoScript['plugin']['tx_' . $signature]['view'];
+            }
         }
 
-        $signature = str_replace('_', '', $extensionKey);
-        if ($this->isBackendMode() && isset($this->typoScript['module.']['tx_' . $signature . '.']['view.'])) {
-            $configuredPaths = (array)$this->typoScript['module.']['tx_' . $signature . '.']['view.'];
-        } elseif ($this->isFrontendMode() && isset($this->typoScript['plugin.']['tx_' . $signature . '.']['view.'])) {
-            $configuredPaths = (array)$this->typoScript['plugin.']['tx_' . $signature . '.']['view.'];
+        if (empty($configuredPaths)) {
+            return $paths;
         }
-        $configuredPaths = GeneralUtility::removeDotsFromTS($configuredPaths);
 
         foreach ($paths as $name => $defaultPaths) {
             if (!empty($configuredPaths[$name])) {
index 58a7643..bfb3c2c 100644 (file)
@@ -170,7 +170,7 @@ class TemplatePathsTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         $configurationManager = $this->getMockBuilder(ConfigurationManagerInterface::class)->getMockForAbstractClass();
         $configurationManager->expects($this->once())->method('getConfiguration')->willReturn([
             'module.' => [
-                'tx_test2.' => [
+                'tx_test.' => [
                     'view.' => [
                         'templateRootPaths.' => [
                             '30' => 'third',
@@ -195,12 +195,12 @@ class TemplatePathsTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         $cache->expects($this->once())->method('get')->willReturn(false);
         $cache->expects($this->once())->method('set');
         $subject = $this->getMockBuilder(TemplatePaths::class)->setMethods(['getConfigurationManager', 'getExtensionPrivateResourcesPath', 'getRuntimeCache', 'isBackendMode', 'isFrontendMode'])->getMock();
-        $subject->expects($this->once())->method('getExtensionPrivateResourcesPath')->with('test2')->willReturn('test/');
+        $subject->expects($this->once())->method('getExtensionPrivateResourcesPath')->with('test')->willReturn('test/');
         $subject->expects($this->once())->method('getConfigurationManager')->willReturn($configurationManager);
         $subject->expects($this->once())->method('getRuntimeCache')->willReturn($cache);
         $subject->expects($this->once())->method('isBackendMode')->willReturn(true);
         $subject->expects($this->never())->method('isFrontendMode');
-        $result = $this->callInaccessibleMethod($subject, 'getContextSpecificViewConfiguration', 'test2');
+        $result = $this->callInaccessibleMethod($subject, 'getContextSpecificViewConfiguration', 'test');
         $this->assertSame([
             'templateRootPaths' => [
                 'test/Templates/',
@@ -254,7 +254,7 @@ class TemplatePathsTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         ]);
         $cache = $this->getMockBuilder(VariableFrontend::class)->setMethods(['get', 'set'])->disableOriginalConstructor()->getMock();
         $cache->expects($this->once())->method('get')->willReturn(false);
-        $cache->expects($this->once())->method('set');
+        $cache->expects($this->never())->method('set');
         $subject = $this->getMockBuilder(TemplatePaths::class)->setMethods(['getConfigurationManager', 'getExtensionPrivateResourcesPath', 'getRuntimeCache', 'isBackendMode', 'isFrontendMode'])->getMock();
         $subject->expects($this->once())->method('getExtensionPrivateResourcesPath')->with('test')->willReturn('test/');
         $subject->expects($this->once())->method('getConfigurationManager')->willReturn($configurationManager);