Blank 'Authored on' field on re-edit of pending revision

jromine - January 31, 2009 - 20:18
Project:Revision Moderation
Version:5.x-1.3
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:duplicate
Description

If you edit your pending revision of a node, the 'Authored on' field
is blank, causing the node created date to be reset when the form
is submitted.

Repeat by:
1. Add a new page with 'New Revisions in Moderation' checked; submit.
2. Edit the (pending revision of the) page; submit.
3. Edit (again) the page; observe 'Authored on' field is blank in the form.

node_form() calls node_object_prepare(), which populates the authored
on (node->date) field. With the late call to node_load() in the
'prepare' section of revision_moderation_nodeapi(), the node->date
field doesn't get populated for the loaded node/revision.

#1

jromine - January 31, 2009 - 20:38

This is a quick-fix patch.

AttachmentSize
revision_moderation-367283-1.patch 694 bytes

#2

O_o - July 13, 2009 - 08:26
Status:active» needs review

I cannot reproduce this bug using the steps you describe. Could you please clarify which type of user role you used when editing?

I did the following to test the bug:

  1. Created a new page with a user not having the administer nodes permission. Node turns up for moderation.
  2. A publisher edits the node and changes the authored on setting (I also tried to leave the form field blank).
  3. When editing the page once again the form field is filled in as it should.

Setting this as needs review for others to test.

#3

jromine - July 13, 2009 - 15:15

As I recall, this bug was difficult to track down. It happens when a user edits a node, the new revision remains unpublished, and the same user re-edits the same node (i.e., re-editing his/her previously unpublished revision).

#4

O_o - July 14, 2009 - 12:12

Aah... know I see it. Yes, the authored on field is indeed empty when editing your own revision once again.

I've been looking into this for an hour and the more I think of it I'm convinced that the node_load($node->nid, $node->vid) in the prepare section of revision_moderation_nodeapi() is the wrong way to do it since the form and node objects has been populated with $node->date information before that step. When we load the node again (actually the editing user's latest revision of the node) we overwrite the $node->date</date> information set by <a href="http://api.drupal.org/api/function/node_object_prepare/5">node_object_prepare()</a>. <code>node_load($node->nid, $node->vid) by itself does not set that information. Search for node_object_prepare in node.module to see what I mean.

If you comment out the line node_load($node->nid, $node->vid) from the prepare section you'll see that the $node->date information exists in $node. It is set by node_object_prepare().

Any ideas?

#5

jromine - July 14, 2009 - 21:01

Well, if I understand the code correctly, revision_moderation_nodeapi() is basically overriding which revision gets loaded, during a callback from node_object_prepare(), right? I think you'll have to use node_load() to load a specific revision.

I question the code setting node->created and node->date in node_object_prepare(). Perhaps that code should be in node_load(), or perhaps it should have its own API call (I think that's the correct fix, but I'm not a node.module expert).

I see a similar work-around to set node->date in blogapi_blogger_new_post(); having modules duplicate core code seems like a bad thing. On the other hand, since we're overriding the revision that gets loaded, maybe it's the responsibility of revision_moderation_nodeapi() to re-populate node->date.

#6

O_o - July 15, 2009 - 08:55

That's correct. You'll have to use node_load() to load a specific revision. I feel the same, having modules duplicate core code does not seem like an acceptable solution.

I found the closed issue #130186: Redirect when editing a node that have a pending revision describing the same bug. It includes another patch that feels more "safe" than the one we are discussing here. I have reopened that issue and I'm going to test the patch.

#7

jromine - July 15, 2009 - 14:16

Yeah, redirect to edit the pending revision is a much better fix.

#8

O_o - July 17, 2009 - 13:44
Status:needs review» duplicate

Setting this as duplicate of #130186: Redirect when editing a node that have a pending revision. Patch provided in that issue should be used.

#9

PeteS - July 24, 2009 - 19:58

As noted before that the menu data is populated in nodeapi/prepare, this issue would probably explain why I'm seeing my menu assignment getting blanked out when editing a pending revision.

 
 

Drupal is a registered trademark of Dries Buytaert.