--- /home/mundt/Entwicklung/htdocs/drupaltest-ogur4/sites/all/modules/workflow_post_install/workflow_post_install.module	2009-04-20 06:45:16.000000000 +0200
+++ /home/mundt/Entwicklung/htdocs/artelectronicmedia.com/sites/all/modules/workflow_post_install/workflow_post_install.module	2010-01-29 14:38:58.768901977 +0100
@@ -52,13 +52,20 @@ function workflow_post_install_menu() {
 function workflow_create_state_for_stateless_nodes() {
   // Get workflow state id from last argument of URL and look up associated id.
   $state_name = end(arg());
+  if (count(arg()) == 4) {
+    $status = arg(2);
+    if ($status != "published" && $status != "unpublished") {
+      drupal_set_message(t('Unrecognized status: @status. Select either "published" or "unpublished".', array("@status" => $status)), 'error');
+      return '<p>'. t('<strong>No nodes have been processed.</strong>') .'</p>';
+    }
+  }
   $count = 0;
   $sid = db_result(db_query("SELECT sid FROM {workflow_states} WHERE state='%s'", $state_name));
   if (empty($sid)) {
     drupal_set_message(t('Invalid workflow state: "@state"', array('@state' => $state_name)), 'error');
   }
   else {
-    $count = _create_workflow_state_for_nodes($sid);
+    $count = _create_workflow_state_for_nodes($sid, $status);
     if ($count > 0) {
       drupal_set_message(t('The content access permissions need to be rebuilt. Please visit <a href="@rebuild-permissions-page">this page</a>.', array('@rebuild-permissions-page' => url('admin/content/node-settings/rebuild'))), 'error');
     }
@@ -79,10 +86,15 @@ function workflow_create_state_for_state
  * @return
  *  The number of nodes that had a state created.
  */
-function _create_workflow_state_for_nodes($sid) {
+function _create_workflow_state_for_nodes($sid, $status = null) {
   $now = time();
   $count = 0;
-  $result = db_query('SELECT n.nid, n.uid, ws.state FROM {node} n INNER JOIN {workflow_type_map} wtm ON n.type=wtm.type LEFT JOIN {workflow_node} wn ON n.nid=wn.nid LEFT JOIN {workflow_states} ws ON wn.sid=ws.sid WHERE wtm.wid > 0');
+  $query = 'SELECT n.nid, n.uid, ws.state FROM {node} n INNER JOIN {workflow_type_map} wtm ON n.type=wtm.type LEFT JOIN {workflow_node} wn ON n.nid=wn.nid LEFT JOIN {workflow_states} ws ON wn.sid=ws.sid WHERE wtm.wid > 0';
+  if ($status == "published")
+    $query .= ' AND n.status = 1';
+  if ($status == "unpublished")
+    $query .= ' AND n.status = 0';
+  $result = db_query($query);
   while ($node = db_fetch_object($result)) {
     if (empty($node->state)) { // i.e. 'No state'
       if (_create_workflow_state_for_node($node->nid, $sid, $node->uid, $now)) {
