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

View File

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