Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-04-20 18:58:49

sthmtc
Member
From: CGN, GER
Registered: 2005-01-17
Posts: 586
Website

how can i import some articles from one site into another?

i have an outdated version of a txp site that contains ~150 articles in a specific section that i’d like to import into the current install. of course without overwriting the articles that are already present… :)

in phpmyadmin, i selected the textpattern table, setup a search (“section = thenameofthesection”) and then exported all these articles. now, when i try to import this phpmyadmin says:

#1062 - Duplicate entry '2' for key 1

what would be the best way to do this? also, i have no idea how IDs are being handled if the import/export is done that way… i’m pretty much cueless when it comes to these things, so any help is greatly appreciated.

Last edited by sthmtc (2008-04-20 18:59:07)

Offline

#2 2008-04-22 21:15:42

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,306

Re: how can i import some articles from one site into another?

You just need to increase your existing article IDs by the old articles count’s value using the following sql command: UPDATE textpattern SET ID = ID + 150
Backup before! ;)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#3 2008-04-22 21:37:08

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,306

Re: how can i import some articles from one site into another?

Crap! Increase your existing article IDs by the highest article ID to import (In german: um den höchsten ID-Wert der zu importierenden Artikel. SO! ;)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#4 2008-04-22 22:29:28

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: how can i import some articles from one site into another?

You just need to increase your existing article IDs by the old articles count’s value using the following sql command: UPDATE textpattern SET ID = ID + 150

Isn’t the ID field auto_increment? I mean, it is. So, you can use it’s automatic increasing thing, by not using the ID in the insert. Then the primary value is filled without any conflicts ;)

Offline

#5 2008-04-22 22:40:13

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,306

Re: how can i import some articles from one site into another?

Sven, make a backup and test locally. I’ve tried the sql command on a very small site with just some articles, no comments etc. After posting these I saw there is a parent_id at least for comments. Think this has to be changed accordingly, if there are any.

Jukka, just for my poor brain’s sake, would you please shed a little light on this:

[…] by not using the ID in the insert.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#6 2008-04-22 23:15:25

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: how can i import some articles from one site into another?

uli sure I can. In example (out from my head so fields don’t match):

insert into `textpattern`
(`id`, `title`, `body`, `body_html`) values
(NULL,'title', 'body', 'body_html') [etc];

And then it just counts the id byitself as it is auto increasing value ;)

Last edited by Gocom (2008-04-22 23:17:00)

Offline

#7 2008-04-22 23:38:03

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,306

Re: how can i import some articles from one site into another?

Yup, Gocom, works! Nice! :)
Do you have a regexp for the IDs to replace with NULL? All the lines begin with INSERT INTO `textpattern` VALUES (<ID_HERE>,'

Last edited by uli (2008-04-22 23:42:14)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#8 2008-04-23 08:03:15

sthmtc
Member
From: CGN, GER
Registered: 2005-01-17
Posts: 586
Website

Re: how can i import some articles from one site into another?

thanks guys… i already solved this myself though :) i did it as gocom suggested… edited the sql

from:

INSERT INTO `textpattern` (`ID`, `Posted`, `AuthorID`, `LastMod`, ...

to

INSERT INTO `textpattern` (`Posted`, `AuthorID`, `LastMod`, ...

and deleted the ID values accordingly:

(281, '2007-08-18 12:25:15', 'admin', '2007-12-06 19:37:43', ...

to

('2007-08-18 12:25:15', 'admin', '2007-12-06 19:37:43', ...

that was it. oh and uli, why do you need a regexp for this? you can do that easily in any editor, no?

Offline

#9 2008-04-23 08:26:29

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,306

Re: how can i import some articles from one site into another?

SQL editor, yes, but I thought of a text editor for doing this. I’m not too familiar with phpMyAdmin and rather trust what I can see ;)

But one warning to future readers: relations between at least comments and articles will be lost for either method proposed here. So backup your data, test on a local installation, fasten all safety belts you can get!


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#10 2008-04-23 08:34:04

sthmtc
Member
From: CGN, GER
Registered: 2005-01-17
Posts: 586
Website

Re: how can i import some articles from one site into another?

uli wrote:

SQL editor, yes, but I thought of a text editor for doing this. I’m not too familiar with phpMyAdmin and rather trust what I can see ;)

i did it in a text editor, textmate to be precise. at least on os x you can press ALT and then select all the lines and edit them all at once. easy peasy :)

Last edited by sthmtc (2008-04-23 08:34:28)

Offline

Board footer

Powered by FluxBB