FEATURE: Remove deprecated uploads url site settings.

FEATURE: Remove deprecated uploads url site settings.

The site settings have been replaced with direct image upload since Discourse 2.3.

diff --git a/app/jobs/onceoff/migrate_url_site_settings.rb b/app/jobs/onceoff/migrate_url_site_settings.rb
deleted file mode 100644
index 7f0bb37..0000000
--- a/app/jobs/onceoff/migrate_url_site_settings.rb
+++ /dev/null
@@ -1,92 +0,0 @@
-# frozen_string_literal: true
-
-module Jobs
-  class MigrateUrlSiteSettings < ::Jobs::Onceoff
-    SETTINGS = [
-      ['logo_url', 'logo'],
-      ['logo_small_url', 'logo_small'],
-      ['digest_logo_url', 'digest_logo'],
-      ['mobile_logo_url', 'mobile_logo'],
-      ['large_icon_url', 'large_icon'],
-      ['favicon_url', 'favicon'],
-      ['apple_touch_icon_url', 'apple_touch_icon'],
-      ['default_opengraph_image_url', 'opengraph_image'],
-      ['twitter_summary_large_image_url', 'twitter_summary_large_image'],
-      ['push_notifications_icon_url', 'push_notifications_icon'],
-    ]
-
-    def execute_onceoff(args)
-      SETTINGS.each do |old_setting, new_setting|
-        upload = SiteSetting.get(new_setting)
-
-        next if upload && upload.id >= Upload::SEEDED_ID_THRESHOLD
-
-        old_url = DB.query_single(
-          "SELECT value FROM site_settings WHERE name = '#{old_setting}'"
-        ).first
-
-        next if old_url.blank?
-
-        count = 0
-        file = nil
-        sleep_interval = 5
-
-        loop do
-          url = UrlHelper.absolute_without_cdn(old_url)
-
-          begin
-            file = FileHelper.download(
-              url,
-              max_file_size: [
-                SiteSetting.max_image_size_kb.kilobytes,
-                20.megabytes
-              ].max,
-              tmp_file_name: 'tmp_site_setting_logo',
-              skip_rate_limit: true,
-              follow_redirect: true
-            )
-          rescue OpenURI::HTTPError,
-                 OpenSSL::SSL::SSLError,
-                 Net::OpenTimeout,
-                 Net::ReadTimeout,
-                 Errno::ECONNREFUSED,
-                 EOFError,
-                 SocketError,
-                 Discourse::InvalidParameters => e
-
-            logger.warn(
-              "Error encountered when trying to download file " +
-              "for #{new_setting}.\n#{e.class}: #{e.message}\n#{e.backtrace.join("\n")}"
-            )
-          end
-
-          count += 1
-          break if file || (file.blank? && count >= 3)
-
-          logger.info(
-            "Failed to download upload from #{url} for #{new_setting}. Retrying..."
-          )
-
-          sleep(count * sleep_interval)
-        end
-
-        next if file.blank?
-
-        upload = UploadCreator.new(
-          file,
-          "#{new_setting}",
-          origin: UrlHelper.absolute(old_url),
-          for_site_setting: true
-        ).create_for(Discourse.system_user.id)
-
-        SiteSetting.set(new_setting, upload)
-      end
-    end
-
-    private
-
-    def logger
-      Rails.logger
-    end
-  end
-end
diff --git a/app/jobs/scheduled/clean_up_deprecated_url_site_settings.rb b/app/jobs/scheduled/clean_up_deprecated_url_site_settings.rb
deleted file mode 100644
index 12d947e..0000000
--- a/app/jobs/scheduled/clean_up_deprecated_url_site_settings.rb
+++ /dev/null
@@ -1,16 +0,0 @@
-# frozen_string_literal: true
-
-module Jobs
-  class CleanUpDeprecatedUrlSiteSettings < ::Jobs::Scheduled
-    every 1.day
-
-    def execute(args)
-      ::Jobs::MigrateUrlSiteSettings::SETTINGS.each do |old_setting, new_setting|
-        if SiteSetting.where("name = ? AND value IS NOT NULL", new_setting).exists?
-          SiteSetting.set(old_setting, nil, warn: false)
-          SiteSetting.find_by(name: old_setting).destroy!
-        end
-      end
-    end
-  end
-end
diff --git a/app/jobs/scheduled/clean_up_uploads.rb b/app/jobs/scheduled/clean_up_uploads.rb
index 95f528c..75e91a8 100644
--- a/app/jobs/scheduled/clean_up_uploads.rb
+++ b/app/jobs/scheduled/clean_up_uploads.rb
@@ -27,15 +27,6 @@ module Jobs
 
       # Any URLs in site settings are fair game
       ignore_urls = [
-        SiteSetting.logo_url(warn: false),
-        SiteSetting.logo_small_url(warn: false),
-        SiteSetting.digest_logo_url(warn: false),
-        SiteSetting.mobile_logo_url(warn: false),
-        SiteSetting.large_icon_url(warn: false),
-        SiteSetting.favicon_url(warn: false),
-        SiteSetting.default_opengraph_image_url(warn: false),
-        SiteSetting.twitter_summary_large_image_url(warn: false),
-        SiteSetting.apple_touch_icon_url(warn: false),
         *SiteSetting.selectable_avatars.split("\n"),
       ].flatten.map do |url|
         if url.present?
diff --git a/config/site_settings.yml b/config/site_settings.yml
index 502d71c..06549cd 100644
--- a/config/site_settings.yml
+++ b/config/site_settings.yml
@@ -62,30 +62,18 @@ branding:
     default: -5
     client: true
     type: upload
-  logo_url:
-    hidden: true
-    default: "/images/d-logo-sketch.png"
   logo_small:
     default: -6
     client: true
     type: upload
-  logo_small_url:
-    hidden: true
-    default: "/images/d-logo-sketch-small.png"
   digest_logo:
     default: ""
     client: true
     type: upload
-  digest_logo_url:
-    hidden: true
-    default: ""
   mobile_logo:
     default: ""
     client: true
     type: upload
-  mobile_logo_url:
-    hidden: true
-    default: ""
   large_icon:
     default: ""
     client: true
@@ -93,35 +81,20 @@ branding:
   manifest_icon:
     default: ""
     type: upload
-  large_icon_url:
-    hidden: true
-    default: ""
   favicon:
     default: ""
     client: true
     type: upload
-  favicon_url:
-    hidden: true
-    default: "/images/default-favicon.ico"
   apple_touch_icon:
     default: ""
     client: true
     type: upload
-  apple_touch_icon_url:
-    hidden: true
-    default: "/images/default-apple-touch-icon.png"
   opengraph_image:
     default: ""
     type: upload
-  default_opengraph_image_url:
-    hidden: true
-    default: ""
   twitter_summary_large_image:
     default: ""
     type: upload
-  twitter_summary_large_image_url:
-    hidden: true
-    default: ""
 
 basic:
   display_local_time_in_user_card:
@@ -300,9 +273,6 @@ basic:
   push_notifications_icon:
     default: ""
     type: upload
-  push_notifications_icon_url:
-    hidden: true
-    default: ""
   short_title:
     default: ""
     max: 12
diff --git a/db/migrate/20190315025804_migrate_blank_override_for_upload_site_settings.rb b/db/migrate/20190315025804_migrate_blank_override_for_upload_site_settings.rb
deleted file mode 100644
index 1e5a3c5..0000000
--- a/db/migrate/20190315025804_migrate_blank_override_for_upload_site_settings.rb
+++ /dev/null
@@ -1,42 +0,0 @@
-# frozen_string_literal: true
-
-class MigrateBlankOverrideForUploadSiteSettings < ActiveRecord::Migration[5.2]
-  def up
-    {
-      'logo_url' => 'logo',
-      'logo_small_url' => 'logo_small',
-      'digest_logo_url' => 'digest_logo',
-      'mobile_logo_url' => 'mobile_logo',
-      'large_icon_url' => 'large_icon',
-      'favicon_url' => 'favicon',
-      'apple_touch_icon_url' => 'apple_touch_icon',
-      'default_opengraph_image_url' => 'opengraph_image',
-      'twitter_summary_large_image_url' => 'twitter_summary_large_image',
-      'push_notifications_icon_url' => 'push_notifications_icon'
-    }.each do |old_name, new_name|
-      if DB.query_single("SELECT 1 FROM site_settings WHERE name = '#{old_name}' AND value = ''").present? &&
-         DB.query_single("SELECT 1 FROM site_settings WHERE name = '#{new_name}'").empty?
-
-        ActiveRecord::Base.connection.execute <<~SQL
-        INSERT INTO site_settings (
-          name,
-          data_type,
-          value,
-          created_at,
-          updated_at
-        ) VALUES (
-          '#{new_name}',
-          18,
-          '',
-          CURRENT_TIMESTAMP,
-          CURRENT_TIMESTAMP
-        )
-        SQL
-      end
-    end
-  end
-
-  def down
-    raise ActiveRecord::IrreversibleMigration
-  end
-end

[... diff too long, it was truncated ...]

GitHub sha: 3370ef18

1 Like

This commit appears in #10102 which was merged by tgxworld.