An odd one.
For some nodes, or a particular content type, a very odd event occurs when a new revision is saved.
I'm using the default 3 states for transitions.
When a user saves a new revision, and sets the value as 'needs review', a second revision is saved, - a copy of the 'pre-edit' state of the node, and that becomes the new published revision.
It doesn't happen for user 1 - the workflow behaves as expected.

What might be causing this ghost revision?

Thanks
Alan

Comments

mparker17’s picture

I'm experiencing this too.

I've found that it'll work for users other than user/1, but I don't know which permission makes it work yet... I'll have to do some more testing.

mparker17’s picture

Title: When saving revision, a second revision is created at the same time » When saving a revision of a book node, a second revision is created at the same time.

For me, this happens only for Book content: all other content types act normally.

For me, setting the Node module's Administer content permission for a role will cause it to work; but that's not ideal because that permission has security implications.

mparker17’s picture

Ha! I think I found the culprit...

In book.module there is the following code:

/**
 * Implements hook_node_presave().
 */
function book_node_presave($node) {
  // Always save a revision for non-administrators.
  if (!empty($node->book['bid']) && !user_access('administer nodes')) {
    $node->revision = 1;
    // The database schema requires a log message for every revision.
    if (!isset($node->log)) {
      $node->log = '';
    }
  }
  // ...
}

... that's probably what's adding the extra revision.

mparker17’s picture

Wow, okay, adding a revision when non-administrators update book pages has a fascinating history that's almost as old as Drupal itself...

It appears to have been added by Dries on Sun Nov 4, 2001 to prevent non-admins from stomping existing content on Drupal.org.

The line of code to add a revision when a non-administrator saves a book page has been moved around quite a bit, and has changed it's form a number of times, but it has stuck around for a really long time!

It was almost removed in #68418-8: Clean up node submit hooks, but got re-introduced when the commits related to that patch were rolled back in #68418-33: Clean up node submit hooks. That issue eventually got marked "Works as designed" and never went anywhere further.

When the book module was refactored in #146425: improve book module: use nodeapi and menu API, it was changed from a hidden form value in the book content type's node-edit-form's submit function to happening immediately before a book node is saved #146425-181: improve book module: use nodeapi and menu API, because certain actions would force the node's author to change, which was undesirable for drupal.org.

And, the line of code to add revisions is still there in Drupal 8.x.

mparker17’s picture

The following issues may be of interest. They provide a bit more context:

mparker17’s picture

I've filed #2220843: Don't save a revision when book nodes are saved by non-administrators against core.

Leaving this issue open in case it's decided that it shouldn't be backported to D7 core: if that happens, hopefully we can patch Workbench Moderation with a work-around.

star-szr’s picture

Adding a related issue that has a patch and some activity.