A platform for community discussion. Free, open, simple.
FIX: Do not clean up uploads when they're used by theme settings (#12326)
David Taylor4430bc153d34
diff --git a/app/jobs/scheduled/clean_up_uploads.rb b/app/jobs/scheduled/clean_up_uploads.rbindex 2b735f61a58..218f50b9628 100644--- a/app/jobs/scheduled/clean_up_uploads.rb+++ b/app/jobs/scheduled/clean_up_uploads.rb@@ -63,6 +63,7 @@ module Jobsencoded_sha = Base62.encode(upload.sha1.hex)next if ReviewableQueuedPost.pending.where("payload->>'raw' LIKE '%#{upload.sha1}%' OR payload->>'raw' LIKE '%#{encoded_sha}%'").exists?next if Draft.where("data LIKE '%#{upload.sha1}%' OR data LIKE '%#{encoded_sha}%'").exists?+ next if ThemeSetting.where(data_type: ThemeSetting.types[:upload]).where("value LIKE ?", "%#{upload.sha1}%").exists?upload.destroyelseupload.deletediff --git a/spec/jobs/clean_up_uploads_spec.rb b/spec/jobs/clean_up_uploads_spec.rbindex 68a73aa1f2a..feb7d18245c 100644--- a/spec/jobs/clean_up_uploads_spec.rb+++ b/spec/jobs/clean_up_uploads_spec.rb@@ -284,4 +284,15 @@ describe Jobs::CleanUpUploads doexpect(Upload.exists?(id: expired_upload.id)).to eq(false)expect(Upload.exists?(id: csv_file.id)).to eq(true)end++ it "does not delete theme setting uploads" do+ theme = Fabricate(:theme)+ theme_upload = fabricate_upload+ ThemeSetting.create!(theme: theme, data_type: ThemeSetting.types[:upload], value: theme_upload.url, name: "my_setting_name")++ Jobs::CleanUpUploads.new.execute(nil)++ expect(Upload.exists?(id: expired_upload.id)).to eq(false)+ expect(Upload.exists?(id: theme_upload.id)).to eq(true)+ endend