Skip to content
Snippets Groups Projects
Commit 1350e2b8 authored by Oliver Bartsch's avatar Oliver Bartsch
Browse files

[BUGFIX] Respect cross classes when removing restrictions

When removeByType is used to remove restrictions
from the container, it is now ensured that also
cross classes are properly respected.

Resolves: #103456
Releases: main, 12.4
Change-Id: I4841fe1cba7388358771cf01ee220afa4482349a
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83562


Tested-by: default avatarStefan Bürk <stefan@buerk.tech>
Reviewed-by: default avatarOliver Bartsch <bo@cedev.de>
Tested-by: default avatarOliver Bartsch <bo@cedev.de>
Tested-by: default avatarcore-ci <typo3@b13.com>
Tested-by: default avatarBenni Mack <benni@typo3.org>
Reviewed-by: default avatarBenni Mack <benni@typo3.org>
Reviewed-by: default avatarStefan Bürk <stefan@buerk.tech>
parent 3d18a57a
Branches
Tags
No related merge requests found
...@@ -69,7 +69,20 @@ abstract class AbstractRestrictionContainer implements QueryRestrictionContainer ...@@ -69,7 +69,20 @@ abstract class AbstractRestrictionContainer implements QueryRestrictionContainer
*/ */
public function removeByType(string $restrictionType): QueryRestrictionContainerInterface public function removeByType(string $restrictionType): QueryRestrictionContainerInterface
{ {
unset($this->restrictions[$restrictionType], $this->enforcedRestrictions[$restrictionType]); foreach ($this->restrictions as $type => $instance) {
if ($instance instanceof $restrictionType) {
unset($this->restrictions[$type]);
break;
}
}
foreach ($this->enforcedRestrictions as $type => $instance) {
if ($instance instanceof $restrictionType) {
unset($this->enforcedRestrictions[$type]);
break;
}
}
return $this; return $this;
} }
......
...@@ -19,6 +19,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction; ...@@ -19,6 +19,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Database\Query\Restriction;
use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\Attributes\Test;
use TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression; use TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression;
use TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction;
use TYPO3\CMS\Core\Tests\Unit\Database\Mocks\InstantiatableAbstractRestrictionContainer; use TYPO3\CMS\Core\Tests\Unit\Database\Mocks\InstantiatableAbstractRestrictionContainer;
use TYPO3\CMS\Core\Tests\Unit\Database\Mocks\MockEnforceableQueryRestriction; use TYPO3\CMS\Core\Tests\Unit\Database\Mocks\MockEnforceableQueryRestriction;
use TYPO3\CMS\Core\Tests\Unit\Database\Mocks\MockQueryRestriction; use TYPO3\CMS\Core\Tests\Unit\Database\Mocks\MockQueryRestriction;
...@@ -56,6 +57,20 @@ final class AbstractRestrictionContainerTest extends AbstractRestrictionTestCase ...@@ -56,6 +57,20 @@ final class AbstractRestrictionContainerTest extends AbstractRestrictionTestCase
self::assertSame('', (string)$expression); self::assertSame('', (string)$expression);
} }
#[Test]
public function crossClassWillBeRemovedWhenRemovedByType(): void
{
$restriction = new class () extends HiddenRestriction {};
$subject = new InstantiatableAbstractRestrictionContainer();
$subject->add($restriction);
$subject->removeByType(HiddenRestriction::class);
$GLOBALS['TCA']['aTable']['ctrl']['enablecolumns']['disabled'] = 'hidden';
$expression = $subject->buildExpression(['aTable' => 'aTable'], $this->expressionBuilder);
self::assertSame('', (string)$expression);
}
#[Test] #[Test]
public function enforceableRestrictionsWillBeRemovedWhenRemovedByTypeAndRemovedAllIsAdditionallyCalled(): void public function enforceableRestrictionsWillBeRemovedWhenRemovedByTypeAndRemovedAllIsAdditionallyCalled(): void
{ {
......
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