|
|
@ -5,13 +5,15 @@ namespace :course_board do
|
|
|
|
logger("Current transfer board id: #{board.id} ~")
|
|
|
|
logger("Current transfer board id: #{board.id} ~")
|
|
|
|
|
|
|
|
|
|
|
|
root_subquery = board.messages.where(parent_id: nil).reorder(nil).pluck(:id)
|
|
|
|
root_subquery = board.messages.where(parent_id: nil).reorder(nil).pluck(:id)
|
|
|
|
next if root_subquery.blank?
|
|
|
|
if root_subquery.present?
|
|
|
|
children_subquery = Message.where(parent_id: root_subquery).reorder(nil).pluck(:id)
|
|
|
|
children_subquery = Message.where(parent_id: root_subquery).reorder(nil).pluck(:id)
|
|
|
|
next if children_subquery.blank?
|
|
|
|
if children_subquery.present?
|
|
|
|
second_children_subquery = Message.where(parent_id: children_subquery).reorder(nil).pluck(:id)
|
|
|
|
second_children_subquery = Message.where(parent_id: children_subquery).reorder(nil).pluck(:id)
|
|
|
|
|
|
|
|
|
|
|
|
ids = children_subquery.concat(second_children_subquery).uniq
|
|
|
|
ids = children_subquery.concat(second_children_subquery).uniq
|
|
|
|
Message.where(id: ids).update_all(board_id: board.id)
|
|
|
|
Message.where(id: ids).update_all(board_id: board.id)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
Board.reset_counters(board.id, :messages)
|
|
|
|
Board.reset_counters(board.id, :messages)
|
|
|
|
logger("transfer success ~")
|
|
|
|
logger("transfer success ~")
|
|
|
|