FIX: Do not clean up uploads when they're used by theme settings (#12326)

We intend to move ThemeSetting to use an upload_id column, rather than storing the URL. So this is a short-term solution.
This commit is contained in:
David Taylor 2021-03-09 19:16:45 +00:00 committed by GitHub
parent e3d8e828b8
commit 4430bc153d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -63,6 +63,7 @@ module Jobs
encoded_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.destroy
else
upload.delete

View File

@ -284,4 +284,15 @@ describe Jobs::CleanUpUploads do
expect(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)
end
end