mirror of
https://github.com/discourse/discourse.git
synced 2025-02-06 11:28:18 +00:00
241e34e6cf
This URL was originally updated in 89cb537fae8a563b22d873ea8efd3009fd32b042. However, some sites are not using the proxy, and have configured their forum to hotlink images directly to avatars.discourse.org. We intend to shut down this domain in favor of `avatars.discourse-cdn.com`, so this migration will re-write any matching site setting values and queue affected posts for rebaking.
28 lines
945 B
Ruby
28 lines
945 B
Ruby
# frozen_string_literal: true
|
|
|
|
class UpdateAvatarServiceDomain < ActiveRecord::Migration[6.1]
|
|
def up
|
|
existing_value = DB.query_single("SELECT value FROM site_settings WHERE name = 'external_system_avatars_url'")&.[](0)
|
|
|
|
if existing_value&.include?("avatars.discourse.org")
|
|
new_value = DB.query_single(<<~SQL)&.[](0)
|
|
UPDATE site_settings
|
|
SET value = REPLACE(value, 'avatars.discourse.org', 'avatars.discourse-cdn.com')
|
|
WHERE name = 'external_system_avatars_url'
|
|
AND value LIKE '%avatars.discourse.org%'
|
|
RETURNING value
|
|
SQL
|
|
|
|
DB.exec <<~SQL, previous: existing_value, new: new_value
|
|
INSERT INTO user_histories
|
|
(action, subject, previous_value, new_value, admin_only, updated_at, created_at, acting_user_id)
|
|
VALUES (3, 'external_system_avatars_url', :previous, :new, true, NOW(), NOW(), -1)
|
|
SQL
|
|
end
|
|
end
|
|
|
|
def down
|
|
# Nothing to do
|
|
end
|
|
end
|