FIX: `Jobs::CleanUpUploads` fails when value of upload data_type is an empty string.

This commit is contained in:
Guo Xiang Tan 2018-11-30 10:46:39 +08:00
parent 3c22fb6b70
commit eecd1a7d8c
2 changed files with 7 additions and 1 deletions

View File

@ -48,7 +48,7 @@ module Jobs
.where("uploads.created_at < ?", grace_period.hour.ago)
.joins(<<~SQL)
LEFT JOIN site_settings ss
ON ss.value::integer = uploads.id
ON NULLIF(ss.value, '')::integer = uploads.id
AND ss.data_type = #{SiteSettings::TypeSupervisor.types[:upload].to_i}
SQL
.joins("LEFT JOIN post_uploads pu ON pu.upload_id = uploads.id")

View File

@ -48,6 +48,7 @@ describe Jobs::CleanUpUploads do
begin
original_provider = SiteSetting.provider
SiteSetting.provider = SiteSettings::DbProvider.new(SiteSetting)
SiteSetting.clean_orphan_uploads_grace_period_hours = 1
logo_upload = fabricate_upload
logo_small_upload = fabricate_upload
@ -85,6 +86,11 @@ describe Jobs::CleanUpUploads do
favicon_upload,
apple_touch_icon_upload
].each { |record| expect(Upload.exists?(id: record.id)).to eq(true) }
fabricate_upload
SiteSetting.opengraph_image = ''
Jobs::CleanUpUploads.new.execute(nil)
ensure
SiteSetting.delete_all
SiteSetting.provider = original_provider