Project

General

Profile

Actions

Feature #90429

closed

ConfigurationManager should offer a way to define the site it is fetching a configuration for

Added by Arne-Kolja Bachstein about 4 years ago. Updated over 1 year ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Backend API
Target version:
-
Start date:
2020-02-19
Due date:
% Done:

0%

Estimated time:
PHP Version:
7.4
Tags:
Complexity:
Sprint Focus:

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.


Related issues 2 (2 open0 closed)

Related to TYPO3 Core - Bug #88572: ConfigurationManager returns wrong configurationAccepted2019-06-17

Actions
Related to TYPO3 Core - Bug #93251: getCurrentPageId not working correctly in multisite systemsNew2021-01-08

Actions
Actions #1

Updated by Georg Ringer about 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

Actions #2

Updated by Georg Ringer about 4 years ago

  • Related to Bug #88572: ConfigurationManager returns wrong configuration added
Actions #3

Updated by Georg Ringer over 3 years ago

  • Related to Bug #93251: getCurrentPageId not working correctly in multisite systems added
Actions #4

Updated by Christian Kuhn over 1 year 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.

Actions

Also available in: Atom PDF