add a sitesetting to enable the CleanUpUploads job
This commit is contained in:
parent
265f5c827e
commit
debd9bfb25
|
@ -4,6 +4,7 @@ module Jobs
|
|||
recurrence { hourly }
|
||||
|
||||
def execute(args)
|
||||
return unless SiteSetting.clean_up_uploads?
|
||||
|
||||
uploads_used_in_posts = PostUpload.uniq.pluck(:upload_id)
|
||||
uploads_used_as_avatars = User.uniq.where('uploaded_avatar_id IS NOT NULL').pluck(:uploaded_avatar_id)
|
||||
|
@ -13,8 +14,7 @@ module Jobs
|
|||
Upload.where("created_at < ?", grace_period.hour.ago)
|
||||
.where("id NOT IN (?)", uploads_used_in_posts + uploads_used_as_avatars)
|
||||
.find_each do |upload|
|
||||
# disable this for now.
|
||||
#upload.destroy
|
||||
upload.destroy
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -184,6 +184,7 @@ class SiteSetting < ActiveRecord::Base
|
|||
setting(:enforce_global_nicknames, true)
|
||||
setting(:discourse_org_access_key, '')
|
||||
|
||||
setting(:clean_up_uploads, false)
|
||||
setting(:uploads_grace_period_in_hours, 1)
|
||||
setting(:enable_s3_uploads, false)
|
||||
setting(:s3_access_key_id, '')
|
||||
|
|
|
@ -619,6 +619,7 @@ en:
|
|||
|
||||
suggested_topics: "Number of suggested topics shown at the bottom of a topic"
|
||||
|
||||
clean_up_uploads: "Remove orphaned uploads to prevent illegal hosting. WARNING: you might want to make a backup of your /uploads directory before enabled this setting."
|
||||
uploads_grace_period_in_hours: "Grace period (in hours) before an orphan upload is removed."
|
||||
enable_s3_uploads: "Place uploads on Amazon S3"
|
||||
s3_upload_bucket: "The Amazon S3 bucket name that files will be uploaded into. WARNING: must be lowercase (cf. http://docs.aws.amazon.com/AmazonS3/latest/dev/BucketRestrictions.html)"
|
||||
|
|
Loading…
Reference in New Issue