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