From 604d8a8aff18bcc51add114cbc5c7205f3300819 Mon Sep 17 00:00:00 2001 From: Stanley Liu Date: Thu, 23 Jul 2020 18:20:06 +0100 Subject: [PATCH] added a new rake task for syncing seeds from staging --- lib/tasks/staging_seeds.rake | 39 ++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 lib/tasks/staging_seeds.rake diff --git a/lib/tasks/staging_seeds.rake b/lib/tasks/staging_seeds.rake new file mode 100644 index 000000000..25ec0b806 --- /dev/null +++ b/lib/tasks/staging_seeds.rake @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +namespace :comfy do + desc "Import CMS Seed data from staging" + + task :seed_import => :environment do |_t| + require 'net/ssh' + require 'net/scp' + + puts "Importing CMS Seed data from Staging Folder to #{local} ..." + + # Locally stored seeds + local = ComfortableMexicanSofa.config.seeds_path + + # SSH into staging server with Net::SSH + # Check to see if local CMS seeds are newer than local and download any + Net::SSH.start(ENV['PP_STAGING'], ENV['PP_USER']) do |ssh| + ssh.sftp.dir.foreach('ProtectedPlanet/current/db/cms_seeds/protected-planet') do |f| + # Go through the various files and folders and check to see if they exist locally + if Dir.children(local).include?(f) + if File.stat(f).file? + local_file_changed = File.stat(f).mtime > Time.at(sftp.stat(f).mtime) + elsif File.stat(f).directory + ssh.sftp.dir.foreach(f) do |file| + local_file_changed = File.stat(file).mtime > Time.at(sftp.stat(file).mtime) + end + end + else + + end + end + # ssh.scp.download!('ProtectedPlanet/current/db/cms_seeds', local, recursive: true) + end + + puts "Replacing your local seed data..." + + Rake::Task["comfy:cms_seeds:import[protected-planet, protectedplanet]"].invoke + end +end \ No newline at end of file