I know there have already been (actually more than one) issues raised regarding CSV import on a Mac and not recognizing the Mac line endings.
The decision was made to close those issues and add a comment in the documentation somewhere (to be honest - I can't even find it anymore. It is pretty tough to find - it's not directly from the Feeds Project page.) and not make a change because it only affects Mac users and the fix has a small performance hit.
The result is that any user using Feeds and Import from a file that has Mac endings will get the following:
- No Error messages
- Nothing happening (as in not working and no feedback as to why)
I don't know the percentage of Drupal developers on Mac - but my impression is it is quite a large group. To me this is not a good basis to close the issue.
My suggestion/plead would be to either have the default configuration such that it does work on Mac OR add a reasonable error message to give some possible indication as to what is going on (this is especially tough since the current site builders handbook has a link to www.example.com for how to setup a CSV import - a link that is broken).
Thanks for any re-consideration of this issue!
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | node_import_with_mac_excel_endings.csv_.txt | 119 bytes | dman |
| #16 | feeds_csv_line_endings-912682-20111008.patch | 334 bytes | dman |
| #8 | line-ending.patch | 1021 bytes | snyderp |
| #6 | 912682-6_auto_detect_line_endings.patch | 533 bytes | alex_b |
Comments
Comment #1
chrsnlsn commentedRan into this problem yesterday,
usually when running my own csv imports I throw this in the top of the file to prevent issues on my mac.
ini_set('auto_detect_line_endings', true);
Later today if I get back to it I will add this to the module and do some tests with my files that weren't working to see if it fixes the issue here.
edit: I added the line to the top of ParserCSV.inc and that fixed the problem.
Comment #2
bobgeier commentedSubscribing
It is a pain to do a replace of Mac CR with a CR/LF combination all the time.
Will try Dru-paul's fix.
Comment #3
alex_b commentedI'd like to make auto detect line endings a hidden setting (see README.txt)
My question now is whether it should be on or off by default. This basically breaks down to:
1. How large is the performance penalty? E. g. on a 10k lines file?
2. How common are carriage-returns as item separators?
http://www.php.net/manual/en/filesystem.configuration.php#ini.auto-detec...
I think 2. is not an issue. I'd like to get a better idea of 1. before turning on auto_detect_line_endings per default. If we can't answer the performance question, I am happy to accept a patch that makes it a hidden setting and leaves it off for now.
Comment #4
chrsnlsn commentedAlex to help shed some light on #1. I found this.
Here
http://bugs.php.net/bug.php?id=23636
So this leads me to believe the size or number of lines in a file has no affect if it is only used when the first line of the file is read.
We've been fine on CSV imports of around 1800 lines.
Comment #5
alex_b commented#4: that's useful to know, thanks. Seems like performance is not going to be a hurdle. An actual performance test is quick and won't hurt though.
Comment #6
alex_b commentedIf we can confirm that the performance penalty is minimal, this patch is may be all we need.
Comment #7
alex_b commentedComment #8
snyderp commentedI've also attached a fix that's been working for me. It
- replaces the line endings CSV files to unix ones that the PHP file functions recognize
- saves the normalized file as a temporary file
- uses the new temporary file to iterate over
If there is any nervousness about making the import depend on a PHP ini setting, this alternative is working well for me.
(this is a first attempt at a Drupal patch. If I'm going through the wrong channels or goofing here, sorry in advance!)
Comment #9
alex_b commented#8
I don't think that's a good approach as it loads a potentially huge file into memory, parses through it and then writes it back to disk. Back to #6.
From a technical perspective, there are 2 things not right with the patch
- it's not rolled from the project directory
- it uses tabs where it should use spaces http://drupal.org/coding-standards
Comment #10
snyderp commentedSorry for the delayed response and thank you very much for the feedback on the patch. I'll be sure to correct these issues for future patches!
Comment #11
vinmassaro commentedI've been running into the same issue and tried different things to get it to work. The main thing was I had smart quotes in a CSV that were only allowing partial imports into Feeds. One method that seems to work for me is:
I created the source CSV file in Excel in Windows, using the CSV (Macintosh) setting. I have not tried creating the source file using Excel for Mac because I did not see a CSV file extension in the save options.
Comment #12
ohthehugemanatee commentedHm... I tried the patch in #6, and it doesn't seem to make a difference to me. CSVs created in Mac Excel still don't work, unless I manually edit the CSV in vi to replace the ^M linebreaks with "real" unix ones. Feeds 6.1.0-beta10 .
I should note that the CSV contains some multi-entry taxonomy term fields (haven't done anything to make it detect those yet), and a long quoted body. It's possible that PHP is picking up the wrong character for line endings, and then not finding any.
Comment #13
kostajh commentedPatch in #6 works great. Thanks!
Comment #15
carn1x commentedSubscribe
EDIT: For anybody else who comes across this in the mean time, I find the quickest solution so far is to edit the CSV in vim and run the command
:%s/\r/\r/gComment #16
dman commented#6 is definitely the most correct fix possible.
And it worked for me today, when I hit it for the first time (after committing the sin of trying to use Excel on the Mac)
Here's a re-roll against todays 7.x-2.x-dev.
Test, commit and backports are all trivial, safe, and I can't imagine any performance issue with what is a core PHP utility.
If this problem is a 'feature request', then due to the unhelpful lack of error message ("There were no new nodes" - which could indicate an error anywhere)
I'd prefer the message said "This CSV appears to be empty" - which would give us a clue where to look. I spent quite a while backtracing the process until I found that the CSV thought the entire file was a header line.
Comment #17
beauz commented#16 works well for me, had the same issues with excel mac.
Comment #18
ambientdrup commentedI ran this patch. Now I can import my nodes again on a Mac using Feeds. However one of my CSV columns is still throwing issues on the import. When I import the column I'm mapping to my node "Body" field is throwing this error in Drupal:
I have FULL HTML set on my import as the text format, and this column does contain HTML. It worked before when I first installed Feeds but now it's not working on re-import and also once I've applied the patch per above.
Additionally if I remove this column mapping on the import, the rest of the import works and the nodes are created without issue.
Any suggestions?
-Trevor
Comment #19
ambientdrup commentedFigured it out. The CSV files need to be in UTF-8 format. Per this post:
http://drupal.org/node/1140194#comment-4679698
I tweaked them and now they are importing as long as they have been saved in UTF-8.
Seems to be working now.
I'll try this without the patch applied as well as now I'm not sure if the patch is required if they are in UTF-8.
-Trevor
Comment #20
ambientdrup commentedYes this does seem to work without having to apply the patch. All I needed to do is re-save my CSVs in UTF-8. Then they import fine.
-Trevor
Comment #21
colanThis should be re-rolled to work with #1369874: Don't roll own CSV parser; use PHP's native one.
Comment #22
Rob_Feature commentedStill running into this and it's been 8 months since the last comment. Status on this?
Comment #23
tomrishworth commentedI just spent a few hours wondering why my imports weren't working. Only when I went to open the csv file in my code editor, that a warning came up about line endings which lead me to this issue.
I used a program called CSVEditor for mac, in which you can select the line endings you want when saving. This fixed the issue for me.
Comment #24
ari-meetai commentedAgreed with #16 on the error messages. Thanks for the work on the patch.
Comment #25
ari-meetai commentedPatch on #16 works for me.
Comment #26
twistor commentedhttp://drupalcode.org/project/feeds.git/commit/b32b431
Committed to 7.x
Comment #27
twistor commentedhttp://drupalcode.org/project/feeds.git/commit/ed44dd1
Comment #28
dman commentedTHANKYOU!