mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 01:24:14 +08:00
4af77f1e38
This PR allows entering a float value for topic timers e.g. 0.5 for 30 minutes when entering hours, 0.5 for 12 hours when entering days. This is achieved by adding a new column to store the duration of a topic timer in minutes instead of the ambiguous both hours and days that it could be before. This PR has ommitted the post migration to delete the duration column in topic timers; it will be done in a subsequent PR to ensure that no data is lost if the UPDATE query to set duration_mintues fails. I have to keep the old keyword of duration in set_or_create_topic_timer for backwards compat, will remove at a later date after plugins are updated.
24 lines
854 B
Ruby
24 lines
854 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Jobs
|
|
class DeleteReplies < ::Jobs::TopicTimerBase
|
|
def execute_timer_action(topic_timer, topic)
|
|
unless Guardian.new(topic_timer.user).is_staff?
|
|
topic_timer.trash!(Discourse.system_user)
|
|
return
|
|
end
|
|
|
|
replies = topic.posts.where("posts.post_number > 1")
|
|
replies = replies.where("like_count < ?", SiteSetting.skip_auto_delete_reply_likes) if SiteSetting.skip_auto_delete_reply_likes > 0
|
|
|
|
replies.where('posts.created_at < ?', topic_timer.duration_minutes.minutes.ago).each do |post|
|
|
PostDestroyer.new(topic_timer.user, post, context: I18n.t("topic_statuses.auto_deleted_by_timer")).destroy
|
|
end
|
|
|
|
topic_timer.execute_at = (replies.minimum(:created_at) || Time.zone.now) + topic_timer.duration_minutes.minutes
|
|
topic_timer.save
|
|
end
|
|
|
|
end
|
|
end
|