discourse/db/migrate/20150729150523_migrate_auto_close_posts.rb

19 lines
645 B
Ruby
Raw Normal View History

2015-07-30 00:20:35 +08:00
class MigrateAutoClosePosts < ActiveRecord::Migration
def up
2016-04-01 05:33:25 +08:00
I18n.overrides_disabled do
strings = []
%w(days hours lastpost_days lastpost_hours lastpost_minutes).map do |k|
strings << I18n.t("topic_statuses.autoclosed_enabled_#{k}.one")
strings << I18n.t("topic_statuses.autoclosed_enabled_#{k}.other").sub("%{count}", "\\d+")
end
2015-07-30 00:20:35 +08:00
2016-04-01 05:33:25 +08:00
sql = "UPDATE posts SET action_code = 'autoclosed.enabled', post_type = 3 "
sql << "WHERE post_type = 2 AND ("
sql << strings.map {|s| "raw ~* #{ActiveRecord::Base.connection.quote(s)}" }.join(' OR ')
sql << ")"
2015-07-30 00:20:35 +08:00
2016-04-01 05:33:25 +08:00
execute sql
end
2015-07-30 00:20:35 +08:00
end
end