Skip to content

Commit

Permalink
Fix staging seeds rake task
Browse files Browse the repository at this point in the history
  • Loading branch information
Levia committed Sep 18, 2020
1 parent 5b2190f commit 83b5554
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
#
Expand Down
32 changes: 17 additions & 15 deletions lib/tasks/staging_seeds.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
end

0 comments on commit 83b5554

Please sign in to comment.