Bug #93484 » Typo3DbBackend.php.patch

View differences:

Typo3DbBackend.issue-93484.php 2021-02-11 11:28:41.998962822 +0100
30 30
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
31 31
use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper;
32 32
use TYPO3\CMS\Extbase\Persistence\Generic\Qom;
33
use TYPO3\CMS\Extbase\Persistence\Generic\Qom\Join;
34
use TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory;
35
use TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface;
33 36
use TYPO3\CMS\Extbase\Persistence\Generic\Query;
34 37
use TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface;
35 38
use TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\BadConstraintException;
......
340 343
     *
341 344
     * @param QueryInterface $query
342 345
     * @return array
343
     * @throws SqlErrorException
346
     * @throws \TYPO3\CMS\Core\Context\Exception\AspectNotFoundException
347
     * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception
348
     * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\SqlErrorException
344 349
     */
345 350
    public function getObjectDataByQuery(QueryInterface $query)
346 351
    {
......
376 381
            }
377 382
        }
378 383

  
384
        $querySource = $query->getSource();
385
        $tableName = $this->resolveWorkspaceOverlaySource($querySource, $query);
386
        if ($tableName === false) {
387
            // No proper source, so we do not have a table name here
388
            // we cannot do an overlay and return the original rows instead.
389
            return $rows;
390
        } else if ($querySource instanceof Qom\JoinInterface) {
391
            // Flatten Source to simple Select
392
            $qob = $this->objectManager->get(QueryObjectModelFactory::class);
393
            $querySource = $qob->selector($tableName, $query->getType());
394
        }
395

  
379 396
        if ($this->configurationManager->isFeatureEnabled('consistentTranslationOverlayHandling') && !empty($rows)) {
380
            $rows = $this->overlayLanguageAndWorkspace($query->getSource(), $rows, $query);
397
            $rows = $this->overlayLanguageAndWorkspace($querySource, $rows, $query);
381 398
        } else {
382
            $rows = $this->doLanguageAndWorkspaceOverlay($query->getSource(), $rows, $query->getQuerySettings());
399
            $rows = $this->doLanguageAndWorkspaceOverlay($querySource, $rows, $query->getQuerySettings());
383 400
        }
384 401

  
385 402
        return $rows;
......
541 558
     * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
542 559
     * @param int|null $workspaceUid
543 560
     * @return array
561
     * @throws \TYPO3\CMS\Core\Context\Exception\AspectNotFoundException
544 562
     */
545 563
    protected function doLanguageAndWorkspaceOverlay(Qom\SourceInterface $source, array $rows, QuerySettingsInterface $querySettings, $workspaceUid = null)
546 564
    {
547 565
        if ($source instanceof Qom\SelectorInterface) {
548 566
            $tableName = $source->getSelectorName();
549
        } elseif ($source instanceof Qom\JoinInterface) {
550
            $tableName = $source->getRight()->getSelectorName();
551 567
        } else {
552 568
            // No proper source, so we do not have a table name here
553 569
            // we cannot do an overlay and return the original rows instead.
......
649 665
     * @param int|null $workspaceUid
650 666
     * @return array
651 667
     * @throws \TYPO3\CMS\Core\Context\Exception\AspectNotFoundException
668
     * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception
652 669
     */
653
    protected function overlayLanguageAndWorkspace(Qom\SourceInterface $source, array $rows, QueryInterface $query, int $workspaceUid = null): array
670
    protected function overlayLanguageAndWorkspace(Qom\SourceInterface &$source, array $rows, QueryInterface $query, int $workspaceUid = null): array
654 671
    {
655 672
        if ($source instanceof Qom\SelectorInterface) {
656 673
            $tableName = $source->getSelectorName();
657
        } elseif ($source instanceof Qom\JoinInterface) {
658
            $tableName = $source->getRight()->getSelectorName();
659 674
        } else {
660 675
            // No proper source, so we do not have a table name here
661 676
            // we cannot do an overlay and return the original rows instead.
......
735 750
    }
736 751

  
737 752
    /**
753
     * Bugfix issue #93484
754
     * https://forge.typo3.org/issues/93484#change-439640
755
     *
756
     * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source
757
     * @param \TYPO3\CMS\Extbase\Persistence\QueryInterface $query
758
     * @return bool
759
     * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception
760
     */
761
    protected function resolveWorkspaceOverlaySource(SourceInterface $source, QueryInterface $query) :? string {
762
        $tableName = null;
763

  
764
        if ($source instanceof Qom\SelectorInterface) {
765
            $tableName = $source->getSelectorName();
766
        } elseif ($source instanceof Qom\JoinInterface) {
767
            /**
768
             * Bugfix issue #93484
769
             * https://forge.typo3.org/issues/93484#change-439640
770
             *
771
             * Derive Table-Name from Model-Name
772
             */
773
            $modelName = $query->getType();
774
            $modelName = '\\' . ltrim($modelName, '\\');
775
            $dataMapper = $this->objectManager->get(DataMapper::class);
776
            $tableName = $dataMapper->getDataMap($modelName)->getTableName();
777
        }
778

  
779
        return $tableName;
780
    }
781

  
782
    /**
738 783
     * Clear the TYPO3 page cache for the given record.
739 784
     * If the record lies on a page, then we clear the cache of this page.
740 785
     * If the record has no PID column, we clear the cache of the current page as best-effort.
(2-2/2)