<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Moved my site onto a different publishing system</title>
	<atom:link href="http://kyber.co.uk/blog/textpattern-to-wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://kyber.co.uk/blog/textpattern-to-wordpress/</link>
	<description>if you are not confused, you are misinformed</description>
	<lastBuildDate>Wed, 18 Jan 2012 10:15:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: kyber</title>
		<link>http://kyber.co.uk/blog/textpattern-to-wordpress/comment-page-1/#comment-57</link>
		<dc:creator>kyber</dc:creator>
		<pubDate>Mon, 08 Jun 2009 11:04:34 +0000</pubDate>
		<guid isPermaLink="false">http://kyber.co.uk/?p=1#comment-57</guid>
		<description>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.

&lt;code&gt;
&lt; ?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-&gt;username = &quot;username&quot;;
$discuss-&gt;password = &quot;password&quot;;
$discuss-&gt;host     = &quot;localhost&quot;;
$discuss-&gt;database = &quot;database&quot;;

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

//
echo &#039;Connected successfully\n&#039;;

// connect to the database
$db_found = mysql_select_db($discuss-&gt;database, $discuss-&gt;db_handle);
if (!$db_found) {
  print &quot;Database NOT Found &quot;;
  mysql_close($discuss-&gt;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-&gt;sql = &quot;SELECT * FROM txp_discuss&quot;;
$discuss-&gt;result = mysql_query($discuss-&gt;sql);
while ($old_comment = mysql_fetch_assoc($discuss-&gt;result)) {
  if ($debug) echo &quot;\nProcessing discussid: &quot;.$old_comment[&#039;discussid&#039;];
  $old_comment_parentid = $old_comment[&#039;parentid&#039;];
  $old_comment_id       = $old_comment[&#039;discussid&#039;];
  $findrec-&gt;sql         = &quot;SELECT comment_ID,discussid,parentid FROM wp_comments,txp_discuss where &quot;.&quot;message = comment_content and message =&#039;&quot;.$old_comment[&#039;message&#039;].&quot;&#039;&quot;;

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

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

  // Now find post text in new foum
  $findrec-&gt;sql = &quot;select ID,post_title from wp_posts where post_title = &quot;.&#039;&quot;&#039;.$old_title.&#039;&quot;&#039;;
  $findrec-&gt;result = mysql_query($findrec-&gt;sql);
  if (mysql_num_rows($findrec-&gt;result) == 0) {

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


}
mysql_close($discuss-&gt;db_handle);
?&gt;
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>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 &#8211; no support here I am afraid).</p>
<p>As the ids used in textpattern and wordpress are completely different, this script does the following:</p>
<p>For each comment in the textpattern comments table,<br />
a) finds corresponding parent post and notes the text<br />
b) searches the wordpress comments database for the matching comment AND<br />
c) seachres the wordpress comments database for the matching post AND<br />
d) links the wordpress comment and post together properly</p>
<p>It updates the comment count as well.</p>
<p>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.</p>
<p>It assumes the following tables are used by textpattern and wordpress and they are all in the same database:</p>
<p>textpattern (holds the original posts)<br />
txp_discuss (holds the original comments)<br />
wp_posts (the imported posts)<br />
wp_comments (the imported comments)</p>
<p>if you have used different table names / prefixes, you will need to change each reference to these.</p>
<p>Hope it helps you. It worked for me.</p>
<p><code><br />
< ?php<br />
class db<br />
{<br />
  var $username;<br />
  var $password;<br />
  var $host;<br />
  var $database;<br />
  var $db_handle;<br />
  var $sql;<br />
  var $results;<br />
  var $rows;<br />
}<br />
$discuss           = new db;<br />
$findrec           = new db;<br />
$discuss->username = "username";<br />
$discuss->password = "password";<br />
$discuss->host     = "localhost";<br />
$discuss->database = "database";</p>
<p>$debug=false;<br />
//<br />
// can be ip address or hostname<br />
//<br />
$discuss->db_handle = mysql_connect($discuss->host, $discuss->username, $discuss->password);<br />
if (!$discuss->db_handle) {<br />
  die('Could not connect: '.mysql_error());<br />
}</p>
<p>//<br />
echo 'Connected successfully\n';</p>
<p>// connect to the database<br />
$db_found = mysql_select_db($discuss->database, $discuss->db_handle);<br />
if (!$db_found) {<br />
  print "Database NOT Found ";<br />
  mysql_close($discuss->db_handle);<br />
}</p>
<p>//<br />
// loop around discuss records and find corresponding k_comments record<br />
// get the parent and use the post to find in new post<br />
//update new forum : ids and counts<br />
//<br />
$discuss->sql = "SELECT * FROM txp_discuss";<br />
$discuss->result = mysql_query($discuss->sql);<br />
while ($old_comment = mysql_fetch_assoc($discuss->result)) {<br />
  if ($debug) echo "\nProcessing discussid: ".$old_comment['discussid'];<br />
  $old_comment_parentid = $old_comment['parentid'];<br />
  $old_comment_id       = $old_comment['discussid'];<br />
  $findrec->sql         = "SELECT comment_ID,discussid,parentid FROM wp_comments,txp_discuss where "."message = comment_content and message ='".$old_comment['message']."'";</p>
<p>  // get corresponding K_comment for D_comment<br />
  $findrec->result = mysql_query($findrec->sql);<br />
  if (mysql_num_rows($findrec->result) == 0) {<br />
    echo "\ntxp_discuss:  comment not found in new forum : ".$old_comment['discussid'];<br />
    echo "\n    old comment" . $old_comment['message'];<br />
    echo "\n    parent " . $old_comment['parentid'];<br />
    continue;<br />
  }<br />
  $comment_row = mysql_fetch_array($findrec->result, MYSQL_ASSOC);<br />
  $new_comment_id = $comment_row['comment_ID'];</p>
<p>  //<br />
  // get  validate parent of old forum and get post text<br />
  $findrec->sql = "select ID,Title,comments_count from textpattern where ID = ".$old_comment_parentid;<br />
  $findrec->result = mysql_query($findrec->sql);<br />
  if (mysql_num_rows($findrec->result) == 0) {<br />
    echo "\ntxp_discuss: no parent [$old_comment_parentid] found for : [$old_comment_id] ";<br />
    continue;<br />
  }<br />
  $find              = mysql_fetch_array($findrec->result, MYSQL_ASSOC);<br />
  $old_title         = $find["Title"];<br />
  $old_comment_count = $find["comments_count"];</p>
<p>  // Now find post text in new foum<br />
  $findrec->sql = "select ID,post_title from wp_posts where post_title = ".'"'.$old_title.'"';<br />
  $findrec->result = mysql_query($findrec->sql);<br />
  if (mysql_num_rows($findrec->result) == 0) {</p>
<p>    echo "\nwp_posts: no post relating to old version [$old_title]  ";<br />
    continue;<br />
  }<br />
  $find         = mysql_fetch_array($findrec->result, MYSQL_ASSOC);<br />
  $new_parentid = $find['ID'];<br />
  //<br />
  /// Update comment count<br />
  $findrec->sql = "update  wp_posts set comment_count = $old_comment_count where ID  = $new_parentid";<br />
  if ($debug )echo "\n".$findrec->sql;<br />
  $findrec->result = mysql_query($findrec->sql);<br />
  // link comments to post<br />
  $findrec->sql = "update  wp_comments set comment_post_ID = $new_parentid where comment_ID  = $new_comment_id";<br />
  if ($debug ) echo "\n".$findrec->sql;<br />
  $findrec->result = mysql_query($findrec->sql);</p>
<p>}<br />
mysql_close($discuss->db_handle);<br />
?><br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kyber</title>
		<link>http://kyber.co.uk/blog/textpattern-to-wordpress/comment-page-1/#comment-55</link>
		<dc:creator>kyber</dc:creator>
		<pubDate>Fri, 05 Jun 2009 11:20:49 +0000</pubDate>
		<guid isPermaLink="false">http://kyber.co.uk/?p=1#comment-55</guid>
		<description>I know how to fix it, just need to find the time to write the script (or find someone to write it for me)</description>
		<content:encoded><![CDATA[<p>I know how to fix it, just need to find the time to write the script (or find someone to write it for me)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kyber</title>
		<link>http://kyber.co.uk/blog/textpattern-to-wordpress/comment-page-1/#comment-56</link>
		<dc:creator>kyber</dc:creator>
		<pubDate>Sun, 31 May 2009 21:07:06 +0000</pubDate>
		<guid isPermaLink="false">http://kyber.co.uk/?p=1#comment-56</guid>
		<description>Just realised that the comments entered on the old system have not been linked in correctly on the new system. Oops.</description>
		<content:encoded><![CDATA[<p>Just realised that the comments entered on the old system have not been linked in correctly on the new system. Oops.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

