A platform for community discussion. Free, open, simple.
DEV: Drop duration column from topic timers (#13543)
Martin Brennand098f51ad3a3
diff --git a/app/models/topic.rb b/app/models/topic.rbindex 00a3eacaa80..9ad202b533d 100644--- a/app/models/topic.rb+++ b/app/models/topic.rb@@ -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::Baseendif topic_timer.based_on_last_post- if duration > 0 || duration_minutes > 0+ if duration_minutes > 0last_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_minutestopic_timer.execute_at = last_post_created_at + duration_minutes.minutestopic_timer.created_at = last_post_created_atendelsif topic_timer.status_type == TopicTimer.types[:delete_replies]- if duration > 0 || duration_minutes > 0+ if duration_minutes > 0first_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_minutestopic_timer.execute_at = first_reply_created_at + duration_minutes.minutestopic_timer.created_at = first_reply_created_atdiff --git a/db/post_migrate/20210628035905_drop_duration_column_from_topic_timers.rb b/db/post_migrate/20210628035905_drop_duration_column_from_topic_timers.rbnew file mode 100644index 00000000000..f8e8ee2c73e--- /dev/null+++ b/db/post_migrate/20210628035905_drop_duration_column_from_topic_timers.rb@@ -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