You are here

public function AcquiaContentHubFiltersCommands::detachFilter in Acquia Content Hub 8.2

Detaches filter from site.

@command acquia:contenthub-filters:detach @aliases ach-cfd

@usage acquia:contenthub-filters:detach 00000000-0000-0000-0000-000000000000 http://example.com/acquia-contenthub/webhook Detaches filter from site.

Parameters

string $uuid: Filter UUID.

string $url: Webhook URL.

Throws

\Exception

File

src/Commands/AcquiaContentHubFiltersCommands.php, line 146

Class

AcquiaContentHubFiltersCommands
Drush command to interact with Acquia Content Hub filters.

Namespace

Drupal\acquia_contenthub\Commands

Code

public function detachFilter(string $uuid, string $url) : void {
  $client = $this->clientFactory
    ->getClient();
  $webhook = $client
    ->getWebHook($url);
  if (empty($webhook) || empty($webhook
    ->getFilters())) {
    $message = 'Webhook with following URL {url} does not exist or no filters attached to this webhook.';
    $this->logger
      ->log(LogLevel::CANCEL, $message, [
      'url' => $url,
    ]);
    return;
  }
  if (!in_array($uuid, $webhook
    ->getFilters(), TRUE)) {
    $this->logger
      ->log(LogLevel::CANCEL, 'Nothing to detach.');
    return;
  }
  $response = $client
    ->removeFilterFromWebhook($uuid, $webhook
    ->getUuid());
  if (empty($response)) {
    return;
  }
  $message = 'Filter {filter} successfully detached from {url}.';
  $context = [
    'filter' => $uuid,
    'url' => $url,
  ];
  $this->logger
    ->log(LogLevel::SUCCESS, $message, $context);
}