Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/03/2010 10:44:26 AM (15 years ago)
Author:
apeatling
Message:

Fixes #1777

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-groups/bp-groups-classes.php

    r2550 r2556  
    121121        global $wpdb, $bp;
    122122
    123         // Delete groupmeta for the group
     123        /* Delete groupmeta for the group */
    124124        groups_delete_groupmeta( $this->id );
    125125
    126         // Modify group count usermeta for members
    127         for ( $i = 0; $i < count($this->user_dataset); $i++ ) {
    128             $user = $this->user_dataset[$i];
    129 
    130             $total_count = get_usermeta( $user->user_id, 'total_group_count' );
    131 
    132             if ( $total_count != '' ) {
    133                 update_usermeta( $user->user_id, 'total_group_count', (int)$total_count - 1 );
    134             }
    135 
    136             // Now delete the group member record
    137             BP_Groups_Member::delete( $user->user_id, $this->id, false );
    138         }
     126        /* Fetch the user IDs of all the members of the group */
     127        $user_ids = BP_Groups_Member::get_group_member_ids( $this->id );
     128        $user_ids = implode( ',', (array)$user_ids );
     129
     130        /* Modify group count usermeta for members */
     131        $wpdb->query( $wpdb->prepare( "UPDATE {$bp->groups->table_name_groupmeta} SET meta_value = meta_value - 1 WHERE meta_key = 'total_group_count' AND user_id IN ( {$user_ids} )" ) );
     132
     133        /* Now delete all group member entries */
     134        BP_Groups_Member::delete_all( $this->id );
    139135
    140136        do_action( 'bp_groups_delete_group', $this );
     
    724720        groups_update_groupmeta( $this->group_id, 'total_member_count', ( (int) groups_get_groupmeta( $this->group_id, 'total_member_count' ) - 1 ) );
    725721
     722        $group_count = get_usermeta( $this->user_id, 'total_group_count' );
     723        if ( !empty( $group_count ) )
     724            update_usermeta( $this->user_id, 'total_group_count', (int)$group_count - 1 );
     725
    726726        return $this->save();
    727727    }
     
    734734
    735735        groups_update_groupmeta( $this->group_id, 'total_member_count', ( (int) groups_get_groupmeta( $this->group_id, 'total_member_count' ) + 1 ) );
     736        update_usermeta( $this->user_id, 'total_group_count', (int)get_usermeta( $this->user_id, 'total_group_count' ) + 1 );
    736737
    737738        return $this->save();
     
    936937            return $wpdb->get_col( $wpdb->prepare( "SELECT DISTINCT m.group_id FROM {$bp->groups->table_name_members} m, {$bp->groups->table_name} g WHERE m.group_id = g.id AND g.status != 'hidden' AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0 ORDER BY rand() LIMIT $total_groups", $user_id ) );
    937938        }
     939    }
     940
     941    function get_group_member_ids( $group_id ) {
     942        global $bp, $wpdb;
     943
     944        return $wpdb->get_col( $wpdb->prepare( "SELECT user_id FROM {$bp->groups->table_name_members} WHERE group_id = %d AND is_confirmed = 1 AND is_banned = 0", $group_id ) );
    938945    }
    939946
     
    9961003
    9971004        return array( 'members' => $members, 'count' => $total_member_count );
     1005    }
     1006
     1007    function delete_all( $group_id ) {
     1008        global $wpdb, $bp;
     1009
     1010        return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE group_id = %d", $group_id ) );
    9981011    }
    9991012
Note: See TracChangeset for help on using the changeset viewer.