FIX: Correctly place moderator post for full topic move with freeze_original (#30324)

When freeze_original option is passed to PostMover, and we are moving all posts there is an issue. We attempt to put the small_action right after the last moved post. The issue is when there is an existing small action after the last moved "real" post. We then try to put the moderator post at the same location of the existing small action, which causes an index conflict and the move fails.

This makes sure that we place the moderator post at the verrrrrry end of the topic :)
This commit is contained in:
Mark VanLandingham
2024-12-17 10:31:34 -06:00
committed by GitHub
parent 37f032752e
commit 415abe6491
2 changed files with 38 additions and 11 deletions

View File

@ -97,11 +97,15 @@ class PostMover
@first_post_number_moved =
posts.first.is_first_post? ? posts[1]&.post_number : posts.first.post_number
if @options[:freeze_original] # in this case we need to add the moderator post after the last copied post
from_posts = @original_topic.ordered_posts.where("post_number > ?", posts.last.post_number)
shift_post_numbers(from_posts) if !@full_move
@first_post_number_moved = posts.last.post_number + 1
if @options[:freeze_original]
# in this case we need to add the moderator post after the last copied post
if @full_move
@first_post_number_moved = @original_topic.ordered_posts.last.post_number + 1
else
from_posts = @original_topic.ordered_posts.where("post_number > ?", posts.last.post_number)
shift_post_numbers(from_posts)
@first_post_number_moved = posts.last.post_number + 1
end
end
move_each_post