From 83b5554695937a4f839c592793a8ab5c13776ba4 Mon Sep 17 00:00:00 2001 From: Ferdinando Primerano Date: Fri, 18 Sep 2020 11:15:19 +0100 Subject: [PATCH] Fix staging seeds rake task --- Gemfile | 2 +- lib/tasks/staging_seeds.rake | 32 +++++++++++++++++--------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/Gemfile b/Gemfile index ec3a0263b..ab54ed61c 100644 --- a/Gemfile +++ b/Gemfile @@ -32,6 +32,7 @@ gem 'sprockets-vue', '~> 0.1.0' gem 'rails-controller-testing' gem 'gdal', '~> 2.0' +gem 'net-sftp' # group :production, :staging do # gem 'unicorn' @@ -51,7 +52,6 @@ group :development do gem 'capistrano-git-with-submodules', '2.0.3' gem 'capistrano-service' gem 'awesome_print' - gem 'net-sftp' # gem 'listen', '~> 3.1.5' # gem 'spring-watcher-listen', '~> 2.0.0' # diff --git a/lib/tasks/staging_seeds.rake b/lib/tasks/staging_seeds.rake index be0e873b7..1a72e283e 100644 --- a/lib/tasks/staging_seeds.rake +++ b/lib/tasks/staging_seeds.rake @@ -12,43 +12,45 @@ namespace :comfy do answer = STDIN.gets.chomp.downcase until valid_answers.include?(answer) - puts question - answer = STDIN.gets.chomp.downcase + puts question + answer = STDIN.gets.chomp.downcase end - + 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 - [destination folder - 'protected-planet' by convention, files/pages/layouts/all] + desc "Import CMS Seed data from staging. Can be run with arguments + [destination folder - 'protected-planet' by convention, files/pages/layouts/all] or can accept user input if no argument is supplied" - task :staging_import, %i[dest folder] => [:environment] do |_t, args| + task :staging_import, %i[dest folder] => [:environment] do |_t, args| dest = nil - answer = nil # answer is synonymous with folder + answer = nil # answer is synonymous with folder if args[:dest].nil? && args[:folder].nil? answers = user_input dest = answers[:destination] answer = answers[:answer] - else + elsif args[:dest] && args[:folder] dest = File.join(ComfortableMexicanSofa.config.seeds_path, args[:dest]) answer = args[:folder].downcase + else + abort('Please specify both destination and folder or leave both blank') end # Creates folder under db/cms_seeds if it doesn't exist unless Dir.exist?(dest) FileUtils.mkdir_p(dest) end - + puts "Importing CMS Seed data from Staging Folder to #{dest} ..." new_session = SyncSeeds.new(PP_STAGING, PP_USER) # SSH into staging server with Net::SSH new_session.start_session do |session| - # First get rid of any local top-level (i.e. which exist in the main + # First get rid of any local top-level (i.e. which exist in the main # directory of dest) folders/files that don't exist remotely new_session.compare_folders(wildcard: '*', local: dest, remote: SOURCE, base: dest) @@ -58,21 +60,21 @@ namespace :comfy do if answer == 'all' puts "Downloading all folders..." else - local_list.filter! { |f| f == answer } + local_list.filter! { |f| f == answer } remote_list.filter! do |f| f.name.force_encoding('UTF-8') == answer end puts "Downloading a new set of #{answer}..." end - + new_session.main_task(local_list: local_list, remote_list: remote_list, local_base: dest, remote_base: SOURCE) - + puts "Finished downloads, now replacing your local seed data with your selection..." - new_session.commence_comfy_import(answer, dest) + new_session.commence_comfy_import(answer, dest) end end -end \ No newline at end of file +end