public function AcquiaContenthubCommands::contenthubPurge in Acquia Content Hub 8
Purges all entities from Acquia Content Hub. WARNING! Be VERY careful when using this command. This destructive command requires elevated keys. Every subsequent execution of this command will override the backup created by the previous call.
@command acquia:contenthub-purge @aliases ach-purge,acquia-contenthub-purge
Parameters
$api: API Key
$secret: Secret Key
File
- src/
Commands/ AcquiaContenthubCommands.php, line 324
Class
- AcquiaContenthubCommands
- A Drush commandfile.
Namespace
Drupal\acquia_contenthub\CommandsCode
public function contenthubPurge($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 PURGE your Content Hub Subscription?\n" . "*************************************************************************************\n" . "PROCEED WITH CAUTION. THIS ACTION WILL PURGE ALL EXISTING ENTITIES IN YOUR CONTENT HUB SUBSCRIPTION.\n" . "While a backup is created for use by the restore command, restoration may not be timely and is not guaranteed. Concurrent or frequent\n" . "use of this command may result in an inability to restore. You can always republish your content as a means of 'recovery'.\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 'purge' command.
if ($client_manager
->isConnected()) {
$response = $client_manager
->createRequest('purge');
}
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) {
// Deleting exported entities from the Tracking Table.
/** @var \Drupal\acquia_contenthub\ContentHubEntitiesTracking $entities_tracking */
$entities_tracking = \Drupal::getContainer()
->get('acquia_contenthub.acquia_contenthub_entities_tracking');
$entities_tracking
->deleteExportedEntities();
$this
->output()
->writeln("Your Subscription is being purged. All clients who have registered to received webhooks will be notified with a reindex webhook when the purge process has been completed.\n");
}
else {
throw new \Exception(dt("Error trying to purge your subscription. You might require elevated keys to perform this operation."));
}
}
}