You are here

protected function Cron::enqueueSubscriptions in Commerce Recurring Framework 8

Enqueues pending and trial subscriptions for activation.

Parameters

\Drupal\advancedqueue\Entity\QueueInterface $recurring_queue: The recurring queue.

1 call to Cron::enqueueSubscriptions()
Cron::run in src/Cron.php
Runs the cron.

File

src/Cron.php, line 127

Class

Cron
Default cron implementation.

Namespace

Drupal\commerce_recurring

Code

protected function enqueueSubscriptions(QueueInterface $recurring_queue) {
  $subscription_storage = $this->entityTypeManager
    ->getStorage('commerce_subscription');
  $subscription_ids = $subscription_storage
    ->getQuery()
    ->condition('state', [
    'pending',
    'trial',
  ], 'IN')
    ->condition('starts', $this->time
    ->getRequestTime(), '<=')
    ->accessCheck(FALSE)
    ->execute();
  if (!$subscription_ids) {
    return;
  }
  foreach ($subscription_ids as $subscription_id) {
    $activate_job = Job::create('commerce_subscription_activate', [
      'subscription_id' => $subscription_id,
    ]);
    $recurring_queue
      ->enqueueJob($activate_job);
  }
}