FIX: PostOwnerChange should update 'topic.last_poser'

This commit is contained in:
Régis Hanol 2018-05-16 19:48:04 +02:00
parent dcf97ca559
commit b284464a91
1 changed files with 10 additions and 9 deletions

View File

@ -12,21 +12,22 @@ class PostOwnerChanger
def change_owner! def change_owner!
@post_ids.each do |post_id| @post_ids.each do |post_id|
post = Post.with_deleted.where(id: post_id, topic_id: @topic.id).first next unless post = Post.with_deleted.find_by(id: post_id, topic_id: @topic.id)
next if post.blank?
@topic.user = @new_owner if post.is_first_post?
if post.user == nil if post.is_first_post?
@topic.recover! if post.is_first_post? @topic.user = @new_owner
@topic.recover! if post.user.nil?
end end
post.topic = @topic post.topic = @topic
post.set_owner(@new_owner, @acting_user, @skip_revision) post.set_owner(@new_owner, @acting_user, @skip_revision)
PostAction.remove_act(@new_owner, post, PostActionType.types[:like]) PostAction.remove_act(@new_owner, post, PostActionType.types[:like])
if post.post_number == 1 level = post.is_first_post? ? :watching : :tracking
TopicUser.change(@new_owner.id, @topic.id, notification_level: NotificationLevels.topic_levels[:watching]) TopicUser.change(@new_owner.id, @topic.id, notification_level: NotificationLevels.topic_levels[level])
else
TopicUser.change(@new_owner.id, @topic.id, notification_level: NotificationLevels.topic_levels[:tracking]) if post == @topic.posts.order("post_number DESC").where("NOT hidden AND posts.deleted_at IS NULL").first
@topic.last_poster = @new_owner
end end
@topic.update_statistics @topic.update_statistics