Index: workflow.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/workflow/workflow.module,v
retrieving revision 1.54.2.6
diff -u -p -r1.54.2.6 workflow.module
--- workflow.module	2 Mar 2007 20:51:57 -0000	1.54.2.6
+++ workflow.module	19 Dec 2007 07:54:32 -0000
@@ -1201,6 +1201,7 @@ function workflow_is_system_state($state
   return isset($states[$state]);
 }
 
+
 /**
  * Create the form for confirmation of deleting a workflow state.
  *
@@ -1218,6 +1219,16 @@ function workflow_state_delete_form($wid
   $form = array();
   $form['wid'] = array('#type' => 'value', '#value' => $wid);
   $form['sid'] = array('#type' => 'value', '#value' => $sid);
+  
+  
+  $options = workflow_get_states($wid);
+  
+  $form['new_sid'] = array(
+    '#type' => 'select',
+    '#title' => 'State to assign orphaned nodes to',
+    '#descriptionn' => 'Since you are deleting a workflow state, nodes which are in that state will be orphaned, and must be reassigned to a new state, please specify it here.',
+    '#options' => $options,
+    );
   return confirm_form(
     $form,
     t('Are you sure you want to delete %title (and all its transitions)?', array('%title' => $states[$sid])),
@@ -1232,7 +1243,7 @@ function workflow_state_delete_form_subm
   $states = workflow_get_states($form_values['wid']);
   $state_name = $states[$form_values['sid']];
   if ($form_values['confirm'] == 1) {
-    workflow_state_delete($form_values['sid']);
+    workflow_state_delete($form_values['sid'],$form_values['new_sid']);
     watchdog('workflow', t('Deleted workflow state %name', array('%name' => $state_name)));
     drupal_set_message(t('The workflow state %name was deleted.', array('%name' => $state_name)));
   }
@@ -1604,7 +1615,16 @@ function workflow_state_create($wid, $na
  * @param $sid
  *   The ID of the state to delete.
  */
-function workflow_state_delete($sid) {
+function workflow_state_delete($sid, $new_sid = null) {
+  if (!$new_sid) {
+    //we're just going to zap all record of workflow stats for nodes in this state.  (Sorry) :)
+    $result = db_query('DELETE from workflow_node WHERE sid = %d',$sid);
+    $result = db_query('DELETE from workflow_node_history WHERE sid = %d OR old_sid = %d',$sid,$sid);
+  } else { 
+    $result = db_query("UPDATE workflow_node SET sid = %d WHERE sid = %d",$new_sid,$sid);
+    $result = db_query('DELETE from workflow_node_history WHERE sid = %d OR old_sid = %d',$sid,$sid); //this should get cleared out though...
+  }
+  
   // find out which transitions this state is involved in
   $preexisting = array();
   $result = db_query("SELECT sid, target_sid FROM {workflow_transitions} WHERE sid = %d OR target_sid = %d", $sid, $sid);
