You are here

class IsAlreadyEnqueued in Acquia Content Hub 8.2

Any entity that is already in the export queue shouldn't be enqueued.

@package Drupal\acquia_contenthub_publisher\EventSubscriber\EnqueueEligibility

Hierarchy

  • class \Drupal\acquia_contenthub_publisher\EventSubscriber\EnqueueEligibility\IsAlreadyEnqueued implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of IsAlreadyEnqueued

1 string reference to 'IsAlreadyEnqueued'
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 IsAlreadyEnqueued
entity_is_queued.enqueue in modules/acquia_contenthub_publisher/acquia_contenthub_publisher.services.yml
Drupal\acquia_contenthub_publisher\EventSubscriber\EnqueueEligibility\IsAlreadyEnqueued

File

modules/acquia_contenthub_publisher/src/EventSubscriber/EnqueueEligibility/IsAlreadyEnqueued.php, line 17

Namespace

Drupal\acquia_contenthub_publisher\EventSubscriber\EnqueueEligibility
View source
class IsAlreadyEnqueued implements EventSubscriberInterface {

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

  /**
   * The publisher tracker.
   *
   * @var \Drupal\acquia_contenthub_publisher\PublisherTracker
   */
  protected $tracker;

  /**
   * IsAlreadyEnqueued constructor.
   *
   * @param \Drupal\Core\Database\Connection $database
   *   The database connection.
   * @param \Drupal\acquia_contenthub_publisher\PublisherTracker $tracker
   *   The publisher tracker.
   */
  public function __construct(Connection $database, PublisherTracker $tracker) {
    $this->database = $database;
    $this->tracker = $tracker;
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events[ContentHubPublisherEvents::ENQUEUE_CANDIDATE_ENTITY][] = [
      'onEnqueueCandidateEntity',
      50,
    ];
    return $events;
  }

  /**
   * Prevents entities already in the export queue to be enqueued again.
   *
   * @param \Drupal\acquia_contenthub_publisher\Event\ContentHubEntityEligibilityEvent $event
   *   The event to determine entity eligibility.
   *
   * @throws \Exception
   */
  public function onEnqueueCandidateEntity(ContentHubEntityEligibilityEvent $event) {
    $uuid = $event
      ->getEntity()
      ->uuid();
    if (!Uuid::isValid($uuid)) {
      return;
    }

    // Get the queue_id from the tracker first.
    $item_id = $this->tracker
      ->getQueueId($uuid);
    if (!empty($item_id)) {

      // This entity is already in the export queue. Log about it?
      $event
        ->setEligibility(FALSE);
      $event
        ->stopPropagation();
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
IsAlreadyEnqueued::$database protected property The database connection.
IsAlreadyEnqueued::$tracker protected property The publisher tracker.
IsAlreadyEnqueued::getSubscribedEvents public static function Returns an array of event names this subscriber wants to listen to.
IsAlreadyEnqueued::onEnqueueCandidateEntity public function Prevents entities already in the export queue to be enqueued again.
IsAlreadyEnqueued::__construct public function IsAlreadyEnqueued constructor.