You are here

public function AcquiaContentHubWebhookInterestCommands::contenthubWebhookInterestsAdd in Acquia Content Hub 8.2

Perform a webhook interest management operation.

@command acquia:contenthub-webhook-interests-add @aliases ach-wi-add

@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-add Add the interests to the webhook

Throws

\Exception

File

src/Commands/AcquiaContentHubWebhookInterestCommands.php, line 156

Class

AcquiaContentHubWebhookInterestCommands
Tests commands that interact with webhook interests.

Namespace

Drupal\acquia_contenthub\Commands

Code

public function contenthubWebhookInterestsAdd() {
  $this
    ->findWebhook();
  if (empty($this
    ->input()
    ->getOptions()['uuids'])) {
    $this
      ->output()
      ->writeln(dt('<fg=white;bg=red;options=bold;>[error] Uuids are required to add interests.</>'));
    return;
  }
  $uuids = explode(',', $this
    ->input()
    ->getOptions()['uuids']);
  $send_update = $this->config
    ->get('send_contenthub_updates') ?? TRUE;
  if ($send_update) {
    $response = $this->client
      ->addEntitiesToInterestList($this->webhookUuid, $uuids);
    if (empty($response)) {
      return;
    }
    if (200 !== $response
      ->getStatusCode()) {
      $this
        ->output()
        ->writeln('An error occurred and interests were not updated.');
      return;
    }
    $this
      ->output()
      ->writeln("\nInterests updated successfully.\n");
  }
  $this
    ->contenthubWebhookInterestsList();
}