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

edward.radau’s picture

Do 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.

damienmckenna’s picture

Version: 7.x-1.3 » 7.x-1.x-dev
Status: Needs review » Active
Issue tags: -file usage workbench moderation

Please only change the status to "needs review" when you have an actual patch file that needs review. Thanks.

vflirt’s picture

Here is a patch for that.

vflirt’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 3: workbench_moderation-file-usage-count-2353491-3.patch, failed testing.

vflirt’s picture

Hmm, 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.

vflirt’s picture

Status: Needs work » Needs review
HenrikBak’s picture

Does 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.

vflirt’s picture

As 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.

muriqui’s picture

Re-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.

rosk0’s picture

Status: Needs review » Reviewed & tested by the community

Found 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.

ram4nd’s picture

fgjohnson@lojoh.ca’s picture

https://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. :-(

eelkeblok’s picture

@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.

eelkeblok’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

This no longer applies to the latest version, unfortunately.

damienmckenna’s picture

Version: 7.x-1.x-dev » 7.x-3.x-dev
Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new1.27 KB
new1.27 KB

Here are clean rerolls for both the 7.x-1.x and 7.x-3.x branches.

fgjohnson@lojoh.ca’s picture

@eelkeblok Re:

WYSIWYG editors not being able to correctly record usage of files is a fairly common problem WYSIWYG habving issues

Good to know.
Thought it was bundled up with everything else.

I'll try your patch and report back.

sgdev’s picture

Status: Needs review » Needs work

Patch for 7.x-3.x-dev does not apply cleanly. Referenced code does not exist in the newest release.

damienmckenna’s picture

I 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.

damienmckenna’s picture

Issue tags: +Needs tests

Just 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.

pub497’s picture

As 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.

gomez_in_the_south’s picture

We 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.

damienmckenna’s picture

Status: Needs work » Closed (outdated)

@Gomez_in_the_South: Thanks for the update.

shivamitakari’s picture

shivamitakari’s picture

Updated #16 patch to support version 7.x-1.4