You are here

protected function SolrConnectorPluginBase::getDataFromHandler in Search API Solr 8

Same name and namespace in other branches
  1. 8.3 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::getDataFromHandler()
  2. 8.2 src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::getDataFromHandler()
  3. 4.x src/SolrConnector/SolrConnectorPluginBase.php \Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase::getDataFromHandler()

Gets data from a Solr endpoint using a given handler.

Parameters

string $handler: The handler used for the API query.

bool $reset: If TRUE the server will be asked regardless if a previous call is cached.

Return value

array Response data with system information.

Throws

\Drupal\search_api_solr\SearchApiSolrException

3 calls to SolrConnectorPluginBase::getDataFromHandler()
SolrConnectorPluginBase::getCoreInfo in src/SolrConnector/SolrConnectorPluginBase.php
Gets information about the Solr Core.
SolrConnectorPluginBase::getLuke in src/SolrConnector/SolrConnectorPluginBase.php
Gets meta-data about the index.
SolrConnectorPluginBase::getServerInfo in src/SolrConnector/SolrConnectorPluginBase.php
Gets information about the Solr server.

File

src/SolrConnector/SolrConnectorPluginBase.php, line 477

Class

SolrConnectorPluginBase
Defines a base class for Solr connector plugins.

Namespace

Drupal\search_api_solr\SolrConnector

Code

protected function getDataFromHandler($handler, $reset = FALSE) {
  static $previous_calls = [];
  $this
    ->connect();

  // We keep the results in a state instead of a cache because we want to
  // access parts of this data even if Solr is temporarily not reachable and
  // caches have been cleared.
  $state_key = 'search_api_solr.endpoint.data';
  $state = \Drupal::state();
  $endpoint_data = $state
    ->get($state_key);
  $server_uri = $this
    ->getServerUri();
  if (!isset($previous_calls[$server_uri][$handler]) || !isset($endpoint_data[$server_uri][$handler]) || $reset) {

    // Don't retry multiple times in case of an exception.
    $previous_calls[$server_uri][$handler] = TRUE;
    if (!is_array($endpoint_data) || !isset($endpoint_data[$server_uri][$handler]) || $reset) {
      $query = $this->solr
        ->createApi([
        'handler' => $handler,
        'version' => Request::API_V1,
      ]);
      $endpoint_data[$server_uri][$handler] = $this
        ->execute($query)
        ->getData();
      $state
        ->set($state_key, $endpoint_data);
    }
  }
  return $endpoint_data[$server_uri][$handler];
}