//if the time now is greater than the time to publish a node, publish it
//if the time now is greater than the time to publish a node, publish it
$nodes=db_query('SELECT *, (publish_on - timezone) AS utc_publish_on 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 + s.timezone',time());
//if this node is not to be unpublished, then we can delete the record
if($n->unpublish_on==0){
// 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's 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');
watchdog('content',t('@type: scheduled publishing of %title.',array('@type'=>$n->type,'%title'=>$n->title)),WATCHDOG_NOTICE,l(t('view'),'node/'.$n->nid));
watchdog('content','@type: scheduled publishing of %title.',array('@type'=>$n->type,'%title'=>$n->title),WATCHDOG_NOTICE,l(t('view'),'node/'.$n->nid));
$clear_cache=TRUE;
}
//if the time is greater than the time to unpublish a node, unpublish it
//if the time is greater than the time to unpublish a node, unpublish it
$nodes=db_query('SELECT *, (unpublish_on - timezone) AS utc_unpublish_on 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 + s.timezone',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 can't be republished
$n=node_load($node->nid);
$n->changed=$node->utc_publish_on;
$n=node_submit($n);
...
...
@@ -263,24 +277,39 @@ function scheduler_cron() {
node_save($n);
db_query('DELETE FROM {scheduler} WHERE nid = %d',$n->nid);
//invoke scheduler API
//invoke scheduler API
_scheduler_scheduler_api($n,'unpublish');
watchdog('content',t('@type: scheduled unpublishing of %title.',array('@type'=>$n->type,'%title'=>$n->title)),WATCHDOG_NOTICE,l(t('view'),'node/'.$n->nid));
watchdog('content','@type: scheduled unpublishing of %title.',array('@type'=>$n->type,'%title'=>$n->title),WATCHDOG_NOTICE,l(t('view'),'node/'.$n->nid));
$clear_cache=TRUE;
}
if($clear_cache){
// clear the cache so an anonymous poster can see the node being published or unpublished
cache_clear_all();
}
}
/**
* Implementation of hook_theme()
*/
functionscheduler_theme(){
returnarray(
'scheduler_timecheck'=>array(
'arguments'=>array('now'=>NULL),
),
);
}
function_scheduler_run_cron(){
watchdog('scheduler','Internal scheduler run activated',array(),WATCHDOG_NOTICE);
t('Your server reports the UTC time as %time and "localtime" as %lt.',$t_options).
t('Your server reports the UTC time as %time and "localtime" as %lt.',$t_options).
'<p />'.
t('If all is well with your server\'s time configuration UTC should match <a target="_blank" href="http://wwp.greenwichmeantime.com/">UTC London Time</a> and the localtime should be the time where you are.').