class EntityUsageRegenerateTrackingInfoWorker in Entity Usage 8.2
RegenerateTrackingInfoWorker class.
A worker plugin to consume items from "entity_usage_regenerate_queue" and regenerate tracking info for each of them.
Plugin annotation
@QueueWorker(
id = "entity_usage_regenerate_queue",
title = @Translation("Entity Usage Regenerate Tracking Queue"),
cron = {"time" = 60}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Queue\QueueWorkerBase implements QueueWorkerInterface
- class \Drupal\entity_usage\Plugin\QueueWorker\EntityUsageRegenerateTrackingInfoWorker implements ContainerFactoryPluginInterface
- class \Drupal\Core\Queue\QueueWorkerBase implements QueueWorkerInterface
Expanded class hierarchy of EntityUsageRegenerateTrackingInfoWorker
File
- src/
Plugin/ QueueWorker/ EntityUsageRegenerateTrackingInfoWorker.php, line 24
Namespace
Drupal\entity_usage\Plugin\QueueWorkerView source
class EntityUsageRegenerateTrackingInfoWorker extends QueueWorkerBase implements ContainerFactoryPluginInterface {
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The logger channel factory.
*
* @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
*/
protected $logger;
/**
* The Entity Usage update manager service.
*
* @var \Drupal\entity_usage\EntityUpdateManager
*/
protected $entityUsageUpdateManager;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, LoggerChannelFactoryInterface $logger_factory, EntityUpdateManager $track_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
$this->logger = $logger_factory
->get('entity_usage');
$this->entityUsageUpdateManager = $track_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'), $container
->get('logger.factory'), $container
->get('entity_usage.entity_update_manager'));
}
/**
* {@inheritdoc}
*/
public function processItem($data) {
// $data here is expected to contain
// - 'entity_type': always present;
// - 'entity_id': present when the entity isn't revisionable;
// - 'entity_revision_id': present when the entity is revisionable;
if (empty($data['entity_type']) || empty($data['entity_id']) && empty($data['entity_revision_id'])) {
// Just skip this item.
return;
}
$storage = $this->entityTypeManager
->getStorage($data['entity_type']);
if ($storage
->getEntityType()
->isRevisionable() && !empty($data['entity_revision_id'])) {
$entity = $storage
->loadRevision($data['entity_revision_id']);
}
elseif (!empty($data['entity_id'])) {
$entity = $storage
->load($data['entity_id']);
}
if ($entity) {
try {
$this->entityUsageUpdateManager
->trackUpdateOnCreation($entity);
} catch (\Exception $e) {
$this->logger
->warning("An error occurred when tracking usage info for entity with data: @data. Error message: {$e->getMessage()}", [
'@data' => json_encode($data),
]);
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityUsageRegenerateTrackingInfoWorker:: |
protected | property | The entity type manager service. | |
EntityUsageRegenerateTrackingInfoWorker:: |
protected | property | The Entity Usage update manager service. | |
EntityUsageRegenerateTrackingInfoWorker:: |
protected | property | The logger channel factory. | |
EntityUsageRegenerateTrackingInfoWorker:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
EntityUsageRegenerateTrackingInfoWorker:: |
public | function |
Works on a single queue item. Overrides QueueWorkerInterface:: |
|
EntityUsageRegenerateTrackingInfoWorker:: |
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. |