Index: scheduler.module =================================================================== --- scheduler.module (revision 3887) +++ scheduler.module (working copy) @@ -437,11 +437,36 @@ * Implementation of hook_cron(). */ function scheduler_cron() { - $clear_cache = FALSE; + $published = scheduler_publish(); + $unpublished = scheduler_unpublish(); - // if the time now is greater than the time to publish a node, publish it - $nodes = db_query('SELECT * FROM {scheduler} s LEFT JOIN {node} n ON s.nid = n.nid WHERE n.status = 0 AND s.publish_on > 0 AND s.publish_on < %d ', time()); + if ($published || $unpublished) { + // Clear the cache so an anonymous poster can see the node being published + // or unpublished. + cache_clear_all(); + } +} +/** + * Publish scheduled nodes. + * + * By default publish any unpublished node. A alternative node set can be passed + * through the $nodes parameter. + * + * @param $nodes + * A query result set of scheduler records. + * + * @return + * TRUE is any node has been published, FALSE otherwise. + */ +function scheduler_publish($nodes = NULL) { + $result = FALSE; + + if (empty($nodes)) { + // If the time now is greater than the time to publish a node, publish it. + $nodes = db_query('SELECT * FROM {scheduler} s LEFT JOIN {node} n ON s.nid = n.nid WHERE n.status = 0 AND s.publish_on > 0 AND s.publish_on < %d ', time()); + } + while ($node = db_fetch_object($nodes)) { $n = node_load($node->nid); $n->changed = $node->publish_on; @@ -455,26 +480,48 @@ $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 this node is not to be unpublished, then we can delete the record. if (isset($n->unpublish_on) && $n->unpublish_on == 0) { db_query('DELETE FROM {scheduler} WHERE nid = %d', $n->nid); } - // we need to unpublish this node at some time so clear the publish on since it's been published + // We need to unpublish this node at some time so clear the publish on since + // it has been published. else { db_query('UPDATE {scheduler} SET publish_on = 0 WHERE nid = %d', $n->nid); } - // invoke scheduler API + // Invoke scheduler API. _scheduler_scheduler_api($n, 'publish'); - $clear_cache = TRUE; + $result = TRUE; } - // if the time is greater than the time to unpublish a node, unpublish it - $nodes = db_query('SELECT * FROM {scheduler} s LEFT JOIN {node} n ON s.nid = n.nid WHERE n.status = 1 AND s.unpublish_on > 0 AND s.unpublish_on < %d', time()); + return $result; +} +/** + * Unpublish scheduled nodes. + * + * By default unpublish any published node. A alternative node set can be passed + * through the $nodes parameter. + * + * @param $nodes + * A query result set of scheduler records. + * + * @return + * TRUE is any node has been unpublished, FALSE otherwise. + */ +function scheduler_unpublish($nodes = NULL) { + $result = FALSE; + + if (empty($nodes)) { + // If the time is greater than the time to unpublish a node, unpublish it. + $nodes = db_query('SELECT * FROM {scheduler} s LEFT JOIN {node} n ON s.nid = n.nid WHERE n.status = 1 AND s.unpublish_on > 0 AND s.unpublish_on < %d', time()); + } + while ($node = db_fetch_object($nodes)) { - // if this node is to be unpublished, we can update the node and remove the record since it can't be republished + // If this node is to be unpublished, we can update the node and remove the + // record since it cannot be republished. $n = node_load($node->nid); $n->changed = $node->unpublish_on; @@ -485,16 +532,13 @@ actions_do($actions, $n, $context, NULL, NULL); db_query('DELETE FROM {scheduler} WHERE nid = %d', $n->nid); - // invoke scheduler API + // Invoke scheduler API. _scheduler_scheduler_api($n, 'unpublish'); - $clear_cache = TRUE; + $result = TRUE; } - if ($clear_cache) { - // clear the cache so an anonymous poster can see the node being published or unpublished - cache_clear_all(); - } + return $result; } /**