Creating and implementing post count policies for users and groups in phpBB

phpBB has lots of features and some are very obscure. I ran into one of these recently for a client. Apparently, it’s possible for users and groups to not have their posts count in their total post count.

Obviously this is not an issue for most boards, and it’s hard to figure out a use case for why you would want to do this. One case is to avoid unearned ranks. phpBB has an optional ranking system which is typically based on the number of posts. Making lots of replies that aren’t really substantive can do this and it’s an issue on some boards. Presumably these boards are not well moderated, as moderators are usually tasked to find and remove these posts.

Whether a post is counted in a user’s total post count or not depends on whether the post_postcount column in the phpbb_posts table is 0 or 1. If it’s 1, it gets counted. If it’s 0, it doesn’t get counted.

For example, you could have a general chat forum and posts in these forums might not want to be counted in a user’s total posts because they are considered trite. Then you could have other forums where the meat of the board’s content is, and posts in these forums could count.

Changing the post count policy

By default, all posts count in a user’s total post count, so if you don’t want posts to count for certain groups or users, you will have to change phpBB’s settings.

This is controlled by a permission. Typically you set this group forum permission. ACP > Forums > Forum based permissions > Group forum permissions.

Next you pick the group, then the forums for the group where the permission will be changed. Next you select the Advanced permissions link and then click on the Post tab. Then set the Increment post counter setting to either Yes or No as desired for the group and the forum. Do this for all the forums whose permission you want to change for the group and save your changes. If you want to change this permission for other groups, repeat.

Increment post counter permission

If you want to remove this permission for a particular user or users only, you can avoid groups by selecting ACP > Forums > Forum based permissions > User forum permissions. In general though I think you’d want to avoid doing this on a user-by-user basis, and do this only for groups.

Changing post counts for old posts

While this works for future posts, it doesn’t affect existing posts. How do you fix these old bogus post counts? As best I can tell there is no extension to help you out. So you have to get down and dirty with your database, using a tool like phpMyAdmin.

Before attempting anything like this, disable your board and back up your database, or at least backup the posts table. This can be done in the ACP on the Maintenance tab.

Generally you need a list of forum_ids and group_ids. A tool like phpMyAdmin makes it simple to look inside your database. Your web host control panel will usually have a tool that runs phpMyAdmin. Make sure you select the database for your board. Your board’s config.php file will provide the database name, if there is any ambiguity.

Database tools like phpMyAdmin are very powerful. It is possible to make large, irreversible changes to the database if you type commands incorrectly.

A forum_id is a number assigned to a forum in the database. You can see a list of forum_ids with this query, which can be executed on the SQL tab for your database in phpMyAdmin. (Change phpbb_ if your table prefix is different):

SELECT forum_id, forum_name FROM phpbb_forums;

Getting forum_id for forums in phpMyAdmin

Next, you need a similar query to get the group_ids for your groups:

SELECT group_id, group_name FROM phpbb_groups;

Getting group_id for groups in phpMyAdmin

With these group_id and forum_id values, you can then write a query to change the post_postcount value in the phpbb_posts table for a particular group and forum. Using the example above, if you wanted to change this flag to 0 (don’t count) for all members in the Registered users group (group_id = 2) to the forum “Your first forum” forum (forum_id = 2), the SQL would be:

UPDATE phpbb_posts p, phpbb_groups g, phpbb_forums f, phpbb_user_group ug
SET post_postcount = 0
WHERE p.forum_id = f.forum_id AND
p.poster_id = ug.user_id AND ug.group_id = 2 AND f.forum_id = 2

If you wanted to set post_postcount to 0 (zero) for all posts made in a forum, the SQL is somewhat simpler. In the case of forum_id = 2 the SQL would be:

UPDATE phpbb_posts p, phpbb_forums f
SET post_postcount = 0
WHERE p.forum_id = f.forum_id AND f.forum_id = 2

Recalculating the post counts

There is one last step: you need to recalculate these statistics:

ACP > General > Resynchronise post counts

Clean up

If you messed up, restore the table you backed up.

Also, if you disabled your board, reenable it.

Leave a Reply

Your email address will not be published.