discourse/db/migrate/20140929204155_migrate_tos_setting.rb
Sam Saffron 30990006a9 DEV: enable frozen string literal on all files
This reduces chances of errors where consumers of strings mutate inputs
and reduces memory usage of the app.

Test suite passes now, but there may be some stuff left, so we will run
a few sites on a branch prior to merging
2019-05-13 09:31:32 +08:00

23 lines
738 B
Ruby

# frozen_string_literal: true
class MigrateTosSetting < ActiveRecord::Migration[4.2]
def up
res = execute("SELECT * FROM site_settings WHERE name = 'tos_accept_required' AND value = 't'")
if res.present? && res.cmd_tuples > 0
label = nil
I18n.overrides_disabled do
label = I18n.t("terms_of_service.signup_form_message", base_path: "")
end
res = execute("SELECT value FROM site_texts WHERE text_type = 'tos_signup_form_message'")
if res.present? && res.cmd_tuples == 1
label = res[0]['value']
end
label = PG::Connection.escape_string(label)
execute("INSERT INTO user_fields (name, field_type, editable) VALUES ('#{label}', 'confirm', false)")
end
end
end