From 851309f187b1ebcd6dc12b79e63ea31f00190b27 Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Fri, 24 Nov 2017 22:15:55 +0000 Subject: [PATCH 1/2] Fix PostgreSQLDatabase::searchEngine() --- code/PostgreSQLDatabase.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/code/PostgreSQLDatabase.php b/code/PostgreSQLDatabase.php index b5a2508..7cb604b 100644 --- a/code/PostgreSQLDatabase.php +++ b/code/PostgreSQLDatabase.php @@ -352,16 +352,13 @@ class PostgreSQLDatabase extends SS_Database { if($keywords) $orderBy = " ORDER BY $sortBy"; else $orderBy=''; - $fullQuery = "SELECT * FROM (" . implode(" UNION ", $tables) . ") AS q1 $orderBy LIMIT $limit OFFSET $offset"; - - // Get the total items in this search - $totalItemsQuery = "SELECT COUNT(*) AS totalitems FROM (" . implode(" UNION ", $tables) . ") AS q1"; - $totalCount = DB::query($totalItemsQuery); + $fullQuery = "SELECT *, count(*) OVER() as _fullcount FROM (" . implode(" UNION ", $tables) . ") AS q1 $orderBy LIMIT $limit OFFSET $offset"; // Get records $records = $this->preparedQuery($fullQuery, $tableParameters); foreach($records as $record){ - $objects[] = new $record['ClassName']($record); + $objects[] = Injector::inst()->createWithArgs($record['ClassName'], array($record)); + $totalCount = $record['_fullcount']; } if(isset($objects)) $results = new ArrayList($objects); @@ -370,7 +367,7 @@ class PostgreSQLDatabase extends SS_Database { $list->setLimitItems(false); $list->setPageStart($start); $list->setPageLength($pageLength); - $list->setTotalItems($totalCount->value()); + $list->setTotalItems($totalCount); return $list; } From 390cb0992819a566f7cbaa2c489a0e4d93f0c5d4 Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Sat, 25 Nov 2017 21:40:01 +0000 Subject: [PATCH 2/2] FIX: Add missing $totalCount variable --- code/PostgreSQLDatabase.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/code/PostgreSQLDatabase.php b/code/PostgreSQLDatabase.php index 7cb604b..36495e0 100644 --- a/code/PostgreSQLDatabase.php +++ b/code/PostgreSQLDatabase.php @@ -356,6 +356,8 @@ class PostgreSQLDatabase extends SS_Database { // Get records $records = $this->preparedQuery($fullQuery, $tableParameters); + + $totalCount = 0; foreach($records as $record){ $objects[] = Injector::inst()->createWithArgs($record['ClassName'], array($record)); $totalCount = $record['_fullcount'];