Closed (fixed)
Project:
Feeds
Version:
7.x-2.x-dev
Component:
Miscellaneous
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
5 May 2011 at 08:08 UTC
Updated:
20 Aug 2014 at 19:40 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
anonI almost have the same problem. What I want to do is to import a csv file from private://.
Edit: My bad, this works for me.
Comment #2
pcambraI think public:// is hardcoded in FeedsFileFetcher.inc
Comment #3
gollyg commentedIt is not hardcoded (or at least it isn't now). It is retrieved from file_default_scheme(), which is set via the file system configuration in the UI.So to enable it to automatically look in your private directory you need to change your default filesystem setting.Although, I am not sure what the rationale is for using that as the *only* place you can place the file. The code comments state that you could potentially upload any file from the server, but I would imagine that using private:// or public:// stream wrappers should solve that issue?Perhaps file_stream_wrapper_valid_scheme() could be used instead? This would validate that the scheme is supported. Otherwise, a simple check on the uri file_uri_scheme matching public or private could be used?Re-read the issue. I see what you are saying.
Comment #4
znerol commentedI had the same need. The attached patch exposes new configuration options for the upload directory. It also allows the administrator to restrict the url-schemes available for users for direct import.
Comment #5
znerol commentedComment #6
johnvNice patch, 2 remarks:
1. shouldn't the upload directory be a module-setting, rather then an importer setting? I don't care where the files are, I want them private and in a/any feeds-directory. Now I need to think again with every new Importer.
2. the feature to import the same file again is lost.
This is my testcase:
First set the general filesystem to Private:
- admin/config/media/file-system : set the Default download method to 'Private local files served by Drupal.'; set corresponding System paths
Set the File-fetcher for the importer to Private:
- admin/structure/feeds/my_importer/settings/FeedsFileFetcher: set Upload directory to 'public://feeds'
Then import data:
- import/my_importer
- select a file;
- press [Import]
- after finishing the import, press [Import] again. You would want to import the same file incase you are testing the importer, and have made some adjustments.
Above worked previously, but I now get an error 'Upload a file first.'
Comment #7
znerol commented1: I don't have any idea how I'd implement a module-wide setting for the file fetcher class. Can you give an example of another fetcher class which does that?
2: The validation code is very messy. IMHO it would be best to split up this class in one for file-uploads and another one for the server directory import batch. They really do not share much code. Nevertheless, patch attached reenabling the behaviour that the last file is used when none is uploaded.
Comment #8
johnv@znerol
1. Indeed, there is no module-settings page, so your patch is OK.
2. Thanks for that update. I wil test again.
Comment #9
johnvAnd the update from #7 is fine, too.
Be careful, that is an add-on to #4.
Comment #10
jmariani commentedHI.
Here's a replacement module to fix the "public" issue.
Please try.
jmariani@git.drupal.org:sandbox/jmariani/1394414.git
Comment #11
johnvjmariani, i cannot access your sandbox.
Comment #12
philipnorton42 commentedYou can view jmariani's sandbox here http://drupal.org/sandbox/jmariani/1394414. Unfortunately, as the module only contains the .info file and the description just advises a simple change to the code I don't really see much point to it.
I have tried the changes proposed by znerol and everything works perfectly. Thanks for the work you have done here znerol! I couldn't get his patches to apply to my code so I applied both of his patches by hand and created a new patch that combines the two (attached).
I would very much like to see this in the next version of Feeds :)
Comment #13
znerol commentedI use #5 and #7 in production on top of 7.x-2.0-alpha5. You can apply those patches using patch parameter
-p1:I set this to RTBC. Would be great if I won't have to patch new releases...
Comment #14
philipnorton42 commentedI found an issue with the code when I tried to migrate this code from one server to another. A fatal error occurs when the file wrapper can't be found due to a misconfiguration between the module and core. Essentially, with the above patch in place Feeds thinks a wrapper called "private" should exist, but Drupal can't find this if the private files haven't been set up yet. The function file_stream_wrapper_get_instance_by_uri() will return false in this instance.
I have attached another small patch to safely handle this issue.
Comment #15
philipnorton42 commentedI found another issue with this code. When downloading a previously uploaded file that has been set to "private://" Drupal will look for any module that implements hook_file_download() to see if any module wants to assign responsibility. As the Feeds module doesn't implement this hook I have created a patch that adds it. Without this hook in place an infinite loop is generated.
The two checks that the hook currently does are:
- Is the file any to do with Feeds?
- Does the user have access to import into this feed.
If no problems are found then the file headers are returned, which prompts Drupal to issue a file download.
It would be great to implement the private file mechanism into some of the tests that are included. I might take it upon myself to do just that :)
Comment #16
franzComment #17
franzAdding keywor for tests as suggested.
Comment #18
philipnorton42 commentedOk. I've finally got around to putting together the test for the private files.
I initially collated everything into a single patch file as the original patches from znerol wouldn't apply to the current version of Feeds. This might need further work but it appears to be behaving nicely at the moment. :)
Comment #19
znerol commentedThanks Phil! The patch applies, tests pass. The code looks okay. I think that #18 should be commited.
Comment #20
philipnorton42 commentedI'm sorry to bump this, but is there any chance of this patch getting applied to the module? I'm happy to do more work on this if anything is missing/broken.
Comment #21
David_Rothstein commentedI'm attaching a version of the patch that applies against the 7.x-2.0-alpha5 release (since I needed it there).
This is just for anyone who needs it; the patch to review is still #18. I took a look at that and have a quick review coming up.
Comment #22
David_Rothstein commentedOverall, #18 worked perfectly fine for my use case. Testing it a bit more I found a few possible issues, but most of them are small:
When a source is manually specified, it's supposed to be possible to specify either a file or directory. This code seems to be assuming that it's always a directory, though. So it seems to break the feature where you can specify a file?
Was removing this line intentional?
The last line should probably use
t('File wrapper @scheme not found.', array('@scheme' => file_uri_scheme($uri)))? Also, there's a minor code style issue ("else {" should be on its own line).Probably need to resolve (or remove) the FIXME :)
I think using reset() inline like that will cause PHP notices in some configurations (since it modifies the input array and therefore needs an actual array to work with). So something that sticks
explode(':', $values['source'])into a variable out front would be better.Alternatively, wouldn't using file_uri_scheme() here work, and be simpler?
Beyond those relatively minor issues (well, except the first one, which may not be so minor), the patch looked good to me and seemed to work well, although I'm not much of a Feeds expert myself...
Comment #23
znerol commentedThe code is actually correct. Though it may profit from some enlightening comments...
[...] Code for file-upload here [...]
The code for direct-mode, i.e. source is a directory on the server is in the
elseclause.Comment #24
David_Rothstein commentedBut that's exactly where the bug is (in direct mode, not file upload).
When direct mode is being used, the text that is displayed on the screen says that it's supposed to work if you type in either an existing directory or an existing file on the server. And before the patch, I'm pretty sure it does. But after the patch, it only seems to work for an existing directory.
Comment #25
znerol commentedOk, got it. I'm working on a patch.
Comment #26
znerol commentedVoilà.
Comment #27
philipnorton42 commentedThanks for the fix znerol.
I can confirm that both the private files and the direct imports work as expected.
Comment #28
johnvFor me, patch #26 is fine.
Comment #29
kristen polSince @philipnorton42 and @johnv confirmed patch in #26, I'm marking RTBC.
[edit] I didn't try private files, but was able to use a format like:
and it used the correct subdirectory (e.g. "something" in example above).
Comment #30
trevorw commentedAny comment on if this will be included in future release?
Idea for some stuck on this too and don't want to run patched code, use Apache (or your webserver of choice) to forbid access to files.
Comment #31
mikran commentedPatch #26 works nicely
Comment #32
franz#26: 1147734-Configurable-upload-directory-for-FeedsFileFetcher-25.patch queued for re-testing.
Comment #33
twistor commentedAwesome patch! Made some changes/improvements.
Should just need a quick review and be good to go.
Comment #34
znerol commentedNice work!
hook_file_downloadnow finally looks sane. I also like the rest of the patch - better validation messages, states, refactoring aroundgetSchemeOptions.However one thing smells a little bit:
We have three times
!$values['direct']here and it seems to me that the lastelseifis dead code.Comment #35
znerol commentedI think the intention was something like this (patch attached):
Comment #36
twistor commentedGood enough for me.
Comment #37
twistor commented@zenerol, thanks for sticking with that patch.
7.x http://drupalcode.org/project/feeds.git/commit/38e7898
Comment #38
marktheshark commentedIn latest dev the only available schema is still public://. Will this patch be officially released?
Comment #39
znerol commented@marktheshark: Please make sure that you set up a valid path for the private file system in admin/config/media/file-system. Also note that this feature is D7 only at the moment.
Comment #40
marktheshark commentedThanks for the info. Is it already included in D7 though already or do I need to apply a patch?
Comment #41
znerol commented@marktheshark: Its included in the dev-version of feeds.
Comment #42
gandhiano commentedI tried the dev version and the issue still persists - all files are uploaded to the public:// root folder, despite all other settings (files retrieved from private://, URI private, file on content type set to use private).
Comment #43
megachriz@gandhiano
Have you set a private file system path at admin/config/media/file-system?
Have you set the "Upload directory" setting of the file fetcher to "private://feeds"?
Or have you mapped to a file field and the files that are being imported don't arive on the private path? That would be a different issue. This issue is about the file you are uploading on the import page.
Comment #44
gandhiano commentedYes, I misunderstood - my issue is about the files being imported, there is no problem with reading from a file on a private:// folder (which I'm also doing), so I think this one can be marked as fixed. I will open or look for another issue.