mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
Import scripts: add method close_inactive_topics
This commit is contained in:
parent
457f5f81d6
commit
35834a9c40
1 changed files with 15 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue