You are here

public function AcquiaContentHubWebhookInterestCommands::contenthubWebhookInterestsDelete in Acquia Content Hub 8.2

Perform a webhook interest management operation.

@command acquia:contenthub-webhook-interests-delete @aliases ach-wi-del

@option webhook_url The webhook URL to use. @default webhook_url null @option uuids The entities against which to perform the operation. Comma-separated. @default uuids null

@usage acquia:contenthub-webhook-interests-delete Delete the interest from the webhook

Throws

\Exception

File

src/Commands/AcquiaContentHubWebhookInterestCommands.php, line 199

Class

AcquiaContentHubWebhookInterestCommands
Tests commands that interact with webhook interests.

Namespace

Drupal\acquia_contenthub\Commands

Code

public function contenthubWebhookInterestsDelete() {
  $this
    ->findWebhook();
  if (empty($this
    ->input()
    ->getOptions()['uuids'])) {
    $this
      ->output()
      ->writeln(dt('<fg=white;bg=red;options=bold;>[error] Uuids are required to delete interests.</>'));
    return;
  }
  $uuids = explode(',', $this
    ->input()
    ->getOptions()['uuids']);
  $this
    ->output()
    ->writeln("\n");
  $send_update = $this->config
    ->get('send_contenthub_updates') ?? TRUE;
  if ($send_update) {
    foreach ($uuids as $uuid) {
      $response = $this->client
        ->deleteInterest($uuid, $this->webhookUuid);
      if (empty($response)) {
        continue;
      }
      if (200 !== $response
        ->getStatusCode()) {
        $this
          ->output()
          ->writeln(dt('An error occurred and the interest @uuid was not removed.', [
          '@uuid' => $uuid,
        ]));
        continue;
      }
      $this
        ->output()
        ->writeln(dt('Interest @uuid removed from webhook @webhook.', [
        '@uuid' => $uuid,
        '@webhook' => $this->webhookUrl,
      ]));
    }
  }
  $this
    ->output()
    ->writeln("\n");
  $this
    ->contenthubWebhookInterestsList();
}