You are here

function drush_acquia_contenthub_restore in Acquia Content Hub 8

Restores the backup created by a previous execution of the "purge" command.

WARNING! This command requires elevated keys. It also deletes all existing entities in your susbscription because they are replaced by a backup copy.

Parameters

string|null $api: API Key.

string|null $secret: Secret Key.

Return value

mixed|false Drush Output.

File

./acquia_contenthub.drush.inc, line 561
ContentHub Drush Commands.

Code

function drush_acquia_contenthub_restore($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 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 (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 'restore' command.
    if ($client_manager
      ->isConnected()) {
      $response = $client_manager
        ->createRequest('restore');
    }
    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 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 {
      return drush_set_error(dt("Error trying to restore your subscription from a backup copy. You might require elevated keys to perform this operation."));
    }
  }
  else {
    return drush_user_abort();
  }
}