[BUGFIX] Resolve and link modified slugs in workspaces properly 55/59955/6
authorBenni Mack <benni@typo3.org>
Sat, 9 Mar 2019 13:36:57 +0000 (14:36 +0100)
committerOliver Hader <oliver.hader@typo3.org>
Mon, 25 Mar 2019 14:57:29 +0000 (15:57 +0100)
When a page (slug) is modified in a preview workspace,
links to that page need to be changed to the new slug, as the
preview (PageRouter) should evaluate this as well.

1) The PageRouter should include records with "-1"
to find them as well, but then fix the "pid" again to
find the pid of the online version.

2) The PageLink Builder now uses the SiteFinder nstead of SiteMatcher
to detect whether the linked page uid is part of a configured site.
We do not need to create/detect a PseudoSite here, only instances
of Site are of interest.

Resolves: #87871
Releases: master, 9.5
Change-Id: Ifd6add71bec1616049f8c6a50a42bc9f573395e2
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/59955
Tested-by: Benjamin Franzke <bfr@qbus.de>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
Reviewed-by: Benjamin Franzke <bfr@qbus.de>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
typo3/sysext/core/Classes/Routing/PageRouter.php
typo3/sysext/frontend/Classes/Typolink/PageLinkBuilder.php
typo3/sysext/frontend/Tests/Functional/SiteHandling/Fixtures/SlugScenario.yaml
typo3/sysext/frontend/Tests/Functional/SiteHandling/SlugLinkGeneratorTest.php

index 4e3afb6..00d04d5 100644 (file)
@@ -326,13 +326,15 @@ class PageRouter implements RouterInterface
      */
     protected function getPagesFromDatabaseForCandidates(array $slugCandidates, int $languageId): array
     {
+        $context = GeneralUtility::makeInstance(Context::class);
+        $searchLiveRecordsOnly = $context->getPropertyFromAspect('workspace', 'isLive');
         $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
             ->getQueryBuilderForTable('pages');
         $queryBuilder
             ->getRestrictions()
             ->removeAll()
             ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
-            ->add(GeneralUtility::makeInstance(FrontendWorkspaceRestriction::class));
+            ->add(GeneralUtility::makeInstance(FrontendWorkspaceRestriction::class, null, null, $searchLiveRecordsOnly));
 
         $statement = $queryBuilder
             ->select('uid', 'l10n_parent', 'pid', 'slug')
@@ -356,7 +358,9 @@ class PageRouter implements RouterInterface
 
         $pages = [];
         $siteMatcher = GeneralUtility::makeInstance(SiteMatcher::class);
+        $pageRepository = GeneralUtility::makeInstance(PageRepository::class, $context);
         while ($row = $statement->fetch()) {
+            $pageRepository->fixVersioningPid('pages', $row);
             $pageIdInDefaultLanguage = (int)($languageId > 0 ? $row['l10n_parent'] : $row['uid']);
             try {
                 if ($siteMatcher->matchByPageId($pageIdInDefaultLanguage)->getRootPageId() === $this->site->getRootPageId()) {
index e60abaa..ca54c25 100644 (file)
@@ -31,6 +31,7 @@ use TYPO3\CMS\Core\Routing\SiteMatcher;
 use TYPO3\CMS\Core\Site\Entity\Site;
 use TYPO3\CMS\Core\Site\Entity\SiteInterface;
 use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
+use TYPO3\CMS\Core\Site\SiteFinder;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\HttpUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
@@ -179,7 +180,7 @@ class PageLinkBuilder extends AbstractTypolinkBuilder
 
         // Check if the target page has a site configuration
         try {
-            $siteOfTargetPage = GeneralUtility::makeInstance(SiteMatcher::class)->matchByPageId((int)$page['uid']);
+            $siteOfTargetPage = GeneralUtility::makeInstance(SiteFinder::class)->getSiteByPageId((int)$page['uid']);
             $currentSite = $this->getCurrentSite();
         } catch (SiteNotFoundException $e) {
             // Usually happens in tests, as Pseudo Sites should be available everywhere.
@@ -188,7 +189,7 @@ class PageLinkBuilder extends AbstractTypolinkBuilder
         }
 
         // Link to a page that has a site configuration
-        if ($siteOfTargetPage instanceof Site) {
+        if ($siteOfTargetPage !== null) {
             $siteLanguageOfTargetPage = $this->getSiteLanguageOfTargetPage($siteOfTargetPage, (string)($conf['language'] ?? 'current'));
             $languageAspect = LanguageAspectFactory::createFromSiteLanguage($siteLanguageOfTargetPage);
 
index d9ad70b..d58412a 100644 (file)
@@ -56,7 +56,7 @@ entities:
             - self: {id: 1101, title: 'FR: Welcome', language: 1, slug: '/bienvenue', subtitle: 'salut-et-bienvenue'}
             - self: {id: 1102, title: 'FR-CA: Welcome', language: 2, slug: '/bienvenue', subtitle: 'salut-et-bienvenue'}
           versionVariants:
-            - version: {title: 'EN: Welcome to ACME Inc', workspace: 1, slug: '/welcome'}
+            - version: {title: 'EN: Welcome to ACME Inc', workspace: 1, slug: '/welcome-modified'}
           entities:
             content:
               - self: {title: 'EN: Content Element #1', type: *contentText}
index a2bd9a7..2acf443 100644 (file)
@@ -586,8 +586,8 @@ class SlugLinkGeneratorTest extends AbstractTestCase
     {
         $instructions = [
             // acme.com -> acme.com (same site): link to changed page
-            ['https://acme.us/', 1100, 1100, false, 1, '/welcome'],
-            ['https://acme.us/', 1100, 1100, true, 1, '/welcome'],
+            ['https://acme.us/', 1100, 1100, false, 1, '/welcome-modified'],
+            ['https://acme.us/', 1100, 1100, true, 1, '/welcome-modified'],
             ['https://acme.us/', 1100, 1100, false, 0, '/welcome'],
             ['https://acme.us/', 1100, 1100, true, 0, '/index.php?id={targetPageId}'], // @todo this is wrong, link should be empty
             // acme.com -> acme.com (same site): link to new page
@@ -596,8 +596,8 @@ class SlugLinkGeneratorTest extends AbstractTestCase
             ['https://acme.us/', 1100, 1950, false, 0, ''],
             ['https://acme.us/', 1100, 1950, true, 0, '/index.php?id={targetPageId}'], // @todo this is wrong, link should be empty
             // blog.acme.com -> acme.com (different site): link to changed page
-            ['https://blog.acme.com/', 2100, 1100, false, 1, 'https://acme.us/welcome'],
-            ['https://blog.acme.com/', 2100, 1100, true, 1, 'https://acme.us/welcome'],
+            ['https://blog.acme.com/', 2100, 1100, true, 1, 'https://acme.us/welcome-modified'],
+            ['https://blog.acme.com/', 2100, 1100, false, 1, 'https://acme.us/welcome-modified'],
             ['https://blog.acme.com/', 2100, 1100, false, 0, 'https://acme.us/welcome'],
             ['https://blog.acme.com/', 2100, 1100, true, 0, '/index.php?id=7131'], // @todo this is wrong, link should be empty
             // blog.acme.com -> acme.com (different site): link to new page