You are here

function simplenews_newsletter_update_sent_status in Simplenews 7

Update the sent status of a node.

If the node part of a translation set, all corresponding translations are updated as well.

Parameters

$node: The node object to be updated.

$status: The new status, defaults to SIMPLENEWS_STATUS_SEND_PENDING.

Related topics

2 calls to simplenews_newsletter_update_sent_status()
simplenews_add_node_to_spool in includes/simplenews.mail.inc
Add the newsletter node to the mail spool.
simplenews_issue_send in includes/simplenews.admin.inc
Callback to send newsletters.

File

./simplenews.module, line 2561
Simplenews node handling, sent email, newsletter block and general hooks

Code

function simplenews_newsletter_update_sent_status($node, $status = SIMPLENEWS_STATUS_SEND_PENDING) {

  // When this node is selected for translation, all translation of this node
  // will be sent too.
  if (module_exists('translation') && translation_supported_type($node->type) && $node->tnid > 0) {
    if ($translations = translation_node_get_translations($node->tnid)) {
      foreach ($translations as $translation) {
        $newsletter = simplenews_newsletter_load($translation->nid);
        if (!$newsletter) {
          $node = node_load($translation->nid);
          $newsletter = (object) simplenews_newsletter_defaults($node);
        }
        $newsletter->status = SIMPLENEWS_STATUS_SEND_PENDING;
        simplenews_newsletter_save($newsletter);
      }
    }
  }
  if (!empty($node->simplenews)) {
    $newsletter = $node->simplenews;
  }
  else {
    $newsletter = simplenews_newsletter_load($node->nid);
  }
  if (!$newsletter) {
    $newsletter = (object) simplenews_newsletter_defaults($node);
  }
  $newsletter->status = $status;
  simplenews_newsletter_save($newsletter);
}