diff --git a/search_api.install b/search_api.install index e24736c..9b1883f 100644 --- a/search_api.install +++ b/search_api.install @@ -125,3 +125,42 @@ function search_api_requirements($phase) { } return array(); } + +/** + * Adapts index config schema to remove an unnecessary layer for plugins. + */ +function search_api_update_8101() { + // This update function updates search indexes for the change from + // https://www.drupal.org/node/2656052. + $config_factory = \Drupal::configFactory(); + $plugin_types = [ + 'processor', + 'datasource', + 'tracker', + ]; + + foreach ($config_factory->listAll('search_api.index.') as $index_id) { + $index = $config_factory->getEditable($index_id); + $changed = FALSE; + + foreach ($plugin_types as $plugin_type) { + $property = $plugin_type . '_settings'; + $plugins = $index->get($property); + foreach ($plugins as $id => $config) { + if (isset($config['plugin_id']) && isset($config['settings'])) { + $changed = TRUE; + $plugins[$id] = $config['settings']; + } + } + $index->set($property, $plugins); + } + + if ($changed) { + // Mark the resulting configuration as trusted data. This avoids issues + // with future schema changes. + $index->save(TRUE); + } + } + + return t('Index config schema updated.'); +} diff --git a/tests/src/Kernel/ContentEntityDatasourceTest.php b/tests/src/Kernel/ContentEntityDatasourceTest.php index 34146bd..3a1ad6a 100644 --- a/tests/src/Kernel/ContentEntityDatasourceTest.php +++ b/tests/src/Kernel/ContentEntityDatasourceTest.php @@ -80,16 +80,10 @@ public function setUp() { 'id' => 'test_index', 'status' => FALSE, 'datasource_settings' => array( - 'entity:' . $this->testEntityTypeId => array( - 'plugin_id' => 'entity:' . $this->testEntityTypeId, - 'settings' => array(), - ), + 'entity:' . $this->testEntityTypeId => array(), ), 'tracker_settings' => array( - 'default' => array( - 'plugin_id' => 'default', - 'settings' => array(), - ), + 'default' => array(), ), )); $this->datasource = $this->index->getDatasource('entity:' . $this->testEntityTypeId); diff --git a/tests/src/Kernel/FieldValuesExtractionTest.php b/tests/src/Kernel/FieldValuesExtractionTest.php index 8ebf023..a8e786b 100644 --- a/tests/src/Kernel/FieldValuesExtractionTest.php +++ b/tests/src/Kernel/FieldValuesExtractionTest.php @@ -120,10 +120,7 @@ public function setUp() { ), ), 'datasource_settings' => array( - 'entity:entity_test_mulrev_changed' => array( - 'plugin_id' => 'entity:entity_test_mulrev_changed', - 'settings' => array(), - ), + 'entity:entity_test_mulrev_changed' => array(), ), ));