Drupal: Changes Workbench state from Draft to Published programatically

I would like to do a bulk operation and change nodes from Draft to Published state. I created a new revision from a previous change, but all changes are set to Draft by default. Now I would just like to post the new edition. (I am using the Workbench module.)

I've tried doing something like below, but none of them work:

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

      

or

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

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

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

      

or

workbench_moderation_moderate($node, 'published');

      

I tried to save money by using below rather than node_save

thinking that I node_save

caused a new draft.

workbench_moderation_node_update($node);

      

I just want to just download node, post the draft and save again.

Any idea what I am doing wrong?

+3


source to share


2 answers


workbench_moderation_moderate is correct, I would do this to bulk publish some nodes:



$nodes = node_load_multiple($nodes);
foreach ($nodes as $node) {
    $node->status = 1;
    node_save($node);
    workbench_moderation_moderate($node, 'published');
}

      

+4


source


In addition to what @klidifia said, I would also like to present another solution that also worked for me.

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

      



The reason I accepted klidifia's answer to my answer is because my solution shows the message From Published --> Published on...

in the current version, whereas the solution above shows a more logical workflow:

From Draft --> Published on...
From Published --> Draft on...

      

+2


source







All Articles