WIP Silverstripe 4 compatibility fixes

This commit is contained in:
elliot sawyer 2017-02-17 16:27:38 +13:00
parent 6fbb25abb1
commit bbdf79ea2b
7 changed files with 40 additions and 23 deletions

View File

@ -2,5 +2,3 @@
global $databaseConfig;
if (isset($databaseConfig['type'])) SearchUpdater::bind_manipulation_capture();
Deprecation::notification_version('1.0.0', 'fulltextsearch');

View File

@ -1,5 +1,7 @@
<?php
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\ClassInfo;
/**
* Base class to manage active search indexes.
*/

View File

@ -1,5 +1,10 @@
<?php
use SilverStripe\View\ViewableData;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DataObjectSchema;
use SilverStripe\Core\Object;
use SilverStripe\Core\ClassInfo;
/**
* SearchIndex is the base index class. Each connector will provide a subclass of this that
* provides search engine specific behavior.
@ -130,7 +135,7 @@ abstract class SearchIndex extends ViewableData
$type = null;
$fieldoptions = $options;
$fields = DataObject::database_fields($dataclass);
$fields = DataObject::getSchema()->databaseFields($class);
if (isset($fields[$field])) {
$type = $fields[$field];
@ -209,7 +214,7 @@ abstract class SearchIndex extends ViewableData
throw new Exception('Can\'t add class to Index after fields have already been added');
}
if (!DataObject::has_own_table($class)) {
if (!DataObject::getSchema()->classHasTable($class)) {
throw new InvalidArgumentException('Can\'t add classes which don\'t have data tables (no $db or $has_one set on the class)');
}
@ -286,7 +291,7 @@ abstract class SearchIndex extends ViewableData
{
foreach ($this->getClasses() as $class => $options) {
foreach (SearchIntrospection::hierarchy($class, $includeSubclasses, true) as $dataclass) {
$fields = DataObject::database_fields($dataclass);
$fields = DataObject::getSchema()->databaseFields($class);
foreach ($fields as $field => $type) {
if (preg_match('/^(\w+)\(/', $type, $match)) {

View File

@ -1,5 +1,7 @@
<?php
use SilverStripe\Core\ClassInfo;
use SilverStripe\ORM\DataObject;
/**
* Some additional introspection tools that are used often by the fulltext search code
*/
@ -45,14 +47,14 @@ class SearchIntrospection
if ($idx !== false) {
array_splice($classes, 0, $idx+1);
}
if ($dataOnly) {
foreach ($classes as $i => $class) {
if (!DataObject::has_own_table($class)) {
unset($classes[$i]);
}
}
}
//@todo find another way to determine if a dataobject does not have a table
// if ($dataOnly) {
// foreach ($classes as $i => $class) {
// if (!DataObject::has_own_table($class)) {
// unset($classes[$i]);
// }
// }
// }
self::$hierarchy[$key] = $classes;
}

View File

@ -1,5 +1,6 @@
<?php
use SilverStripe\Core\ClassInfo;
/**
* A Search Variant handles decorators and other situations where the items to reindex or search through are modified
* from the default state - for instance, dealing with Versioned or Subsite

View File

@ -4,6 +4,11 @@ use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Psr\Log\LoggerInterface;
use SilverStripe\Dev\BuildTask;
use SilverStripe\Control\Director;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Object;
class Solr
{
@ -179,7 +184,7 @@ class Solr_BuildTask extends BuildTask
*/
public function getLogger()
{
return $this->logger;
return Injector::inst()->get('Logger');
}
/**
@ -197,7 +202,7 @@ class Solr_BuildTask extends BuildTask
*/
protected function getLoggerFactory()
{
return Injector::inst()->get('SearchLogFactory');
// return Injector::inst()->get('SearchLogFactory');
}
/**
@ -212,8 +217,9 @@ class Solr_BuildTask extends BuildTask
// Set new logger
$logger = $this
->getLoggerFactory()
->getOutputLogger($name, $verbose);
->getLoggerFactory();
//@todo: Cannot instantiate interface SearchLogFactory
// ->getOutputLogger($name, $verbose);
$this->setLogger($logger);
}
}
@ -229,6 +235,7 @@ class Solr_Configure extends Solr_BuildTask
// Find the IndexStore handler, which will handle uploading config files to Solr
$store = $this->getSolrConfigStore();
$indexes = Solr::get_indexes();
foreach ($indexes as $instance) {
try {
@ -251,23 +258,23 @@ class Solr_Configure extends Solr_BuildTask
protected function updateIndex($instance, $store)
{
$index = $instance->getIndexName();
$this->getLogger()->info("Configuring $index.");
$this->getLogger()->addInfo("Configuring $index.");
// Upload the config files for this index
$this->getLogger()->info("Uploading configuration ...");
$this->getLogger()->addInfo("Uploading configuration ...");
$instance->uploadConfig($store);
// Then tell Solr to use those config files
$service = Solr::service();
if ($service->coreIsActive($index)) {
$this->getLogger()->info("Reloading core ...");
$this->getLogger()->addInfo("Reloading core ...");
$service->coreReload($index);
} else {
$this->getLogger()->info("Creating core ...");
$this->getLogger()->addInfo("Creating core ...");
$service->coreCreate($index, $store->instanceDir($index));
}
$this->getLogger()->info("Done");
$this->getLogger()->addInfo("Done");
}
/**
@ -280,7 +287,7 @@ class Solr_Configure extends Solr_BuildTask
$options = Solr::solr_options();
if (!isset($options['indexstore']) || !($indexstore = $options['indexstore'])) {
user_error('No index configuration for Solr provided', E_USER_ERROR);
throw new Exception('No index configuration for Solr provided', E_USER_ERROR);
}
// Find the IndexStore handler, which will handle uploading config files to Solr

View File

@ -2,6 +2,8 @@
Solr::include_client_api();
use SilverStripe\Dev\BuildTask;
use SilverStripe\Control\Director;
abstract class SolrIndex extends SearchIndex
{
public static $fulltextTypeMap = array(