20180502015927_issue_1219_zhtw_locale_typo.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
  2. class Issue1219ZhtwLocaleTypo < ActiveRecord::Migration[5.1]
  3. CURRENT_VERSION = Gem::Version.new(Version.get)
  4. APPLICABLE_VERSION = Gem::Version.new('2.5.0')
  5. def up
  6. return if !Setting.exists?(name: 'system_init_done')
  7. return if CURRENT_VERSION < APPLICABLE_VERSION
  8. if Locale.exists?(locale: 'zh-tw')
  9. Locale.find_by(locale: 'zj-tw')&.destroy
  10. else
  11. Locale.find_by(locale: 'zj-tw')&.update(locale: 'zh-tw')
  12. end
  13. Translation.where(locale: 'zj-tw')&.update_all(locale: 'zh-tw') # rubocop:disable Rails/SkipsModelValidations
  14. User.where('preferences LIKE ?', "%\nlocale: zj-tw\n%").each do |u|
  15. u.preferences[:locale] = 'zh-tw'
  16. u.save
  17. end
  18. end
  19. def down
  20. return if !Setting.exists?(name: 'system_init_done')
  21. return if CURRENT_VERSION >= APPLICABLE_VERSION
  22. if Locale.exists?(locale: 'zj-tw')
  23. Locale.find_by(locale: 'zh-tw')&.destroy
  24. else
  25. Locale.find_by(locale: 'zh-tw')&.update(locale: 'zj-tw')
  26. end
  27. Translation.where(locale: 'zh-tw')&.update_all(locale: 'zj-tw') # rubocop:disable Rails/SkipsModelValidations
  28. User.where('preferences LIKE ?', "%\nlocale: zh-tw\n%").each do |u|
  29. u.preferences[:locale] = 'zj-tw'
  30. u.save
  31. end
  32. end
  33. end