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) .where("uploads.created_at < ?", grace_period.hour.ago)
.joins(<<~SQL) .joins(<<~SQL)
LEFT JOIN site_settings ss 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} AND ss.data_type = #{SiteSettings::TypeSupervisor.types[:upload].to_i}
SQL SQL
.joins("LEFT JOIN post_uploads pu ON pu.upload_id = uploads.id") .joins("LEFT JOIN post_uploads pu ON pu.upload_id = uploads.id")

View File

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