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.

Files: 
CommentFileSizeAuthor
#5 feeds-file-field-2053837-5.patch3.13 KBGaëlG
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch feeds-file-field-2053837-5.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
#3 feeds-file-feeld-2053837-2.patch2.68 KBosopolar
PASSED: [[SimpleTest]]: [MySQL] 4,509 pass(es).
[ View ]
#1 feeds-file-feeld-2053837-1.patch2.62 KBosopolar
FAILED: [[SimpleTest]]: [MySQL] 4,511 pass(es), 0 fail(s), and 39 exception(s).
[ View ]

Comments

osopolar’s picture

Status:Active» Needs review
StatusFileSize
new2.62 KB
FAILED: [[SimpleTest]]: [MySQL] 4,511 pass(es), 0 fail(s), and 39 exception(s).
[ View ]

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

StatusFileSize
new2.68 KB
PASSED: [[SimpleTest]]: [MySQL] 4,509 pass(es).
[ View ]
+++ 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
StatusFileSize
new3.13 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch feeds-file-field-2053837-5.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

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

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

I propose

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

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

<?php
   
// 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.