Import scripts: add method close_inactive_topics

This commit is contained in:
Neil Lalonde 2014-06-04 10:37:43 -04:00
parent 457f5f81d6
commit 35834a9c40

View file

@ -239,6 +239,21 @@ class ImportScripts::Base
Post.exec_sql("update topics t set bumped_at = (select max(created_at) from posts where topic_id = t.id)")
end
def close_inactive_topics(opts={})
num_days = opts[:days] || 30
puts '', "Closing topics that have been inactive for more than #{num_days} days."
query = Topic.where('last_posted_at < ?', num_days.days.ago).where(closed: false)
total_count = query.count
closed_count = 0
query.find_each do |topic|
topic.update_status('closed', true, Discourse.system_user)
closed_count += 1
print_status(closed_count, total_count)
end
end
def print_status(current, max)
print "\r%9d / %d (%5.1f%%) " % [current, max, ((current.to_f / max.to_f) * 100).round(1)]
end