#5018 closed defect (bug) (fixed)
Update user meta field 'total_group_count' when user joins group
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 1.8 | Priority: | normal |
Severity: | normal | Version: | 1.7 |
Component: | Groups | Keywords: | |
Cc: |
Description
In buddypress if user leaves group we update user meta 'total_group_count' field but it missed when user joins group.
And somehow my user count 'total_group_count' went in minus number. so, it is advisable to check
if ( groups_is_user_member( $user_id, $group_id ) )
before update count,
we have done it when user joins group.
Is it appropriate to prevent minus count ?? I have just advised.
Attachments (1)
Change History (7)
#2
@
12 years ago
ya, we have this function 'groups_total_groups_for_user' which count groups for user we can make use of it to update it. and I think while we decrease this count simple check for greater than zero would work...
bp_update_user_meta( $user_id, 'total_group_count', (int) groups_total_groups_for_user( $user_id ) + 1 );
and for leave group
if( (int) groups_total_groups_for_user( $user_id ) > 0 ) bp_update_user_meta( $user_id, 'total_group_count', (int) (int) groups_total_groups_for_user( $user_id ) - 1 );
if user's group count is already zero then we don't decrease it. It seems little funny but I think it could be happen by mistake, because we don't check for user membership in this function so, its necessary to avoid minus count.
I have not tested it though, but it seems working.
Very odd that we're not upgrading a user's total_group_count when they join. (We do when they accept an invitation or when the request is approved.) I guess it's never come up, because we don't really appear to use this value anywhere in BP, at least not where I can see.
So, yes, it appears that we should be doing so.
Also, everywhere where we change total_group_count, we do it by incrementing or decrementing the current count. This can cause problems like the one you describe. Instead, I think it makes more sense to actually tabulate the group count at that moment, by querying the group member table. It definitely takes more resources to do this, but joining/leaving groups is a pretty rare occurrence.
Moving to 1.8 for examination. If you have a patch for either of these two problems, please feel free to post it.