20240612071836_cleanup_obsolete_translations.rb 949 B

123456789101112131415161718
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class CleanupObsoleteTranslations < ActiveRecord::Migration[7.0]
  3. def change
  4. # return if it's a new setup
  5. return if !Setting.exists?(name: 'system_init_done')
  6. # https://github.com/zammad/zammad/issues/5189
  7. # When the Weblate toolchain was introduced to Zammad, old Translation records were
  8. # not automatically cleaned up, causing lots of customized translations to be
  9. # shown in the translation management screen, even though they came from the codebase.
  10. # This method locates and deletes all Translations which are present in many languages
  11. # and not changed by the user.
  12. old_scope = 'target_initial = target AND is_synchronized_from_codebase = false'
  13. sources = Translation.where(old_scope).having('COUNT(*) >= 20').group(:source).pluck(:source)
  14. Translation.where(old_scope).where(source: sources).delete_all
  15. end
  16. end