Skip to:
Content

BuddyPress.org

Changeset 7872


Ignore:
Timestamp:
02/14/2014 12:08:21 PM (8 years ago)
Author:
boonebgorges
Message:

Introduce bp_activity_add_meta()

See #5400

Location:
trunk
Files:
2 edited

Legend:

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

    r7854 r7872  
    668668        $retval = true;
    669669    }
     670
     671    return $retval;
     672}
     673
     674/**
     675 * Add a piece of activity metadata.
     676 *
     677 * @since BuddyPress (2.0.0)
     678 *
     679 * @param int $activity_id ID of the activity item.
     680 * @param string $meta_key Metadata key.
     681 * @param mixed $meta_value Metadata value.
     682 * @param bool $unique. Optional. Whether to enforce a single metadata value
     683 *        for the given key. If true, and the object already has a value for
     684 *        the key, no change will be made. Default: false.
     685 * @return int|bool The meta ID on successful update, false on failure.
     686 */
     687function bp_activity_add_meta( $activity_id, $meta_key, $meta_value, $unique = false ) {
     688    add_filter( 'query', 'bp_filter_metaid_column_name' );
     689    $retval = add_metadata( 'activity', $activity_id, $meta_key, $meta_value, $unique );
     690    remove_filter( 'query', 'bp_filter_metaid_column_name' );
    670691
    671692    return $retval;
  • trunk/tests/testcases/activity/functions.php

    r7853 r7872  
    313313
    314314    /**
     315     * @group activitymeta
     316     * @group bp_activity_add_meta
     317     */
     318    public function test_bp_activity_add_meta_no_meta_key() {
     319        $this->assertFalse( bp_activity_add_meta( 1, '', 'bar' ) );
     320    }
     321
     322    /**
     323     * @group activitymeta
     324     * @group bp_activity_add_meta
     325     */
     326    public function test_bp_activity_add_meta_empty_object_id() {
     327        $this->assertFalse( bp_activity_add_meta( 0, 'foo', 'bar' ) );
     328    }
     329
     330    /**
     331     * @group activitymeta
     332     * @group bp_activity_add_meta
     333     */
     334    public function test_bp_activity_add_meta_existing_unique() {
     335        $a = $this->factory->activity->create();
     336        bp_activity_add_meta( $a, 'foo', 'bar' );
     337        $this->assertFalse( bp_activity_add_meta( 0, 'foo', 'baz', true ) );
     338    }
     339
     340    /**
     341     * @group activitymeta
     342     * @group bp_activity_add_meta
     343     */
     344    public function test_bp_activity_add_meta_existing_not_unique() {
     345        $a = $this->factory->activity->create();
     346        bp_activity_add_meta( $a, 'foo', 'bar' );
     347        $this->assertNotEmpty( bp_activity_add_meta( $a, 'foo', 'baz' ) );
     348    }
     349
     350    /**
    315351     * @group bp_activity_get_user_mentionname
    316352     */
Note: See TracChangeset for help on using the changeset viewer.