class EntityShareAsyncWorker in Entity Share 8.3
Same name and namespace in other branches
- 8.2 modules/entity_share_async/src/Plugin/QueueWorker/EntityShareAsyncWorker.php \Drupal\entity_share_async\Plugin\QueueWorker\EntityShareAsyncWorker
Asynchronous import queue worker.
Plugin annotation
@QueueWorker(
id = "entity_share_async_import",
title = @Translation("Entity Share asynchronous import"),
cron = {"time" = 30}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Queue\QueueWorkerBase implements QueueWorkerInterface
- class \Drupal\entity_share_async\Plugin\QueueWorker\EntityShareAsyncWorker implements ContainerFactoryPluginInterface
- class \Drupal\Core\Queue\QueueWorkerBase implements QueueWorkerInterface
Expanded class hierarchy of EntityShareAsyncWorker
File
- modules/
entity_share_async/ src/ Plugin/ QueueWorker/ EntityShareAsyncWorker.php, line 25
Namespace
Drupal\entity_share_async\Plugin\QueueWorkerView source
class EntityShareAsyncWorker extends QueueWorkerBase implements ContainerFactoryPluginInterface {
/**
* Logger.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* The import service.
*
* @var \Drupal\entity_share_client\Service\ImportServiceInterface
*/
private $importService;
/**
* The state storage.
*
* @var \Drupal\Core\State\StateInterface
*/
private $stateStorage;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerInterface $logger, ImportServiceInterface $import_service, StateInterface $state_storage) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->logger = $logger;
$this->importService = $import_service;
$this->stateStorage = $state_storage;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('logger.channel.entity_share_async'), $container
->get('entity_share_client.import_service'), $container
->get('state'));
}
/**
* {@inheritdoc}
*/
public function processItem($item) {
$async_states = $this->stateStorage
->get(QueueHelperInterface::STATE_ID, []);
// Import the entity.
$import_context = new ImportContext($item['remote_id'], $item['channel_id'], $item['import_config_id']);
$ids = $this->importService
->importEntities($import_context, [
$item['uuid'],
], FALSE);
if (empty($ids)) {
$this->logger
->warning("Cannot synchronize item @uuid from channel @channel_id of remote @remote_id with the import config @import_config_id", [
'@uuid' => $item['uuid'],
'@channel_id' => $item['channel_id'],
'@remote_id' => $item['remote_id'],
'@import_config_id' => $item['import_config_id'],
]);
}
if (isset($async_states[$item['remote_id']][$item['channel_id']][$item['uuid']])) {
unset($async_states[$item['remote_id']][$item['channel_id']][$item['uuid']]);
}
// Update states.
$this->stateStorage
->set(QueueHelperInterface::STATE_ID, $async_states);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityShareAsyncWorker:: |
private | property | The import service. | |
EntityShareAsyncWorker:: |
protected | property | Logger. | |
EntityShareAsyncWorker:: |
private | property | The state storage. | |
EntityShareAsyncWorker:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
EntityShareAsyncWorker:: |
public | function |
Works on a single queue item. Overrides QueueWorkerInterface:: |
|
EntityShareAsyncWorker:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. |