You are here

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

Expanded class hierarchy of DelayedRequestDispatcher

File

src/Plugin/QueueWorker/DelayedRequestDispatcher.php, line 20

Namespace

Drupal\email_confirmer\Plugin\QueueWorker
View 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

Namesort descending Modifiers Type Description Overrides
DelayedRequestDispatcher::$already protected property Already processed items.
DelayedRequestDispatcher::$entityTypeManager protected property The entity type manager.
DelayedRequestDispatcher::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
DelayedRequestDispatcher::processItem public function Works on a single queue item. Overrides QueueWorkerInterface::processItem
DelayedRequestDispatcher::__construct public function Creates a new DelayedRequestDispatcher object. Overrides PluginBase::__construct
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 3
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.