Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal: Change Workbench state from Draft to Published programatically

Tags:

drupal

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->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'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?

like image 869
Keven Avatar asked Apr 25 '26 18:04

Keven


1 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');
}
like image 164
klidifia Avatar answered Apr 27 '26 07:04

klidifia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!