Skip to content

Commit

Permalink
Use arbitrary values for the filter query marker
Browse files Browse the repository at this point in the history
  • Loading branch information
phansys committed May 16, 2021
1 parent dbcfbba commit cab4bcf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Filter/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Sonata\DoctrineORMAdminBundle\Filter;

use Doctrine\ORM\Query\Expr\Comparison;
use Doctrine\ORM\Query\Expr\Orx;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface as BaseProxyQueryInterface;
use Sonata\AdminBundle\Filter\Filter as BaseFilter;
Expand Down Expand Up @@ -189,8 +190,8 @@ private function addOrParameter(BaseProxyQueryInterface $query, $parameter): voi

$expressionParts = $expression->getParts();

if (isset($expressionParts[0]) && \is_string($expressionParts[0]) &&
0 === strpos($expressionParts[0], ':sonata_admin_datagrid_filter_query_marker')
if (isset($expressionParts[0]) && $expressionParts[0] instanceof Comparison &&
0 === strpos($expressionParts[0]->getLeftExpr(), "'sonata_admin_datagrid_filter_query_marker_a'")
) {
$expression->add($parameter);

Expand All @@ -204,8 +205,7 @@ private function addOrParameter(BaseProxyQueryInterface $query, $parameter): voi

if (null === $groupName) {
// Add the ":sonata_admin_datagrid_filter_query_marker" parameter as marker for the `Orx` expression.
$orExpression->add($qb->expr()->isNull(':sonata_admin_datagrid_filter_query_marker'));
$qb->setParameter('sonata_admin_datagrid_filter_query_marker', 'sonata_admin.datagrid.filter_query.marker');
$orExpression->add($qb->expr()->neq("'sonata_admin_datagrid_filter_query_marker_a'", "'sonata_admin_datagrid_filter_query_marker_b'"));
} else {
self::$groupedOrExpressions[$groupName] = $orExpression;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Filter/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function orExpressionProvider(): iterable

yield 'Missing "or_group" option, fallback to DQL marker' => [
'SELECT e FROM MyEntity e WHERE 1 = 2 AND (:parameter_1 = 4 OR 5 = 6)'
.' AND (:sonata_admin_datagrid_filter_query_marker IS NULL'
.' AND (\'sonata_admin_datagrid_filter_query_marker_a\' <> \'sonata_admin_datagrid_filter_query_marker_b\''
.' OR e.project LIKE :project_0 OR e.version LIKE :version_1) AND 7 = 8',
[
[
Expand Down

0 comments on commit cab4bcf

Please sign in to comment.