You are here

public function AcquiaSearchSolrApi::getIndexes in Acquia Connector 7.3

Returns list of search indexes.

Return value

array Search indexes list.

1 call to AcquiaSearchSolrApi::getIndexes()
AcquiaSearchSolrApi::getPreferredIndexService in acquia_search/includes/AcquiaSearchSolrApi.php
Returns preferred search index service.

File

acquia_search/includes/AcquiaSearchSolrApi.php, line 124

Class

AcquiaSearchSolrApi
Class AcquiaSearchApi.

Code

public function getIndexes() {
  $query = [
    'network_id' => $this->subscription,
  ];
  $nonce = AcquiaSearchSolrCrypt::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' => isset($response->status_message) ? $response->status_message : '',
      '@code' => isset($response->code) ? $response->code : '',
      '@request' => isset($response->request) ? $response->request : '',
    ]);
    watchdog('acquia_search_solr', $error_message, [], WATCHDOG_ERROR);
    return [];
  }
  return $this
    ->processResponse($response->data);
}