You are here

class RemoveUnmodifiedEntities in Acquia Content Hub 8.2

Removes unmodified entities from export.

@package Drupal\acquia_contenthub_publisher\EventSubscriber\PublishEntities

Hierarchy

  • class \Drupal\acquia_contenthub_publisher\EventSubscriber\PublishEntities\RemoveUnmodifiedEntities implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of RemoveUnmodifiedEntities

1 string reference to 'RemoveUnmodifiedEntities'
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 RemoveUnmodifiedEntities
remove_unmodified_entities.publish in modules/acquia_contenthub_publisher/acquia_contenthub_publisher.services.yml
Drupal\acquia_contenthub_publisher\EventSubscriber\PublishEntities\RemoveUnmodifiedEntities

File

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

Namespace

Drupal\acquia_contenthub_publisher\EventSubscriber\PublishEntities
View source
class RemoveUnmodifiedEntities implements EventSubscriberInterface {

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

  /**
   * RemoveUnmodifiedEntities 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::PUBLISH_ENTITIES][] = [
      'onPublishEntities',
      1000,
    ];
    return $events;
  }

  /**
   * Removes unmodified entities before publishing.
   *
   * @param \Drupal\acquia_contenthub\Event\ContentHubPublishEntitiesEvent $event
   *   The Content Hub publish entities event.
   */
  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);
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RemoveUnmodifiedEntities::$database protected property The database connection.
RemoveUnmodifiedEntities::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
RemoveUnmodifiedEntities::onPublishEntities public function Removes unmodified entities before publishing.
RemoveUnmodifiedEntities::__construct public function RemoveUnmodifiedEntities constructor.