public function AcquiaContenthubCommands::contenthubRestore in Acquia Content Hub 8
Restores the backup taken by a previous execution of the "purge" command. WARNING! Be VERY careful when using this command. This destructive command requires elevated keys. By restoring a backup you will delete all the existing entities in your subscription.
@command acquia:contenthub-restore @aliases ach-restore,acquia-contenthub-restore
Parameters
$api: API Key
$secret: Secret Key
File
- src/
Commands/ AcquiaContenthubCommands.php, line 377
Class
- AcquiaContenthubCommands
- A Drush commandfile.
Namespace
Drupal\acquia_contenthub\CommandsCode
public function contenthubRestore($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 RESTORE the latest backup taken after purging your Content Hub Subscription?\n" . "*************************************************************************************\n" . "PROCEED WITH CAUTION. THIS ACTION WILL ELIMINATE ALL EXISTING ENTITIES IN YOUR CONTENT HUB SUBSCRIPTION.\n" . "This restore command should only be used after an accidental purge event has taken place *and* completed. This will attempt to restore\n" . "from the last purge-generated backup. In the event this fails, you will need to republish your content to Content Hub.\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 'restore' command.
if ($client_manager
->isConnected()) {
$response = $client_manager
->createRequest('restore');
}
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 restored. All clients who have registered to received webhooks will be notified with a reindex webhook when the restore process has been completed.\n");
}
else {
throw new \Exception(dt("Error trying to restore your subscription from a backup copy. You might require elevated keys to perform this operation."));
}
}
}