public function ReExport::onHandleWebhook in Acquia Content Hub 8.2
Handles webhook events.
Parameters
\Drupal\acquia_contenthub\Event\HandleWebhookEvent $event: The HandleWebhookEvent object.
Throws
\Exception
File
- modules/
acquia_contenthub_publisher/ src/ EventSubscriber/ HandleWebhook/ ReExport.php, line 75
Class
- ReExport
- Re-exports an entity and all its dependencies on a webhook request.
Namespace
Drupal\acquia_contenthub_publisher\EventSubscriber\HandleWebhookCode
public function onHandleWebhook(HandleWebhookEvent $event) : void {
$payload = $event
->getPayload();
$client = $event
->getClient();
$settings = $client
->getSettings();
$client_uuid = $settings
->getUuid();
if ('successful' !== $payload['status'] || empty($payload['uuid']) || 'republish' !== $payload['crud'] || $payload['initiator'] === $client_uuid || empty($payload['cdf'])) {
return;
}
// Obtaining Entity from Webhook message.
$uuid = $payload['cdf']['uuid'];
$type = $payload['cdf']['type'];
$dependencies = $payload['cdf']['dependencies'] ?? [];
try {
$entity = $this->entityRepository
->loadEntityByUuid($type, $uuid);
} catch (\Exception $exception) {
$entity = FALSE;
}
if (!$entity) {
$body = sprintf('The entity "%s:%s" could not be found and thus cannot be re-exported from a webhook request by origin = %s.', $type, $uuid, $payload['initiator']);
$this->channel
->error($body);
$response = $this
->getResponse($event, $body, 404);
}
else {
$this->publisherActions
->reExportEntityFull($entity, $dependencies);
$body = sprintf('Entity "%s/%s" successfully enqueued for export from webhook UUID = %s by origin = %s.', $type, $uuid, $payload['uuid'], $payload['initiator']);
$this->channel
->info($body);
$response = $this
->getResponse($event, $body, 200);
}
$event
->setResponse($response);
$event
->stopPropagation();
}