Currently, field_attach_update() is called first during file_entity_file_update(). This needs to happen actually after hook_file_update() so that fields will be passed the file entity after it has been saved to the database.

This matters for file_entity_revisions when saving a revision, because the vid passed to the fields hasn't yet been updated with the next vid. This causes the most recent field revision to be overridden with the new data, and the resulting revision_id is one behind where it should be for the corresponding file.

This comes about from #2098007: Field revisioning isnt working quite right.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

reubenavery’s picture

Status: Active » Needs review
FileSize
1.02 KB

My proposed solution is to move the field_attach_update() call into an implementation of hook_entity_update() which is invoked immediately following hook_file_update by file_save().

Here's my little patch.

klonos’s picture

Dave Reid’s picture

Status: Needs review » Postponed (maintainer needs more info)

Invoking field_attach_update as soon as possible is the standard behavior. That's what node_save() does - it invokes field_attach_insert/update before hook_node_insert/update and hook_entity_insert/update.

reubenavery’s picture

hmm.. but it also invokes field_attach_presave() first, which file_save does not.

quite a series of rabbit holes, this process.

reubenavery’s picture

Issue summary: View changes

Adding link to file_entity_revisions issue which started this.