FIX Replace Object reference with Injector and use ModuleLoader to resolve schema location

This commit is contained in:
Robbie Averill 2017-11-16 10:12:08 +13:00
parent fc51d1a62e
commit 216613d746
3 changed files with 24 additions and 15 deletions

View File

@ -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'],

View File

@ -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, '/');
}
/**

View File

@ -1,9 +1,10 @@
<?php
namespace SilverStripe\FullTextSearch\Solr\Tasks;
use Monolog\Handler\StreamHandler;
use Psr\Log\LoggerInterface;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\BuildTask;
use Psr\Log\LoggerInterface;
use SilverStripe\FullTextSearch\Utils\Logging\SearchLogFactory;
/**
@ -21,13 +22,13 @@ class Solr_BuildTask extends BuildTask
protected $logger = null;
/**
* Get the current logger
* Get the monolog logger
*
* @return LoggerInterface
*/
public function getLogger()
{
return Injector::inst()->get(LoggerInterface::class);
return $this->logger;
}
/**