QueueHelper.php in Entity Share 8.2
File
modules/entity_share_async/src/Service/QueueHelper.php
View source
<?php
declare (strict_types=1);
namespace Drupal\entity_share_async\Service;
use Drupal\Core\Queue\QueueFactory;
use Drupal\Core\State\StateInterface;
class QueueHelper implements QueueHelperInterface {
protected $queueFactory;
protected $state;
public function __construct(QueueFactory $queue_factory, StateInterface $state) {
$this->queueFactory = $queue_factory;
$this->state = $state;
}
public function enqueue($remote_id, $channel_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])) {
$async_states[$remote_id][$channel_id][$uuid] = $uuid;
$item = [
'uuid' => $uuid,
'remote_id' => $remote_id,
'channel_id' => $channel_id,
];
$queue
->createItem($item);
}
}
$this->state
->set(QueueHelperInterface::STATE_ID, $async_states);
}
}