=Short Description=

When using a FileFetcher attached to a feed node to upload a file, the resulting filepath of the uploaded file does not get saved. This means that the file's content never gets loaded into 'batch->raw', and the filepath does not 'stick' for subsequent node edits.

= Environment Info =
Feeds Dev (downloaded from CVS on 2010-03-12)
Acquia Drupal 6.15
MySql 14.14, distrib 5.137

=Longer Description=
FileFetcher does not seem to work when it is part of an importer that is attached to a feed node.

This is repeatable. Here is how to see it for yourself:

1. Override the default 'Feed' importer to use 'File Upload' for the fetcher.
2. Save an RSS feed to a file (see the attached 'topstories' file for an example)
3. Create a Feed node and use the 'upload' field to upload the saved RSS file
4. Save the node.
5. Try to do an import on the node. No feed content will be found.
6. Try to edit the node. The Feed 'file' fields will be blank.

= Diagnosis =
It looks like the file is being uploaded successfully, but that the path is not being saved as the 'feed source'. It looks like we are trying to save the path in feeds_nodeapi function for 'validation' operations, but that this save is unsuccessful.

I had used the development module's debugging 'dvm' statements to trace file uploading. The file does get successfully uploaded into the '*/files/feeds/' directory. But the path to this file does not get saved.

On line 83 of FeedsFileFetcher.inc in the sourceFormValidate function, it looks like we are trying to save the path to the Feed subform's 'source' field

// If there is a file uploaded, save it, otherwise validate input on                                             
    // file.                                                                                                         
    if ($file = file_save_upload('feeds', array(), $feed_dir)) {
      file_set_status($file, FILE_STATUS_PERMANENT);
      $values['source'] = $file->filepath;
    }

The sourceFormValidate function gets called via 'configFormValidate' on line 277 of feeds.module, in the feeds_nodeapi function, for the 'validate' operation. It looks like the feeds_nodeapi function tries to update the '$node' object with form values. Within the 'validate' operation code block the node object does get updated (e.g. $node->feeds->source has the file path). But the node object data seems to get lost when the 'update' operation code block comes around (e.g. $node->feeds->source is blank).

I'm not sure what is causing this. Perhaps node form values can not be modified in validate functions?

CommentFileSizeAuthor
#5 740962-5_upload.patch5.91 KBalex_b
topstories.txt36.79 KBocean_cybrarian
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alex_b’s picture

Thank you for the detailed report. Need got get time to review this.

alex_b’s picture

Is this the same issue as reported here?

#740442: filefield_feeds_set_target not beeing invoked

ocean_cybrarian’s picture

This is not the same issue.

The bug I reported above (http://drupal.org/node/740962 ) is in reference to the 'upload' file field on a feed node's editing/creation form.

I think the bug in http://drupal.org/node/740442 is about trying to parse a source element into a mapping field.

By the way, I'm in general very impressed by the Feeds code, love your work.

alex_b’s picture

#3 - thank you for quick response and the appreciation of Feeds. Give me some time to review this issue closer.

alex_b’s picture

Priority: Normal » Critical
Status: Active » Needs review
FileSize
5.91 KB

You were right, changes to $node->feeds in 'validate' are not carried over to 'update'/'insert' stages. That has to do with how values are passed within node module (see node_form_validate() in node.pages.inc). BTW, we've already run into this issue - just look at how the title is cached between 'validate' and 'presave'.

Here is the fix. The attached patch...

A ... caches $node->feed in nodeapi() so that plugin's configFormValidate() methods can modify the $value array on node forms just as on standalone forms.
B ... moves validation stage all the way up to the beginning of 'validate' to have the uploaded file available when retrieving the title.
C ... adds $form['#attributes']['enctype'] = 'multipart/form-data'; as upload on forms wasn't working at all if upload module wasn't installed.
D ... adds a test that verifies correct behavior when using the file fetcher on a node.

Can you verify whether the attached patch addresses all the problems you found?

This should go into the next release, setting issue to critical.

ocean_cybrarian’s picture

Status: Needs review » Fixed

The patch addresses all of my problems.

Thanks for the fix Alex!

Changing status to 'fixed'.

alex_b’s picture

Status: Fixed » Reviewed & tested by the community

Glad to hear that. The patch isn't committed yet, so I'll changes it to RTBC.

Will White’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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