You are here

public function AcquiaContenthubCommands::contenthubDelete in Acquia Content Hub 8

Deletes a single entity from the Content Hub.

@command acquia:contenthub-delete @aliases ach-del,acquia-contenthub-delete

Parameters

$uuid: Entity's UUID

File

src/Commands/AcquiaContenthubCommands.php, line 286

Class

AcquiaContenthubCommands
A Drush commandfile.

Namespace

Drupal\acquia_contenthub\Commands

Code

public function contenthubDelete($uuid) {

  /** @var \Drupal\acquia_contenthub\Client\ClientManager $client_manager */
  $client_manager = \Drupal::service('acquia_contenthub.client_manager');
  if (!Uuid::isValid($uuid)) {
    throw new \Exception(dt("Argument provided is not a UUID."));
  }
  else {
    $warning_message = dt('Are you sure you want to delete the entity with uuid = @uuid from the Content Hub? There is no way back from this action!', [
      '@uuid' => $uuid,
    ]);
    if ($this
      ->io()
      ->confirm($warning_message)) {
      $client = $client_manager
        ->getConnection();
      if ($client
        ->deleteEntity($uuid)) {
        $this
          ->output()
          ->writeln(dt("Entity with UUID = @uuid has been successfully deleted from the Content Hub.", [
          '@uuid' => $uuid,
        ]));
      }
      else {
        throw new \Exception(dt("Entity with UUID = @uuid cannot be deleted.", [
          '@uuid' => $uuid,
        ]));
      }
    }
  }
}