diff --git a/app/jobs/scheduled/check_out_of_date_themes.rb b/app/jobs/scheduled/check_out_of_date_themes.rb
new file mode 100644
index 00000000000..8bd992f6e89
--- /dev/null
+++ b/app/jobs/scheduled/check_out_of_date_themes.rb
@@ -0,0 +1,16 @@
+module Jobs
+ class CheckOutOfDateThemes < Jobs::Scheduled
+ every 1.day
+
+ def execute(args)
+ target_themes = RemoteTheme
+ .joins("JOIN themes ON themes.remote_theme_id = remote_themes.id")
+ .where.not(remote_url: "")
+
+ target_themes.each do |remote|
+ remote.update_remote_version
+ remote.save!
+ end
+ end
+ end
+end
diff --git a/app/models/admin_dashboard_data.rb b/app/models/admin_dashboard_data.rb
index b64e82dfaca..fffdd0e0360 100644
--- a/app/models/admin_dashboard_data.rb
+++ b/app/models/admin_dashboard_data.rb
@@ -101,7 +101,8 @@ class AdminDashboardData
:github_config_check, :s3_config_check, :image_magick_check,
:failing_emails_check,
:subfolder_ends_in_slash_check,
- :pop3_polling_configuration, :email_polling_errored_recently
+ :pop3_polling_configuration, :email_polling_errored_recently,
+ :out_of_date_themes
add_problem_check do
sidekiq_check || queue_size_check
@@ -247,4 +248,16 @@ class AdminDashboardData
I18n.t('dashboard.force_https_warning') unless SiteSetting.force_https
end
+ def out_of_date_themes
+ old_themes = RemoteTheme.out_of_date_themes
+ return unless old_themes.present?
+
+ html = old_themes.map do |name, id|
+ "
#{CGI.escapeHTML(name)}"
+ end.join("\n")
+
+ message = I18n.t("dashboard.out_of_date_themes")
+ message += ""
+ message
+ end
end
diff --git a/app/models/remote_theme.rb b/app/models/remote_theme.rb
index f817a090a7a..578711a4c59 100644
--- a/app/models/remote_theme.rb
+++ b/app/models/remote_theme.rb
@@ -56,11 +56,18 @@ class RemoteTheme < ActiveRecord::Base
end
end
+ def self.out_of_date_themes
+ self.joins("JOIN themes ON themes.remote_theme_id = remote_themes.id")
+ .where.not(remote_url: "")
+ .where("commits_behind > 0 OR remote_version <> local_version")
+ .pluck("themes.name", "themes.id")
+ end
+
def update_remote_version
importer = ThemeStore::GitImporter.new(remote_url, private_key: private_key)
importer.import!
self.updated_at = Time.zone.now
- self.remote_version, self.commits_behind = importer.commits_since(remote_version)
+ self.remote_version, self.commits_behind = importer.commits_since(local_version)
end
def update_from_remote(importer = nil, skip_update: false)
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index ecd2ec798cd..cc10f8c9cb8 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -1097,6 +1097,7 @@ en:
poll_pop3_timeout: "Connection to the POP3 server is timing out. Incoming email could not be retrieved. Please check your POP3 settings and service provider."
poll_pop3_auth_error: "Connection to the POP3 server is failing with an authentication error. Please check your POP3 settings."
force_https_warning: "Your website is using SSL. But `force_https` is not yet enabled in your site settings."
+ out_of_date_themes: "Updates are available for the following themes:"
site_settings:
censored_words: "Words that will be automatically replaced with ■■■■"
diff --git a/spec/models/admin_dashboard_data_spec.rb b/spec/models/admin_dashboard_data_spec.rb
index f65de862fd1..1a96b1fe9e1 100644
--- a/spec/models/admin_dashboard_data_spec.rb
+++ b/spec/models/admin_dashboard_data_spec.rb
@@ -336,4 +336,19 @@ describe AdminDashboardData do
end
end
+ describe '#out_of_date_themes' do
+ let(:remote) { RemoteTheme.create!(remote_url: "https://github.com/org/testtheme") }
+ let!(:theme) { Theme.create!(remote_theme_id: remote.id, name: "Test< Theme", user_id: -1) }
+
+ it "outputs correctly formatted html" do
+ remote.update!(local_version: "old version", remote_version: "new version", commits_behind: 2)
+ dashboard_data = described_class.new
+ expect(dashboard_data.out_of_date_themes).to eq(
+ I18n.t("dashboard.out_of_date_themes") + ""
+ )
+
+ remote.update!(local_version: "new version", commits_behind: 0)
+ expect(dashboard_data.out_of_date_themes).to eq(nil)
+ end
+ end
end
diff --git a/spec/models/remote_theme_spec.rb b/spec/models/remote_theme_spec.rb
index 31f772b94ec..202e170b0a3 100644
--- a/spec/models/remote_theme_spec.rb
+++ b/spec/models/remote_theme_spec.rb
@@ -151,4 +151,17 @@ describe RemoteTheme do
expect(scheme_count).to eq(1)
end
end
+
+ context ".out_of_date_themes" do
+ let(:remote) { RemoteTheme.create!(remote_url: "https://github.com/org/testtheme") }
+ let!(:theme) { Theme.create!(remote_theme_id: remote.id, name: "Test Theme", user_id: -1) }
+
+ it "finds out of date themes" do
+ remote.update!(local_version: "old version", remote_version: "new version", commits_behind: 2)
+ expect(described_class.out_of_date_themes).to eq([[theme.name, theme.id]])
+
+ remote.update!(local_version: "new version", commits_behind: 0)
+ expect(described_class.out_of_date_themes).to eq([])
+ end
+ end
end