mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:44:49 +08:00
DEV: Drop duration column from topic timers (#13543)
The duration column has been ignored since the commit4af77f1e38
for topic_timers, we use duration_minutes instead. Also removing the duration key from Topic.set_or_create_timer. The only plugin to use this was discourse-solved, which doesn't use it any longer sincec722b94a97
This commit is contained in:
parent
03338f9086
commit
d098f51ad3
|
@ -1319,19 +1319,13 @@ class Topic < ActiveRecord::Base
|
|||
# * by_user: User who is setting the topic's status update.
|
||||
# * based_on_last_post: True if time should be based on timestamp of the last post.
|
||||
# * category_id: Category that the update will apply to.
|
||||
# * duration: TODO(2021-06-01): DEPRECATED - do not use
|
||||
# * duration_minutes: The duration of the timer in minutes, which is used if the timer is based
|
||||
# on the last post or if the timer type is delete_replies.
|
||||
# * silent: Affects whether the close topic timer status change will be silent or not.
|
||||
def set_or_create_timer(status_type, time, by_user: nil, based_on_last_post: false, category_id: SiteSetting.uncategorized_category_id, duration: nil, duration_minutes: nil, silent: nil)
|
||||
return delete_topic_timer(status_type, by_user: by_user) if time.blank? && duration_minutes.blank? && duration.blank?
|
||||
def set_or_create_timer(status_type, time, by_user: nil, based_on_last_post: false, category_id: SiteSetting.uncategorized_category_id, duration_minutes: nil, silent: nil)
|
||||
return delete_topic_timer(status_type, by_user: by_user) if time.blank? && duration_minutes.blank?
|
||||
|
||||
duration_minutes = duration_minutes ? duration_minutes.to_i : 0
|
||||
|
||||
# TODO(2021-06-01): deprecated - remove this when plugins calling set_or_create_timer
|
||||
# have been fixed to use duration_minutes
|
||||
duration = duration ? duration.to_i : 0
|
||||
|
||||
public_topic_timer = !!TopicTimer.public_types[status_type]
|
||||
topic_timer_options = { topic: self, public_type: public_topic_timer }
|
||||
topic_timer_options.merge!(user: by_user) unless public_topic_timer
|
||||
|
@ -1347,29 +1341,15 @@ class Topic < ActiveRecord::Base
|
|||
end
|
||||
|
||||
if topic_timer.based_on_last_post
|
||||
if duration > 0 || duration_minutes > 0
|
||||
if duration_minutes > 0
|
||||
last_post_created_at = self.ordered_posts.last.present? ? self.ordered_posts.last.created_at : time_now
|
||||
|
||||
# TODO(2021-06-01): deprecated - remove this when plugins calling set_or_create_timer
|
||||
# have been fixed to use duration_minutes
|
||||
if duration > 0
|
||||
duration_minutes = duration * 60
|
||||
end
|
||||
|
||||
topic_timer.duration_minutes = duration_minutes
|
||||
topic_timer.execute_at = last_post_created_at + duration_minutes.minutes
|
||||
topic_timer.created_at = last_post_created_at
|
||||
end
|
||||
elsif topic_timer.status_type == TopicTimer.types[:delete_replies]
|
||||
if duration > 0 || duration_minutes > 0
|
||||
if duration_minutes > 0
|
||||
first_reply_created_at = (self.ordered_posts.where("post_number > 1").minimum(:created_at) || time_now)
|
||||
|
||||
# TODO(2021-06-01): deprecated - remove this when plugins calling set_or_create_timer
|
||||
# have been fixed to use duration_minutes
|
||||
if duration > 0
|
||||
duration_minutes = duration * 60 * 24
|
||||
end
|
||||
|
||||
topic_timer.duration_minutes = duration_minutes
|
||||
topic_timer.execute_at = first_reply_created_at + duration_minutes.minutes
|
||||
topic_timer.created_at = first_reply_created_at
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class DropDurationColumnFromTopicTimers < ActiveRecord::Migration[6.1]
|
||||
DROPPED_COLUMNS ||= {
|
||||
topic_timers: %i{duration}
|
||||
}
|
||||
|
||||
def up
|
||||
DROPPED_COLUMNS.each do |table, columns|
|
||||
Migration::ColumnDropper.execute_drop(table, columns)
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
add_column :topic_timers, :duration, :string
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user