You are here

function drush_search_api_enable in Search API 7

Same name and namespace in other branches
  1. 8 search_api.drush.inc \drush_search_api_enable()

Enable index(es).

Parameters

string|integer $index_id: The index name or id which should be enabled.

File

./search_api.drush.inc, line 240
Drush commands for SearchAPI.

Code

function drush_search_api_enable($index_id = NULL) {
  if (search_api_drush_static(__FUNCTION__)) {
    return;
  }
  $indexes = search_api_drush_get_index($index_id);
  if (empty($indexes)) {
    return;
  }
  foreach ($indexes as $index) {
    $vars = array(
      '!index' => $index->name,
    );
    if (!$index->enabled) {
      drush_log(dt("Enabling index !index and queueing items for indexing.", $vars), 'notice');
      $success = FALSE;
      try {
        if ($success = search_api_index_enable($index->id)) {
          drush_log(dt("The index !index was successfully enabled.", $vars), 'ok');
        }
      } catch (SearchApiException $e) {
        drush_log($e
          ->getMessage(), 'error');
      }
      if (!$success) {
        drush_log(dt("Error enabling index !index.", $vars), 'error');
      }
    }
    else {
      drush_log(dt("The index !index is already enabled.", $vars), 'error');
    }
  }
}