Fixed bug #2314: When moving records the translation do not move with it (thanks...
authorRupert Germann <rupi@gmx.li>
Tue, 20 Oct 2009 19:51:27 +0000 (19:51 +0000)
committerRupert Germann <rupi@gmx.li>
Tue, 20 Oct 2009 19:51:27 +0000 (19:51 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@6193 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_clipboard.php
t3lib/class.t3lib_tcemain.php

index 8b09baf..11299e7 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -23,6 +23,7 @@
 
 2009-10-20  Rupert Germann  <rupi@gmx.li>
 
+       * Fixed bug #2314: When moving records the translation do not move with it (thanks to Tolleiv Nietsch)
        * Fixed bug #539: lang-children "get lost"(should be deleted) when deleting parent-record in default language (thanks to Tolleiv Nietsch)
        * Fixed bug #10081: t3lib_div must not die if a locallang file is not found (thanks to Franz Holzinger)
        * Fixed bug #12194: The filetree does not show whether a folder is write protected
index 6bf5f76..21545b6 100644 (file)
@@ -466,6 +466,9 @@ class t3lib_clipboard {
                                                                        '<a href="'.htmlspecialchars($this->removeUrl($table,$uid)).'#clip_head"><img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/close_12h.gif','width="11" height="12"').' border="0" title="'.$this->clLabel('removeItem').'" alt="" /></a>'.
                                                                        '</td>
                                                                </tr>';
+
+                                                       $lines[] = $this->getLocalisations($table, $rec, $bgColClass, $pad);
+
                                                } else {
                                                        unset($this->clipData[$pad]['el'][$k]);
                                                        $this->changed=1;
@@ -486,6 +489,51 @@ class t3lib_clipboard {
                return $lines;
        }
 
+
+       /**
+        * returns all localisations of the current record
+        *
+        * @param       string          the table
+        * @param       array           the current record
+        * @return      string          HTML table rows
+        */
+       function getLocalisations($table, $parentRec, $bgColClass, $pad) {
+
+               $lines = array();
+               if ($table != 'pages' &&
+                               $GLOBALS['TCA'][$table]['ctrl']['languageField'] &&
+                               $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']
+                               && !$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerTable']) {
+                       $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+                               '*',
+                               $table,
+                               $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'] . '=' . intval($parentRec['uid']) .
+                                       ' AND ' . $GLOBALS['TCA'][$table]['ctrl']['languageField'] . '!=0' .
+                                       ' AND ' . $GLOBALS['TCA'][$table]['ctrl']['delete'] . '=0' .
+                                       ' AND t3ver_wsid=' . $parentRec['t3ver_wsid']
+                       );
+
+                       foreach ($rows as $rec) {
+                               $lines[]='
+                               <tr>
+                                       <td class="' . $bgColClass . '">' .
+                                               t3lib_iconWorks::getIconImage($table, $rec, $this->backPath,' style="margin-left: 38px;"') . '</td>
+                                       <td class="' . $bgColClass . '" nowrap="nowrap" width="95%">&nbsp;' . htmlspecialchars(
+                                                       t3lib_div::fixed_lgd_cs(t3lib_BEfunc::getRecordTitle($table, $rec), $GLOBALS['BE_USER']->uc['titleLen'])) .
+                                                       ($pad == 'normal' ? (
+                                                               ' <strong>(' . ($this->clipData['normal']['mode'] == 'copy' ? $this->clLabel('copy', 'cm') :
+                                                               $this->clLabel('cut','cm')).')</strong>') :
+                                                               ''
+                                                       ) . '&nbsp;</td>
+                                       <td class="' . $bgColClass . '" align="center" nowrap="nowrap">&nbsp;</td>
+                               </tr>';
+                       }
+               }
+               return implode('',$lines);
+       }
+
+
+
        /**
         * Wraps title of pad in bold-tags and maybe the number of elements if any.
         *
index 2b4b982..73f340e 100644 (file)
@@ -3425,7 +3425,7 @@ class t3lib_TCEmain       {
                        }
 
                                // Checking if there is anything else disallowing moving the record by checking if editing is allowed
-                       $mayEditAccess = $this->BE_USER->recordEditAccessInternals($table,$uid);
+                       $mayEditAccess = $this->BE_USER->recordEditAccessInternals($table, $uid, false, false, true);
 
                                // If moving is allowed, begin the processing:
                        if ($mayEditAccess)     {
@@ -3540,6 +3540,14 @@ class t3lib_TCEmain      {
                        $newVersion_placeholderFieldArray['t3ver_wsid'] = $this->BE_USER->workspace;    // Setting workspace - only so display of place holders can filter out those from other workspaces.
                        $newVersion_placeholderFieldArray[$TCA[$table]['ctrl']['label']] = '[MOVE-TO PLACEHOLDER for #'.$uid.', WS#'.$this->BE_USER->workspace.']';
 
+                               // moving localized records requires to keep localization-settings for the placeholder too
+                       if (array_key_exists('languageField', $GLOBALS['TCA'][$table]['ctrl']) && array_key_exists('transOrigPointerField', $GLOBALS['TCA'][$table]['ctrl'])) {
+                               $l10nParentRec = t3lib_BEfunc::getRecord($table, $uid);
+                               $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['languageField']] = $l10nParentRec[$GLOBALS['TCA'][$table]['ctrl']['languageField']];
+                               $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] = $l10nParentRec[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']];
+                               unset($l10nParentRec);
+                       }
+
                        $newVersion_placeholderFieldArray['pid'] = 0;   // Initially, create at root level.
                        $id = 'NEW_MOVE_PLH';
                        $this->insertDB($table,$id,$newVersion_placeholderFieldArray,FALSE);    // Saving placeholder as 'original'
@@ -3552,6 +3560,9 @@ class t3lib_TCEmain       {
                        $updateFields['t3ver_state'] = 4;       // Setting placeholder state value for version (so it can know it is currently a new version...)
                        $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid='.intval($wsUid), $updateFields);
                }
+
+                       //check for the localizations of that element and move them as well
+               $this->moveL10nOverlayRecords($table, $uid, $destPid);
        }
 
        /**
@@ -3609,6 +3620,8 @@ class t3lib_TCEmain       {
                                $this->moveRecord_procFields($table,$uid,$destPid);
                                        // Create query for update:
                                $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid='.intval($uid), $updateFields);
+                                       // check for the localizations of that element
+                               $this->moveL10nOverlayRecords($table, $uid, $destPid);
 
                                        // Call post processing hooks:
                                foreach($hookObjectsArr as $hookObj) {
@@ -3652,6 +3665,8 @@ class t3lib_TCEmain       {
                                                $this->moveRecord_procFields($table,$uid,$destPid);
                                                        // Create query for update:
                                                $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid='.intval($uid), $updateFields);
+                                                       // check for the localizations of that element
+                                               $this->moveL10nOverlayRecords($table, $uid, $destPid);
 
                                                        // Call post processing hooks:
                                                foreach($hookObjectsArr as $hookObj) {
@@ -3750,6 +3765,27 @@ class t3lib_TCEmain      {
        }
 
        /**
+        * Find l10n-overlay records and perform the requested move action for these records.
+        *
+        * @param       string          $table: Record Table
+        * @param       string          $uid: Record UID
+        * @param       string          $destPid: Position to move to
+        * @return      void
+        */
+       function moveL10nOverlayRecords($table, $uid, $destPid) {
+                       //there's no need to perform this for page-records
+               if ($table == 'pages') return;
+               t3lib_div::loadTCA($table);
+
+               $l10nRecords = t3lib_BEfunc::getRecordsByField($table, $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'], $uid);
+               if (is_array($l10nRecords)) {
+                       foreach ($l10nRecords as $record) {
+                               $this->moveRecord($table, $record['uid'], $destPid);
+                       }
+               }
+       }
+
+       /**
         * Localizes a record to another system language
         * In reality it only works if transOrigPointerTable is not set. For "pages" the implementation is hardcoded
         *
@@ -4646,6 +4682,10 @@ class t3lib_TCEmain      {
                                                                                if ($TCA[$table]['ctrl']['sortby'])     {
                                                                                        $keepFields[] = $TCA[$table]['ctrl']['sortby'];
                                                                                }
+                                                                                       // l10n-fields must be kept otherwise the localization will be lost during the publishing
+                                                                               if ($TCA[$table]['ctrl']['transOrigPointerField']) {
+                                                                                       $keepFields[] = $TCA[$table]['ctrl']['transOrigPointerField'];
+                                                                               }
 
                                                                                        // Swap "keepfields"
                                                                                foreach($keepFields as $fN)     {