You are here

function search_api_elasticsearch_update_7101 in Search API Elasticsearch 7

Upgrade to multiple client support and convert settings.

File

./search_api_elasticsearch.install, line 11
Install/Uninstall/Update tasks for the Search API Elasticsearch module.

Code

function search_api_elasticsearch_update_7101() {
  module_load_include('module', 'search_api');

  // Disable Search API servers.
  foreach (search_api_server_load_multiple(FALSE, array(
    'class' => 'search_api_elasticsearch_service',
  ), TRUE) as $server) {
    $server
      ->update(array(
      'enabled' => 0,
    ));
  }

  // Enable Search API Elasticsearch Elastica.
  module_enable(array(
    'search_api_elasticsearch_elastica',
  ));

  // Update Search API servers to use the new class
  foreach (search_api_server_load_multiple(FALSE, array(
    'class' => 'search_api_elasticsearch_service',
  ), TRUE) as $server) {
    $server->class = 'search_api_elasticsearch_elastica_service';
    $server
      ->save();
  }

  // Enable Search API servers.
  foreach (search_api_server_load_multiple(FALSE, array(
    'class' => 'search_api_elasticsearch_elastica_service',
  ), TRUE) as $server) {
    $server
      ->update(array(
      'enabled' => 1,
    ));
  }
}