A platform for community discussion. Free, open, simple.
FIX: After moving the posts topic timestamp should be updated with newest post
Vinoth Kannane8559f222c85
diff --git a/app/models/post_mover.rb b/app/models/post_mover.rbindex 42e8ad42b5f..75e3cb16768 100644--- a/app/models/post_mover.rb+++ b/app/models/post_mover.rb@@ -47,7 +47,7 @@ class PostMovernotify_users_that_posts_have_movedupdate_statisticsupdate_user_actions- set_last_post_user_id(destination_topic)+ update_last_post_statsif moving_all_posts@original_topic.update_status('closed', true, @user)@@ -204,9 +204,15 @@ class PostMoverendend- def set_last_post_user_id(topic)- user_id = topic.posts.last.user_id rescue nil- return if user_id.nil?- topic.update_attribute :last_post_user_id, user_id+ def update_last_post_stats+ post = destination_topic.posts.where.not(post_type: Post.types[:whisper]).last+ if post && post_ids.include?(post.id)+ attrs = {}+ attrs[:last_posted_at] = post.created_at+ attrs[:last_post_user_id] = post.user_id+ attrs[:bumped_at] = post.created_at unless post.no_bump+ attrs[:updated_at] = 'now()'+ destination_topic.update_columns(attrs)+ endendenddiff --git a/spec/models/post_mover_spec.rb b/spec/models/post_mover_spec.rbindex 3ef6bd21542..d483b354fa3 100644--- a/spec/models/post_mover_spec.rb+++ b/spec/models/post_mover_spec.rb@@ -192,8 +192,11 @@ describe PostMover donew_topic.reloadexpect(new_topic.posts_count).to eq(2)expect(new_topic.highest_post_number).to eq(2)- expect(new_topic.last_post_user_id).to eq(new_topic.posts.last.user_id)- expect(new_topic.last_posted_at).to be_present++ last_post = new_topic.posts.last+ expect(new_topic.last_post_user_id).to eq(last_post.user_id)+ expect(new_topic.last_posted_at).to eq(last_post.created_at)+ expect(new_topic.bumped_at).to eq(last_post.created_at)p2.reloadexpect(p2.sort_order).to eq(1)