You are here

function _revisioning_scheduler_schedule_publication in Revisioning 7

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

Schedule the supplied node for publication at the supplied date & time.

Parameters

string $date: Publication date as a string, e.g. '25-12-2012'

string $time: Publication time as a string, e.g. '23:59'

object $node: The node object

Return value

null|bool TRUE: revision successfully scheduled empty: revision not scheduled, should be published immediately FALSE: error, date & time in the past or database error

2 calls to _revisioning_scheduler_schedule_publication()
revisioning_scheduler_node_update in revisioning_scheduler/revisioning_scheduler.module
Implements hook_node_update().
revisioning_scheduler_revisionapi in revisioning_scheduler/revisioning_scheduler.module
Implements hook_revisionapi().

File

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

Code

function _revisioning_scheduler_schedule_publication($date, $time, $node) {
  $date = trim($date);
  $time = trim($time);
  if (empty($time)) {
    $time = '00:00';
  }
  $scheduled_time = strtotime($date . $time);
  if ($scheduled_time > time() - REVISIONING_SCHEDULER_SLACK) {
    if ($scheduled_time <= time()) {

      // Schedule immediately.
      return;
    }
    _revisioning_scheduler_unschedule_all_revisions($node->nid);
    global $user;
    $data = array(
      'revision_nid' => $node->nid,
      'revision_vid' => $node->vid,
      'revision_uid' => $user->uid,
      'revision_date' => $scheduled_time,
    );
    if (drupal_write_record('revisioning_scheduler', $data)) {
      if ($scheduled_time > time()) {
        drupal_set_message(t('Revision scheduled for publication at %time on %date.', array(
          '%time' => $time,
          '%date' => $date,
        )));
      }
      else {

        // Should never get here.
        drupal_set_message(t('Revision will be published at next cron run.'));
      }
      return TRUE;
    }
  }
  drupal_set_message(t('Publication could not be scheduled at this date & time: %date %time.', array(
    '%date' => $date,
    '%time' => $time,
  )), 'error');
  return FALSE;
}