Merge branch 'compat/4marco' into compat/4

This commit is contained in:
elliot sawyer 2017-04-26 20:58:14 +12:00
commit 6b58da3f9b
24 changed files with 108 additions and 67 deletions

View File

@ -1,4 +1,4 @@
Injector:
SilverStripe\Core\Injector\Injector:
RequestProcessor:
properties:
filters:

View File

@ -1,3 +1,3 @@
DataObject:
SilverStripe\ORM\DataObject\DataObject:
extensions:
- 'SearchUpdater_ObjectHandler'
- 'SilverStripe\FullTextSearch\Search\Updaters\SearchUpdater_ObjectHandler'

View File

@ -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

View File

@ -1,8 +1,11 @@
<?php
namespace SilverStripe\FullTextSearch\Search;
use ReflectionClass;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\ClassInfo;
use SilverStripe\FullTextSearch\Search\Indexes\SearchIndex;
/**
* Base class to manage active search indexes.
*/
@ -40,7 +43,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(SearchIndex::class);
$hidden = array();
$candidates = array();

View File

@ -2,9 +2,10 @@
namespace SilverStripe\FullTextSearch\Search\Indexes;
use Exception;
use InvalidArgumentException;
use SilverStripe\View\ViewableData;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DataObjectSchema;
use SilverStripe\Core\Object;
use SilverStripe\Core\ClassInfo;
use SilverStripe\FullTextSearch\Search\SearchIntrospection;
@ -303,7 +304,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);
}
}

View File

@ -2,7 +2,14 @@
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;
use SilverStripe\Core\Object;
/**
* This class is responsible for capturing changes to DataObjects and triggering index updates of the resulting dirty index
* items.
@ -15,8 +22,7 @@ use SilverStripe\ORM\DB;
*
* TODO: The way we bind in is awful hacky.
*/
use SilverStripe\Core\Object;
use SilverStripe\ORM\DataExtension;
class SearchUpdater extends Object
{
@ -27,7 +33,7 @@ class SearchUpdater extends Object
{
global $databaseConfig;
$current = DB::getConn();
$current = DB::get_conn();
if (!$current || !$current->currentDatabase() || @$current->isManipulationCapture) {
return;
} // If not yet set, or its already captured, just return

View File

@ -1,10 +1,4 @@
<?php
/**
* Created by PhpStorm.
* User: elliot
* Date: 21/04/17
* Time: 1:13 PM
*/
namespace SilverStripe\FullTextSearch\Search\Variants;

View File

@ -3,6 +3,8 @@ namespace SilverStripe\FullTextSearch\Solr;
use SilverStripe\Control\Director;
use SilverStripe\Core\Object;
use SilverStripe\FullTextSearch\Search\FullTextSearch;
use SolrIndex;
class Solr
{
@ -136,7 +138,7 @@ class Solr
public static function get_indexes()
{
return FullTextSearch::get_indexes('SolrIndex');
return FullTextSearch::get_indexes(SolrIndex::class);
}
/**
@ -156,4 +158,5 @@ class Solr
$included = true;
}
}
}
}

View File

@ -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;

View File

@ -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

View File

@ -2,6 +2,8 @@
namespace SilverStripe\FullTextSearch\Solr\Reindex\Jobs;
use Monolog\Logger;
use Psr\Log\LoggerInterface;
use SilverStripe\FullTextSearch\Utils\Logging\SearchLogFactory;
use SilverStripe\FullTextSearch\Solr\Reindex\Handlers\SolrReindexHandler;
if (!interface_exists('QueuedJob')) {
return;
@ -44,7 +46,7 @@ abstract class SolrReindexQueuedJobBase implements QueuedJob
*/
protected function getLoggerFactory()
{
return Injector::inst()->get('SearchLogFactory');
return Injector::inst()->get(SearchLogFactory::class);
}
/**
@ -103,7 +105,7 @@ abstract class SolrReindexQueuedJobBase implements QueuedJob
*/
protected function getHandler()
{
return Injector::inst()->get('SolrReindexHandler');
return Injector::inst()->get(SolrReindexHandler::class);
}
public function jobFinished()

View File

@ -3,5 +3,5 @@ namespace SilverStripe\FullTextSearch\Solr\Services;
class Solr3Service extends SolrService
{
private static $core_class = 'Solr3Service_Core';
private static $core_class = Solr3Service_Core::class;
}

View File

@ -3,5 +3,6 @@ namespace SilverStripe\FullTextSearch\Solr\Services;
class Solr4Service extends SolrService
{
private static $core_class = 'Solr4Service_Core';
private static $core_class = Solr4Service_Core::class;
}

View File

@ -44,7 +44,7 @@ class Solr4Service_Core extends SolrService_Core
$rawPost = "<add overwrite=\"{$overwriteVal}\"{$commitWithinString}>";
foreach ($documents as $document) {
if ($document instanceof Apache_Solr_Document) {
if ($document instanceof \Apache_Solr_Document) {
$rawPost .= $this->_documentToXmlFragment($document);
}
}

View File

@ -2,6 +2,7 @@
namespace SilverStripe\FullTextSearch\Solr\Services;
use SilverStripe\Core\Config\Config;
use SilverStripe\FullTextSearch\Solr\Solr;
Solr::include_client_api();
/**
* The API for accessing the primary Solr installation, which includes both SolrService_Core,
@ -10,7 +11,7 @@ Solr::include_client_api();
*/
class SolrService extends SolrService_Core
{
private static $core_class = 'SolrService_Core';
private static $core_class = SolrService_Core::class;
/**
* Handle encoding the GET parameters and making the HTTP call to execute a core command

View File

@ -1,10 +1,4 @@
<?php
/**
* Created by PhpStorm.
* User: elliot
* Date: 21/04/17
* Time: 12:45 PM
*/
namespace SilverStripe\FullTextSearch\Solr\Services;

View File

@ -1,6 +1,8 @@
<?php
namespace SilverStripe\FullTextSearch\Solr\Stores;
use SilverStripe\FullTextSearch\Solr\Solr;
use SilverStripe\FullTextSearch\Utils\WebDAV;
/**
* Class SolrConfigStore_WebDAV

View File

@ -1,6 +1,9 @@
<?php
namespace SilverStripe\FullTextSearch\Solr\Tasks;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Dev\BuildTask;
use Psr\Log\LoggerInterface;
use SilverStripe\FullTextSearch\Utils\Logging\SearchLogFactory;
/**
* Abstract class for build tasks
*/
@ -22,7 +25,9 @@ class Solr_BuildTask extends BuildTask
*/
public function getLogger()
{
return Injector::inst()->get('Logger');
//@todo left commented after a confusing merge conflict. Revisit if further testing is required
//return Injector::inst()->get('Logger');
return Injector::inst()->get(LoggerInterface::class);
}
/**
@ -40,7 +45,9 @@ class Solr_BuildTask extends BuildTask
*/
protected function getLoggerFactory()
{
// return Injector::inst()->get('SearchLogFactory');
//@todo left commented after a confusing merge conflict. Revisit if further testing is required
//return Injector::inst()->get('SearchLogFactory');
return Injector::inst()->get(SearchLogFactory::class);
}
/**
@ -55,9 +62,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);
}
}

View File

@ -1,9 +1,15 @@
<?php
namespace SilverStripe\FullTextSearch\Solr\Tasks;
use Exception;
use SilverStripe\Core\ClassInfo;
use SilverStripe\FullTextSearch\Solr\Solr;
use SilverStripe\FullTextSearch\Solr\Stores\SolrConfigStore_File;
use SilverStripe\FullTextSearch\Solr\Stores\SolrConfigStore_WebDAV;
use SilverStripe\FullTextSearch\Solr\Stores\SolrConfigStore;
class Solr_Configure extends Solr_BuildTask
{
private static $segment = 'Solr_Configure';
protected $enabled = true;
public function run($request)
@ -74,10 +80,13 @@ class Solr_Configure extends Solr_BuildTask
return new SolrConfigStore_File($indexstore);
} elseif ($mode == 'webdav') {
return new SolrConfigStore_WebDAV($indexstore);
} elseif (ClassInfo::exists($mode) && ClassInfo::classImplements($mode, 'SolrConfigStore')) {
//@todo left commented after confusing merge conflict. Revisit if further testing is required
//} elseif (ClassInfo::exists($mode) && ClassInfo::classImplements($mode, 'SolrConfigStore')) {
} elseif (ClassInfo::exists($mode) && ClassInfo::classImplements($mode, SolrConfigStore::class)) {
return new $mode($indexstore);
} else {
user_error('Unknown Solr index mode '.$indexstore['mode'], E_USER_ERROR);
}
}
}
}

View File

@ -1,5 +1,13 @@
<?php
namespace SilverStripe\FullTextSearch\Solr\Tasks;
use ReflectionClass;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\FullTextSearch\Search\Variants\SearchVariant;
use SilverStripe\ORM\DataList;
use SilverStripe\FullTextSearch\Solr\Reindex\Handlers\SolrReindexHandler;
use SilverStripe\FullTextSearch\Solr\SolrIndex;
/**
* Task used for both initiating a new reindex, as well as for processing incremental batches
* within a reindex.
@ -36,9 +44,12 @@ class Solr_Reindex extends Solr_BuildTask
*/
protected function getHandler()
{
//@todo: this needs to determine the best class from a Factory implementation
//@todo: it was 'SolrReindexHandler' but that doesn't work on 4.0
return Injector::inst()->get('SolrReindexImmediateHandler');
//@todo left commented after a confusing merge conflict. Revisit if further investigation /testing is needed
//return Injector::inst()->get('SolrReindexImmediateHandler');
return Injector::inst()->get(SolrReindexHandler::class);
}
/**
@ -67,7 +78,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(SolrIndex::class) as $solrIndexClass) {
$reflection = new ReflectionClass($solrIndexClass);
//skip over abstract classes
if (!$reflection->isInstantiable()) {

View File

@ -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

View File

@ -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: <basefolder>/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: <basefolder>/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: <basefolder>/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: <basefolder>/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
)
));

View File

@ -4,6 +4,7 @@ use SilverStripe\Dev\SapphireTest;
use SilverStripe\FullTextSearch\Search\FullTextSearch;
use SilverStripe\FullTextSearch\Tests\SolrReindexTest\SolrReindexTest_Variant;
use SilverStripe\FullTextSearch\Solr\Reindex\Handlers\SolrReindexHandler;
/**
* Additional tests of solr reindexing processes when run with queuedjobs
@ -106,7 +107,7 @@ class SolrReindexQueuedTest extends SapphireTest
*/
protected function getHandler()
{
return Injector::inst()->get('SolrReindexHandler');
return Injector::inst()->get(SolrReindexHandler::class);
}
/**
@ -158,7 +159,7 @@ class SolrReindexQueuedTest extends SapphireTest
$this->assertEquals(3, $logger->countMessages(' of SolrReindexTest_Item in {"SolrReindexTest_Variant":"1"}'));
$this->assertEquals(1, $logger->countMessages('Completed init of reindex'));
// Test that invalid classes are removed
$this->assertNotEmpty($logger->getMessages('Clearing obsolete classes from SolrReindexTest_Index'));
Phockito::verify($this->service, 1)

View File

@ -4,6 +4,7 @@ use SilverStripe\Dev\SapphireTest;
use SilverStripe\FullTextSearch\Search\FullTextSearch;
use SilverStripe\FullTextSearch\Tests\SolrReindexTest\SolrReindexTest_Variant;
use SilverStripe\FullTextSearch\Solr\Reindex\Handlers\SolrReindexHandler;
if (class_exists('Phockito')) {
Phockito::include_hamcrest(false);
@ -102,7 +103,7 @@ class SolrReindexTest extends SapphireTest
*/
protected function getHandler()
{
return Injector::inst()->get('SolrReindexHandler');
return Injector::inst()->get(SolrReindexHandler::class);
}
/**