You are here

class UpdatePublished in Acquia Content Hub 8.2

Class UpdatePublished.

Subscribes to onHandleWebhook.

Hierarchy

  • class \Drupal\acquia_contenthub_publisher\EventSubscriber\HandleWebhook\UpdatePublished implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of UpdatePublished

1 file declares its use of UpdatePublished
UpdatePublishedTest.php in tests/src/Kernel/EventSubscriber/HandleWebhook/UpdatePublishedTest.php
1 string reference to 'UpdatePublished'
acquia_contenthub_publisher.services.yml in modules/acquia_contenthub_publisher/acquia_contenthub_publisher.services.yml
modules/acquia_contenthub_publisher/acquia_contenthub_publisher.services.yml
1 service uses UpdatePublished
acquia_contenthub_publisher.handle_webhook.update_published in modules/acquia_contenthub_publisher/acquia_contenthub_publisher.services.yml
Drupal\acquia_contenthub_publisher\EventSubscriber\HandleWebhook\UpdatePublished

File

modules/acquia_contenthub_publisher/src/EventSubscriber/HandleWebhook/UpdatePublished.php, line 16

Namespace

Drupal\acquia_contenthub_publisher\EventSubscriber\HandleWebhook
View source
class UpdatePublished implements EventSubscriberInterface {

  /**
   * The database connection.
   *
   * @var \Drupal\Core\Database\Connection
   */
  protected $database;

  /**
   * UpdatePublished constructor.
   *
   * @param Drupal\Core\Database\Connection $database
   *   The database connection.
   */
  public function __construct(Connection $database) {
    $this->database = $database;
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[AcquiaContentHubEvents::HANDLE_WEBHOOK][] = 'onHandleWebhook';
    return $events;
  }

  /**
   * On handle webhook event.
   *
   * @param \Drupal\acquia_contenthub\Event\HandleWebhookEvent $event
   *   The handle webhook event.
   */
  public function onHandleWebhook(HandleWebhookEvent $event) {
    $payload = $event
      ->getPayload();
    $client = $event
      ->getClient();
    if ($payload['status'] == 'successful' && $payload['crud'] == 'update' && $payload['initiator'] == $client
      ->getSettings()
      ->getUuid()) {
      $uuids = [];
      if (isset($payload['assets']) && count($payload['assets'])) {
        $types = [
          'drupal8_content_entity',
          'drupal8_config_entity',
        ];
        foreach ($payload['assets'] as $asset) {
          if (!in_array($asset['type'], $types)) {
            continue;
          }
          $uuids[] = $asset['uuid'];
        }
      }
      if ($uuids) {
        $query = $this->database
          ->select('acquia_contenthub_publisher_export_tracking', 'acpet')
          ->fields('acpet', [
          'entity_uuid',
        ]);
        $query
          ->condition('acpet.entity_uuid', $uuids, 'IN');
        $items = $query
          ->execute()
          ->fetchAll();
        $uuids = [];
        foreach ($items as $item) {
          $uuids[] = $item->entity_uuid;
        }
        $update = $this->database
          ->update('acquia_contenthub_publisher_export_tracking')
          ->fields([
          'status' => PublisherTracker::CONFIRMED,
        ]);
        $update
          ->condition('entity_uuid', $uuids, 'IN');
        $update
          ->execute();
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
UpdatePublished::$database protected property The database connection.
UpdatePublished::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
UpdatePublished::onHandleWebhook public function On handle webhook event.
UpdatePublished::__construct public function UpdatePublished constructor.