You are here

function scheduler_node_insert in Scheduler 7

Same name and namespace in other branches
  1. 8 scheduler.module \scheduler_node_insert()

Implements hook_node_insert().

File

./scheduler.module, line 614
Scheduler publishes and unpublishes nodes on dates specified by the user.

Code

function scheduler_node_insert($node) {

  // Only insert into database if we need to (un)publish this node at some date.
  if (!empty($node->publish_on) || !empty($node->unpublish_on)) {
    db_insert('scheduler')
      ->fields(array(
      'nid' => $node->nid,
      'publish_on' => $node->publish_on,
      'unpublish_on' => $node->unpublish_on,
    ))
      ->execute();

    // Invoke the events to indicate that a new node has been scheduled.
    if (module_exists('rules')) {
      if (!empty($node->publish_on)) {
        rules_invoke_event('scheduler_new_node_is_scheduled_for_publishing_event', $node, $node->publish_on, $node->unpublish_on);
      }
      if (!empty($node->unpublish_on)) {
        rules_invoke_event('scheduler_new_node_is_scheduled_for_unpublishing_event', $node, $node->publish_on, $node->unpublish_on);
      }
    }
  }
}