FIX: Update quotes after moving posts (#8326)

This commit is contained in:
Dan Ungureanu 2019-11-12 15:16:39 +02:00 committed by GitHub
parent 241d9a3034
commit bbcce08712
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View File

@ -126,6 +126,7 @@ class PostMover
move_incoming_emails move_incoming_emails
move_notifications move_notifications
update_reply_counts update_reply_counts
update_quotes
move_first_post_replies move_first_post_replies
delete_post_replies delete_post_replies
copy_first_post_timings copy_first_post_timings
@ -256,6 +257,18 @@ class PostMover
SQL SQL
end end
def update_quotes
DB.exec <<~SQL
UPDATE posts p
SET raw = REPLACE(p.raw,
', post:' || mp.old_post_number || ', topic:' || mp.old_topic_id,
', post:' || mp.new_post_number || ', topic:' || mp.new_topic_id),
baked_version = NULL
FROM moved_posts mp, quoted_posts qp
WHERE p.id = qp.post_id AND mp.old_post_id = qp.quoted_post_id
SQL
end
def move_first_post_replies def move_first_post_replies
DB.exec <<~SQL DB.exec <<~SQL
UPDATE post_replies pr UPDATE post_replies pr

View File

@ -90,6 +90,27 @@ describe PostMover do
expect(move_message.post_type).to eq(Post.types[:small_action]) expect(move_message.post_type).to eq(Post.types[:small_action])
expect(move_message.raw).to include("3 posts were split") expect(move_message.raw).to include("3 posts were split")
end end
it "correctly remaps quotes" do
raw = <<~RAW
[quote="dan, post:#{p2.post_number}, topic:#{p2.topic_id}, full:true"]
some quote from the other post
[/quote]
the quote above should be updated with new post number and topic id
RAW
p3.update!(raw: raw)
p3.rebake!
expect { topic.move_posts(user, [p2.id], title: "new testing topic name") }
.to change { p2.reload.topic_id }
.and change { p2.post_number }
.and change { p3.reload.raw }
.and change { p3.baked_version }.to nil
expect(p3.raw).to include("post:#{p2.post_number}, topic:#{p2.topic_id}")
end
end end
context "errors" do context "errors" do