You are here

function elasticsearch_connector_cluster_indices_add_submit in Elasticsearch Connector 7.5

Same name and namespace in other branches
  1. 7 elasticsearch_connector.admin.inc \elasticsearch_connector_cluster_indices_add_submit()
  2. 7.2 elasticsearch_connector.admin.inc \elasticsearch_connector_cluster_indices_add_submit()

Submit the values of index create form.

_state

Parameters

array $form:

1 string reference to 'elasticsearch_connector_cluster_indices_add_submit'
elasticsearch_connector_cluster_indices_add in ./elasticsearch_connector.admin.inc
Create new index in the cluster with shard settings and other settings.

File

./elasticsearch_connector.admin.inc, line 536
Created on Dec 23, 2013

Code

function elasticsearch_connector_cluster_indices_add_submit($form, &$form_state) {
  $values = $form_state['values'];
  $cluster = $form['#cluster'];
  $client = elasticsearch_connector_load_library($cluster);
  $index = isset($form['#index']) ? $form['#index'] : FALSE;
  if ($client) {
    if (empty($index)) {
      try {
        $index_params['index'] = $values['index_name'];
        $index_params['body']['settings']['number_of_shards'] = $values['num_of_shards'];
        $index_params['body']['settings']['number_of_replicas'] = $values['num_of_replica'];
        drupal_alter('elasticsearch_connector_add_index', $index_params, $cluster, $client);
        $response = $client
          ->indices()
          ->create($index_params);
        if (elasticsearch_connector_check_response_ack($response)) {
          drupal_set_message(t('The index %index has been successfully created.', array(
            '%index' => $values['index_name'],
          )));
        }
        else {
          drupal_set_message(t('Fail to create the index %index', array(
            '%index' => $values['index_name'],
          )), 'error');
        }

        // If the form has been opened in dialog, close the window if it was
        // setup to do so.
        if (elasticsearch_connector_in_dialog() && elasticsearch_connector_close_on_submit()) {
          elasticsearch_connector_close_on_redirect($cluster->cluster_id, $values['index_name']);
        }
      } catch (Exception $e) {
        drupal_set_message($e
          ->getMessage(), 'error');
      }
    }
    else {
      try {
        $index_params['index'] = $values['index_name'];
        $index_params['body']['settings']['number_of_replicas'] = $values['num_of_replica'];
        drupal_alter('elasticsearch_connector_update_index', $index_params, $cluster, $client);
        $response = $client
          ->indices()
          ->putSettings($index_params);
        if (elasticsearch_connector_check_response_ack($response)) {
          drupal_set_message(t('The index %index has been successfully updated.', array(
            '%index' => $values['index_name'],
          )));
        }
        else {
          drupal_set_message(t('Fail to update the index %index', array(
            '%index' => $values['index_name'],
          )), 'error');
        }

        // If the form has been opened in dialog, close the window if it was
        // setup to do so.
        if (elasticsearch_connector_in_dialog() && elasticsearch_connector_close_on_submit()) {
          elasticsearch_connector_close_on_redirect($cluster->cluster_id, $values['index_name']);
        }
      } catch (Exception $e) {
        drupal_set_message($e
          ->getMessage(), 'error');
      }
    }
  }
}