Change Workbench state from Draft to Published programatically I would like to do a bulk operation and change nodes from a state of Draft to Published. I created a new revision from a previous change, but all revisions default to Draft. Now I would like to basically just publish the new revision. (I am using the Workbench module.)

I have tried doing things like the below, but none of them seem to work:

$node-&gt;workbench_moderation['current']-&gt;published = "1";


or

$node-&gt;workbench_moderation['current']-&gt;from_state = "draft";
$node-&gt;workbench_moderation['current']-&gt;state = "published";
$node-&gt;workbench_moderation['current']-&gt;published = "1";

$node-&gt;workbench_moderation['published']-&gt;from_state = "draft";
$node-&gt;workbench_moderation['published']-&gt;state = "published";
$node-&gt;workbench_moderation['published']-&gt;published = "1";

$node-&gt;workbench_moderation['my_revision']-&gt;from_state = "draft";
$node-&gt;workbench_moderation['my_revision']-&gt;state = "published";
$node-&gt;workbench_moderation['my_revision']-&gt;published = "1";
$node-&gt;workbench_moderation['my_revision']-&gt;current = TRUE;


or

workbench_moderation_moderate($node, 'published');


I've tried saving using the below rather than node_save as well, thinking maybe the node_save triggered a new draft.

workbench_moderation_node_update($node);


I just want to simply load the node, publish the draft, then save it again.

Any idea what I am doing wrong?
There are two solutions which I have found will work:

The First:

$nid = 1234;
$node = node_load($nid);
$node-&gt;body['und'][0]['value'] = 'new body';
$node-&gt;revision = 1;
$node-&gt;log = 'State Changed to published';
node_save($node);
workbench_moderation_moderate($node, 'published');


NOTE: I intentionally put workbench_moderation_moderate() after node_save() because in my case node_save() will trigger a new draft.  After the draft is created, I publish that draft.

The second:

$nid = 1234;
$node = node_load($nid);
$node-&gt;body['und'][0]['value'] = 'new body';
$node-&gt;workbench_moderation_state_new = workbench_moderation_state_published();
$node-&gt;revision = 1;
$node-&gt;log = 'State Changed to published';
node_save($node);


I am going with the first solution over the second solution because of the status messages. The first shows the two messages under the current revision:

From Draft --&gt; Published on...
From Published --&gt; Draft on... 


whereas the second solution only shows one message which doesn't really make much sense:

From Published --&gt; Published on...