mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 20:33:38 +08:00
FIX: Correctly update replies when first post gets moved
This commit is contained in:
parent
4113b57cfe
commit
50db6a1d62
|
@ -129,6 +129,7 @@ class PostMover
|
||||||
move_incoming_emails
|
move_incoming_emails
|
||||||
move_notifications
|
move_notifications
|
||||||
update_reply_counts
|
update_reply_counts
|
||||||
|
move_first_post_replies
|
||||||
delete_post_replies
|
delete_post_replies
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -254,6 +255,16 @@ class PostMover
|
||||||
SQL
|
SQL
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def move_first_post_replies
|
||||||
|
DB.exec <<~SQL
|
||||||
|
UPDATE post_replies pr
|
||||||
|
SET post_id = mp.new_post_id
|
||||||
|
FROM moved_posts mp, moved_posts mr
|
||||||
|
WHERE mp.old_post_id <> mp.new_post_id AND pr.post_id = mp.old_post_id AND
|
||||||
|
EXISTS (SELECT 1 FROM moved_posts mr WHERE mr.new_post_id = pr.reply_id)
|
||||||
|
SQL
|
||||||
|
end
|
||||||
|
|
||||||
def delete_post_replies
|
def delete_post_replies
|
||||||
DB.exec <<~SQL
|
DB.exec <<~SQL
|
||||||
DELETE
|
DELETE
|
||||||
|
|
|
@ -584,6 +584,12 @@ describe PostMover do
|
||||||
topic.reload
|
topic.reload
|
||||||
expect(topic.posts.by_post_number).to match_array([p1, p3, p4])
|
expect(topic.posts.by_post_number).to match_array([p1, p3, p4])
|
||||||
expect(topic.highest_post_number).to eq(p4.post_number)
|
expect(topic.highest_post_number).to eq(p4.post_number)
|
||||||
|
|
||||||
|
# updates replies for posts moved to same topic
|
||||||
|
expect(PostReply.where(reply_id: p2.id).pluck(:post_id)).to contain_exactly(new_first.id)
|
||||||
|
|
||||||
|
# leaves replies to the first post of the original topic unchanged
|
||||||
|
expect(PostReply.where(reply_id: p3.id).pluck(:post_id)).to contain_exactly(p1.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "preserves post actions in the new post" do
|
it "preserves post actions in the new post" do
|
||||||
|
|
Loading…
Reference in New Issue
Block a user