diff --git a/app/jobs/scheduled/version_check.rb b/app/jobs/scheduled/version_check.rb index a50e7c2fef3..d760f7cef5d 100644 --- a/app/jobs/scheduled/version_check.rb +++ b/app/jobs/scheduled/version_check.rb @@ -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 diff --git a/app/mailers/version_mailer.rb b/app/mailers/version_mailer.rb index 42019f0ad07..b39136933c6 100644 --- a/app/mailers/version_mailer.rb +++ b/app/mailers/version_mailer.rb @@ -5,10 +5,19 @@ class VersionMailer < ActionMailer::Base def send_notice if SiteSetting.contact_email.present? - build_email( SiteSetting.contact_email, - template: 'new_version_mailer', - new_version: DiscourseUpdates.latest_version, - installed_version: Discourse::VERSION::STRING ) + 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 diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 85c1f5b2304..d4372debbb5 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -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: diff --git a/lib/discourse_redis.rb b/lib/discourse_redis.rb index 78d5ba1871c..eae89cf5415 100644 --- a/lib/discourse_redis.rb +++ b/lib/discourse_redis.rb @@ -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, diff --git a/lib/discourse_updates.rb b/lib/discourse_updates.rb index 250e2f8975d..725ed6c8723 100644 --- a/lib/discourse_updates.rb +++ b/lib/discourse_updates.rb @@ -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 \ No newline at end of file