20220630140511_issue3829_broken_avatars.rb 746 B

123456789101112131415161718192021222324
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class Issue3829BrokenAvatars < ActiveRecord::Migration[6.1]
  3. def change
  4. # return if it's a new setup
  5. return if !Setting.exists?(name: 'system_init_done')
  6. object_name = 'User'
  7. object_id = ObjectLookup.by_name(object_name)
  8. User.all.pluck(:id, :image_source).each do |user_id, image_source|
  9. next if image_source.blank?
  10. next if image_source.match?(%r{\.(?:png|jpg|jpeg)}i)
  11. avatar = Avatar.where(
  12. object_lookup_id: object_id,
  13. o_id: user_id,
  14. ).where('source_url LIKE ?', "#{image_source}%").first
  15. next if avatar.nil?
  16. Avatar.remove_one(object_name, user_id, avatar.id)
  17. end
  18. end
  19. end