Problem/Motivation

In the use case that follows, there is a flag exposed to users on the node edit form that fires a hook_node_presave to turn-on/off og menu.

If a site uses any type of workflow, then resaving a revision or anything that isn't the current live revision and which has OG Menu's turned off will cause the og_menu to be deleted. The live revision has og_menu turned on, just not the revision. That isn't good. Editing a revision or something about to be staged to live shouldn't effect the live revision.

Proposed resolution

Confirm that the currently saved revision in hook_node_update is also the current revision.

Remaining tasks

Review

User interface changes

n/a

API changes

n/a

Data model changes

n/a

Original report by @fuerst
When reverting a node revision for a OG node the OG menu of that node will be removed. That happens at og_menu_nodeapi() in the $op case update: There is no $node->og_menu set at this stage. Calling $node->og_menu = og_menu_get_group_menus(array($node->nid)) may fix this but I'm unsure if this causes a conflict when updating a node the standard way (by editing & saving).

Comments

justindodge’s picture

I was having a similar issue with 7.x-2.0.

A simple fix was to add a check in og_menu_node_update:

/**
 * Implementation of hook_node_update()
 */
function og_menu_node_update($node) {
  if (og_is_group_type('node', $node->type)) {
    if(isset($node->is_current) && $node->is_current === false) {
      //To ensure compatiblity with the the revisioning module, and so that unexpected changes
      //don't happen to the current node's og_menu, we are not going to make any changes to 
      //the menu unless we are working with the current revision.
      return;
    }

The same could be applied to the equivalent hook_nodeapi function in D6.

The problem with what's going on in this function in general is, as stated by the OP, that $node->og_menu is never available, and so the resulting condition acts incorrectly. The problem with my solution is that it although it handles one situation with node revisions, it will still fail when og nodes are saved programmatically, via node_save for example.

This variable is populated in og_menu_node_prepare(), which is a hook only used for the node form. A better place for this might be the 'load' function of nodeapi, but I haven't had time to consider the consequences of implementing this and how it would affect the behavior of the form posts.

A final thought for solution would be to change the conditionals in hook_node_update. Right now it's:

if ($node->og_menu) {
//do updating
}
else {
//delete everything.. !?
}

but a safer alternative would be to do nothing if the og_menu property is not set at all, and be more explicit about what it contains:

if (isset($node->og_menu) && sizeof($node->og_menu) >= 0 ) {
//do updating
}
elseif(isset($node->og_menu) && sizeof($node->og_menu) == 0) {
//delete everything.. 
}
else {
//Do nothing, not applicable
}

Hope that helps...

LSU_JBob’s picture

Version: 6.x-2.4 » 7.x-3.x-dev
Status: Active » Needs review
StatusFileSize
new1 KB

took justindodge's changes and rolled them into a patch for 7.x-3.x

rv0’s picture

Status: Needs review » Fixed

please check if this still happens now
#1393958: Menus are lost when using Panelizer module might have fixed this.

re-open if not.

Status: Fixed » Closed (fixed)

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

fuerst’s picture

Version: 7.x-3.x-dev » 6.x-2.4
Status: Closed (fixed) » Active

I had filed the bug for version 6.x-2.4. Since #1393958 covers 7.x only I assume the bug still exists in 6.x

troybthompson’s picture

Would this be related to the menu being deleted when creating a new draft using workbench_moderation? I'm using the 7.x-3.x version.

rv0’s picture

#6 yes.. is this happening with latest 3.x version?

troybthompson’s picture

I apologize, it looks like I just missed the latest version. Yes, the new version fixes it in 7. Thanks!

rv0’s picture

great to hear
leaving this open for 6.x

fuerst’s picture

Status: Active » Needs review
StatusFileSize
new619 bytes

Looks like there is no easy way in Drupal 6 to check if a node is reverted or just updated. I found when $node->revision_uid and $node->old_vid both are set the node was reverted. That is kind of hacky I guess. Patch is attached anyway.

fuerst’s picture

Version: 6.x-2.4 » 6.x-2.x-dev

Patch in #10 is against latest 6.x-2.x-dev

osopolar’s picture

heddn’s picture

Title: Reverting node revision removes Menu » Re-saving revisions shouldn't remove menu from live revision
Version: 6.x-2.x-dev » 7.x-3.x-dev
Issue summary: View changes
Priority: Normal » Major
StatusFileSize
new2.47 KB

Let's fix this on 7.x first, then we can backport.

rv0’s picture

Strange, from the comments above you would think it didn't happen in 7.x... Seems like some regression was introduced somewhere.
Basically all this patch adds is this, right?

  if (($current_revision = node_load($node->nid)) && $node->vid == $current_revision->vid) {
heddn’s picture

Basically, yes. That is all it does. It doesn't catch all workflow issues. In fact, it doesn't catch what I needed for my site's specific implementation at all. However, I'm hoping it will catch other's. Maybe we could have someone test with workbench moderation?

rv0’s picture

Status: Needs review » Postponed (maintainer needs more info)

Tried to reproduce it with core revisions and also with workbench moderation;.. Wasn't able to reproduce the issue.
Anyone have detailed instructions on how to reproduce this in D7?