You are here

function simplenews_node_update in Simplenews 7

Same name and namespace in other branches
  1. 7.2 simplenews.module \simplenews_node_update()

Implements hook_node_update().

File

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

Code

function simplenews_node_update($node) {
  if (!simplenews_check_node_types($node->type)) {
    return;
  }
  $node->simplenews = simplenews_newsletter_load($node->nid);
  if (!$node->simplenews) {
    $node->simplenews = (object) simplenews_newsletter_defaults($node);
  }
  else {

    // Update tid.
    $terms = simplenews_get_term_values($node);
    $node->simplenews->tid = $terms[0]['tid'];
  }

  // Check if the newsletter is set to send on publish and needs to be send.
  if ($node->simplenews->status == SIMPLENEWS_STATUS_SEND_PUBLISH && $node->status == NODE_PUBLISHED) {
    module_load_include('inc', 'simplenews', 'includes/simplenews.mail');
    simplenews_add_node_to_spool($node);
  }
  else {

    // simplenews_update_sent_status() already saves the node, only need to do
    // it when not sending.
    simplenews_newsletter_save($node->simplenews);
  }
}