From 8228c762c9ec774d7fbed8408a9b26af5c526348 Mon Sep 17 00:00:00 2001 From: Marco Hermo Date: Sun, 23 Apr 2017 06:21:06 +1200 Subject: [PATCH] Explicit namespace definition on YAML files --- _config/binding.yml | 2 +- _config/config.yml | 4 +-- _config/processor.yml | 34 +++++++++---------- code/search/FullTextSearch.php | 3 +- code/search/indexes/SearchIndex.php | 4 ++- code/search/updaters/SearchUpdater.php | 5 +++ code/solr/Solr.php | 3 +- .../solr/reindex/handlers/SolrReindexBase.php | 1 + .../handlers/SolrReindexImmediateHandler.php | 3 ++ .../reindex/jobs/SolrReindexQueuedJobBase.php | 4 +-- code/solr/services/Solr3Service.php | 2 +- code/solr/services/Solr4Service.php | 2 +- code/solr/services/Solr4Service_Core.php | 2 +- code/solr/services/SolrService.php | 2 +- code/solr/stores/SolrConfigStore_WebDAV.php | 4 +++ code/solr/tasks/Solr_BuildTask.php | 12 ++++--- code/solr/tasks/Solr_Configure.php | 8 ++++- code/solr/tasks/Solr_Reindex.php | 13 ++++--- code/utils/logging/MonologFactory.php | 2 ++ docs/en/Solr.md | 16 ++++----- tests/SolrReindexQueuedTest.php | 2 +- tests/SolrReindexTest.php | 2 +- 22 files changed, 81 insertions(+), 49 deletions(-) diff --git a/_config/binding.yml b/_config/binding.yml index 5f1cfd2..14702a3 100644 --- a/_config/binding.yml +++ b/_config/binding.yml @@ -1,4 +1,4 @@ -Injector: +SilverStripe\Core\Injector\Injector: RequestProcessor: properties: filters: diff --git a/_config/config.yml b/_config/config.yml index 7193cb2..86f8423 100644 --- a/_config/config.yml +++ b/_config/config.yml @@ -1,3 +1,3 @@ -DataObject: +SilverStripe\ORM\DataObject\DataObject: extensions: - - 'SearchUpdater_ObjectHandler' + - 'SilverStripe\FullTextSearch\Search\Updaters\SearchUpdater_ObjectHandler' diff --git a/_config/processor.yml b/_config/processor.yml index 430ec5e..fbd4b3e 100644 --- a/_config/processor.yml +++ b/_config/processor.yml @@ -1,13 +1,13 @@ --- Name: defaultprocessor --- -Injector: - SearchUpdateProcessor: - class: SearchUpdateImmediateProcessor - SolrReindexHandler: - class: SolrReindexImmediateHandler - SearchLogFactory: - class: 'MonologFactory' +SilverStripe\Core\Injector\Injector: + SilverStripe\FullTextSearch\Search\Processors\SearchUpdateProcessor: + class: SilverStripe\FullTextSearch\Search\Processors\SearchUpdateImmediateProcessor + SilverStripe\FullTextSearch\Solr\Reindex\Handlers\SolrReindexHandler: + class: SilverStripe\FullTextSearch\Solr\Reindex\Handlers\SolrReindexImmediateHandler + SilverStripe\FullTextSearch\Utils\Logging\SearchLogFactory: + class: 'SilverStripe\FullTextSearch\Utils\Logging\MonologFactory' --- Name: messagequeueprocessor Only: @@ -15,11 +15,11 @@ Only: Except: Environment: 'dev' --- -Injector: - SearchUpdateProcessor: - class: SearchUpdateMessageQueueProcessor - SolrReindexHandler: - class: SolrReindexMessageHandler +SilverStripe\Core\Injector\Injector: + SilverStripe\FullTextSearch\Search\Processors\SearchUpdateProcessor: + class: SilverStripe\FullTextSearch\Search\Processors\SearchUpdateMessageQueueProcessor + SilverStripe\FullTextSearch\Solr\Reindex\Handlers\SolrReindexHandler: + class: SilverStripe\FullTextSearch\Solr\Reindex\Handlers\SolrReindexMessageHandler --- Name: queuedjobprocessor Only: @@ -27,8 +27,8 @@ Only: Except: Environment: 'dev' --- -Injector: - SearchUpdateProcessor: - class: SearchUpdateQueuedJobProcessor - SolrReindexHandler: - class: SolrReindexQueuedHandler +SilverStripe\Core\Injector\Injector: + SilverStripe\FullTextSearch\Search\Processors\SearchUpdateProcessor: + class: SilverStripe\FullTextSearch\Search\Processors\SearchUpdateQueuedJobProcessor + SilverStripe\FullTextSearch\Solr\Reindex\Handlers\SolrReindexHandler: + class: SilverStripe\FullTextSearch\Solr\Reindex\Handlers\SolrReindexQueuedHandler diff --git a/code/search/FullTextSearch.php b/code/search/FullTextSearch.php index b419d25..bebe9fd 100644 --- a/code/search/FullTextSearch.php +++ b/code/search/FullTextSearch.php @@ -2,6 +2,7 @@ namespace SilverStripe\FullTextSearch\Search; +use ReflectionClass; use SilverStripe\Core\Config\Config; use SilverStripe\Core\ClassInfo; /** @@ -41,7 +42,7 @@ class FullTextSearch if (self::$all_indexes === null) { // Get declared indexes, or otherwise default to all subclasses of SearchIndex $classes = Config::inst()->get(__CLASS__, 'indexes') - ?: ClassInfo::subclassesFor('SearchIndex'); + ?: ClassInfo::subclassesFor('SilverStripe\FullTextSearch\Solr\SearchIndex'); $hidden = array(); $candidates = array(); diff --git a/code/search/indexes/SearchIndex.php b/code/search/indexes/SearchIndex.php index 2e1750d..bd75ab5 100644 --- a/code/search/indexes/SearchIndex.php +++ b/code/search/indexes/SearchIndex.php @@ -2,6 +2,8 @@ namespace SilverStripe\FullTextSearch\Search\Indexes; +use Exception; +use InvalidArgumentException; use SilverStripe\View\ViewableData; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObjectSchema; @@ -303,7 +305,7 @@ abstract class SearchIndex extends ViewableData $type = $match[1]; } list($type, $args) = Object::parse_class_spec($type); - if (is_subclass_of($type, 'StringField')) { + if (is_subclass_of($type, 'SilverStripe\ORM\FieldType\DBString')) { $this->addFulltextField($field); } } diff --git a/code/search/updaters/SearchUpdater.php b/code/search/updaters/SearchUpdater.php index b4460c3..5a1699b 100644 --- a/code/search/updaters/SearchUpdater.php +++ b/code/search/updaters/SearchUpdater.php @@ -2,7 +2,12 @@ namespace SilverStripe\FullTextSearch\Search\Updaters; +use SilverStripe\Dev\SapphireTest; +use SilverStripe\FullTextSearch\Search\FullTextSearch; +use SilverStripe\FullTextSearch\Search\SearchIntrospection; +use SilverStripe\FullTextSearch\Search\Variants\SearchVariant; use SilverStripe\ORM\DB; +use SilverStripe\Core\ClassInfo; /** * This class is responsible for capturing changes to DataObjects and triggering index updates of the resulting dirty index * items. diff --git a/code/solr/Solr.php b/code/solr/Solr.php index 98d3972..8fe496d 100644 --- a/code/solr/Solr.php +++ b/code/solr/Solr.php @@ -3,6 +3,7 @@ namespace SilverStripe\FullTextSearch\Solr; use SilverStripe\Control\Director; use SilverStripe\Core\Object; +use SilverStripe\FullTextSearch\Search\FullTextSearch; class Solr { @@ -136,7 +137,7 @@ class Solr public static function get_indexes() { - return FullTextSearch::get_indexes('SolrIndex'); + return FullTextSearch::get_indexes('SilverStripe\FullTextSearch\Solr\SolrIndex'); } /** diff --git a/code/solr/reindex/handlers/SolrReindexBase.php b/code/solr/reindex/handlers/SolrReindexBase.php index f127537..0afea23 100644 --- a/code/solr/reindex/handlers/SolrReindexBase.php +++ b/code/solr/reindex/handlers/SolrReindexBase.php @@ -3,6 +3,7 @@ namespace SilverStripe\FullTextSearch\Solr\Reindex\Handlers; use Psr\Log\LoggerInterface; +use SilverStripe\FullTextSearch\Search\Variants\SearchVariant; use SilverStripe\FullTextSearch\Solr\Solr; use SilverStripe\FullTextSearch\Solr\SolrIndex; diff --git a/code/solr/reindex/handlers/SolrReindexImmediateHandler.php b/code/solr/reindex/handlers/SolrReindexImmediateHandler.php index c0c48bb..b67a33f 100644 --- a/code/solr/reindex/handlers/SolrReindexImmediateHandler.php +++ b/code/solr/reindex/handlers/SolrReindexImmediateHandler.php @@ -3,7 +3,10 @@ namespace SilverStripe\FullTextSearch\Solr\Reindex\Handlers; use Psr\Log\LoggerInterface; +use SilverStripe\Control\Director; +use SilverStripe\FullTextSearch\Solr\Solr; use SilverStripe\FullTextSearch\Solr\SolrIndex; +use SilverStripe\ORM\DB; /** * Invokes an immediate reindex diff --git a/code/solr/reindex/jobs/SolrReindexQueuedJobBase.php b/code/solr/reindex/jobs/SolrReindexQueuedJobBase.php index 3d5903e..e1cb64b 100644 --- a/code/solr/reindex/jobs/SolrReindexQueuedJobBase.php +++ b/code/solr/reindex/jobs/SolrReindexQueuedJobBase.php @@ -44,7 +44,7 @@ abstract class SolrReindexQueuedJobBase implements QueuedJob */ protected function getLoggerFactory() { - return Injector::inst()->get('SearchLogFactory'); + return Injector::inst()->get('SilverStripe\FullTextSearch\Utils\Logging\SearchLogFactory'); } /** @@ -103,7 +103,7 @@ abstract class SolrReindexQueuedJobBase implements QueuedJob */ protected function getHandler() { - return Injector::inst()->get('SolrReindexHandler'); + return Injector::inst()->get('SilverStripe\FullTextSearch\Solr\Reindex\Handlers\SolrReindexHandler'); } public function jobFinished() diff --git a/code/solr/services/Solr3Service.php b/code/solr/services/Solr3Service.php index f2546a6..d540de2 100644 --- a/code/solr/services/Solr3Service.php +++ b/code/solr/services/Solr3Service.php @@ -3,5 +3,5 @@ namespace SilverStripe\FullTextSearch\Solr\Services; class Solr3Service extends SolrService { - private static $core_class = 'Solr3Service_Core'; + private static $core_class = 'SilverStripe\FullTextSearch\Solr\Services\Solr3Service'; } diff --git a/code/solr/services/Solr4Service.php b/code/solr/services/Solr4Service.php index ea69e77..9dc3346 100644 --- a/code/solr/services/Solr4Service.php +++ b/code/solr/services/Solr4Service.php @@ -3,5 +3,5 @@ namespace SilverStripe\FullTextSearch\Solr\Services; class Solr4Service extends SolrService { - private static $core_class = 'Solr4Service_Core'; + private static $core_class = 'SilverStripe\FullTextSearch\Solr\Services\Solr4Service'; } diff --git a/code/solr/services/Solr4Service_Core.php b/code/solr/services/Solr4Service_Core.php index bdde99a..056c658 100644 --- a/code/solr/services/Solr4Service_Core.php +++ b/code/solr/services/Solr4Service_Core.php @@ -44,7 +44,7 @@ class Solr4Service_Core extends SolrService_Core $rawPost = ""; foreach ($documents as $document) { - if ($document instanceof Apache_Solr_Document) { + if ($document instanceof \Apache_Solr_Document) { $rawPost .= $this->_documentToXmlFragment($document); } } diff --git a/code/solr/services/SolrService.php b/code/solr/services/SolrService.php index 6aae39b..a7f53d5 100644 --- a/code/solr/services/SolrService.php +++ b/code/solr/services/SolrService.php @@ -10,7 +10,7 @@ Solr::include_client_api(); */ class SolrService extends SolrService_Core { - private static $core_class = 'SolrService_Core'; + private static $core_class = 'SilverStripe\FullTextSearch\Solr\Services\SolrService'; /** * Handle encoding the GET parameters and making the HTTP call to execute a core command diff --git a/code/solr/stores/SolrConfigStore_WebDAV.php b/code/solr/stores/SolrConfigStore_WebDAV.php index 96259cb..037821e 100644 --- a/code/solr/stores/SolrConfigStore_WebDAV.php +++ b/code/solr/stores/SolrConfigStore_WebDAV.php @@ -2,6 +2,10 @@ namespace SilverStripe\FullTextSearch\Solr\Stores; +use SilverStripe\FullTextSearch\Solr\Solr; +use SilverStripe\FullTextSearch\Utils\WebDAV; + + /** * Class SolrConfigStore_WebDAV * diff --git a/code/solr/tasks/Solr_BuildTask.php b/code/solr/tasks/Solr_BuildTask.php index d26f647..fa06e23 100644 --- a/code/solr/tasks/Solr_BuildTask.php +++ b/code/solr/tasks/Solr_BuildTask.php @@ -1,6 +1,9 @@ get('Logger'); + return Injector::inst()->get('Psr\Log\LoggerInterface'); } /** @@ -40,7 +43,7 @@ class Solr_BuildTask extends BuildTask */ protected function getLoggerFactory() { -// return Injector::inst()->get('SearchLogFactory'); + return Injector::inst()->get('SilverStripe\FullTextSearch\Utils\Logging\SearchLogFactory'); } /** @@ -55,9 +58,8 @@ class Solr_BuildTask extends BuildTask // Set new logger $logger = $this - ->getLoggerFactory(); -//@todo: Cannot instantiate interface SearchLogFactory -// ->getOutputLogger($name, $verbose); + ->getLoggerFactory() + ->getOutputLogger($name, $verbose); $this->setLogger($logger); } } diff --git a/code/solr/tasks/Solr_Configure.php b/code/solr/tasks/Solr_Configure.php index 8989f9c..31471fe 100644 --- a/code/solr/tasks/Solr_Configure.php +++ b/code/solr/tasks/Solr_Configure.php @@ -1,5 +1,11 @@ get('SolrReindexImmediateHandler'); + return Injector::inst()->get('SilverStripe\FullTextSearch\Solr\Reindex\Handlers\SolrReindexHandler'); } /** @@ -65,7 +70,7 @@ class Solr_Reindex extends Solr_BuildTask // this is for when index names do not match the class name (this can be done by overloading getIndexName() on // indexes if ($index && !ClassInfo::exists($index)) { - foreach(ClassInfo::subclassesFor('SolrIndex') as $solrIndexClass) { + foreach(ClassInfo::subclassesFor('SilverStripe\FullTextSearch\Solr\SolrIndex') as $solrIndexClass) { $reflection = new ReflectionClass($solrIndexClass); //skip over abstract classes if (!$reflection->isInstantiable()) { diff --git a/code/utils/logging/MonologFactory.php b/code/utils/logging/MonologFactory.php index bff773f..d92b4bf 100644 --- a/code/utils/logging/MonologFactory.php +++ b/code/utils/logging/MonologFactory.php @@ -4,6 +4,8 @@ use Monolog\Formatter\FormatterInterface; use Monolog\Formatter\LineFormatter; use Monolog\Handler\HandlerInterface; use Monolog\Logger; +use SilverStripe\Core\Injector\Injector; +use SilverStripe\Control\Director; /** * Provides logging based on monolog diff --git a/docs/en/Solr.md b/docs/en/Solr.md index 89e22bb..a5e1773 100644 --- a/docs/en/Solr.md +++ b/docs/en/Solr.md @@ -56,16 +56,16 @@ All possible parameters incl optional ones with example values: Solr::configure_server(array( 'host' => 'localhost', // default: localhost | The host or IP Solr is listening on 'port' => '8983', // default: 8983 | The port Solr is listening on - 'path' => '/solr' // default: /solr | The suburl the solr service is available on - 'version' => '4' // default: 4 | Solr server version - currently only 3 and 4 supported - 'service' => 'Solr4Service' // default: depends on version, Solr3Service for 3, Solr4Service for 4 | the class that provides actual communcation to the Solr server - 'extraspath' => BASE_PATH .'/fulltextsearch/conf/solr/4/extras/' // default: /fulltextsearch/conf/solr/{version}/extras/ | Absolute path to the folder containing templates which are used for generating the schema and field definitions. - 'templates' => BASE_PATH . '/fulltextsearch/conf/solr/4/templates/' // default: /fulltextsearch/conf/solr/{version}/templates/ | Absolute path to the configuration default files, e.g. solrconfig.xml + 'path' => '/solr', // default: /solr | The suburl the solr service is available on + 'version' => '4', // default: 4 | Solr server version - currently only 3 and 4 supported + 'service' => 'Solr4Service', // default: depends on version, Solr3Service for 3, Solr4Service for 4 | the class that provides actual communcation to the Solr server + 'extraspath' => BASE_PATH .'/fulltextsearch/conf/solr/4/extras/', // default: /fulltextsearch/conf/solr/{version}/extras/ | Absolute path to the folder containing templates which are used for generating the schema and field definitions. + 'templates' => BASE_PATH . '/fulltextsearch/conf/solr/4/templates/', // default: /fulltextsearch/conf/solr/{version}/templates/ | Absolute path to the configuration default files, e.g. solrconfig.xml 'indexstore' => array( 'mode' => 'file', // a classname which implements SolrConfigStore, or 'file' or 'webdav' - 'path' => BASE_PATH . '/.solr' // The (locally accessible) path to write the index configurations to OR The suburl on the solr host that is set up to accept index configurations via webdav - 'remotepath' => '/opt/solr/config' // default (file mode only): same as 'path' above | The path that the Solr server will read the index configurations from - 'auth' => 'solr:solr' // default: none | Webdav only - A username:password pair string to use to auth against the webdav server + 'path' => BASE_PATH . '/.solr', // The (locally accessible) path to write the index configurations to OR The suburl on the solr host that is set up to accept index configurations via webdav + 'remotepath' => '/opt/solr/config', // default (file mode only): same as 'path' above | The path that the Solr server will read the index configurations from + 'auth' => 'solr:solr', // default: none | Webdav only - A username:password pair string to use to auth against the webdav server 'port' => '80' // default: same as solr port | The port for WebDAV if different from the Solr port ) )); diff --git a/tests/SolrReindexQueuedTest.php b/tests/SolrReindexQueuedTest.php index ed7aa0c..1baf385 100644 --- a/tests/SolrReindexQueuedTest.php +++ b/tests/SolrReindexQueuedTest.php @@ -106,7 +106,7 @@ class SolrReindexQueuedTest extends SapphireTest */ protected function getHandler() { - return Injector::inst()->get('SolrReindexHandler'); + return Injector::inst()->get('SilverStripe\FullTextSearch\Solr\Reindex\Handlers\SolrReindexHandler'); } /** diff --git a/tests/SolrReindexTest.php b/tests/SolrReindexTest.php index 1c2c2a6..6338e35 100644 --- a/tests/SolrReindexTest.php +++ b/tests/SolrReindexTest.php @@ -102,7 +102,7 @@ class SolrReindexTest extends SapphireTest */ protected function getHandler() { - return Injector::inst()->get('SolrReindexHandler'); + return Injector::inst()->get('SilverStripe\FullTextSearch\Solr\Reindex\Handlers\SolrReindexHandler'); } /**