20180502015927_issue_1219_zhtw_locale_typo.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. class Issue1219ZhtwLocaleTypo < ActiveRecord::Migration[5.1]
  2. CURRENT_VERSION = Gem::Version.new(Version.get)
  3. APPLICABLE_VERSION = Gem::Version.new('2.5.0')
  4. def up
  5. return if !Setting.find_by(name: 'system_init_done')
  6. return if CURRENT_VERSION < APPLICABLE_VERSION
  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. def down
  19. return if !Setting.find_by(name: 'system_init_done')
  20. return if CURRENT_VERSION >= APPLICABLE_VERSION
  21. if Locale.exists?(locale: 'zj-tw')
  22. Locale.find_by(locale: 'zh-tw')&.destroy
  23. else
  24. Locale.find_by(locale: 'zh-tw')&.update(locale: 'zj-tw')
  25. end
  26. Translation.where(locale: 'zh-tw')&.update_all(locale: 'zj-tw') # rubocop:disable Rails/SkipsModelValidations
  27. User.where('preferences LIKE ?', "%\nlocale: zh-tw\n%").each do |u|
  28. u.preferences[:locale] = 'zj-tw'
  29. u.save
  30. end
  31. end
  32. end