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