2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2018-05-02 02:15:16 +00:00
|
|
|
class Issue1219ZhtwLocaleTypo < ActiveRecord::Migration[5.1]
|
|
|
|
CURRENT_VERSION = Gem::Version.new(Version.get)
|
|
|
|
APPLICABLE_VERSION = Gem::Version.new('2.5.0')
|
|
|
|
|
|
|
|
def up
|
2020-08-03 08:35:43 +00:00
|
|
|
return if !Setting.exists?(name: 'system_init_done')
|
2018-05-04 14:05:10 +00:00
|
|
|
return if CURRENT_VERSION < APPLICABLE_VERSION
|
2018-05-02 02:15:16 +00:00
|
|
|
|
|
|
|
if Locale.exists?(locale: 'zh-tw')
|
|
|
|
Locale.find_by(locale: 'zj-tw')&.destroy
|
|
|
|
else
|
|
|
|
Locale.find_by(locale: 'zj-tw')&.update(locale: 'zh-tw')
|
|
|
|
end
|
|
|
|
|
2019-02-11 13:52:50 +00:00
|
|
|
Translation.where(locale: 'zj-tw')&.update_all(locale: 'zh-tw') # rubocop:disable Rails/SkipsModelValidations
|
2018-05-02 02:15:16 +00:00
|
|
|
User.where('preferences LIKE ?', "%\nlocale: zj-tw\n%").each do |u|
|
|
|
|
u.preferences[:locale] = 'zh-tw'
|
|
|
|
u.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
2020-08-03 08:35:43 +00:00
|
|
|
return if !Setting.exists?(name: 'system_init_done')
|
2018-05-04 14:05:10 +00:00
|
|
|
return if CURRENT_VERSION >= APPLICABLE_VERSION
|
2018-05-02 02:15:16 +00:00
|
|
|
|
|
|
|
if Locale.exists?(locale: 'zj-tw')
|
|
|
|
Locale.find_by(locale: 'zh-tw')&.destroy
|
|
|
|
else
|
|
|
|
Locale.find_by(locale: 'zh-tw')&.update(locale: 'zj-tw')
|
|
|
|
end
|
|
|
|
|
2019-02-11 13:52:50 +00:00
|
|
|
Translation.where(locale: 'zh-tw')&.update_all(locale: 'zj-tw') # rubocop:disable Rails/SkipsModelValidations
|
2018-05-02 02:15:16 +00:00
|
|
|
User.where('preferences LIKE ?', "%\nlocale: zh-tw\n%").each do |u|
|
|
|
|
u.preferences[:locale] = 'zj-tw'
|
|
|
|
u.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|