You are here

public function RemoveUnmodifiedEntities::onPublishEntities in Acquia Content Hub 8.2

Removes unmodified entities before publishing.

Parameters

\Drupal\acquia_contenthub\Event\ContentHubPublishEntitiesEvent $event: The Content Hub publish entities event.

File

modules/acquia_contenthub_publisher/src/EventSubscriber/PublishEntities/RemoveUnmodifiedEntities.php, line 50

Class

RemoveUnmodifiedEntities
Removes unmodified entities from export.

Namespace

Drupal\acquia_contenthub_publisher\EventSubscriber\PublishEntities

Code

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) {

    // Can't check it if it doesn't have a hash.
    // @todo make this a query.
    if (!$result->hash) {
      continue;
    }
    $wrapper = $dependencies[$result->entity_uuid];
    if ($wrapper
      ->getHash() == $result->hash) {
      $event
        ->removeDependency($result->entity_uuid);
    }
  }
}