You are here

function search_api_admin_index_view in Search API 7

Page callback for displaying an index's status.

Parameters

SearchApiIndex $index: The index to display.

string|null $action: (optional) An action to execute for the index. One of "reindex", "clear", "enable" or "disable". For "disable", a confirm dialog will be shown.

See also

search_api_menu()

1 string reference to 'search_api_admin_index_view'
search_api_menu in ./search_api.module
Implements hook_menu().

File

./search_api.admin.inc, line 917
Administration page callbacks for the Search API module.

Code

function search_api_admin_index_view(SearchApiIndex $index, $action = NULL) {
  if (!empty($action)) {
    if ($action == 'enable') {
      if (isset($_GET['token']) && drupal_valid_token($_GET['token'], $index->machine_name)) {
        if ($index
          ->update(array(
          'enabled' => 1,
        ))) {
          drupal_set_message(t('The index was successfully enabled.'));
        }
        else {
          drupal_set_message(t('The index could not be enabled. Check the logs for details.'), 'error');
        }
        drupal_goto('admin/config/search/search_api/index/' . $index->machine_name);
      }
      else {
        return MENU_ACCESS_DENIED;
      }
    }
    else {
      $ret = drupal_get_form('search_api_admin_confirm', 'index', $action, $index);
      if (!empty($ret['actions'])) {
        return $ret;
      }
    }
  }
  $status = search_api_index_status($index);
  try {
    $server = $index
      ->server();
  } catch (SearchApiException $e) {
    $server = NULL;
    $vars['%server'] = $index->server;
    $message = t('The index has an unknown server (ID: %server) set. Please check the index settings.', $vars);
    drupal_set_message($message, 'error');
  }
  $ret['view'] = array(
    '#theme' => 'search_api_index',
    '#id' => $index->id,
    '#name' => $index->name,
    '#machine_name' => $index->machine_name,
    '#description' => $index->description,
    '#item_type' => $index->item_type,
    '#datasource_config' => $index
      ->datasource()
      ->getConfigurationSummary($index),
    '#enabled' => $index->enabled,
    '#server' => $server,
    '#options' => $index->options,
    '#fields' => $index
      ->getFields(),
    '#indexed_items' => $status['indexed'],
    '#on_server' => NULL,
    '#total_items' => $status['total'],
    '#status' => $index->status,
    '#read_only' => $index->read_only,
  );
  try {
    $ret['view']['#on_server'] = _search_api_get_items_on_server($index);
  } catch (SearchApiException $e) {
    watchdog_exception('search_api', $e);
  }
  if ($index->enabled && !$index->read_only) {
    $ret['form'] = drupal_get_form('search_api_admin_index_status_form', $index, $status);
  }
  return $ret;
}