Class: Wordmove::Actions::Ftp::DownloadRemoteDb

Inherits:
Object
  • Object
show all
Extended by:
LightService::Action
Includes:
Helpers, Helpers, WordpressDirectory::LocalHelperMethods, WordpressDirectory::RemoteHelperMethods
Defined in:
lib/wordmove/actions/ftp/download_remote_db.rb

Overview

Downloads the remote DB over FTP protocol

Class Method Summary collapse

Class Method Details

.executeLightService::Context

Returns Action’s context.

Parameters:

  • remote_options (Hash)

    Remote host options fetched from movefile (with symbolized keys)

  • cli_options (Hash)

    Command line options (with symbolized keys)

  • logger (Wordmove::Logger)
  • photocopier (Photocopier::FTP)
  • db_paths (BbPathsConfig)

    Configuration object for database

Returns:

  • (LightService::Context)

    Action’s context



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/wordmove/actions/ftp/download_remote_db.rb', line 27

executed do |context| # rubocop:disable Metrics/BlockLength
  context.logger.task 'Download remote DB'

  if simulate?(cli_options: context.cli_options)
    context.logger.info 'A dump of the remote DB would have been saved into ' \
                        "#{context.db_paths.local.path}, " \
                        'but you\'re simulating'
    next context
  end

  result = Wordmove::Actions::PutFile.execute(
    photocopier: context.photocopier,
    logger: context.logger,
    cli_options: context.cli_options,
    command_args: [
      context.db_paths.ftp.local.generated_dump_script_path,
      context.db_paths.ftp.remote.dump_script_path
    ]
  )
  context.fail_and_return!(result.message) if result.failure?

  dump_url = [
    context.db_paths.ftp.remote.dump_script_url,
    '?shared_key=',
    context.db_paths.ftp.token
  ].join

  begin
    download(url: dump_url, local_path: context.db_paths.local.path)
  rescue => _e # rubocop:disable Style/RescueStandardError
    context.fail_and_return!(e.message)
  end

  unless File.exist? context.db_paths.local.path
    context.fail_and_return!('Download of remote DB failed')
  end

  context.logger.success "Remote DB dump downloaded in #{context.db_paths.local.path}"
end