You are here

public function SmsQueueProcessor::processUnqueued in SMS Framework 8

Same name and namespace in other branches
  1. 2.x src/Provider/SmsQueueProcessor.php \Drupal\sms\Provider\SmsQueueProcessor::processUnqueued()
  2. 2.1.x src/Provider/SmsQueueProcessor.php \Drupal\sms\Provider\SmsQueueProcessor::processUnqueued()

Check for messages not in the Drupal queue and add them.

@todo rename?

Overrides SmsQueueProcessorInterface::processUnqueued

File

src/Provider/SmsQueueProcessor.php, line 62

Class

SmsQueueProcessor
The SMS Queue Processor.

Namespace

Drupal\sms\Provider

Code

public function processUnqueued() {

  /** @var \Drupal\sms\Entity\SmsGatewayInterface $sms_gateway */
  $ids = [];
  foreach ($this->smsGatewayStorage
    ->loadMultiple() as $sms_gateway) {
    $query = $this->smsMessageStorage
      ->getQuery()
      ->condition('gateway', $sms_gateway
      ->id(), '=')
      ->condition('queued', 0, '=')
      ->condition('processed', NULL, 'IS NULL');
    if (!$sms_gateway
      ->isScheduleAware()) {
      $query
        ->condition('send_on', REQUEST_TIME, '<=');
    }
    $ids += $query
      ->execute();
  }

  /** @var \Drupal\sms\Entity\SmsMessageInterface $sms_message */
  foreach ($this->smsMessageStorage
    ->loadMultiple($ids) as $sms_message) {
    $data = [
      'id' => $sms_message
        ->id(),
    ];
    if ($this->queue
      ->createItem($data)) {
      $sms_message
        ->setQueued(TRUE)
        ->save();
    }
  }
}