Bug #89295

Typo3QuerySettings set as DefaultQuerySettings in a Repositories initializeObject Method are not honored

Added by Frank Berger 5 months ago. Updated about 1 month ago.

Status:
Needs Feedback
Priority:
Should have
Category:
Extbase
Target version:
-
Start date:
2019-09-27
Due date:
% Done:

0%

TYPO3 Version:
9
PHP Version:
7.2
Tags:
extbase repository
Complexity:
medium
Is Regression:
Sprint Focus:

Description

The premise is that an Extbase Repository has been extended from Repository, and the initializeObject Method is used to set Typo3QuerySettings and stored in $this->setDefaultQuerySettings, for example like this:

class EventRepository extends Repository
{
    public function initializeObject()
    {
        $querySettings = $this->objectManager->get(Typo3QuerySettings::class);
        $context = GeneralUtility::makeInstance(Context::class);
        $querySettings->setLanguageUid($context->getPropertyFromAspect('language','id'));
        $querySettings->setLanguageOverlayMode(1);
        $this->setDefaultQuerySettings($querySettings);
    }
}

The reason why we set for example the language like this has a different issue, which will be a different bug report. This is just an example.

The expected behaviour now is that any method using $this->createQuery(), including the magic findX methods and findAll will now use these settings.

This does not happen as in Generic\QueryFactory->create a new DefaultQuery is generated.

public function create($className)
{
         $query = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\QueryInterface::class, $className);
         $querySettings = $this->objectManager->get(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface::class);

This has several side effects. Parts of 'our' defaultQuerySettings are used, parts of the new one are used. And anything related to the storagePageIds will fail (no storagePageId will be set in the querySettings, not from typoscript or the the pages field or flexform)

We patched in our project the call-chain down to Generic\QueryFactory->create so the repositories defaultQuerySettings will be passed through the instances and if not null will be used instead if a new instance.

The patch is attached.

The System behaves as expected after that, honoring the settings set in a initializeObject method, even for the magic Methods

extbase-querysettings.diff View - Patchfile for this issue (4.44 KB) Frank Berger, 2019-09-27 16:20

History

#1 Updated by Frank Berger 4 months ago

  • Tags set to extbase repository
  • Complexity set to medium

#2 Updated by Alexander Schnitzler about 1 month ago

  • Status changed from New to Needs Feedback

I cannot reproduce this issue.
It's true that the query factory does not respect query settings, but in \TYPO3\CMS\Extbase\Persistence\Repository::createQuery, which is called by the findAll (and magic) method(s), the defaultQuerySettings (if present) are copied over to the query object.

Please see https://github.com/TYPO3/TYPO3.CMS/blob/v9.5.13/typo3/sysext/extbase/Classes/Persistence/Repository.php#L201 for more information.

If I misunderstood the problem, please provide further feedback.

#3 Updated by Frank Berger about 1 month ago

  • Assignee set to Alexander Schnitzler

The Problem is here:

https://github.com/TYPO3/TYPO3.CMS/blob/v9.5.13/typo3/sysext/extbase/Classes/Persistence/Generic/QueryFactory.php#L80

This is called before the defaultQuerySettings are applied in

https://github.com/TYPO3/TYPO3.CMS/blob/v9.5.13/typo3/sysext/extbase/Classes/Persistence/Repository.php#L201

Which means if you just use defaultQuerySettings you will override any preconfigured or contextrelated storagePageIds

therefore either the setting of the storagePageIds need to be done later - i.e. in Repository->createQuery after the clone OR the defaultQuerySettings need to be applied before, like in the patch I suggested..

sorry if that was not clear in my initial report

#4 Updated by Frank Berger about 1 month ago

sorry, in hindsight - which is 20-20 - I should have lead with that..

Also available in: Atom PDF