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:
parent
e3d8e828b8
commit
4430bc153d
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue