Class: Wordmove::Deployer::FTP

Inherits:
Base
  • Object
show all
Defined in:
lib/wordmove/deployer/ftp.rb

Instance Attribute Summary

Attributes inherited from Base

#logger, #options

Instance Method Summary collapse

Methods inherited from Base

deployer_for, fetch_movefile, #remote_get_directory, #remote_put_directory

Constructor Details

#initialize(options) ⇒ FTP

Returns a new instance of FTP.



10
11
12
13
14
15
# File 'lib/wordmove/deployer/ftp.rb', line 10

def initialize(options)
  super
  ftp_options = options[:remote][:ftp]
  @copier = Photocopier::FTP.new(ftp_options)
  @copier.logger = logger
end

Instance Method Details

#pull_dbObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/wordmove/deployer/ftp.rb', line 49

def pull_db
  super

  remote_dump_script = remote_wpcontent_path("dump.php")
  local_dump_path = local_wpcontent_path("dump.sql")

  # generate a secure one-time password
  one_time_password = SecureRandom.hex(40)

  # generate dump script
  dump_script = generate_dump_script(options[:remote][:database], one_time_password)
  # upload the dump script
  remote_put(dump_script, remote_dump_script)
  # download the resulting dump (using the password)
  dump_url = "#{remote_wpcontent_url("dump.php")}?shared_key=#{one_time_password}"
  download(dump_url, local_dump_path)

  # gsub sql
  adapt_sql(local_dump_path, options[:remote], options[:local])
  # import locally
  run mysql_import_command(local_dump_path, options[:local][:database])

  # remove it remotely
  remote_delete(remote_dump_script)
  # and locally
  run "rm #{local_dump_path}"
end

#push_dbObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/wordmove/deployer/ftp.rb', line 17

def push_db
  super

  remote_import_script_path = remote_wpcontent_path("import.php")
  local_dump_path = local_wpcontent_path("dump.sql")
  remote_dump_path = remote_wpcontent_path("dump.sql")

  # dump local mysql into file
  run mysql_dump_command(options[:local][:database], local_dump_path)
  # gsub sql
  adapt_sql(local_dump_path, options[:local], options[:remote])
  # upload it
  remote_put(local_dump_path, remote_dump_path)

  # generate a secure one-time password
  one_time_password = SecureRandom.hex(40)
  # generate import script
  import_script = generate_import_script(options[:remote][:database], one_time_password)
  # upload import script
  remote_put(import_script, remote_import_script_path)
  # run import script
  import_url = "#{remote_wpcontent_url("import.php")}?shared_key=#{one_time_password}&start=1&foffset=0&totalqueries=0&fn=dump.sql"
  download(import_url, local_dump_path + "_")

  # remove script remotely
  remote_delete(remote_import_script_path)
  # remove dump remotely
  remote_delete(remote_dump_path)
  # and locally
  run "rm #{local_dump_path}"
end