You are here

public function SearchApiSolrBackend::isAvailable in Search API Solr 4.x

Same name and namespace in other branches
  1. 8.3 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::isAvailable()
  2. 8 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::isAvailable()
  3. 8.2 src/Plugin/search_api/backend/SearchApiSolrBackend.php \Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend::isAvailable()

Throws

\Drupal\Component\Plugin\Exception\PluginException

\Drupal\search_api\SearchApiException

File

src/Plugin/search_api/backend/SearchApiSolrBackend.php, line 608

Class

SearchApiSolrBackend
Apache Solr backend for search api.

Namespace

Drupal\search_api_solr\Plugin\search_api\backend

Code

public function isAvailable() {
  try {
    $connector = $this
      ->getSolrConnector();
    $server_available = $connector
      ->pingServer() !== FALSE;
    $core_available = $connector
      ->pingCore() !== FALSE;
    if ($server_available && !$core_available) {
      \Drupal::messenger()
        ->addWarning($this
        ->t('Server %server is reachable but the configured %core is not available.', [
        '%server' => $this
          ->getServer()
          ->label(),
        '%core' => $connector
          ->isCloud() ? 'collection' : 'core',
      ]));
    }
    return $server_available && $core_available;
  } catch (\Exception $e) {
    $this
      ->logException($e);
  }

  // If any exception was thrown we consider the server to be unavailable.
  return FALSE;
}