function drush_acquia_contenthub_reindex in Acquia Content Hub 8
Rebuilds the Elastic Search Index in the Content Hub Subscription.
WARNING! This requires elevated keys. This command will rebuild the Elastic Search Index from the subscription. It is important in cases where the field definition has changed, then all existing entities with the previous definition would have to be deleted and the index rebuilt. After that the new definition of the entities with that field can be pushed to Content Hub.
Parameters
string|null $api: API Key.
string|null $secret: Secret Key.
Return value
mixed|false Drush Output.
File
- ./
acquia_contenthub.drush.inc, line 620 - ContentHub Drush Commands.
Code
function drush_acquia_contenthub_reindex($api = NULL, $secret = NULL) {
/** @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 (drush_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 {
return drush_set_error(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) {
drush_print("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 {
return drush_set_error(dt("Error trying to re-index your subscription. You might require elevated keys to perform this operation."));
}
}
else {
return drush_user_abort();
}
}