Actions
Bug #103456
closedAbstractRestrictionContainer::removeByType() causes problems with xclassed restrictions.
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