mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 15:25:35 +08:00
Get detailed info about new versions from the Discourse Hub. Include version notes from the latest version in notification email.
This commit is contained in:
parent
4f8aed295a
commit
df220ae973
|
@ -8,7 +8,7 @@ module Jobs
|
|||
def execute(args)
|
||||
if SiteSetting.version_checks? and (DiscourseUpdates.updated_at.nil? or DiscourseUpdates.updated_at < 1.minute.ago)
|
||||
begin
|
||||
should_send_email = (SiteSetting.new_version_emails and DiscourseUpdates.missing_versions_count and DiscourseUpdates.missing_versions_count == 0)
|
||||
prev_missing_versions_count = DiscourseUpdates.missing_versions_count || 0
|
||||
|
||||
json = DiscourseHub.discourse_version_check
|
||||
DiscourseUpdates.last_installed_version = Discourse::VERSION::STRING
|
||||
|
@ -16,8 +16,9 @@ module Jobs
|
|||
DiscourseUpdates.critical_updates_available = json['criticalUpdates']
|
||||
DiscourseUpdates.missing_versions_count = json['missingVersionsCount']
|
||||
DiscourseUpdates.updated_at = Time.zone.now
|
||||
DiscourseUpdates.missing_versions = json['versions']
|
||||
|
||||
if should_send_email and json['missingVersionsCount'] > 0
|
||||
if SiteSetting.new_version_emails and json['missingVersionsCount'] > 0 and prev_missing_versions_count < json['missingVersionsCount'].to_i
|
||||
message = VersionMailer.send_notice
|
||||
Email::Sender.new(message, :new_version).send
|
||||
end
|
||||
|
|
|
@ -5,10 +5,19 @@ class VersionMailer < ActionMailer::Base
|
|||
|
||||
def send_notice
|
||||
if SiteSetting.contact_email.present?
|
||||
missing_versions = DiscourseUpdates.missing_versions
|
||||
if missing_versions.present? and missing_versions.first['notes'].present?
|
||||
build_email( SiteSetting.contact_email,
|
||||
template: 'new_version_mailer_with_notes',
|
||||
notes: missing_versions.first['notes'],
|
||||
new_version: DiscourseUpdates.latest_version,
|
||||
installed_version: Discourse::VERSION::STRING )
|
||||
else
|
||||
build_email( SiteSetting.contact_email,
|
||||
template: 'new_version_mailer',
|
||||
new_version: DiscourseUpdates.latest_version,
|
||||
installed_version: Discourse::VERSION::STRING )
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -927,11 +927,22 @@ en:
|
|||
text_body_template: |
|
||||
A new version of Discourse is available.
|
||||
|
||||
Your version: %{installed_version}
|
||||
|
||||
**New version: %{new_version}**
|
||||
|
||||
Please upgrade as soon as possible to get the latest fixes and new features.
|
||||
|
||||
new_version_mailer_with_notes:
|
||||
subject_template: "[%{site_name}] Updates Are Available"
|
||||
text_body_template: |
|
||||
A new version of Discourse is available. Please upgrade as soon as possible to get the latest fixes and new features.
|
||||
|
||||
Your version: %{installed_version}
|
||||
|
||||
Please upgrade as soon as possible to get the latest fixes and new features.
|
||||
**New version: %{new_version}**
|
||||
|
||||
%{notes}
|
||||
|
||||
system_messages:
|
||||
post_hidden:
|
||||
|
|
|
@ -45,7 +45,8 @@ class DiscourseRedis
|
|||
# Proxy key methods through, but prefix the keys with the namespace
|
||||
[:append, :blpop, :brpop, :brpoplpush, :decr, :decrby, :del, :exists, :expire, :expireat, :get, :getbit, :getrange, :getset,
|
||||
:hdel, :hexists, :hget, :hgetall, :hincrby, :hincrbyfloat, :hkeys, :hlen, :hmget, :hmset, :hset, :hsetnx, :hvals, :incr,
|
||||
:incrby, :incrbyfloat, :lindex, :linsert, :llen, :lpop, :lpush, :lpushx, :lrange, :lrem, :lset, :ltrim, :mget, :move, :mset,
|
||||
:incrby, :incrbyfloat, :lindex, :linsert, :llen, :lpop, :lpush, :lpushx, :lrange, :lrem, :lset, :ltrim,
|
||||
:mapped_hmset, :mapped_hmget, :mapped_mget, :mapped_mset, :mapped_msetnx, :mget, :move, :mset,
|
||||
:msetnx, :persist, :pexpire, :pexpireat, :psetex, :pttl, :rename, :renamenx, :rpop, :rpoplpush, :rpush, :rpushx, :sadd, :scard,
|
||||
:sdiff, :set, :setbit, :setex, :setnx, :setrange, :sinter, :sismember, :smembers, :sort, :spop, :srandmember, :srem, :strlen,
|
||||
:sunion, :ttl, :type, :watch, :zadd, :zcard, :zcount, :zincrby, :zrange, :zrangebyscore, :zrank, :zrem, :zremrangebyrank,
|
||||
|
|
|
@ -72,6 +72,30 @@ module DiscourseUpdates
|
|||
end"
|
||||
end
|
||||
|
||||
def missing_versions=(versions)
|
||||
# delete previous list from redis
|
||||
prev_keys = $redis.lrange(missing_versions_list_key, 0, 4)
|
||||
if prev_keys
|
||||
$redis.del prev_keys
|
||||
$redis.del(missing_versions_list_key)
|
||||
end
|
||||
|
||||
# store the list in redis
|
||||
version_keys = []
|
||||
versions[0,5].each do |v|
|
||||
key = "#{missing_versions_key_prefix}:#{v['version']}"
|
||||
$redis.mapped_hmset key, v
|
||||
version_keys << key
|
||||
end
|
||||
$redis.rpush missing_versions_list_key, version_keys
|
||||
versions
|
||||
end
|
||||
|
||||
def missing_versions
|
||||
keys = $redis.lrange(missing_versions_list_key, 0, 4) # max of 5 versions
|
||||
keys.present? ? keys.map { |k| $redis.hgetall(k) } : []
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
|
@ -94,5 +118,13 @@ module DiscourseUpdates
|
|||
def updated_at_key
|
||||
'last_version_check_at'
|
||||
end
|
||||
|
||||
def missing_versions_list_key
|
||||
'missing_versions'
|
||||
end
|
||||
|
||||
def missing_versions_key_prefix
|
||||
'missing_version'
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user