Project

General

Profile

Actions

Bug #103456

closed

AbstractRestrictionContainer::removeByType() causes problems with xclassed restrictions.

Added by Ole Trenner 8 months ago. Updated 5 months ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Database API (Doctrine DBAL)
Target version:
-
Start date:
2024-03-21
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
12
PHP Version:
Tags:
restrictions, xclass
Complexity:
medium
Is Regression:
Sprint Focus:

Description

The current implementation of AbstractRestrictionContainer::removeByType() removes values from the restrictions and enforcedRestrictions arrays by unsetting the restriction-type as specified by the parameter:

unset($this->restrictions[$restrictionType], $this->enforcedRestrictions[$restrictionType]);

This causes problems when a restriction is xclassed. The common approach to disable default restrictions is something like this:

$queryBuilder->getRestrictions()
->removeByType(HiddenRestriction::class)
->removeByType(StartTimeRestriction::class)
->removeByType(EndTimeRestriction::class);

and this would fail to remove an xclassed restriction with the current implementation.

An alternative approach might be to iterate over the array values and check if they are instances of the specified type:

public function removeByType(string $restrictionType): QueryRestrictionContainerInterface
{
foreach ($this->restrictions as $type => $instance) {
if ($instance instanceof $restrictionType) {
unset($this->restrictions[$type]);
}
}
foreach ($this->enforcedRestrictions as $type => $instance) {
if ($instance instanceof $restrictionType) {
unset($this->enforcedRestrictions[$type]);
}
}
return $this;
}

This approach would work both for the original and possible xclassed restrictions.

Thank you :)
Ole.

Actions #1

Updated by Gerrit Code Review 8 months ago

  • Status changed from New to Under Review

Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/83562

Actions #2

Updated by Gerrit Code Review 8 months ago

Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/83568

Actions #3

Updated by Gerrit Code Review 8 months ago

Patch set 2 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/83562

Actions #4

Updated by Gerrit Code Review 8 months ago

Patch set 1 for branch 12.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/83539

Actions #5

Updated by Gerrit Code Review 8 months ago

Patch set 2 for branch 12.4 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/83539

Actions #6

Updated by Oliver Bartsch 8 months ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #7

Updated by Benni Mack 5 months ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF