You are here

public function QueueHelper::enqueue in Entity Share 8.2

Same name and namespace in other branches
  1. 8.3 modules/entity_share_async/src/Service/QueueHelper.php \Drupal\entity_share_async\Service\QueueHelper::enqueue()

Enqueue entity to be synced later.

Parameters

string $remote_id: The remote ID.

string $channel_id: The channel ID.

string[] $uuids: The UUIDs of the entities to pull.

Overrides QueueHelperInterface::enqueue

File

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

Class

QueueHelper
Class QueueHelper.

Namespace

Drupal\entity_share_async\Service

Code

public function enqueue($remote_id, $channel_id, array $uuids) {

  /** @var \Drupal\Core\Queue\QueueInterface $queue */
  $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] = $uuid;

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

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