class DelayedRequestDispatcher in Email confirmer 8
Process queued confirmation requests on CRON run.
Plugin annotation
@QueueWorker(
id = "email_confirmer_requests",
title = @Translation("Delayed confirmation request dispatcher"),
cron = {"time" = 5}
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Queue\QueueWorkerBase implements QueueWorkerInterface
- class \Drupal\email_confirmer\Plugin\QueueWorker\DelayedRequestDispatcher implements ContainerFactoryPluginInterface
- class \Drupal\Core\Queue\QueueWorkerBase implements QueueWorkerInterface
Expanded class hierarchy of DelayedRequestDispatcher
File
- src/
Plugin/ QueueWorker/ DelayedRequestDispatcher.php, line 20
Namespace
Drupal\email_confirmer\Plugin\QueueWorkerView source
class DelayedRequestDispatcher extends QueueWorkerBase implements ContainerFactoryPluginInterface {
/**
* Already processed items.
*
* @var array
*/
protected $already;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Creates a new DelayedRequestDispatcher object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->already = [];
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($container
->get('entity_type.manager'));
}
/**
* {@inheritdoc}
*/
public function processItem($data) {
// Ignore dupes.
if (isset($this->already[$data])) {
return;
}
// Delivery pendings requests.
/** @var \Drupal\email_confirmer\EmailConfirmationInterface $confirmation */
$confirmation = $this->entityTypeManager
->getStorage('email_confirmer_confirmation')
->load($data);
if (!$confirmation) {
return;
}
if ($confirmation
->getCreatedTime() + intval(\Drupal::config('email_confirmer.settings')
->get('resendrequest_delay')) < \Drupal::time()
->getRequestTime()) {
throw new RequeueException('Early confirmation request re-send');
}
// Remember already processed.
$this->already[$data] = $data;
// Deliver the confirmation request.
if ($confirmation
->isPending() && $confirmation
->setLastRequestDate(NULL)
->sendRequest()) {
$confirmation
->save();
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DelayedRequestDispatcher:: |
protected | property | Already processed items. | |
DelayedRequestDispatcher:: |
protected | property | The entity type manager. | |
DelayedRequestDispatcher:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
DelayedRequestDispatcher:: |
public | function |
Works on a single queue item. Overrides QueueWorkerInterface:: |
|
DelayedRequestDispatcher:: |
public | function |
Creates a new DelayedRequestDispatcher 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. |