Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-09-28 07:28:22

Sander
New Member
Registered: 2009-09-28
Posts: 2

Improving the Wordpress import

Allright, so this is a complete rewrite of what I posted this morning. I have been working with the Wordpress import tool and I found it had some flaws which made it impossible for me to import my old blog into Wordpress.

UTF8 and latin
Since my blog’s database is in latin1, and the textpattern database is in UTF-8, I had to do some conversion. So I wrote this little function, and I wrapped it around some of the fields in the insert-queries:


function sanderSpecialReplace($string) {
    return utf8_encode ($string);
}

It is a simple wrap like this, because it used to be more complicated. I added it to the Body and Body_html fields for posts and name and message for comments, like this:


Body = '".doSlash(sanderSpecialReplace($Body))."',

You should put it around ALL fields which could be affected here. I just added it to the fields that needed it in my specific case.

Empty Excepts
Since I never use these, the import didn’t work. The standard ‘textpattern’ table does not accept empty excerpts (or at least, it doesnt on my installation. For some reason, I had to do some database changes to make the import work. If I do not, I get errors like “Field Excerpt does not have a default value”.


ALTER TABLE `textpattern` CHANGE `Excerpt` `Excerpt` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL ,
CHANGE `Excerpt_html` `Excerpt_html` MEDIUMTEXT CHARACTER SET utf8 COLLATE utf8_general_ci NULL 

Capabilities
Wordpress 2.4.8 uses the field “wp_capabilities” instead of “capabilities”. That’s a simple change.

I hope you guys can use this :). The software I used:
- PHP 5.3.0, Apache 2.2.13, mysql 5.1.38-community, windows Vista, textpattern 4.2.0 and wordpress 2.4.8

Last edited by Sander (2009-09-28 10:52:32)

Offline

#2 2009-09-28 13:25:18

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,447
Website GitHub

Re: Improving the Wordpress import

Thanks for the insight on the importer.

I guess the Excerpt needs setting explicitly in the Insert query to get round the empty excerpt error. The capabilities thing shouldn’t be tricky to get round provided we can get at the WP version used. Will have to think about the UTF-8 thing. I don’t know anything about WP so I don’t know if this is something that should be applied to all imports or a user option.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2009-09-28 13:40:20

Sander
New Member
Registered: 2009-09-28
Posts: 2

Re: Improving the Wordpress import

Anytime.

Setting the Excerpt explicitly works indeed.

You can get at the version of the database by checking out the field db_version in table wp_options. A list is here: Link

I could find some stuff about Wordpress databases.

Link
Link
Link

Last edited by Sander (2009-09-28 13:41:15)

Offline

Board footer

Powered by FluxBB