app_version.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # Copyright (C) 2012-2022 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. =begin
  13. set new app version and if browser reload is required
  14. AppVersion.set(true) # true == reload is required / false == no reload is required
  15. send also reload type to clients
  16. AppVersion.set(true, 'app_version')
  17. AppVersion.set(true, 'restart_manual')
  18. AppVersion.set(true, 'restart_auto')
  19. AppVersion.set(true, 'config_changed')
  20. =end
  21. def self.set(reload_required = false, type = 'app_version')
  22. return false if !Setting.exists?(name: 'app_version')
  23. version = "#{Time.zone.now.strftime('%Y%m%d%H%M%S')}:#{reload_required}"
  24. Setting.set('app_version', version)
  25. # broadcast to clients
  26. Sessions.broadcast(event_data(type), 'public')
  27. end
  28. =begin
  29. get event data
  30. AppVersion.event_data(type)
  31. types:
  32. app_version -> new app version
  33. restart_manual -> app needs restart
  34. restart_auto -> app is restarting
  35. config_changed -> config has changed
  36. returns
  37. {
  38. event: 'maintenance'
  39. data: {
  40. type: 'app_version',
  41. app_version: app_version,
  42. }
  43. }
  44. =end
  45. def self.event_data(type = 'app_version')
  46. {
  47. event: 'maintenance',
  48. data: {
  49. type: type,
  50. app_version: get,
  51. }
  52. }
  53. end
  54. end