A platform for community discussion. Free, open, simple.
FIX: keep first post edit history when moving/merging (#22966)
Renato Atilio701ae8764efa
diff --git a/app/models/post_mover.rb b/app/models/post_mover.rbindex fd2d4793e89..cfa1720318c 100644--- a/app/models/post_mover.rb+++ b/app/models/post_mover.rb@@ -260,7 +260,13 @@ class PostMoverPostAction.copy(post, new_post)- attrs_to_update = { reply_count: @reply_count[1] || 0 }+ PostRevision.copy(post, new_post)++ attrs_to_update = {+ reply_count: @reply_count[1] || 0,+ version: post.version,+ public_version: post.public_version,+ }if new_post.post_number != @move_map[post.post_number]attrs_to_update[:post_number] = @move_map[post.post_number]diff --git a/app/models/post_revision.rb b/app/models/post_revision.rbindex 91554852383..6a5033cfc67 100644--- a/app/models/post_revision.rb+++ b/app/models/post_revision.rb@@ -39,6 +39,17 @@ class PostRevision < ActiveRecord::Basedef create_notificationPostActionNotifier.after_create_post_revision(self)end++ def self.copy(original_post, target_post)+ cols_to_copy = (column_names - %w[id post_id]).join(", ")++ DB.exec <<~SQL+ INSERT INTO post_revisions(post_id, #{cols_to_copy})+ SELECT #{target_post.id}, #{cols_to_copy}+ FROM post_revisions+ WHERE post_id = #{original_post.id}+ SQL+ endend# == Schema Informationdiff --git a/spec/models/post_mover_spec.rb b/spec/models/post_mover_spec.rbindex 1f5a155399a..28186efd54d 100644--- a/spec/models/post_mover_spec.rb+++ b/spec/models/post_mover_spec.rb@@ -875,6 +875,18 @@ RSpec.describe PostMover doexpect(TopicUser.find_by(topic: destination_topic, user: user).liked).to eq(true)end+ it "copies the post revisions from first post to the new post" do+ p1.revise(another_user, { raw: "A different raw content" })++ moved_to = topic.move_posts(user, [p1.id], destination_topic_id: destination_topic.id)+ new_post = moved_to.posts.last++ expect(new_post.id).not_to eq(p1.id)+ expect(new_post.version).to eq(2)+ expect(new_post.public_version).to eq(2)+ expect(new_post.post_revisions.size).to eq(1)+ end+context "with read state and other stats per user" dodef create_topic_user(user, topic, opts = {})notification_level = opts.delete(:notification_level) || :regular@@ -1223,6 +1235,18 @@ RSpec.describe PostMover doexpect(new_topic.first_post.custom_fields).to eq(custom_fields)end+ it "preserves the post revisions in the new post" do+ p1.revise(another_user, { raw: "A different raw content" })++ new_topic = topic.move_posts(user, [p1.id], title: "new testing topic name")+ new_post = new_topic.posts.where(post_number: 1).first++ expect(new_post.id).not_to eq(p1.id)+ expect(new_post.version).to eq(2)+ expect(new_post.public_version).to eq(2)+ expect(new_post.post_revisions.size).to eq(1)+ end+include_examples "moves email related stuff" dolet!(:old_post) { p1 }end