You are here

public function SearchApiAcquiaApi::getIndexes in Acquia Search for Search API 7.2

Returns list of search indexes.

Return value

array Search indexes list.

1 call to SearchApiAcquiaApi::getIndexes()
SearchApiAcquiaApi::getPreferredCoreService in includes/v3/SearchApiAcquiaApi.php
Returns preferred search index service.

File

includes/v3/SearchApiAcquiaApi.php, line 124

Class

SearchApiAcquiaApi
Class SearchApiAcquiaApi.

Code

public function getIndexes() {
  $query = [
    'network_id' => $this->subscription,
  ];
  $nonce = SearchApiAcquiaCrypt::randomBytes(24);
  $config_path = '/v2/index/configure';
  $auth_string = sprintf('id=%s&nonce=%s&realm=search&version=2.0', $this->appUuid, $nonce);
  $host = preg_replace('(^https?://)', '', $this->host);
  $req_params = [
    'GET',
    $host,
    $config_path,
    drupal_http_build_query($query),
    $auth_string,
    REQUEST_TIME,
  ];
  $headers = [
    'Authorization' => $this
      ->calculateAuthHeader($this->apiKey, $req_params, $auth_string),
    'X-Authorization-Timestamp' => REQUEST_TIME,
  ];
  $url = url($this->host . $config_path, [
    'https' => TRUE,
    'query' => $query,
  ]);
  $options = [
    'headers' => $headers,
    'timeout' => self::REQUEST_TIMEOUT,
  ];
  $response = drupal_http_request($url, $options);
  if ($response->code > 300 || !isset($response->data)) {
    $error_message = t("Couldn't connect to Solr. Reason: @reason. Status code: @code. Request: @request", [
      '@reason' => $response->status_message,
      '@code' => $response->code,
      '@request' => $response->request,
    ]);
    watchdog('acquia_search_solr', $error_message, [], WATCHDOG_ERROR);
    return [];
  }
  return $this
    ->processResponse($response->data);
}