Feature #90429
closedConfigurationManager should offer a way to define the site it is fetching a configuration for
0%
Description
I have a multi-site setup in 9 LTS and I am doing the following in a Symfony console command:
$siteFinder = $objectManager->get(SiteFinder::class); $site = $siteFinder->getSiteByIdentifier($input->getArgument('site')); $objectManager = GeneralUtility::makeInstance(ObjectManager::class); $configurationManager = $objectManager->get(ConfigurationManagerInterface::class); $contentObjectRenderer = $objectManager->get(ContentObjectRenderer::class); $configurationManager->setContentObject($contentObjectRenderer); $settings = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
Doing this, the ConfigurationManager always returns the configuration for the root page of the first site it finds in the page tree, as the following code at https://github.com/TYPO3/TYPO3.CMS/blob/9.5/typo3/sysext/extbase/Classes/Configuration/BackendConfigurationManager.php#L158 does not handle the current site:
protected function getCurrentPageIdFromCurrentSiteRoot() { $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) ->getQueryBuilderForTable('pages'); $queryBuilder ->getRestrictions() ->removeAll() ->add(GeneralUtility::makeInstance(DeletedRestriction::class)) ->add(GeneralUtility::makeInstance(HiddenRestriction::class)); $rootPage = $queryBuilder ->select('uid') ->from('pages') ->where( $queryBuilder->expr()->eq('is_siteroot', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT)) ) ->orderBy('sorting') ->execute() ->fetch(); if (empty($rootPage)) { return 0; } return (int)$rootPage['uid']; }
Also affected:
There is no other place where $this->currentPageId gets set than in https://github.com/TYPO3/TYPO3.CMS/blob/9.5/typo3/sysext/extbase/Classes/Configuration/BackendConfigurationManager.php#L130, so $this->currentPageId is only available in a second call of this function:
protected function getCurrentPageId() { if ($this->currentPageId !== null) { return $this->currentPageId; } $this->currentPageId = $this->getCurrentPageIdFromGetPostData() ?: $this->getCurrentPageIdFromCurrentSiteRoot(); $this->currentPageId = $this->currentPageId ?: $this->getCurrentPageIdFromRootTemplate(); $this->currentPageId = $this->currentPageId ?: self::DEFAULT_BACKEND_STORAGE_PID; return $this->currentPageId; }
At the moment I succeeded with the workaround of faking the current page id in my console command like this:
$siteFinder = $objectManager->get(SiteFinder::class); $site = $siteFinder->getSiteByIdentifier($input->getArgument('site')); if (!isset($_GET)) { $_GET = []; } $_GET['id'] = $site->getRootPageId(); $objectManager = GeneralUtility::makeInstance(ObjectManager::class); $configurationManager = $objectManager->get(ConfigurationManagerInterface::class); $contentObjectRenderer = $objectManager->get(ContentObjectRenderer::class); $configurationManager->setContentObject($contentObjectRenderer); $settings = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
This is, however, a quite dirty workaround. A quick fix would be to offer a setter for $this->currentPageId. However, maybe it would be better to offer a setter for the current site and from that fallback to the site's $rootPageId if no $currentPageId is set.
Updated by Georg Ringer over 4 years ago
- Status changed from New to Needs Feedback
can you test if this is solved with the change I am doing at #88572? thanks
Updated by Georg Ringer over 4 years ago
- Related to Bug #88572: ConfigurationManager returns wrong configuration added
Updated by Georg Ringer almost 4 years ago
- Related to Bug #93251: getCurrentPageId not working correctly in multisite systems added
Updated by Christian Kuhn almost 2 years ago
- Status changed from Needs Feedback to Closed
Closing here: ConfigurationManager in extbase is still a broader mess, even with some simplifications that happen with v12 - the dependency management is pretty much borked and needs an overhaul. We should change things with fresh issues.