2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-31 12:06:56 +08:00
|
|
|
class MigrateAutoClosePosts < ActiveRecord::Migration[4.2]
|
2015-07-30 00:20:35 +08:00
|
|
|
def up
|
2015-11-20 05:36:59 +08:00
|
|
|
I18n.overrides_disabled do
|
2015-11-15 05:11:22 +08:00
|
|
|
strings = []
|
|
|
|
%w(days hours lastpost_days lastpost_hours lastpost_minutes).map do |k|
|
2019-07-23 04:30:57 +08:00
|
|
|
strings += I18n.t("topic_statuses.autoclosed_enabled_#{k}").values.map { |s| s.sub("%{count}", "\\d+") }
|
2015-11-15 05:11:22 +08:00
|
|
|
end
|
2015-07-30 00:20:35 +08:00
|
|
|
|
2019-07-23 04:16:43 +08:00
|
|
|
sql = <<~SQL
|
|
|
|
UPDATE posts
|
|
|
|
SET action_code = 'autoclosed.enabled',
|
|
|
|
post_type = 3
|
|
|
|
WHERE post_type = 2 AND (
|
|
|
|
#{strings.map { |s| "raw ~* #{ActiveRecord::Base.connection.quote(s)}" }.join(' OR ')}
|
|
|
|
)
|
|
|
|
SQL
|
2015-07-30 00:20:35 +08:00
|
|
|
|
2015-11-15 05:11:22 +08:00
|
|
|
execute sql
|
|
|
|
end
|
2015-07-30 00:20:35 +08:00
|
|
|
end
|
|
|
|
end
|