Bug #81208 » 81208_v9.diff

Ralf Merz, 2019-10-08 15:46

View differences:

Classes/Persistence/Generic/Storage/Typo3DbBackend.php
546 546
    {
547 547
        if ($source instanceof Qom\SelectorInterface) {
548 548
            $tableName = $source->getSelectorName();
549
            $forceRecordReloadInWorkspace = false;
549 550
        } elseif ($source instanceof Qom\JoinInterface) {
550 551
            $tableName = $source->getRight()->getSelectorName();
552
            $forceRecordReloadInWorkspace = true;
551 553
        } else {
552 554
            // No proper source, so we do not have a table name here
553 555
            // we cannot do an overlay and return the original rows instead.
......
569 571
        // by the table and if there's only one row in the result set
570 572
        // (applying this to all rows does not work, since the sorting
571 573
        // order would be destroyed and possible limits not met anymore)
572
        if (!empty($workspaceUid)
573
            && BackendUtility::isTableWorkspaceEnabled($tableName)
574
            && count($rows) === 1
574
        $isInWorkspaceContext = !empty($workspaceUid)
575
          && BackendUtility::isTableWorkspaceEnabled($tableName);
576
        if ($isInWorkspaceContext && count($rows) === 1
575 577
        ) {
576 578
            $queryBuilder = $this->connectionPool->getQueryBuilderForTable($tableName);
577 579
            $queryBuilder->getRestrictions()->removeAll();
......
588 590
                ->fetch();
589 591
            if (!empty($movePlaceholder)) {
590 592
                $rows = [$movePlaceholder];
593
                // Records have been "reloaded"
594
                $forceRecordReloadInWorkspace = false;
591 595
            }
592 596
        }
593 597

  
594 598
        $overlaidRows = [];
595 599
        foreach ($rows as $row) {
596
            // If current row is a translation select its parent
600
            $originalRow = $row;
601
            // If current row is a translation or we are in a workspace preview, select its parent
597 602
            if (isset($tableName) && isset($GLOBALS['TCA'][$tableName])
598 603
                && isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])
599 604
                && isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'])
600 605
                && isset($row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']])
601
                && $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] > 0
606
                && (
607
                  $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] > 0
608
                  || ($forceRecordReloadInWorkspace && $isInWorkspaceContext)
609
                )
602 610
            ) {
603 611
                $queryBuilder = $this->connectionPool->getQueryBuilderForTable($tableName);
604 612
                $queryBuilder->getRestrictions()->removeAll();
......
633 641
                $row = $pageRepository->getRecordOverlay($tableName, $row, $querySettings->getLanguageUid(), $overlayMode);
634 642
            }
635 643
            if (is_array($row)) {
644
                if ($forceRecordReloadInWorkspace && $isInWorkspaceContext) {
645
                    // Add additional fields back to the overlaid record
646
                    $row = array_merge($originalRow, $row);
647
                    //$row = array_merge(...$row);
648
                }
636 649
                $overlaidRows[] = $row;
637 650
            }
638 651
        }
......
654 667
    {
655 668
        if ($source instanceof Qom\SelectorInterface) {
656 669
            $tableName = $source->getSelectorName();
670
            $forceRecordReloadInWorkspace = false;
657 671
        } elseif ($source instanceof Qom\JoinInterface) {
658 672
            $tableName = $source->getRight()->getSelectorName();
673
            $forceRecordReloadInWorkspace = true;
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.
......
677 692
        // by the table and if there's only one row in the result set
678 693
        // (applying this to all rows does not work, since the sorting
679 694
        // order would be destroyed and possible limits not met anymore)
680
        if (!empty($workspaceUid)
681
            && BackendUtility::isTableWorkspaceEnabled($tableName)
682
            && count($rows) === 1
683
        ) {
695
        $isInWorkspaceContext = !empty($workspaceUid)
696
          && BackendUtility::isTableWorkspaceEnabled($tableName);
697
        if ($isInWorkspaceContext && count($rows) === 1) {
684 698
            $versionId = $workspaceUid;
685 699
            $queryBuilder = $this->connectionPool->getQueryBuilderForTable($tableName);
686 700
            $queryBuilder->getRestrictions()->removeAll();
......
697 711
                ->fetchAll();
698 712
            if (!empty($movePlaceholder)) {
699 713
                $rows = $movePlaceholder;
714
                // Records have been "reloaded"
715
                $forceRecordReloadInWorkspace = false;
700 716
            }
701 717
        }
702 718
        $overlaidRows = [];
703 719
        foreach ($rows as $row) {
720
            $originalRow = $row;
721
            // If current row is a translation or we are in a workspace preview, select its parent
722
            if (isset($tableName) && isset($GLOBALS['TCA'][$tableName])
723
              && isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])
724
              && isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'])
725
              && isset($row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']])
726
              && (
727
                $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] > 0
728
                || ($forceRecordReloadInWorkspace && $isInWorkspaceContext)
729
              )
730
            ) {
731
                $queryBuilder = $this->connectionPool->getQueryBuilderForTable($tableName);
732
                $queryBuilder->getRestrictions()->removeAll();
733
                $row = $queryBuilder
734
                  ->select($tableName . '.*')
735
                  ->from($tableName)
736
                  ->where(
737
                    $queryBuilder->expr()->eq(
738
                      $tableName . '.uid',
739
                      $queryBuilder->createNamedParameter(
740
                        $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']],
741
                        \PDO::PARAM_INT
742
                      )
743
                    ),
744
                    $queryBuilder->expr()->eq(
745
                      $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'],
746
                      $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
747
                    )
748
                  )
749
                  ->setMaxResults(1)
750
                  ->execute()
751
                  ->fetch();
752
            }
753

  
754

  
704 755
            $pageRepository->versionOL($tableName, $row, true);
705 756
            $querySettings = $query->getQuerySettings();
706 757
            if (is_array($row) && $querySettings->getLanguageOverlayMode()) {
......
728 779
                }
729 780
            }
730 781
            if ($row !== null && is_array($row)) {
782
                if ($forceRecordReloadInWorkspace && $isInWorkspaceContext) {
783
                    // Add additional fields back to the overlaid record
784
                    $row = array_merge($originalRow, $row);
785
                }
731 786
                $overlaidRows[] = $row;
732 787
            }
733 788
        }
(4-4/5)