Moved my site onto a different publishing system

My blog has been running on an open source CMS (content management system) called Textpattern since 2004. Whilst I believe that this is an excellent CMS, it has to be said that development of the core by the open source community has been very limited for the last few years. I wish I had the time to help out, but I don’t. I therefore decided to move over to one of the most popular blogging systems, WordPress – also open source. This has a huge number of users, followers and contributors. I do not think that it is as technically elegant as Textpattern or, to some extent, as flexible (it is certainly first and foremost a blogging system rather than a true CMS but can be made to work much like one). Integration with other systems (social networking sites, etc) is better catered for though thanks to it popularity. Templating is not as clean but it is much easier to switch between templates than in Textpattern and many many more are available.

There is an import script provided in the WordPress package for Textpattern (amongst several other cms/blog sources) but it does not work that well. Fortunately, Alexandru Brie, a Romanian programmer and IT consultant, came to the rescue with revised guidance and an updated script.

3 thoughts on “Moved my site onto a different publishing system

  1. A friend knocked up a simple php script for me to fix the comments problem. I have provided a copy of the script below in case it is of use to anyone else (to be used at own risk – no support here I am afraid).

    As the ids used in textpattern and wordpress are completely different, this script does the following:

    For each comment in the textpattern comments table,
    a) finds corresponding parent post and notes the text
    b) searches the wordpress comments database for the matching comment AND
    c) seachres the wordpress comments database for the matching post AND
    d) links the wordpress comment and post together properly

    It updates the comment count as well.

    Where there is no matching parent post for a comment in the textpattern table or the matching comment or post is missing from wordpress, it spits out the details so that these can be checked manually.

    It assumes the following tables are used by textpattern and wordpress and they are all in the same database:

    textpattern (holds the original posts)
    txp_discuss (holds the original comments)
    wp_posts (the imported posts)
    wp_comments (the imported comments)

    if you have used different table names / prefixes, you will need to change each reference to these.

    Hope it helps you. It worked for me.


    < ?php class db { var $username; var $password; var $host; var $database; var $db_handle; var $sql; var $results; var $rows; } $discuss = new db; $findrec = new db; $discuss->username = "username";
    $discuss->password = "password";
    $discuss->host = "localhost";
    $discuss->database = "database";

    $debug=false;
    //
    // can be ip address or hostname
    //
    $discuss->db_handle = mysql_connect($discuss->host, $discuss->username, $discuss->password);
    if (!$discuss->db_handle) {
    die('Could not connect: '.mysql_error());
    }

    //
    echo 'Connected successfully\n';

    // connect to the database
    $db_found = mysql_select_db($discuss->database, $discuss->db_handle);
    if (!$db_found) {
    print "Database NOT Found ";
    mysql_close($discuss->db_handle);
    }

    //
    // loop around discuss records and find corresponding k_comments record
    // get the parent and use the post to find in new post
    //update new forum : ids and counts
    //
    $discuss->sql = "SELECT * FROM txp_discuss";
    $discuss->result = mysql_query($discuss->sql);
    while ($old_comment = mysql_fetch_assoc($discuss->result)) {
    if ($debug) echo "\nProcessing discussid: ".$old_comment['discussid'];
    $old_comment_parentid = $old_comment['parentid'];
    $old_comment_id = $old_comment['discussid'];
    $findrec->sql = "SELECT comment_ID,discussid,parentid FROM wp_comments,txp_discuss where "."message = comment_content and message ='".$old_comment['message']."'";

    // get corresponding K_comment for D_comment
    $findrec->result = mysql_query($findrec->sql);
    if (mysql_num_rows($findrec->result) == 0) {
    echo "\ntxp_discuss: comment not found in new forum : ".$old_comment['discussid'];
    echo "\n old comment" . $old_comment['message'];
    echo "\n parent " . $old_comment['parentid'];
    continue;
    }
    $comment_row = mysql_fetch_array($findrec->result, MYSQL_ASSOC);
    $new_comment_id = $comment_row['comment_ID'];

    //
    // get validate parent of old forum and get post text
    $findrec->sql = "select ID,Title,comments_count from textpattern where ID = ".$old_comment_parentid;
    $findrec->result = mysql_query($findrec->sql);
    if (mysql_num_rows($findrec->result) == 0) {
    echo "\ntxp_discuss: no parent [$old_comment_parentid] found for : [$old_comment_id] ";
    continue;
    }
    $find = mysql_fetch_array($findrec->result, MYSQL_ASSOC);
    $old_title = $find["Title"];
    $old_comment_count = $find["comments_count"];

    // Now find post text in new foum
    $findrec->sql = "select ID,post_title from wp_posts where post_title = ".'"'.$old_title.'"';
    $findrec->result = mysql_query($findrec->sql);
    if (mysql_num_rows($findrec->result) == 0) {

    echo "\nwp_posts: no post relating to old version [$old_title] ";
    continue;
    }
    $find = mysql_fetch_array($findrec->result, MYSQL_ASSOC);
    $new_parentid = $find['ID'];
    //
    /// Update comment count
    $findrec->sql = "update wp_posts set comment_count = $old_comment_count where ID = $new_parentid";
    if ($debug )echo "\n".$findrec->sql;
    $findrec->result = mysql_query($findrec->sql);
    // link comments to post
    $findrec->sql = "update wp_comments set comment_post_ID = $new_parentid where comment_ID = $new_comment_id";
    if ($debug ) echo "\n".$findrec->sql;
    $findrec->result = mysql_query($findrec->sql);

    }
    mysql_close($discuss->db_handle);
    ?>

Leave a Reply