Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/24/2010 09:22:29 PM (14 years ago)
Author:
djpaul
Message:

Fixed #2676

File:
1 edited

Legend:

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

    r2919 r3300  
    6161        if ( $this->id ) {
    6262            // Update
    63             $result = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET initiator_user_id = %d, friend_user_id = %d, is_confirmed = %d, is_limited = %d, date_created = FROM_UNIXTIME(%d) ) WHERE id = %d", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created, $this->id ) );
     63            $result = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET initiator_user_id = %d, friend_user_id = %d, is_confirmed = %d, is_limited = %d, date_created = %s ) WHERE id = %d", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created, $this->id ) );
    6464        } else {
    6565            // Save
    66             $result = $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->friends->table_name} ( initiator_user_id, friend_user_id, is_confirmed, is_limited, date_created ) VALUES ( %d, %d, %d, %d, FROM_UNIXTIME(%d) )", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created ) );
     66            $result = $wpdb->query( $wpdb->prepare( "INSERT INTO {$bp->friends->table_name} ( initiator_user_id, friend_user_id, is_confirmed, is_limited, date_created ) VALUES ( %d, %d, %d, %d, %s )", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created ) );
    6767            $this->id = $wpdb->insert_id;
    6868        }
     
    127127        $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(id) FROM {$bp->friends->table_name} WHERE (initiator_user_id = %d OR friend_user_id = %d) AND is_confirmed = 1", $user_id, $user_id ) );
    128128
    129         if ( !$count )
     129        // Do not update meta if user has never had friends
     130        if ( !$count && !get_user_meta( $user_id, 'total_friend_count', true ) )
    130131            return 0;
    131132
    132         update_usermeta( $user_id, 'total_friend_count', $count );
    133         return $count;
     133        update_user_meta( $user_id, 'total_friend_count', (int)$count );
     134        return (int)$count;
    134135    }
    135136
     
    202203        global $wpdb, $bp;
    203204
    204         return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET is_confirmed = 1, date_created = FROM_UNIXTIME(%d) WHERE id = %d AND friend_user_id = %d", time(), $friendship_id, $bp->loggedin_user->id ) );
     205        return $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET is_confirmed = 1, date_created = %s WHERE id = %d AND friend_user_id = %d", bp_core_current_time(), $friendship_id, $bp->loggedin_user->id ) );
    205206    }
    206207
     
    315316        global $wpdb, $bp;
    316317
     318        // Get friends of $user_id
     319        $friend_ids = BP_Friends_Friendship::get_friend_user_ids( $user_id );
     320
     321        // Delete all friendships related to $user_id
    317322        $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->friends->table_name} WHERE friend_user_id = %d OR initiator_user_id = %d", $user_id, $user_id ) );
    318323
    319324        // Delete friend request notifications for members who have a notification from this user.
    320325        $wpdb->query( $wpdb->prepare( "DELETE FROM {$bp->core->table_name_notifications} WHERE component_name = 'friends' AND ( component_action = 'friendship_request' OR component_action = 'friendship_accepted' ) AND item_id = %d", $user_id ) );
     326
     327        // Loop through friend_ids and update their counts
     328        foreach ( (array)$friend_ids as $friend_id ) {
     329            BP_Friends_Friendship::total_friend_count( $friend_id );
     330        }
    321331    }
    322332}
Note: See TracChangeset for help on using the changeset viewer.