You are here

public function StandardSolrCloudConnector::deleteCollection in Search API Solr 4.x

Deletes collection.

Parameters

string|null $collection: Collection.

Return value

bool TRUE if successful, FALSE otherwise.

Throws

\Drupal\search_api_solr\SearchApiSolrException

Overrides SolrCloudConnectorInterface::deleteCollection

File

src/Plugin/SolrConnector/StandardSolrCloudConnector.php, line 405

Class

StandardSolrCloudConnector
Standard Solr Cloud connector.

Namespace

Drupal\search_api_solr\Plugin\SolrConnector

Code

public function deleteCollection(?string $collection = NULL) : bool {
  $this
    ->connect();
  $this
    ->useTimeout(self::INDEX_TIMEOUT);
  try {
    $collection = $collection ?? $this->configuration['core'];
    $query = $this->solr
      ->createCollections();
    $action = $query
      ->createDelete([
      'name' => $collection,
    ]);
    $query
      ->setAction($action);
    $response = $this->solr
      ->collections($query);
    return $response
      ->getWasSuccessful();
  } catch (HttpException $e) {
    throw new SearchApiSolrException("Deleting collection {$collection} failed with error code " . $e
      ->getCode() . ': ' . $e
      ->getMessage(), $e
      ->getCode(), $e);
  }
}