From ea943237660ad9162e56b694ec6f5f03526161f7 Mon Sep 17 00:00:00 2001 From: Brian Helba Date: Tue, 13 Nov 2018 06:27:38 -0500 Subject: [PATCH] FIX: 'migrate_from_s3' rake task should respect max sizes (#6598) Rather than hardcode a maximum size of 20MB for uploads migrated from S3, the task should use site settings for this value. --- lib/tasks/uploads.rake | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/tasks/uploads.rake b/lib/tasks/uploads.rake index 043f333a1a9..562d9997c9f 100644 --- a/lib/tasks/uploads.rake +++ b/lib/tasks/uploads.rake @@ -120,6 +120,8 @@ def migrate_from_s3 db = RailsMultisite::ConnectionManagement.current_db puts "Migrating uploads from S3 to local storage for '#{db}'..." + + max_file_size = [SiteSetting.max_image_size_kb, SiteSetting.max_attachment_size_kb].max.kilobytes Post .where("user_id > 0") @@ -131,7 +133,7 @@ def migrate_from_s3 post.raw.gsub!(/(\/\/[\w.-]+amazonaws\.com\/(original|optimized)\/([a-z0-9]+\/)+\h{40}([\w.-]+)?)/i) do |url| begin if filename = guess_filename(url, post.raw) - file = FileHelper.download("http:#{url}", max_file_size: 20.megabytes, tmp_file_name: "from_s3", follow_redirect: true) + file = FileHelper.download("http:#{url}", max_file_size: max_file_size, tmp_file_name: "from_s3", follow_redirect: true) sha1 = Upload.generate_digest(file) origin = nil @@ -160,7 +162,7 @@ def migrate_from_s3 if sha1 = Upload.sha1_from_short_url(url) if upload = Upload.find_by(sha1: sha1) if upload.url.start_with?("//") - file = FileHelper.download("http:#{upload.url}", max_file_size: 20.megabytes, tmp_file_name: "from_s3", follow_redirect: true) + file = FileHelper.download("http:#{upload.url}", max_file_size: max_file_size, tmp_file_name: "from_s3", follow_redirect: true) filename = upload.original_filename origin = upload.origin upload.destroy