[BUGFIX] Avoid SQL error when module is opened on moved page
authorTolleiv Nietsch <info@tolleiv.de>
Sat, 5 Mar 2011 09:49:29 +0000 (04:49 -0500)
committerTolleiv Nietsch <info@tolleiv.de>
Sun, 6 Mar 2011 19:59:00 +0000 (14:59 -0500)
In case the backend module is opened on a page which was moved
within the current workspace there's a SQL error caused because
the processing for the relevant "Pagetree" runs empty.
Adding the current page to the processing can never break this part
because it will always be part of the result anyways.

Change-Id: I57d7740a4c436bf3fd44b8cc93d4ae1d9e9529b9
Resolves: #13635

typo3/sysext/workspaces/Classes/Service/Workspaces.php

index e4753df..afa1a8a 100644 (file)
@@ -361,31 +361,48 @@ class tx_Workspaces_Service_Workspaces {
                        }
                        $pageList = implode(',', $newList);
                }
+
                unset($searchObj);
                if (intval($GLOBALS['TCA']['pages']['ctrl']['versioningWS']) === 2 && $pageList) {
-                       if ($pageList) {
-                                       // Remove the "subbranch" if a page was moved away
-                               $movedAwayPages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid, pid, t3ver_move_id', 'pages', 't3ver_move_id IN (' . $pageList . ') AND t3ver_wsid=' . $wsid . t3lib_BEfunc::deleteClause($table), '', 'uid', '', 't3ver_move_id');
-                               $pageIds = t3lib_div::intExplode(',', $pageList, TRUE);
-
-                                       // move all pages away
-                               $newList = array_diff($pageIds, array_keys($movedAwayPages));
-
-                                       // move back in if still connected to the "remaining" pages
-                               do {
-                                       $changed = FALSE;
-                                       foreach ($movedAwayPages as $uid => $rec) {
-                                               if (in_array($rec['pid'], $newList) && !in_array($uid, $newList)) {
-                                                       $newList[] = $uid;
-                                                       $changed = TRUE;
-                                               }
+                               // Remove the "subbranch" if a page was moved away
+                       $movedAwayPages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+                               'uid, pid, t3ver_move_id',
+                               'pages',
+                               't3ver_move_id IN (' . $pageList . ') AND t3ver_wsid=' . intval($wsid) . t3lib_BEfunc::deleteClause('pages'),
+                               '',
+                               'uid',
+                               '',
+                               't3ver_move_id'
+                       );
+                       $pageIds = t3lib_div::intExplode(',', $pageList, TRUE);
+
+                               // move all pages away
+                       $newList = array_diff($pageIds, array_keys($movedAwayPages));
+
+                               // keep current page in the list
+                       $newList[] = $pageId;
+                               // move back in if still connected to the "remaining" pages
+                       do {
+                               $changed = FALSE;
+                               foreach ($movedAwayPages as $uid => $rec) {
+                                       if (in_array($rec['pid'], $newList) && !in_array($uid, $newList)) {
+                                               $newList[] = $uid;
+                                               $changed = TRUE;
                                        }
-                               } while ($changed);
+                               }
+                       } while ($changed);
+                       $pageList = implode(',', $newList);
 
-                               $pageList = implode(',', $newList);
-                       }
                                // In case moving pages is enabled we need to replace all move-to pointer with their origin
-                       $pages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid, t3ver_move_id', 'pages', 'uid IN (' . $pageList . ')' . t3lib_BEfunc::deleteClause($table), '', 'uid', '', 'uid');
+                       $pages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
+                               'uid, t3ver_move_id',
+                               'pages',
+                               'uid IN (' . $pageList . ')' . t3lib_BEfunc::deleteClause('pages'),
+                               '',
+                               'uid',
+                               '',
+                               'uid'
+                       );
 
                        $newList = array();
                        $pageIds = t3lib_div::intExplode(',', $pageList, TRUE);