Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/14/2014 07:02:16 PM (11 years ago)
Author:
boonebgorges
Message:

Add delete_all support for all _delete_meta() functions

The delete_all parameter allows you to delete all meta items matching the
specified meta_key, regardless of the associated object.

Because our meta delete functions also support the deletion of all metadata
associated with an object (by leaving out the meta_key param), a decision had
to be made regarding the behavior when _delete_meta() is called with delete_all

true and meta_key = false. The most logical (and least destructive) strategy

was deemed to be: force delete_all to false when meta_key is also false. This
ensures that you don't accidentally wipe out all metadata for a component.

See #5400

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/testcases/activity/functions.php

    r7879 r7883  
    337337    /**
    338338     * @group activitymeta
     339     * @group bp_activity_delete_meta
     340     */
     341    public function test_bp_activity_delete_meta_with_delete_all_but_no_meta_key() {
     342        // With no meta key, don't delete for all items - just delete
     343        // all for a single item
     344        $a1 = $this->factory->activity->create();
     345        $a2 = $this->factory->activity->create();
     346        bp_activity_update_meta( $a1, 'foo', 'bar' );
     347        bp_activity_update_meta( $a1, 'foo1', 'bar1' );
     348        bp_activity_update_meta( $a2, 'foo', 'bar' );
     349        bp_activity_update_meta( $a2, 'foo1', 'bar1' );
     350
     351        $this->assertTrue( bp_activity_delete_meta( $a1, '', '', true ) );
     352        $this->assertEmpty( bp_activity_get_meta( $a1 ) );
     353        $this->assertSame( 'bar', bp_activity_get_meta( $a2, 'foo' ) );
     354        $this->assertSame( 'bar1', bp_activity_get_meta( $a2, 'foo1' ) );
     355    }
     356
     357    /**
     358     * @group activitymeta
     359     * @group bp_activity_delete_meta
     360     */
     361    public function test_bp_activity_delete_meta_with_delete_all() {
     362        // With no meta key, don't delete for all items - just delete
     363        // all for a single item
     364        $a1 = $this->factory->activity->create();
     365        $a2 = $this->factory->activity->create();
     366        bp_activity_update_meta( $a1, 'foo', 'bar' );
     367        bp_activity_update_meta( $a1, 'foo1', 'bar1' );
     368        bp_activity_update_meta( $a2, 'foo', 'bar' );
     369        bp_activity_update_meta( $a2, 'foo1', 'bar1' );
     370
     371        $this->assertTrue( bp_activity_delete_meta( $a1, 'foo', '', true ) );
     372        $this->assertEmpty( '', bp_activity_get_meta( $a1, 'foo' ) );
     373        $this->assertEmpty( '', bp_activity_get_meta( $a2, 'foo' ) );
     374        $this->assertSame( 'bar1', bp_activity_get_meta( $a1, 'foo1' ) );
     375        $this->assertSame( 'bar1', bp_activity_get_meta( $a2, 'foo1' ) );
     376    }
     377    /**
     378     * @group activitymeta
    339379     * @group bp_activity_add_meta
    340380     */
Note: See TracChangeset for help on using the changeset viewer.