Skip to content

Commit

Permalink
[TASK] Use TSFE API methods for checking workspace preview
Browse files Browse the repository at this point in the history
Instead of using the public "workspacePreview" parameter in TSFE,
which is only set when a sys_preview keyword is used, the parameter
from the BE User can be used instead directly (which is used anyways
when using the API methods TSFE->whichWorkspace()).

The TSFE method doWorkspacePreview() is adapted accordingly to be in line
with the rest of the code.

Resolves: #84038
Releases: master
Change-Id: Ic819e099abf36bda867bb2235d6aa23fbbfe19a4
Reviewed-on: https://review.typo3.org/55895
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Reviewed-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
  • Loading branch information
bmack authored and wouter90 committed Feb 25, 2018
1 parent fd8621d commit 5e9728a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ class TypoScriptFrontendController implements LoggerAwareInterface

/**
* Integer, that indicates which workspace is being previewed.
* Not in use anymore, as this is part of the workspace preview functionality, use $TSFE->whichWorkspace() instead.
* @var int
*/
public $workspacePreview = 0;
Expand Down Expand Up @@ -3167,7 +3168,7 @@ public function clearPageCacheContent_pidList($pidList)
public function setSysLastChanged()
{
// We only update the info if browsing the live workspace
if ($this->whichWorkspace() === 0 && $this->page['SYS_LASTCHANGED'] < (int)$this->register['SYS_LASTCHANGED']) {
if (!$this->doWorkspacePreview() && $this->page['SYS_LASTCHANGED'] < (int)$this->register['SYS_LASTCHANGED']) {
$connection = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable('pages');
$connection->update(
Expand Down Expand Up @@ -3945,23 +3946,17 @@ public function logDeprecatedTyposcript($typoScriptProperty, $explanation = '')
*/
public function doWorkspacePreview()
{
return $this->workspacePreview !== 0;
return $this->whichWorkspace() > 0;
}

/**
* Returns the uid of the current workspace
*
* @return int|null returns workspace integer for which workspace is being preview. NULL if none.
* @return int returns workspace integer for which workspace is being preview. 0 if none (= live workspace).
*/
public function whichWorkspace()
{
$ws = null;
if ($this->doWorkspacePreview()) {
$ws = (int)$this->workspacePreview;
} elseif ($this->beUserLogin) {
$ws = $this->getBackendUser()->workspace;
}
return $ws;
return $this->beUserLogin ? $this->getBackendUser()->workspace : 0;
}

/********************************************
Expand Down
16 changes: 1 addition & 15 deletions typo3/sysext/workspaces/Classes/Hook/PreviewHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public function initializePreviewUser(&$params, &$pObj)
$BE_USER->groupList = $tempBackendUser->groupList;
$BE_USER->userGroups = $tempBackendUser->userGroups;
$BE_USER->userGroupsUID = $tempBackendUser->userGroupsUID;
$BE_USER->workspace = (int)$workspaceUid;
$pObj->beUserLogin = true;
} else {
$BE_USER = null;
Expand All @@ -124,27 +125,12 @@ public function initializePreviewUser(&$params, &$pObj)
unset($tempBackendUser);
$params['BE_USER'] = $BE_USER;
}
if ($pObj->isBackendUserLoggedIn()
&& is_object($params['BE_USER'])
&& $workspaceUid > 0
) {
// Check Access to workspace
if ($params['BE_USER']->checkWorkspace($workspaceRecord ?: $workspaceUid)
&& $params['BE_USER']->isInWebMount($pObj->id)
) {
$pObj->workspacePreview = (int)$workspaceUid;
} else {
// No preview, will fallback to "Live" at the moment
$pObj->workspacePreview = 0;
}
}

// Now, if "ADMCMD_noBeUser" is set, then ensure that there is no workspace preview and no BE User logged in.
// This option is solely used to ensure that a be user can preview the live version of a page in the
// workspace preview module.
if (GeneralUtility::_GET('ADMCMD_noBeUser')) {
$params['BE_USER'] = null;
$pObj->workspacePreview = 0;
$pObj->beUserLogin = false;
// Caching is disabled, because otherwise generated URLs could include the ADMCMD_noBeUser parameter
$pObj->set_no_cache('GET Parameter ADMCMD_noBeUser was given', true);
Expand Down

0 comments on commit 5e9728a

Please sign in to comment.