[BUGFIX] Flaws in copying a page with localized content elements 56/32356/4
authorOliver Hader <oliver@typo3.org>
Mon, 25 Aug 2014 16:00:24 +0000 (18:00 +0200)
committerOliver Hader <oliver.hader@typo3.org>
Thu, 8 Oct 2015 10:47:54 +0000 (12:47 +0200)
Copying a page with localized content elements in a workspace
has some flaws. In a workspace a duplicated record will end up
in a new-placeholder and the specific version record.

The tranlation pointer field of the new-placeholder still
contains the unmodified value of the original record, the
specific version record is fine however.

The reason for that is the special handling for cloning a page
in DataHandler. Each record of a particular table is copied in
reverse order. This way, the localization is created earlier
than the record of the default language.

This change is about skipping the direct copyRecord() call for
records that will be processed inside another copyRecord() call
for the record of the default language.

Resolves: #61179
Releases: master, 6.2
Change-Id: I6647b02095343756d3a41b0c0e985b4777429cd8
Reviewed-on: http://review.typo3.org/32356
Reviewed-by: Andreas Wolf <andreas.wolf@typo3.org>
Tested-by: Andreas Wolf <andreas.wolf@typo3.org>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
typo3/sysext/core/Classes/DataHandling/DataHandler.php
typo3/sysext/core/Tests/Functional/DataHandling/Regular/Modify/DataSet/copyPage.csv
typo3/sysext/workspaces/Tests/Functional/DataHandling/Regular/Modify/DataSet/copyPage.csv
typo3/sysext/workspaces/Tests/Functional/DataHandling/Regular/Publish/DataSet/copyPage.csv
typo3/sysext/workspaces/Tests/Functional/DataHandling/Regular/PublishAll/DataSet/copyPage.csv

index c43ccd3..86ee475 100644 (file)
@@ -3338,7 +3338,13 @@ class DataHandler {
        public function copyRecord($table, $uid, $destPid, $first = FALSE, $overrideValues = array(), $excludeFields = '', $language = 0, $ignoreLocalization = FALSE) {
                $uid = ($origUid = (int)$uid);
                // Only copy if the table is defined in $GLOBALS['TCA'], a uid is given and the record wasn't copied before:
-               if (!$GLOBALS['TCA'][$table] || !$uid || $this->isRecordCopied($table, $uid)) {
+               if (empty($GLOBALS['TCA'][$table]) || $uid === 0) {
+                       return NULL;
+               }
+               if ($this->isRecordCopied($table, $uid)) {
+                       if (!empty($overrideValues)) {
+                               $this->log($table, $uid, 5, 0, 1, 'Repeated attempt to copy record "' . $table . ':' . $uid . '" with override values');
+                       }
                        return NULL;
                }
 
@@ -3532,12 +3538,33 @@ class DataHandler {
                        foreach ($copyTablesArray as $table) {
                                // All records under the page is copied.
                                if ($table && is_array($GLOBALS['TCA'][$table]) && $table != 'pages') {
-                                       $mres = $this->databaseConnection->exec_SELECTquery('uid', $table, 'pid=' . (int)$uid . $this->deleteClause($table), '', $GLOBALS['TCA'][$table]['ctrl']['sortby'] ? $GLOBALS['TCA'][$table]['ctrl']['sortby'] . ' DESC' : '');
-                                       while ($row = $this->databaseConnection->sql_fetch_assoc($mres)) {
+                                       $fields = 'uid';
+                                       $languageField = NULL;
+                                       $transOrigPointerField = NULL;
+                                       if (BackendUtility::isTableLocalizable($table)) {
+                                               $languageField = $GLOBALS['TCA'][$table]['ctrl']['languageField'];
+                                               $transOrigPointerField = $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'];
+                                               $fields .= ',' . $languageField . ',' . $transOrigPointerField;
+                                       }
+                                       $rows = $this->databaseConnection->exec_SELECTgetRows(
+                                               $fields,
+                                               $table,
+                                               'pid=' . (int)$uid . $this->deleteClause($table),
+                                               '',
+                                               (!empty($GLOBALS['TCA'][$table]['ctrl']['sortby']) ? $GLOBALS['TCA'][$table]['ctrl']['sortby'] . ' DESC' : ''),
+                                               '',
+                                               'uid'
+                                       );
+                                       foreach ($rows as $row) {
+                                               // Skip localized records that will be processed in
+                                               // copyL10nOverlayRecords() on copying the default language record
+                                               $transOrigPointer = $row[$transOrigPointerField];
+                                               if ($row[$languageField] > 0 && $transOrigPointer > 0 && isset($rows[$transOrigPointer])) {
+                                                       continue;
+                                               }
                                                // Copying each of the underlying records...
                                                $this->copyRecord($table, $row['uid'], $theNewRootID);
                                        }
-                                       $this->databaseConnection->sql_free_result($mres);
                                }
                        }
                        $this->processRemapStack();
index b934106..d92c131 100644 (file)
@@ -11,7 +11,7 @@ tt_content
 ,298,89,512,0,0,0,0,0,0,0,0,"Regular Element #2"
 ,299,89,768,0,0,0,0,0,0,0,0,"Regular Element #3"
 ,300,89,1024,0,1,299,0,0,0,0,0,"[Translate to Dansk:] Regular Element #3"
-,301,91,256,0,1,302,0,0,0,0,0,"[Translate to Dansk:] Regular Element #3"
-,302,91,128,0,0,0,0,0,0,0,0,"Regular Element #3"
+,301,91,256,0,0,0,0,0,0,0,0,"Regular Element #3"
+,302,91,128,0,1,301,0,0,0,0,0,"[Translate to Dansk:] Regular Element #3"
 ,303,91,64,0,0,0,0,0,0,0,0,"Regular Element #2"
 ,304,91,32,0,0,0,0,0,0,0,0,"Regular Element #1"
index 7ceb653..4b9efb5 100644 (file)
@@ -13,10 +13,10 @@ tt_content
 ,299,89,768,0,0,0,0,0,0,0,0,"Regular Element #3"
 ,300,89,1024,0,1,299,0,0,0,0,0,"[Translate to Dansk:] Regular Element #3"
 ,301,-1,512,0,0,0,2,2,0,298,0,"Regular Element #2"
-,302,91,256,0,1,299,1,1,0,0,0,"[Translate to Dansk:] Regular Element #3"
-,303,-1,256,0,1,304,1,-1,0,302,0,"[Translate to Dansk:] Regular Element #3"
-,304,91,128,0,0,0,1,1,0,0,0,"Regular Element #3"
-,305,-1,128,0,0,0,1,-1,0,304,0,"Regular Element #3"
+,302,91,256,0,0,0,1,1,0,0,0,"Regular Element #3"
+,303,-1,256,0,0,0,1,-1,0,302,0,"Regular Element #3"
+,304,91,128,0,1,302,1,1,0,0,0,"[Translate to Dansk:] Regular Element #3"
+,305,-1,128,0,1,302,1,-1,0,304,0,"[Translate to Dansk:] Regular Element #3"
 ,306,91,64,0,0,0,1,1,0,0,0,"Regular Element #2"
 ,307,-1,64,0,0,0,1,-1,0,306,0,"Regular Element #2"
 ,308,91,32,0,0,0,1,1,0,0,0,"Regular Element #1"
index e2a36e1..2d444da 100644 (file)
@@ -12,9 +12,9 @@ tt_content
 ,299,89,768,0,0,0,0,0,0,0,0,"Regular Element #3"
 ,300,89,1024,0,1,299,0,0,0,0,0,"[Translate to Dansk:] Regular Element #3"
 ,301,-1,512,0,0,0,2,2,0,298,0,"Regular Element #2"
-,302,91,256,0,1,299,1,1,0,0,0,"[Translate to Dansk:] Regular Element #3"
-,303,-1,256,0,1,304,1,-1,0,302,0,"[Translate to Dansk:] Regular Element #3"
-,304,91,128,0,0,0,1,1,0,0,0,"Regular Element #3"
-,305,-1,128,0,0,0,1,-1,0,304,0,"Regular Element #3"
+,302,91,256,0,0,0,1,1,0,0,0,"Regular Element #3"
+,303,-1,256,0,0,0,1,-1,0,302,0,"Regular Element #3"
+,304,91,128,0,1,302,1,1,0,0,0,"[Translate to Dansk:] Regular Element #3"
+,305,-1,128,0,1,302,1,-1,0,304,0,"[Translate to Dansk:] Regular Element #3"
 ,306,91,64,0,0,0,0,0,0,0,0,"Regular Element #2"
 ,308,91,32,0,0,0,0,0,0,0,0,"Regular Element #1"
index 488d315..fb62935 100644 (file)
@@ -12,7 +12,7 @@ tt_content
 ,299,89,768,0,0,0,0,0,0,0,0,"Regular Element #3"
 ,300,89,1024,0,1,299,0,0,0,0,0,"[Translate to Dansk:] Regular Element #3"
 ,301,-1,512,0,0,0,2,2,0,298,0,"Regular Element #2"
-,302,91,256,0,1,299,0,0,0,0,0,"[Translate to Dansk:] Regular Element #3"
-,304,91,128,0,0,0,0,0,0,0,0,"Regular Element #3"
+,302,91,256,0,0,0,0,0,0,0,0,"Regular Element #3"
+,304,91,128,0,1,302,0,0,0,0,0,"[Translate to Dansk:] Regular Element #3"
 ,306,91,64,0,0,0,0,0,0,0,0,"Regular Element #2"
 ,308,91,32,0,0,0,0,0,0,0,0,"Regular Element #1"