discourse/lib/site_settings/deprecated_settings.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

76 lines
2.2 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
module SiteSettings
end
module SiteSettings::DeprecatedSettings
SETTINGS = [
# [<old setting>, <new_setting>, <override>, <version to drop>]
["search_tokenize_chinese_japanese_korean", "search_tokenize_chinese", true, "2.9"],
["default_categories_regular", "default_categories_normal", true, "3.0"],
["min_trust_to_send_messages", "personal_message_enabled_groups", false, "3.0"],
["enable_personal_messages", "personal_message_enabled_groups", false, "3.0"],
]
def setup_deprecated_methods
SETTINGS.each do |old_setting, new_setting, override, version|
2018-11-14 05:07:04 -05:00
unless override
SiteSetting.singleton_class.public_send(
:alias_method,
:"_#{old_setting}",
:"#{old_setting}",
)
end
2018-11-14 04:32:32 -05:00
define_singleton_method old_setting do |warn: true|
if warn
Discourse.deprecate(
"`SiteSetting.#{old_setting}` has been deprecated. Please use `SiteSetting.#{new_setting}` instead.",
drop_from: version,
)
end
2018-11-14 04:32:32 -05:00
self.public_send(override ? new_setting : "_#{old_setting}")
end
2018-11-14 05:07:04 -05:00
unless override
SiteSetting.singleton_class.public_send(
:alias_method,
:"_#{old_setting}?",
:"#{old_setting}?",
)
end
2018-11-14 04:32:32 -05:00
define_singleton_method "#{old_setting}?" do |warn: true|
if warn
Discourse.deprecate(
"`SiteSetting.#{old_setting}?` has been deprecated. Please use `SiteSetting.#{new_setting}?` instead.",
drop_from: version,
)
end
2018-11-14 04:32:32 -05:00
self.public_send("#{override ? new_setting : "_" + old_setting}?")
end
2018-11-14 05:07:04 -05:00
unless override
SiteSetting.singleton_class.public_send(
:alias_method,
:"_#{old_setting}=",
:"#{old_setting}=",
)
end
2018-11-14 04:32:32 -05:00
define_singleton_method "#{old_setting}=" do |val, warn: true|
if warn
Discourse.deprecate(
"`SiteSetting.#{old_setting}=` has been deprecated. Please use `SiteSetting.#{new_setting}=` instead.",
drop_from: version,
)
end
2018-11-14 04:32:32 -05:00
self.public_send("#{override ? new_setting : "_" + old_setting}=", val)
end
end
end
end