Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/07/2013 02:06:51 AM (13 years ago)
Author:
boonebgorges
Message:

Improvements to how group total_member_count is refreshed on membership events

  • Use an actual member count when refreshing, rather than incrementing
  • Centralize all of the updating in the database methods, rather than having the updates spread throughout the groups component

Also adds integration tests for total_member_count as relates to the groups_*
functions.

See #5018

File:
1 edited

Legend:

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

    r7180 r7182  
    12261226                self::refresh_total_group_count_for_user( $this->user_id );
    12271227
     1228                // Update the group's member count
     1229                self::refresh_total_member_count_for_group( $this->group_id );
     1230
    12281231                do_action_ref_array( 'groups_member_after_save', array( &$this ) );
    12291232
     
    12561259
    12571260        function ban() {
    1258 
    12591261                if ( !empty( $this->is_admin ) )
    12601262                        return false;
     
    12631265                $this->is_banned = 1;
    12641266
    1265                 groups_update_groupmeta( $this->group_id, 'total_member_count', ( (int) groups_get_groupmeta( $this->group_id, 'total_member_count' ) - 1 ) );
    1266 
    12671267                return $this->save();
    12681268        }
    12691269
    12701270        function unban() {
    1271 
    12721271                if ( !empty( $this->is_admin ) )
    12731272                        return false;
    12741273
    12751274                $this->is_banned = 0;
    1276 
    1277                 groups_update_groupmeta( $this->group_id, 'total_member_count', ( (int) groups_get_groupmeta( $this->group_id, 'total_member_count' ) + 1 ) );
    12781275
    12791276                return $this->save();
     
    12991296                        return false;
    13001297
    1301                 groups_update_groupmeta( $this->group_id, 'total_member_count', ( (int) groups_get_groupmeta( $this->group_id, 'total_member_count' ) - 1 ) );
    1302 
    13031298                // Update the user's group count
    13041299                self::refresh_total_group_count_for_user( $this->user_id );
    13051300
     1301                // Update the group's member count
     1302                self::refresh_total_member_count_for_group( $this->group_id );
     1303
    13061304                return $result;
    13071305        }
     
    13091307        /** Static Methods ********************************************************/
    13101308
     1309        /**
     1310         * Refresh the total_group_count for a user
     1311         *
     1312         * @since BuddyPress (1.8)
     1313         * @param int $user_id
     1314         * @return bool True on success
     1315         */
    13111316        public static function refresh_total_group_count_for_user( $user_id ) {
    1312                 bp_update_user_meta( $user_id, 'total_group_count', (int) self::total_group_count( $user_id ) );
     1317                return bp_update_user_meta( $user_id, 'total_group_count', (int) self::total_group_count( $user_id ) );
     1318        }
     1319
     1320        /**
     1321         * Refresh the total_member_count for a group
     1322         *
     1323         * @since BuddyPress (1.8)
     1324         * @param int $group_id
     1325         * @return bool True on success
     1326         */
     1327        public static function refresh_total_member_count_for_group( $group_id ) {
     1328                return groups_update_groupmeta( $group_id, 'total_member_count', (int) BP_Groups_Group::get_total_member_count( $group_id ) );
    13131329        }
    13141330
     
    13201336                // Update the user's group count
    13211337                self::refresh_total_group_count_for_user( $user_id );
     1338
     1339                // Update the group's member count
     1340                self::refresh_total_member_count_for_group( $group_id );
    13221341
    13231342                return $remove;
Note: See TracChangeset for help on using the changeset viewer.