Skip to:
Content

BuddyPress.org

Opened 4 years ago

Closed 4 years ago

#6681 closed enhancement (fixed)

Delete all of a user's notifications after they're deleted

Reported by: henry.wright Owned by: boonebgorges
Milestone: 2.5 Priority: normal
Severity: normal Version: 2.3.3
Component: Toolbar & Notifications Keywords: has-patch has-unit-tests
Cc:

Description

Some notifications seem to remain in the database after a user is deleted. I don't see a reason to keep them? Even custom notifications added by plugins could get the chop:

function example_func( $user_id ) {
    $where = array(
        'user_id' => $user_id,
        'item_id' => false,
        'secondary_item_id' => false,
        'component_action' => false,
        'component_name' => false
    );
    BP_Notifications_Notification::delete( $where );
}
add_action( 'delete_user', 'example_func' );
// More hooks needed here to cover the various ways users can be deleted.

Attachments (4)

6681.diff (1.2 KB) - added by henry.wright 4 years ago.
6681.2.diff (1.2 KB) - added by henry.wright 4 years ago.
6681.3.diff (1.2 KB) - added by Mamaduka 4 years ago.
6681.3-tests.diff (2.3 KB) - added by Mamaduka 4 years ago.

Download all attachments as: .zip

Change History (13)

#1 @DJPaul
4 years ago

  • Keywords needs-patch good-first-bug added
  • Milestone changed from Awaiting Review to Future Release

Yes. The rest of BP, we normally hook to wpmu_delete_user and delete_user for this, and sometimes even bp_make_spam_user if it makes sense to tidy-up after a user has been spammed.

#2 @henry.wright
4 years ago

Probably wouldn't want to do this on spamming a user just in case that action needs to be undone.

@henry.wright
4 years ago

#3 @henry.wright
4 years ago

  • Keywords has-patch added; needs-patch removed

I've added a new function bp_core_delete_notifications_on_user_delete() to bp-members-functions.php. Not sure if that's the right place?

#4 follow-up: @boonebgorges
4 years ago

  • Keywords needs-unit-tests added; good-first-bug removed
  • Milestone changed from Future Release to 2.5

Thanks, henry.wright! The function looks good at a glance. It ought to live in bp-notifications, because currently, if notifications is disabled, the function will produce fatal errors. Unit tests would also be rad.

#5 in reply to: ↑ 4 @henry.wright
4 years ago

Replying to boonebgorges:

...It ought to live in bp-notifications, because currently, if notifications is disabled, the function will produce fatal errors...

Right, see what you mean, but I think we might have a problem?

If the notifications component is disabled, and a user is then deleted, we'd still want the relevant items in the notifications table removed (even though notifications are now disabled, they may have been enabled at an earlier date).

Do functions in bp-notifications fire if the notifications component is disabled?

Last edited 4 years ago by henry.wright (previous) (diff)

#6 @boonebgorges
4 years ago

Do functions in bp-notifications fire if the notifications component is disabled?

No. But I think we shouldn't worry about that. Components can't be expected to clean up after themselves if they've been turned off. Moving all of this logic inside of bp-core is going to create all sorts of bp_is_active() headaches that I'd like to avoid. In any case, it's not going to break anyone's site if this data is not cleared up. So let's keep it in bp-notifications.

#7 @henry.wright
4 years ago

Components can't be expected to clean up after themselves if they've been turned off.

That sounds reasonable to me!

2nd patch to follow...

@henry.wright
4 years ago

@Mamaduka
4 years ago

#8 @Mamaduka
4 years ago

  • Keywords has-unit-tests added; needs-unit-tests removed

Update original patch with correct PHPDoc version also added unit tests.

Sorry for direct queries BP_Notifications_Notification::get() checks agains registered components, while BP_Notifications_Notification::delete() doesn't care about that.

#9 @boonebgorges
4 years ago

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

In 10437:

Delete a user's notifications when the user is deleted.

Props henry.wright, Mamaduka.
Fixes #6681.

Note: See TracTickets for help on using tickets.