[BUGFIX] Flaws in copying a page with localized content elements 06/43906/2
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:51:54 +0000 (12:51 +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/43906
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 fa067ad..2967d44 100644 (file)
@@ -3089,13 +3089,15 @@ class DataHandler {
         * @param array $overrideValues Associative array with field/value pairs to override directly. Notice; Fields must exist in the table record and NOT be among excluded fields!
         * @param string $excludeFields Commalist of fields to exclude from the copy process (might get default values)
         * @param integer $language Language ID (from sys_language table)
-        * @return integer ID of new record, if any
-        * @todo Define visibility
+        * @return NULL|int ID of new record, if any
         */
        public function copyRecord($table, $uid, $destPid, $first = 0, $overrideValues = array(), $excludeFields = '', $language = 0) {
                $uid = ($origUid = (int)$uid);
+               if (empty($GLOBALS['TCA'][$table]) || $uid === 0) {
+                       return NULL;
+               }
                // 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 (!$this->isRecordCopied($table, $uid)) {
                        // This checks if the record can be selected which is all that a copy action requires.
                        if ($this->doesRecordExist($table, $uid, 'show')) {
                                // Check if table is allowed on destination page
@@ -3199,6 +3201,8 @@ class DataHandler {
                        } else {
                                $this->log($table, $uid, 3, 0, 1, 'Attempt to copy record without permission');
                        }
+               } elseif (!empty($overrideValues)) {
+                       $this->log($table, $uid, 5, 0, 1, 'Repeated attemp to copy record "' . $table . ':' . $uid . '" with override values');
                }
        }
 
@@ -3270,12 +3274,33 @@ class DataHandler {
                        foreach ($copyTablesArray as $table) {
                                // All records under the page is copied.
                                if ($table && is_array($GLOBALS['TCA'][$table]) && $table != 'pages') {
-                                       $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid', $table, 'pid=' . (int)$uid . $this->deleteClause($table), '', $GLOBALS['TCA'][$table]['ctrl']['sortby'] ? $GLOBALS['TCA'][$table]['ctrl']['sortby'] . ' DESC' : '');
-                                       while ($row = $GLOBALS['TYPO3_DB']->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 = $GLOBALS['TYPO3_DB']->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);
                                        }
-                                       $GLOBALS['TYPO3_DB']->sql_free_result($mres);
                                }
                        }
                        return $theNewRootID;
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"