20240318132554_issue_5091_timezone_default.rb 747 B

123456789101112131415161718192021222324252627
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Issue5091TimezoneDefault < 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. set_timezone_to_utc_if_needed
  7. add_validation_preference
  8. end
  9. private
  10. def set_timezone_to_utc_if_needed
  11. current_timezone = Setting.get('timezone_default')
  12. return if Setting::Validation::TimeZone.valid_timezone_identifier?(current_timezone)
  13. Setting.set('timezone_default', 'UTC')
  14. end
  15. def add_validation_preference
  16. setting = Setting.find_by(name: 'timezone_default')
  17. setting.preferences[:validations] = ['Setting::Validation::TimeZone']
  18. setting.save!
  19. end
  20. end