Commit c40ba4a2 authored by Christian Kuhn's avatar Christian Kuhn
Browse files

[TASK] Type hint BackendUserAuthentication->workspace to int

Public property BackendUserAuthentication->workspace is
always an integer and should be declared as such. This
avoids a series of casts throughout the core.

Change-Id: I6fae41981b0923b61c4f4405762d155a149f983c
Resolves: #98416
Releases: main
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/75845


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Stefan Bürk's avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent c6fed04a
......@@ -575,11 +575,6 @@ parameters:
count: 1
path: ../../typo3/sysext/core/Classes/Domain/Repository/PageRepository.php
-
message: "#^Property TYPO3\\\\CMS\\\\Core\\\\Authentication\\\\BackendUserAuthentication\\:\\:\\$workspace \\(int\\) in isset\\(\\) is not nullable\\.$#"
count: 1
path: ../../typo3/sysext/core/Classes/Error/ErrorHandler.php
-
message: "#^Result of && is always true\\.$#"
count: 1
......
......@@ -539,7 +539,7 @@ class EditDocumentController
}
// If pages are being edited, we set an instruction about updating the page tree after this operation.
if ($tce->pagetreeNeedsRefresh
&& (isset($this->data['pages']) || $beUser->workspace != 0 && !empty($this->data))
&& (isset($this->data['pages']) || $beUser->workspace !== 0 && !empty($this->data))
) {
BackendUtility::setUpdateSignal('updatePageTree');
}
......@@ -2195,7 +2195,7 @@ class EditDocumentController
$reqRecord = BackendUtility::getRecord($table, $theUid, 'uid,pid' . ($tableSupportsVersioning ? ',t3ver_oid' : ''));
if (is_array($reqRecord)) {
// If workspace is OFFLINE:
if ($this->getBackendUser()->workspace != 0) {
if ($this->getBackendUser()->workspace !== 0) {
// Check for versioning support of the table:
if ($tableSupportsVersioning) {
// If the record is already a version of "something" pass it by.
......
......@@ -480,7 +480,7 @@ class TreeController
return GeneralUtility::makeInstance(
PageTreeRepository::class,
(int)$backendUser->workspace,
$backendUser->workspace,
[],
$additionalQueryRestrictions
);
......
......@@ -185,7 +185,7 @@ class PageLayoutController
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
$queryBuilder->getRestrictions()->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, (int)$this->getBackendUser()->workspace));
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->getBackendUser()->workspace));
$statement = $queryBuilder->select('uid', $GLOBALS['TCA']['pages']['ctrl']['languageField'])
->from('pages')
->where(
......@@ -657,7 +657,7 @@ class PageLayoutController
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, (int)$this->getBackendUser()->workspace));
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->getBackendUser()->workspace));
$queryBuilder
->count('uid')
->from('tt_content')
......
......@@ -253,7 +253,7 @@ class LocalizationRepository
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, (int)$this->getBackendUser()->workspace));
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->getBackendUser()->workspace));
return $queryBuilder;
}
......
......@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Backend\Form\Wizard;
use TYPO3\CMS\Backend\Tree\View\PageTreeView;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Database\Query\QueryHelper;
......@@ -119,10 +120,11 @@ class SuggestWizardDefaultReceiver
if (isset($config['maxItemsInResultList'])) {
$this->maxItems = $config['maxItemsInResultList'];
}
$GLOBALS['BE_USER']->initializeWebmountsForElementBrowser();
$backendUser = $this->getBackendUser();
$backendUser->initializeWebmountsForElementBrowser();
if ($this->table === 'pages') {
$this->queryBuilder->andWhere(
QueryHelper::stripLogicalOperatorPrefix($GLOBALS['BE_USER']->getPagePermsClause(Permission::PAGE_SHOW)),
QueryHelper::stripLogicalOperatorPrefix($backendUser->getPagePermsClause(Permission::PAGE_SHOW)),
$this->queryBuilder->expr()->eq('sys_language_uid', 0)
);
}
......@@ -339,16 +341,17 @@ class SuggestWizardDefaultReceiver
*/
protected function checkRecordAccess($row, $uid)
{
$backendUser = $this->getBackendUser();
$retValue = true;
$table = $this->mmForeignTable ?: $this->table;
if ($table === 'pages') {
if (!BackendUtility::readPageAccess($uid, $GLOBALS['BE_USER']->getPagePermsClause(Permission::PAGE_SHOW))) {
if (!BackendUtility::readPageAccess($uid, $backendUser->getPagePermsClause(Permission::PAGE_SHOW))) {
$retValue = false;
}
} elseif (isset($GLOBALS['TCA'][$table]['ctrl']['is_static']) && (bool)$GLOBALS['TCA'][$table]['ctrl']['is_static']) {
$retValue = true;
} else {
if (!is_array(BackendUtility::readPageAccess($row['pid'], $GLOBALS['BE_USER']->getPagePermsClause(Permission::PAGE_SHOW)))) {
if (!is_array(BackendUtility::readPageAccess($row['pid'], $backendUser->getPagePermsClause(Permission::PAGE_SHOW)))) {
$retValue = false;
}
}
......@@ -363,7 +366,7 @@ class SuggestWizardDefaultReceiver
protected function makeWorkspaceOverlay(&$row)
{
// Check for workspace-versions
if ($GLOBALS['BE_USER']->workspace != 0 && BackendUtility::isTableWorkspaceEnabled($this->table)) {
if ($this->getBackendUser()->workspace !== 0 && BackendUtility::isTableWorkspaceEnabled($this->table)) {
BackendUtility::workspaceOL($this->mmForeignTable ?: $this->table, $row);
}
}
......@@ -432,6 +435,11 @@ class SuggestWizardDefaultReceiver
return $GLOBALS['LANG'];
}
public function getBackendUser(): BackendUserAuthentication
{
return $GLOBALS['BE_USER'];
}
/**
* @param string $table
* @return QueryBuilder
......
......@@ -481,7 +481,7 @@ abstract class AbstractTreeView
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, (int)$this->getBackendUser()->workspace));
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->getBackendUser()->workspace));
$count = $queryBuilder
->count('uid')
->from($this->table)
......@@ -524,7 +524,7 @@ abstract class AbstractTreeView
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, (int)$this->getBackendUser()->workspace));
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->getBackendUser()->workspace));
$queryBuilder
->select(...$this->fieldArray)
->from($this->table)
......
......@@ -299,7 +299,7 @@ class BackendUtility
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, static::getBackendUserAuthentication()->workspace ?? 0));
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, static::getBackendUserAuthentication()->workspace));
$queryBuilder->select('*')
->from($table)
......@@ -2990,7 +2990,7 @@ class BackendUtility
// Initialize workspace ID
$wsid = (int)$wsid;
if ($wsid === -99 && static::getBackendUserAuthentication() instanceof BackendUserAuthentication) {
$wsid = (int)static::getBackendUserAuthentication()->workspace;
$wsid = static::getBackendUserAuthentication()->workspace;
}
if ($wsid === 0) {
// Return early if in live workspace
......
......@@ -22,6 +22,7 @@ use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\Event\IsContentUsedOnPageLayoutEvent;
use TYPO3\CMS\Backend\View\Event\ModifyDatabaseQueryForContentEvent;
use TYPO3\CMS\Backend\View\PageLayoutContext;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Frontend\VariableFrontend;
use TYPO3\CMS\Core\Database\ConnectionPool;
......@@ -215,7 +216,7 @@ class ContentFetcher
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, (int)$GLOBALS['BE_USER']->workspace));
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->getBackendUser()->workspace));
$queryBuilder
->select('*')
->from('tt_content');
......@@ -258,4 +259,9 @@ class ContentFetcher
{
return GeneralUtility::makeInstance(CacheManager::class)->getCache('runtime');
}
public function getBackendUser(): BackendUserAuthentication
{
return $GLOBALS['BE_USER'];
}
}
......@@ -317,7 +317,7 @@ class PageLayoutContext
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
$queryBuilder->getRestrictions()->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, (int)$this->getBackendUser()->workspace));
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->getBackendUser()->workspace));
$queryBuilder->select('uid', $GLOBALS['TCA']['pages']['ctrl']['languageField'])
->from('pages')
->where(
......
......@@ -102,9 +102,8 @@ class BackendUserAuthentication extends AbstractUserAuthentication
* -99 is ERROR (none available)
* 0 is online
* >0 is custom workspaces
* @var int
*/
public $workspace = -99;
public int $workspace = -99;
/**
* Custom workspace record if any
......@@ -678,7 +677,7 @@ class BackendUserAuthentication extends AbstractUserAuthentication
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, (int)$this->workspace));
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->workspace));
$recordLocalizations = $queryBuilder->select('*')
->from($table)
->where(
......
......@@ -48,7 +48,7 @@ class WorkspaceRestriction implements QueryRestrictionInterface
*/
public function __construct(int $workspaceId = 0)
{
$this->workspaceId = (int)$workspaceId;
$this->workspaceId = $workspaceId;
}
/**
......
......@@ -241,9 +241,7 @@ class ErrorHandler implements ErrorHandlerInterface, LoggerAwareInterface
if (isset($backendUser->user['uid'])) {
$userId = $backendUser->user['uid'];
}
if (isset($backendUser->workspace)) {
$workspace = $backendUser->workspace;
}
$workspace = $backendUser->workspace;
if ($backUserId = $backendUser->getOriginalUserIdWhenInSwitchUserMode()) {
$data['originalUser'] = $backUserId;
}
......
......@@ -465,7 +465,7 @@ class RecordListController
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
$queryBuilder->getRestrictions()->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, (int)$this->getBackendUserAuthentication()->workspace));
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->getBackendUserAuthentication()->workspace));
$statement = $queryBuilder->select('uid', $languageField)
->from('pages')
->where(
......
......@@ -148,7 +148,7 @@ class PageLinkHandler extends AbstractLinkHandler implements LinkHandlerInterfac
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, (int)$this->getBackendUser()->workspace));
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->getBackendUser()->workspace));
$contentElements = $queryBuilder
->select('*')
......
......@@ -2346,7 +2346,7 @@ class DatabaseRecordList
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, (int)$this->getBackendUserAuthentication()->workspace));
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->getBackendUserAuthentication()->workspace));
$queryBuilder
->select(...$fields)
->from($table);
......@@ -3025,7 +3025,7 @@ class DatabaseRecordList
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, (int)$this->getBackendUserAuthentication()->workspace));
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->getBackendUserAuthentication()->workspace));
$result = $queryBuilder
->select('*')
->from('pages')
......
......@@ -21,6 +21,7 @@ use Doctrine\DBAL\Connection;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\DateTimeAspect;
use TYPO3\CMS\Core\Database\ConnectionPool;
......@@ -326,14 +327,14 @@ class SlugService implements LoggerAwareInterface
protected function getRecordHistoryStore(): RecordHistoryStore
{
$backendUser = $GLOBALS['BE_USER'];
$backendUser = $this->getBackendUser();
return GeneralUtility::makeInstance(
RecordHistoryStore::class,
RecordHistoryStore::USER_BACKEND,
$backendUser->user['uid'],
(int)$backendUser->getOriginalUserIdWhenInSwitchUserMode(),
$this->context->getPropertyFromAspect('date', 'timestamp'),
$backendUser->workspace ?? 0
$backendUser->workspace
);
}
......@@ -360,4 +361,9 @@ class SlugService implements LoggerAwareInterface
{
unset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass']['redirects']);
}
protected function getBackendUser(): BackendUserAuthentication
{
return $GLOBALS['BE_USER'];
}
}
......@@ -34,7 +34,7 @@ class WorkspaceSelectorToolbarItem implements ToolbarItemInterface, RequestAware
protected array $availableWorkspaces;
public function __construct(
WorkspaceService $workspaceService,
private readonly WorkspaceService $workspaceService,
private readonly UriBuilder $uriBuilder,
private readonly BackendViewFactory $backendViewFactory,
) {
......@@ -64,7 +64,7 @@ class WorkspaceSelectorToolbarItem implements ToolbarItemInterface, RequestAware
}
$currentWorkspace = $this->getBackendUser()->workspace;
$view = $this->backendViewFactory->create($this->request, ['typo3/cms-workspaces']);
$view->assign('workspaceTitle', $currentWorkspace !== -99 ? WorkspaceService::getWorkspaceTitle($currentWorkspace) : '');
$view->assign('workspaceTitle', $currentWorkspace !== -99 ? $this->workspaceService->getWorkspaceTitle($currentWorkspace) : '');
return $view->render('ToolbarItems/ToolbarItem');
}
......@@ -77,7 +77,7 @@ class WorkspaceSelectorToolbarItem implements ToolbarItemInterface, RequestAware
$additionalItems = [];
$backendUser = $this->getBackendUser();
$view = $this->backendViewFactory->create($this->request, ['typo3/cms-workspaces']);
$activeWorkspace = (int)$backendUser->workspace;
$activeWorkspace = $backendUser->workspace;
foreach ($this->availableWorkspaces as $workspaceId => $label) {
$workspaceId = (int)$workspaceId;
$item = [
......
......@@ -24,7 +24,6 @@ use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Http\JsonResponse;
use TYPO3\CMS\Core\Type\Bitmask\Permission;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Workspaces\Service\WorkspaceService;
/**
......@@ -33,6 +32,12 @@ use TYPO3\CMS\Workspaces\Service\WorkspaceService;
*/
class AjaxController
{
public function __construct(
private readonly WorkspaceService $workspaceService,
private readonly ModuleProvider $moduleProvider,
) {
}
/**
* Sets the TYPO3 Backend context to a certain workspace,
* called by the Backend toolbar menu
......@@ -74,7 +79,7 @@ class AjaxController
}
$ajaxResponse = [
'title' => WorkspaceService::getWorkspaceTitle($workspaceId),
'title' => $this->workspaceService->getWorkspaceTitle($workspaceId),
'workspaceId' => $workspaceId,
'pageId' => ($finalPageUid && $originalPageId == $finalPageUid) ? null : $finalPageUid,
'pageModule' => $this->getPageModuleName(),
......@@ -91,11 +96,9 @@ class AjaxController
protected function getPageModuleName(): string
{
$backendUser = $this->getBackendUser();
$moduleProvider = GeneralUtility::makeInstance(ModuleProvider::class);
$pageModule = trim($backendUser->getTSConfig()['options.']['overridePageModule'] ?? '');
$pageModule = $moduleProvider->isModuleRegistered($pageModule) ? $pageModule : 'web_layout';
return $moduleProvider->accessGranted($pageModule, $backendUser) ? $pageModule : '';
$pageModule = $this->moduleProvider->isModuleRegistered($pageModule) ? $pageModule : 'web_layout';
return $this->moduleProvider->accessGranted($pageModule, $backendUser) ? $pageModule : '';
}
protected function getBackendUser(): BackendUserAuthentication
......
......@@ -127,7 +127,7 @@ class PreviewController
unset($queryParameters['L']);
}
$parameters = $queryParameters;
if (!WorkspaceService::isNewPage($pageUid)) {
if (!$this->workspaceService->isNewPage($pageUid)) {
$parameters['ADMCMD_prev'] = 'LIVE';
$liveUrl = $this->generateUrl($site, $pageUid, $parameters);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment