2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
2016-02-12 14:07:15 +00:00
|
|
|
|
|
|
|
class AppVersion
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
get current app version
|
|
|
|
|
|
|
|
version = AppVersion.get
|
|
|
|
|
|
|
|
returns
|
|
|
|
|
|
|
|
'20150212131700:0' # 'version:if_browser_reload_is_required'
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
|
|
|
def self.get
|
|
|
|
Setting.get('app_version')
|
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
set new app version and if browser reload is required
|
|
|
|
|
|
|
|
AppVersion.set(true) # true == reload is required / false == no reload is required
|
|
|
|
|
2016-05-26 21:40:10 +00:00
|
|
|
send also reload type to clients
|
|
|
|
|
2016-06-10 11:05:22 +00:00
|
|
|
AppVersion.set(true, 'app_version')
|
|
|
|
AppVersion.set(true, 'restart_manual')
|
2016-05-26 21:40:10 +00:00
|
|
|
AppVersion.set(true, 'restart_auto')
|
2016-06-10 11:05:22 +00:00
|
|
|
AppVersion.set(true, 'config_changed')
|
2016-05-26 21:40:10 +00:00
|
|
|
|
2016-02-12 14:07:15 +00:00
|
|
|
=end
|
|
|
|
|
2016-06-10 11:05:22 +00:00
|
|
|
def self.set(reload_required = false, type = 'app_version')
|
2020-08-03 08:35:43 +00:00
|
|
|
return false if !Setting.exists?(name: 'app_version')
|
2018-10-09 06:17:41 +00:00
|
|
|
|
2016-02-12 14:07:15 +00:00
|
|
|
version = "#{Time.zone.now.strftime('%Y%m%d%H%M%S')}:#{reload_required}"
|
|
|
|
Setting.set('app_version', version)
|
|
|
|
|
|
|
|
# broadcast to clients
|
2016-05-26 21:40:10 +00:00
|
|
|
Sessions.broadcast(event_data(type), 'public')
|
2016-02-12 14:07:15 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
=begin
|
|
|
|
|
|
|
|
get event data
|
|
|
|
|
2016-05-26 21:40:10 +00:00
|
|
|
AppVersion.event_data(type)
|
|
|
|
|
|
|
|
types:
|
|
|
|
|
|
|
|
app_version -> new app version
|
|
|
|
restart_manual -> app needs restart
|
|
|
|
restart_auto -> app is restarting
|
|
|
|
config_changed -> config has changed
|
2016-02-12 14:07:15 +00:00
|
|
|
|
2016-12-13 13:58:13 +00:00
|
|
|
returns
|
2016-02-12 14:07:15 +00:00
|
|
|
|
|
|
|
{
|
2016-05-25 07:19:45 +00:00
|
|
|
event: 'maintenance'
|
2016-02-12 14:07:15 +00:00
|
|
|
data: {
|
2016-05-25 07:19:45 +00:00
|
|
|
type: 'app_version',
|
2016-02-12 14:07:15 +00:00
|
|
|
app_version: app_version,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
2016-05-26 21:40:10 +00:00
|
|
|
def self.event_data(type = 'app_version')
|
2016-02-12 14:07:15 +00:00
|
|
|
{
|
2016-05-25 07:19:45 +00:00
|
|
|
event: 'maintenance',
|
2018-12-19 17:31:51 +00:00
|
|
|
data: {
|
|
|
|
type: type,
|
2016-02-12 14:07:15 +00:00
|
|
|
app_version: get,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|