diff --git a/scheduler.module b/scheduler.module old mode 100644 new mode 100755 index 48b22d1..752d480 --- a/scheduler.module +++ b/scheduler.module @@ -728,43 +728,51 @@ function _scheduler_publish() { foreach ($nids as $nid) { $n = node_load($nid); - $n->changed = $n->publish_on; - $old_creation_date = $n->created; - if (variable_get('scheduler_publish_touch_'. $n->type, 0) == 1) { - $n->created = $n->publish_on; - } - - $create_publishing_revision = variable_get('scheduler_publish_revision_'. $n->type, 0) == 1; - if ($create_publishing_revision) { - $n->revision = TRUE; - $n->log = "Node published by scheduler module. Original creation date was ". format_date($old_creation_date, 'custom', $date_format) ."."; + //Fallback, if node does not exist. + if (!empty($n)) { + $n->changed = $n->publish_on; + $old_creation_date = $n->created; + if (variable_get('scheduler_publish_touch_'. $n->type, 0) == 1) { + $n->created = $n->publish_on; + } + + $create_publishing_revision = variable_get('scheduler_publish_revision_'. $n->type, 0) == 1; + if ($create_publishing_revision) { + $n->revision = TRUE; + $n->log = "Node published by scheduler module. Original creation date was ". format_date($old_creation_date, 'custom', $date_format) ."."; + } + + // Use the actions system to publish the node. + watchdog('scheduler', '@type: scheduled publishing of %title.', array('@type' => $n->type, '%title' => $n->title), WATCHDOG_NOTICE, l(t('view'), 'node/'. $n->nid)); + $actions = array('node_publish_action', 'node_save_action'); + $context['node'] = $n; + actions_do($actions, $n, $context, NULL, NULL); + + // If this node is not to be unpublished, then we can delete the record. + if (isset($n->unpublish_on) && $n->unpublish_on == 0) { + db_delete('scheduler') + ->condition('nid', $n->nid) + ->execute(); + } + // We need to unpublish this node at some time so clear the publish on since + // it has been published. + else { + db_update('scheduler') + ->fields(array('publish_on' => 0)) + ->condition('nid', $n->nid) + ->execute(); + } + + // Invoke scheduler API. + _scheduler_scheduler_api($n, 'publish'); + + $result = TRUE; } - - // Use the actions system to publish the node. - watchdog('scheduler', '@type: scheduled publishing of %title.', array('@type' => $n->type, '%title' => $n->title), WATCHDOG_NOTICE, l(t('view'), 'node/'. $n->nid)); - $actions = array('node_publish_action', 'node_save_action'); - $context['node'] = $n; - actions_do($actions, $n, $context, NULL, NULL); - - // If this node is not to be unpublished, then we can delete the record. - if (isset($n->unpublish_on) && $n->unpublish_on == 0) { + else{ db_delete('scheduler') - ->condition('nid', $n->nid) - ->execute(); - } - // We need to unpublish this node at some time so clear the publish on since - // it has been published. - else { - db_update('scheduler') - ->fields(array('publish_on' => 0)) - ->condition('nid', $n->nid) + ->condition('nid', $nid) ->execute(); - } - - // Invoke scheduler API. - _scheduler_scheduler_api($n, 'publish'); - - $result = TRUE; + } } return $result; @@ -798,30 +806,32 @@ function _scheduler_unpublish() { // If this node is to be unpublished, we can update the node and remove the // record since it cannot be republished. $n = node_load($nid); - $old_change_date = $n->changed; - $n->changed = $n->unpublish_on; - - if ($n->status == 1) { - $create_unpublishing_revision = variable_get('scheduler_unpublish_revision_'. $n->type, 0) == 1; - if ($create_unpublishing_revision) { - $n->revision = TRUE; - $n->log = "Node unpublished by scheduler module. Original change date was ". format_date($old_change_date, 'custom', $date_format) ."."; + if(!empty($n)){ + $old_change_date = $n->changed; + $n->changed = $n->unpublish_on; + + if ($n->status == 1) { + $create_unpublishing_revision = variable_get('scheduler_unpublish_revision_'. $n->type, 0) == 1; + if ($create_unpublishing_revision) { + $n->revision = TRUE; + $n->log = "Node unpublished by scheduler module. Original change date was ". format_date($old_change_date, 'custom', $date_format) ."."; + } + + // Use the actions system to unpublish the node. + watchdog('scheduler', '@type: scheduled unpublishing of %title.', array('@type' => $n->type, '%title' => $n->title), WATCHDOG_NOTICE, l(t('view'), 'node/'. $n->nid)); + $actions = array('node_unpublish_action', 'node_save_action'); + $context['node'] = $n; + actions_do($actions, $n, $context, NULL, NULL); } - - // Use the actions system to unpublish the node. - watchdog('scheduler', '@type: scheduled unpublishing of %title.', array('@type' => $n->type, '%title' => $n->title), WATCHDOG_NOTICE, l(t('view'), 'node/'. $n->nid)); - $actions = array('node_unpublish_action', 'node_save_action'); - $context['node'] = $n; - actions_do($actions, $n, $context, NULL, NULL); + + // Invoke scheduler API. + _scheduler_scheduler_api($n, 'unpublish'); } db_delete('scheduler') ->condition('nid', $n->nid) ->execute(); - // Invoke scheduler API. - _scheduler_scheduler_api($n, 'unpublish'); - $result = TRUE; }