You are here

class QueueHelper in Entity Share 8.3

Same name and namespace in other branches
  1. 8.2 modules/entity_share_async/src/Service/QueueHelper.php \Drupal\entity_share_async\Service\QueueHelper

Populate a queue for asynchronous treatment.

@package Drupal\entity_share_async\Service

Hierarchy

Expanded class hierarchy of QueueHelper

1 string reference to 'QueueHelper'
entity_share_async.services.yml in modules/entity_share_async/entity_share_async.services.yml
modules/entity_share_async/entity_share_async.services.yml
1 service uses QueueHelper
entity_share_async.queue_helper in modules/entity_share_async/entity_share_async.services.yml
Drupal\entity_share_async\Service\QueueHelper

File

modules/entity_share_async/src/Service/QueueHelper.php, line 15

Namespace

Drupal\entity_share_async\Service
View source
class QueueHelper implements QueueHelperInterface {

  /**
   * The queue factory service.
   *
   * @var \Drupal\Core\Queue\QueueFactory
   */
  protected $queueFactory;

  /**
   * The state service.
   *
   * @var \Drupal\Core\State\StateInterface
   */
  protected $state;

  /**
   * QueueHelper constructor.
   *
   * @param \Drupal\Core\Queue\QueueFactory $queue_factory
   *   The queue factory service.
   * @param \Drupal\Core\State\StateInterface $state
   *   The state service.
   */
  public function __construct(QueueFactory $queue_factory, StateInterface $state) {
    $this->queueFactory = $queue_factory;
    $this->state = $state;
  }

  /**
   * {@inheritdoc}
   */
  public function enqueue($remote_id, $channel_id, $import_config_id, array $uuids) {
    $queue = $this->queueFactory
      ->get(QueueHelperInterface::QUEUE_NAME);
    $async_states = $this->state
      ->get(QueueHelperInterface::STATE_ID, []);
    foreach ($uuids as $uuid) {
      if (!isset($async_states[$remote_id][$channel_id][$uuid])) {

        // Add the entity to the async states.
        $async_states[$remote_id][$channel_id][$uuid] = $import_config_id;

        // Create queue item.
        $item = [
          'uuid' => $uuid,
          'remote_id' => $remote_id,
          'channel_id' => $channel_id,
          'import_config_id' => $import_config_id,
        ];
        $queue
          ->createItem($item);
      }
    }

    // Update states.
    $this->state
      ->set(QueueHelperInterface::STATE_ID, $async_states);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
QueueHelper::$queueFactory protected property The queue factory service.
QueueHelper::$state protected property The state service.
QueueHelper::enqueue public function Enqueue entity to be synced later. Overrides QueueHelperInterface::enqueue
QueueHelper::__construct public function QueueHelper constructor.
QueueHelperInterface::QUEUE_NAME constant The queue ID.
QueueHelperInterface::STATE_ID constant The state ID.