mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
FIX: when moving posts, retain creator and date from OP
This commit is contained in:
parent
ca50252f77
commit
ffa523a543
3 changed files with 20 additions and 4 deletions
|
@ -22,11 +22,15 @@ class PostMover
|
||||||
def to_new_topic(title, category_id=nil)
|
def to_new_topic(title, category_id=nil)
|
||||||
@move_type = PostMover.move_types[:new_topic]
|
@move_type = PostMover.move_types[:new_topic]
|
||||||
|
|
||||||
|
post = Post.find_by(id: post_ids.first)
|
||||||
|
raise Discourse::InvalidParameters unless post
|
||||||
|
|
||||||
Topic.transaction do
|
Topic.transaction do
|
||||||
move_posts_to Topic.create!(
|
move_posts_to Topic.create!(
|
||||||
user: user,
|
user: post.user,
|
||||||
title: title,
|
title: title,
|
||||||
category_id: category_id
|
category_id: category_id,
|
||||||
|
created_at: post.created_at
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
class FixIncorrectTopicCreatorAfterMove < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
execute "UPDATE topics SET user_id = p.user_id
|
||||||
|
FROM posts p
|
||||||
|
WHERE p.topic_id = topics.id AND
|
||||||
|
p.post_number = 1 AND
|
||||||
|
p.user_id <> topics.user_id"
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
end
|
||||||
|
end
|
|
@ -64,7 +64,7 @@ describe PostMover do
|
||||||
expect(TopicUser.find_by(user_id: user.id, topic_id: topic.id).last_read_post_number).to eq(p3.post_number)
|
expect(TopicUser.find_by(user_id: user.id, topic_id: topic.id).last_read_post_number).to eq(p3.post_number)
|
||||||
|
|
||||||
expect(new_topic).to be_present
|
expect(new_topic).to be_present
|
||||||
expect(new_topic.featured_user1_id).to eq(another_user.id)
|
expect(new_topic.featured_user1_id).to eq(p4.user_id)
|
||||||
expect(new_topic.like_count).to eq(1)
|
expect(new_topic.like_count).to eq(1)
|
||||||
|
|
||||||
expect(new_topic.category).to eq(category)
|
expect(new_topic.category).to eq(category)
|
||||||
|
@ -112,7 +112,7 @@ describe PostMover do
|
||||||
moved_to.reload
|
moved_to.reload
|
||||||
expect(moved_to.posts_count).to eq(3)
|
expect(moved_to.posts_count).to eq(3)
|
||||||
expect(moved_to.highest_post_number).to eq(3)
|
expect(moved_to.highest_post_number).to eq(3)
|
||||||
expect(moved_to.featured_user1_id).to eq(another_user.id)
|
expect(moved_to.user_id).to eq(p1.user_id)
|
||||||
expect(moved_to.like_count).to eq(1)
|
expect(moved_to.like_count).to eq(1)
|
||||||
expect(moved_to.category_id).to eq(SiteSetting.uncategorized_category_id)
|
expect(moved_to.category_id).to eq(SiteSetting.uncategorized_category_id)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue