You are here

function search_api_solr_update_8320 in Search API Solr 8.3

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

Fix 2.x to 3.0 upgrade path of spellcheck components.

File

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

Code

function search_api_solr_update_8320() {
  foreach (search_api_solr_update_helper_get_field_type_configs() as $field_type_name => $field_type_config) {
    $save = FALSE;
    if (isset($field_type_config['spellcheck_field_type']) && empty($field_type_config['spellcheck_field_type'])) {
      unset($field_type_config['spellcheck_field_type']);
      $save = TRUE;
    }
    if (!empty($field_type_config['solr_configs']) && !empty($field_type_config['solr_configs']['searchComponents'])) {
      foreach ($field_type_config['solr_configs']['searchComponents'] as &$component) {
        if ('spellcheck' === $component['name']) {
          if (isset($component['lst']) && is_array($component['lst'])) {
            foreach ($component['lst'] as $key => &$lst) {
              if ('spellchecker' === $lst['name']) {
                if (isset($lst['str']) && is_array($lst['str'])) {
                  foreach ($lst['str'] as $str) {
                    if ('onlyMorePopular' === $str['name']) {
                      continue 2;
                    }
                  }
                  $lst['str'][] = [
                    'name' => 'onlyMorePopular',
                    'VALUE' => 'true',
                  ];
                  $save = TRUE;
                }
              }
            }
            if ('str' === $key) {

              // An previously erroneous implementation of
              // search_api_solr_update_8315() added that entry which needs to
              // be removed now.
              unset($component['lst']['str']);
              $save = TRUE;
            }
          }
        }
      }
    }
    if ($save) {
      search_api_solr_update_helper_save_field_type_config($field_type_name, $field_type_config);
    }
  }
}