diff --git a/config/schema/search_api.tracker.schema.yml b/config/schema/search_api.tracker.schema.yml index 297badc..1cb3518 100644 --- a/config/schema/search_api.tracker.schema.yml +++ b/config/schema/search_api.tracker.schema.yml @@ -1,4 +1,3 @@ -# @todo Update the key when https://www.drupal.org/node/2291073 is fixed. plugin.plugin_configuration.search_api_tracker.default: type: sequence label: 'Entity tracker configuration' diff --git a/src/Entity/Index.php b/src/Entity/Index.php index 954db69..b58744b 100644 --- a/src/Entity/Index.php +++ b/src/Entity/Index.php @@ -19,7 +19,6 @@ use Drupal\search_api\Query\QueryInterface; use Drupal\search_api\Query\ResultSetInterface; use Drupal\search_api\SearchApiException; use Drupal\search_api\ServerInterface; -use Drupal\search_api\Tracker\TrackerInterface; use Drupal\search_api\Utility; use Drupal\user\TempStoreException; use Drupal\views\Views; @@ -361,12 +360,7 @@ class Index extends ConfigEntityBase implements IndexInterface { * {@inheritdoc} */ public function getTrackerId() { - $settings = $this->getTrackerSettings(); - if (!$settings) { - return \Drupal::config('search_api.settings')->get('default_tracker'); - } - $tracker_settings = reset($settings); - return $tracker_settings['plugin_id']; + return $this->getTrackerInstance()->getConfiguration()['plugin_id']; } /** @@ -374,14 +368,14 @@ class Index extends ConfigEntityBase implements IndexInterface { */ public function getTrackerInstance() { if (!$this->trackerInstance) { - if ($this->getTrackerSettings() === array()) { + if ($this->tracker_settings === array()) { $tracker_settings = array( 'settings' => array(), 'plugin_id' => $this->getTrackerId(), ); } else { - $tracker_settings = $this->getTrackerSettings()[$this->getTrackerId()]; + $tracker_settings = $this->tracker_settings[$this->getTrackerId()]; } $tracker_plugin_configuration = array('index' => $this) + $tracker_settings['settings']; @@ -397,10 +391,6 @@ class Index extends ConfigEntityBase implements IndexInterface { return $this->trackerInstance; } - public function getTrackerSettings() { - return $this->tracker_settings; - } - /** * {@inheritdoc} */ @@ -456,7 +446,7 @@ class Index extends ConfigEntityBase implements IndexInterface { // Filter processors by status if required. Enabled processors are those // which have settings in the "processors" option. if ($only_enabled) { - $processors_settings = $this->getProcessorSettings(); + $processors_settings = $this->processor_settings; $processors = array_intersect_key($processors, $processors_settings); } @@ -468,7 +458,6 @@ class Index extends ConfigEntityBase implements IndexInterface { */ public function getProcessorsByStage($stage, $only_enabled = TRUE) { $processors = $this->loadProcessors(); - $processor_settings = $this->getProcessorSettings(); $processor_weights = array(); // Get a list of all processors meeting the criteria (stage and, optionally, @@ -504,7 +493,7 @@ class Index extends ConfigEntityBase implements IndexInterface { if (empty($this->processorInstances)) { /** @var $processor_plugin_manager \Drupal\search_api\Processor\ProcessorPluginManager */ $processor_plugin_manager = \Drupal::service('plugin.manager.search_api.processor'); - $processor_settings = $this->getProcessorSettings(); + $processor_settings = $this->processor_settings; foreach ($processor_plugin_manager->getDefinitions() as $name => $processor_definition) { if (empty($this->processorInstances[$name])) { @@ -534,21 +523,6 @@ class Index extends ConfigEntityBase implements IndexInterface { /** * {@inheritdoc} */ - public function getProcessorSettings() { - return $this->processor_settings; - } - - /** - * {@inheritdoc} - */ - public function setProcessorSettings(array $processors) { - $this->processor_settings = $processors; - return $this; - } - - /** - * {@inheritdoc} - */ public function preprocessIndexItems(array &$items) { foreach ($this->getProcessorsByStage(ProcessorInterface::STAGE_PREPROCESS_INDEX) as $processor) { $processor->preprocessIndexItems($items); @@ -653,7 +627,7 @@ class Index extends ConfigEntityBase implements IndexInterface { $fields = $this->getCache(__FUNCTION__, FALSE); if (!$fields) { $fields = array(); - foreach ($this->getFieldSettings() as $key => $field_info) { + foreach ($this->field_settings as $key => $field_info) { $fields[$key] = Utility::createField($this, $key, $field_info); } } @@ -694,8 +668,8 @@ class Index extends ConfigEntityBase implements IndexInterface { $fulltext_fields = $this->getCache(__FUNCTION__); if (!$fulltext_fields) { $fulltext_fields = array(); - foreach ($this->getFieldSettings() as $key => $field_info) { - if (Utility::isTextType($field_info['type'])) { + foreach ($this->getFields() as $key => $field) { + if (Utility::isTextType($field->getType())) { $fulltext_fields[] = $key; } } @@ -707,21 +681,6 @@ class Index extends ConfigEntityBase implements IndexInterface { /** * {@inheritdoc} */ - public function getFieldSettings() { - return $this->field_settings; - } - - /** - * {@inheritdoc} - */ - public function setFieldSettings(array $fields = array()) { - $this->field_settings = $fields; - return $this; - } - - /** - * {@inheritdoc} - */ public function getPropertyDefinitions($datasource_id, $alter = TRUE) { $alter = $alter ? 1 : 0; $properties = $this->getCache(__FUNCTION__); @@ -1192,9 +1151,7 @@ class Index extends ConfigEntityBase implements IndexInterface { * The previous version of the index. */ protected function reactToServerSwitch(IndexInterface $original) { - if (!$original->status() || !$this->status()) { - throw new SearchApiException("Invalid operation, this should only be called when the index was enabled before the change and remained so."); - } + assert($original->status() && $this->status(), '::reactToServerSwitch should only be called when the index is enabled.'); if ($this->getServerId() != $original->getServerId()) { if ($original->isServerEnabled()) { @@ -1222,9 +1179,7 @@ class Index extends ConfigEntityBase implements IndexInterface { * The previous version of the index. */ protected function reactToDatasourceSwitch(IndexInterface $original) { - if (!$original->status() || !$this->status()) { - throw new SearchApiException("Invalid operation, this should only be called when the index was enabled before the change and remained so."); - } + assert($original->status() && $this->status(), '::reactToDatasourceSwitch should only be called when the index is enabled.'); $new_datasource_ids = $this->getDatasourceIds(); $original_datasource_ids = $original->getDatasourceIds(); @@ -1247,9 +1202,7 @@ class Index extends ConfigEntityBase implements IndexInterface { * The previous version of the index. */ protected function reactToTrackerSwitch(IndexInterface $original) { - if (!$original->status() || !$this->status()) { - throw new SearchApiException("Invalid operation, this should only be called when the index was enabled before the change and remained so."); - } + assert($original->status() && $this->status(), '::reactToTrackerSwitch should only be called when the index is enabled.'); if ($this->getTrackerId() != $original->getTrackerId()) { $index_task_manager = \Drupal::getContainer()->get('search_api.index_task_manager'); @@ -1361,8 +1314,6 @@ class Index extends ConfigEntityBase implements IndexInterface { } } - // @todo Override static load() etc. methods? Measure performance difference. - /** * {@inheritdoc} */ diff --git a/src/IndexInterface.php b/src/IndexInterface.php index 4aa2645..da84764 100644 --- a/src/IndexInterface.php +++ b/src/IndexInterface.php @@ -280,24 +280,6 @@ interface IndexInterface extends ConfigEntityInterface { public function getProcessorsByStage($stage, $only_enabled = TRUE); /** - * Retrieves this index's processor settings. - * - * @return array - * An array of processors and their settings. - */ - public function getProcessorSettings(); - - /** - * Sets this index's processor settings. - * - * @param array $processors - * An array of processors and their settings. - * - * @return $this - */ - public function setProcessorSettings(array $processors); - - /** * Preprocesses data items for indexing. * * Lets all enabled processors for this index preprocess the indexed data. @@ -423,24 +405,6 @@ interface IndexInterface extends ConfigEntityInterface { public function getFulltextFields(); /** - * Retrieves this index's field settings. - * - * @return array - * An array of field settings. - */ - public function getFieldSettings(); - - /** - * Sets this index's field settings. - * - * @param array $fields - * An array of field settings. - * - * @return $this - */ - public function setFieldSettings(array $fields); - - /** * Retrieves the properties of one of this index's datasources. * * @param string|null $datasource_id diff --git a/tests/search_api_test_dependencies/src/Plugin/search_api/datasource/TestDatasource.php b/tests/search_api_test_dependencies/src/Plugin/search_api/datasource/TestDatasource.php index 800f18f..739b9ff 100644 --- a/tests/search_api_test_dependencies/src/Plugin/search_api/datasource/TestDatasource.php +++ b/tests/search_api_test_dependencies/src/Plugin/search_api/datasource/TestDatasource.php @@ -29,7 +29,7 @@ class TestDatasource extends DatasourcePluginBase { * {@inheritdoc} */ public function calculateDependencies() { - return $this->configuration; + return $this->configuration['settings']; } /** diff --git a/tests/src/Kernel/DependencyRemovalTest.php b/tests/src/Kernel/DependencyRemovalTest.php index c5b3242..9702b43 100644 --- a/tests/src/Kernel/DependencyRemovalTest.php +++ b/tests/src/Kernel/DependencyRemovalTest.php @@ -57,9 +57,17 @@ class DependencyRemovalTest extends KernelTestBase { $this->index = Index::create(array( 'id' => 'test_index', 'name' => 'Test index', - 'tracker' => 'default', - 'datasources' => array( - 'entity:user', + 'tracker_settings' => array( + 'default' => array( + 'plugin_id' => 'default', + 'setttings' => array(), + ) + ), + 'datasource_settings' => array( + 'entity:user' => array( + 'plugin_id' => 'entity:user', + 'settings' => array(), + ) ), )); @@ -173,17 +181,21 @@ class DependencyRemovalTest extends KernelTestBase { // server. $dependency_key = $this->dependency->getConfigDependencyKey(); $dependency_name = $this->dependency->getConfigDependencyName(); - $this->index->set('datasources', array( - 'entity:user', - 'search_api_test_dependencies', - )); - $this->index->set('datasource_configs', array( + $datasource_settings = array( + 'entity:user' => array( + 'plugin_id' => 'entity:user', + 'settings' => array(), + ), 'search_api_test_dependencies' => array( - $dependency_key => array( - $dependency_name, + 'plugin_id' => 'search_api_test_dependencies', + 'settings' => array( + $dependency_key => array( + $dependency_name, + ), ), - ), - )); + ) + ); + $this->index->set('datasource_settings', $datasource_settings); $this->index->save(); // Check the dependencies were calculated correctly. @@ -231,15 +243,15 @@ class DependencyRemovalTest extends KernelTestBase { // server. $dependency_key = $this->dependency->getConfigDependencyKey(); $dependency_name = $this->dependency->getConfigDependencyName(); - $this->index->set('datasources', array( - 'search_api_test_dependencies', - )); - $this->index->set('datasource_configs', array( + $this->index->set('datasource_settings', array( 'search_api_test_dependencies' => array( - $dependency_key => array( - $dependency_name, + 'plugin_id' => 'search_api_test_dependencies', + 'settings' => array( + $dependency_key => array( + $dependency_name, + ), ), - ), + ) )); $this->index->save(); @@ -275,7 +287,7 @@ class DependencyRemovalTest extends KernelTestBase { // server. $dependency_key = $this->dependency->getConfigDependencyKey(); $dependency_name = $this->dependency->getConfigDependencyName(); - $this->index->set('processors', array( + $this->index->set('processor_settings', array( 'search_api_test_dependencies' => array( 'plugin_id' => 'search_api_test_dependencies', 'settings' => array(