public function AcquiaContentHubFiltersCommands::attachFilter in Acquia Content Hub 8.2
Attaches filter to site.
@command acquia:contenthub-filters:attach @aliases ach-cfa
@usage acquia:contenthub-filters:attach 00000000-0000-0000-0000-000000000000 http://example.com/acquia-contenthub/webhook Attaches filter to site.
Parameters
string $uuid: Filter UUID.
string $url: Webhook URL (e.g. http://example.com/acquia-contenthub/webhook).
Throws
\Exception
File
- src/
Commands/ AcquiaContentHubFiltersCommands.php, line 95
Class
- AcquiaContentHubFiltersCommands
- Drush command to interact with Acquia Content Hub filters.
Namespace
Drupal\acquia_contenthub\CommandsCode
public function attachFilter(string $uuid, string $url) : void {
$client = $this->clientFactory
->getClient();
$webhook = $client
->getWebHook($url);
if (empty($webhook)) {
$this->logger
->log(LogLevel::CANCEL, 'Webhook with following URL {url} or UUID {uuid} not exist.', [
'url' => $url,
'uuid' => $uuid,
]);
return;
}
if (in_array($uuid, $webhook
->getFilters())) {
$this->logger
->log(LogLevel::CANCEL, 'Filter already attached to {url}.', [
'url' => $url,
]);
return;
}
$response = $client
->addFilterToWebhook($uuid, $webhook
->getUuid());
if (empty($response)) {
return;
}
if (isset($response['success'], $response['error']) && !$response['success']) {
$context = [
'code' => $response['error']['code'],
'reason' => $response['error']['message'],
];
$this->logger
->log(LogLevel::ERROR, 'Operation failed (code: {code}). {reason}', $context);
return;
}
$this->logger
->log(LogLevel::SUCCESS, 'Filter successfully attached to {url}.', [
'url' => $url,
]);
}