Skip to:
Content

BuddyPress.org

Changeset 10002


Ignore:
Timestamp:
07/09/2015 12:28:55 AM (5 years ago)
Author:
boonebgorges
Message:

BP_XProfile_Group::save() should not return false when a save is successful but no rows are updated.

It ought to be semantically possible to save a fieldgroup without making any
changes to the group. Otherwise the return values of the save() method are
inconsistent, and the 'xprofile_group_after_save' hook is not fired reliably.

Props Offereins.
Fixes #6552.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-xprofile/classes/class-bp-xprofile-group.php

    r9974 r10002  
    141141        $query = $wpdb->query( $sql );
    142142
    143         // Bail if query fails
    144         if ( empty( $query ) || is_wp_error( $query ) ) {
     143        // Bail if query fails. If `$query` is 0, it means the save was successful, but no fields were updated.
     144        if ( false === $query || is_wp_error( $query ) ) {
    145145            return false;
    146146        }
  • trunk/tests/phpunit/testcases/xprofile/class-bp-xprofile-group.php

    r9819 r10002  
    66 */
    77class BP_Tests_BP_XProfile_Group extends BP_UnitTestCase {
     8
     9    /**
     10     * @ticket BP6552
     11     */
     12    public function test_save_should_not_return_false_when_no_fields_have_been_altered() {
     13        $g = $this->factory->xprofile_group->create();
     14        $group = new BP_XProfile_Group( $g );
     15
     16        $saved = $group->save();
     17
     18        $this->assertEquals( $g, $saved );
     19    }
     20
    821    /**
    922     * @group fetch_visibility_level
Note: See TracChangeset for help on using the changeset viewer.