Skip to content

Commit

Permalink
[TASK] Remove last occurrences of default draft workspace
Browse files Browse the repository at this point in the history
The default draft workspace was deprecated with TYPO3 4.4,
and removed with TYPO3 4.6, but some parts were still left in TYPO3 Core,
and can simply removed now.

Default draft workspace was always marked as "-1", where as "0" was the
live workspace, and everything greater zero is a regular workspace we use
throughout the TYPO3 Core.

See https://typo3.org/news/article/bringing-workspaces-up-to-speed/
for more information about the deprecation.

Resolves: #84026
Releases: master
Change-Id: Ic85425425c4a091bc058091cd483351d84b4d912
Reviewed-on: https://review.typo3.org/55880
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: Jigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
  • Loading branch information
bmack authored and Jigal van Hemert committed Feb 24, 2018
1 parent efeb346 commit 7768d5e
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use TYPO3\CMS\Core\Type\Bitmask\JsConfirmation;
use TYPO3\CMS\Core\Type\Bitmask\Permission;
use TYPO3\CMS\Core\Type\Exception\InvalidEnumerationValueException;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
Expand Down Expand Up @@ -83,7 +84,6 @@ class BackendUserAuthentication extends AbstractUserAuthentication
/**
* User workspace.
* -99 is ERROR (none available)
* -1 is offline
* 0 is online
* >0 is custom workspaces
* @var int
Expand Down Expand Up @@ -2242,37 +2242,33 @@ public function setWorkspacePreview($previewState)

/**
* Return default workspace ID for user,
* If EXT:workspaces is not installed the user will be pushed the the
* Live workspace
* if EXT:workspaces is not installed the user will be pushed to the
* Live workspace, if he has access to. If no workspace is available for the user, the workspace ID is set to "-99"
*
* @return int Default workspace id. If no workspace is available it will be "-99
* @return int Default workspace id.
*/
public function getDefaultWorkspace()
{
if (!ExtensionManagementUtility::isLoaded('workspaces')) {
return 0;
}
// Online is default
if ($this->checkWorkspace(0)) {
return 0;
}
// Otherwise -99 is the fallback
$defaultWorkspace = -99;
if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('workspaces') || $this->checkWorkspace(0)) {
// Check online
$defaultWorkspace = 0;
} elseif ($this->checkWorkspace(-1)) {
// Check offline
$defaultWorkspace = -1;
} elseif (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('workspaces')) {
// Traverse custom workspaces:
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_workspace');
$queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(RootLevelRestriction::class));
$workspaces = $queryBuilder->select('uid', 'title', 'adminusers', 'members', 'reviewers')
->from('sys_workspace')
->orderBy('title')
->execute()
->fetchAll(\PDO::FETCH_ASSOC);

if ($workspaces !== false) {
foreach ($workspaces as $rec) {
if ($this->checkWorkspace($rec)) {
$defaultWorkspace = $rec['uid'];
break;
}
}
// Traverse all workspaces
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_workspace');
$queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(RootLevelRestriction::class));
$result = $queryBuilder->select('*')
->from('sys_workspace')
->orderBy('title')
->execute();
while ($workspaceRecord = $result->fetch()) {
if ($this->checkWorkspace($workspaceRecord)) {
$defaultWorkspace = (int)$workspaceRecord['uid'];
break;
}
}
return $defaultWorkspace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ You can name bookmarks, you can even group them and share them. If you want to e
<trans-unit id="workspaceSelector.details" xml:space="preserve">
<source>There are two basic workspace types in TYPO3: The "Live" workspace and a number of "Draft" workspaces.
When working in the Live workspace all changes you make will take immediate effect. This is the default and traditional state of operation in TYPO3.
When working in the default Draft workspace or any customly created workspaces changes are not applied to the live website but rather made through new versions of any element editable. Since versioning doesn't apply to all elements in TYPO3 there are limitations to what can be done in draft workspaces; Only elements with versioning support can be edited and everything else is read-only. Draft workspaces allow preview in the frontend. When changes are final in a draft workspace they can be published into the live workspace.</source>
When working in a customly created workspaces changes are not applied to the live website but rather made through new versions of any element editable. Since versioning doesn't apply to all elements in TYPO3 there are limitations to what can be done in draft workspaces; Only elements with versioning support can be edited and everything else is read-only. Draft workspaces allow preview in the frontend. When changes are final in a draft workspace they can be published into the live workspace.</source>
</trans-unit>
</body>
</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1116,12 +1116,8 @@ public function determineId()
(
$backendUser->user['workspace_preview']
|| GeneralUtility::_GP('ADMCMD_view')
|| $this->doWorkspacePreview()
)
&& (
$this->whichWorkspace() === -1
|| $this->whichWorkspace() > 0
)
&& $this->whichWorkspace() > 0
&& !GeneralUtility::_GP('ADMCMD_noBeUser')
) {
// Will show special preview message.
Expand Down Expand Up @@ -1202,8 +1198,7 @@ protected function determineIdIsHiddenPage()
->execute()
->fetch();

$workspace = $this->whichWorkspace();
if ($workspace !== 0 && $workspace !== false) {
if ($this->whichWorkspace() > 0) {
// Fetch overlay of page if in workspace and check if it is hidden
$pageSelectObject = GeneralUtility::makeInstance(PageRepository::class);
$pageSelectObject->versioningPreview = true;
Expand Down Expand Up @@ -3180,8 +3175,8 @@ public function clearPageCacheContent_pidList($pidList)
*/
public function setSysLastChanged()
{
// Draft workspaces are always uid 1 or more. We do not update SYS_LASTCHANGED if we are browsing page from one of theses workspaces
if ((int)$this->whichWorkspace() < 1 && $this->page['SYS_LASTCHANGED'] < (int)$this->register['SYS_LASTCHANGED']) {
// We only update the info if browsing the live workspace
if ($this->whichWorkspace() === 0 && $this->page['SYS_LASTCHANGED'] < (int)$this->register['SYS_LASTCHANGED']) {
$connection = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionForTable('pages');
$connection->update(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@
<trans-unit id="shortcut_onlineWS">
<source>LIVE workspace</source>
</trans-unit>
<trans-unit id="shortcut_offlineWS">
<source>Draft workspace</source>
</trans-unit>
<trans-unit id="shortcut_active">
<source>active</source>
</trans-unit>
Expand Down Expand Up @@ -159,9 +156,6 @@
<trans-unit id="bookmark_onlineWS">
<source>LIVE workspace</source>
</trans-unit>
<trans-unit id="bookmark_offlineWS">
<source>Draft workspace</source>
</trans-unit>
<trans-unit id="bookmark_active">
<source>active</source>
</trans-unit>
Expand Down
17 changes: 7 additions & 10 deletions typo3/sysext/workspaces/Classes/Hook/PreviewHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use TYPO3\CMS\Core\Database\Query\Restriction\RootLevelRestriction;
use TYPO3\CMS\Core\Type\Bitmask\Permission;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;

/**
* Hook for checking if the preview mode is activated
Expand Down Expand Up @@ -64,7 +63,7 @@ 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'];
$workspaceUid = (int)$this->previewConfiguration['fullWorkspace'];
$workspaceRecord = null;
if ($this->previewConfiguration['BEUSER_uid'] > 0) {
// First initialize a temp user object and resolve usergroup information
Expand Down Expand Up @@ -127,18 +126,16 @@ public function initializePreviewUser(&$params, &$pObj)
}
if ($pObj->isBackendUserLoggedIn()
&& is_object($params['BE_USER'])
&& MathUtility::canBeInterpretedAsInteger($workspaceUid)
&& $workspaceUid > 0
) {
if ($workspaceUid == 0
|| $workspaceUid >= -1
&& $params['BE_USER']->checkWorkspace($workspaceRecord ?: $workspaceUid)
// Check Access to workspace
if ($params['BE_USER']->checkWorkspace($workspaceRecord ?: $workspaceUid)
&& $params['BE_USER']->isInWebMount($pObj->id)
) {
// Check Access to workspace. Live (0) is OK to preview for all.
$pObj->workspacePreview = (int)$workspaceUid;
} else {
// No preview, will default to "Live" at the moment
$pObj->workspacePreview = -99;
// No preview, will fallback to "Live" at the moment
$pObj->workspacePreview = 0;
}
}
}
Expand Down Expand Up @@ -305,7 +302,7 @@ protected function getPreviewInputCode()
*
* @param string $backendUserUid 32 byte MD5 hash keyword for the URL: "?ADMCMD_prev=[keyword]
* @param int $ttl Time-To-Live for keyword
* @param int|null $fullWorkspace Which workspace to preview. Workspace UID, -1 or >0. If set, the getVars is ignored in the frontend, so that string can be empty
* @param int|null $fullWorkspace Which workspace ID to preview.
* @return string Returns keyword to use in URL for ADMCMD_prev=
*/
public function compilePreviewKeyword($backendUserUid, $ttl = 172800, $fullWorkspace = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ public function renderPreviewInfo(array $params, \TYPO3\CMS\Frontend\Controller\
$content .= sprintf(
$pObj->config['config']['message_preview_workspace'],
$currentWorkspaceTitle,
$currentWorkspaceId ?? -1
$currentWorkspaceId ?? -99
);
} else {
$text = LocalizationUtility::translate(
'LLL:EXT:workspaces/Resources/Private/Language/locallang_mod.xlf:previewText',
'workspaces',
[$currentWorkspaceTitle, $currentWorkspaceId ?? -1]
[$currentWorkspaceTitle, $currentWorkspaceId ?? -99]
);
if ($pObj->doWorkspacePreview()) {
$urlForStoppingPreview = GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . 'index.php?ADMCMD_prev=LOGOUT&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'));
Expand Down
4 changes: 2 additions & 2 deletions typo3/sysext/workspaces/Classes/Service/WorkspaceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function getCmdArrayForPublishWS($wsid, $doSwap, $pageId = 0, $language =
{
$wsid = (int)$wsid;
$cmd = [];
if ($wsid >= -1 && $wsid !== 0) {
if ($wsid > 0) {
// Define stage to select:
$stage = -99;
if ($wsid > 0) {
Expand Down Expand Up @@ -180,7 +180,7 @@ public function getCmdArrayForFlushWS($wsid, $flush = true, $pageId = 0, $langua
{
$wsid = (int)$wsid;
$cmd = [];
if ($wsid >= -1 && $wsid !== 0) {
if ($wsid > 0) {
// Define stage to select:
$stage = -99;
// Select all versions to swap:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,6 @@
<trans-unit id="label_onlymychanges">
<source>Show only my changes</source>
</trans-unit>
<trans-unit id="label_offlineWSes">
<source>Draft workspaces</source>
</trans-unit>
<trans-unit id="label_allWSes">
<source>All workspaces</source>
</trans-unit>
Expand Down

0 comments on commit 7768d5e

Please sign in to comment.