Skip to:
Content

BuddyPress.org

Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#7394 closed defect (bug) (fixed)

BP_Activity_Activity::__construct() sets id even if not valid

Reported by: jdgrimes's profile jdgrimes Owned by: boonebgorges's profile boonebgorges
Milestone: 2.8 Priority: normal
Severity: normal Version:
Component: Activity Keywords: has-patch
Cc:

Description

In many of BuddyPress's objects that are constructed with an ID, the id attribute is only set to a non-zero value if the passed ID actually belongs to an existing record in the database. However, in BP_Activity_Activity::__construct(), the id is set, and in populate() it is not set to 0 if the ID is invalid. In other objects, populate() will set the ID to 0 if it can't find the record in the database.

So for most objects, you can check if an item exists with a certain ID like this:

<?php
$object = new BP_Groups_Group( $id );

if ( ! $object->id ) {
    // doesn't exist.
}

However, for BP_Activity_Activity, this doesn't work, and there is apparently no other method available specifically for checking if an activity item with a given ID actually exists.

Attachments (1)

7394.diff (2.8 KB) - added by jdgrimes 8 years ago.
Set id to 0 in populate() if row not found

Download all attachments as: .zip

Change History (4)

@jdgrimes
8 years ago

Set id to 0 in populate() if row not found

#1 @jdgrimes
8 years ago

  • Keywords has-patch added

In 7394.diff I've just modified populate() to set id to 0 if the row isn't found in the database, the same behavior as seen in other objects.

#2 @boonebgorges
8 years ago

  • Owner set to boonebgorges
  • Resolution set to fixed
  • Status changed from new to closed

In 11312:

Activity: After populate(), activity items with a bad ID should have id = 0.

Props jdgrimes.
Fixes #7394.

#3 @boonebgorges
8 years ago

  • Milestone changed from Awaiting Review to 2.8

Yes. See #4185 [7134] for the same change in BP_Groups_Group.

Note: See TracTickets for help on using tickets.