Fix Comment Count
Last modified: October 6, 2006 - 01:15
PLEASE NOTE These snippets are user submitted. Use at your own risk. For users who have setup Drupal using an alternate database to the default (MYSQL), please note that the snippets may contain some database queries specific to MYSQL.
Here is the situation:
You have used a script to import some nodes and their comments, but the 'x comments' link under each node has not been updated.
Just copy this snippet to a new page (with the php input format selected), visit that page, and you are done.
Note: this will hammer the server if you have a lot of nodes. Consider LIMITing the SQL SELECT statement to do it in stages if this is the case.
<?php
echo 'Fixing comment count for: ';
$query = db_rewrite_sql('SELECT n.nid, n.body FROM {node} n WHERE nid > 1');
$result = db_query($query);
while ($node = db_fetch_array($result)) {
_comment_update_node_statistics($node['nid']);
echo $node['nid']."\n";
}
?>