I've noticed a problem with attaching fields to file types. I added a taxonomy term to my Document file type and am now seeing a serious flaw in the way that field data is saved. The file_managed and file_managed_revisions vid is not matching up with the attached field's vid, and what's worse, this is causing the value to fall out when I revert revisions. I found a clue to the reason why this is happening, in file_entity_revisions_file_entity_form_submit(), it revisions the file by creating a new copy and keeping the old copy, but once it is done, it calls unset($form_state['values']['replace_upload']). I'm not sure what happens after that, but here is what i'm seeing:

My last revision is vid=40. I replace the file and change the file field's value (in this case, it is a taxonomy representing division). When file_entity_revisions_file_entity_form_submit() is called, the new file has vid=41. When the hook_file_update is called, the file has the correct division TID. Checking the database after, the newest revision is vid=42, so 41 got skipped. That is file_managed however, when checking the field value (field_data_field_division), its vid is 40. Since the current vid is 40, it still shows the correct value while viewing the file, but when you start reverting revisions, problems run amok. I'm seeing that the vid on the fields is always 1 behind the current revision. I'm currently in the process of trying to repair this issue, but any help and insight would be greatly appreciated.

Members fund testing for the Drupal project. Drupal Association Learn more

Comments

pcrats33’s picture

Issue summary: View changes
pcrats33’s picture

In testing, it looks like file_save eventually calls module_invoke_all('file_update', $file) which calls file_entity_file_update() right before file_entity_revisions_file_update(). We need to reverse this order otherwise all the field information will be saved before the new VID is assigned. Hence field information being written with the old VID number.

pcrats33’s picture

I have wrote a patch that reverses the order that hook_file_update is called so that the revisions module is called before file_entity saves the field data. This resolves the issue in its entirety.

pcrats33’s picture

Status: Active » Needs review