diff --git a/app/jobs/onceoff/rebake_all_html_theme_fields.rb b/app/jobs/onceoff/rebake_all_html_theme_fields.rb new file mode 100644 index 0000000000..afdce8abc1 --- /dev/null +++ b/app/jobs/onceoff/rebake_all_html_theme_fields.rb @@ -0,0 +1,11 @@ +module Jobs + class RebakeAllHtmlThemeFields < Jobs::Onceoff + def execute_onceoff(args) + ThemeField.where(type_id: ThemeField.types[:html]).find_each do |theme_field| + theme_field.update(value_baked: nil) + end + + Theme.clear_cache! + end + end +end diff --git a/app/models/javascript_cache.rb b/app/models/javascript_cache.rb index e11c40feb2..cb850af6de 100644 --- a/app/models/javascript_cache.rb +++ b/app/models/javascript_cache.rb @@ -7,7 +7,7 @@ class JavascriptCache < ActiveRecord::Base before_save :update_digest def url - "#{GlobalSetting.cdn_url}#{GlobalSetting.relative_url_root}/theme-javascripts/#{digest}.js" + "#{GlobalSetting.cdn_url}#{GlobalSetting.relative_url_root}/theme-javascripts/#{digest}.js?__ws=#{Discourse.current_hostname}" end private diff --git a/spec/jobs/rebake_all_html_theme_fields_spec.rb b/spec/jobs/rebake_all_html_theme_fields_spec.rb new file mode 100644 index 0000000000..91dd4828f7 --- /dev/null +++ b/spec/jobs/rebake_all_html_theme_fields_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +describe Jobs::RebakeAllHtmlThemeFields do + let(:theme) { Fabricate(:theme) } + let(:theme_field) { ThemeField.create!(theme: theme, target_id: 0, name: "header", value: "") } + + it 'extracts inline javascripts' do + theme_field.update_attributes(value_baked: 'need to be rebaked') + + described_class.new.execute_onceoff({}) + + theme_field.reload + expect(theme_field.value_baked).to include('theme-javascripts') + end +end diff --git a/spec/models/javascript_cache_spec.rb b/spec/models/javascript_cache_spec.rb index 1599fbe92e..28b06a2ea8 100644 --- a/spec/models/javascript_cache_spec.rb +++ b/spec/models/javascript_cache_spec.rb @@ -29,4 +29,11 @@ RSpec.describe JavascriptCache, type: :model do expect(javascript_cache.errors.details[:content]).to include(error: :empty) end end + + describe 'url' do + it 'works with multisite' do + javascript_cache = JavascriptCache.create!(content: 'console.log("hello");', theme_field: theme_field) + expect(javascript_cache.url).to include("?__ws=test.localhost") + end + end end