"Fossies" - the Fresh Open Source Software Archive

Member "discourse-2.8.3/config/initializers/014-track-setting-changes.rb" (14 Apr 2022, 1779 Bytes) of package /linux/www/discourse-2.8.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Ruby source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "014-track-setting-changes.rb": 2.7.13_vs_2.8.0.

    1 # frozen_string_literal: true
    2 
    3 DiscourseEvent.on(:site_setting_changed) do |name, old_value, new_value|
    4   Category.clear_subcategory_ids if name === :max_category_nesting
    5 
    6   # Enabling `must_approve_users` on an existing site is odd, so we assume that the
    7   # existing users are approved.
    8   if name == :must_approve_users && new_value == true
    9 
   10     User.where(approved: false)
   11       .joins("LEFT JOIN reviewables r ON r.target_id = users.id")
   12       .where(r: { id: nil }).update_all(approved: true)
   13   end
   14 
   15   if name == :emoji_set
   16     Emoji.clear_cache
   17 
   18     before = "/images/emoji/#{old_value}/"
   19     after = "/images/emoji/#{new_value}/"
   20 
   21     Scheduler::Defer.later("Fix Emoji Links") do
   22       DB.exec("UPDATE posts SET cooked = REPLACE(cooked, :before, :after) WHERE cooked LIKE :like",
   23         before: before,
   24         after: after,
   25         like: "%#{before}%"
   26       )
   27     end
   28   end
   29 
   30   Stylesheet::Manager.clear_color_scheme_cache! if [:base_font, :heading_font].include?(name)
   31 
   32   Report.clear_cache(:storage_stats) if [:backup_location, :s3_backup_bucket].include?(name)
   33 
   34   if name == :slug_generation_method
   35     Scheduler::Defer.later("Null topic slug") do
   36       Topic.update_all(slug: nil)
   37     end
   38   end
   39 
   40   Jobs.enqueue(:update_s3_inventory) if [:enable_s3_inventory, :s3_upload_bucket].include?(name)
   41 
   42   SvgSprite.expire_cache if name.to_s.include?("_icon")
   43 
   44   if SiteIconManager::WATCHED_SETTINGS.include?(name)
   45     SiteIconManager.ensure_optimized!
   46   end
   47 
   48   if SiteSetting::WATCHED_SETTINGS.include?(name)
   49     SiteSetting.reset_cached_settings!
   50   end
   51 
   52   # Make sure medium and high priority thresholds were calculated.
   53   if name == :reviewable_low_priority_threshold && Reviewable.min_score_for_priority(:medium) > 0
   54     Reviewable.set_priorities(low: new_value)
   55   end
   56 end