mirror of
https://github.com/discourse/discourse.git
synced 2025-02-07 03:48:23 +00:00
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.
31 lines
772 B
Ruby
31 lines
772 B
Ruby
# frozen_string_literal: true
|
|
|
|
class RebakeOldAvatarServiceUrls < ActiveRecord::Migration[6.1]
|
|
def up
|
|
# Only need to run this migration if 20220302163246
|
|
# changed the site setting. We can determine that
|
|
# by checking for a user_histories entry in the last
|
|
# month
|
|
|
|
recently_changed = DB.query_single(<<~SQL).[](0)
|
|
SELECT 1
|
|
FROM user_histories
|
|
WHERE action = 3
|
|
AND subject = 'external_system_avatars_url'
|
|
AND previous_value LIKE '%avatars.discourse.org%'
|
|
AND created_at > NOW() - INTERVAL '1 month'
|
|
SQL
|
|
|
|
if recently_changed
|
|
execute <<~SQL
|
|
UPDATE posts SET baked_version = 0
|
|
WHERE cooked LIKE '%avatars.discourse.org%'
|
|
SQL
|
|
end
|
|
end
|
|
|
|
def down
|
|
# Nothing to do
|
|
end
|
|
end
|