Commit aeda613a authored by Markus Klein's avatar Markus Klein Committed by Nicole Cordes
Browse files

[BUGFIX] Do not inject non-singleton class into singleton

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: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: default avatarThomas Hohn <thomas@hohn.dk>
Reviewed-by: default avatarJoerg Boesche <typo3@joergboesche.de>
Reviewed-by: default avatarDaniel Goerz <ervaude@gmail.com>
Reviewed-by: default avatarStefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: default avatarStefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Jigal van Hemert's avatarJigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: Jigal van Hemert's avatarJigal van Hemert <jigal.van.hemert@typo3.org>
Reviewed-by: Nicole Cordes's avatarNicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes's avatarNicole Cordes <typo3@cordes.co>
parent 2510406d
......@@ -13,23 +13,23 @@ 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
*/
......@@ -41,14 +41,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.
*
......@@ -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 . ',';
}
......
......@@ -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);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment