2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-02-01 00:09:03 +08:00
|
|
|
PRIVATE_BOOTSTRAP_MODE_MIN_USERS = 10
|
|
|
|
|
2019-04-18 23:48:01 +08:00
|
|
|
DiscourseEvent.on(:site_setting_changed) do |name, old_value, new_value|
|
2020-04-09 20:42:24 +08:00
|
|
|
Category.clear_subcategory_ids if name === :max_category_nesting
|
|
|
|
|
2019-04-18 23:48:01 +08:00
|
|
|
# Enabling `must_approve_users` on an existing site is odd, so we assume that the
|
|
|
|
# existing users are approved.
|
|
|
|
if name == :must_approve_users && new_value == true
|
2020-03-03 03:33:52 +08:00
|
|
|
User
|
|
|
|
.where(approved: false)
|
|
|
|
.joins("LEFT JOIN reviewables r ON r.target_id = users.id")
|
|
|
|
.where(r: { id: nil })
|
|
|
|
.update_all(approved: true)
|
2019-04-17 02:42:47 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
if name == :emoji_set
|
|
|
|
Emoji.clear_cache
|
|
|
|
|
2019-04-18 23:48:01 +08:00
|
|
|
before = "/images/emoji/#{old_value}/"
|
|
|
|
after = "/images/emoji/#{new_value}/"
|
2019-04-17 02:42:47 +08:00
|
|
|
|
|
|
|
Scheduler::Defer.later("Fix Emoji Links") do
|
|
|
|
DB.exec(
|
|
|
|
"UPDATE posts SET cooked = REPLACE(cooked, :before, :after) WHERE cooked LIKE :like",
|
|
|
|
before: before,
|
|
|
|
after: after,
|
|
|
|
like: "%#{before}%",
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-02-01 00:09:03 +08:00
|
|
|
# Set bootstrap min users for private sites to a lower default
|
|
|
|
if name == :login_required && SiteSetting.bootstrap_mode_enabled == true
|
|
|
|
if new_value == true &&
|
|
|
|
SiteSetting.bootstrap_mode_min_users == SiteSetting.defaults.get(:bootstrap_mode_min_users)
|
|
|
|
SiteSetting.bootstrap_mode_min_users = PRIVATE_BOOTSTRAP_MODE_MIN_USERS
|
|
|
|
end
|
|
|
|
|
|
|
|
# Set bootstrap min users for public sites back to the default
|
|
|
|
if new_value == false &&
|
|
|
|
SiteSetting.bootstrap_mode_min_users == PRIVATE_BOOTSTRAP_MODE_MIN_USERS
|
|
|
|
SiteSetting.bootstrap_mode_min_users = SiteSetting.defaults.get(:bootstrap_mode_min_users)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-07-07 01:11:10 +08:00
|
|
|
Stylesheet::Manager.clear_color_scheme_cache! if %i[base_font heading_font].include?(name)
|
2020-09-04 21:25:50 +08:00
|
|
|
|
2019-04-17 02:42:47 +08:00
|
|
|
Report.clear_cache(:storage_stats) if %i[backup_location s3_backup_bucket].include?(name)
|
|
|
|
|
|
|
|
if name == :slug_generation_method
|
|
|
|
Scheduler::Defer.later("Null topic slug") { Topic.update_all(slug: nil) }
|
|
|
|
end
|
|
|
|
|
2019-12-24 21:11:37 +08:00
|
|
|
Jobs.enqueue(:update_s3_inventory) if %i[enable_s3_inventory s3_upload_bucket].include?(name)
|
2019-04-17 02:42:47 +08:00
|
|
|
|
|
|
|
SvgSprite.expire_cache if name.to_s.include?("_icon")
|
2019-05-01 21:44:45 +08:00
|
|
|
|
|
|
|
SiteIconManager.ensure_optimized! if SiteIconManager::WATCHED_SETTINGS.include?(name)
|
2019-07-13 02:42:43 +08:00
|
|
|
|
2021-04-24 02:34:24 +08:00
|
|
|
# Make sure medium and high priority thresholds were calculated.
|
|
|
|
if name == :reviewable_low_priority_threshold && Reviewable.min_score_for_priority(:medium) > 0
|
|
|
|
Reviewable.set_priorities(low: new_value)
|
|
|
|
end
|
2023-04-13 15:38:54 +08:00
|
|
|
|
|
|
|
Emoji.clear_cache && Discourse.request_refresh! if name == :emoji_deny_list
|
2023-05-12 22:09:40 +08:00
|
|
|
|
2023-06-08 02:31:20 +08:00
|
|
|
Discourse.clear_urls! if %i[tos_topic_id privacy_topic_id].include?(name)
|
|
|
|
|
2023-05-25 04:05:36 +08:00
|
|
|
# Update seeded topics
|
|
|
|
if %i[title site_description].include?(name)
|
|
|
|
topics = SeedData::Topics.with_default_locale
|
|
|
|
topics.update(site_setting_names: ["welcome_topic_id"], skip_changed: true)
|
|
|
|
elsif %i[company_name contact_email governing_law city_for_disputes].include?(name)
|
|
|
|
topics = SeedData::Topics.with_default_locale
|
|
|
|
%w[tos_topic_id privacy_topic_id].each do |site_setting|
|
|
|
|
topic_id = SiteSetting.get(site_setting)
|
|
|
|
if topic_id > 0 && Topic.with_deleted.exists?(id: topic_id)
|
|
|
|
if SiteSetting.company_name.blank?
|
|
|
|
topics.delete(site_setting_names: [site_setting], skip_changed: true)
|
|
|
|
else
|
|
|
|
topics.update(site_setting_names: [site_setting], skip_changed: true)
|
|
|
|
end
|
|
|
|
elsif SiteSetting.company_name.present?
|
|
|
|
topics.create(site_setting_names: [site_setting])
|
|
|
|
end
|
|
|
|
end
|
2023-05-12 22:09:40 +08:00
|
|
|
end
|
2019-04-17 02:42:47 +08:00
|
|
|
end
|