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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

osopolar’s picture

Status: Active » Needs review
FileSize
2.62 KB

The 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.

Status: Needs review » Needs work

The last submitted patch, feeds-file-feeld-2053837-1.patch, failed testing.

osopolar’s picture

+++ b/mappers/file.inc
@@ -131,3 +135,44 @@ function file_feeds_set_target($source, $entity, $target, $value) {
+  $field_info_instances = field_info_instances($entity->feeds_item->entity_type, $entity->type);

$entity->type is not for every entity available. Using entity_extract_ids() instead.

New Patch attached.

osopolar’s picture

Status: Needs work » Needs review
GaëlG’s picture

Issue summary: View changes
FileSize
3.13 KB

It did not work for multilingual fields (using this patch: https://drupal.org/comment/8016755#comment-8016755).

Status: Needs review » Needs work

The last submitted patch, 5: feeds-file-field-2053837-5.patch, failed testing.

osopolar’s picture

Thanks GaëlG, for adding multilingual stuff.

Some suggestions to improve this code:

Instead of

if (in_array($field_info['type'], array('file', 'image'))) {
  ...
}

I propose

    if (!in_array($field_info['type'], array('file', 'image'))) {
      continue;
    }

And below the above code we also need to check the following:

    // Nothing to validate if field is empty.
    if (empty($entity->{$field_info['field_name']})) {
      continue;
    }

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.

Max1’s picture

Max1’s picture

twistor’s picture

Status: Needs work » Fixed

I 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.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.