From 60790eb006eeaf288740bbfc3cc6eaa602179c13 Mon Sep 17 00:00:00 2001
From: Rishabh <rishabh.nambiar@discourse.org>
Date: Wed, 16 Jan 2019 14:37:05 +0530
Subject: [PATCH] FIX: Use GlobalSetting values instead of ENV variables in
 migrate_to_s3

TIL how GlobalSetting works in sync with environment variables
Also fixes a small bug where bucket value was being used when it could have been nil
---
 lib/tasks/uploads.rake | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/tasks/uploads.rake b/lib/tasks/uploads.rake
index 9f850ab0b98..37b54255299 100644
--- a/lib/tasks/uploads.rake
+++ b/lib/tasks/uploads.rake
@@ -214,7 +214,6 @@ def migrate_to_s3
   db = RailsMultisite::ConnectionManagement.current_db
 
   dry_run = !!ENV["DRY_RUN"]
-  bucket_has_folder_path = true if ENV["DISCOURSE_S3_BUCKET"].include? "/"
 
   puts "*" * 30 + " DRY RUN " + "*" * 30 if dry_run
   puts "Migrating uploads to S3 for '#{db}'..."
@@ -245,10 +244,11 @@ def migrate_to_s3
     exit 3
   end
 
+  bucket_has_folder_path = true if GlobalSetting.s3_bucket.include? "/"
   s3 = Aws::S3::Client.new(S3Helper.s3_options(GlobalSetting))
 
   if bucket_has_folder_path
-    bucket, folder = S3Helper.get_bucket_and_folder_path(ENV["DISCOURSE_S3_BUCKET"])
+    bucket, folder = S3Helper.get_bucket_and_folder_path(GlobalSetting.s3_bucket)
     folder = File.join(folder, "/")
   else
     bucket, folder = GlobalSetting.s3_bucket, ""