Is there any way to recalcule the Post Counts?

I've imported my posts using phpbb2drupal, but the Post Counts are way too low to be real. So I'd like to recalculate them.

Comments

maartenvg’s picture

I came across the same problem, so I created an MySQL query that can recalculate the post count of all users in 1 go. It uses multiple subqueries so I'm not sure which version of MySQL is required (I'm running 5.0.22).

function flatforum_recalculate_posts() {
  db_query('TRUNCATE TABLE {flatforum}');
  db_query('INSERT INTO {flatforum} (uid,posts) (SELECT idc, count_comments + count_nodes FROM (SELECT u.uid as idc, count(c.cid) as count_comments from {users} as u right join {comments} as c on c.uid=u.uid GROUP BY u.uid) as t1, (SELECT u.uid as idn, count(n.nid) as count_nodes from {users} as u right join {node} as n on n.uid=u.uid GROUP BY u.uid) as t2 WHERE  t1.idc = t2.idn)');
}

if you call this functions from a hook_enable() hook in the flatforum.install, you can just disable and re-enable the module to get everything recounted. This then also works when doing a fresh install. You could also make it into a menu-call or a button on a administration page.
The problem lies in the fact that flatforum only registers the topics that phpbb2drupal imports, but not the topic-replies.

michelle’s picture

Status: Active » Closed (fixed)

Just tidying up.

Michelle