<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[BuddyPress] [2556] trunk: Fixes #1777</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd>2556</dd>
<dt>Author</dt> <dd>apeatling</dd>
<dt>Date</dt> <dd>2010-02-03 10:44:26 +0000 (Wed, 03 Feb 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Fixes #1777</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpgroupsbpgroupsclassesphp">trunk/bp-groups/bp-groups-classes.php</a></li>
<li><a href="#trunkbpgroupsbpgroupsnotificationsphp">trunk/bp-groups/bp-groups-notifications.php</a></li>
<li><a href="#trunkbpgroupsphp">trunk/bp-groups.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpgroupsbpgroupsclassesphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/bp-groups-classes.php (2555 => 2556)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/bp-groups-classes.php        2010-02-03 10:13:54 UTC (rev 2555)
+++ trunk/bp-groups/bp-groups-classes.php        2010-02-03 10:44:26 UTC (rev 2556)
</span><span class="lines">@@ -120,23 +120,19 @@
</span><span class="cx">         function delete() {
</span><span class="cx">                 global $wpdb, $bp;
</span><span class="cx">
</span><del>-                // Delete groupmeta for the group
</del><ins>+                /* Delete groupmeta for the group */
</ins><span class="cx">                 groups_delete_groupmeta( $this->id );
</span><span class="cx">
</span><del>-                // Modify group count usermeta for members
-                for ( $i = 0; $i < count($this->user_dataset); $i++ ) {
-                        $user = $this->user_dataset[$i];
</del><ins>+                /* Fetch the user IDs of all the members of the group */
+                $user_ids = BP_Groups_Member::get_group_member_ids( $this->id );
+                $user_ids = implode( ',', (array)$user_ids );
</ins><span class="cx">
</span><del>-                        $total_count = get_usermeta( $user->user_id, 'total_group_count' );
</del><ins>+                /* Modify group count usermeta for members */
+                $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} )" ) );
</ins><span class="cx">
</span><del>-                        if ( $total_count != '' ) {
-                                update_usermeta( $user->user_id, 'total_group_count', (int)$total_count - 1 );
-                        }
</del><ins>+                /* Now delete all group member entries */
+                BP_Groups_Member::delete_all( $this->id );
</ins><span class="cx">
</span><del>-                        // Now delete the group member record
-                        BP_Groups_Member::delete( $user->user_id, $this->id, false );
-                }
-
</del><span class="cx">                 do_action( 'bp_groups_delete_group', $this );
</span><span class="cx">
</span><span class="cx">                 // Finally remove the group entry from the DB
</span><span class="lines">@@ -723,6 +719,10 @@
</span><span class="cx">
</span><span class="cx">                 groups_update_groupmeta( $this->group_id, 'total_member_count', ( (int) groups_get_groupmeta( $this->group_id, 'total_member_count' ) - 1 ) );
</span><span class="cx">
</span><ins>+                $group_count = get_usermeta( $this->user_id, 'total_group_count' );
+                if ( !empty( $group_count ) )
+                        update_usermeta( $this->user_id, 'total_group_count', (int)$group_count - 1 );
+
</ins><span class="cx">                 return $this->save();
</span><span class="cx">         }
</span><span class="cx">
</span><span class="lines">@@ -733,6 +733,7 @@
</span><span class="cx">                 $this->is_banned = 0;
</span><span class="cx">
</span><span class="cx">                 groups_update_groupmeta( $this->group_id, 'total_member_count', ( (int) groups_get_groupmeta( $this->group_id, 'total_member_count' ) + 1 ) );
</span><ins>+                update_usermeta( $this->user_id, 'total_group_count', (int)get_usermeta( $this->user_id, 'total_group_count' ) + 1 );
</ins><span class="cx">
</span><span class="cx">                 return $this->save();
</span><span class="cx">         }
</span><span class="lines">@@ -937,6 +938,12 @@
</span><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx">
</span><ins>+        function get_group_member_ids( $group_id ) {
+                global $bp, $wpdb;
+
+                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 ) );
+        }
+
</ins><span class="cx">         function get_group_administrator_ids( $group_id ) {
</span><span class="cx">                 global $bp, $wpdb;
</span><span class="cx">
</span><span class="lines">@@ -997,6 +1004,12 @@
</span><span class="cx">                 return array( 'members' => $members, 'count' => $total_member_count );
</span><span class="cx">         }
</span><span class="cx">
</span><ins>+        function delete_all( $group_id ) {
+                global $wpdb, $bp;
+
+                return $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->groups->table_name_members} WHERE group_id = %d", $group_id ) );
+        }
+
</ins><span class="cx">         function delete_all_for_user( $user_id ) {
</span><span class="cx">                 global $wpdb, $bp;
</span><span class="cx">
</span></span></pre></div>
<a id="trunkbpgroupsbpgroupsnotificationsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups/bp-groups-notifications.php (2555 => 2556)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups/bp-groups-notifications.php        2010-02-03 10:13:54 UTC (rev 2555)
+++ trunk/bp-groups/bp-groups-notifications.php        2010-02-03 10:44:26 UTC (rev 2556)
</span><span class="lines">@@ -6,16 +6,17 @@
</span><span class="cx">         $group = new BP_Groups_Group( $group_id );
</span><span class="cx">         $subject = '[' . get_blog_option( BP_ROOT_BLOG, 'blogname' ) . '] ' . __( 'Group Details Updated', 'buddypress' );
</span><span class="cx">
</span><del>-        foreach ( $group->user_dataset as $user ) {
-                if ( 'no' == get_usermeta( $user->user_id, 'notification_groups_group_updated' ) ) continue;
</del><ins>+        $user_ids = BP_Groups_Member::get_group_member_ids( $this->id );
+        foreach ( $user_ids as $user_id ) {
+                if ( 'no' == get_usermeta( $user_id, 'notification_groups_group_updated' ) ) continue;
</ins><span class="cx">
</span><del>-                $ud = bp_core_get_core_userdata( $user->user_id );
</del><ins>+                $ud = bp_core_get_core_userdata( $user_id );
</ins><span class="cx">
</span><span class="cx">                 // Set up and send the message
</span><span class="cx">                 $to = $ud->user_email;
</span><span class="cx">
</span><span class="cx">                 $group_link = site_url( $bp->groups->slug . '/' . $group->slug );
</span><del>-                $settings_link = bp_core_get_user_domain( $user->user_id ) . 'settings/notifications/';
</del><ins>+                $settings_link = bp_core_get_user_domain( $user_id ) . 'settings/notifications/';
</ins><span class="cx">
</span><span class="cx">                 $message = sprintf( __(
</span><span class="cx"> 'Group details for the group "%s" were updated:
</span></span></pre></div>
<a id="trunkbpgroupsphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-groups.php (2555 => 2556)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-groups.php        2010-02-03 10:13:54 UTC (rev 2555)
+++ trunk/bp-groups.php        2010-02-03 10:44:26 UTC (rev 2556)
</span><span class="lines">@@ -2256,7 +2256,10 @@
</span><span class="cx">
</span><span class="cx">         do_action( 'groups_ban_member', $user_id, $group_id );
</span><span class="cx">
</span><del>-        return $member->ban();
</del><ins>+        if ( !$member->ban() )
+                return false;
+
+        update_usermeta( $user_id, 'total_group_count', (int)$total_count - 1 );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> function groups_unban_member( $user_id, $group_id ) {
</span></span></pre>
</div>
</div>
</body>
</html>