Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Update quotes after moving posts #8326

Merged
merged 1 commit into from Nov 12, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -126,6 +126,7 @@ def move_each_post
move_incoming_emails
move_notifications
update_reply_counts
update_quotes
move_first_post_replies
delete_post_replies
copy_first_post_timings
@@ -256,6 +257,18 @@ def update_reply_counts
SQL
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
DB.exec <<~SQL
UPDATE post_replies pr
@@ -90,6 +90,27 @@
expect(move_message.post_type).to eq(Post.types[:small_action])
expect(move_message.raw).to include("3 posts were split")
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

context "errors" do
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.