Skip to content

Commit

Permalink
[BUGFIX] Avoid using BackendWorkspaceRestriction
Browse files Browse the repository at this point in the history
When using BackendWorkspaceRestriction the DB query
fetches newly created records of ALL workspaces, not just the currently
given workspace.

For this reason it is highly discouraged to use this
restriction but use the main WorkspaceRestriction instead.

This change adapts all remaining places which especially
is relevant when having multiple NEW PLACEHOLDERs in various
workspaces to only work on the current workspace.

Resolves: #92209
Releases: master, 10.4
Change-Id: Ie8b2321270b4804fa59cef1fa712cd820242ee40
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/65822
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Benni Mack <benni@typo3.org>
  • Loading branch information
bmack committed Sep 23, 2020
1 parent 174c73d commit b62ef21
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 26 deletions.
Expand Up @@ -18,8 +18,8 @@
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction;
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
use TYPO3\CMS\Core\Site\Entity\NullSite;
use TYPO3\CMS\Core\Site\Entity\SiteInterface;
Expand Down Expand Up @@ -133,7 +133,7 @@ public function translationInfo($table, $uid, $languageUid = 0, array $row = nul
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->getBackendUserAuthentication()->workspace));
$queryBuilder
->select(...GeneralUtility::trimExplode(',', $selFieldList))
->from($table)
Expand Down
Expand Up @@ -35,8 +35,8 @@
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction;
use TYPO3\CMS\Core\Database\ReferenceIndex;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
Expand Down Expand Up @@ -1897,7 +1897,7 @@ protected function getQueryBuilderForTranslationMode(int $page, int $column, int
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->getBackendUser()->workspace));

return $queryBuilder
->count('uid')
Expand Down Expand Up @@ -2061,7 +2061,7 @@ protected function languageSwitch(string $table, int $uid, $pid = null)
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->getBackendUser()->workspace));

$result = $queryBuilder->select(...GeneralUtility::trimExplode(',', $fetchFields, true))
->from($table)
Expand Down Expand Up @@ -2167,7 +2167,7 @@ protected function localizationRedirect(ServerRequestInterface $request): ?Respo
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->getBackendUser()->workspace));
$localizedRecord = $queryBuilder->select('uid')
->from($table)
->where(
Expand Down Expand Up @@ -2239,7 +2239,7 @@ protected function getLanguages(int $id, string $table): array
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
$queryBuilder->getRestrictions()->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->getBackendUser()->workspace));
$statement = $queryBuilder->select('uid', $GLOBALS['TCA']['pages']['ctrl']['languageField'])
->from('pages')
->where(
Expand Down
6 changes: 3 additions & 3 deletions typo3/sysext/backend/Classes/Utility/BackendUtility.php
Expand Up @@ -33,9 +33,9 @@
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Database\Query\QueryHelper;
use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction;
use TYPO3\CMS\Core\Database\RelationHandler;
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
Expand Down Expand Up @@ -294,7 +294,7 @@ public static function getRecordLocalization($table, $uid, $language, $andWhereC
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, static::getBackendUserAuthentication()->workspace));

$queryBuilder->select('*')
->from($table)
Expand Down Expand Up @@ -1797,7 +1797,7 @@ public static function getProcessedValue(
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, static::getBackendUserAuthentication()->workspace));
$constraints = [
$queryBuilder->expr()->eq(
$theColConf['foreign_field'],
Expand Down
16 changes: 5 additions & 11 deletions typo3/sysext/core/Classes/DataHandling/DataHandler.php
Expand Up @@ -38,7 +38,6 @@
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryHelper;
use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionContainerInterface;
use TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction;
Expand Down Expand Up @@ -4341,24 +4340,19 @@ public function moveL10nOverlayRecords($table, $uid, $destPid, $originalRecordDe
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->BE_USER->workspace));

$queryBuilder->select('*')
$l10nRecords = $queryBuilder->select('*')
->from($table)
->where(
$queryBuilder->expr()->eq(
$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'],
$queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT, ':pointer')
)
);

if (BackendUtility::isTableWorkspaceEnabled($table)) {
$queryBuilder->andWhere(
$queryBuilder->expr()->eq('t3ver_oid', $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT))
);
}
)
->execute()
->fetchAll();

$l10nRecords = $queryBuilder->execute()->fetchAll();
if (is_array($l10nRecords)) {
$localizedDestPids = [];
// If $$originalRecordDestinationPid < 0, then it is the uid of the original language record we are inserting after
Expand Down
Expand Up @@ -19,8 +19,8 @@
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction;
use TYPO3\CMS\Core\Database\RelationHandler;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\DataHandling\ReferenceIndexUpdater;
Expand Down Expand Up @@ -881,7 +881,7 @@ protected function fetchTranslationValues(string $tableName, array $fieldNames,
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class, $this->backendUser->workspace, false));
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->backendUser->workspace));
$statement = $queryBuilder
->select(...array_values($fieldNames))
->from($tableName)
Expand Down Expand Up @@ -1090,7 +1090,7 @@ protected function fetchDependentElements(string $tableName, array $ids, array $
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class, $this->backendUser->workspace, false));
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $this->backendUser->workspace));

$zeroParameter = $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT);
$ids = $this->filterNumericIds($ids);
Expand Down
Expand Up @@ -20,8 +20,8 @@
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\WorkspaceRestriction;
use TYPO3\CMS\Core\Exception;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
Expand Down Expand Up @@ -841,7 +841,7 @@ protected function getTemplateQueryBuilder(int $pid): QueryBuilder
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
->add(GeneralUtility::makeInstance(WorkspaceRestriction::class, $GLOBALS['BE_USER']->workspace));

$queryBuilder->select('*')
->from('sys_template')
Expand Down

0 comments on commit b62ef21

Please sign in to comment.