You are here

protected function UserMailQueueProcessor::lastItem in Open Social 8.9

Same name and namespace in other branches
  1. 8.8 modules/social_features/social_user/src/Plugin/QueueWorker/UserMailQueueProcessor.php \Drupal\social_user\Plugin\QueueWorker\UserMailQueueProcessor::lastItem()
  2. 10.3.x modules/social_features/social_user/src/Plugin/QueueWorker/UserMailQueueProcessor.php \Drupal\social_user\Plugin\QueueWorker\UserMailQueueProcessor::lastItem()
  3. 10.0.x modules/social_features/social_user/src/Plugin/QueueWorker/UserMailQueueProcessor.php \Drupal\social_user\Plugin\QueueWorker\UserMailQueueProcessor::lastItem()
  4. 10.1.x modules/social_features/social_user/src/Plugin/QueueWorker/UserMailQueueProcessor.php \Drupal\social_user\Plugin\QueueWorker\UserMailQueueProcessor::lastItem()
  5. 10.2.x modules/social_features/social_user/src/Plugin/QueueWorker/UserMailQueueProcessor.php \Drupal\social_user\Plugin\QueueWorker\UserMailQueueProcessor::lastItem()

Check if this item is last.

Parameters

string $mail_id: The email ID that is in the batch.

Return value

int The remaining number.

1 call to UserMailQueueProcessor::lastItem()
UserMailQueueProcessor::processItem in modules/social_features/social_user/src/Plugin/QueueWorker/UserMailQueueProcessor.php
Works on a single queue item.

File

modules/social_features/social_user/src/Plugin/QueueWorker/UserMailQueueProcessor.php, line 188

Class

UserMailQueueProcessor
Queue worker to process email to users.

Namespace

Drupal\social_user\Plugin\QueueWorker

Code

protected function lastItem($mail_id) {

  // Escape the condition values.
  $item_type = $this->connection
    ->escapeLike('mail');
  $item_id = $this->connection
    ->escapeLike($mail_id);

  // Get all queue items from the queue worker.
  $query = $this->connection
    ->select('queue', 'q');
  $query
    ->fields('q', [
    'data',
    'name',
  ]);

  // Plugin name is queue name.
  $query
    ->condition('q.name', 'user_email_queue');

  // Add conditions for the item type and item mail id's.
  // This is not exact but an educated guess as there can be user id's in the
  // data that could contain the item id.
  $query
    ->condition('q.data', '%' . $item_type . '%', 'LIKE');
  $query
    ->condition('q.data', '%' . $item_id . '%', 'LIKE');
  $results = (int) $query
    ->countQuery()
    ->execute()
    ->fetchField();

  // Return TRUE when last item.
  return !($results !== 1);
}