The MU forums have moved to WordPress.org

Comment count incorrect after import (8 posts)

  1. rebootnow
    Member
    Posted 14 years ago #

    I have just exported a fairly large blog from a WP 2.7.1 install and imported the XML file into a brand new WPMU 2.7.1 install. I set the appropriate variables in php.ini to ensure that the large file could import.

    Everything looks roughly ok, except that while the comments do appear, the comment count is wrong (always "no responses"). I sniffed around in the db and found that the "comment_count" field for every post in "wp_posts" is set to zero instead of the correct number of posts.

    Is this a bug in the import feature, or is there a step I am missing?

    BTW, the other things that weren't quite right: The categories are visible in the admin dashboard, but not in the sidebar (may be a theme issue) and not all the posts came through (the 10 most recent posts of 827 did not make it).

  2. rebootnow
    Member
    Posted 14 years ago #

    I now see that the import is not actually completing.

    I have increased the timeouts I know about with the following in php.ini:
    upload_max_filesize = 50M
    post_max_size = 50M
    max_execution_time = 5000
    max_input_time = 5000

    But I still see a fatal error saying that a plugin exceeded the maximum execution time of 60s. Verbatim error text:

    Fatal error: Maximum execution time of 60 seconds exceeded in <site address>/wp-includes/plugin.php on line 302

    Is there another setting I need to change somewhere?

  3. andrea_r
    Moderator
    Posted 14 years ago #

    It was a bug it in the import. If the blog is that big, you'll have to use the database method to ensure you get everything.

    http://bavatuesdays.com/importing-a-single-wp-blog-to-a-wpmu-installation/

  4. rebootnow
    Member
    Posted 14 years ago #

    Thanks andrea_r. I finally got things working by breaking the XML file into smaller pieces.

    When I am feeling brave I will experiment with the database method. I do wonder whether the bavatuesdays post is still relevant with 2.7.1 though. For example, I don't see where it deals with the new comment_count field in wp_posts.

  5. andrea_r
    Moderator
    Posted 14 years ago #

    'I finally got things working by breaking the XML file into smaller pieces."

    That works too.

    "I do wonder whether the bavatuesdays post is still relevant with 2.7.1 though. For example, I don't see where it deals with the new comment_count field in wp_posts. "

    Process is still the same, as long as you're going from a single WP 2.7.1 to a WPMU 2.7.1, and rename whatever tables you find (except where noted), it should work.

  6. quarkin
    Member
    Posted 14 years ago #

    I wrote this code to fix my regular wordpress installations comment and category counts after importing. I create a file with this code, drop it in the blogs root directory and visit the page to fix the counts. Maybe it could be altered by someone to work with WPMU.

    <?php
    // Place this file in your blogs root directory and navigate to it.  Script will correct counts for comments and categories.
    include("wp-config.php");
    
    if (!mysql_connect(DB_HOST, DB_USER, DB_PASSWORD)) {  die('Could not connect: ' . mysql_error());  }
    if (!mysql_select_db(DB_NAME)) {  die('Could not connect: ' . mysql_error());  }
    
    $result = mysql_query("SELECT term_taxonomy_id FROM ".$table_prefix."term_taxonomy");
    while ($row = mysql_fetch_array($result)) {
      $term_taxonomy_id = $row['term_taxonomy_id'];
      echo "term_taxonomy_id: ".$term_taxonomy_id." count = ";
      $countresult = mysql_query("SELECT count(*) FROM ".$table_prefix."term_relationships WHERE term_taxonomy_id = '$term_taxonomy_id'");
      $countarray = mysql_fetch_array($countresult);
      $count = $countarray[0];
      echo $count."<br />";
      mysql_query("UPDATE ".$table_prefix."term_taxonomy SET count = '$count' WHERE term_taxonomy_id = '$term_taxonomy_id'");
    }
    
    $result = mysql_query("SELECT ID FROM ".$table_prefix."posts");
    while ($row = mysql_fetch_array($result)) {
      $post_id = $row['ID'];
      echo "post_id: ".$post_id." count = ";
      $countresult = mysql_query("SELECT count(*) FROM ".$table_prefix."comments WHERE comment_post_ID = '$post_id' AND comment_approved = 1");
      $countarray = mysql_fetch_array($countresult);
      $count = $countarray[0];
      echo $count."<br />";
      mysql_query("UPDATE ".$table_prefix."posts SET comment_count = '$count' WHERE ID = '$post_id'");
    }
    
    mysql_close();
    ?>
  7. jefflin
    Member
    Posted 14 years ago #

    Thanks quarkin, you just saved me a lot of time!

  8. teabag
    Member
    Posted 14 years ago #

    Quarkin - you are a star. I had the same problem and your script sorted it out!

About this Topic

  • Started 14 years ago by rebootnow
  • Latest reply from teabag