this seems to me to be exactly the same issue as reported in #1350162: CSV unrecognized

i have Node Export and Node Export CSV installed. i export a node in CSV format and then try to paste that code into the Import form. i also try downloading the export to a file and then importing that file.

in both cases, i get "Node export was unable to recognize the format of the supplied code. No nodes imported."

the problem is that when node_export_csv_node_export_import() compares the counts of the first and second rows of the array created by node_export_csv_csv_to_array(), the counts are unequal. some further testing showed that the data row is missing some keys:

2 : language
18 : log
22 : picture
26 : menu['link_title']

it is apparently not handling blank cells correctly - the parts of the original CSV line that look like ",123,,456,"

if i take the CSV and use it to define arrays in a PHP file, delimiting all of the cells with double quotes, the counts are equal.

this is the sample export CSV

nid,type,language,uid,status,created,changed,comment,promote,moderate,sticky,tnid,translate,vid,revision_uid,title,body,teaser,log,revision_timestamp,format,name,picture,data,uuid,revision_uuid,menu['link_title'],menu['mlid'],menu['plid'],menu['menu_name'],menu['weight'],menu['module'],menu['expanded'],menu['hidden'],menu['has_children'],menu['customized'],menu['parent_depth_limit']
465,story,,1,1,1330139899,1330139903,0,1,0,0,0,0,735,1,test story node for export / import,this is only a test,this is only a test,,1330139903,1,admin,,a:0:{},5ff26ce0-5f5f-11e1-a208-0019d169b656,FALSE,,0,0,primary-links,0,menu,0,0,0,0,8

even if i change that CSV to look like 465,story,"",1,1,... the import fails. it looks like node_export_csv_csv_to_array() is depending on there being some value between enclosures to create a cell in the row of the array it creates.

Comments

danielb’s picture

Thanks for reposting and narrowing down the problem and investigating column counts (that was the problem in the other issue). I've got a lot of pies to cook, but I'll be sure to test out this case soon.

danielb’s picture

I can confirm the bug plus additional problems with some code that hasn't been backported from D7

danielb’s picture

I've committed some fixes and they'll appear in the next dev snapshot (check the date is after this posting). It should add "" instead of empty strings, so you'll have to export again. It also fixes stuff on the import side of things and changes how variables are decoded.

danielb’s picture

Hmm it seems to output """""" instead of ""

Not really ideal, obviously "" gets enclosed in more "" and then each " gets escaped with another ", but it works.

I'll see if I can improve it though.

danielb’s picture

Status: Active » Needs review

OK I'm pretty happy with it, have made another commit. I'll leave the issue open a little while in case there are any objections.

danielb’s picture

Status: Needs review » Active

Hmm it really should handle the original case you reported, but it seems pretty hard to do because of how it works :/
I'll fiddle about with it and see.

danielb’s picture

Status: Active » Needs review

Alright I've changed it again, removed the "" strategy, now it should detect double commas ,, and assume an empty value exists there.
So with this new code you should be able to import your old CSV that you already exported.

brad.bulger’s picture

I downloaded the latest dev version and tried the same case again - worked like a charm. I tried pasting the CSV produced by export into the import form, worked fine. I also confirmed that downloading the CSV as a file and then importing from the file worked.

Thanks for digging into this!

brad.bulger’s picture

oh, i see, this is still the multiple double-quotes. i'll try it again in a while to pick up the latest changes.

brad.bulger’s picture

Using the 27 Feb dev build, the only issue I'm seeing now is a different one - I'm getting eval parse errors trying to import a node with single quotes in the text.

The import CSV:

nid,type,language,uid,status,created,changed,comment,promote,moderate,sticky,tnid,translate,vid,revision_uid,title,body,teaser,log,revision_timestamp,format,name,picture,data,menu['link_title'],menu['mlid'],menu['plid'],menu['menu_name'],menu['weight'],menu['module'],menu['expanded'],menu['hidden'],menu['has_children'],menu['customized'],menu['parent_depth_limit']
465,story,,1,1,1330139899,1330446222,0,1,0,0,0,0,735,1,test story node for export / import again,"this is only a test. Let's add some, hmm, ""quotes"" and things, shall we?

Certainly, certainly.
","this is only a test. Let's add some, hmm, ""quotes"" and things, shall we?

Certainly, certainly.
",,1330446222,1,admin,,a:0:{},,0,0,primary-links,0,menu,0,0,0,0,8

The parse errors, and the code that caused them:

$node->body = 'this is only a test. Let's add some, hmm, "quotes" and things, shall we? Certainly, certainly. ';

Parse error: syntax error, unexpected T_STRING in /var/www/drupal/sites/all/modules/node_export/modules/node_export_csv/node_export_csv.module(207) : eval()'d code on line 1

$node->teaser = 'this is only a test. Let's add some, hmm, "quotes" and things, shall we? Certainly, certainly. ';

Parse error: syntax error, unexpected T_STRING in /var/www/drupal/sites/all/modules/node_export/modules/node_export_csv/node_export_csv.module(207) : eval()'d code on line 1

When I put in a quick hack to escape the single quotes, everything else looked fine - the null values are unquoted, the CSV imports fine as pasted code and uploaded file, and the downloaded CSV file opens correctly as a spreadsheet.

danielb’s picture

I've just committed a quick hack for that too then.

danielb’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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