Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If the feed contains urls to files, that dosn't exists, feeds correctly trows errors in FeedsEnclosure::getFile() and with the fix in #2053355: Notice: Undefined variable: file FeedsParser.inc:388 no file object will be returned. Anyway I get the following warnings and errors, when a (remote) file does not exists:
Undefined index: fid file.field.inc:219 [11.45 sec, 45.77 MB] [notice]
array_flip(): Can only flip STRING and INTEGER values! entity.inc:178 [11.45 sec, 45.77 MB] [warning]
Trying to get property of non-object file.field.inc:220 [11.45 sec, 45.77 MB] [notice]
Undefined property: stdClass::$uri file.inc:566 [11.46 sec, 45.77 MB] [notice]
Undefined property: stdClass::$filemime media.types.inc:196 [11.46 sec, 45.79 MB] [notice]
WD node: PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'uri': INSERT INTO {file_managed} (filesize, status, timestamp, type) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1,
:db_insert_placeholder_2, :db_insert_placeholder_3); Array
(
[:db_insert_placeholder_0] => 0
[:db_insert_placeholder_1] => 1
[:db_insert_placeholder_2] => 1375197803
[:db_insert_placeholder_3] => default
)
in drupal_write_record() (line 7136 of /drupalroot/includes/common.inc). [11.5 sec, 46.09 MB]
The problem is that file_feeds_set_target()
(in mappers/file.inc) always creates $field[LANGUAGE_NONE][$delta]
and ads it to the entity. In cases the file could not be added the value shouldn't be added to the field.
Comment | File | Size | Author |
---|---|---|---|
#5 | feeds-file-field-2053837-5.patch | 3.13 KB | GaëlG |
#3 | feeds-file-feeld-2053837-2.patch | 2.68 KB | osopolar |
#1 | feeds-file-feeld-2053837-1.patch | 2.62 KB | osopolar |
Comments
Comment #1
osopolarThe function
file_feeds_set_target()
is called for uri, alt and title separately. Therefore adding the value to the field could not be controlled inside this function.This could be solved using the hook_feeds_presave(). Before the entity gets saved all file/image fields could be checked if they are containing the file object by checking if the fid is present.
Patch attached.
Comment #3
osopolar$entity->type is not for every entity available. Using entity_extract_ids() instead.
New Patch attached.
Comment #4
osopolarComment #5
GaëlGIt did not work for multilingual fields (using this patch: https://drupal.org/comment/8016755#comment-8016755).
Comment #7
osopolarThanks GaëlG, for adding multilingual stuff.
Some suggestions to improve this code:
Instead of
I propose
And below the above code we also need to check the following:
Due to changes by issue #2093651: Simplify target callbacks. the patch won't apply to the current d7 dev. So if somebody ports the patch to current dev, would be nice if above changes would be included too.
Comment #8
Max1 CreditAttribution: Max1 commentedComment #9
Max1 CreditAttribution: Max1 commentedComment #10
twistor CreditAttribution: twistor as a volunteer commentedI highly doubt this is a problem in dev anymore. We call _field_filter_items() for every field now. That's basically what this patch does. Plus, file_field_presave() also filters out field values with missing fids.