Ugh... thank god for Xdebug and Eclipse, I *never* would have found this one.

First, some background: I'm using workflow with my images. Workflow enables you to present the workflow tab to users who are the "author" of the node. In my case, I was setting up the gallery and it's images as uid 1, then resetting the author on the image to allow another user to change the workflow without them having the ability to actually edit the image node itself.

Great idea, but it flat out wasn't working. No matter what I did Drupal kept on saying that the author ($node->uid) was uid1, even though the node table in the db said that the UID was 3. Here's the stack to the bug:

node_load calls node_gallery_nodeapi. When the operation is 'load' and the node in question is an image type, line 274 of node_gallery.module merges the existing node object with the array returned from node_gallery_get_image_file(). node_gallery_get_image_file consists of one line:

return db_fetch_object(dbquery("SELECT i.*, f.* FROM {node_galleries} i INNER JOIN {files} f ON i.fid = f.fid WHERE i.nid = %d", $node->nid));

And guess what? Column name collision between node and files on the column uid. So, since I imported the image file as uid 1, when that array is merged with $node, the file's uid trumps the node's uid, and my bug is biting hard.

There's two ways to fix this, but I'm still green enough with Drupal I don't know the best path to take:

  1. Fix line 220 of node_gallery.inc so that it doesn't select f.*, but selects every column except uid from table f. While this approach will work, I don't know if this is the "drupal way" - if the core devs add a column to the file table, we'll not pick it up until we change this code.
  2. Change the order of the merge on line 274 of node_gallery.module so that the uid on the node trumps that of the file. This is much less of a hack, but has possible repercussions as it might break something else
  3. We can leave the SQL alone, but manually delete the uid key from the array before we return from node_gallery_get_image_file().

Personally, I think option 3 is the best way to go, but would love some input.

I'm just glad I found this, it's been nagging me for days!

CommentFileSizeAuthor
#1 Issue_637958.patch816 bytesjustintime
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

justintime’s picture

Assigned: Unassigned » justintime
Status: Active » Needs review
FileSize
816 bytes

I love it when bad bugs die with < 3 lines of code!

Here is a patch implementing #3 above.

justintime’s picture

Just a note - this same collision is happening between node.status and file.status. I'm guessing we should also delete the status attribute from the object too? Otherwise, a node marked as unpublished will appear as published when linked to a file that is published.

kmonty’s picture

I'm glad you found this too! This bug was preventing me from closing out #550994: Admin editing gallery changes user ID

I'm in favor of option #3 myself, so I'll use that and just document this thread in code in the event something likes this ever rears its head again.

Thanks!

kmonty’s picture

Status: Needs review » Fixed

Committed.

Unfortunately it did not help solve the issue mentioned previously, although it did help solve one of the two bugs introduced by my patch.

Status: Fixed » Closed (fixed)

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