You are here

function search_api_solr_update_8301 in Search API Solr 8.3

Same name and namespace in other branches
  1. 4.x search_api_solr.install \search_api_solr_update_8301()

Field types clean-up.

File

./search_api_solr.install, line 872
Install, update and uninstall functions for the Search API Solr module.

Code

function search_api_solr_update_8301() {
  $config_factory = \Drupal::configFactory();
  foreach ($config_factory
    ->listAll('search_api.index.') as $index_name) {
    $index = $config_factory
      ->getEditable($index_name);
    $field_settings = $index
      ->get('field_settings');
    foreach ($field_settings as &$field_setting) {
      if ('solr_text_ngram' === $field_setting['type']) {
        $field_setting['type'] = 'solr_text_custom:edge';
      }
      if ('solr_string_ngram' === $field_setting['type']) {
        $field_setting['type'] = 'solr_text_custom:edgestring';
      }
      if ('solr_text_phonetic' === $field_setting['type']) {
        $field_setting['type'] = 'solr_text_custom:phonetic';
      }
    }
    $index
      ->set('field_settings', $field_settings)
      ->save(TRUE);
  }
}