2013-02-20 04:16:50 +08:00
|
|
|
module DiscourseUpdates
|
|
|
|
|
|
|
|
class << self
|
|
|
|
|
|
|
|
def check_version
|
2013-07-03 23:06:07 +08:00
|
|
|
version_info = if updated_at.nil?
|
|
|
|
DiscourseVersionCheck.new(
|
|
|
|
installed_version: Discourse::VERSION::STRING,
|
|
|
|
installed_sha: (Discourse.git_version == 'unknown' ? nil : Discourse.git_version),
|
|
|
|
updated_at: nil
|
|
|
|
)
|
|
|
|
else
|
|
|
|
DiscourseVersionCheck.new(
|
|
|
|
latest_version: latest_version,
|
|
|
|
critical_updates: critical_updates_available?,
|
|
|
|
installed_version: Discourse::VERSION::STRING,
|
|
|
|
installed_sha: (Discourse.git_version == 'unknown' ? nil : Discourse.git_version),
|
|
|
|
missing_versions_count: missing_versions_count,
|
|
|
|
updated_at: updated_at
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
if version_info.updated_at.nil? or
|
|
|
|
(version_info.missing_versions_count == 0 and version_info.latest_version != version_info.installed_version)
|
|
|
|
# Version check data is out of date.
|
|
|
|
Jobs.enqueue(:version_check, all_sites: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
version_info
|
2013-02-20 04:16:50 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def latest_version
|
|
|
|
$redis.get latest_version_key
|
|
|
|
end
|
|
|
|
|
2013-03-06 07:14:51 +08:00
|
|
|
def missing_versions_count
|
|
|
|
$redis.get(missing_versions_count_key).try(:to_i)
|
2013-02-20 04:16:50 +08:00
|
|
|
end
|
|
|
|
|
2013-03-06 23:34:15 +08:00
|
|
|
def critical_updates_available?
|
2013-02-20 04:16:50 +08:00
|
|
|
($redis.get(critical_updates_available_key) || false) == 'true'
|
|
|
|
end
|
|
|
|
|
2013-07-03 23:06:07 +08:00
|
|
|
def updated_at
|
|
|
|
t = $redis.get(updated_at_key)
|
|
|
|
t ? Time.zone.parse(t) : nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def updated_at=(time_with_zone)
|
|
|
|
$redis.set updated_at_key, time_with_zone.as_json
|
|
|
|
end
|
|
|
|
|
2013-03-06 23:34:15 +08:00
|
|
|
['latest_version', 'missing_versions_count', 'critical_updates_available'].each do |name|
|
2013-03-06 07:14:51 +08:00
|
|
|
eval "define_method :#{name}= do |arg|
|
|
|
|
$redis.set #{name}_key, arg
|
|
|
|
end"
|
|
|
|
end
|
|
|
|
|
2013-02-20 04:16:50 +08:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def latest_version_key
|
|
|
|
'discourse_latest_version'
|
|
|
|
end
|
|
|
|
|
|
|
|
def critical_updates_available_key
|
|
|
|
'critical_updates_available'
|
|
|
|
end
|
2013-03-06 07:14:51 +08:00
|
|
|
|
|
|
|
def missing_versions_count_key
|
|
|
|
'missing_versions_count'
|
|
|
|
end
|
2013-07-03 23:06:07 +08:00
|
|
|
|
|
|
|
def updated_at_key
|
|
|
|
'last_version_check_at'
|
|
|
|
end
|
2013-02-20 04:16:50 +08:00
|
|
|
end
|
|
|
|
end
|