[FEATURE] Include preview link in notification
authorSonja Scholz <ss@cabag.ch>
Fri, 4 Mar 2011 13:55:35 +0000 (14:55 +0100)
committerMichael Klapper <michael.klapper+github@gmail.com>
Thu, 7 Jul 2011 07:51:20 +0000 (09:51 +0200)
Until now there haven't been a preview link in the notification mails.

With this feature there are two new markers that can be used in the
notification template. One marker for the workspace preview link and
one marker for the splitted workspace preview link.
Additionally this feature adds a hook, so it is possible for a
developer to add severall additional markers.

The preview link for the splitted workspace view goes across the
backend login screen. If an user has no valid backend session he
can simply login and after an successfull login he will be redirected
to the desired worskpace view. If the user already logged in to the
backend he becomes directly the workspace module without any new
login.

If the recipient of the review email was last time logged in into the
live WS. The workspace will now forced (if the permission allows) to
the desired WS where the changes are present. Otherwise it's not possible
to get the splitted preview screen running.

Change-Id: Ifec84d7475aa111cc55a0fb2915d3ddfa6c5fcc4
Resolves: #13518

typo3/sysext/workspaces/Classes/Controller/PreviewController.php
typo3/sysext/workspaces/Classes/ExtDirect/AbstractHandler.php
typo3/sysext/workspaces/Classes/ExtDirect/ActionHandler.php
typo3/sysext/workspaces/Classes/Service/Befunc.php
typo3/sysext/workspaces/Classes/Service/Workspaces.php

index 669b8f0..f1113f8 100644 (file)
@@ -75,13 +75,28 @@ class Tx_Workspaces_Controller_PreviewController extends Tx_Workspaces_Controlle
         * The preview itself consists of three frames, so there are
         * only the frames-urls we've to generate here
         *
+        * @param integer $previewWS
+        *
         * @return void
         */
-       public function indexAction() {
+       public function indexAction($previewWS = null) {
                // @todo language doesn't always come throught the L parameter
                // @todo Evaluate how the intval() call can be used with Extbase validators/filters
                $language = intval(t3lib_div::_GP('L'));
 
+               /** @var $wsService tx_Workspaces_Service_Workspaces */
+               $wsService = t3lib_div::makeInstance('tx_Workspaces_Service_Workspaces');
+               $wsList = $wsService->getAvailableWorkspaces();
+               $activeWorkspace = $GLOBALS['BE_USER']->workspace;
+
+               if (!is_null($previewWS)) {
+                       if (in_array($previewWS, array_keys($wsList)) && $activeWorkspace != $previewWS) {
+                               $activeWorkspace = $previewWS;
+                               $GLOBALS['BE_USER']->setWorkspace($activeWorkspace);
+                               t3lib_BEfunc::setUpdateSignal('updatePageTree');
+                       }
+               }
+
                $controller = t3lib_div::makeInstance('Tx_Workspaces_Controller_ReviewController', TRUE);
                /** @var $uriBuilder Tx_Extbase_MVC_Web_Routing_UriBuilder */
                $uriBuilder = $this->objectManager->create('Tx_Extbase_MVC_Web_Routing_UriBuilder');
index 761e8c3..f6e1de6 100644 (file)
@@ -37,12 +37,7 @@ abstract class tx_Workspaces_ExtDirect_AbstractHandler {
         * @return integer The current workspace ID
         */
        protected function getCurrentWorkspace() {
-               $workspaceId = $GLOBALS['BE_USER']->workspace;
-               if ($GLOBALS['BE_USER']->isAdmin()) {
-                       $activeId = $GLOBALS['BE_USER']->getSessionData('tx_workspace_activeWorkspace');
-                       $workspaceId = $activeId !== NULL ? $activeId : $workspaceId;
-               }
-               return $workspaceId;
+               return $this->getWorkspaceService()->getCurrentWorkspace();
        }
 
        /**
@@ -66,6 +61,15 @@ abstract class tx_Workspaces_ExtDirect_AbstractHandler {
 
                return $response;
        }
+
+       /**
+        * Gets an instance of the workspaces service.
+        *
+        * @return tx_Workspaces_Service_Workspaces
+        */
+       protected function getWorkspaceService() {
+               return t3lib_div::makeInstance('tx_Workspaces_Service_Workspaces');
+       }
 }
 
 
index b9f73f0..b1e54bd 100644 (file)
@@ -50,17 +50,11 @@ class tx_Workspaces_ExtDirect_ActionHandler extends tx_Workspaces_ExtDirect_Abst
         * @return string the full domain including the protocol http:// or https://, but without the trailing '/'
         */
        public function generateWorkspacePreviewLink($uid) {
-               $ttlHours = intval($GLOBALS['BE_USER']->getTSConfigVal('options.workspaces.previewLinkTTLHours'));
-               $ttlHours = ($ttlHours ? $ttlHours : 24*2) * 3600;
-               $linkParams = array(
-                       'ADMCMD_prev'   => t3lib_BEfunc::compilePreviewKeyword('', $GLOBALS['BE_USER']->user['uid'], $ttlHours, $this->getCurrentWorkspace()),
-                       'id'                    => $uid
-               );
-               return t3lib_BEfunc::getViewDomain($uid) . '/index.php?' . t3lib_div::implodeArrayForUrl('', $linkParams);
+               return $this->getWorkspaceService()->generateWorkspacePreviewLink($uid);
        }
 
        /**
-        * Swaps a sisngle record.
+        * Swaps a single record.
         *
         * @param string $table
         * @param integer $t3ver_oid
index ce0995e..755f8ac 100644 (file)
@@ -32,8 +32,6 @@
  */
 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.
@@ -48,28 +46,7 @@ class tx_Workspaces_Service_Befunc {
         * @return void
         */
        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) {
-                       $ctrl = t3lib_div::makeInstance('Tx_Workspaces_Controller_PreviewController', FALSE);
-                       $objectManager = t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager');
-                       /** @var $uriBuilder Tx_Extbase_MVC_Web_Routing_UriBuilder */
-                       $uriBuilder = $objectManager->create('Tx_Extbase_MVC_Web_Routing_UriBuilder');
-                       /**
-                        *  This seems to be very harsh to set this directly to "/typo3 but the viewOnClick also
-                        *  has /index.php as fixed value here and dealing with the backPath is very error-prone
-                        *
-                        *  @todo make sure this would work in local extension installation too
-                        */
-                       $backPath = '/' . TYPO3_mainDir;
-                               // @todo why do we need these additional params? the URIBuilder should add the controller, but he doesn't :(
-                       $additionalParams = '&tx_workspaces_web_workspacesworkspaces%5Bcontroller%5D=Preview&M=web_WorkspacesWorkspaces&id=';
-                       $viewScript = $backPath . $uriBuilder->uriFor('index', array(), 'Tx_Workspaces_Controller_PreviewController', 'workspaces', 'web_workspacesworkspaces') . $additionalParams;
-               }
+               $viewScript = $this->getWorkspaceService()->generateWorkspaceSplittedPreviewLink($pageUid);
        }
 
        /**
@@ -77,19 +54,22 @@ class tx_Workspaces_Service_Befunc {
         * the results are cached at run-time to avoid too many database-queries
         *
         * @throws InvalidArgumentException
-        * @param  $uid
-        * @return void
+        * @param integer $uid
+        * @return integer
+        * @deprecated since TYPO3 4.6 - use tx_Workspaces_Service_Workspaces::getLivePageUid() instead
         */
        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];
+               t3lib_div::deprecationLog(__METHOD__ . ' is deprected since TYPO3 4.6 - use tx_Workspaces_Service_Workspaces::getLivePageUid() instead');
+               return $this->getWorkspaceService()->getLivePageUid($uid);
+       }
+
+       /**
+        * Gets an instance of the workspaces service.
+        *
+        * @return tx_Workspaces_Service_Workspaces
+        */
+       protected function getWorkspaceService() {
+               return t3lib_div::makeInstance('tx_Workspaces_Service_Workspaces');
        }
 }
 
index 14ea0d8..de901e9 100644 (file)
  * @package Workspaces
  * @subpackage Service
  */
-class tx_Workspaces_Service_Workspaces {
+class tx_Workspaces_Service_Workspaces implements t3lib_Singleton {
+       /**
+        * @var array
+        */
+       protected $pageCache = array();
+
        const TABLE_WORKSPACE = 'sys_workspace';
        const SELECT_ALL_WORKSPACES = -98;
        const LIVE_WORKSPACE_ID = 0;
@@ -62,6 +67,19 @@ class tx_Workspaces_Service_Workspaces {
                return $availableWorkspaces;
        }
 
+       /**
+        * Gets the current workspace ID.
+        *
+        * @return integer The current workspace ID
+        */
+       public function getCurrentWorkspace() {
+               $workspaceId = $GLOBALS['BE_USER']->workspace;
+               if ($GLOBALS['BE_USER']->isAdmin()) {
+                       $activeId = $GLOBALS['BE_USER']->getSessionData('tx_workspace_activeWorkspace');
+                       $workspaceId = $activeId !== NULL ? $activeId : $workspaceId;
+               }
+               return $workspaceId;
+       }
 
        /**
         * Find the title for the requested workspace.
@@ -541,6 +559,79 @@ class tx_Workspaces_Service_Workspaces {
                }
                return $result;
        }
+
+       /**
+        * Generates a workspace preview link.
+        *
+        * @param integer $uid The ID of the record to be linked
+        * @return string the full domain including the protocol http:// or https://, but without the trailing '/'
+        */
+       public function generateWorkspacePreviewLink($uid) {
+               $timeToLiveHours = intval($GLOBALS['BE_USER']->getTSConfigVal('options.workspaces.previewLinkTTLHours'));
+               $timeToLiveHours = ($timeToLiveHours ? $timeToLiveHours : 24*2) * 3600;
+               $linkParams = array(
+                       'ADMCMD_prev'   => t3lib_BEfunc::compilePreviewKeyword('', $GLOBALS['BE_USER']->user['uid'], $timeToLiveHours, $this->getCurrentWorkspace()),
+                       'id'                    => $uid
+               );
+               return t3lib_BEfunc::getViewDomain($uid) . '/index.php?' . t3lib_div::implodeArrayForUrl('', $linkParams);
+       }
+
+       /**
+        * Generates a workspace splitted preview link.
+        *
+        * @param integer $uid The ID of the record to be linked
+        * @param boolean $addDomain Parameter to decide if domain should be added to the generated link, FALSE per default
+        * @return string the preview link without the trailing '/'
+        */
+       public function generateWorkspaceSplittedPreviewLink($uid, $addDomain = FALSE) {
+                       // In case a $pageUid is submitted we need to make sure it points to a live-page
+               if ($uid >  0) {
+                       $uid = $this->getLivePageUid($uid);
+               }
+
+               $objectManager = t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager');
+               /** @var $uriBuilder Tx_Extbase_MVC_Web_Routing_UriBuilder */
+               $uriBuilder = $objectManager->create('Tx_Extbase_MVC_Web_Routing_UriBuilder');
+               /**
+                *  This seems to be very harsh to set this directly to "/typo3 but the viewOnClick also
+                *  has /index.php as fixed value here and dealing with the backPath is very error-prone
+                *
+                *  @todo make sure this would work in local extension installation too
+                */
+               $backPath = '/' . TYPO3_mainDir;
+               $redirect = $backPath . 'index.php?redirect_url=';
+                       // @todo why do we need these additional params? the URIBuilder should add the controller, but he doesn't :(
+               $additionalParams = '&tx_workspaces_web_workspacesworkspaces%5Bcontroller%5D=Preview&M=web_WorkspacesWorkspaces&id=';
+               $viewScript = $backPath . $uriBuilder->setArguments(array('tx_workspaces_web_workspacesworkspaces' => array('previewWS' => $GLOBALS['BE_USER']->workspace)))
+                                                                                               ->uriFor('index', array(), 'Tx_Workspaces_Controller_PreviewController', 'workspaces', 'web_workspacesworkspaces') . $additionalParams;
+
+               if ($addDomain === TRUE) {
+                       return t3lib_BEfunc::getViewDomain($uid) . $redirect . urlencode($viewScript) . $uid;
+               } else {
+                       return $viewScript;
+               }
+       }
+
+       /**
+        * Find the Live-Uid for a given page,
+        * the results are cached at run-time to avoid too many database-queries
+        *
+        * @throws InvalidArgumentException
+        * @param integer $uid
+        * @return integer
+        */
+       public function getLivePageUid($uid) {
+               if (!isset($this->pageCache[$uid])) {
+                       $pageRecord = t3lib_beFunc::getRecord('pages', $uid);
+                       if (is_array($pageRecord)) {
+                               $this->pageCache[$uid] = ($pageRecord['t3ver_oid'] ? $pageRecord['t3ver_oid'] : $uid);
+                       } else {
+                               throw new InvalidArgumentException('uid is supposed to point to an existing page - given value was:' . $uid, 1290628113);
+                       }
+               }
+
+               return $this->pageCache[$uid];
+       }
 }