You are here

public function DumpAssets::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_subscriber/src/EventSubscriber/HandleWebhook/DumpAssets.php, line 83

Class

DumpAssets
Class DumpAssets.

Namespace

Drupal\acquia_contenthub_subscriber\EventSubscriber\HandleWebhook

Code

public function onHandleWebhook(HandleWebhookEvent $event) : void {
  $payload = $event
    ->getPayload();
  $client_uuid = $event
    ->getClient()
    ->getSettings()
    ->getUuid();
  if ('pending' !== $payload['status'] || 'dump' !== $payload['crud'] || $payload['initiator'] === $client_uuid || empty($payload['types']) || !is_array($payload['types'])) {
    return;
  }
  $entities = [];
  foreach ($payload['types'] as $entity_type) {
    try {
      $loaded = $this->manager
        ->getStorage($entity_type)
        ->loadMultiple();
    } catch (\Exception $e) {
      $loaded = [];
    }
    $uuids = [];
    foreach ($loaded as $entity) {
      $uuids[$entity
        ->uuid()] = $entity;
    }
    if ($uuids) {
      foreach ($this->tracker
        ->getUntracked(array_keys($uuids)) as $uuid) {
        $entities[$uuid] = $uuids[$uuid];
      }
    }
  }
  if ($entities) {
    $document = $this->common
      ->getLocalCdfDocument(...array_values($entities));
    $response = $this
      ->getResponse($event, $document
      ->toString());
    $event
      ->setResponse($response);
    $event
      ->stopPropagation();
  }
}