2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-02-19 14:16:50 -06:00
|
|
|
module Jobs
|
2019-10-01 23:01:53 -05:00
|
|
|
class VersionCheck < ::Jobs::Scheduled
|
2014-02-05 17:14:41 -06:00
|
|
|
every 1.day
|
2013-02-19 14:16:50 -06:00
|
|
|
|
|
|
|
def execute(args)
|
2023-01-09 06:20:10 -06:00
|
|
|
if SiteSetting.version_checks? &&
|
|
|
|
(DiscourseUpdates.updated_at.nil? || DiscourseUpdates.updated_at < (1.minute.ago))
|
2013-03-25 10:35:33 -05:00
|
|
|
begin
|
2013-12-31 14:52:16 -06:00
|
|
|
prev_missing_versions_count = DiscourseUpdates.missing_versions_count || 0
|
2013-08-16 16:28:36 -05:00
|
|
|
|
2013-03-25 10:35:33 -05:00
|
|
|
json = DiscourseHub.discourse_version_check
|
2013-11-04 11:51:01 -06:00
|
|
|
DiscourseUpdates.last_installed_version = Discourse::VERSION::STRING
|
2023-01-09 06:20:10 -06:00
|
|
|
DiscourseUpdates.latest_version = json["latestVersion"]
|
|
|
|
DiscourseUpdates.critical_updates_available = json["criticalUpdates"]
|
|
|
|
DiscourseUpdates.missing_versions_count = json["missingVersionsCount"]
|
2013-07-03 10:06:07 -05:00
|
|
|
DiscourseUpdates.updated_at = Time.zone.now
|
2023-01-09 06:20:10 -06:00
|
|
|
DiscourseUpdates.missing_versions = json["versions"]
|
2014-08-22 19:02:14 -05:00
|
|
|
|
2023-01-09 06:20:10 -06:00
|
|
|
if SiteSetting.new_version_emails && json["missingVersionsCount"] > (0) &&
|
|
|
|
prev_missing_versions_count < (json["missingVersionsCount"].to_i)
|
2013-08-16 16:28:36 -05:00
|
|
|
message = VersionMailer.send_notice
|
|
|
|
Email::Sender.new(message, :new_version).send
|
|
|
|
end
|
2013-03-25 10:35:33 -05:00
|
|
|
rescue => e
|
2014-08-18 01:42:48 -05:00
|
|
|
raise e unless Rails.env.development? # Fail version check silently in development mode
|
2013-03-25 10:35:33 -05:00
|
|
|
end
|
2013-02-21 09:19:02 -06:00
|
|
|
end
|
2013-02-19 14:16:50 -06:00
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
2014-02-05 17:14:41 -06:00
|
|
|
end
|