You are here

public function RecipientHandlerSelectBase::addToSpool in Simplenews 8.2

Same name and namespace in other branches
  1. 3.x src/Plugin/simplenews/RecipientHandler/RecipientHandlerSelectBase.php \Drupal\simplenews\Plugin\simplenews\RecipientHandler\RecipientHandlerSelectBase::addToSpool()

Adds a newsletter issue to the mail spool.

Return value

int Number of recipients added.

Overrides RecipientHandlerInterface::addToSpool

File

src/Plugin/simplenews/RecipientHandler/RecipientHandlerSelectBase.php, line 17

Class

RecipientHandlerSelectBase
Base for Recipient Handlers that access the database directly using Select.

Namespace

Drupal\simplenews\Plugin\simplenews\RecipientHandler

Code

public function addToSpool() {
  $entity_type = $this->issue
    ->getEntityTypeId();
  $query = $this
    ->buildRecipientQuery();
  $query
    ->addExpression("'{$entity_type}'", 'entity_type');
  $query
    ->addExpression($this->issue
    ->id(), 'entity_id');
  $query
    ->addExpression(SIMPLENEWS_SUBSCRIPTION_STATUS_SUBSCRIBED, 'status');
  $query
    ->addExpression(REQUEST_TIME, 'timestamp');
  $this->connection
    ->insert('simplenews_mail_spool')
    ->from($query)
    ->execute();
  return $query
    ->countQuery()
    ->execute()
    ->fetchField();
}