You are here

function elasticsearch_watchdog_update_7001 in Elasticsearch Connector 7.2

Same name and namespace in other branches
  1. 7 modules/elasticsearch_watchdog/elasticsearch_watchdog.install \elasticsearch_watchdog_update_7001()

Updating the watchdog settings to handle the new

File

modules/elasticsearch_watchdog/elasticsearch_watchdog.install, line 165
Created on Jan 08, 2014

Code

function elasticsearch_watchdog_update_7001() {
  $new_val['cluster_id'] = variable_get('elasticsearch_watchdog_cluster_id', '');
  if (!empty($new_val['cluster_id'])) {
    module_load_include('inc', 'elasticsearch_watchdog', 'elasticsearch_watchdog.admin');
    $old_alias = variable_get('elasticsearch_watchdog_index', 'elasticsearch_watchdog');
    $old_template = variable_get('elasticsearch_watchdog_index', 'elasticsearch_watchdog') . '_template';
    $new_val['index'] = variable_get('elasticsearch_watchdog_index', 'elasticsearch_watchdog') . '_index';
    variable_set('elasticsearch_watchdog_cluster_id', $new_val);
    $index_name = elasticsearch_watchdog_get_realindex_name();
    $alias_name = elasticsearch_watchdog_get_index_name();
    $client = elasticsearch_connector_get_client_by_id($new_val['cluster_id']);
    if ($client) {
      try {
        $client
          ->indices()
          ->deleteAlias(array(
          'index' => $index_name,
          'name' => $old_alias,
        ));
        $client
          ->indices()
          ->putAlias(array(
          'index' => $index_name,
          'name' => $alias_name,
        ));
        $client
          ->indices()
          ->deleteTemplate(array(
          'name' => $old_template,
        ));
      } catch (Exception $e) {
        throw $e;
      }
    }
  }
}