Gossamer Forum
Home : Products : Gossamer Forum : Discussion :

Recalc user posts?

Quote Reply
Recalc user posts?
I know, I know, "...will this guy ever stop posting questions!"

What's the best way to recalculate the number of posts each user has made?
Quote Reply
Re: [HeavyBombers] Recalc user posts? In reply to
hmmm been thinking something similar for a while now. BUT slightly different.

Is there anyway to merge users?
ie ... a user signs up changes their email to another one ... (any type of personal reason), they forget their password and their password to that email account, so they sign up under a new name.
or - somebody just signs up as 2,3 people to have fun and later decides to keep only 1.

Angelic

openoffice + gimp + sketch ... Smile
Quote Reply
Re: [HeavyBombers] Recalc user posts? In reply to
You can use the script below, change the paths according to your setup. Users with guest status will have zero posts (consistent with how GForum handles guest posts)

Code:
#!/path/to/perl

use strict;
use lib '/path/to/gforum/admin';
use GForum qw/$DB/;

GForum::init('/path/to/gforum/admin');

my $user_t = $DB->table ('User');
my $post_t = $DB->table ('Post');

my $sth = $user_t->select;

while (my $user = $sth->fetchrow_hashref) {
my $post_num = $post_t->count( { user_id_fk => $user->{user_id} } );
if ($user->{user_status} == 0) {
$user_t->update ( { user_posts => 0 } , { user_id => $user->{user_id} });
}
else {
$user_t->update ( { user_posts => $post_num } , { user_id => $user->{user_id} });
}
}

If you don't trust the script, or you want to be sure that the right thing goes on, place a print command instead of the updates, then you can see what is happening.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [QooQ] Recalc user posts? In reply to
Ah ha! Some of my users must have signed up on your site Smile

But seriously, that's a good one. Perhaps we can push both Merge Post and Merge User toward the top of the 1.1.5 bandwagon.

I can see how merge user would be much trickier than merge post though, lots of stuff going on there.

It would also help if there was a check process to prevent users signing up on the same e-mail account (they totally forgot they'd signed up or whatever and go after a new username).

Last edited by:

HeavyBombers: May 3, 2002, 4:59 AM
Quote Reply
Re: [yogi] Recalc user posts? In reply to
I know nothing about Perl, when you say print command do you mean?

Code:
$user_t->update becomes $user_t->print


When I posted this I was thinking along the lines of a SQL query, but will give this a whirl. Thanks,
Quote Reply
Re: [HeavyBombers] Recalc user posts? In reply to
No, I mean something like
Code:
print $user->{user_username} . ": " $post_num;
This replaces the $user_t->update lines.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [HeavyBombers] Recalc user posts? In reply to
hehe ... actually thinking of myself but was too embarassed to say that Blush

being able to change names is cool but when folks figure out it's smart to reserve your name by signing up twice ... you might just want to be able to gather your history for accounting history. While others will prefer to let history pass and leave it alone.

openoffice + gimp + sketch ... Smile