Skip to:
Content

BuddyPress.org

Changeset 8132


Ignore:
Timestamp:
03/14/2014 12:50:26 AM (11 years ago)
Author:
boonebgorges
Message:

In update_meta() functions, return integer value if a new metadata is created

Previously, BP update_meta() functions returned true on a successful update
*or* on the successful creation of new metadata. This is not consistent with
WP's update_metadata(), which on the creation of new metadata acts as a wrapper
for add_metadata(), which in turn returns an integer (the ID of the newly
created database row).

This changeset aligns BP's behavior with WP's.

We don't have any tests that directly address the data type returned by these
functions, but we do have a number of assertTrue assertions to verify the
setup of various tests. Where appropriate, these have been changed to the more
generous assertNotEmpty.

See #5399

Location:
trunk
Files:
8 edited

Legend:

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

    r8131 r8132  
    662662 *        metadata entries with the specified value. Otherwise, update all
    663663 *        entries.
    664  * @return bool True on success, false on failure.
     664 * @return bool|int Returns false on failure. On successful update of existing
     665 *         metadata, returns true. On successful creation of new metadata,
     666 *         returns the integer ID of the new metadata row.
    665667 */
    666668function bp_activity_update_meta( $activity_id, $meta_key, $meta_value, $prev_value = '' ) {
     
    674676    $retval = update_metadata( 'activity', $activity_id, $meta_key, $meta_value, $prev_value );
    675677    remove_filter( 'query', 'bp_filter_metaid_column_name' );
    676 
    677     // Legacy - return true if we fall through to add_metadata()
    678     if ( is_int( $retval ) ) {
    679         $retval = true;
    680     }
    681678
    682679    return $retval;
  • trunk/bp-blogs/bp-blogs-functions.php

    r8130 r8132  
    921921 *        metadata entries with the specified value. Otherwise, update all
    922922 *        entries.
    923  * @return bool True on success, false on failure.
     923 * @return bool|int Returns false on failure. On successful update of existing
     924 *         metadata, returns true. On successful creation of new metadata,
     925 *         returns the integer ID of the new metadata row.
    924926 */
    925927function bp_blogs_update_blogmeta( $blog_id, $meta_key, $meta_value, $prev_value = '' ) {
     
    928930    $retval = update_metadata( 'blog', $blog_id, $meta_key, $meta_value, $prev_value );
    929931    remove_filter( 'query', 'bp_filter_metaid_column_name' );
    930 
    931     // Legacy - New items fall through to add_metadata(). Return true
    932     // instead of the ID returned from that function.
    933     if ( is_int( $retval ) ) {
    934         $retval = true;
    935     }
    936932
    937933    return $retval;
  • trunk/bp-groups/bp-groups-functions.php

    r8129 r8132  
    10961096 *        metadata entries with the specified value. Otherwise, update all
    10971097 *        entries.
    1098  * @return bool True on success, false on failure.
     1098 * @return bool|int Returns false on failure. On successful update of existing
     1099 *         metadata, returns true. On successful creation of new metadata,
     1100 *         returns the integer ID of the new metadata row.
    10991101 */
    11001102function groups_update_groupmeta( $group_id, $meta_key, $meta_value, $prev_value = '' ) {
     
    11031105    $retval = update_metadata( 'group', $group_id, $meta_key, $meta_value, $prev_value );
    11041106    remove_filter( 'query', 'bp_filter_metaid_column_name' );
    1105 
    1106     // Legacy - return true if we fall through to add_metadata()
    1107     if ( is_int( $retval ) ) {
    1108         $retval = true;
    1109     }
    11101107
    11111108    return $retval;
  • trunk/bp-xprofile/bp-xprofile-functions.php

    r8130 r8132  
    665665 *        metadata entries with the specified value. Otherwise, update all
    666666 *        entries.
    667  * @return bool True on success, false on failure.
     667 * @return bool|int Returns false on failure. On successful update of existing
     668 *         metadata, returns true. On successful creation of new metadata,
     669 *         returns the integer ID of the new metadata row.
    668670 */
    669671function bp_xprofile_update_meta( $object_id, $object_type, $meta_key, $meta_value, $prev_value = '' ) {
     
    674676    remove_filter( 'query', 'bp_xprofile_filter_meta_query' );
    675677    remove_filter( 'query', 'bp_filter_metaid_column_name' );
    676 
    677     // Legacy - if we fall through to add_metadata(), return true rather
    678     // than the integer meta_id
    679     if ( is_int( $retval ) ) {
    680         $retval = (bool) $retval;
    681     }
    682678
    683679    return $retval;
  • trunk/tests/testcases/activity/functions.php

    r8131 r8132  
    165165        $a = $this->factory->activity->create();
    166166        $this->assertSame( '', bp_activity_get_meta( $a, 'foo' ), '"foo" meta should be empty for this activity item.' );
    167         $this->assertTrue( bp_activity_update_meta( $a, 'foo', 'bar' ) );
     167        $this->assertNotEmpty( bp_activity_update_meta( $a, 'foo', 'bar' ) );
    168168        $this->assertSame( 'bar', bp_activity_get_meta( $a, 'foo' ) );
    169169    }
  • trunk/tests/testcases/blogs/functions.php

    r8131 r8132  
    1919     */
    2020    public function test_bp_blogs_delete_blogmeta_illegal_characters() {
    21         $this->assertTrue( bp_blogs_update_blogmeta( 1, 'foo', 'bar' ) );
     21        $this->assertNotEmpty( bp_blogs_update_blogmeta( 1, 'foo', 'bar' ) );
    2222        $this->assertSame( 'bar', bp_blogs_get_blogmeta( 1, 'foo' ) );
    2323        $krazy_key = ' f!@#$%^o *(){}o?+';
     
    3232     */
    3333    public function test_bp_blogs_delete_blogmeta_trim_meta_value() {
    34         $this->assertTrue( bp_blogs_update_blogmeta( 1, 'foo', 'bar' ) );
     34        $this->assertNotEmpty( bp_blogs_update_blogmeta( 1, 'foo', 'bar' ) );
    3535        $this->assertSame( 'bar', bp_blogs_get_blogmeta( 1, 'foo' ) );
    3636        bp_blogs_delete_blogmeta( 1, 'foo', '   bar  ' );
     
    193193     */
    194194    public function test_bp_blogs_update_blogmeta_new() {
    195         $this->assertTrue( bp_blogs_update_blogmeta( 1, 'foo', 'bar' ) );
     195        $this->assertNotEmpty( bp_blogs_update_blogmeta( 1, 'foo', 'bar' ) );
    196196        $this->assertSame( 'bar', bp_blogs_get_blogmeta( 1, 'foo' ) );
    197197    }
  • trunk/tests/testcases/groups/functions.php

    r8131 r8132  
    309309        $g = $this->factory->group->create();
    310310        $this->assertSame( '', groups_get_groupmeta( $g, 'foo' ), '"foo" meta should be empty for this group.' );
    311         $this->assertTrue( groups_update_groupmeta( $g, 'foo', 'bar' ) );
     311        $this->assertNotEmpty( groups_update_groupmeta( $g, 'foo', 'bar' ) );
    312312        $this->assertSame( 'bar', groups_get_groupmeta( $g, 'foo' ) );
    313313    }
     
    468468    public function test_groups_delete_groupmeta_with_illegal_key_characters() {
    469469        $g = $this->factory->group->create();
    470         $this->assertTrue( groups_update_groupmeta( $g, 'foo', 'bar' ), 'Value of "foo" should be set at this point.' );
     470        $this->assertNotEmpty( groups_update_groupmeta( $g, 'foo', 'bar' ), 'Value of "foo" should be set at this point.' );
    471471
    472472        $krazy_key = ' f!@#$%^o *(){}o?+';
  • trunk/tests/testcases/xprofile/functions.php

    r8131 r8132  
    418418        $g = $this->factory->xprofile_group->create();
    419419        $this->assertSame( '', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
    420         $this->assertTrue( bp_xprofile_update_meta( $g, 'group', 'foo', 'bar' ) );
     420        $this->assertNotEmpty( bp_xprofile_update_meta( $g, 'group', 'foo', 'bar' ) );
    421421        $this->assertSame( 'bar', bp_xprofile_get_meta( $g, 'group', 'foo' ) );
    422422    }
Note: See TracChangeset for help on using the changeset viewer.