Skip to:
Content

BuddyPress.org

Changeset 8175


Ignore:
Timestamp:
03/27/2014 06:20:37 PM (5 years ago)
Author:
boonebgorges
Message:

Don't allow a user to favorite a single activity item more than once.

Fixes #5478

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-functions.php

    r8135 r8175  
    407407        $user_id = bp_loggedin_user_id();
    408408
    409     // Update the user's personal favorites
    410     $my_favs   = bp_get_user_meta( $user_id, 'bp_favorite_activities', true );
     409    $my_favs = bp_get_user_meta( $user_id, 'bp_favorite_activities', true );
     410    if ( empty( $my_favs ) || ! is_array( $my_favs ) ) {
     411        $my_favs = array();
     412    }
     413
     414    // Bail if the user has already favorited this activity item
     415    if ( in_array( $activity_id, $my_favs ) ) {
     416        return false;
     417    }
     418
     419    // Add to user's favorites
    411420    $my_favs[] = $activity_id;
    412421
  • trunk/tests/testcases/activity/functions.php

    r8133 r8175  
    696696    }
    697697
     698    /**
     699     * @group favorites
     700     * @group bp_activity_add_user_favorite
     701     */
     702    public function test_add_user_favorite_already_favorited() {
     703        $u = $this->create_user();
     704        $a = $this->factory->activity->create();
     705
     706        bp_activity_add_user_favorite( $a, $u );
     707
     708        $this->assertFalse( bp_activity_add_user_favorite( $a, $u ) );
     709        $this->assertSame( array( $a ), bp_activity_get_user_favorites( $u ) );
     710        $this->assertEquals( 1, bp_activity_get_meta( $a, 'favorite_count' ) );
     711    }
     712
    698713    public function check_activity_caches() {
    699714        foreach ( $this->acaches as $k => $v ) {
Note: See TracChangeset for help on using the changeset viewer.