[BUGFIX] Make slugs unique when copying pages 86/59686/5
authorHelmut Hummel <typo3@helhum.io>
Tue, 12 Feb 2019 17:45:35 +0000 (18:45 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 1 Mar 2019 16:02:34 +0000 (17:02 +0100)
When a page is copied the slug for the copied page
needs to be unique for a site. To accomplish that,
the site for the record is fetched. Since this new
record does not have a uid yet, the parent page uid
must be used to determine the site.

Resolves: #87697
Releases: master, 9.5
Change-Id: Iac5fa7adc673c41662b652e932c23b90633e0d5d
Reviewed-on: https://review.typo3.org/c/59686
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Jürgen Venne <venne@schaffrath-digital.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Jürgen Venne <venne@schaffrath-digital.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/core/Classes/DataHandling/SlugHelper.php
typo3/sysext/core/Tests/Functional/DataHandling/Regular/DataSet/LiveDefaultPages.csv
typo3/sysext/core/Tests/Functional/DataHandling/Regular/Modify/DataSet/copyPage.csv

index ed4c603..fd4bcc4 100644 (file)
@@ -256,10 +256,16 @@ class SlugHelper
      */
     public function isUniqueInSite(string $slug, RecordState $state): bool
     {
-        $pageId = (int)$state->resolveNodeAggregateIdentifier();
+        $pageId = $state->resolveNodeAggregateIdentifier();
         $recordId = $state->getSubject()->getIdentifier();
         $languageId = $state->getContext()->getLanguageId();
 
+        if (!MathUtility::canBeInterpretedAsInteger($pageId)) {
+            // If this is a new page, we use the parent page to resolve the site
+            $pageId = $state->getNode()->getIdentifier();
+        }
+        $pageId = (int)$pageId;
+
         if ($pageId < 0) {
             $pageId = $this->resolveLivePageId($recordId);
         }
index 6c06853..92e9708 100644 (file)
@@ -1,6 +1,6 @@
-"pages",,,,,,,,,,,,,
-,"uid","pid","sorting","deleted","sys_language_uid","l10n_parent","t3_origuid","t3ver_wsid","t3ver_state","t3ver_stage","t3ver_oid","t3ver_move_id","title"
-,1,0,256,0,0,0,0,0,0,0,0,0,"FunctionalTest"
-,88,1,256,0,0,0,0,0,0,0,0,0,"DataHandlerTest"
-,89,88,256,0,0,0,0,0,0,0,0,0,"Relations"
-,90,88,512,0,0,0,0,0,0,0,0,0,"Target"
+"pages",,,,,,,,,,,,,,
+,"uid","pid","sorting","deleted","sys_language_uid","l10n_parent","t3_origuid","t3ver_wsid","t3ver_state","t3ver_stage","t3ver_oid","t3ver_move_id","title","slug"
+,1,0,256,0,0,0,0,0,0,0,0,0,"FunctionalTest","/"
+,88,1,256,0,0,0,0,0,0,0,0,0,"DataHandlerTest","/data-handler"
+,89,88,256,0,0,0,0,0,0,0,0,0,"Relations","/data-handler/relations"
+,90,88,512,0,0,0,0,0,0,0,0,0,"Target","/data-handler/target"
index db37b4f..769adec 100644 (file)
@@ -1,10 +1,10 @@
 "pages",,,,,,,,,,,,,,
-,"uid","pid","sorting","deleted","t3_origuid","t3ver_wsid","t3ver_state","t3ver_stage","t3ver_oid","t3ver_move_id","title",,,
-,1,0,256,0,0,0,0,0,0,0,"FunctionalTest",,,
-,88,1,256,0,0,0,0,0,0,0,"DataHandlerTest",,,
-,89,88,256,0,0,0,0,0,0,0,"Relations",,,
-,90,88,512,0,0,0,0,0,0,0,"Target",,,
-,91,90,256,0,89,0,0,0,0,0,"Relations",,,
+,"uid","pid","sorting","deleted","t3_origuid","t3ver_wsid","t3ver_state","t3ver_stage","t3ver_oid","t3ver_move_id","title","slug",,
+,1,0,256,0,0,0,0,0,0,0,"FunctionalTest","/",,
+,88,1,256,0,0,0,0,0,0,0,"DataHandlerTest","/data-handler",,
+,89,88,256,0,0,0,0,0,0,0,"Relations","/data-handler/relations",,
+,90,88,512,0,0,0,0,0,0,0,"Target","/data-handler/target",,
+,91,90,256,0,89,0,0,0,0,0,"Relations","/data-handler/relations-1",,
 "tt_content",,,,,,,,,,,,,,
 ,"uid","pid","sorting","deleted","sys_language_uid","l18n_parent","l10n_source","t3_origuid","t3ver_wsid","t3ver_state","t3ver_stage","t3ver_oid","t3ver_move_id","header"
 ,296,88,256,0,0,0,0,0,0,0,0,0,0,"Regular Element #0"