[BUGFIX] Do not inject non-singleton class into singleton 33/50033/7
authorMarkus Klein <markus.klein@typo3.org>
Tue, 27 Sep 2016 22:22:31 +0000 (00:22 +0200)
committerNicole Cordes <typo3@cordes.co>
Mon, 3 Apr 2017 21:42:03 +0000 (23:42 +0200)
BackendConfigurationManager must not inject an instance of
QueryGenerator as the latter is not a singleton.
Instead create a local instance of QueryGenerator when it is needed.

Releases: master
Resolves: #48544
Change-Id: If58f3a5c9c6a1003a0301bd2d68622ee8ccba843
Reviewed-on: https://review.typo3.org/50033
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Thomas Hohn <thomas@hohn.dk>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
typo3/sysext/extbase/Classes/Configuration/BackendConfigurationManager.php
typo3/sysext/extbase/Tests/Unit/Configuration/BackendConfigurationManagerTest.php

index d7caea8..238e33f 100644 (file)
@@ -13,24 +13,24 @@ namespace TYPO3\CMS\Extbase\Configuration;
  *
  * The TYPO3 project - inspiring people to share!
  */
+
 use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
 use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
+use TYPO3\CMS\Core\Database\QueryGenerator;
+use TYPO3\CMS\Core\TypoScript\TemplateService;
+use TYPO3\CMS\Core\Utility\ArrayUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Extbase\Mvc\Web\BackendRequestHandler;
+use TYPO3\CMS\Extbase\Mvc\Web\FrontendRequestHandler;
+use TYPO3\CMS\Frontend\Page\PageRepository;
 
 /**
  * A general purpose configuration manager used in backend mode.
  */
-class BackendConfigurationManager extends \TYPO3\CMS\Extbase\Configuration\AbstractConfigurationManager
+class BackendConfigurationManager extends AbstractConfigurationManager
 {
     /**
-     * Needed to recursively fetch a page tree
-     *
-     * @var \TYPO3\CMS\Core\Database\QueryGenerator
-     */
-    protected $queryGenerator;
-
-    /**
      * @var array
      */
     protected $typoScriptSetupCache = [];
@@ -42,14 +42,6 @@ class BackendConfigurationManager extends \TYPO3\CMS\Extbase\Configuration\Abstr
     protected $currentPageId;
 
     /**
-     * @param \TYPO3\CMS\Core\Database\QueryGenerator $queryGenerator
-     */
-    public function injectQueryGenerator(\TYPO3\CMS\Core\Database\QueryGenerator $queryGenerator)
-    {
-        $this->queryGenerator = $queryGenerator;
-    }
-
-    /**
      * Returns TypoScript Setup array from current Environment.
      *
      * @return array the raw TypoScript setup
@@ -59,8 +51,8 @@ class BackendConfigurationManager extends \TYPO3\CMS\Extbase\Configuration\Abstr
         $pageId = $this->getCurrentPageId();
 
         if (!array_key_exists($pageId, $this->typoScriptSetupCache)) {
-            /** @var $template \TYPO3\CMS\Core\TypoScript\TemplateService */
-            $template = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\TypoScript\TemplateService::class);
+            /** @var $template TemplateService */
+            $template = GeneralUtility::makeInstance(TemplateService::class);
             // do not log time-performance information
             $template->tt_track = 0;
             // Explicitly trigger processing of extension static files
@@ -69,8 +61,8 @@ class BackendConfigurationManager extends \TYPO3\CMS\Extbase\Configuration\Abstr
             // Get the root line
             $rootline = [];
             if ($pageId > 0) {
-                /** @var $sysPage \TYPO3\CMS\Frontend\Page\PageRepository */
-                $sysPage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
+                /** @var $sysPage PageRepository */
+                $sysPage = GeneralUtility::makeInstance(PageRepository::class);
                 // Get the rootline for the current page
                 $rootline = $sysPage->getRootLine($pageId, '', true);
             }
@@ -101,7 +93,7 @@ class BackendConfigurationManager extends \TYPO3\CMS\Extbase\Configuration\Abstr
             $pluginSignature = strtolower($extensionName . '_' . $pluginName);
             if (is_array($setup['module.']['tx_' . $pluginSignature . '.'])) {
                 $overruleConfiguration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($setup['module.']['tx_' . $pluginSignature . '.']);
-                \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($pluginConfiguration, $overruleConfiguration);
+                ArrayUtility::mergeRecursiveWithOverrule($pluginConfiguration, $overruleConfiguration);
             }
         }
         return $pluginConfiguration;
@@ -153,7 +145,7 @@ class BackendConfigurationManager extends \TYPO3\CMS\Extbase\Configuration\Abstr
      */
     protected function getCurrentPageIdFromGetPostData()
     {
-        return (int)\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('id');
+        return (int)GeneralUtility::_GP('id');
     }
 
     /**
@@ -244,8 +236,8 @@ class BackendConfigurationManager extends \TYPO3\CMS\Extbase\Configuration\Abstr
     {
         if (!isset($frameworkConfiguration['mvc']['requestHandlers'])) {
             $frameworkConfiguration['mvc']['requestHandlers'] = [
-                \TYPO3\CMS\Extbase\Mvc\Web\FrontendRequestHandler::class => \TYPO3\CMS\Extbase\Mvc\Web\FrontendRequestHandler::class,
-                \TYPO3\CMS\Extbase\Mvc\Web\BackendRequestHandler::class => \TYPO3\CMS\Extbase\Mvc\Web\BackendRequestHandler::class
+                FrontendRequestHandler::class => FrontendRequestHandler::class,
+                BackendRequestHandler::class => BackendRequestHandler::class
             ];
         }
         return $frameworkConfiguration;
@@ -265,10 +257,11 @@ class BackendConfigurationManager extends \TYPO3\CMS\Extbase\Configuration\Abstr
         }
 
         $recursiveStoragePids = '';
-        $storagePids = \TYPO3\CMS\Core\Utility\GeneralUtility::intExplode(',', $storagePid);
+        $storagePids = GeneralUtility::intExplode(',', $storagePid);
         $permsClause = $this->getBackendUser()->getPagePermsClause(1);
+        $queryGenerator = GeneralUtility::makeInstance(QueryGenerator::class);
         foreach ($storagePids as $startPid) {
-            $pids = $this->queryGenerator->getTreeList($startPid, $recursionDepth, 0, $permsClause);
+            $pids = $queryGenerator->getTreeList($startPid, $recursionDepth, 0, $permsClause);
             if ((string)$pids !== '') {
                 $recursiveStoragePids .= $pids . ',';
             }
index c327bfc..1f00481 100644 (file)
@@ -14,6 +14,8 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Configuration;
  * The TYPO3 project - inspiring people to share!
  */
 use Prophecy\Prophecy\ObjectProphecy;
+use TYPO3\CMS\Core\Database\QueryGenerator;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Test case
@@ -304,13 +306,12 @@ class BackendConfigurationManagerTest extends \TYPO3\TestingFramework\Core\Unit\
         $beUserAuthentication->getPagePermsClause(1)->willReturn('1=1');
         $GLOBALS['BE_USER'] = $beUserAuthentication->reveal();
 
-        /** @var $abstractConfigurationManager \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager */
         $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions']);
         $queryGenerator = $this->createMock(\TYPO3\CMS\Core\Database\QueryGenerator::class);
         $queryGenerator->expects($this->any())
             ->method('getTreeList')
             ->will($this->onConsecutiveCalls('4', '', '5,6'));
-        $abstractConfigurationManager->_set('queryGenerator', $queryGenerator);
+        GeneralUtility::addInstance(QueryGenerator::class, $queryGenerator);
 
         $expectedResult = '4,5,6';
         $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
@@ -330,13 +331,12 @@ class BackendConfigurationManagerTest extends \TYPO3\TestingFramework\Core\Unit\
         $beUserAuthentication->getPagePermsClause(1)->willReturn('1=1');
         $GLOBALS['BE_USER'] = $beUserAuthentication->reveal();
 
-        /** @var $abstractConfigurationManager \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager */
-        $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions']);
+        $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions', 'getQueryGenerator']);
         $queryGenerator = $this->createMock(\TYPO3\CMS\Core\Database\QueryGenerator::class);
         $queryGenerator->expects($this->any())
             ->method('getTreeList')
             ->will($this->onConsecutiveCalls('4', '', '3,5,6'));
-        $abstractConfigurationManager->_set('queryGenerator', $queryGenerator);
+        GeneralUtility::addInstance(QueryGenerator::class, $queryGenerator);
 
         $expectedResult = '4,3,5,6';
         $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
@@ -352,10 +352,6 @@ class BackendConfigurationManagerTest extends \TYPO3\TestingFramework\Core\Unit\
 
         $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions']);
 
-        $queryGenerator = $this->createMock(\TYPO3\CMS\Core\Database\QueryGenerator::class);
-        $queryGenerator->expects($this->never())->method('getTreeList');
-        $abstractConfigurationManager->_set('queryGenerator', $queryGenerator);
-
         $expectedResult = '1,2,3';
         $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid);
         $this->assertEquals($expectedResult, $actualResult);
@@ -371,10 +367,6 @@ class BackendConfigurationManagerTest extends \TYPO3\TestingFramework\Core\Unit\
 
         $abstractConfigurationManager = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager::class, ['overrideSwitchableControllerActions', 'getContextSpecificFrameworkConfiguration', 'getTypoScriptSetup', 'getPluginConfiguration', 'getSwitchableControllerActions']);
 
-        $queryGenerator = $this->createMock(\TYPO3\CMS\Core\Database\QueryGenerator::class);
-        $queryGenerator->expects($this->never())->method('getTreeList');
-        $abstractConfigurationManager->_set('queryGenerator', $queryGenerator);
-
         $expectedResult = '1,2,3';
         $actualResult = $abstractConfigurationManager->_call('getRecursiveStoragePids', $storagePid, $recursive);
         $this->assertEquals($expectedResult, $actualResult);