class AcquiaSearchCommands in Acquia Search 2.x
Same name and namespace in other branches
- 3.x src/Commands/AcquiaSearchCommands.php \Drupal\acquia_search\Commands\AcquiaSearchCommands
A Drush commandfile.
In addition to this file, you need a drush.services.yml in root of your module, and a composer.json file that provides the name of the services file to use.
See these files for an example of injecting Drupal services:
- http://cgit.drupalcode.org/devel/tree/src/Commands/DevelCommands.php
- http://cgit.drupalcode.org/devel/tree/drush.services.yml
Hierarchy
- class \Drupal\acquia_search\Commands\AcquiaSearchCommands extends \Drush\Commands\DrushCommands
Expanded class hierarchy of AcquiaSearchCommands
1 string reference to 'AcquiaSearchCommands'
1 service uses AcquiaSearchCommands
File
- src/
Commands/ AcquiaSearchCommands.php, line 21
Namespace
Drupal\acquia_search\CommandsView source
class AcquiaSearchCommands extends DrushCommands {
/**
* Cache service.
*
* @var \Drupal\Core\Cache\CacheBackendInterface
*/
private $cache;
/**
* Core service.
*
* @var \Drupal\acquia_search\PreferredSearchCoreService
*/
private $preferredCoreService;
/**
* AcquiaSearchCommands constructor.
*
* @param \Drupal\Core\Cache\CacheBackendInterface $cache
* Cache backend service.
*/
public function __construct(CacheBackendInterface $cache) {
parent::__construct();
$this->cache = $cache;
$this->preferredCoreService = acquia_search_get_core_service();
}
/**
* Lists available Acquia search cores.
*
* @param array $options
* An associative array of options whose values come from cli, aliases,
* config, etc.
*
* @option format
* Optional. Format may be json, print_r, or var_dump. Defaults to print_r.
*
* @command acquia:search-solr:cores
*
* @aliases acquia:ss:cores
*
* @usage acquia:search-solr:cores
* Lists all available Acquia search cores.
* @usage acquia:ss:cores --format=json
* Lists all available Acquia search cores in JSON format.
*
* @validate-module-enabled acquia_search
*
* @throws \Exception
* If no cores available.
*/
public function searchSolrCoresList(array $options = [
'format' => NULL,
]) {
if (!($available_cores = $this->preferredCoreService
->getAvailableCores())) {
throw new \Exception('No Acquia search cores available');
}
$result = [];
foreach ($available_cores as $core) {
$result[] = $core['core_id'];
}
$result = array_unique($result, SORT_REGULAR);
switch ($options['format']) {
case 'json':
$this
->output()
->writeln(Json::encode($result));
break;
case 'var_dump':
case 'var_export':
$this
->output()
->writeln(var_export($result, TRUE));
break;
case 'print_r':
default:
$this
->output()
->writeln(print_r($result, TRUE));
break;
}
}
/**
* Resets the Acquia Solr Search cores cache.
*
* By identifier provided either by configuration or by argument.
*
* @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.
*
* @validate-module-enabled acquia_search
*
* @throws \Exception
* In case of the invalid Acquia subscription identifier provided via id
* option or stored in the module configuration.
*/
public function searchSolrResetCoresCache() {
if (\Drupal::state()
->get('acquia_subscription_data')) {
$sub = new Subscription();
$sub
->update();
$this
->output()
->writeln(dt('Refreshed list of cores from Acquia Connector subscription data.'));
}
$search_v3_enabled = \Drupal::config('acquia_search.settings')
->get('search_v3_enabled');
if ($search_v3_enabled) {
$cid = sprintf("acquia_search.v3indexes");
if ($this->cache
->get($cid)) {
$this->cache
->delete($cid);
$this
->output()
->writeln(dt('Cleared list of cores from acquia_search.v3indexes cache.'));
}
}
}
/**
* Lists possible Acquia search cores.
*
* A search core should be in the available cores list to work properly.
*
* @param array $options
* An associative array of options whose values come from cli, aliases,
* config, etc.
*
* @option format
* Optional. Format may be json, print_r, or var_dump. Defaults to print_r.
*
* @command acquia:search-solr:cores:possible
*
* @aliases acquia:ss:cores:possible
*
* @usage acquia:search-solr:cores:possible
* Lists all possible Acquia search cores.
* @usage acquia:ss:cores:possible --format=json
* Lists all possible Acquia search cores in JSON format.
*
* @validate-module-enabled acquia_search
*
* @throws \Exception
* In case if no possible search cores found.
*/
public function searchSolrCoresPossible(array $options = [
'format' => NULL,
]) {
if (!($possible_cores = $this->preferredCoreService
->getListOfPossibleCores())) {
throw new \Exception('No possible cores');
}
switch ($options['format']) {
case 'json':
$this
->output()
->writeln(Json::encode($possible_cores));
break;
case 'var_dump':
case 'var_export':
$this
->output()
->writeln(var_export($possible_cores, TRUE));
break;
case 'print_r':
default:
$this
->output()
->writeln(print_r($possible_cores, TRUE));
break;
}
}
/**
* Display preferred Acquia search core.
*
* @command acquia:search-solr:cores:preferred
* @aliases acquia:ss:cores:preferred
*
* @usage acquia:search-solr:cores:preferred
* Display preferred Acquia search core.
* @usage acquia:ss:cores:preferred
* Display preferred Acquia search core.
*
* @validate-module-enabled acquia_search
*
* @throws \Exception
* In case if no preferred search core available.
*/
public function searchSolrCoresPreferred() {
if (!($preferred_core = $this->preferredCoreService
->getPreferredCore())) {
throw new \Exception('No preferred search core available');
}
$this
->output()
->writeln($preferred_core['core_id']);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AcquiaSearchCommands:: |
private | property | Cache service. | |
AcquiaSearchCommands:: |
private | property | Core service. | |
AcquiaSearchCommands:: |
public | function | Lists available Acquia search cores. | |
AcquiaSearchCommands:: |
public | function | Lists possible Acquia search cores. | |
AcquiaSearchCommands:: |
public | function | Display preferred Acquia search core. | |
AcquiaSearchCommands:: |
public | function | Resets the Acquia Solr Search cores cache. | |
AcquiaSearchCommands:: |
public | function | AcquiaSearchCommands constructor. |