public function ContentHubConnectionManager::updateWebhook in Acquia Content Hub 8.2
Updates the specified webhook on Content Hub.
Parameters
string $webhook_url: The webhook to update.
Return value
array The response of the attempt.
Throws
\Exception
File
- src/
ContentHubConnectionManager.php, line 212
Class
- ContentHubConnectionManager
- Responsible for connection management actions.
Namespace
Drupal\acquia_contenthubCode
public function updateWebhook(string $webhook_url) : array {
$this
->initialize();
if (!$this
->webhookIsRegistered($this->settings
->getWebhook('url'))) {
return $this
->registerWebhook($webhook_url);
}
if ($this
->webhookIsRegistered($webhook_url)) {
$this->logger
->error('The webhook @webhook has already been registered!', [
'@webhook' => $webhook_url,
]);
return [];
}
$options['url'] = $webhook_url;
$response = $this
->handleResponse($this->client
->updateWebhook($this->settings
->getWebhook('uuid'), $options));
if (!isset($response['success'])) {
$this->logger
->error('Unexpected error occurred during webhook update. Response: @resp', [
'@resp' => print_r($response),
]);
return [];
}
if ($response['success'] === FALSE) {
if (!isset($response['error']['message'])) {
$this->logger
->error('Unable to update URL %url, Unable to connect to Content Hub.', [
'%url' => $webhook_url,
]);
return [];
}
$this->logger
->error('Unable to update URL %url, Error %error: %error_message.', [
'%url' => $webhook_url,
'%error' => $response['error']['code'],
'%error_message' => $response['error']['message'],
]);
return [];
}
$this->logger
->notice('Webhook url @old has been successfully updated to @new', [
'@old' => $this->settings
->getWebhook('settings_url'),
'@new' => $webhook_url,
]);
$this
->saveWebhookConfig($response['uuid'], $webhook_url);
return $response['data'] ?? $response;
}