[TASK] Consolidate hooks in workspace preview 66/55866/2
authorBenni Mack <benni@typo3.org>
Thu, 22 Feb 2018 20:00:27 +0000 (21:00 +0100)
committerFrank Naegler <frank.naegler@typo3.org>
Fri, 23 Feb 2018 11:22:38 +0000 (12:22 +0100)
The Workspace preview hooks first hook into TSFE->connectToDB
to see if ADMCMD_prev is set via GP/cookie. If so, the TSFE object gets
re-instantiated, which is utterly unnecessary.

Additionally, it unsets the BE user cookie, solely to use a SECOND hook
(initializePreviewUser()) to check if the BE_USER is null.

Instead, the hooks are consolidated and the one hook after a regular BE user
exists, gets used, and overridden by a custom BE user object as defined
in the preview configuration with the workspace preview.

Resolves: #84014
Releases: master
Change-Id: Id3caf9cd99ff13c906062ff95523f6066d90d322
Reviewed-on: https://review.typo3.org/55866
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
typo3/sysext/workspaces/Classes/Hook/PreviewHook.php
typo3/sysext/workspaces/ext_localconf.php

index c38091a..da81a03 100644 (file)
@@ -51,39 +51,22 @@ class PreviewHook implements \TYPO3\CMS\Core\SingletonInterface
     protected $forceReadPermissions = false;
 
     /**
-     * hook to check if the preview is activated
-     * right now, this hook is called at the end of "$TSFE->connectToDB"
-     *
-     * @param array $params (not needed right now)
-     * @param \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $pObj
-     */
-    public function checkForPreview($params, &$pObj)
-    {
-        $this->previewConfiguration = $this->getPreviewConfiguration();
-        if (is_array($this->previewConfiguration)) {
-            // Configuration after initialization of TSFE object.
-            // Basically this unsets the BE cookie if any and forces
-            // the BE user set according to the preview configuration.
-            // @previouslyknownas TSFE->ADMCMD_preview_postInit
-            // Clear cookies:
-            unset($_COOKIE['be_typo_user']);
-        }
-    }
-
-    /**
-     * hook after the regular BE user has been initialized
-     * if there is no BE user login, but a preview configuration
-     * the BE user of the preview configuration gets initialized
+     * Hook after the regular BE user has been initialized
+     * if there is a preview configuration
+     * the BE user of the preview configuration gets initialized and
+     * is used instead for the current request, overriding any existing
+     * authenticated backend user.
      *
      * @param array $params holding the BE_USER object
      * @param \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $pObj
      */
     public function initializePreviewUser(&$params, &$pObj)
     {
+        $this->previewConfiguration = $this->getPreviewConfiguration();
         // if there is a valid BE user, and the full workspace should be previewed, the workspacePreview option should be set
         $workspaceUid = $this->previewConfiguration['fullWorkspace'];
         $workspaceRecord = null;
-        if ((is_null($params['BE_USER']) || $params['BE_USER'] === false) && $this->previewConfiguration !== false && $this->previewConfiguration['BEUSER_uid'] > 0) {
+        if ($this->previewConfiguration['BEUSER_uid'] > 0) {
             // First initialize a temp user object and resolve usergroup information
             /** @var FrontendBackendUserAuthentication $tempBackendUser */
             $tempBackendUser = $this->createFrontendBackendUser();
index 95a0a89..30d668f 100644 (file)
@@ -30,7 +30,6 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['hook_prev
 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/alt_doc.php']['makeEditForm_accessCheck']['workspaces'] = \TYPO3\CMS\Workspaces\Hook\BackendUtilityHook::class . '->makeEditForm_accessCheck';
 
 // Register hook to check for the preview mode in the FE
-$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['connectToDB']['version_preview'] = \TYPO3\CMS\Workspaces\Hook\PreviewHook::class . '->checkForPreview';
 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/index_ts.php']['postBeUser']['version_preview'] = \TYPO3\CMS\Workspaces\Hook\PreviewHook::class . '->initializePreviewUser';
 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauthgroup.php']['getPagePermsClause']['version_preview'] = \TYPO3\CMS\Workspaces\Hook\PreviewHook::class . '->overridePagePermissionClause';
 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauthgroup.php']['calcPerms']['version_preview'] = \TYPO3\CMS\Workspaces\Hook\PreviewHook::class . '->overridePermissionCalculation';