You are here

class ScheduledRuleProcessor in RNG - Events and Registrations 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/QueueWorker/ScheduledRuleProcessor.php \Drupal\rng\Plugin\QueueWorker\ScheduledRuleProcessor
  2. 3.x src/Plugin/QueueWorker/ScheduledRuleProcessor.php \Drupal\rng\Plugin\QueueWorker\ScheduledRuleProcessor

Triggers scheduled rules.

Plugin annotation


@QueueWorker(
  id = "rng_rule_scheduler",
  title = @Translation("Scheduled rule processor"),
  cron = {"time" = 60}
)

Hierarchy

Expanded class hierarchy of ScheduledRuleProcessor

File

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

Namespace

Drupal\rng\Plugin\QueueWorker
View source
class ScheduledRuleProcessor extends QueueWorkerBase implements ContainerFactoryPluginInterface {

  /**
   * The RNG event manager.
   *
   * @var \Drupal\rng\EventManagerInterface
   */
  protected $eventManager;

  /**
   * Constructs a ScheduledRuleProcessor object.
   *
   * @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\rng\EventManagerInterface $event_manager
   *   The RNG event manager.
   */
  public function __construct(array $configuration, $plugin_id, array $plugin_definition, EventManagerInterface $event_manager) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->eventManager = $event_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('rng.event_manager'));
  }

  /**
   * {@inheritdoc}
   *
   * @param integer $data['rule_scheduler_id']
   *   ID of a rule component entity.
   */
  public function processItem($data) {
    if (!isset($data['rule_scheduler_id'])) {
      return;
    }
    if (!($rule_schedule = RuleSchedule::load($data['rule_scheduler_id']))) {
      return;
    }
    $rule_schedule
      ->incrementAttempts();
    $rule_schedule
      ->save();
    if (($component = $rule_schedule
      ->getComponent()) && ($rule = $component
      ->getRule())) {
      $event = $rule
        ->getEvent();
      $event_meta = $this->eventManager
        ->getMeta($event);
      $context = [
        'event' => $event,
        'registrations' => $event_meta
          ->getRegistrations(),
      ];
      foreach ($rule
        ->getActions() as $action) {
        $action
          ->execute($context);
      }
      $rule_schedule
        ->delete();
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
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.
ScheduledRuleProcessor::$eventManager protected property The RNG event manager.
ScheduledRuleProcessor::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create
ScheduledRuleProcessor::processItem public function Overrides QueueWorkerInterface::processItem
ScheduledRuleProcessor::__construct public function Constructs a ScheduledRuleProcessor object. Overrides PluginBase::__construct