You are here

public function QueueHelper::enqueue 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::enqueue()

Enqueue entity to be synced later.

Parameters

string $remote_id: The remote ID.

string $channel_id: The channel ID.

string $import_config_id: The import config 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
Populate a queue for asynchronous treatment.

Namespace

Drupal\entity_share_async\Service

Code

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);
}