ScheduledRuleProcessor.php in RNG - Events and Registrations 3.x
File
src/Plugin/QueueWorker/ScheduledRuleProcessor.php
View source
<?php
namespace Drupal\rng\Plugin\QueueWorker;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Queue\QueueWorkerBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\rng\EventManagerInterface;
use Drupal\rng\Entity\RuleSchedule;
class ScheduledRuleProcessor extends QueueWorkerBase implements ContainerFactoryPluginInterface {
protected $eventManager;
public function __construct(array $configuration, $plugin_id, array $plugin_definition, EventManagerInterface $event_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->eventManager = $event_manager;
}
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'));
}
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();
}
}
}