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

emmene-moi’s picture

but then the field data is duplicated...

sun.core’s picture

Component: field system » user.module
Priority: Major » Normal

Sounds good. Can you roll a proper patch?

pillarsdotnet’s picture

Component: user.module » file system
Status: Active » Needs review
StatusFileSize
new827 bytes

Patch rolled.

Status: Needs review » Needs work

The last submitted patch, file_field_update.patch, failed testing.

pillarsdotnet’s picture

Status: Needs work » Needs review
StatusFileSize
new828 bytes

Good testbot... Nice testbot...

emmene-moi’s picture

Status: Needs review » Closed (fixed)