A painting of me

Import Moveable Type Export File into Textpattern

   18 December 2004, early afternoon

I’ve modified the Wordpress Moveable Type import script so that it will import posts, comments, and primary categories from a moveable type export file into a textpattern database. I think that under the GNU license my changes are OK.

To say it hasn’t been thoroughly tested would be an understatement. It worked on my computer at home. So please backup your database before using it, just incase it munges it up. You should be able to run the script multiple times, it doesn’t import duplicates.

To use the script, copy the file to your textpattern directory, rename it to mt-import.php, and browse to the file in your web browser. You’ll need to set a variable in the php file that says where the moveable type file with your exported posts is. Once the script has completed running, you need to run the _update.php script to clean up the category table. You may also need to clean up the authors who were imported, fixing passwords and email addresses as needed.

The script: import-mt.txt

Update: The script no longer applies textile rules to the titles.

Update: The script handles importing authors slightly better. If your Moveable Type author name, and the name you supplied to Textpattern match, you shouldn’t experience problems importing authors.

Update: The script handles importing authors slightly better. If your Moveable Type author name, and the name you supplied to Textpattern match, you shouldn’t experience problems importing authors. This won’t help people who’ve already used the script.

Update May 15th: I fixed a bug which would spit out a bogus error after a new author was inserted into the database.

*Update May 16th:* This script will fail spectacularly if you specify a table prefix when setting up textpattern.

Update May 16th: If applying textile to your old MT posts is just going to munge them up, then replace line 200, $body_html = $textile->textileThis($post_content); with $body_html = $post_content;

Update June 1st: The script no longer reports a mysql error when inserting categories (they were being inserted properly, but the check to see they were inserted was wrong.) The script now works with table prefixes.

Update Dec 18th: The script no longer requires you run _update.php after you have imported your entries. It will rebuild the category tree when it is done importing by itself now. I’ve also tested importing to a RC1 install.

Update Aug 29th 2005: This script is no longer needed; Textpattern can import Moveable Type installs from within the application.

|  

Comments

  1. and now we can ALL “import posts, comments, and primary categories from a moveable type export file into a textpattern database.”
    yay the excitement! :P

  2. I’m not a stranger to sarcasm.

  3. Do you know how to merge authors? I imported MT posts and now I have two authors named “Ry Rivard,” but one shows up only as “7” and I have two of another author, and all the other non-duplicated authors have number’s instead of names in the archive pages.

  4. Merging Authors will require some SQL, but here is how I think you can go about fixing the problem:

    First, open up the txp_users table. You will need eventually need to delete all the duplicate authors from this table. Before doing that however, note which users correspond to the same author. You should have one user you created in txp, and one user that was created by the import script. Note the RealName fields of both matching authors. The RealName field it the author id in the textpattern table.

    Next, open up the textpattern table. You will need to run the following SQL query for each author you want to merge. You should have a list of the RealName entries you want to use, those that were created and assigned by textpattern, and the corresponding RealName entries that the moveable type import script made.

    update textpattern
    set AuthorId = [the txp assigned RealName]
    where AuthorId = [the MT script RealName]

    Once you have done this, all the articles you have imported will point to the correct author.

    You then can erase the bad authors from the txp_users table. You must run the following SQL query

    delete from txp_users
    where user_id= [the MT script user id]

    That should clean things up. Hope it helps. If you don’t think the above describes your problem, send me more information.

  5. Hey, Ramanan. I’m going to refer people to this article, so this thing better work! ;) BTW, I take it you will make necessary changes to make it work with the impending release of 1.19?

  6. Hopefully there won’t be too many changes to make, but yeah, I intend to keep the script up to date. And this script “works”. Heh.

  7. Worked fine—thanks!

    One problem through: the script created a bunch of authors, and I don’t know how to assign passwords to them.

    The default password doesn’t allow me to log in as any of those authors, and when I change it to something else in the database I get the same result.

  8. You can actually just erase all the authors if you don’t want them. The old articles should still be there, and be editable by your master account. If you can’t log in as one of the authors, make sure you are using field name as the login name.

  9. I want to migrate the authors rather than delete them.

    The “name” and “RealName” fields contain the same values, so I’m sure I didn’t try the wrong login names.

    What’s funny, too, is that the password listed in the database for my “Publisher” account isn’t the password I use to log into TextPattern; it’s the password I use to log into my hosting account.

  10. Wait—it’s weirder. The publisher account password in the database isn’t anything I’ve seen anywhere. Yet I can log in with the publisher password I actually chose.

  11. Thanks for the script it worked like a charm. However when I run _update.php I’m receiving this error:

    Fatal error: Call to undefined function: safe_delete()

    Any idea what I’m doing wrong?

  12. Not a clue. That script is written by Dean. If you are using a newer version of Textpattern perhaps you don’t need to run it anymore?

  13. Ramanan – great script. However, I’ve come across one tiny flaw (although I may be the one at fault, I’m not sure).

    Somewhere along the line there’s an assumption that all the comments and posting times are either in UTC or at the server’s local timezone.

    So whenever I then import these to my new Txp blog (which is at +13 to the TextDrive servers on UTC) they’ll have the the times listed in the rendered pages at 13 hours ahead of when they were actually posted.

    Is there some SQL that might fix this (it’s outside my very limited SQL knowledge)?

  14. I’m not sure off the top of my head, but if you post to the thread at the Text Patter forum I’m sure you’ll get a response. I suspect you can probably just add 13 hours to the time, but I’ll need to experiment first. Also, I’ll update the script if it is indeed importing things incorrectly.

  15. Thanks – I posted there, then eventually figured it out myself. Details here.

  16. I wonder if it is actually a Textpattern bug. I was under the impression Textpattern would add the time offset to any dates before displaying the date. I had to do this myself for my friendly time plugin.

Don't be shy, you can comment too!

 
Some things to keep in mind: You can style comments using Textile. In particular, *text* will get turned into text and _text_ will get turned into text. You can post a link using the command "linktext":link, so something like "google":http://www.google.com will get turned in to google. I may erase off-topic comments, or edit poorly formatted comments; I do this very rarely.