Opened 11 years ago
Closed 11 years ago
#5333 closed defect (bug) (fixed)
new_blog_post activity items not deleted when blog post is deleted
Reported by: | henry.wright | Owned by: | |
---|---|---|---|
Milestone: | 2.0 | Priority: | normal |
Severity: | normal | Version: | 1.9.1 |
Component: | Activity | Keywords: | needs-patch |
Cc: |
Description
When site tracking is enabled, new blog posts generate an activity entry along the lines of "Member X wrote blog post Hello World".
If the blog post author deletes the blog post, the activity entry remains in the stream - resulting in a broken link to the blog post.
Attachments (3)
Change History (24)
#2
follow-up:
↓ 3
@
11 years ago
- Milestone changed from Awaiting Review to 2.0
add_action( 'delete_post', 'bp_blogs_remove_post' ); fires for 'deleted' posts. Just doesn't seem to be a hook that fires for 'trashed' posts.
Ah, if that's true, then it should definitely be fixed. We should think about hooking to 'transition_post_type' instead.
#3
in reply to:
↑ 2
@
11 years ago
Replying to boonebgorges:
We should think about hooking to 'transition_post_type' instead.
agreed - although I'm not familiar with that hook?
My initial thought was to do this:
add_action( 'trashed_post', 'bp_blogs_remove_post' );
But then I thought, wait, what if a post author decides to untrash a post?
So, perhaps a better solution would be to avoid using the bp_blogs_remove_post
function when a post is trashed and instead modify the activity item so that it is hidden from the stream.
This can be done easily for the sitewide stream by passing the activity item's ID to bp_activity_add()
and setting hide_sitewide => true
. Not sure if there is a similar param available which could be used to hide from the user's activity stream?
This general approach could also work for when a post is unpublished and republished etc.
#4
@
11 years ago
Hide
function hide_activity_item( $postid ) { $args = array( 'user_id' => bp_loggedin_user_id(), 'type' => 'new_blog_post', 'secondary_item_id' => $postid ); $activity_id = bp_activity_get_activity_id( $args ); bp_activity_add( array( 'id' => $activity_id, 'hide_sitewide' => true ) ); } add_action( 'trashed_post', 'hide_activity_item' );
And show
function show_activity_item( $postid ) { $args = array( 'user_id' => bp_loggedin_user_id(), 'type' => 'new_blog_post', 'secondary_item_id' => $postid ); $activity_id = bp_activity_get_activity_id( $args ); bp_activity_add( array( 'id' => $activity_id, 'hide_sitewide' => false ) ); } add_action( 'untrashed_post', 'show_activity_item' );
Notes:
- I haven't tested this but I'm hoping it illustrates my thoughts.
- This would only work for the site-wide stream. Is there a
hide_user_stream
param?
#5
follow-up:
↓ 6
@
11 years ago
This would only work for the site-wide stream. Is there a hide_user_stream param?
No. hide_sitewide
is used for hiding duplicates as well as for privacy purposes. See #3857. It's for this reason that your suggestion, while clever, won't work.
#6
in reply to:
↑ 5
@
11 years ago
Replying to boonebgorges:
No.
hide_sitewide
is used for hiding duplicates as well as for privacy purposes. See #3857. It's for this reason that your suggestion, while clever, won't work.
I had an idea you were going to say that. Back to the drawing board I go :)
#7
@
11 years ago
Considering #3857 seems as though it will be a big task that won't be in place for some time, what are your thoughts on deleting the activity item on trashed_post
and adding a new one on untrashed_post
? All I can think of is mischievous users might decide this is a good way to 'bump' their post to the top of the activity stream due to a new recorded_time
being introduced each time a new activity entry is added.
#9
@
11 years ago
boonebgorges - looks like you are already on to this with bp_blogs_catch_published_post
. My vote is let that function house the logic and hook to it where appropriate (as you mentioned in the beginning).
Something like?
if ( 'trash' === $new_status ) { // delete activity item return; }
Update: On second thoughts please see my patch below which I think is a simpler approach.
#10
@
11 years ago
Please find the attached patch.
I've hooked bp_blogs_remove_post
to trashed_post
so that activity items are deleted from the activity stream when a post is trashed.
bp_blogs_catch_published_post
will detect if a user decides to untrash the post and will handle the creation of a new activity entry.
#12
@
11 years ago
So now my thoughts are turning to "Member X commented on blog post Hello World".
When a blog post is deleted, activity entries such as this are deleted from the activity stream. However, on trashing a post, they're not deleted. So we have the same problem as discussed above.
I'm not sure deleting this sort of activity entry on trashing a post and creating a new activity entry on 'untrash' is a good idea because if a blog post has many comments from a single commenter - that commenter's activity stream is suddenly going to be flooded with many new activity items at the moment the blog post is untrashed.
"Member X commented on blog post Hello World"
"Member X commented on blog post Hello World"
"Member X commented on blog post Hello World"
etc.
This leads me to think a way of hiding and showing activity entries is needed. There's currently no param available for this. Would it be worth introducing one? Or perhaps there is a better way of doing it that I'm missing?
UPDATE:
Completely ignore this particular post.
I was thinking the recorded date of the activity item is the date the activity item is created. Of course this isn't the case. The recorded time is the date the comment was made.
'recorded_time' => $recorded_comment->comment_date_gmt
Hence, the problem I've outlined in this particular post is invalid :)
#13
@
11 years ago
Patch incoming. Spent a few hours looking at this.
- The attached patch works, but probably nicer to integrate into a
bp_blogs_catch_published_post()
-type wrapper per Boone's comments. - Also correct that someone could trash and untrash, and as Activity doesn't have an equivalent "trashed" status, so we either have to leave the activity items behind pointing to dead links, or they loose the activity item, per this ticket. :) Consensus seems to be that we should delete activity when a post is trashed.
- I discovered when testing that we don't handle Activity items if the post goes from published -> draft.
#14
@
11 years ago
Hi Paul
My patch doesn't take into account the published-to-draft status transition so it was never a great approach.
Your patch got me thinking of all possible eventualities. Aside from delete, it seems all of the following status transitions can occur:
Published - > Future
Published - > Draft - covered in 5333-1
Published - > Pending
Published - > Private
Published - > Trash - covered in 5333-1
http://codex.wordpress.org/Post_Status
- Is it worth modifying your patch to take all these possibilities into account?
- Should the same housekeeping be done for blog post comments?
#15
@
11 years ago
DJPaul - Thanks for the patch.
but probably nicer to integrate into a bp_blogs_catch_published_post()-type wrapper
Yup, the more possibilities I'm seeing, the more I'm thinking it should all be centralized.
See 5333.02.patch.
In other words:
- Do nothing if this is just an edit.
- If the post is being published (ie, transitioned to 'publish' from a non-'publish' status), post a new activity item. (This reproduces the existing bp_blogs_catch_published_post().)
- If the post is being unpublished, delete the activity item. DJPaul, your patch only deletes for publish->trash and publish->draft, but I think henry.wright is correct that we should account for other cases as well. Was your original concern about custom statuses? Maybe we can just extend our whitelist.
Should the same housekeeping be done for blog post comments?
Yes. Let's wait until we get it how we want it for posts, and then we can port it to comments.
#16
@
11 years ago
I like how you've used if ( 'publish' === $old_status )
to catch everything! Very nice and concise!
Yes. Let's wait until we get it how we want it for posts, and then we can port it to comments.
OK, sounds good.
Apologies - when I said 'deleted', I should have been more specific. I actually mean 'trashed'.
add_action( 'delete_post', 'bp_blogs_remove_post' );
fires for 'deleted' posts. Just doesn't seem to be a hook that fires for 'trashed' posts.