| Project: | Drupal core |
| Version: | 7.x-dev |
| Component: | file.module |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
file_field_update() (file field's implementation of hook_field_update()) checks if a value has been removed from the previous values, to keep track of file references.
It hardocodes a check on $object->revision. See #644332: Do we need to abstract $object->revision ('new revision') property about that.
More problematic, to compare new values with previous values, it does a full load the current object.
a) I'm not sure the current code is the correct way of doing that - could use the opinion of an entity API guru.
$load_function = $obj_type . '_load';
$original = $load_function($id);(this is the main reason I'm marking this 'critical')
b) entity_save() triggering an entity_load() doesn't sound too great. Reacting on values being removed is a legitimate use case for 'resource reference' field types, I'm wondering if we can make this better.
Comments
#1
subscribe. still getting my head around the fields code, came across this function here #618654: (Fixed, but needs cleanup) File and image fields are treated as temporary files and automatically deleted after six hours.
#2
Not critical. Please read and understand Priority levels of Issues, thanks.
#3
#733756: image_field_insert() makes no sense and causes a memory leak with devel_generate() was a memory leak on inserts caused by this, although that was fixed by completely removing image_field_insert().
Subscribing to this one.
#4
I think that instead of a full entity load, the code could use field_attach_load() with $options = array('field_id' => $field['id']) to get the current values of the field for the object. This is guaranteed to work whatever the entity type, and would avoid triggering a full entity load() during an entity update().
#5
Quick patch, not tested - I don't know if this part is tested in the current test suite, for that matter.
#6
The last submitted patch, file_field_load_on_update.patch, failed testing.
#7
Oops, f_a_load() works by altering the entity by ref.
#8
That works for me, do we want to defer the $revision stuff to #644332: Do we need to abstract $object->revision ('new revision') property?
#9
Yes, that other issue has more discussions on that topic.
#10
RTBC, then.
#11
Committed to CVS HEAD. Thanks.
#12
Automatically closed -- issue fixed for 2 weeks with no activity.