function workflow_transition in Workflow 5.2
Same name and namespace in other branches
- 6.2 workflow.module \workflow_transition()
- 6 workflow.module \workflow_transition()
- 7.2 workflow.deprecated.inc \workflow_transition()
- 7 workflow.module \workflow_transition()
Validate target state and either execute a transition immediately or schedule a transition to be executed later by cron.
Parameters
$node:
$sid: An integer; the target state ID.
2 calls to workflow_transition()
- workflow_comment in ./
workflow.module - Implementation of hook_comment().
- workflow_nodeapi in ./
workflow.module - Implementation of hook_nodeapi().
File
- ./
workflow.module, line 384
Code
function workflow_transition($node, $sid) {
// Make sure new state is a valid choice.
if (array_key_exists($sid, workflow_field_choices($node))) {
if (!$node->workflow_scheduled) {
// It's an immediate change. Do the transition.
workflow_execute_transition($node, $sid, $node->workflow_comment);
}
else {
// Schedule the the time to change the state.
$comment = $node->workflow_comment;
$old_sid = workflow_node_current_state($node);
if ($node->workflow_scheduled_date['day'] < 10) {
$node->workflow_scheduled_date['day'] = '0' . $node->workflow_scheduled_date['day'];
}
if ($node->workflow_scheduled_date['month'] < 10) {
$node->workflow_scheduled_date['month'] = '0' . $node->workflow_scheduled_date['month'];
}
if (!$node->workflow_scheduled_hour) {
$node->workflow_scheduled_hour = '00:00';
}
$scheduled = $node->workflow_scheduled_date['year'] . $node->workflow_scheduled_date['month'] . $node->workflow_scheduled_date['day'] . ' ' . $node->workflow_scheduled_hour . 'Z';
if ($scheduled = strtotime($scheduled)) {
// Adjust for user and site timezone settings.
global $user;
if (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone)) {
$timezone = $user->timezone;
}
else {
$timezone = variable_get('date_default_timezone', 0);
}
$scheduled = $scheduled - $timezone;
// Clear previous entries and insert.
db_query("DELETE FROM {workflow_scheduled_transition} WHERE nid = %d", $node->nid);
db_query("INSERT INTO {workflow_scheduled_transition} VALUES (%d, %d, %d, %d, '%s')", $node->nid, $old_sid, $sid, $scheduled, $comment);
drupal_set_message(t("@node_title is scheduled for state change on !scheduled_date", array(
"@node_title" => $node->title,
"!scheduled_date" => format_date($scheduled),
)));
}
}
}
}