[BUGFIX] storagePid is lost when persistence.recursive is set 86/23086/5
authorSteffen Müller <typo3@t3node.com>
Tue, 13 Aug 2013 18:55:01 +0000 (20:55 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Wed, 14 Aug 2013 05:35:29 +0000 (07:35 +0200)
If recursive storagePid is set via TypoScript, the storagePid
itself is missing in the list of pids.

Resolves: #51064
Releases: 6.2, 6.1
Change-Id: I5f06911bb60b847e4a97b5690e57557d4dec66b7
Reviewed-on: https://review.typo3.org/23086
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/extbase/Classes/Configuration/AbstractConfigurationManager.php
typo3/sysext/extbase/Tests/Unit/Configuration/AbstractConfigurationManagerTest.php
typo3/sysext/extbase/Tests/Unit/Configuration/BackendConfigurationManagerTest.php
typo3/sysext/extbase/Tests/Unit/Configuration/FrontendConfigurationManagerTest.php

index b50c523..12487c2 100755 (executable)
@@ -177,7 +177,18 @@ abstract class AbstractConfigurationManager implements \TYPO3\CMS\Core\Singleton
                        }
 
                        if (!empty($frameworkConfiguration['persistence']['recursive'])) {
-                               $frameworkConfiguration['persistence']['storagePid'] = $this->getRecursiveStoragePids($frameworkConfiguration['persistence']['storagePid'], (int) $frameworkConfiguration['persistence']['recursive']);
+                               // All implementations of getTreeList allow to pass the ids negative to include them into the result
+                               // otherwise only childpages are returned
+                               $storagePids = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $frameworkConfiguration['persistence']['storagePid']);
+                               array_walk($storagePids, function (&$storagePid) {
+                                       if ($storagePid > 0) {
+                                               $storagePid = -$storagePid;
+                                       }
+                               });
+                               $frameworkConfiguration['persistence']['storagePid'] = $this->getRecursiveStoragePids(
+                                       implode(',', $storagePids),
+                                       (int) $frameworkConfiguration['persistence']['recursive']
+                               );
                        }
                }
                // 1st level cache
index f504141..e148efe 100644 (file)
@@ -308,6 +308,36 @@ class AbstractConfigurationManagerTest extends \TYPO3\CMS\Extbase\Tests\Unit\Bas
        }
 
        /**
+        * @test
+        */
+       public function getConfigurationRetrievesStoragePidIncludingGivenStoragePidWithRecursiveSetForSingleStoragePid() {
+               $pluginConfiguration = array(
+                       'persistence' => array(
+                               'storagePid' => 1,
+                               'recursive' => 99
+                       )
+               );
+               $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->will($this->returnValue($pluginConfiguration));
+               $this->abstractConfigurationManager->expects($this->once())->method('getRecursiveStoragePids')->with('-1');
+               $this->abstractConfigurationManager->getConfiguration('SomeOtherExtensionName', 'SomeOtherCurrentPluginName');
+       }
+
+       /**
+        * @test
+        */
+       public function getConfigurationRetrievesStoragePidIncludingGivenStoragePidWithRecursiveSetForMultipleStoragePid() {
+               $pluginConfiguration = array(
+                       'persistence' => array(
+                               'storagePid' => '1,25',
+                               'recursive' => 99
+                       )
+               );
+               $this->abstractConfigurationManager->expects($this->once())->method('getPluginConfiguration')->will($this->returnValue($pluginConfiguration));
+               $this->abstractConfigurationManager->expects($this->once())->method('getRecursiveStoragePids')->with('-1,-25');
+               $this->abstractConfigurationManager->getConfiguration('SomeOtherExtensionName', 'SomeOtherCurrentPluginName');
+       }
+
+       /**
         * switchableControllerActions *
         */
        /**
index ea7a38e..d93faab 100644 (file)
@@ -350,10 +350,29 @@ class BackendConfigurationManagerTest extends \TYPO3\CMS\Extbase\Tests\Unit\Base
                $queryGenerator = $this->getMock('TYPO3\\CMS\\Core\\Database\\QueryGenerator');
                $queryGenerator->expects($this->any())
                        ->method('getTreeList')
-                       ->will($this->onConsecutiveCalls('1,4', '2', '3,5,6'));
+                       ->will($this->onConsecutiveCalls('4', '', '5,6'));
                $abstractConfigurationManager->_set('queryGenerator', $queryGenerator);
 
-               $expectedResult = '1,4,2,3,5,6';
+               $expectedResult = '4,5,6';
+               $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
+               $this->assertEquals($expectedResult, $actualResult);
+       }
+
+       /**
+        * @test
+        */
+       public function storagePidsAreExtendedIfRecursiveSearchIsConfiguredAndWithPidIncludedForNegativePid() {
+               $storagePid = '1,2,-3';
+               $recursive = 99;
+               /** @var $abstractConfigurationManager \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager */
+               $abstractConfigurationManager = $this->getAccessibleMock('TYPO3\CMS\\Extbase\\Configuration\\BackendConfigurationManager', array('overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions'));
+               $queryGenerator = $this->getMock('TYPO3\\CMS\\Core\\Database\\QueryGenerator');
+               $queryGenerator->expects($this->any())
+                       ->method('getTreeList')
+                       ->will($this->onConsecutiveCalls('4', '', '3,5,6'));
+               $abstractConfigurationManager->_set('queryGenerator', $queryGenerator);
+
+               $expectedResult = '4,3,5,6';
                $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
                $this->assertEquals($expectedResult, $actualResult);
        }
index 1b04a1f..99c76d6 100644 (file)
@@ -346,10 +346,30 @@ class FrontendConfigurationManagerTest extends \TYPO3\CMS\Extbase\Tests\Unit\Bas
                $cObjectMock = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
                $cObjectMock->expects($this->any())
                        ->method('getTreeList')
-                       ->will($this->onConsecutiveCalls('3,4', '5', '9,898,12'));
+                       ->will($this->onConsecutiveCalls('4', '', '898,12'));
                $abstractConfigurationManager->setContentObject($cObjectMock);
 
-               $expectedResult = '3,4,5,9,898,12';
+               $expectedResult = '4,898,12';
+               $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
+               $this->assertEquals($expectedResult, $actualResult);
+       }
+
+       /**
+        * @test
+        */
+       public function storagePidsAreExtendedIfRecursiveSearchIsConfiguredAndWithPidIncludedForNegativePid() {
+               $storagePid = '-3,5,9';
+               $recursive = 99;
+               /** @var $abstractConfigurationManager \TYPO3\CMS\Extbase\Configuration\FrontendConfigurationManager */
+               $abstractConfigurationManager = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Configuration\\FrontendConfigurationManager', array('overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions'));
+               /** @var $cObjectMock \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer */
+               $cObjectMock = $this->getMock('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
+               $cObjectMock->expects($this->any())
+                       ->method('getTreeList')
+                       ->will($this->onConsecutiveCalls('3,4', '', '898,12'));
+               $abstractConfigurationManager->setContentObject($cObjectMock);
+
+               $expectedResult = '3,4,898,12';
                $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
                $this->assertEquals($expectedResult, $actualResult);
        }