From 778c21e81720378ec9ef0e16c19706021ade598b Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Tue, 27 Aug 2024 17:06:55 +0200 Subject: [PATCH] BaseType/Fixup * fix totals query. Rather treat original query as subquery than trying to modify it * fixes queries utilizing HAVING and GROUP BY --- includes/basetype.class.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/includes/basetype.class.php b/includes/basetype.class.php index 39c40539..e9889fb7 100644 --- a/includes/basetype.class.php +++ b/includes/basetype.class.php @@ -277,8 +277,13 @@ abstract class BaseType { if ($calcTotal) { - $totalQuery = substr_replace($totalQuery, 'SELECT COUNT(*) ', 0, strpos($totalQuery, 'FROM')); - $this->matches += DB::{$n}($dbIdx)->selectCell($totalQuery); + // hackfix the inner items query to not contain duplicate column names + // yes i know the real solution would be to not have items and item_stats share column names + // soon™.... + if (get_class($this) == 'ItemList') + $totalQuery = str_replace([', `is`.*', ', i.id AS id'], '', $totalQuery); + + $this->matches += DB::{$n}($dbIdx)->selectCell('SELECT COUNT(*) FROM ('.$totalQuery.') x'); } foreach ($rows as $id => $row)