From a581e0e52a0fdee30ec6856f54c813552c188c96 Mon Sep 17 00:00:00 2001 From: Eric Gesemann Date: Tue, 2 Jun 2026 12:04:51 +0200 Subject: [PATCH] Remove `GroupByModifierListener` and improve distinct count handling in `SelectModifierListener` --- .../GroupByModifierListener.php | 20 ------------------- .../SelectModifierListener.php | 14 ++++++------- 2 files changed, 7 insertions(+), 27 deletions(-) delete mode 100644 src/EventListener/QueryStructModifier/GroupByModifierListener.php diff --git a/src/EventListener/QueryStructModifier/GroupByModifierListener.php b/src/EventListener/QueryStructModifier/GroupByModifierListener.php deleted file mode 100644 index 188c1c1c..00000000 --- a/src/EventListener/QueryStructModifier/GroupByModifierListener.php +++ /dev/null @@ -1,20 +0,0 @@ -config->isCounting) - { - $event->queryStruct->setGroupBy(null); - } - } -} \ No newline at end of file diff --git a/src/EventListener/QueryStructModifier/SelectModifierListener.php b/src/EventListener/QueryStructModifier/SelectModifierListener.php index 7469bc52..997a7ae9 100644 --- a/src/EventListener/QueryStructModifier/SelectModifierListener.php +++ b/src/EventListener/QueryStructModifier/SelectModifierListener.php @@ -5,8 +5,8 @@ namespace HeimrichHannot\FlareBundle\EventListener\QueryStructModifier; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Exception as DBALException; use HeimrichHannot\FlareBundle\Event\ModifyListQueryStructEvent; -use HeimrichHannot\FlareBundle\Exception\AbortFilteringException; use HeimrichHannot\FlareBundle\Query\TableAliasRegistry; use Symfony\Component\EventDispatcher\Attribute\AsEventListener; @@ -18,7 +18,7 @@ public function __construct( ) {} /** - * @throws AbortFilteringException + * @throws DBALException */ public function __invoke(ModifyListQueryStructEvent $event): void { @@ -27,13 +27,13 @@ public function __invoke(ModifyListQueryStructEvent $event): void if ($event->config->isCounting) { $struct->setSelect(\sprintf( - "COUNT(%s) AS %s", - (\count($struct->getJoins()) < 1) - ? '*' - : \sprintf('DISTINCT(%s)', $this->connection->quoteIdentifier(TableAliasRegistry::ALIAS_MAIN . '.id')), - $this->connection->quoteIdentifier('count') + "COUNT(DISTINCT(%s)) AS %s", + $this->connection->quoteIdentifier(TableAliasRegistry::ALIAS_MAIN . '.id'), + $this->connection->quoteIdentifier('count'), )); + $struct->setGroupBy(null); + return; }