Fixed bug #10693: Save and view command previews wrong page record
authortolleiv <tolleiv@743128fe-103e-dd11-99c4-001b210b3e58>
Mon, 20 Dec 2010 20:15:17 +0000 (20:15 +0000)
committertolleiv <tolleiv@743128fe-103e-dd11-99c4-001b210b3e58>
Mon, 20 Dec 2010 20:15:17 +0000 (20:15 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/CoreProjects/workspaces/workspaces/trunk@3490 743128fe-103e-dd11-99c4-001b210b3e58

typo3/sysext/workspaces/ChangeLog
typo3/sysext/workspaces/Classes/Service/Befunc.php

index 2c2373d..70a3b90 100644 (file)
@@ -1,5 +1,6 @@
 2010-12-20  Tolleiv Nietsch <typo3@tolleiv.de>
 
+       * Fixed bug #10693: Save and view command previews wrong page record
        * Fixed bug #11532: Generate Workspace Preview Link not working
        * Fixed bug #11605: Do you really want to swap?? - one question mark is enough
        * Fixed bug #11531 Check if email is set before trying to send an email
index d56d247..d0441bc 100644 (file)
@@ -31,6 +31,9 @@
  * @subpackage Service
  */
 class tx_Workspaces_Service_Befunc {
+
+       protected static $pageCache = array();
+
        /**
         * Hooks into the t3lib_beFunc::viewOnClick and redirects to the workspace preview
         * only if we're in a workspace and if the frontend-preview is disabled.
@@ -44,7 +47,13 @@ class tx_Workspaces_Service_Befunc {
         * @param  $switchFocus
         * @return void
         */
-       public function preProcess($pageUid, $backPath, $rootLine, $anchorSection, &$viewScript, $additionalGetVars, $switchFocus) {
+       public function preProcess(&$pageUid, $backPath, $rootLine, $anchorSection, &$viewScript, $additionalGetVars, $switchFocus) {
+
+                       // In case a $pageUid is submitted we need to make sure it points to a live-page
+               if ($pageUid >  0) {
+                       $pageUid = $this->getLivePageUid($pageUid);
+               }
+
                if ($GLOBALS['BE_USER']->workspace !== 0 && !$GLOBALS['BE_USER']->user['workspace_preview']) {
                        $ctrl = t3lib_div::makeInstance('Tx_Workspaces_Controller_PreviewController', FALSE);
                        $uriBuilder = t3lib_div::makeInstance('Tx_Extbase_MVC_Web_Routing_UriBuilder');
@@ -61,6 +70,25 @@ class tx_Workspaces_Service_Befunc {
                }
        }
 
+       /**
+        * Find the Live-Uid for a given page,
+        * the results are cached at run-time to avoid too many database-queries
+        *
+        * @throws InvalidArgumentException
+        * @param  $uid
+        * @return void
+        */
+       protected function getLivePageUid($uid) {
+               if (!isset(self::$pageCache[$uid])) {
+                       $rec = t3lib_beFunc::getRecord('pages', $uid);
+                       if (is_array($rec)) {
+                               self::$pageCache[$uid] = $rec['t3ver_oid'] ? $rec['t3ver_oid'] : $uid;
+                       } else {
+                               throw new InvalidArgumentException('uid is supposed to point to an existing page - given value was:' . $uid, 1290628113);
+                       }
+               }
+               return self::$pageCache[$uid];
+       }
 }
 
 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/Service/Befunc.php'])) {