From bbdf79ea2b94d563faf7158d93bf94ff9baf8a61 Mon Sep 17 00:00:00 2001 From: elliot sawyer Date: Fri, 17 Feb 2017 16:27:38 +1300 Subject: [PATCH] WIP Silverstripe 4 compatibility fixes --- _config.php | 2 -- code/search/FullTextSearch.php | 2 ++ code/search/SearchIndex.php | 11 ++++++++--- code/search/SearchIntrospection.php | 18 ++++++++++-------- code/search/SearchVariant.php | 1 + code/solr/Solr.php | 27 +++++++++++++++++---------- code/solr/SolrIndex.php | 2 ++ 7 files changed, 40 insertions(+), 23 deletions(-) diff --git a/_config.php b/_config.php index c9e422a..3a5121a 100644 --- a/_config.php +++ b/_config.php @@ -2,5 +2,3 @@ global $databaseConfig; if (isset($databaseConfig['type'])) SearchUpdater::bind_manipulation_capture(); - -Deprecation::notification_version('1.0.0', 'fulltextsearch'); diff --git a/code/search/FullTextSearch.php b/code/search/FullTextSearch.php index 905a03c..636bbaa 100644 --- a/code/search/FullTextSearch.php +++ b/code/search/FullTextSearch.php @@ -1,5 +1,7 @@ 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)) { diff --git a/code/search/SearchIntrospection.php b/code/search/SearchIntrospection.php index e88aeac..389ed05 100644 --- a/code/search/SearchIntrospection.php +++ b/code/search/SearchIntrospection.php @@ -1,5 +1,7 @@ $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; } diff --git a/code/search/SearchVariant.php b/code/search/SearchVariant.php index df6e187..978e867 100644 --- a/code/search/SearchVariant.php +++ b/code/search/SearchVariant.php @@ -1,5 +1,6 @@ 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 diff --git a/code/solr/SolrIndex.php b/code/solr/SolrIndex.php index 49e1dc8..f74dbf1 100644 --- a/code/solr/SolrIndex.php +++ b/code/solr/SolrIndex.php @@ -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(