20220308072741_rename_tw_locale.rb 736 B

123456789101112131415161718192021
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class RenameTwLocale < ActiveRecord::Migration[6.0]
  3. # Copied from db/migrate/20180502015927_issue_1219_zhtw_locale_typo.rb as this
  4. # needed to be re-executed.
  5. def change
  6. return if !Setting.exists?(name: 'system_init_done')
  7. if Locale.exists?(locale: 'zh-tw')
  8. Locale.find_by(locale: 'zj-tw')&.destroy
  9. else
  10. Locale.find_by(locale: 'zj-tw')&.update(locale: 'zh-tw')
  11. end
  12. Translation.where(locale: 'zj-tw')&.update_all(locale: 'zh-tw') # rubocop:disable Rails/SkipsModelValidations
  13. User.where('preferences LIKE ?', "%\nlocale: zj-tw\n%").each do |u|
  14. u.preferences[:locale] = 'zh-tw'
  15. u.save
  16. end
  17. end
  18. end