app_version.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class AppVersion
  3. =begin
  4. get current app version
  5. version = AppVersion.get
  6. returns
  7. '20150212131700:0' # 'version:if_browser_reload_is_required'
  8. =end
  9. def self.get
  10. Setting.get('app_version')
  11. end
  12. MSG_APP_VERSION = 'app_version'.freeze
  13. MSG_RESTART_MANUAL = 'restart_manual'.freeze
  14. MSG_RESTART_AUTO = 'restart_auto'.freeze
  15. MSG_CONFIG_CHANGED = 'config_changed'.freeze
  16. =begin
  17. set new app version and if browser reload is required
  18. AppVersion.set(true) # true == reload is required / false == no reload is required
  19. send also reload type to clients
  20. AppVersion.set(true, AppVersion::MSG_APP_VERSION) # -> new app version
  21. AppVersion.set(true, AppVersion::MSG_RESTART_MANUAL) # -> app needs restart
  22. AppVersion.set(true, AppVersion::MSG_RESTART_AUTO) # -> app is restarting
  23. AppVersion.set(true, AppVersion::MSG_CONFIG_CHANGED) # -> config has changed
  24. =end
  25. def self.set(reload_required = false, type = MSG_APP_VERSION)
  26. return false if !Setting.exists?(name: 'app_version')
  27. version = "#{Time.zone.now.strftime('%Y%m%d%H%M%S')}:#{reload_required}"
  28. Setting.set('app_version', version)
  29. # broadcast to clients
  30. Sessions.broadcast(event_data(type), 'public')
  31. Gql::Subscriptions::AppMaintenance.trigger({ type: type })
  32. end
  33. def self.event_data(type = 'app_version')
  34. {
  35. event: 'maintenance',
  36. data: {
  37. type: type,
  38. app_version: get,
  39. }
  40. }
  41. end
  42. end