When using the VBO plugin to change revision moderation states, the state is properly changed then changed back to the original state all in the same action.

Environment:

  • Drupal 7.15
  • Workbench 1.1
  • VBO 3.0

Process

I have a cloned workbench view of content revisions with a relationship to the full node. The content may exist in 1 of 4 moderation states. I added a VBO field to the view to allow editors the ability to change the moderation state for the current revision of multiple node entities. I've tried using the VBO field as a dropdown and as a button with no success. (See figure 1)

First:
I am asked for the moderation state to change them to. I get a dropdown with moderation states and an empty checkbox. (See figure 2)

Second:
If I proceed with the empty checkbox checked or unchecked, the revisions' moderation states are updated to the requested state, then immediately changed back to the original state, as indicated by the moderation log. (See figure 3)

Comments

agentrickard’s picture

Project: Workbench » Workbench Moderation
Version: 7.x-1.1 » 7.x-1.x-dev
Issue tags: -vbo, -Workbench Moderation

Please file issues against the proper module.

KeyboardCowboy’s picture

Assigned: Unassigned » KeyboardCowboy
Status: Active » Needs work

My apologies. I thought the issue was in how workbench was providing arguments to VBO. I'll dig back in and move this issue to the VBO queue if the problem still exists.

agentrickard’s picture

@KeyboardCowboy

You misunderstand me. Workbench Moderation is the proper queue, not Workbench.

mstef’s picture

Here's the empty checkbox..

function workbench_moderation_set_state_action_form($context) {
  $form = array();

  $form['state'] = array(
    '#type' => 'select',
    '#options' => workbench_moderation_state_labels(),
    '#default_value' => isset($context['state']) ? $context['state'] : '',
  );

  $form['force_transition'] = array(
    '#type' => 'checkbox',
    '#default_value' => FALSE,
  );

  return $form;
}
mstef’s picture

It doesn't seem to make any sense..

During submit, the moderation takes place if that checkbox is checked or if you have permission. Why provide an unrestricted checkbox that allows you to bypass permissions?

I think..
1. The checkbox should be removed
2. The code that checks the checkbox's value should be removed.
3. An error message should print if you don't have permission for a given node.
4. The change in moderation needs to be fixed, because it doesn't work.

mstef’s picture

It looks like the action isn't working because 2 records are inserted into the workbench_moderation_node_history table. I just used VBO to change a draft to published, and the first record did just that, but then a second record was inserted moving it back from published to draft.

mstef’s picture

Status: Needs work » Active

workbench_moderation_node_update() is executed after the VBO-induced moderation change. That call seems to be reverting the change.

mstef’s picture

And line 690 in workbench_moderation_node_update() is what does it...

  // Set default moderation state values.
  if (!isset($node->workbench_moderation_state_current)) {
    $node->workbench_moderation_state_current = ($node->status ? workbench_moderation_state_published() : workbench_moderation_state_none());
  };
  if (!isset($node->workbench_moderation_state_new)) {
    $node->workbench_moderation_state_new = variable_get('workbench_moderation_default_state_' . $node->type, workbench_moderation_state_none());
  };
mstef’s picture

Status: Active » Needs review
StatusFileSize
new1.85 KB

Here's a patch that does all that I suggested in #5.

To avoid the revert of moderation in hook_node_update(), I set $node->workbench_moderation['updating_live_revision'] = array(TRUE) before running the moderation.

byrond’s picture

Status: Needs review » Reviewed & tested by the community

While attempting to use Views Bulk Operations to set the moderation state to Published on a group of nodes that were in Draft but had $node->status=1 (core "published"), the moderation state was changed to Published and then back to Draft. #9 fixed this issue and prevented another error I was getting:

Uncaught exception thrown in shutdown function.EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7633 of /includes/common.inc).

The error message is a little unclear when the reason _workbench_moderation_moderate_access returns false is because of an invalid state transition (for example, the current state is the target state). Maybe, "Moderation state could not be changed for %node" would be better? There doesn't seem to be a way to get more detailed information from the access function, so maybe the error should be more generic.

BrockBoland’s picture

Status: Reviewed & tested by the community » Needs work

Found a problem with #9. If you have a node that has a published revision, and a newer draft, this can fail. The new call to _workbench_moderation_moderate_access() fails because it's passing the published revision of the node. I think that a call to workbench_moderation_node_current_load() is all that's needed. Trying this out now.

BrockBoland’s picture

Status: Needs work » Needs review
StatusFileSize
new1.94 KB

workbench_moderation_node_current_load() did the trick.

BrockBoland’s picture

Another variation. I'm not proposing this for inclusion in the module, merely sharing it in case anyone else has the same needs.

For my client, I need the bulk update to create a new revision on the node, in order to track what users make what changes to nodes. workbench_moderation_moderate() doesn't create a revision, so I replaced it with a call to node_save().

Furthermore, the 'behavior' => array('changes_property') defined on the action (in workbench_moderation_action_info()) results in a node_save() call after the actual action function (workbench_moderation_set_state_action()) is run. This resulted in two new revisions, since node_save() was called twice: once in the action function, and again somewhere else up the chain.

Only use this patch if you want the bulk state change to create a new revision on each node that's updated.

scotwith1t’s picture

I don't need the additional revision when it's moderated, so #12 worked great for me. Thanks BrockBoland!!

scotwith1t’s picture

Spoke too soon. I did a couple mass changes of moderation state (to approved, in my case), but when i do something else in the same VBO view, like promote 1 to front page or make sticky, it reverts it back to the default moderation state (back to needs review, in my case), including the ones I just approved...i wonder if the checkbox was just an incomplete implementation, seeing as it says something about "force the transition", seems like that might be important...never written a VBO action before, so i'd have to dig around to find out what's missing. i'll ask someone else to look at this with me as well.

scotwith1t’s picture

Version: 7.x-1.x-dev » 7.x-1.3
Assigned: KeyboardCowboy » Unassigned

We didn't have time to really dig into this, so we just set the default_state to TRUE and hid the checkbox, but that didn't work either. seems something may be wrong with the permissions check here, but i can't really put my finger on it right now...will report back if we figure it out, but the VBO isn't working for us. perhaps it's corrected in -dev? might try that shortly...

tedstein’s picture

Status: Needs review » Reviewed & tested by the community

I just worked on the same site that scotself was having trouble with and it is now fixed.

#12 did the job.

This should go upstream: The checkbox is an un-finished feature (or just a security hole) and saving the node twice in the action is a bug.

Thanks mstef and BrockBoland.

hass’s picture

Version: 7.x-1.3 » 7.x-1.x-dev
robcarr’s picture

Issue summary: View changes

This fix could do with being committed to DEV. Patch at #13 cured all my VBO issues

ryanc’s picture

#13 solved the issue for me.

Justtry’s picture

+1, #13 works for me, thanks

  • colan committed 808b1a2 on 7.x-1.x authored by BrockBoland
    Issue #1787214 by KeyboardCowboy, BrockBoland, mstef: Create new...
colan’s picture

Status: Reviewed & tested by the community » Fixed
colan’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Status: Fixed » Active

Forgot to set this up for forward porting.

das-peter’s picture

Status: Active » Fixed

Does not apply to the 2.x branch, it uses State Machine / State Flow to manage the states - so no actions defined by our module.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.