Plugin

Developer
Supported

EE 1
EE 2
External Entries

Back to this add-on's main page
View Other Add-ons From Adam Khan

     

You must be logged in to post.

Syntax error?

Support Request

JCDerrick
JCDerrick

Hi, I was just testing this out in EE 2.3.1 and am getting this error when trying to run a simple test.

Error
The following tag has a syntax error:
{exp:external_entries:insert}
Please correct the syntax in your template.

{exp:external_entries:insert table="exp_channel_titles" debug="n"}
{insert
:title}Testing a Simple Place{/insert:title}
{insert
:url_title}testing_a_simple_place{/insert:url_title}
{
/exp:external_entries:insert}

{exp
:external_entries:insert table="exp_channel_data" debug="n"}
{insert
:field_id_199}No{/insert:field_id_199}
{insert
:field_ft_199}none{/insert:field_ft_199}
{insert
:field_id_200}Hypothetically speakingthis is where my description would gomaybe with "quote" in some places and perhaps a <a href="http://www.hawaii-guide.com">link</ain othersDoes it actually work?{/insert:field_id_200}
{insert
:field_ft_200}none{/insert:field_ft_200}
{
/exp:external_entries:insert} 
JCDerrick
# 1
JCDerrick

Wait, I think I have it figured out. Sorry about that.

Adam Khan
# 2
Developer
Adam Khan

Ah, okay, good.

I was going to ask what you get when you switch debugging to yes. Now I won’t bother.

JCDerrick
# 3
JCDerrick

Hi Adam, it does seem I running into one other strange issue. This line below doesn’t seem to insert anything into the db. The first line was working great, but this one doesn’t work… even when it’s by itself in the template. Any thoughts?

{exp:external_entries:insert table="exp_channel_data" debug="n"}
{insert
:site_id}1{/insert:site_id}
{insert
:channel_id}26{/insert:channel_id}
{insert
:field_id_199}No{/insert:field_id_199}
{insert
:field_ft_199}none{/insert:field_ft_199}
{insert
:field_id_200}Hypothetically speakingthis is where my description would gomaybe with "quote" in some places and perhaps a <a href="http://www.hawaii-guide.com">link</ain othersDoes it actually work?{/insert:field_id_200}
{insert
:field_ft_200}none{/insert:field_ft_200}
{
/exp:external_entries:insert} 
Adam Khan
# 4
Developer
Adam Khan

So I’ll ask: What do you get with the debug option set to yes?

JCDerrick
# 5
JCDerrick

Duh on my part, sorry. Here’s what I see… but nothing is added in the db. I just checked via phpmyadmin.

External Entries (Insert) Debug is on. Errors:

  No errors!

External Entries (Insert) SQL: INSERT INTO exp_channel_data SET site_id = “1”, channel_id = “26”, field_id_199 = “No”, field_ft_199 = “none”, field_id_200 = “Hypothetically speaking, this is where my description would go, maybe with “quote” in some places and perhaps a link in others. Does it actually work?”, field_ft_200 = “none”

JCDerrick
# 6
JCDerrick

Could the “quote” marks in the field_id cause any problems? And if so, how could I strip those out?

Eventually my plan is to move a bunch of entry data in one channel into another (with similar fields, but different field names) - I’m consolidating my channels to where they use ONE set of shared custom fields, versus having a set of unique custom fields for every channel (stupid set up on my part two years ago, I have like 150 custom fields, but when I consolidate I’ll have only 21). At this point, I think your Add-On is the only way I can do this easily. I have tried Data Grab as well, but with little luck bc of errors.

Adam Khan
# 7
Developer
Adam Khan

JCDerrick, that’s what I was thinking, the quotes being a problem. I imagine I must have tested for that way back when but can’t remember. Did you try without the quotes? Taking a look into it myself now on my test site.

Also, can you try with EE output debugging switched on and see if that reveals the error?

Adam Khan
# 8
Developer
Adam Khan

There are two issues here it turns out. Yes, the quotes won’t work, and also, I forgot that the entry_id field in exp_channel_titles is an autoincrement but it’s not in exp_channel_data, so exp_channel_data’s entry_id field is getting entered as 0. To get around this problem requires using an embedded template (or a variables addon like Stash) because the second (or rather, third) call of the plugin can’t read the PHP variable due to the parsing order.

So, the first template (set PHP Output) has the following:

{exp:external_entries:insert 
 table
="exp_channel_titles" 
 
debug="y"
}
{insert
:site_id}1{/insert:site_id}
{insert
:author_id}1{/insert:channel_id}
{insert
:channel_id}1{/insert:channel_id}
{insert
:title}Testing a Simple Place{/insert:title}
{insert
:url_title}testing_a_simple_place{/insert:url_title}
{
/exp:external_entries:insert}

{exp
:external_entries:select 
 table
="exp_channel_titles" 
 
debug="n" 
 
limit="1" 
 
orderby="entry_id" sort="desc"
 
allow_php="yes"
}
<?php $entry_id 
"{select:entry_id}"?>
{
/exp:external_entries:select}

{embed
="site/.index-inner"
 
entry_id="<?php echo $entry_id; ?>"

This is to grab the entry_id and pass it to the inner tempate:

<p>Entry ID{embed:entry_id}</p>

{exp:external_entries:insert 
 table
="exp_channel_data" 
 
debug="y"
 
allow_php="yes"
}
{insert
:entry_id}{embed:entry_id}{/insert:entry_id}
{insert
:site_id}1{/insert:site_id}
{insert
:channel_id}4{/insert:channel_id}
{insert
:field_id_18}Hypothetically speakingthis is where my description would gomaybe with "quote" in some places and perhaps a <a href="http://www.hawaii-guide.com">link</ain othersDoes it actually work?{/insert:field_id_18}
{
/exp:external_entries:insert} 

To fix the quotes problem, try inserting the following at line 241 of the plugin;

$insert str_replace('"''\"'$insert); 

Or

$insert addslashes($insert); 

A bit nasty but it’ll do the trick without removing the links etc. Then you can do a search-and-replace if need be for \”. There must be a better way to do it but I haven’t figured that out yet. Tried heredoc but it didn’t work.

Adam Khan
# 9
Developer
Adam Khan

Also, to do this, these aren’t enough fields in the exp_channel_titles table. When I did a similar type of import into channel entries, here are all the fields that were necessary:

site_id, channel_id, author_id, ip_address, title, url_title, status, entry_date, year, month, day, edit_date

JCDerrick
# 10
JCDerrick

Excellent, so far, so good.

Is there any “easy” way you can think of to start moving the data from one channel to another? Am I better off doing one entry at a time (there are 600 of them) or can I somehow automated the process?

Thanks for your help in getting this working, so far the quotes haven’t been an issue with the first fix. We’ll see how things go as I move images and other data from field to field in my backend. I think the hardest field to move is going to be anything that in a Matrix field (any suggestions on that?) I also have a MX Google Map field, but maybe I can figure that out somehow.

Adam Khan
# 11
Developer
Adam Khan

When there’s been lots of moving around to do I’‘ve done it by putting a series of direct SQL operations in PHP in a template and run them by loading that page. You’d need to work out the series of manipulations, obviously, and test each step with a limit=1, things like that.

Once biting the bullet and going at the the DB directly things get a little less daunting.

Also, I would have thought to move them to a different channel you’d just need to change their channel_id.