A platform for community discussion. Free, open, simple.
FIX: Correctly update replies when first post gets moved
Gerhard Schlager50db6a1d62d5
diff --git a/app/models/post_mover.rb b/app/models/post_mover.rbindex 12ca7e06474..bf7ca569ade 100644--- a/app/models/post_mover.rb+++ b/app/models/post_mover.rb@@ -129,6 +129,7 @@ class PostMovermove_incoming_emailsmove_notificationsupdate_reply_counts+ move_first_post_repliesdelete_post_repliesend@@ -254,6 +255,16 @@ class PostMoverSQLend+ 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_repliesDB.exec <<~SQLDELETEdiff --git a/spec/models/post_mover_spec.rb b/spec/models/post_mover_spec.rbindex 3cebd1e36e1..da1aedd7f68 100644--- a/spec/models/post_mover_spec.rb+++ b/spec/models/post_mover_spec.rb@@ -584,6 +584,12 @@ describe PostMover dotopic.reloadexpect(topic.posts.by_post_number).to match_array([p1, p3, p4])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)endit "preserves post actions in the new post" do