You are here

function simplenews_add_node_to_spool in Simplenews 7.2

Same name and namespace in other branches
  1. 7 includes/simplenews.mail.inc \simplenews_add_node_to_spool()

Add the newsletter node to the mail spool.

Parameters

$node: The newsletter node to be sent.

Related topics

11 calls to simplenews_add_node_to_spool()
SimplenewsSendTestCase::testProgrammaticNewsletter in tests/simplenews.test
Creates and sends a node using the API.
SimplenewsSourceTestCase::testSendCaching in tests/simplenews.test
Test sending a newsletter to 100 recipients with caching enabled.
SimplenewsSourceTestCase::testSendHidden in tests/simplenews.test
Send a issue with the newsletter set to hidden.
SimplenewsSourceTestCase::testSendHTML in tests/simplenews.test
Send a newsletter with the HTML format.
SimplenewsSourceTestCase::testSendMissingNode in tests/simplenews.test
Test with disabled caching.

... See full list

File

includes/simplenews.mail.inc, line 18
Simplenews email send and spool handling

Code

function simplenews_add_node_to_spool($node) {
  $newsletter = simplenews_newsletter_load(simplenews_issue_newsletter_id($node));
  $handler = simplenews_issue_handler($node);
  $handler_settings = simplenews_issue_handler_settings($node);
  $recipient_handler = simplenews_get_recipient_handler($newsletter, $handler, $handler_settings);

  // To send the newsletter, the node id and target email addresses
  // are stored in the spool.
  // Only subscribed recipients are stored in the spool (status = 1).
  $select = $recipient_handler
    ->buildRecipientQuery();
  $select
    ->addExpression('\'node\'', 'entity_type');
  $select
    ->addExpression($node->nid, 'entity_id');
  $select
    ->addExpression(SIMPLENEWS_SUBSCRIPTION_STATUS_SUBSCRIBED, 'status');
  $select
    ->addExpression(REQUEST_TIME, 'timestamp');
  db_insert('simplenews_mail_spool')
    ->from($select)
    ->execute();

  // Update simplenews newsletter status to send pending.
  simplenews_issue_update_sent_status($node);

  // Notify other modules that a newsletter was just spooled.
  module_invoke_all('simplenews_spooled', $node);
}