class FileLinkMetadataUpdate in File Link 2.0.x
Defines 'file_link_metadata_update' queue worker.
Plugin annotation
@QueueWorker(
id = "file_link_metadata_update",
title = @Translation("File Link Metadata Update"),
cron = {"time" = 60}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Queue\QueueWorkerBase implements QueueWorkerInterface
- class \Drupal\file_link\Plugin\QueueWorker\FileLinkMetadataUpdate implements ContainerFactoryPluginInterface
- class \Drupal\Core\Queue\QueueWorkerBase implements QueueWorkerInterface
Expanded class hierarchy of FileLinkMetadataUpdate
2 files declare their use of FileLinkMetadataUpdate
- FileLinkItem.php in src/
Plugin/ Field/ FieldType/ FileLinkItem.php - LinkToFileConstraint.php in src/
Plugin/ Validation/ Constraint/ LinkToFileConstraint.php
File
- src/
Plugin/ QueueWorker/ FileLinkMetadataUpdate.php, line 21
Namespace
Drupal\file_link\Plugin\QueueWorkerView source
class FileLinkMetadataUpdate extends QueueWorkerBase implements ContainerFactoryPluginInterface {
/**
* Counter of processing queue workers.
*
* @var int
*/
protected static $processing = 0;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* FileLinkMetadataUpdate constructor.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entityTypeManager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entityTypeManager;
}
/**
* {@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'));
}
/**
* {@inheritdoc}
*/
public function processItem($data) {
if ($data instanceof FileLinkQueueItem) {
$storage = $this->entityTypeManager
->getStorage($data
->getType());
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
if ($data
->getRevisionId() !== NULL) {
$entity = $storage
->loadRevision($data
->getRevisionId());
}
else {
$entity = $storage
->load($data
->getId());
}
if ($entity === NULL) {
// The entity must have been removed.
return;
}
if ($entity
->hasTranslation($data
->getLang())) {
$entity = $entity
->getTranslation($data
->getLang());
}
// Do not create a revision but re-save the revision.
if ($entity
->getEntityType()
->isRevisionable()) {
$entity
->setNewRevision(FALSE);
}
if ($entity instanceof EntityChangedInterface) {
if ($entity
->getChangedTime() > $data
->getTime()) {
// The entity has been changed since.
return;
}
// Do not update the changed time here.
$entity
->setChangedTime($entity
->getChangedTime());
}
// Set the static property to be processing.
static::$processing++;
try {
$entity
->save();
} catch (\Exception $exception) {
// Decrease the counter and re-throw the exception.
static::$processing--;
throw $exception;
}
static::$processing--;
}
}
/**
* Indication of whether the queue is processing.
*
* @return bool
* True if the queue worker is processing.
*/
public static function isProcessing() : bool {
return static::$processing > 0;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FileLinkMetadataUpdate:: |
protected | property | The entity type manager. | |
FileLinkMetadataUpdate:: |
protected static | property | Counter of processing queue workers. | |
FileLinkMetadataUpdate:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
FileLinkMetadataUpdate:: |
public static | function | Indication of whether the queue is processing. | |
FileLinkMetadataUpdate:: |
public | function |
Works on a single queue item. Overrides QueueWorkerInterface:: |
|
FileLinkMetadataUpdate:: |
public | function |
FileLinkMetadataUpdate constructor. 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:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. |