Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/14/2014 07:02:16 PM (10 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/blogs/functions.php

    r7879 r7883  
    6363    /**
    6464     * @group blogmeta
     65     * @group bp_blogs_delete_blogmeta
     66     */
     67    public function test_bp_blogs_delete_blogmeta_with_delete_all_but_no_meta_key() {
     68        // With no meta key, don't delete for all items - just delete
     69        // all for a single item
     70        bp_blogs_add_blogmeta( 1, 'foo', 'bar' );
     71        bp_blogs_add_blogmeta( 1, 'foo1', 'bar1' );
     72        bp_blogs_add_blogmeta( 2, 'foo', 'bar' );
     73        bp_blogs_add_blogmeta( 2, 'foo1', 'bar1' );
     74
     75        $this->assertTrue( bp_blogs_delete_blogmeta( 1, '', '', true ) );
     76        $this->assertEmpty( bp_blogs_get_blogmeta( 1 ) );
     77        $this->assertSame( 'bar', bp_blogs_get_blogmeta( 2, 'foo' ) );
     78        $this->assertSame( 'bar1', bp_blogs_get_blogmeta( 2, 'foo1' ) );
     79    }
     80
     81    /**
     82     * @group blogmeta
     83     * @group bp_blogs_delete_blogmeta
     84     */
     85    public function test_bp_blogs_delete_blogmeta_with_delete_all() {
     86        // With no meta key, don't delete for all items - just delete
     87        // all for a single item
     88        bp_blogs_add_blogmeta( 1, 'foo', 'bar' );
     89        bp_blogs_add_blogmeta( 1, 'foo1', 'bar1' );
     90        bp_blogs_add_blogmeta( 2, 'foo', 'bar' );
     91        bp_blogs_add_blogmeta( 2, 'foo1', 'bar1' );
     92
     93        $this->assertTrue( bp_blogs_delete_blogmeta( 1, 'foo', '', true ) );
     94        $this->assertEmpty( '', bp_blogs_get_blogmeta( 1, 'foo' ) );
     95        $this->assertEmpty( '', bp_blogs_get_blogmeta( 2, 'foo' ) );
     96        $this->assertSame( 'bar1', bp_blogs_get_blogmeta( 1, 'foo1' ) );
     97        $this->assertSame( 'bar1', bp_blogs_get_blogmeta( 2, 'foo1' ) );
     98    }
     99
     100    /**
     101     * @group blogmeta
    65102     * @group bp_blogs_get_blogmeta
    66103     */
Note: See TracChangeset for help on using the changeset viewer.