Import: unexpected T_STRING, expecting ')'

Barrett - May 12, 2009 - 19:59
Project:Node Export
Version:6.x-2.6
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:won't fix
Description

I'm moving my blog from one site running 6.11 to another. I've used 6.x-2.6 to export a blog node, copied and pasted the code over to the import window of the new site, but I get the errors below. I'd appreciate any pointers.

Parse error: syntax error, unexpected T_STRING, expecting ')' in /home5/smithwe1/public_html/drupal-6.11/sites/all/modules/node_export/node_export.pages.inc(325) : eval()'d code on line 30

Fatal error: __clone method called on non-object in /home5/smithwe1/public_html/drupal-6.11/includes/common.inc on line 1691

The data being imported is:
array(
'nid' => NULL,
'type' => 'blog',
'language' => '',
'uid' => '1',
'status' => '1',
'created' => NULL,
'changed' => '1234118257',
'comment' => '2',
'promote' => '1',
'moderate' => '0',
'sticky' => '0',
'tnid' => '0',
'translate' => '0',
'vid' => NULL,
'revision_uid' => '1',
'title' => 'Hiking Sugarloaf with Evan',
'body' => 'Yesterday, Evan and I left Molly at home and went to Sugarloaf to hike. Evan followed good hiking practice by having a pre-hike nap in the car on the way.
[G2:4639]

Several of the trails still had snow on them and the trail up to the peak was pretty treacherous.
[G2:4644 class=\"g2image_float_left\"][G2:4642]

We found passable routes, though, and a good spot with a nice view to stop for a snack.
[G2:4646 class=\"g2image_float_left\"][G2:4648]

After a couple hours of hiking, we spent some time playing in the snow before loading up to come home.
[G2:4650 class=\"g2image_float_left\"][G2:4652]

Unfortunately, on the way home Evan got sick...very sick. There was used Z-Bar all over the back seat. He\'s still a little under the weather today, but seems to be on the mend.

Once I got him home and cleaned up, my first thought was, \"I really wish I had sprung for the upholstery protection package when I bought my car.\" Everything came right up though. I was amazed.',
'teaser' => 'Yesterday, Evan and I left Molly at home and went to Sugarloaf to hike. Evan followed good hiking practice by having a pre-hike nap in the car on the way.
[G2:4639]

Several of the trails still had snow on them and the trail up to the peak was pretty treacherous.
[G2:4644 class=\"g2image_float_left\"][G2:4642]

',
'log' => '',
'revision_timestamp' => '1234118257',
'format' => '1',
'name' => 'Barrett',
'picture' => '',
'data' => 'a:2:{s:7:\"contact\";i:0;s:13:\"form_build_id\";s:37:\"form-474d88df20e558c63cf8e3a74c34c6b6\";}',
'path' => NULL,
'last_comment_timestamp' => '1234104158',
'last_comment_name' => NULL,
'comment_count' => '0',
'taxonomy' => array(
'1' => array(
'3' => '3',
),
'tags' => array(
'2' => 'hiking, Sugarloaf',
),
),
'files' => array(),
'menu' => NULL,
'#_export_node_encode_object' => '1',
)

#1

danielb - May 12, 2009 - 23:27

can you please paste the code in a code block or pastebin?

Make sure there are no input filters or wysiwyg on the textarea where you paste it.

#2

Barrett - May 13, 2009 - 02:41

array(
  'nid' => NULL,
  'type' => 'blog',
  'language' => '',
  'uid' => '1',
  'status' => '1',
  'created' => NULL,
  'changed' => '1234118257',
  'comment' => '2',
  'promote' => '1',
  'moderate' => '0',
  'sticky' => '0',
  'tnid' => '0',
  'translate' => '0',
  'vid' => NULL,
  'revision_uid' => '1',
  'title' => 'Hiking Sugarloaf with Evan',
  'body' => 'Yesterday, Evan and I left Molly at home and went to <a href=\"http://www.sugarloafmd.com/\" target=\"_blank\" title=\"Sugarloaf Mountain, MD\">Sugarloaf</a> to hike.  Evan followed good hiking practice by having a pre-hike nap in the car on the way.
[G2:4639]

Several of the <a href=\"http://www.sugarloafmd.com/images/maps/sugarloaf_map1.pdf\" title=\"Trail Map\" target=\"_blank\">trails</a> still had snow on them and the trail up to the peak was pretty treacherous.
[G2:4644 class=\"g2image_float_left\"][G2:4642]

We found passable routes, though, and a good spot with a nice view to stop for a snack.
[G2:4646 class=\"g2image_float_left\"][G2:4648]

After a couple hours of hiking, we spent some time playing in the snow before loading up to come home.
[G2:4650 class=\"g2image_float_left\"][G2:4652]

Unfortunately, on the way home Evan got sick...very sick.  There was used <a href=\"http://www.clifbar.com/food/products_clif_kid_zbar/\" title=\"Clif ZBar\" target=\"_blank\">Z-Bar</a> all over the back seat.  He\'s still a little under the weather today, but seems to be on the mend.

Once I got him home and cleaned up, my first thought was, \"I really wish I had sprung for the upholstery protection package when I bought my car.\"  Everything came right up though.  I was amazed.',
  'teaser' => 'Yesterday, Evan and I left Molly at home and went to <a href=\"http://www.sugarloafmd.com/\" target=\"_blank\" title=\"Sugarloaf Mountain, MD\">Sugarloaf</a> to hike.  Evan followed good hiking practice by having a pre-hike nap in the car on the way.
[G2:4639]

Several of the <a href=\"http://www.sugarloafmd.com/images/maps/sugarloaf_map1.pdf\" title=\"Trail Map\" target=\"_blank\">trails</a> still had snow on them and the trail up to the peak was pretty treacherous.
[G2:4644 class=\"g2image_float_left\"][G2:4642]

',
  'log' => '',
  'revision_timestamp' => '1234118257',
  'format' => '1',
  'name' => 'Barrett',
  'picture' => '',
  'data' => 'a:2:{s:7:\"contact\";i:0;s:13:\"form_build_id\";s:37:\"form-474d88df20e558c63cf8e3a74c34c6b6\";}',
  'path' => NULL,
  'last_comment_timestamp' => '1234104158',
  'last_comment_name' => NULL,
  'comment_count' => '0',
  'taxonomy' => array(
    '1' => array(
      '3' => '3',
    ),
    'tags' => array(
      '2' => 'hiking, Sugarloaf',
    ),
  ),
  'files' => array(),
  'menu' => NULL,
  '#_export_node_encode_object' => '1',
)

#3

danielb - May 13, 2009 - 04:38

Works fine for me mate.

#4

Barrett - May 13, 2009 - 12:07

I don't understand it, but I get the same errors (albeit related to different line numbers) no matter what I try to import. I've tried uninstalling and reinstalling the module, running as root and as non-root, importing different content types (e.g., blogs, books) and with different combinations of settings for the import and I get the same error every time.

#5

danielb - May 13, 2009 - 13:00

Have you tried pasting it back into the site you got it from, does it work there?

Are you sure nothing could change the submitted text in the form like another module or input format?

#6

Barrett - May 13, 2009 - 14:18

Thanks for your help with this, danielb.

It does throw the same error when importing back to the site from which it was exported.

I'm importing through the Import form at admin/content/import. I have no wysiwygs, etc installed and I see no indication as to what filter (if any) that form is applying. The site default is filtered html but even turning off all the filters within that configuration results in the same errors

Node Export is the only non-core module enabled on the exporting site.

I don't know what the relevance is, but I'm also seeing: "Invalid argument supplied for foreach() in /home5/smithwe1/public_html/barrett/sites/all/modules/node_export/node_export.pages.inc on line 334." reported in my error logs immediately after each failed import attempt.

#7

danielb - May 14, 2009 - 10:09
Status:active» postponed (maintainer needs more info)

I can't reproduce this. My strategy would have been to debug the code in node_export.page.inc on line 321-328 using messages and checking the output corresponds to what is expected. For example:

/**
*  eval and return decoded string
*/
function node_export_node_decode($string) {
  drupal_set_message('node_export_node_decode()<pre>'.htmlspecialchars(print_r($string,true)));
  $array = eval('return '.$string.';');
  $return = node_export_node_decode_objects($array);
  return $return;
}

I see you are a module developer so you may be willing to have a go at this, otherwise I have no clue whats going on :/

#8

Barrett - May 14, 2009 - 13:27

I've determined that something isn't going correctly with escaping of single quotes in the body and/or teaser. Notice the line "He's still a little under the weather.." in the body element declaration below. As you can see in the code block showing the code imported (http://drupal.org/node/460756#comment-1582606), it's escaped in the statement as exported but based on the output below is getting lost somewhere in processing.

When I edit the imported code to either remove the single-quote/apostrophe or double escape it (ie "He\\'s") in the code to be imported, it works fine.

node_export_node_decode()

array(
  'nid' => NULL,
  'type' => 'blog',
  'language' => '',
  'uid' => '1',
  'status' => '1',
  'created' => NULL,
  'changed' => '1234118257',
  'comment' => '2',
  'promote' => '1',
  'moderate' => '0',
  'sticky' => '0',
  'tnid' => '0',
  'translate' => '0',
  'vid' => NULL,
  'revision_uid' => '1',
  'title' => 'Hiking Sugarloaf with Evan',
  'body' => 'Yesterday, Evan and I left Molly at home and went to <a href="http://www.sugarloafmd.com/" target="_blank" title="Sugarloaf Mountain, MD">Sugarloaf</a> to hike.  Evan followed good hiking practice by having a pre-hike nap in the car on the way.
[G2:4639]

Several of the <a href="http://www.sugarloafmd.com/images/maps/sugarloaf_map1.pdf" title="Trail Map" target="_blank">trails</a> still had snow on them and the trail up to the peak was pretty treacherous.
[G2:4644 class="g2image_float_left"][G2:4642]

We found passable routes, though, and a good spot with a nice view to stop for a snack.
[G2:4646 class="g2image_float_left"][G2:4648]

After a couple hours of hiking, we spent some time playing in the snow before loading up to come home.
[G2:4650 class="g2image_float_left"][G2:4652]

Unfortunately, on the way home Evan got sick...very sick.  There was used <a href="http://www.clifbar.com/food/products_clif_kid_zbar/" title="Clif ZBar" target="_blank">Z-Bar</a> all over the back seat.  He's still a little under the weather today, but seems to be on the mend.

Once I got him home and cleaned up, my first thought was, "I really wish I had sprung for the upholstery protection package when I bought my car."  Everything came right up though.  I was amazed.',
  'teaser' => 'Yesterday, Evan and I left Molly at home and went to <a href="http://www.sugarloafmd.com/" target="_blank" title="Sugarloaf Mountain, MD">Sugarloaf</a> to hike.  Evan followed good hiking practice by having a pre-hike nap in the car on the way.
[G2:4639]

Several of the <a href="http://www.sugarloafmd.com/images/maps/sugarloaf_map1.pdf" title="Trail Map" target="_blank">trails</a> still had snow on them and the trail up to the peak was pretty treacherous.
[G2:4644 class="g2image_float_left"][G2:4642]

',
  'log' => '',
  'revision_timestamp' => '1234118257',
  'format' => '1',
  'name' => 'Barrett',
  'picture' => '',
  'data' => 'a:2:{s:7:"contact";i:0;s:13:"form_build_id";s:37:"form-474d88df20e558c63cf8e3a74c34c6b6";}',
  'path' => NULL,
  'last_comment_timestamp' => '1234104158',
  'last_comment_name' => NULL,
  'comment_count' => '0',
  'taxonomy' => array(
    '1' => array(
      '3' => '3',
    ),
    'tags' => array(
      '2' => 'hiking, Sugarloaf',
    ),
  ),
  'files' => array(),
  'menu' => NULL,
  '#_export_node_encode_object' => '1',
)

#9

danielb - May 14, 2009 - 23:23

Can you tell me about your server config?

I wonder why it works on mine.

#10

Barrett - May 15, 2009 - 02:26

magic_quotes was the first thing I thought of. They're off. What else would you like to know? Nothing else is jumping out at me in the settings.

#11

danielb - May 15, 2009 - 02:38

What version of PHP are you running?

#12

Barrett - May 15, 2009 - 12:27

5.2.9 on linux

#13

danielb - May 16, 2009 - 00:34

I have 5.2.8, surely that would be similar enough.

#14

danielb - May 16, 2009 - 00:46
Status:postponed (maintainer needs more info)» active

OK I found something that might explain what is going on.
http://au2.php.net/stripslashes and http://au2.php.net/addslashes
It seems there are magic_quotes settings in php that may do this automatically and cause my stripslashes() to go one step too far.

line 338-340 in node_export.pages.inc

<?php

   
if (is_string($v)) {
     
$array[$k] = stripslashes($v);
    }

?>

should become:

<?php

   
if (is_string($v)) {
      if (
get_magic_quotes_gpc()) {
         
$array[$k] = stripslashes($v);
      }
      else {
         
$array[$k] = $v;
      }
    }

?>

that's my theory for now

are you able to check your magic quotes settings in php?

here are mine:

magic_quotes_gpc On On
magic_quotes_runtime Off Off
magic_quotes_sybase Off Off

#15

Barrett - May 16, 2009 - 03:07

That seems reasonable. My settings have all the magic_quotes functions off.

magic_quotes_gpc Off Off
magic_quotes_runtime Off Off
magic_quotes_sybase Off Off

The solution you gave doesn't work though. The $array variable in node_export_node_decode is a string, not an array, because the escaping slash has been stripped before the string is passed into that function, so evaluating it as an array fails.

#16

danielb - May 16, 2009 - 03:31

damn ok

how about something like this to manually double escape stuff???

line 324 node_export.pages.inc

<?php
function node_export_node_decode($string) {
 
$string = str_replace('\\\'', '\\\\\'', $string);
 
$array = eval('return '.$string.';');
 
$return = node_export_node_decode_objects($array);
  return
$return;
}
?>

#17

danielb - May 16, 2009 - 05:47

obviously i'd also need an if test to make sure it only does it for those with magic quotes off.
Just wondering whether the logic of the string replace is correct.

#18

Barrett - May 16, 2009 - 13:16

The slash is getting stripped even farther upstream than that. Adding

<?php
watchdog
('WTF', 'node_export_node_import:<pre>'.htmlspecialchars($node_code).'</pre>');
?>
to node_export_node_import, I get the code below.

I thought that perhaps adding slashes at the stop of node_export_node_import would work, but of course some of the slashes should not be escaped. I think we need to be looking at the export routines instead. Perhaps instead of the export window showing "He\'s" it needs to be displaying "He's"?

node_export_node_import:

array(
  'nid' => NULL,
  'type' => 'blog',
  'language' => '',
  'uid' => '1',
  'status' => '1',
  'created' => NULL,
  'changed' => '1234118257',
  'comment' => '2',
  'promote' => '1',
  'moderate' => '0',
  'sticky' => '0',
  'tnid' => '0',
  'translate' => '0',
  'vid' => NULL,
  'revision_uid' => '1',
  'title' => 'Hiking Sugarloaf with Evan',
  'body' => 'Yesterday, Evan and I left Molly at home and went to <a href="http://www.sugarloafmd.com/" target="_blank" title="Sugarloaf Mountain, MD">Sugarloaf</a> to hike.  Evan followed good hiking practice by having a pre-hike nap in the car on the way.
[G2:4639]

Several of the <a href="http://www.sugarloafmd.com/images/maps/sugarloaf_map1.pdf" title="Trail Map" target="_blank">trails</a> still had snow on them and the trail up to the peak was pretty treacherous.
[G2:4644 class="g2image_float_left"][G2:4642]

We found passable routes, though, and a good spot with a nice view to stop for a snack.
[G2:4646 class="g2image_float_left"][G2:4648]

After a couple hours of hiking, we spent some time playing in the snow before loading up to come home.
[G2:4650 class="g2image_float_left"][G2:4652]

Unfortunately, on the way home Evan got sick...very sick.  There was used <a href="http://www.clifbar.com/food/products_clif_kid_zbar/" title="Clif ZBar" target="_blank">Z-Bar</a> all over the back seat.  He's still a little under the weather today, but seems to be on the mend.

Once I got him home and cleaned up, my first thought was, "I really wish I had sprung for the upholstery protection package when I bought my car."  Everything came right up though.  I was amazed.',
  'teaser' => 'Yesterday, Evan and I left Molly at home and went to <a href="http://www.sugarloafmd.com/" target="_blank" title="Sugarloaf Mountain, MD">Sugarloaf</a> to hike.  Evan followed good hiking practice by having a pre-hike nap in the car on the way.
[G2:4639]

Several of the <a href="http://www.sugarloafmd.com/images/maps/sugarloaf_map1.pdf" title="Trail Map" target="_blank">trails</a> still had snow on them and the trail up to the peak was pretty treacherous.
[G2:4644 class="g2image_float_left"][G2:4642]

',
  'log' => '',
  'revision_timestamp' => '1234118257',
  'format' => '1',
  'name' => 'Barrett',
  'picture' => '',
  'data' => 'a:2:{s:7:"contact";i:0;s:13:"form_build_id";s:37:"form-474d88df20e558c63cf8e3a74c34c6b6";}',
  'path' => NULL,
  'last_comment_timestamp' => '1234104158',
  'last_comment_name' => NULL,
  'comment_count' => '0',
  'taxonomy' => array(
    '1' => array(
      '3' => '3',
    ),
    'tags' => array(
      '2' => 'hiking, Sugarloaf',
    ),
  ),
  'files' => array(),
  'menu' => NULL,
  '#_export_node_encode_object' => '1',
)

#19

danielb - May 16, 2009 - 13:32

i'm going to do some testing with magic quotes off

#20

danielb - May 17, 2009 - 06:46

OK I can turn magic_quotes_runtime off but it doesn't seem the make a difference, the code is still imported fine.

I don't think there is anything wrong with the export code as it matches the syntax of other exports done in Drupal.

Have you encountered problems importing/exporting content types with apostrophe's in the type description? (using content_copy module that comes with cck) - is it double escaped there?

#21

Barrett - May 17, 2009 - 13:15

I thought your previous post said it was magic_quotes_gpc you have enabled.

I'm hopeful I'll be able too spend some time today testing out issues like the importing of content types you mentioned. I'll post back with results as soon as I get them. Thanks again for sticking with this.

#22

danielb - May 17, 2009 - 23:44

Yes but you cannot turn magic_quotes_gpc off :( If I try changing the htaccess file it breaks the whole site, and I don't have access to php.ini

#23

danielb - May 18, 2009 - 09:52

The situation with my hosting is giving my a lot of grief, I'm going to set up apache on my netbook and use it as a server for a while.

#24

Barrett - May 18, 2009 - 11:55

I've confirmed that turning on magic_quotes_gpc makes things work. I haven't found a fix to handle cases when it's off yet, but the search continues.

#25

danielb - May 18, 2009 - 12:33

Well the impression I get from the PHP manual is the correct thing to do is code with magic quotes off in the first place, and then apply a fix when magic_quotes_gpc() is on. D'oh.
I have setup drupal on my new apache server and turned magic quotes off, but I'm too tired to debug this right now.

#26

danielb - May 19, 2009 - 12:36

Just tested with magic quotes gpc and runtime off, works fine for me :/

#27

Barrett - May 20, 2009 - 18:06
Status:active» closed

You're kidding me, right? :^\

You know, I'm just looking to do a one-shot migration of my blog content from one site to another. If I'm the only one reporting a problem then it doesn't make sense to spend more time on it. I'll just turn off magic quotes, do the import, and turn them back off.

Thanks for all your time.

#28

danielb - May 20, 2009 - 23:38
Title:parse and syntax errors when importing in 6.11 using 6.x-2.6 for both import and export» Import: unexpected T_STRING, expecting ')'
Category:support request» bug report
Status:closed» active

I wouldn't mind keeping this open for a few weeks to see if anyone else replies.
Plus, I have to remove the attempted fix in 2.8 in the next release, so this will remind me.

#29

danielb - May 23, 2009 - 06:21

The attempted fix was removed.

#30

danielb - June 7, 2009 - 10:18
Status:active» won't fix
 
 

Drupal is a registered trademark of Dries Buytaert.