TYPO3 v15 dev-main snapshot ()

This commit is contained in:
2026-08-10 22:31:03 +02:00
commit 61d66df078
65 changed files with 8311 additions and 0 deletions
@@ -0,0 +1,117 @@
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Beuser\Domain\Repository;
use TYPO3\CMS\Beuser\Domain\Dto\BackendUserGroup;
use TYPO3\CMS\Beuser\Event\AfterBackendGroupListConstraintsAssembledFromDemandEvent;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException;
use TYPO3\CMS\Extbase\Persistence\Generic\QueryResult;
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
use TYPO3\CMS\Extbase\Persistence\Repository;
/**
* Repository for \TYPO3\CMS\Beuser\Domain\Model\BackendUserGroup
* @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
* @extends Repository<\TYPO3\CMS\Beuser\Domain\Model\BackendUserGroup>
*/
class BackendUserGroupRepository extends Repository
{
public const TABLE_NAME = 'be_groups';
protected $defaultOrderings = [
'title' => QueryInterface::ORDER_ASCENDING,
];
/**
* Overwrite createQuery to don't respect enable fields
*/
public function createQuery(): QueryInterface
{
$query = parent::createQuery();
$query->getQuerySettings()->setIgnoreEnableFields(true);
return $query;
}
/**
* Get QueryBuilder without restrictions for table be_groups
*/
public function getQueryBuilder(bool $removeRestrictions = true): QueryBuilder
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(self::TABLE_NAME);
if ($removeRestrictions === true) {
$queryBuilder->getRestrictions()->removeAll();
}
return $queryBuilder;
}
/**
* Finds Backend Usergroups on a given list of uids
*/
public function findByUidList(array $uidList): array
{
$query = $this->createQuery();
// being explicit here, albeit `Typo3DbQueryParser::parseDynamicOperand` uses prepared parameters
$uidList = array_map(intval(...), $uidList);
$query->matching($query->in('uid', $uidList));
return $query->execute(true);
}
/**
* Preforms a query on be_groups, matching the field title with like
* @throws InvalidQueryException
*/
public function findByFilter(BackendUserGroup $backendUserGroupDto): QueryResult
{
$constraints = [];
$query = $this->createQuery();
$query->setOrderings(['title' => QueryInterface::ORDER_ASCENDING]);
if ($backendUserGroupDto->getTitle() !== '') {
$searchConstraints = [];
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(self::TABLE_NAME);
$searchConstraints[] = $query->like(
'title',
'%' . $queryBuilder->escapeLikeWildcards($backendUserGroupDto->getTitle()) . '%'
);
if (MathUtility::canBeInterpretedAsInteger($backendUserGroupDto->getTitle())) {
$searchConstraints[] = $query->equals('uid', (int)$backendUserGroupDto->getTitle());
}
if (count($searchConstraints) >= 2) {
$constraints[] = $query->logicalOr(...$searchConstraints);
} else {
$constraints = $searchConstraints;
}
}
$constraints = $this->eventDispatcher->dispatch(
new AfterBackendGroupListConstraintsAssembledFromDemandEvent(
$backendUserGroupDto,
$query,
$constraints
)
)->constraints;
$query->matching($query->logicalAnd(...$constraints));
/** @var QueryResult $result */
$result = $query->execute();
return $result;
}
}
@@ -0,0 +1,171 @@
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Beuser\Domain\Repository;
use TYPO3\CMS\Beuser\Domain\Model\BackendUser;
use TYPO3\CMS\Beuser\Domain\Model\Demand;
use TYPO3\CMS\Beuser\Event\AfterBackendUserListConstraintsAssembledFromDemandEvent;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Session\Backend\SessionBackendInterface;
use TYPO3\CMS\Core\Session\SessionManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\QueryResult;
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
use TYPO3\CMS\Extbase\Persistence\Repository;
/**
* Repository for \TYPO3\CMS\Beuser\Domain\Model\BackendUser
* @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
* @extends Repository<BackendUser>
*/
class BackendUserRepository extends Repository
{
/**
* Finds Backend Users on a given list of uids
*/
public function findByUidList(array $uidList): QueryResult
{
$query = $this->createQuery();
$query->matching($query->in('uid', array_map(intval(...), $uidList)));
/** @var QueryResult $result */
$result = $query->execute();
return $result;
}
/**
* Find Backend Users matching to Demand object properties
*/
public function findDemanded(Demand $demand): QueryResult
{
$constraints = [];
$query = $this->createQuery();
$query->setOrderings(['userName' => QueryInterface::ORDER_ASCENDING]);
// Username
if ($demand->getUserName() !== '') {
$searchConstraints = [];
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('be_users');
foreach (['userName', 'realName'] as $field) {
$searchConstraints[] = $query->like(
$field,
'%' . $queryBuilder->escapeLikeWildcards($demand->getUserName()) . '%'
);
}
if (MathUtility::canBeInterpretedAsInteger($demand->getUserName())) {
$searchConstraints[] = $query->equals('uid', (int)$demand->getUserName());
}
if (count($searchConstraints) === 1) {
$constraints[] = reset($searchConstraints);
} else {
$constraints[] = $query->logicalOr(...$searchConstraints);
}
}
switch ($demand->getUserType()) {
case Demand::USERTYPE_ADMINONLY:
// Only display admin users
$constraints[] = $query->equals('admin', 1);
break;
case Demand::USERTYPE_USERONLY:
// Only display non-admin users
$constraints[] = $query->equals('admin', 0);
break;
}
switch ($demand->getStatus()) {
case Demand::STATUS_ACTIVE:
// Only display active users
$constraints[] = $query->equals('disable', 0);
break;
case Demand::STATUS_INACTIVE:
// Only display in-active users
$constraints[] = $query->equals('disable', 1);
break;
}
switch ($demand->getLogins()) {
case Demand::LOGIN_NONE:
// Not logged in before
$constraints[] = $query->equals('lastlogin', 0);
break;
case Demand::LOGIN_SOME:
// At least one login
$constraints[] = $query->logicalNot($query->equals('lastlogin', 0));
break;
case Demand::LOGIN_CURRENT:
// Currently logged-in users
$sessionTimeout = (int)($GLOBALS['TYPO3_CONF_VARS']['BE']['sessionTimeout'] ?? 28800);
$constraints[] = $query->greaterThanOrEqual('lastlogin', time() - $sessionTimeout);
}
// In backend user group
if ($demand->getBackendUserGroup()) {
$constraints[] = $query->logicalOr(
$query->equals('usergroup', $demand->getBackendUserGroup()),
$query->like('usergroup', $demand->getBackendUserGroup() . ',%'),
$query->like('usergroup', '%,' . $demand->getBackendUserGroup()),
$query->like('usergroup', '%,' . $demand->getBackendUserGroup() . ',%'),
);
}
$constraints = $this->eventDispatcher->dispatch(
new AfterBackendUserListConstraintsAssembledFromDemandEvent(
$demand,
$query,
$constraints
)
)->constraints;
$query->matching($query->logicalAnd(...$constraints));
/** @var QueryResult $result */
$result = $query->execute();
return $result;
}
/**
* Find Backend Users currently online
*/
public function findOnline(): QueryResult
{
$uids = [];
foreach ($this->getSessionBackend()->getAll() as $sessionRecord) {
if (isset($sessionRecord['ses_userid']) && !in_array($sessionRecord['ses_userid'], $uids, true)) {
$uids[] = $sessionRecord['ses_userid'];
}
}
$query = $this->createQuery();
$query->matching($query->in('uid', $uids));
/** @var QueryResult $result */
$result = $query->execute();
return $result;
}
/**
* Overwrite createQuery to don't respect enable fields
*/
public function createQuery(): QueryInterface
{
$query = parent::createQuery();
$query->getQuerySettings()->setIgnoreEnableFields(true);
return $query;
}
protected function getSessionBackend(): SessionBackendInterface
{
return GeneralUtility::makeInstance(SessionManager::class)->getSessionBackend('BE');
}
}
@@ -0,0 +1,93 @@
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Beuser\Domain\Repository;
use TYPO3\CMS\Beuser\Domain\Model\BackendUser;
use TYPO3\CMS\Core\Authentication\AbstractUserAuthentication;
use TYPO3\CMS\Core\Session\Backend\HashableSessionBackendInterface;
use TYPO3\CMS\Core\Session\Backend\SessionBackendInterface;
use TYPO3\CMS\Core\Session\SessionManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* @internal This class is a TYPO3 Backend implementation and is not considered part of the Public TYPO3 API.
*/
class BackendUserSessionRepository
{
protected SessionBackendInterface $sessionBackend;
public function __construct()
{
$this->sessionBackend = GeneralUtility::makeInstance(SessionManager::class)->getSessionBackend('BE');
}
/**
* Find all active sessions for all backend users
*/
public function findAllActive(): array
{
$allSessions = $this->sessionBackend->getAll();
// Map array to correct keys
$allSessions = array_map(
static function (array $session): array {
return [
'id' => $session['ses_id'], // this is the hashed sessionId
'ip' => $session['ses_iplock'],
'timestamp' => $session['ses_tstamp'],
'ses_userid' => $session['ses_userid'],
];
},
$allSessions
);
// Sort by timestamp
usort($allSessions, static function ($session1, $session2) {
return $session1['timestamp'] <=> $session2['timestamp'];
});
return $allSessions;
}
/**
* Find Sessions for specific BackendUser
*/
public function findByBackendUser(BackendUser $backendUser): array
{
$allActive = $this->findAllActive();
return array_filter(
$allActive,
static function (array $session) use ($backendUser): bool {
return (int)$session['ses_userid'] === $backendUser->getUid();
}
);
}
public function getPersistedSessionIdentifier(AbstractUserAuthentication $userObject): string
{
$currentSessionId = $userObject->getSession()->getIdentifier();
if ($this->sessionBackend instanceof HashableSessionBackendInterface) {
$currentSessionId = $this->sessionBackend->hash($currentSessionId);
}
return $currentSessionId;
}
public function terminateSessionByIdentifier(string $sessionIdentifier): bool
{
return $this->sessionBackend->remove($sessionIdentifier);
}
}
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Beuser\Domain\Repository;
use TYPO3\CMS\Beuser\Domain\Model\FileMount;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
use TYPO3\CMS\Extbase\Persistence\Repository;
/**
* Repository for \TYPO3\CMS\Extbase\Domain\Model\FileMount.
* @extends Repository<FileMount>
*/
class FileMountRepository extends Repository
{
public function initializeObject(): void
{
/** @var Typo3QuerySettings $querySettings */
$querySettings = GeneralUtility::makeInstance(Typo3QuerySettings::class);
$querySettings->setRespectStoragePage(false);
$querySettings->setIgnoreEnableFields(true);
$this->setDefaultQuerySettings($querySettings);
}
}