From 216613d74666e058a81a159be21283838185a49c Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Thu, 16 Nov 2017 10:12:08 +1300 Subject: [PATCH] FIX Replace Object reference with Injector and use ModuleLoader to resolve schema location --- code/solr/Solr.php | 29 ++++++++++++++++++----------- code/solr/SolrIndex.php | 3 ++- code/solr/tasks/Solr_BuildTask.php | 7 ++++--- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/code/solr/Solr.php b/code/solr/Solr.php index 2ccb21f..9947014 100644 --- a/code/solr/Solr.php +++ b/code/solr/Solr.php @@ -3,6 +3,9 @@ namespace SilverStripe\FullTextSearch\Solr; use SilverStripe\Control\Director; +use SilverStripe\Core\Injector\Injector; +use SilverStripe\Core\Manifest\Module; +use SilverStripe\Core\Manifest\ModuleLoader; use SilverStripe\FullTextSearch\Search\FullTextSearch; use SilverStripe\FullTextSearch\Solr\Services\Solr4Service; use SilverStripe\FullTextSearch\Solr\Services\Solr3Service; @@ -79,18 +82,22 @@ class Solr // Build some by-version defaults $version = isset(self::$solr_options['version']) ? self::$solr_options['version'] : $defaults['version']; + /** @var Module $module */ + $module = ModuleLoader::getModule('silverstripe/fulltextsearch'); + $modulePath = $module->getPath(); + if (version_compare($version, '4', '>=')) { - $versionDefaults = array( - 'service' => Solr4Service::class, - 'extraspath' => Director::baseFolder().'/fulltextsearch/conf/solr/4/extras/', - 'templatespath' => Director::baseFolder().'/fulltextsearch/conf/solr/4/templates/', - ); + $versionDefaults = [ + 'service' => Solr4Service::class, + 'extraspath' => $modulePath . '/conf/solr/4/extras/', + 'templatespath' => $modulePath . '/conf/solr/4/templates/', + ]; } else { - $versionDefaults = array( - 'service' => Solr3Service::class, - 'extraspath' => Director::baseFolder().'/fulltextsearch/conf/solr/3/extras/', - 'templatespath' => Director::baseFolder().'/fulltextsearch/conf/solr/3/templates/', - ); + $versionDefaults = [ + 'service' => Solr3Service::class, + 'extraspath' => $modulePath . '/conf/solr/3/extras/', + 'templatespath' => $modulePath . '/conf/solr/3/templates/', + ]; } return (self::$merged_solr_options = array_merge($defaults, $versionDefaults, self::$solr_options)); @@ -119,7 +126,7 @@ class Solr $options = self::solr_options(); if (!self::$service_singleton) { - self::$service_singleton = Object::create( + self::$service_singleton = Injector::inst()->create( $options['service'], $options['host'], $options['port'], diff --git a/code/solr/SolrIndex.php b/code/solr/SolrIndex.php index c23cb06..2c69992 100644 --- a/code/solr/SolrIndex.php +++ b/code/solr/SolrIndex.php @@ -82,7 +82,8 @@ abstract class SolrIndex extends SearchIndex public function getTemplatesPath() { $globalOptions = Solr::solr_options(); - return $this->templatesPath ? $this->templatesPath : $globalOptions['templatespath']; + $path = $this->templatesPath ? $this->templatesPath : $globalOptions['templatespath']; + return rtrim($path, '/'); } /** diff --git a/code/solr/tasks/Solr_BuildTask.php b/code/solr/tasks/Solr_BuildTask.php index 578f1e0..f9c24ec 100644 --- a/code/solr/tasks/Solr_BuildTask.php +++ b/code/solr/tasks/Solr_BuildTask.php @@ -1,9 +1,10 @@ get(LoggerInterface::class); + return $this->logger; } /**