You are here

function revisioning_scheduler_node_presave in Revisioning 7

Same name and namespace in other branches
  1. 8 revisioning_scheduler/revisioning_scheduler.module \revisioning_scheduler_node_presave()

Implements hook_node_presave().

Called when saving, be it an edit or when creating a node.

Picks up the value for the scheduled publication date (if entered) and decides whether the node should be published immediately or scheduled for a later date.

File

revisioning_scheduler/revisioning_scheduler.module, line 263
Allows revisions to be published at specified dates and times.

Code

function revisioning_scheduler_node_presave($node) {
  if (!isset($node->nid)) {

    // This may happen when importing files using Feeds module.
    return;
  }
  if (empty($node->revision_moderation) || !empty($node->auto_publish)) {
    _revisioning_scheduler_unschedule_all_revisions($node->nid);
  }
  elseif (!empty($node->publication_date)) {
    $datetime = explode(' ', trim($node->publication_date));
    $date = $datetime[0];
    $time = isset($datetime[1]) ? $datetime[1] : '00:00';
    $node->publication_date = "{$date} {$time}";
    $scheduled_time = strtotime($node->publication_date);
    if ($date == 'now' || $scheduled_time > time() - REVISIONING_SCHEDULER_SLACK && $scheduled_time <= time()) {

      // Publish immediately without scheduling.
      // Follow the default saving process making this revision current and
      // published, as opposed to pending.
      unset($node->revision_moderation);
      $node->status = NODE_PUBLISHED;
      _revisioning_scheduler_unschedule_all_revisions($node->nid);
    }
    else {

      // Schedule publication date.
      return;
    }
  }

  // Publication date does not apply in this situation.
  unset($node->publication_date);
}