protected function RngCron::scheduleRules in RNG - Events and Registrations 8
Same name and namespace in other branches
- 8.2 src/RngCron.php \Drupal\rng\RngCron::scheduleRules()
- 3.x src/RngCron.php \Drupal\rng\RngCron::scheduleRules()
Add scheduled rules to be executed to the queue.
1 call to RngCron::scheduleRules()
- RngCron::hook_cron in src/
RngCron.php - React to Drupal `hook_cron` hooks.
File
- src/
RngCron.php, line 54
Class
- RngCron
- RNG Cron.
Namespace
Drupal\rngCode
protected function scheduleRules() {
$ids = $this->ruleSchedulerStorage
->getQuery()
->condition('trigger_date', time(), '<=')
->condition('in_queue', 0, '=')
->condition('attempts', RuleSchedule::ATTEMPTS_MAX, '<=')
->execute();
/** @var \Drupal\rng\RuleScheduleInterface[] $rule_schedules */
$rule_schedules = $this->ruleSchedulerStorage
->loadMultiple($ids);
foreach ($rule_schedules as $rule_schedule) {
$data = [
'rule_scheduler_id' => $rule_schedule
->id(),
];
if ($this->ruleSchedulerQueue
->createItem($data)) {
$rule_schedule
->setInQueue(TRUE)
->save();
// De-activate the rule once it is queued.
if ($component = $rule_schedule
->getComponent()) {
if ($rule = $component
->getRule()) {
$rule
->setIsActive(FALSE)
->save();
}
}
}
}
}