function workflow_cron in Workflow 6
Same name and namespace in other branches
- 8 workflow.module \workflow_cron()
- 5.2 workflow.module \workflow_cron()
- 5 workflow.module \workflow_cron()
- 6.2 workflow.module \workflow_cron()
- 7.2 workflow.module \workflow_cron()
- 7 workflow.module \workflow_cron()
Implementation of hook_cron().
File
- ./
workflow.module, line 1089 - Support workflows made up of arbitrary states.
Code
function workflow_cron() {
$clear_cache = FALSE;
// If the time now is greater than the time to execute a
// transition, do it.
$nodes = db_query('SELECT * FROM {workflow_scheduled_transition} s WHERE s.scheduled > 0 AND s.scheduled < %d', time());
while ($row = db_fetch_object($nodes)) {
$node = node_load($row->nid);
// Make sure transition is still valid; i.e., the node is
// still in the state it was when the transition was scheduled.
if ($node->_workflow == $row->old_sid) {
// Do transition.
workflow_execute_transition($node, $row->sid, $row->comment, TRUE);
watchdog('content', '%type: scheduled transition of %title.', array(
'%type' => t($node->type),
'%title' => $node->title,
), WATCHDOG_NOTICE, l(t('view'), 'node/' . $node->nid));
$clear_cache = TRUE;
}
else {
// Node is not in the same state it was when the transition
// was scheduled. Defer to the node's current state and
// abandon the scheduled transition.
db_query('DELETE FROM {workflow_scheduled_transition} WHERE nid = %d', $node->nid);
}
}
if ($clear_cache) {
// Clear the cache so that if the transition resulted in a node
// being published, the anonymous user can see it.
cache_clear_all();
}
}