UpdatePublished.php in Acquia Content Hub 8.2
File
modules/acquia_contenthub_publisher/src/EventSubscriber/HandleWebhook/UpdatePublished.php
View source
<?php
namespace Drupal\acquia_contenthub_publisher\EventSubscriber\HandleWebhook;
use Drupal\acquia_contenthub\AcquiaContentHubEvents;
use Drupal\acquia_contenthub\Event\HandleWebhookEvent;
use Drupal\acquia_contenthub_publisher\PublisherTracker;
use Drupal\Core\Database\Connection;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class UpdatePublished implements EventSubscriberInterface {
protected $database;
public function __construct(Connection $database) {
$this->database = $database;
}
public static function getSubscribedEvents() {
$events[AcquiaContentHubEvents::HANDLE_WEBHOOK][] = 'onHandleWebhook';
return $events;
}
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();
}
}
}
}