From e08b5feb8ad97e4e0d7eca661af22941dc97ae69 Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Wed, 20 Sep 2017 23:18:53 +0200 Subject: [PATCH] improved status output during auto-closing and ignore deleted topic timers --- lib/tasks/topics.rake | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/tasks/topics.rake b/lib/tasks/topics.rake index f862071daff..f0cb196f0e6 100644 --- a/lib/tasks/topics.rake +++ b/lib/tasks/topics.rake @@ -14,9 +14,14 @@ def close_old_topics(category) topics_closed = 0 total = topics.count + if total == 0 + print " all old topics are closed" + return + end + topics.find_each do |topic| topic.update_status("closed", true, Discourse.system_user) - print_status("\tClosing topics: ", topics_closed += 1, total) + print_status(" closing old topics: ", topics_closed += 1, total) end end @@ -28,15 +33,21 @@ def apply_auto_close(category) FROM topic_timers WHERE topic_timers.topic_id = topics.id AND topic_timers.status_type = ? + AND topic_timers.deleted_at IS NULL ) SQL topics_closed = 0 total = topics.count + if total == 0 + print " all topics have auto-close applied" + return + end + topics.find_each do |topic| topic.inherit_auto_close_from_category - print_status("\tApplying auto-close to topics: ", topics_closed += 1, total) + print_status(" applying auto-close to topics: ", topics_closed += 1, total) end end @@ -46,7 +57,9 @@ task "topics:apply_autoclose" => :environment do categories.find_each do |category| puts "", "Applying auto-close to category '#{category.name}' ..." close_old_topics(category) + puts "" apply_auto_close(category) + puts "" end puts "", "Done"