From debd9bfb25f4f8727a556635a7ba69bd69f0f8ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Wed, 16 Oct 2013 10:55:42 +0200 Subject: [PATCH] add a sitesetting to enable the CleanUpUploads job --- app/jobs/scheduled/clean_up_uploads.rb | 4 ++-- app/models/site_setting.rb | 1 + config/locales/server.en.yml | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/jobs/scheduled/clean_up_uploads.rb b/app/jobs/scheduled/clean_up_uploads.rb index 6c2ff7c7a4c..8146602eb1a 100644 --- a/app/jobs/scheduled/clean_up_uploads.rb +++ b/app/jobs/scheduled/clean_up_uploads.rb @@ -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 diff --git a/app/models/site_setting.rb b/app/models/site_setting.rb index a0d57706237..628dec3dea1 100644 --- a/app/models/site_setting.rb +++ b/app/models/site_setting.rb @@ -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, '') diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 9ab54fe4389..14189b335a3 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -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)"