From 60933898fbb352e585d42f8c92fc26981d71a17b Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Thu, 8 Sep 2022 13:13:36 +0200 Subject: [PATCH] FilterProcessor: Use cached iterator At the moment, when iterating over a chain, a new iterator is constructed each time containing new content. This prevents that rule/chain removed from somewhere else is also applied here, because it does not notice at all that something was removed. --- src/Compat/FilterProcessor.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Compat/FilterProcessor.php b/src/Compat/FilterProcessor.php index 0b091f1..37e2db7 100644 --- a/src/Compat/FilterProcessor.php +++ b/src/Compat/FilterProcessor.php @@ -143,7 +143,16 @@ protected function requireAndResolveFilterColumns(Filter\Rule $filter, Query $qu $subQueryGroups = []; $outsourcedRules = []; - foreach ($filter as $child) { + + $iterator = $filter->getIterator(true); + for ($iterator->rewind(); $iterator->valid(); $iterator->next()) { + $child = $iterator->current(); + if ($child instanceof Filter\Condition && ! $child->getChain()) { + // Due to __clone() circular dependency (chain <-> rule) it's not sufficient to only set + // the chain when adding the rule to that chain. Query class operates also on cloned filters + $child->setChain($filter); + } + /** @var Filter\Rule $child */ $rewrittenFilter = $this->requireAndResolveFilterColumns($child, $query, $forceOptimization); if ($rewrittenFilter !== null) {