Commit d31e9a69 authored by Helmut Hummel's avatar Helmut Hummel Committed by Helmut Hummel
Browse files

[!!!][TASK] Doctrine: Simplify restriction handling

To make the set of restrictions that are in effect when creating queries
with the QueryBuilder becomes more understandable,
we need to remove the QueryContext and the magic applied to that and replace it
with the following behavior:

delete, hidden, starttime, endtime restrictions are always enabled
and need to be removed if needed.
Other restrictions need to be provided manually depending on the desired result.

Resolves: #76167
Resolves: #76264
Releases: master
Change-Id: Iaf0cb08475ed44966838c3fbdd5756d3ba6ebcc1
Reviewed-on: https://review.typo3.org/48049

Tested-by: default avatarHelmut Hummel <helmut.hummel@typo3.org>
Reviewed-by: default avatarMorton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: default avatarMorton Jonuschat <m.jonuschat@mojocode.de>
Reviewed-by: Jan Helke's avatarJan Helke <typo3@helke.de>
Tested-by: Jan Helke's avatarJan Helke <typo3@helke.de>
Reviewed-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring's avatarAnja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Nicole Cordes's avatarNicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes's avatarNicole Cordes <typo3@cordes.co>
Reviewed-by: default avatarHelmut Hummel <helmut.hummel@typo3.org>
parent 1baca110
......@@ -13,9 +13,7 @@ namespace TYPO3\CMS\Backend\Backend\Avatar;
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException;
use TYPO3\CMS\Core\Resource\ProcessedFile;
use TYPO3\CMS\Core\Resource\ResourceFactory;
......@@ -67,15 +65,16 @@ class DefaultAvatarProvider implements AvatarProviderInterface
*/
protected function getAvatarFileUid($beUserId)
{
/** @var QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file_reference');
$file = $queryBuilder
->select('uid_local')
->from('sys_file_reference')
->where($queryBuilder->expr()->eq('tablenames', $queryBuilder->createNamedParameter('be_users')))
->andWhere($queryBuilder->expr()->eq('fieldname', $queryBuilder->createNamedParameter('avatar')))
->andWhere($queryBuilder->expr()->eq('table_local', $queryBuilder->createNamedParameter('sys_file')))
->andWhere($queryBuilder->expr()->eq('uid_foreign', (int)$beUserId))
->where(
$queryBuilder->expr()->eq('tablenames', $queryBuilder->createNamedParameter('be_users')),
$queryBuilder->expr()->eq('fieldname', $queryBuilder->createNamedParameter('avatar')),
$queryBuilder->expr()->eq('table_local', $queryBuilder->createNamedParameter('sys_file')),
$queryBuilder->expr()->eq('uid_foreign', (int)$beUserId)
)
->execute()
->fetchColumn();
......
......@@ -16,7 +16,7 @@ namespace TYPO3\CMS\Backend\Clipboard;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryContextType;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Imaging\IconProvider\SvgIconProvider;
......@@ -496,23 +496,24 @@ class Clipboard
{
$lines = array();
$tcaCtrl = $GLOBALS['TCA'][$table]['ctrl'];
if ($table != 'pages' && BackendUtility::isTableLocalizable($table) && !$tcaCtrl['transOrigPointerTable']) {
if ($table !== 'pages' && BackendUtility::isTableLocalizable($table) && !$tcaCtrl['transOrigPointerTable']) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
$queryBuilder->getQueryContext()->setContext(QueryContextType::UNRESTRICTED);
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class));
$queryBuilder
->select('*')
->from($table)
->where($queryBuilder->expr()->eq($tcaCtrl['transOrigPointerField'], (int)$parentRec['uid']))
->andWhere($queryBuilder->expr()->neq($tcaCtrl['languageField'], 0));
if (isset($tcaCtrl['delete']) && $tcaCtrl['delete']) {
$queryBuilder->andWhere($queryBuilder->expr()->eq($tcaCtrl['delete'], 0));
}
->where(
$queryBuilder->expr()->eq($tcaCtrl['transOrigPointerField'], (int)$parentRec['uid']),
$queryBuilder->expr()->neq($tcaCtrl['languageField'], 0)
);
if (isset($tcaCtrl['versioningWS']) && $tcaCtrl['versioningWS']) {
$queryBuilder->andWhere($queryBuilder->expr()->eq('t3ver_wsid', $parentRec['t3ver_wsid']));
$queryBuilder->andWhere($queryBuilder->expr()->eq('t3ver_wsid', (int)$parentRec['t3ver_wsid']));
}
$rows = $queryBuilder
->execute()
->fetchAll();
$rows = $queryBuilder->execute()->fetchAll();
if (is_array($rows)) {
$modeData = '';
if ($pad == 'normal') {
......@@ -1120,5 +1121,4 @@ class Clipboard
{
return $GLOBALS['BE_USER'];
}
}
......@@ -16,7 +16,8 @@ namespace TYPO3\CMS\Backend\Configuration;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryContextType;
use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Lang\LanguageService;
......@@ -123,18 +124,21 @@ class TranslationConfigurationProvider
$selFieldList = 'uid,' . $GLOBALS['TCA'][$translationTable]['ctrl']['languageField'];
}
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($translationTable);
$queryBuilder->getQueryContext()->setContext(QueryContextType::BACKEND_NO_VERSIONING_PLACEHOLDERS);
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
$queryBuilder
->select(...GeneralUtility::trimExplode(',', $selFieldList))
->from($translationTable)
->where($queryBuilder->expr()->eq($GLOBALS['TCA'][$translationTable]['ctrl']['transOrigPointerField'], (int)$uid))
->andWhere($queryBuilder->expr()->eq('pid', (int)($table === 'pages' ? $row['uid'] : $row['pid'])));
->where(
$queryBuilder->expr()->eq($GLOBALS['TCA'][$translationTable]['ctrl']['transOrigPointerField'], (int)$uid),
$queryBuilder->expr()->eq('pid', (int)($table === 'pages' ? $row['uid'] : $row['pid']))
);
if (!$languageUid) {
$queryBuilder
->andWhere($queryBuilder->expr()->gt($GLOBALS['TCA'][$translationTable]['ctrl']['languageField'], 0));
$queryBuilder->andWhere($queryBuilder->expr()->gt($GLOBALS['TCA'][$translationTable]['ctrl']['languageField'], 0));
} else {
$queryBuilder
->andWhere($queryBuilder->expr()->eq($GLOBALS['TCA'][$translationTable]['ctrl']['languageField'], (int)$languageUid));
$queryBuilder->andWhere($queryBuilder->expr()->eq($GLOBALS['TCA'][$translationTable]['ctrl']['languageField'], (int)$languageUid));
}
$translationRecords = $queryBuilder
->execute()
......
......@@ -16,8 +16,6 @@ namespace TYPO3\CMS\Backend\History;
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\QueryContextType;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
......@@ -171,12 +169,11 @@ class RecordHistory
public function toggleHighlight($uid)
{
$uid = (int)$uid;
/** @var QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_history');
$row = $queryBuilder
->select('snapshot')
->from('sys_history')
->where($queryBuilder->expr()->eq('uid', $uid))
->where($queryBuilder->expr()->eq('uid', (int)$uid))
->execute()
->fetch();
......@@ -185,7 +182,7 @@ class RecordHistory
$queryBuilder
->update('sys_history')
->set('snapshot', (int)!$row['snapshot'])
->where($queryBuilder->expr()->eq('uid', $uid))
->where($queryBuilder->expr()->eq('uid', (int)$uid))
->execute();
}
}
......@@ -661,17 +658,15 @@ class RecordHistory
if ($elParts[0] == 'pages' && $this->showSubElements && $this->hasPageAccess('pages', $elParts[1])) {
foreach ($GLOBALS['TCA'] as $tablename => $value) {
// check if there are records on the page
/** @var QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($tablename);
$queryBuilder->getQueryContext()->setContext(QueryContextType::UNRESTRICTED);
$queryBuilder->getRestrictions()->removeAll();
$rows = $queryBuilder
->select('uid')
->from($tablename)
->where($queryBuilder->expr()->eq('pid', (int)$elParts[1]))
->execute()
->fetchAll();
if (empty($rows)) {
->execute();
if ($rows->rowCount() === 0) {
continue;
}
foreach ($rows as $row) {
......@@ -709,7 +704,6 @@ class RecordHistory
// If table is found in $GLOBALS['TCA']:
$uid = $this->resolveElement($table, $uid);
// Selecting the $this->maxSteps most recent states:
/** @var QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_history');
$rows = $queryBuilder
->select('sys_history.*', 'sys_log.userid', 'sys_log.log_data')
......@@ -719,10 +713,10 @@ class RecordHistory
$queryBuilder->expr()->eq(
'sys_history.sys_log_uid',
$queryBuilder->quoteIdentifier('sys_log.uid')
)
),
$queryBuilder->expr()->eq('sys_history.tablename', $queryBuilder->createNamedParameter($table)),
$queryBuilder->expr()->eq('sys_history.recuid', (int)$uid)
)
->andWhere($queryBuilder->expr()->eq('sys_history.tablename', $queryBuilder->createNamedParameter($table)))
->andWhere($queryBuilder->expr()->eq('sys_history.recuid', (int)$uid))
->orderBy('sys_log.uid', 'DESC')
->setMaxResults((int)$this->maxSteps)
->execute()
......@@ -759,28 +753,28 @@ class RecordHistory
// SELECT INSERTS/DELETES
if ($this->showInsertDelete) {
// Select most recent inserts and deletes // WITHOUT snapshots
/** @var QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_log');
$rows = $queryBuilder
$result = $queryBuilder
->select('uid', 'userid', 'action', 'tstamp', 'log_data')
->from('sys_log')
->where($queryBuilder->expr()->eq('type', 1))
->andWhere($queryBuilder->expr()->orX(
$queryBuilder->expr()->eq('action', 1),
$queryBuilder->expr()->eq('action', 3)
))
->andWhere($queryBuilder->expr()->eq('tablename', $queryBuilder->createNamedParameter($table)))
->andWhere($queryBuilder->expr()->eq('recuid', (int)$uid))
->where(
$queryBuilder->expr()->eq('type', 1),
$queryBuilder->expr()->orX(
$queryBuilder->expr()->eq('action', 1),
$queryBuilder->expr()->eq('action', 3)
),
$queryBuilder->expr()->eq('tablename', $queryBuilder->createNamedParameter($table)),
$queryBuilder->expr()->eq('recuid', (int)$uid)
)
->orderBy('uid', 'DESC')
->setMaxResults((int)$this->maxSteps)
->execute()
->fetchAll();
->execute();
// If none are found, nothing more to do
if (empty($rows)) {
if ($result->rowCount() === 0) {
return $changeLog;
}
foreach ($rows as $row) {
foreach ($result as $row) {
if ($this->lastSyslogId && $row['uid'] < $this->lastSyslogId) {
continue;
}
......@@ -914,7 +908,6 @@ class RecordHistory
if (empty($shUid)) {
return;
}
/** @var QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_history');
$record = $queryBuilder
->select('*')
......
......@@ -20,6 +20,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\QueryHelper;
use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -834,11 +836,17 @@ abstract class AbstractTreeView
return $this->getDataCount($res);
} else {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table);
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
$count = $queryBuilder
->count('uid')
->from($this->table)
->where($queryBuilder->expr()->eq($this->parentField, $queryBuilder->createNamedParameter($uid)))
->andWhere(QueryHelper::stripLogicalOperatorPrefix($this->clause))
->where(
$queryBuilder->expr()->eq($this->parentField, (int)$uid),
QueryHelper::stripLogicalOperatorPrefix($this->clause)
)
->execute()
->fetchColumn();
......@@ -894,11 +902,17 @@ abstract class AbstractTreeView
return $parentId;
} else {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table);
$queryBuilder->getRestrictions()
->removeAll()
->add(GeneralUtility::makeInstance(DeletedRestriction::class))
->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
$queryBuilder
->select(...$this->fieldArray)
->from($this->table)
->where($queryBuilder->expr()->eq($this->parentField, $queryBuilder->createNamedParameter($parentId)))
->andWhere(QueryHelper::stripLogicalOperatorPrefix($this->clause));
->where(
$queryBuilder->expr()->eq($this->parentField, (int)$parentId),
QueryHelper::stripLogicalOperatorPrefix($this->clause)
);
foreach (QueryHelper::parseOrderBy($this->orderByFields) as $orderPair) {
list($fieldName, $order) = $orderPair;
......
......@@ -17,7 +17,10 @@ namespace TYPO3\CMS\Backend\Tree\View;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryContextType;
use TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\EndTimeRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\StartTimeRestriction;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
......@@ -341,15 +344,20 @@ class PagePositionMap
$lines = array();
foreach ($colPosArray as $kk => $vv) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
$queryBuilder->getQueryContext()
->setContext(QueryContextType::BACKEND_NO_VERSIONING_PLACEHOLDERS)
->setIgnoreEnableFields($showHidden);
$queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class));
if ($showHidden) {
$queryBuilder->getRestrictions()
->removeByType(HiddenRestriction::class)
->removeByType(StartTimeRestriction::class)
->removeByType(EndTimeRestriction::class);
}
$queryBuilder
->select('*')
->from('tt_content')
->where($queryBuilder->expr()->eq('pid', (int)$pid))
->andWhere($queryBuilder->expr()->eq('colPos', (int)$vv))
->where(
$queryBuilder->expr()->eq('pid', (int)$pid),
$queryBuilder->expr()->eq('colPos', (int)$vv)
)
->orderBy('sorting');
if ((string)$this->cur_sys_language !== '') {
......
......@@ -19,7 +19,6 @@ use TYPO3\CMS\Backend\Toolbar\Enumeration\InformationStatus;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Belog\Domain\Model\Constraint;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
......@@ -51,12 +50,13 @@ class SystemInformationController extends AbstractController
$this->setStartAndEndTimeFromTimeSelector($constraint);
// we can't use the extbase repository here as the required TypoScript may not be parsed yet
/** @var QueryBuilder $queryBuilder */
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_log');
$count = $queryBuilder->count('error')
->from('sys_log')
->where($queryBuilder->expr()->gte('tstamp', $timestamp))
->andWhere($queryBuilder->expr()->in('error', [-1, 1, 2]))
->where(
$queryBuilder->expr()->gte('tstamp', $timestamp),
$queryBuilder->expr()->in('error', [-1, 1, 2])
)
->execute()
->fetchColumn(0);
......
......@@ -72,9 +72,11 @@ class BackendUserSessionRepository extends Repository
->update('be_sessions')
->set('ses_userid', $authentication->user['ses_backuserid'])
->set('ses_backuserid', 0)
->where($queryBuilder->expr()->eq('ses_id', $queryBuilder->createNamedParameter($GLOBALS['BE_USER']->id)))
->andWhere($queryBuilder->expr()->eq('ses_name', $queryBuilder->createNamedParameter(BackendUserAuthentication::getCookieName())))
->andWhere($queryBuilder->expr()->eq('ses_userid', (int)$GLOBALS['BE_USER']->user['uid']))
->where(
$queryBuilder->expr()->eq('ses_id', $queryBuilder->createNamedParameter($GLOBALS['BE_USER']->id)),
$queryBuilder->expr()->eq('ses_name', $queryBuilder->createNamedParameter(BackendUserAuthentication::getCookieName())),
$queryBuilder->expr()->eq('ses_userid', (int)$GLOBALS['BE_USER']->user['uid'])
)
->execute();
}
}
......@@ -19,8 +19,14 @@ use TYPO3\CMS\Core\Crypto\Random;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
use TYPO3\CMS\Core\Database\Query\QueryHelper;
use TYPO3\CMS\Core\Database\Query\Restriction\DefaultRestrictionContainer;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\EndTimeRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionContainerInterface;
use TYPO3\CMS\Core\Database\Query\Restriction\RootLevelRestriction;
use TYPO3\CMS\Core\Database\Query\Restriction\StartTimeRestriction;
use TYPO3\CMS\Core\Exception;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
......@@ -1050,6 +1056,7 @@ abstract class AbstractUserAuthentication
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable($this->session_table);
$queryBuilder->setRestrictions($this->userConstraints());
$queryBuilder->select('*')
->from($this->session_table)
->from($this->user_table)
......@@ -1057,28 +1064,21 @@ abstract class AbstractUserAuthentication
$queryBuilder->expr()->eq(
$this->session_table . '.ses_id',
$queryBuilder->createNamedParameter($this->id)
)
)
->andWhere(
),
$queryBuilder->expr()->eq(
$this->session_table . '.ses_name',
$queryBuilder->createNamedParameter($this->name)
)
)
// Condition on which to join the session and user table
->andWhere(
),
// Condition on which to join the session and user table
$queryBuilder->expr()->eq(
$this->session_table . '.ses_userid',
$queryBuilder->quoteIdentifier($this->user_table . '.' . $this->userid_column)
)
)
->andWhere(
),
$queryBuilder->expr()->eq(
$this->session_table . '.ses_hashlock',
$queryBuilder->createNamedParameter($this->hashLockClause_getHashInt())
)
)
->andWhere($this->userConstraints($queryBuilder->expr()));
);
if ($this->lockIP) {
$queryBuilder->andWhere(
......@@ -1097,50 +1097,38 @@ abstract class AbstractUserAuthentication
}
/**
* @param ExpressionBuilder $expressionBuilder
* @param string $tableAlias
* @return \Doctrine\DBAL\Query\Expression\CompositeExpression
* This returns the restrictions needed to select the user respecting
* enable columns and flags like deleted, hidden, starttime, endtime
* and rootLevel
*
* @return \TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionContainerInterface
* @internal
*/
protected function userConstraints(
ExpressionBuilder $expressionBuilder,
string $tableAlias = ''
): \Doctrine\DBAL\Query\Expression\CompositeExpression {
if ($tableAlias === '') {
$tableAlias = $this->user_table;
}
protected function userConstraints(): QueryRestrictionContainerInterface
{
$restrictionContainer = GeneralUtility::makeInstance(DefaultRestrictionContainer::class);
$constraints = $expressionBuilder->andX();
if ($this->enablecolumns['rootLevel']) {
$constraints->add(
$expressionBuilder->eq($tableAlias . '.pid', 0)
);
if (empty($this->enablecolumns['disabled'])) {
$restrictionContainer->removeByType(HiddenRestriction::class);
}
if ($this->enablecolumns['disabled']) {
$constraints->add(
$expressionBuilder->eq($tableAlias . '.' . $this->enablecolumns['disabled'], 0)
);
if (empty($this->enablecolumns['deleted'])) {
$restrictionContainer->removeByType(DeletedRestriction::class);
}
if ($this->enablecolumns['deleted']) {
$constraints->add(
$expressionBuilder->eq($tableAlias . '.' . $this->enablecolumns['deleted'], 0)
);
if (empty($this->enablecolumns['starttime'])) {
$restrictionContainer->removeByType(StartTimeRestriction::class);
}
if ($this->enablecolumns['starttime']) {
$constraints->add(
$expressionBuilder->lte($tableAlias . '.' . $this->enablecolumns['starttime'], $GLOBALS['EXEC_TIME'])
);
if (empty($this->enablecolumns['endtime'])) {
$restrictionContainer->removeByType(EndTimeRestriction::class);
}
if ($this->enablecolumns['endtime']) {
$constraints->add(
$expressionBuilder->orX(
$expressionBuilder->eq($tableAlias . '.' . $this->enablecolumns['endtime'], 0),
$expressionBuilder->gt($tableAlias . '.' . $this->enablecolumns['endtime'], $GLOBALS['EXEC_TIME'])
)
);
if (!empty($this->enablecolumns['rootLevel'])) {
$restrictionContainer->add(GeneralUtility::makeInstance(RootLevelRestriction::class, [$this->user_table]));
}
return $constraints;
return $restrictionContainer;
}
/**
......@@ -1479,7 +1467,10 @@ abstract class AbstractUserAuthentication
$authInfo['db_user']['username_column'] = $this->username_column;
$authInfo['db_user']['userident_column'] = $this->userident_column;
$authInfo['db_user']['usergroup_column'] = $this->usergroup_column;
$authInfo['db_user']['enable_clause'] = $this->userConstraints($expressionBuilder);
$authInfo['db_user']['enable_clause'] = $this->userConstraints()->buildExpression(
[$this->user_table],
$expressionBuilder
);
if ($this->checkPid && $this->checkPid_value !== null) {
$authInfo['db_user']['checkPidList'] = $this->checkPid_value;
$authInfo['db_user']['check_pid_clause'] = $expressionBuilder->in(
......@@ -1521,9 +1512,7 @@ abstract class AbstractUserAuthentication
$query->expr()->lt(
'ses_tstamp',
$query->createNamedParameter((int)($GLOBALS['EXEC_TIME'] - $this->gc_time))
)
)
->andWhere(
),
$query->expr()->eq(
'ses_name',
$query->createNamedParameter($this->name)
......@@ -1604,10 +1593,10 @@ abstract class AbstractUserAuthentication
public function getRawUserByUid($uid)
{
$query = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->user_table);
$query->setRestrictions($this->userConstraints());
$query->select('*')
->from($this->user_table)
->where($query->expr()->eq('uid', $query->createNamedParameter($uid)))
->andWhere($this->userConstraints($query->expr()));
->where($query->expr()->eq('uid', (int)$uid));
return $query->execute()->fetch();
}
......@@ -1623,10 +1612,10 @@ abstract class AbstractUserAuthentication
public function getRawUserByName($name)
{
$query = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->user_table);
$query->setRestrictions($this->userConstraints());
$query->select('*')
->from($this->user_table)
->where($query->expr()->eq('username', $query->createNamedParameter($name)))
->andWhere($this->userConstraints($query->expr()));
->where($query->expr()->eq('username', $query->createNamedParameter($name)));
return $query->execute()->fetch();
}
......@@ -1650,6 +1639,7 @@ abstract class AbstractUserAuthentication
$user = false;
if ($username || $extraWhere) {
$query = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($dbUser['table']);
$query->getRestrictions()->removeAll();