You are here

public function AcquiaSearchCommands::searchSolrResetCoresCache in Acquia Search 3.x

Same name and namespace in other branches
  1. 2.x src/Commands/AcquiaSearchCommands.php \Drupal\acquia_search\Commands\AcquiaSearchCommands::searchSolrResetCoresCache()

Resets the Acquia Solr Search cores cache.

By identifier provided either by configuration or by argument.

@option id Optional. The Acquia subscription identifier corresponding to the search core for cache reset. By default, this identifier is provided by configuration.

@command acquia:search-solr:cores:cache-reset

@aliases acquia:ss:cores:cr

@usage acquia:search-solr:cores:cache-reset Clears the Acquia search cores cache for the default Acquia subscription identifier provided by module configuration. @usage acquia:ss:cores:cr --id=ABC-12345 Clears the Acquia Search cores cache for the ABC-12345 subscription identifier.

@validate-module-enabled acquia_search

Parameters

array $options: An associative array of options whose values come from cli, aliases, config, etc.

Throws

\Exception In case of the invalid Acquia subscription identifier provided via id option or stored in the module configuration.

File

src/Commands/AcquiaSearchCommands.php, line 125

Class

AcquiaSearchCommands
A Drush commandfile.

Namespace

Drupal\acquia_search\Commands

Code

public function searchSolrResetCoresCache(array $options = [
  'id' => NULL,
]) {
  $id = $options['id'];
  if (empty($id)) {
    $id = Storage::getIdentifier();
    if (empty($id)) {
      throw new \Exception('No Acquia subscription identifier specified in command line or by configuration.');
    }
  }
  if (!preg_match('@^[A-Z]{4,5}-[0-9]{5,6}$@', $id)) {
    throw new \Exception('Provide a valid Acquia subscription identifier');
  }
  $cid = sprintf("acquia_search.indexes.%s", $id);
  if ($this->cache
    ->get($cid)) {
    $this->cache
      ->delete($cid);
    $this
      ->output()
      ->writeln(dt('Cache cleared for @id', [
      '@id' => $id,
    ]));
    return;
  }
  $this
    ->output()
    ->writeln(dt('Cache is empty for @id', [
    '@id' => $id,
  ]));
}