I added an image field to the user field list.
Unfortunately, when I try to add an image to the field I get an error line 459 in file "file.field.inc" because items[$delta] is empty.
I digged in and discovered that the file gets deleted before being saved... so the field is empty but shouldn't.
After further verification, I noticed that we have, line 274 of file.field.inc:
if (isset($original_item['fid']) && !in_array($original_item['fid'], $current_fids)) {
// Decrement the file usage count by 1 and delete the file if possible.
file_field_delete_file($original_item, $field, $entity_type, $id);
}
In fact, the files get deleted when $current_fids is empty, which happens when you first create a field.
Shouldn't we do something like below to prevent this?
if (isset($original_item['fid']) && !in_array($original_item['fid'], $current_fids) && count($current_fids)>0) {
// Decrement the file usage count by 1 and delete the file if possible.
file_field_delete_file($original_item, $field, $entity_type, $id);
}
I tested, my problem is gone with this patch.
Comments
Comment #1
emmene-moi commentedbut then the field data is duplicated...
Comment #2
sun.core commentedSounds good. Can you roll a proper patch?
Comment #3
pillarsdotnet commentedPatch rolled.
Comment #5
pillarsdotnet commentedGood testbot... Nice testbot...
Comment #6
emmene-moi commented