Skip to content
Snippets Groups Projects
Commit c7289fa3 authored by Manuel Selbach's avatar Manuel Selbach Committed by Richard Haeser
Browse files

[BUGFIX] Use single instance of DocumentTypeExclusionRestriction

With this change, the DocumentTypeExclusionRestrictionTest will use
NOT IN instead of <>. This will allow to have only one instance of that
restriction.

Additionally multiple casts to integer have been removed.

Resolves: #87938
Releases: master, 9.5
Change-Id: I3c1c5cc47800dae3f13afc654f55236634ad5bc5
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/60275


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: default avatarDennis Prinse <dennis@dennisprinse.com>
Tested-by: default avatarRichard Haeser <richard@maxserv.com>
Reviewed-by: default avatarDennis Prinse <dennis@dennisprinse.com>
Reviewed-by: default avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: default avatarClaus Due <claus@phpmind.net>
Reviewed-by: default avatarRichard Haeser <richard@maxserv.com>
parent e8310ca6
Branches
Tags
No related merge requests found
...@@ -357,14 +357,17 @@ class TreeController ...@@ -357,14 +357,17 @@ class TreeController
$userTsConfig = $this->getBackendUser()->getTSConfig(); $userTsConfig = $this->getBackendUser()->getTSConfig();
$excludedDocumentTypes = GeneralUtility::intExplode(',', $userTsConfig['options.']['pageTree.']['excludeDoktypes'] ?? '', true); $excludedDocumentTypes = GeneralUtility::intExplode(',', $userTsConfig['options.']['pageTree.']['excludeDoktypes'] ?? '', true);
$additionalPageTreeQueryRestrictions = []; $additionalQueryRestrictions = [];
if (!empty($excludedDocumentTypes)) { if (!empty($excludedDocumentTypes)) {
foreach ($excludedDocumentTypes as $excludedDocumentType) { $additionalQueryRestrictions[] = $this->retrieveDocumentTypeExclusionRestriction($excludedDocumentTypes);
$additionalPageTreeQueryRestrictions[] = new DocumentTypeExclusionRestriction((int)$excludedDocumentType);
}
} }
$repository = GeneralUtility::makeInstance(PageTreeRepository::class, (int)$backendUser->workspace, [], $additionalPageTreeQueryRestrictions); $repository = GeneralUtility::makeInstance(
PageTreeRepository::class,
(int)$backendUser->workspace,
[],
$additionalQueryRestrictions
);
$entryPoints = (int)($backendUser->uc['pageTree_temporaryMountPoint'] ?? 0); $entryPoints = (int)($backendUser->uc['pageTree_temporaryMountPoint'] ?? 0);
if ($entryPoints > 0) { if ($entryPoints > 0) {
...@@ -415,6 +418,19 @@ class TreeController ...@@ -415,6 +418,19 @@ class TreeController
return $entryPoints; return $entryPoints;
} }
/**
* @param int[] $excludedDocumentTypes
* @return DocumentTypeExclusionRestriction|null
*/
protected function retrieveDocumentTypeExclusionRestriction(array $excludedDocumentTypes): ?DocumentTypeExclusionRestriction
{
if (empty($excludedDocumentTypes)) {
return null;
}
return GeneralUtility::makeInstance(DocumentTypeExclusionRestriction::class, $excludedDocumentTypes);
}
/** /**
* Returns the first configured domain name for a page * Returns the first configured domain name for a page
* *
......
...@@ -24,16 +24,20 @@ use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder; ...@@ -24,16 +24,20 @@ use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
class DocumentTypeExclusionRestriction implements QueryRestrictionInterface class DocumentTypeExclusionRestriction implements QueryRestrictionInterface
{ {
/** /**
* @var int * @var int[]
*/ */
protected $doktype; protected $doktypes;
/** /**
* @param int $doktype * @param int[]|int $doktype
*/ */
public function __construct(int $doktype) public function __construct($doktype)
{ {
$this->doktype = (int)$doktype; if (is_array($doktype)) {
$this->doktypes = $doktype;
} else {
$this->doktypes = [$doktype];
}
} }
/** /**
...@@ -52,7 +56,7 @@ class DocumentTypeExclusionRestriction implements QueryRestrictionInterface ...@@ -52,7 +56,7 @@ class DocumentTypeExclusionRestriction implements QueryRestrictionInterface
continue; continue;
} }
$constraints[] = $expressionBuilder->neq($tableAlias . '.doktype', $this->doktype); $constraints[] = $expressionBuilder->notIn($tableAlias . '.doktype', $this->doktypes);
} }
return $expressionBuilder->andX(...$constraints); return $expressionBuilder->andX(...$constraints);
......
<?php
declare(strict_types = 1);
namespace TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction;
/*
* 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!
*/
use TYPO3\CMS\Core\Database\Query\Restriction\DocumentTypeExclusionRestriction;
class DocumentTypeExclusionRestrictionTest extends AbstractRestrictionTestCase
{
public function buildRestrictionsAddsDoktypeWhereClauseDataProvider(): array
{
return [
'build with one parameter' => [
[1],
'"pages"."doktype" NOT IN (1)',
],
'build with multiple parameter' => [
[1, 4, 100],
'"pages"."doktype" NOT IN (1, 4, 100)',
],
'build with int parameter' => [
1,
'"pages"."doktype" NOT IN (1)',
],
];
}
/**
* @test
*
* @dataProvider buildRestrictionsAddsDoktypeWhereClauseDataProvider
*/
public function buildRestrictionsAddsDoktypeWhereClause($excludedDocumentTypes, string $expected): void
{
$subject = new DocumentTypeExclusionRestriction($excludedDocumentTypes);
$expression = $subject->buildExpression(['pages' => 'pages'], $this->expressionBuilder);
self::assertSame($expected, (string)$expression);
}
}
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