You are here

public function ContentHubConnectionManager::addDefaultFilterToWebhook in Acquia Content Hub 8.2

Adds default filter to a Webhook.

Parameters

string $webhook_uuid: The webhook UUID.

Throws

\Exception

1 call to ContentHubConnectionManager::addDefaultFilterToWebhook()
ContentHubConnectionManager::registerWebhook in src/ContentHubConnectionManager.php
Registers a webhook if it has not been registered already.

File

src/ContentHubConnectionManager.php, line 167

Class

ContentHubConnectionManager
Responsible for connection management actions.

Namespace

Drupal\acquia_contenthub

Code

public function addDefaultFilterToWebhook(string $webhook_uuid) : void {
  $this
    ->initialize();
  $filter_name = self::DEFAULT_FILTER . $this->client
    ->getSettings()
    ->getName();
  $filter = $this
    ->createDefaultFilter($filter_name);
  $list = $this->client
    ->listFiltersForWebhook($webhook_uuid);
  if (isset($filter['uuid']) && is_array($list['data']) && in_array($filter['uuid'], $list['data'], TRUE)) {

    // The default filter is already attached to the current webhook.
    return;
  }

  // Default Filter for the current client exists but is not attached to this
  // client's webhook.
  if (!isset($filter['uuid'])) {
    return;
  }
  $response = $this->client
    ->addFilterToWebhook($filter['uuid'], $webhook_uuid);
  if (isset($response['success']) && $response['success'] === FALSE) {
    $this->logger
      ->error('Could not add default filter "@d_filter" to Webhook UUID = "@whuuid". Reason: "@reason"', [
      '@d_filter' => $filter_name,
      '@whuuid' => $webhook_uuid,
      '@reason' => $response['error']['message'],
    ]);
    return;
  }
  $this->logger
    ->notice('Added filter "@filter" (@uuid) to Webhook UUID = "@whuuid".', [
    '@filter' => $filter_name,
    '@uuid' => $filter['uuid'],
    '@whuuid' => $webhook_uuid,
  ]);
}