wordmove 5.2.2 → 6.0.0.alpha.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +12 -5
  3. data/.rubocop.yml +2 -5
  4. data/.ruby-version +1 -1
  5. data/.yardopts +1 -0
  6. data/CONTRIBUTING.md +15 -0
  7. data/Rakefile +4 -3
  8. data/exe/wordmove +2 -1
  9. data/lib/wordmove/actions/adapt_local_db.rb +101 -0
  10. data/lib/wordmove/actions/adapt_remote_db.rb +88 -0
  11. data/lib/wordmove/actions/backup_local_db.rb +56 -0
  12. data/lib/wordmove/actions/delete_local_file.rb +34 -0
  13. data/lib/wordmove/actions/delete_remote_file.rb +43 -0
  14. data/lib/wordmove/actions/filter_and_setup_tasks_to_run.rb +42 -0
  15. data/lib/wordmove/actions/ftp/backup_remote_db.rb +54 -0
  16. data/lib/wordmove/actions/ftp/cleanup_after_adapt.rb +70 -0
  17. data/lib/wordmove/actions/ftp/download_remote_db.rb +69 -0
  18. data/lib/wordmove/actions/ftp/get_directory.rb +67 -0
  19. data/lib/wordmove/actions/ftp/helpers.rb +91 -0
  20. data/lib/wordmove/actions/ftp/pull_wordpress.rb +56 -0
  21. data/lib/wordmove/actions/ftp/push_wordpress.rb +54 -0
  22. data/lib/wordmove/actions/ftp/put_and_import_dump_remotely.rb +81 -0
  23. data/lib/wordmove/actions/ftp/put_directory.rb +67 -0
  24. data/lib/wordmove/actions/get_file.rb +38 -0
  25. data/lib/wordmove/actions/helpers.rb +142 -0
  26. data/lib/wordmove/actions/put_file.rb +48 -0
  27. data/lib/wordmove/actions/run_after_pull_hook.rb +26 -0
  28. data/lib/wordmove/actions/run_after_push_hook.rb +26 -0
  29. data/lib/wordmove/actions/run_before_pull_hook.rb +26 -0
  30. data/lib/wordmove/actions/run_before_push_hook.rb +26 -0
  31. data/lib/wordmove/actions/run_local_command.rb +34 -0
  32. data/lib/wordmove/actions/setup_context_for_db.rb +73 -0
  33. data/lib/wordmove/actions/ssh/backup_remote_db.rb +49 -0
  34. data/lib/wordmove/actions/ssh/cleanup_after_adapt.rb +54 -0
  35. data/lib/wordmove/actions/ssh/download_remote_db.rb +81 -0
  36. data/lib/wordmove/actions/ssh/get_directory.rb +76 -0
  37. data/lib/wordmove/actions/ssh/helpers.rb +128 -0
  38. data/lib/wordmove/actions/ssh/pull_wordpress.rb +56 -0
  39. data/lib/wordmove/actions/ssh/push_wordpress.rb +54 -0
  40. data/lib/wordmove/actions/ssh/put_and_import_dump_remotely.rb +75 -0
  41. data/lib/wordmove/actions/ssh/put_directory.rb +76 -0
  42. data/lib/wordmove/actions/ssh/run_remote_command.rb +39 -0
  43. data/lib/wordmove/assets/dump.php.erb +6 -6
  44. data/lib/wordmove/assets/import.php.erb +7 -7
  45. data/lib/wordmove/assets/wordmove_schema_global.yml +2 -0
  46. data/lib/wordmove/cli.rb +152 -91
  47. data/lib/wordmove/db_paths_config.rb +44 -0
  48. data/lib/wordmove/doctor/movefile.rb +8 -8
  49. data/lib/wordmove/doctor/mysql.rb +18 -15
  50. data/lib/wordmove/doctor/rsync.rb +2 -2
  51. data/lib/wordmove/doctor/ssh.rb +3 -3
  52. data/lib/wordmove/doctor/wpcli.rb +5 -5
  53. data/lib/wordmove/environments_list.rb +4 -4
  54. data/lib/wordmove/exceptions.rb +13 -0
  55. data/lib/wordmove/generators/movefile.rb +7 -5
  56. data/lib/wordmove/generators/movefile_adapter.rb +11 -5
  57. data/lib/wordmove/guardian.rb +5 -5
  58. data/lib/wordmove/hook.rb +13 -14
  59. data/lib/wordmove/logger.rb +11 -10
  60. data/lib/wordmove/movefile.rb +63 -59
  61. data/lib/wordmove/organizers/ftp/pull.rb +53 -0
  62. data/lib/wordmove/organizers/ftp/push.rb +54 -0
  63. data/lib/wordmove/organizers/ssh/pull.rb +53 -0
  64. data/lib/wordmove/organizers/ssh/push.rb +54 -0
  65. data/lib/wordmove/version.rb +1 -1
  66. data/lib/wordmove/wordpress_directory.rb +76 -8
  67. data/lib/wordmove/wpcli.rb +88 -0
  68. data/lib/wordmove.rb +33 -11
  69. data/wordmove.gemspec +37 -30
  70. metadata +139 -35
  71. data/lib/wordmove/deployer/base.rb +0 -193
  72. data/lib/wordmove/deployer/ftp.rb +0 -160
  73. data/lib/wordmove/deployer/ssh/default_sql_adapter.rb +0 -47
  74. data/lib/wordmove/deployer/ssh/wpcli_sql_adapter.rb +0 -55
  75. data/lib/wordmove/deployer/ssh.rb +0 -169
  76. data/lib/wordmove/sql_adapter/default.rb +0 -68
  77. data/lib/wordmove/sql_adapter/wpcli.rb +0 -54
  78. data/lib/wordmove/wordpress_directory/path.rb +0 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f06e5ea25d6f6ba6a89a0794f707054bd610332b13577da5f5927abb012e80b
4
- data.tar.gz: 606d54185e3da1bc13027223105dd345e3a5af67420eabc5ed44bd4aea1e65ac
3
+ metadata.gz: ff2399e2a947da60d6acac49fb8dc6beb32f3571d4f79cf5f1ea0c5f8f0fcfe6
4
+ data.tar.gz: 1aa500f453341eceb9a1d82d03abec6c139de29806b840d0844f578241ae696c
5
5
  SHA512:
6
- metadata.gz: beaf05a7ce50d11c7477bb7369c727c17ac4d98f541dbcfd383b90486541edba836086fec890df43ff4f9e78041df50be7cb356b3d0eba7de96e71ae122dd37f
7
- data.tar.gz: d17d47f4febc8ea941aa4eb038c85c45c749105b92e23a59fb521b13c8bdf518edcd35de6208080e7847008763a7c38913dfe51eba702ba49823de7acc465887
6
+ metadata.gz: 7e3480a25ffeff1808227e5036dc4c7e0d69d92822019b3ffb3e5d47b54bf60809d1a0951c3ee38574dd9e9f345ddcff7d49e92ab171c5930e8d2d0d9f886fd0
7
+ data.tar.gz: 5c742c2644d644f9f3d61c0d77dbc15c69957244f98c20dade5e04867b59d55202b88449ea1a9f5ff9ca2952a7e43b1db24fdf8c4e4d387438dd8b0807317096
@@ -15,16 +15,23 @@ on:
15
15
 
16
16
  jobs:
17
17
  test:
18
-
19
18
  runs-on: ubuntu-latest
19
+ container:
20
+ image: welaika/wordmove:latest
20
21
 
21
22
  steps:
22
23
  - uses: actions/checkout@v2
23
- - name: Set up Ruby
24
- uses: ruby/setup-ruby@v1
24
+ - name: Cache gems
25
+ uses: actions/cache@v2
25
26
  with:
26
- ruby-version: 2.6
27
+ path: .vendor/bundle
28
+ key: wordmove-${{ hashFiles('wordmove.gemspec') }}
29
+ - name: Install bundler
30
+ run: |
31
+ echo $(pwd)
32
+ bundle config set path .vendor/bundle
33
+ gem install bundler:2.3.3
27
34
  - name: Install dependencies
28
- run: bundle install
35
+ run : bundle install
29
36
  - name: Run tests
30
37
  run: bundle exec rake
data/.rubocop.yml CHANGED
@@ -1,7 +1,8 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.6
2
+ TargetRubyVersion: 2.7.1
3
3
  DisplayCopNames: true
4
4
  DisplayStyleGuide: true
5
+ NewCops: enable
5
6
 
6
7
  Exclude:
7
8
  - 'bin/*'
@@ -27,10 +28,6 @@ Metrics/CyclomaticComplexity:
27
28
  Metrics/PerceivedComplexity:
28
29
  Max: 10
29
30
 
30
- Style/StringLiterals:
31
- Enabled: false
32
- EnforcedStyle: double_quotes
33
-
34
31
  Style/Documentation:
35
32
  Enabled: false
36
33
 
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.5
1
+ 2.7.1
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --plugin activesupport-concern
data/CONTRIBUTING.md CHANGED
@@ -77,6 +77,21 @@ or run the executable directly
77
77
  bin/wordmove --version
78
78
  ```
79
79
 
80
+ #### Documenting
81
+
82
+ A large part of the code is documented using https://yardoc.org/.
83
+
84
+ Please, stick with this practice when you're implementing new code. If you want to preview yard
85
+ documentation locally
86
+
87
+ ```
88
+ yard server -r
89
+ ```
90
+
91
+ then visit the served HTML at http://localhost:8808.
92
+
93
+ YARD documentation is automatically published by rubygems site at each release.
94
+
80
95
  ### Maintainer tasks
81
96
 
82
97
  ToDo:
data/Rakefile CHANGED
@@ -1,8 +1,9 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
  require 'rubocop/rake_task'
4
4
 
5
5
  RSpec::Core::RakeTask.new(:spec)
6
- task default: :spec
7
6
  RuboCop::RakeTask.new(:rubocop)
7
+
8
8
  task default: :rubocop
9
+ task default: :spec
data/exe/wordmove CHANGED
@@ -3,4 +3,5 @@
3
3
  $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
4
4
 
5
5
  require 'wordmove'
6
- Wordmove::CLI.start
6
+
7
+ Dry::CLI.new(Wordmove::CLI::Commands).call
@@ -0,0 +1,101 @@
1
+ module Wordmove
2
+ module Actions
3
+ #
4
+ # Adapt the local DB for the remote destination.
5
+ # "To adapt" in Wordmove jargon means to transform URLs strings into the database. This action
6
+ # will substitute local URLs with remote ones, in order to make the DB to work correctly once
7
+ # pushed to the remote wordpress installation.
8
+ #
9
+ class AdaptLocalDb
10
+ extend ::LightService::Action
11
+ include Wordmove::Actions::Helpers
12
+ include Wordmove::Wpcli
13
+
14
+ expects :local_options,
15
+ :remote_options,
16
+ :cli_options,
17
+ :logger,
18
+ :photocopier,
19
+ :db_paths
20
+
21
+ # @!method execute
22
+ # @param local_options [Hash] Local host options fetched from
23
+ # movefile (with symbolized keys)
24
+ # @param remote_options [Hash] Remote host options fetched from
25
+ # movefile (with symbolized keys)
26
+ # @param cli_options [Hash] Command line options
27
+ # @param logger [Wordmove::Logger]
28
+ # @param photocopier [Photocopier::SSH|Photocopier::FTP]
29
+ # @param db_paths [BbPathsConfig] Configuration object for database
30
+ # @!scope class
31
+ # @return [LightService::Context] Action's context
32
+ executed do |context| # rubocop:disable Metrics/BlockLength
33
+ context.logger.task 'Adapt local DB'
34
+
35
+ unless wp_in_path?
36
+ raise UnmetPeerDependencyError, 'WP-CLI is not installed or not in your $PATH'
37
+ end
38
+
39
+ next context if simulate?(cli_options: context.cli_options)
40
+
41
+ result = Wordmove::Actions::RunLocalCommand.execute(
42
+ cli_options: context.cli_options,
43
+ logger: context.logger,
44
+ command: mysql_dump_command(
45
+ env_db_options: context.local_options[:database],
46
+ save_to_path: context.db_paths.local.path
47
+ )
48
+ )
49
+ context.fail_and_return!(result.message) if result.failure?
50
+
51
+ if context.cli_options[:no_adapt]
52
+ context.logger.warn 'Skipping DB adapt'
53
+ else
54
+ result = Wordmove::Actions::RunLocalCommand.execute(
55
+ cli_options: context.cli_options,
56
+ logger: context.logger,
57
+ command: wpcli_search_replace_command(context, :vhost)
58
+ )
59
+ context.fail_and_return!(result.message) if result.failure?
60
+
61
+ result = Wordmove::Actions::RunLocalCommand.execute(
62
+ cli_options: context.cli_options,
63
+ logger: context.logger,
64
+ command: wpcli_search_replace_command(context, :wordpress_path)
65
+ )
66
+ context.fail_and_return!(result.message) if result.failure?
67
+ end
68
+
69
+ result = Wordmove::Actions::RunLocalCommand.execute(
70
+ cli_options: context.cli_options,
71
+
72
+ logger: context.logger,
73
+ command: mysql_dump_command(
74
+ env_db_options: context.local_options[:database],
75
+ save_to_path: context.db_paths.local.adapted_path
76
+ )
77
+ )
78
+ context.fail_and_return!(result.message) if result.failure?
79
+
80
+ if context.photocopier.is_a? Photocopier::SSH
81
+ result = Wordmove::Actions::RunLocalCommand.execute(
82
+ cli_options: context.cli_options,
83
+ logger: context.logger,
84
+ command: compress_command(file_path: context.db_paths.local.adapted_path)
85
+ )
86
+ context.fail_and_return!(result.message) if result.failure?
87
+ end
88
+
89
+ result = Wordmove::Actions::RunLocalCommand.execute(
90
+ cli_options: context.cli_options,
91
+ logger: context.logger,
92
+ command: mysql_import_command(
93
+ dump_path: context.db_paths.local.path,
94
+ env_db_options: context.local_options[:database]
95
+ )
96
+ )
97
+ context.fail_and_return!(result.message) if result.failure?
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,88 @@
1
+ module Wordmove
2
+ module Actions
3
+ #
4
+ # Adapt the remote DB for the local destination.
5
+ # "To adapt" in Wordmove jargon means to transform URLs strings into the database. This action
6
+ # will substitute remote URLs with local ones, in order to make the DB to work correctly once
7
+ # pulled to the local wordpress installation.
8
+ #
9
+ # @note This action is not responsible to download the remote DB nor to backup any DB at all.
10
+ # It expects to find a dump of the remote DB into +context.db_paths.local.gzipped_path+
11
+ # (SSH) or +context.db_paths.local.path+ (FTP), otherwise it will fail and stop the
12
+ # procedure.
13
+ #
14
+ class AdaptRemoteDb
15
+ extend ::LightService::Action
16
+ include Wordmove::Actions::Helpers
17
+ include Wordmove::Wpcli
18
+
19
+ expects :local_options,
20
+ :cli_options,
21
+ :logger,
22
+ :db_paths
23
+
24
+ # @!method execute
25
+ # @param local_options [Hash] Local host options fetched from
26
+ # movefile (with symbolized keys)
27
+ # @param cli_options [Hash] Command line options
28
+ # @param logger [Wordmove::Logger]
29
+ # @param db_paths [BbPathsConfig] Configuration object for database
30
+ # @!scope class
31
+ # @return [LightService::Context] Action's context
32
+ executed do |context| # rubocop:disable Metrics/BlockLength
33
+ context.logger.task 'Adapt remote DB'
34
+
35
+ unless wp_in_path?
36
+ raise UnmetPeerDependencyError, 'WP-CLI is not installed or not in your $PATH'
37
+ end
38
+
39
+ next context if simulate?(cli_options: context.cli_options)
40
+
41
+ if File.exist?(context.db_paths.local.gzipped_path)
42
+ Wordmove::Actions::RunLocalCommand.execute(
43
+ cli_options: context.cli_options,
44
+ logger: context.logger,
45
+ command: uncompress_command(file_path: context.db_paths.local.gzipped_path)
46
+ )
47
+ end
48
+
49
+ unless File.exist?(context.db_paths.local.path)
50
+ context.fail_and_return!(
51
+ "Cannot find the dump file to adapt in #{context.db_paths.local.path}"
52
+ )
53
+ end
54
+
55
+ result = Wordmove::Actions::RunLocalCommand.execute(
56
+ cli_options: context.cli_options,
57
+ logger: context.logger,
58
+ command: mysql_import_command(
59
+ dump_path: context.db_paths.local.path,
60
+ env_db_options: context.local_options[:database]
61
+ )
62
+ )
63
+ context.fail_and_return!(result.message) if result.failure?
64
+
65
+ if context.cli_options[:no_adapt]
66
+ context.logger.warn 'Skipping DB adapt'
67
+ next context
68
+ end
69
+
70
+ result = Wordmove::Actions::RunLocalCommand.execute(
71
+ cli_options: context.cli_options,
72
+ logger: context.logger,
73
+ command: wpcli_search_replace_command(context, :vhost)
74
+ )
75
+ context.fail_and_return!(result.message) if result.failure?
76
+
77
+ result = Wordmove::Actions::RunLocalCommand.execute(
78
+ cli_options: context.cli_options,
79
+ logger: context.logger,
80
+ command: wpcli_search_replace_command(context, :wordpress_path)
81
+ )
82
+ context.fail_and_return!(result.message) if result.failure?
83
+
84
+ context.logger.success 'Local DB adapted'
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,56 @@
1
+ module Wordmove
2
+ module Actions
3
+ #
4
+ # Take a backup of the local database and save it in +wp-content/+ folder.
5
+ #
6
+ class BackupLocalDb
7
+ extend ::LightService::Action
8
+ include Wordmove::Actions::Helpers
9
+
10
+ expects :local_options
11
+ expects :cli_options
12
+ expects :db_paths
13
+ expects :logger
14
+
15
+ # @!method execute
16
+ # @param local_options [Hash] Local host options fetched from
17
+ # movefile (with symbolized keys)
18
+ # @param cli_options [Hash] Command line options
19
+ # @param db_paths [BbPathsConfig] Configuration object for database
20
+ # @param logger [Wordmove::Logger]
21
+ # @!scope class
22
+ # @return [LightService::Context] Action's context
23
+ executed do |context|
24
+ context.logger.task 'Backup local DB'
25
+
26
+ if simulate?(cli_options: context.cli_options)
27
+ context.logger.info 'A backup of the local DB would have been saved into ' \
28
+ "#{context.db_paths.backup.local.gzipped_path}, " \
29
+ 'but you\'re simulating'
30
+ next context
31
+ end
32
+
33
+ result = Wordmove::Actions::RunLocalCommand.execute(
34
+ cli_options: context.cli_options,
35
+ logger: context.logger,
36
+ command: mysql_dump_command(
37
+ env_db_options: context.local_options[:database],
38
+ save_to_path: context.db_paths.backup.local.path
39
+ )
40
+ )
41
+ context.fail_and_return!(result.message) if result.failure?
42
+
43
+ result = Wordmove::Actions::RunLocalCommand.execute(
44
+ cli_options: context.cli_options,
45
+ logger: context.logger,
46
+ command: compress_command(file_path: context.db_paths.backup.local.path)
47
+ )
48
+ context.fail_and_return!(result.message) if result.failure?
49
+
50
+ context.logger.success(
51
+ "Backup saved at #{context.db_paths.backup.local.gzipped_path}"
52
+ )
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,34 @@
1
+ module Wordmove
2
+ module Actions
3
+ # Delete a local file situated at the given path.
4
+ # Command won't be run if +--simulate+ flag is present on CLI.
5
+ # @note This action is *not* meant to be organized, but as a standalone one.
6
+ class DeleteLocalFile
7
+ extend LightService::Action
8
+ include Wordmove::Actions::Helpers
9
+
10
+ expects :file_path,
11
+ :logger,
12
+ :cli_options
13
+
14
+ # @!method execute
15
+ # @param file_path [String]
16
+ # @param logger [Wordmove::Logger]
17
+ # @param cli_options [Hash] Command line options (with symbolized keys)
18
+ # @!scope class
19
+ # @return [LightService::Context] Action's context
20
+ executed do |context|
21
+ context.logger.task_step true, "delete: '#{context.file_path}'"
22
+
23
+ next context if simulate?(cli_options: context.cli_options)
24
+
25
+ unless File.exist?(context.file_path)
26
+ context.logger.info "File #{context.file_path} does not exist. Nothing done."
27
+ next context
28
+ end
29
+
30
+ File.delete(context.file_path)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,43 @@
1
+ module Wordmove
2
+ module Actions
3
+ # Delete a remote file
4
+ # @note This action is *not* meant to be organized, but as a standalone one.
5
+ class DeleteRemoteFile
6
+ extend LightService::Action
7
+ include Wordmove::Actions::Helpers
8
+
9
+ expects :photocopier,
10
+ :logger,
11
+ :cli_options,
12
+ :remote_file
13
+
14
+ # @!method execute
15
+ # @param photocopier [Photocopier]
16
+ # @param logger [Wordmove::Logger]
17
+ # @param cli_options [Hash] Command line options (with symbolized keys)
18
+ # @param remote_file ((String) remote file path)
19
+ # @!scope class
20
+ # @return [LightService::Context] Action's context
21
+ executed do |context|
22
+ command = 'delete'
23
+
24
+ context.logger.task_step false, "#{command}: #{context.remote_file}"
25
+
26
+ next context if simulate?(cli_options: context.cli_options)
27
+
28
+ _stdout, stderr, exit_code = context.photocopier.send(command, context.remote_file)
29
+
30
+ next context if exit_code&.zero?
31
+
32
+ # When +context.photocopier+ is a +Photocopier::FTP+ instance, +delte+ will always
33
+ # return +nil+; so it's impossible to correctly fail the context when using
34
+ # FTP protocol. The problem is how +Net::FTP+ ruby class behaves.
35
+ # IMO this is an acceptable tradeoff.
36
+ unless exit_code.nil?
37
+ context.fail! "Error code #{exit_code} returned while deleting file "\
38
+ "#{context.remote_file}: #{stderr}"
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,42 @@
1
+ module Wordmove
2
+ module Actions
3
+ # Given the command line options and given the denied-by-config actions,
4
+ # selects the actions to be run altering the context.
5
+ class FilterAndSetupTasksToRun
6
+ extend ::LightService::Action
7
+ include Wordmove::Actions::Helpers
8
+ include Wordmove::Actions::Ssh::Helpers
9
+ include WordpressDirectory::RemoteHelperMethods
10
+
11
+ expects :guardian,
12
+ :cli_options
13
+ promises :folder_tasks,
14
+ :database_task,
15
+ :wordpress_task
16
+
17
+ # @!method execute
18
+ # @param guardian [Wordmove::Guardian]
19
+ # @param cli_options [Hash]
20
+ # @!scope class
21
+ # @return [LightService::Context] Action's context
22
+ executed do |context|
23
+ all_tasks = Wordmove::CLI::PullPushShared::WORDPRESS_OPTIONS
24
+
25
+ requested_tasks = all_tasks.select do |task|
26
+ context.cli_options[task] ||
27
+ (context.cli_options[:all] && context.cli_options[task] != false)
28
+ end
29
+
30
+ allowed_tasks = requested_tasks.select { |task| context.guardian.allows task }
31
+
32
+ # Since we `promises` the following variables, we cannot set them as `nil`
33
+ context.database_task = allowed_tasks.delete(:db) || false
34
+ context.wordpress_task = allowed_tasks.delete(:wordpress) || false
35
+ # :db and :wordpress were just removed, so we consider
36
+ # the reminders as folder tasks. It's a weak assumption
37
+ # though.
38
+ context.folder_tasks = allowed_tasks
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,54 @@
1
+ module Wordmove
2
+ module Actions
3
+ module Ftp
4
+ # Bakups an already downloaded remote DB dump
5
+ class BackupRemoteDb
6
+ extend ::LightService::Action
7
+ include Wordmove::Actions::Helpers
8
+
9
+ expects :remote_options,
10
+ :cli_options,
11
+ :logger,
12
+ :photocopier,
13
+ :db_paths
14
+
15
+ # @!method execute
16
+ # @param remote_options [Hash] Options for the remote host fetched from the movefile
17
+ # @param cli_options [Hash] Command line options (with symbolized keys)
18
+ # @param logger [Wordmove::Logger]
19
+ # @param photocopier [Photocopier::FTP]
20
+ # @param db_paths [BbPathsConfig] Configuration object for database
21
+ # @!scope class
22
+ # @return [LightService::Context] Action's context
23
+ executed do |context|
24
+ context.logger.task 'Backup remote DB'
25
+
26
+ if simulate?(cli_options: context.cli_options)
27
+ context.logger.info 'A backup of the remote DB would have been saved into ' \
28
+ "#{context.db_paths.backup.remote.gzipped_path}, " \
29
+ 'but you\'re simulating'
30
+ next context
31
+ end
32
+
33
+ begin
34
+ result = Wordmove::Actions::RunLocalCommand.execute(
35
+ logger: context.logger,
36
+ cli_options: context.cli_options,
37
+ command: compress_command(file_path: context.db_paths.local.path)
38
+ )
39
+ raise(result.message) if result.failure?
40
+
41
+ FileUtils.mv(
42
+ context.db_paths.local.gzipped_path,
43
+ context.db_paths.backup.remote.gzipped_path
44
+ )
45
+
46
+ context.logger.success("Backup saved at #{context.db_paths.backup.remote.gzipped_path}")
47
+ rescue Errno::ENOENT, RuntimeError => e
48
+ context.fail_and_return!("Remote DB backup failed with: <#{e.message}>. Aborting.")
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,70 @@
1
+ module Wordmove
2
+ module Actions
3
+ module Ftp
4
+ # Cleanup file created during DB push/pull operations
5
+ class CleanupAfterAdapt
6
+ extend ::LightService::Action
7
+ include Wordmove::Actions::Helpers
8
+
9
+ expects :db_paths,
10
+ :cli_options,
11
+ :logger,
12
+ :photocopier
13
+
14
+ # @!method execute
15
+ # @param logger [Wordmove::Logger]
16
+ # @param cli_options [Hash] Command line options (with symbolized keys)
17
+ # @param db_paths [BbPathsConfig] Configuration object for database
18
+ # @param photocopier [Photocopier::FTP]
19
+ # @!scope class
20
+ # @return [LightService::Context] Action's context
21
+ executed do |context| # rubocop:disable Metrics/BlockLength
22
+ context.logger.task 'Cleanup'
23
+
24
+ if simulate?(cli_options: context.cli_options)
25
+ context.logger.info 'No cleanup during simulation'
26
+ next context
27
+ end
28
+
29
+ result = Wordmove::Actions::DeleteLocalFile.execute(
30
+ logger: context.logger,
31
+ cli_options: context.cli_options,
32
+ file_path: context.db_paths.local.path
33
+ )
34
+
35
+ if result.failure?
36
+ context.logger.warning 'Failed to delete local file ' \
37
+ "#{context.db_paths.local.path} because: " \
38
+ "#{result.message}" \
39
+ '. Manual intervention required'
40
+ end
41
+
42
+ [
43
+ context.db_paths.ftp.remote.dump_script_path,
44
+ context.db_paths.ftp.remote.import_script_path,
45
+ context.db_paths.remote.path,
46
+ context.db_paths.ftp.remote.dumped_path
47
+ ].each do |file|
48
+ begin
49
+ result = Wordmove::Actions::DeleteRemoteFile.execute(
50
+ photocopier: context.photocopier,
51
+ logger: context.logger,
52
+ cli_options: context.cli_options,
53
+ remote_file: file
54
+ )
55
+ rescue Net::FTPPermError => _e
56
+ context.logger.info "#{file} doesn't exist remotely. Nothing to cleanup"
57
+ end
58
+
59
+ if result.failure? # rubocop:disable Style/Next
60
+ context.logger.warning 'Failed to delete remote file ' \
61
+ "#{file} because: " \
62
+ "#{result.message}" \
63
+ '. Manual intervention required'
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,69 @@
1
+ module Wordmove
2
+ module Actions
3
+ module Ftp
4
+ # Downloads the remote DB over FTP protocol
5
+ class DownloadRemoteDb
6
+ extend ::LightService::Action
7
+ include Wordmove::Actions::Helpers
8
+ include Wordmove::Actions::Ftp::Helpers
9
+ include WordpressDirectory::LocalHelperMethods
10
+ include WordpressDirectory::RemoteHelperMethods
11
+
12
+ expects :remote_options,
13
+ :cli_options,
14
+ :logger,
15
+ :photocopier,
16
+ :db_paths
17
+
18
+ # @!method execute
19
+ # @param remote_options [Hash] Remote host options fetched from
20
+ # movefile (with symbolized keys)
21
+ # @param cli_options [Hash] Command line options (with symbolized keys)
22
+ # @param logger [Wordmove::Logger]
23
+ # @param photocopier [Photocopier::FTP]
24
+ # @param db_paths [BbPathsConfig] Configuration object for database
25
+ # @!scope class
26
+ # @return [LightService::Context] Action's context
27
+ executed do |context| # rubocop:disable Metrics/BlockLength
28
+ context.logger.task 'Download remote DB'
29
+
30
+ if simulate?(cli_options: context.cli_options)
31
+ context.logger.info 'A dump of the remote DB would have been saved into ' \
32
+ "#{context.db_paths.local.path}, " \
33
+ 'but you\'re simulating'
34
+ next context
35
+ end
36
+
37
+ result = Wordmove::Actions::PutFile.execute(
38
+ photocopier: context.photocopier,
39
+ logger: context.logger,
40
+ cli_options: context.cli_options,
41
+ command_args: [
42
+ context.db_paths.ftp.local.generated_dump_script_path,
43
+ context.db_paths.ftp.remote.dump_script_path
44
+ ]
45
+ )
46
+ context.fail_and_return!(result.message) if result.failure?
47
+
48
+ dump_url = [
49
+ context.db_paths.ftp.remote.dump_script_url,
50
+ '?shared_key=',
51
+ context.db_paths.ftp.token
52
+ ].join
53
+
54
+ begin
55
+ download(url: dump_url, local_path: context.db_paths.local.path)
56
+ rescue => _e # rubocop:disable Style/RescueStandardError
57
+ context.fail_and_return!(e.message)
58
+ end
59
+
60
+ unless File.exist? context.db_paths.local.path
61
+ context.fail_and_return!('Download of remote DB failed')
62
+ end
63
+
64
+ context.logger.success "Remote DB dump downloaded in #{context.db_paths.local.path}"
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end