You are here

function elasticsearch_watchdog_settings_validate in Elasticsearch Connector 7.5

Same name and namespace in other branches
  1. 7 modules/elasticsearch_watchdog/elasticsearch_watchdog.admin.inc \elasticsearch_watchdog_settings_validate()
  2. 7.2 modules/elasticsearch_watchdog/elasticsearch_watchdog.admin.inc \elasticsearch_watchdog_settings_validate()

Validate the setting form submission.

_state

Parameters

array $form:

1 string reference to 'elasticsearch_watchdog_settings_validate'
elasticsearch_watchdog_settings in modules/elasticsearch_watchdog/elasticsearch_watchdog.admin.inc
Building a settings form for the Elasticsearch watchdog functionality.

File

modules/elasticsearch_watchdog/elasticsearch_watchdog.admin.inc, line 43
Created on Jan 06, 2014

Code

function elasticsearch_watchdog_settings_validate($form, &$form_state) {
  $values = $form_state['values'];
  if (!empty($form_state['triggering_element']['#ajax']) || empty($values['elasticsearch_watchdog_cluster_id']['index'])) {
    return;
  }
  $client = elasticsearch_connector_get_client_by_id($values['elasticsearch_watchdog_cluster_id']['cluster_id']);
  $index_name = elasticsearch_watchdog_get_index_name($values['elasticsearch_watchdog_cluster_id']['index']);
  $type_name = elasticsearch_watchdog_get_type_name();
  if ($client) {
    if (!$client
      ->indices()
      ->exists(array(
      'index' => $index_name,
    ))) {
      form_set_error('elasticsearch_watchdog_cluster_id', t('The index doesn\'t exists. Please created it before continue.'));
    }
    else {
      if (!$client
        ->indices()
        ->existsType(array(
        'index' => $index_name,
        'type' => $type_name,
      ))) {
        elasticsearch_watchdog_create_type($client, $index_name, $type_name);
      }
    }
  }
  else {
    form_set_error('elasticsearch_watchdog_cluster_id', t('Cannot connect to the cluster for some reason! Please contact your system administrator.'));
  }
}