function workflow_transition in Workflow 6.2
Same name and namespace in other branches
- 5.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.
3 calls to workflow_transition()
- workflow_comment in ./
workflow.module - Implementation of hook_comment().
- workflow_nodeapi in ./
workflow.module - Implementation of hook_nodeapi().
- workflow_tab_form_submit in ./
workflow.pages.inc - Submit handler for the form on the workflow tab.
File
- ./
workflow.module, line 169 - Support workflows made up of arbitrary states.
Code
function workflow_transition($node, $sid) {
// Make sure new state is a valid choice.
if (array_key_exists($sid, workflow_field_choices($node))) {
$node->workflow_scheduled = isset($node->workflow_scheduled) ? $node->workflow_scheduled : FALSE;
if (!$node->workflow_scheduled) {
// It's an immediate change. Do the transition.
workflow_execute_transition($node, $sid, isset($node->workflow_comment) ? $node->workflow_comment : NULL);
}
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);
// Get name of state.
$state_name = workflow_get_state_name($sid);
watchdog('workflow', '@node_title scheduled for state change to %state_name on !scheduled_date', array(
'@node_title' => $node->title,
'%state_name' => $state_name,
'!scheduled_date' => format_date($scheduled),
), WATCHDOG_NOTICE, l('view', "node/{$node->nid}/workflow"));
drupal_set_message(t('@node_title is scheduled for state change to %state_name on !scheduled_date', array(
'@node_title' => $node->title,
'%state_name' => $state_name,
'!scheduled_date' => format_date($scheduled),
)));
}
}
}
}