Fixed bug #16846: Sorting order of newly created child elements on workspaces is...
authorOliver Hader <oliver.hader@typo3.org>
Tue, 28 Dec 2010 15:30:59 +0000 (15:30 +0000)
committerOliver Hader <oliver.hader@typo3.org>
Tue, 28 Dec 2010 15:30:59 +0000 (15:30 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@9950 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_loaddbgroup.php

index a058d53..2e80e55 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-12-28  Oliver Hader  <oliver.hader@typo3.org>
+
+       * Fixed bug #16846: Sorting order of newly created child elements on workspaces is wrong
+
 2010-12-28  Steffen Gebert  <steffen@steffen-gebert.de>
 
        * Fixed bug #16093: Media content object with selection of "HTML Embed Element" does not respect dimension settings (Thanks to Simon Schaufelberger)
index c444535..5ecb171 100644 (file)
@@ -620,7 +620,18 @@ class t3lib_loadDBGroup {
                        if (!(t3lib_div::testInt($updateToUid) && $updateToUid > 0)) {
                                $updateToUid = 0;
                        }
-                       $fields = 'uid,' . $foreign_field . ($symmetric_field ? ',' . $symmetric_field : '');
+
+                       $considerWorkspaces = ($GLOBALS['BE_USER']->workspace !== 0 && t3lib_BEfunc::isTableWorkspaceEnabled($foreign_table));
+
+                       $fields = 'uid,' . $foreign_field;
+                               // Consider the symmetric field if defined:
+                       if ($symmetric_field) {
+                               $fields .= ',' . $symmetric_field;
+                       }
+                               // Consider workspaces if defined and currently used:
+                       if ($considerWorkspaces) {
+                               $fields .= ',' . 't3ver_state,t3ver_oid';
+                       }
 
                                // update all items
                        foreach ($this->itemArray as $val) {
@@ -628,12 +639,15 @@ class t3lib_loadDBGroup {
                                $table = $val['table'];
 
                                        // fetch the current (not overwritten) relation record if we should handle symmetric relations
-                               if ($conf['symmetric_field']) {
+                               if ($symmetric_field || $considerWorkspaces) {
                                        $row = t3lib_BEfunc::getRecord($table, $uid, $fields, '', FALSE);
+                               }
+                               if ($symmetric_field) {
                                        $isOnSymmetricSide = t3lib_loadDBGroup::isOnSymmetricSide($parentUid, $conf, $row);
                                }
 
                                $updateValues = array();
+                               $workspaceValues = array();
 
                                        // no update to the uid is requested, so this is the normal behaviour
                                        // just update the fields and care about sorting
@@ -658,15 +672,16 @@ class t3lib_loadDBGroup {
                                                } elseif ($GLOBALS['TCA'][$foreign_table]['ctrl']['sortby']) { // manual sortby for all table records
                                                        $sortby = $GLOBALS['TCA'][$foreign_table]['ctrl']['sortby'];
                                                }
-                                                       // strip a possible "ORDER BY" in front of the $sortby value
-                                               $sortby = $GLOBALS['TYPO3_DB']->stripOrderBy($sortby);
-                                               $symSortby = $conf['symmetric_sortby'];
-
-                                                       // set the sorting on the right side, it depends on who created the relation, so what uid is in the symmetric_field
-                                               if ($isOnSymmetricSide && $symSortby) {
-                                                       $updateValues[$symSortby] = ++$c;
-                                               } elseif ($sortby) {
-                                                       $updateValues[$sortby] = ++$c;
+                                                       // Apply sorting on the symmetric side (it depends on who created the relation, so what uid is in the symmetric_field):
+                                               if ($isOnSymmetricSide && isset($conf['symmetric_sortby']) && $conf['symmetric_sortby']) {
+                                                       $sortby = $conf['symmetric_sortby'];
+                                                       // Strip a possible "ORDER BY" in front of the $sortby value:
+                                               } else {
+                                                       $sortby = $GLOBALS['TYPO3_DB']->stripOrderBy($sortby);
+                                               }
+
+                                               if ($sortby) {
+                                                       $updateValues[$sortby] = $workspaceValues[$sortby] = ++$c;
                                                }
                                        }
 
@@ -680,10 +695,17 @@ class t3lib_loadDBGroup {
                                        }
                                }
 
+                                       // Update accordant fields in the database:
                                if (count($updateValues)) {
                                        $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid=' . intval($uid), $updateValues);
                                        $this->updateRefIndex($table, $uid);
                                }
+                                       // Update accordant fields in the database for workspaces overlays/placeholders:
+                               if (count($workspaceValues) && $considerWorkspaces) {
+                                       if (isset($row['t3ver_oid']) && $row['t3ver_oid'] && $row['t3ver_state'] == -1) {
+                                               $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid=' . intval($row['t3ver_oid']), $workspaceValues);
+                                       }
+                               }
                        }
                }
        }