RemoveUnmodifiedEntities.php in Acquia Content Hub 8.2
File
modules/acquia_contenthub_publisher/src/EventSubscriber/PublishEntities/RemoveUnmodifiedEntities.php
View source
<?php
namespace Drupal\acquia_contenthub_publisher\EventSubscriber\PublishEntities;
use Drupal\acquia_contenthub\AcquiaContentHubEvents;
use Drupal\acquia_contenthub\Event\ContentHubPublishEntitiesEvent;
use Drupal\acquia_contenthub_publisher\PublisherTracker;
use Drupal\Core\Database\Connection;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class RemoveUnmodifiedEntities implements EventSubscriberInterface {
protected $database;
public function __construct(Connection $database) {
$this->database = $database;
}
public static function getSubscribedEvents() {
$events[AcquiaContentHubEvents::PUBLISH_ENTITIES][] = [
'onPublishEntities',
1000,
];
return $events;
}
public function onPublishEntities(ContentHubPublishEntitiesEvent $event) {
$dependencies = $event
->getDependencies();
$uuids = array_keys($dependencies);
$query = $this->database
->select('acquia_contenthub_publisher_export_tracking', 't')
->fields('t', [
'entity_uuid',
'hash',
]);
$query
->condition('t.entity_uuid', $uuids, 'IN');
$query
->condition('t.status', [
PublisherTracker::CONFIRMED,
PublisherTracker::EXPORTED,
], 'IN');
$results = $query
->execute();
foreach ($results as $result) {
if (!$result->hash) {
continue;
}
$wrapper = $dependencies[$result->entity_uuid];
if ($wrapper
->getHash() == $result->hash) {
$event
->removeDependency($result->entity_uuid);
}
}
}
}