FIX: Bookmark topics were not being updated when the post moved (#12542)

Because bookmarks have both topic and post ID, when the post was moved into another topic the bookmark was still attached to the post but did not show in the UI. This PR makes it so the all topic IDs for bookmarks attached to a post are updated when a post is moved.

Also included is a migration to fix affected records (e.g. on Meta there are 20 affected records).

See: https://meta.discourse.org/t/improved-bookmarks-with-reminders/144542/203
This commit is contained in:
Martin Brennan
2021-03-29 11:25:48 +10:00
committed by GitHub
parent d5e44fdd46
commit 2d686191b5
3 changed files with 55 additions and 0 deletions

View File

@@ -76,6 +76,7 @@ class PostMover
update_user_actions
update_last_post_stats
update_upload_security_status
update_bookmarks
if moving_all_posts
@original_topic.update_status('closed', true, @user)
@@ -491,6 +492,10 @@ class PostMover
end
end
def update_bookmarks
Bookmark.where(post_id: post_ids).update_all(topic_id: @destination_topic.id)
end
def watch_new_topic
if @destination_topic.archetype == Archetype.private_message
if @original_topic.archetype == Archetype.private_message