diff --git workflow.module workflow.module index 49133b4..c959e96 100644 --- workflow.module +++ workflow.module @@ -269,8 +269,14 @@ 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) { + // Clear $node->workflow_comment so we don't process comment more + // than once in case of subsequent nodeapi updates during one request + // Modules that hook on workflow should get comment from DB (directly or using Token module) + // instead of taking it out of $node object. + $comment = isset($node->workflow_comment) ? $node->workflow_comment : NULL; + unset($node->workflow_comment); // It's an immediate change. Do the transition. - workflow_execute_transition($node, $sid, isset($node->workflow_comment) ? $node->workflow_comment : NULL); + workflow_execute_transition($node, $sid, $comment); } else { // Schedule the the time to change the state. @@ -493,15 +499,16 @@ function workflow_execute_transition($node, $sid, $comment = NULL, $force = FALS global $user; $old_sid = workflow_node_current_state($node); if ($old_sid == $sid) { - // Stop if not going to a different state. - // Write comment into history though. + // Write comment into history. + // No comment and no state change means do nothing. + // We clear comment in workflow_transition() so empty subsequent runs terminate here if ($comment && !$node->_workflow_scheduled_comment) { $node->workflow_stamp = time(); db_query("UPDATE {workflow_node} SET stamp = %d WHERE nid = %d", $node->workflow_stamp, $node->nid); $result = module_invoke_all('workflow', 'transition pre', $old_sid, $sid, $node); _workflow_write_history($node, $sid, $comment); + $result = module_invoke_all('workflow', 'transition post', $old_sid, $sid, $node); } - $result = module_invoke_all('workflow', 'transition post', $old_sid, $sid, $node); return; }