From 8927721ea66c2c7f746d6dbe04316202ddd43e10 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Thu, 2 Aug 2018 11:29:18 +1200 Subject: [PATCH] FIX Ensure alterQuery is compatible with silverstripe/fulltextsearch <3.3 --- src/Search/FluentSearchVariant.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Search/FluentSearchVariant.php b/src/Search/FluentSearchVariant.php index 19134369..508ba608 100644 --- a/src/Search/FluentSearchVariant.php +++ b/src/Search/FluentSearchVariant.php @@ -2,13 +2,13 @@ namespace TractorCow\Fluent\Search; +use SilverStripe\FullTextSearch\Search\Queries\SearchQuery; +use SilverStripe\FullTextSearch\Search\SearchIntrospection; +use SilverStripe\FullTextSearch\Search\Variants\SearchVariant; +use SilverStripe\ORM\DataObject; use TractorCow\Fluent\Extension\FluentExtension; -use TractorCow\Fluent\State\FluentState; use TractorCow\Fluent\Model\Locale; -use SilverStripe\ORM\DataObject; -use SilverStripe\FullTextSearch\Search\Variants\SearchVariant; -use SilverStripe\FullTextSearch\Search\SearchIntrospection; -use SilverStripe\FullTextSearch\Search\Queries\SearchQuery; +use TractorCow\Fluent\State\FluentState; if (!class_exists(SearchVariant::class)) { return; @@ -47,7 +47,9 @@ public function activateState($state) public function alterQuery($query, $index) { if (FluentState::singleton()->getIsFrontend() && Locale::getCached()->count()) { - $query->addFilter('_locale', [ + // Backwards compatibility for silverstripe/fulltextsearch 3.2/3.3 + $method = method_exists($query, 'addFilter') ? 'addFilter' : 'filter'; + $query->$method('_locale', [ $this->currentState(), SearchQuery::$missing ]);