diff --git a/lib/modules/sync_seeds.rb b/lib/modules/sync_seeds.rb index 5d4b70893..cef53b0a1 100644 --- a/lib/modules/sync_seeds.rb +++ b/lib/modules/sync_seeds.rb @@ -73,8 +73,8 @@ def check_if_newer(parent_folder, local_item, remote_item, remote_path, local_pa downloaded end - def compare_folders(wildcard, local, remote, base) - puts "Checking to see what files need to be deleted from #{base}" + def compare_folders(wildcard, local, remote) + puts "Checking to see what files need to be deleted from #{local}" remote_list = @session.sftp.dir.glob(remote, wildcard).map do |f| f.name.force_encoding('UTF-8') @@ -82,7 +82,7 @@ def compare_folders(wildcard, local, remote, base) local_list = Dir.glob(wildcard, base: local) - files_for_deletion(local_list, remote_list, base) + files_for_deletion(local_list, remote_list, local) end def check_inside_folder(folder, local_list) @@ -120,7 +120,8 @@ def main_task(local_list, remote_list) end end - def commence_import(answer) + # Piggybacks on existing Comfy modules + def commence_comfy_import(answer) logger = ComfortableMexicanSofa.logger ComfortableMexicanSofa.logger = Logger.new(STDOUT) diff --git a/lib/tasks/staging_seeds.rake b/lib/tasks/staging_seeds.rake index fce3dc1fd..de1312203 100644 --- a/lib/tasks/staging_seeds.rake +++ b/lib/tasks/staging_seeds.rake @@ -6,24 +6,25 @@ namespace :comfy do PP_STAGING = 'new-web.pp-staging.linode.protectedplanet.net'.freeze PP_USER = 'wcmc'.freeze - desc "Import CMS Seed data from staging. Can be run with arguments (, files/pages/layouts/all) or can accept user input if no argument is supplied" - task :staging_import, %i[to folder] => [:environment] do |_t, args| - - if args.length.nil? - puts question = "What would you like to import? 'All/Files/Layouts/Pages' or 'Nothing' to quit" - valid_answers = ['All', 'Files', 'Layouts', 'Pages', 'Nothing'] - answer = STDIN.gets.chomp.downcase.capitalize - until valid_answers.include?(answer) - puts question - end - - # Fast-tracked unhappy path - abort('Goodbye') if answer == 'Nothing' - else - to = File.join(ComfortableMexicanSofa.config.seeds_path, args[:to]) - answer = args[:folder].downcase.capitalize! + def user_input + puts question = "What would you like to import? 'All/Files/Layouts/Pages' or 'Nothing' to quit" + valid_answers = ['All', 'Files', 'Layouts', 'Pages', 'Nothing'] + answer = STDIN.gets.chomp.downcase.capitalize + until valid_answers.include?(answer) + puts question end + # Fast-tracked unhappy path + abort('Goodbye') if answer == 'Nothing' + + { answer: answer, destination: File.join(ComfortableMexicanSofa.config.seeds_path, 'protected-planet') } + end + + desc "Import CMS Seed data from staging. Can be run with arguments [, files/pages/layouts/all] or can accept user input if no argument is supplied" + task :staging_import, %i[to folder] => [:environment] do |_t, args| + to = args[:to].nil? ? user_input[:destination] : File.join(ComfortableMexicanSofa.config.seeds_path, args[:to]) + answer = args[:answer].nil? ? user_input[:answer] : args[:folder].downcase.capitalize! + puts "Importing CMS Seed data from Staging Folder to #{to} ..." new_session = SyncSeeds.new(PP_STAGING, PP_USER) @@ -32,7 +33,7 @@ namespace :comfy do new_session.start_session do |session| # First get rid of any local top-level (i.e. which exist in the main # directory of REMOTE) folders/files that don't exist remotely - new_session.compare_folders('*', to, FROM, to) + new_session.compare_folders('*', to, FROM) local_list = new_session.list_local_files(to) remote_list = new_session.list_remote_files(FROM) @@ -52,7 +53,7 @@ namespace :comfy do puts "Finished downloads, now replacing your local seed data with your selection..." - new_session.commence_import(answer) + # new_session.commence_comfy_import(answer) end end