Hi,
I've noticed this issue while trying to deal with Files that were still associated with past revisions. I noticed that while creating a new node and saving it and afterward creating a new revision from it and attaching a file to that revision I am seeing in the database in the file_usage table that for this particular node and file ID of that new file the count is 2. However that cannot be possible as this is a completely new file and shouldn't be set as if it were used in 2 places.
So while I was tracking this down I noticed in the workbench_moderation.module file on line 698 it calls field_attach_update. Problem is file_field_update (from field.attach.inc in the file.module of Core) had been called prior to that which correctly set the count to the new file to 1 for that new revision. If that is called again, it will invoke yet another update request and file_field_update will run as if this is a new revision.
That's what I found anyway. Can anyone else confirm whether this is happening?
Thanks
Comments
Comment #1
edward.radau commentedDo any of the maintainers have any feedback regarding this? What I'd really like to know is what purpose does the code in line 698 of workbench_moderation.module serve and if it is at all necessary.
Comment #2
damienmckennaPlease only change the status to "needs review" when you have an actual patch file that needs review. Thanks.
Comment #3
vflirt commentedHere is a patch for that.
Comment #4
vflirt commentedComment #6
vflirt commentedHmm, found the issue that the files get deleted.
This is cause of how all the moderation is handled so node->original will be loaded with node_load before setting the "live" revision to the current one.
So doing node_load will load the draft and the draft would be considered the original for the node_save($live_revision); in function workbench_moderation_store which is obviously wrong and not what is wanted.
Comment #7
vflirt commentedComment #8
HenrikBak commentedDoes the above patch solve the problem with file usage? I have the exact the same issue and also found that field_attach_update was the cause of the problem, but I'm not sure what purpose the function serves in this module.
Comment #9
vflirt commentedAs far as I tested locally it does not call field_attach_update so the file usage stays correct. Feel free to test and see if that works for you.
Comment #10
muriqui commentedRe-roll of #6.
Seems like a good solution to me, given that field_attach_update() is already called by node_save() before hook_node_update() is invoked; workbench_moderation_node_update() probably shouldn't be calling it again inside the same transaction.
Comment #11
rosk0Found the same issue with field collections being not deleted because of this extra revision generated by extra call to field_attach_updated() from workbench_moderation_node_update().
Tested this path, works great.
Comment #12
ram4nd commentedComment #13
fgjohnson@lojoh.ca commentedhttps://www.drupal.org/node/2353491#comment-9670051
Seems to work well when using "Primary Image" in wetkit - offering a usage of 2 for a translated node.
But when putting WYSIWYG images on the same translated node, the counter increments by 1, not 2. :-(
Comment #14
eelkeblok@fgjohnson Are you sure that last point has anything to do with Workbench Moderation? WYSIWYG editors not being able to correctly record usage of files is a fairly common problem.
Comment #15
eelkeblokThis no longer applies to the latest version, unfortunately.
Comment #16
damienmckennaHere are clean rerolls for both the 7.x-1.x and 7.x-3.x branches.
Comment #17
fgjohnson@lojoh.ca commented@eelkeblok Re:
Good to know.
Thought it was bundled up with everything else.
I'll try your patch and report back.
Comment #18
sgdev commentedPatch for 7.x-3.x-dev does not apply cleanly. Referenced code does not exist in the newest release.
Comment #19
damienmckennaI would suspect this would need tests to identify whether or not the problem still exists with the v3 branch, given the major overhaul that went into the 3.0 release.
Comment #20
damienmckennaJust to be clear, someone should write tests that step through what is expected to happen as files are added, then see if the v3 branch still has the bug. Once we have a solid test it'll be easier to fix the problem.
Comment #21
pub497 commentedAs of version 3.0 I no longer have this issue. Creating new revisions containing the same file increases the file count of a specific file, deleting decreases. Creating a new revision of an existing revision but changing the file creates a new file with a count of 1. So latest version is working good.
Comment #22
gomez_in_the_south commentedWe were having the same problem with double rows being created on a single save. Instead of with files, the duplicate rows were with Field Collections. I can confirm that the 3.0 branch fixed the issue for us.
Comment #23
damienmckenna@Gomez_in_the_South: Thanks for the update.
Comment #24
shivamitakari commentedComment #25
shivamitakari commentedUpdated #16 patch to support version 7.x-1.4