public function AcquiaContenthubCommands::contenthubReindex in Acquia Content Hub 8
Reindexes all entities in Content Hub.
@command acquia:contenthub-reindex @aliases ach-reindex,acquia-contenthub-reindex
Parameters
$api: API Key
$secret: Secret Key
File
- src/
Commands/ AcquiaContenthubCommands.php, line 426
Class
- AcquiaContenthubCommands
- A Drush commandfile.
Namespace
Drupal\acquia_contenthub\CommandsCode
public function contenthubReindex($api, $secret) {
/** @var \Drupal\acquia_contenthub\Client\ClientManager $client_manager */
$client_manager = \Drupal::service('acquia_contenthub.client_manager');
$warning_message = "Are you sure you want to REINDEX your Content Hub Subscription?\n" . "*************************************************************************************\n" . "PROCEED WITH CAUTION. THIS ACTION WILL REBUILD THE ELASTIC SEARCH INDEX IN YOUR CONTENT HUB SUBSCRIPTION.\n" . "This command will rebuild your index from the data currently stored in Content Hub. Make sure to first 'unpublish' all the entities that contain undesired\n" . "field definitions, otherwise you will rebuild essentially the same index you have today. Entities containing fields with new definitions can be\n" . "published after the index has been rebuilt.\n For more information, check https://docs.acquia.com/content-hub.\n" . "*************************************************************************************\n" . "Are you sure you want to proceed?\n";
if ($this
->io()
->confirm($warning_message)) {
// If API/Secret Keys have been given, reset the connection to use those
// keys instead of the ones set in the configuration.
if (!empty($api) && !empty($secret)) {
$client_manager
->resetConnection([
'api' => $api,
'secret' => $secret,
]);
}
// Execute the 'reindex' command.
if ($client_manager
->isConnected()) {
/** @var \Drupal\acquia_contenthub\Controller\ContentHubReindex $reindex */
$reindex = \Drupal::service('acquia_contenthub.acquia_contenthub_reindex');
$response = $client_manager
->createRequest('reindex');
$reindex
->setReindexStateSent();
}
else {
throw new \Exception(dt('Error trying to connect to the Content Hub. Make sure this site is registered to Content hub.'));
}
if (isset($response['success']) && $response['success'] === TRUE) {
$this
->output()
->writeln("Your Subscription is being re-indexed. All clients who have registered to received webhooks will be notified with a reindex webhook when the process has been completed.\n");
}
else {
throw new \Exception(dt("Error trying to re-index your subscription. You might require elevated keys to perform this operation."));
}
}
}