wordmove 5.2.1 → 6.0.0.alpha.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +12 -5
- data/.rubocop.yml +2 -5
- data/.ruby-version +1 -1
- data/.yardopts +1 -0
- data/CONTRIBUTING.md +15 -0
- data/Rakefile +4 -3
- data/exe/wordmove +2 -1
- data/lib/wordmove/actions/adapt_local_db.rb +103 -0
- data/lib/wordmove/actions/adapt_remote_db.rb +90 -0
- data/lib/wordmove/actions/backup_local_db.rb +58 -0
- data/lib/wordmove/actions/delete_local_file.rb +34 -0
- data/lib/wordmove/actions/delete_remote_file.rb +43 -0
- data/lib/wordmove/actions/filter_and_setup_tasks_to_run.rb +42 -0
- data/lib/wordmove/actions/ftp/backup_remote_db.rb +56 -0
- data/lib/wordmove/actions/ftp/cleanup_after_adapt.rb +72 -0
- data/lib/wordmove/actions/ftp/download_remote_db.rb +71 -0
- data/lib/wordmove/actions/ftp/get_directory.rb +67 -0
- data/lib/wordmove/actions/ftp/helpers.rb +91 -0
- data/lib/wordmove/actions/ftp/pull_wordpress.rb +56 -0
- data/lib/wordmove/actions/ftp/push_wordpress.rb +54 -0
- data/lib/wordmove/actions/ftp/put_and_import_dump_remotely.rb +83 -0
- data/lib/wordmove/actions/ftp/put_directory.rb +67 -0
- data/lib/wordmove/actions/get_file.rb +38 -0
- data/lib/wordmove/actions/helpers.rb +142 -0
- data/lib/wordmove/actions/put_file.rb +48 -0
- data/lib/wordmove/actions/run_after_pull_hook.rb +26 -0
- data/lib/wordmove/actions/run_after_push_hook.rb +26 -0
- data/lib/wordmove/actions/run_before_pull_hook.rb +26 -0
- data/lib/wordmove/actions/run_before_push_hook.rb +26 -0
- data/lib/wordmove/actions/run_local_command.rb +34 -0
- data/lib/wordmove/actions/setup_context_for_db.rb +78 -0
- data/lib/wordmove/actions/ssh/backup_remote_db.rb +51 -0
- data/lib/wordmove/actions/ssh/cleanup_after_adapt.rb +56 -0
- data/lib/wordmove/actions/ssh/download_remote_db.rb +83 -0
- data/lib/wordmove/actions/ssh/get_directory.rb +76 -0
- data/lib/wordmove/actions/ssh/helpers.rb +128 -0
- data/lib/wordmove/actions/ssh/pull_wordpress.rb +56 -0
- data/lib/wordmove/actions/ssh/push_wordpress.rb +54 -0
- data/lib/wordmove/actions/ssh/put_and_import_dump_remotely.rb +77 -0
- data/lib/wordmove/actions/ssh/put_directory.rb +76 -0
- data/lib/wordmove/actions/ssh/run_remote_command.rb +39 -0
- data/lib/wordmove/assets/dump.php.erb +6 -6
- data/lib/wordmove/assets/import.php.erb +7 -7
- data/lib/wordmove/assets/wordmove_schema_global.yml +2 -0
- data/lib/wordmove/assets/wordmove_schema_remote.yml +2 -2
- data/lib/wordmove/cli.rb +152 -91
- data/lib/wordmove/db_paths_config.rb +44 -0
- data/lib/wordmove/doctor/movefile.rb +8 -8
- data/lib/wordmove/doctor/mysql.rb +18 -15
- data/lib/wordmove/doctor/rsync.rb +2 -2
- data/lib/wordmove/doctor/ssh.rb +3 -3
- data/lib/wordmove/doctor/wpcli.rb +5 -5
- data/lib/wordmove/environments_list.rb +4 -4
- data/lib/wordmove/exceptions.rb +13 -0
- data/lib/wordmove/generators/movefile.rb +7 -5
- data/lib/wordmove/generators/movefile_adapter.rb +11 -5
- data/lib/wordmove/guardian.rb +5 -5
- data/lib/wordmove/hook.rb +13 -14
- data/lib/wordmove/logger.rb +11 -10
- data/lib/wordmove/movefile.rb +63 -59
- data/lib/wordmove/organizers/ftp/pull.rb +52 -0
- data/lib/wordmove/organizers/ftp/push.rb +53 -0
- data/lib/wordmove/organizers/ssh/pull.rb +52 -0
- data/lib/wordmove/organizers/ssh/push.rb +53 -0
- data/lib/wordmove/version.rb +1 -1
- data/lib/wordmove/wordpress_directory.rb +76 -8
- data/lib/wordmove/wpcli.rb +88 -0
- data/lib/wordmove.rb +33 -11
- data/wordmove.gemspec +37 -30
- metadata +139 -35
- data/lib/wordmove/deployer/base.rb +0 -193
- data/lib/wordmove/deployer/ftp.rb +0 -160
- data/lib/wordmove/deployer/ssh/default_sql_adapter.rb +0 -47
- data/lib/wordmove/deployer/ssh/wpcli_sql_adapter.rb +0 -55
- data/lib/wordmove/deployer/ssh.rb +0 -169
- data/lib/wordmove/sql_adapter/default.rb +0 -68
- data/lib/wordmove/sql_adapter/wpcli.rb +0 -54
- data/lib/wordmove/wordpress_directory/path.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 940d75a3bdf8e78dfff726d64c99c2a303ed0d0323c596df8617a1dc7d3e23ee
|
4
|
+
data.tar.gz: 5b1c355dc1bfd4111f9f1f3cabdfae9f248dd1c4437b3111d4555b70bf6ec02f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6627537b7592ba9453612c3eea7cce646ab54e8c8383c0b76fa19f6f68dd6f66a5ddb6e82739606e5a8cf5972bff566f7d5a454e9f61b46289f6a43bf543f5c0
|
7
|
+
data.tar.gz: d12311a3fdd3d48e1fe041a7c58f90337364b281e9c63bda4299fcf23e50712489949860a690c803927b77d721325f962ce9fd2de8e7934ad8217ee33559272e
|
data/.github/workflows/ruby.yml
CHANGED
@@ -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:
|
24
|
-
uses:
|
24
|
+
- name: Cache gems
|
25
|
+
uses: actions/cache@v2
|
25
26
|
with:
|
26
|
-
|
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.
|
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.
|
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
|
2
|
-
require
|
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
@@ -0,0 +1,103 @@
|
|
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
|
+
next context if context.database_task == false
|
34
|
+
|
35
|
+
context.logger.task 'Adapt local DB'
|
36
|
+
|
37
|
+
unless wp_in_path?
|
38
|
+
raise UnmetPeerDependencyError, 'WP-CLI is not installed or not in your $PATH'
|
39
|
+
end
|
40
|
+
|
41
|
+
next context if simulate?(cli_options: context.cli_options)
|
42
|
+
|
43
|
+
result = Wordmove::Actions::RunLocalCommand.execute(
|
44
|
+
cli_options: context.cli_options,
|
45
|
+
logger: context.logger,
|
46
|
+
command: mysql_dump_command(
|
47
|
+
env_db_options: context.local_options[:database],
|
48
|
+
save_to_path: context.db_paths.local.path
|
49
|
+
)
|
50
|
+
)
|
51
|
+
context.fail_and_return!(result.message) if result.failure?
|
52
|
+
|
53
|
+
if context.cli_options[:no_adapt]
|
54
|
+
context.logger.warn 'Skipping DB adapt'
|
55
|
+
else
|
56
|
+
result = Wordmove::Actions::RunLocalCommand.execute(
|
57
|
+
cli_options: context.cli_options,
|
58
|
+
logger: context.logger,
|
59
|
+
command: wpcli_search_replace_command(context, :vhost)
|
60
|
+
)
|
61
|
+
context.fail_and_return!(result.message) if result.failure?
|
62
|
+
|
63
|
+
result = Wordmove::Actions::RunLocalCommand.execute(
|
64
|
+
cli_options: context.cli_options,
|
65
|
+
logger: context.logger,
|
66
|
+
command: wpcli_search_replace_command(context, :wordpress_path)
|
67
|
+
)
|
68
|
+
context.fail_and_return!(result.message) if result.failure?
|
69
|
+
end
|
70
|
+
|
71
|
+
result = Wordmove::Actions::RunLocalCommand.execute(
|
72
|
+
cli_options: context.cli_options,
|
73
|
+
|
74
|
+
logger: context.logger,
|
75
|
+
command: mysql_dump_command(
|
76
|
+
env_db_options: context.local_options[:database],
|
77
|
+
save_to_path: context.db_paths.local.adapted_path
|
78
|
+
)
|
79
|
+
)
|
80
|
+
context.fail_and_return!(result.message) if result.failure?
|
81
|
+
|
82
|
+
if context.photocopier.is_a? Photocopier::SSH
|
83
|
+
result = Wordmove::Actions::RunLocalCommand.execute(
|
84
|
+
cli_options: context.cli_options,
|
85
|
+
logger: context.logger,
|
86
|
+
command: compress_command(file_path: context.db_paths.local.adapted_path)
|
87
|
+
)
|
88
|
+
context.fail_and_return!(result.message) if result.failure?
|
89
|
+
end
|
90
|
+
|
91
|
+
result = Wordmove::Actions::RunLocalCommand.execute(
|
92
|
+
cli_options: context.cli_options,
|
93
|
+
logger: context.logger,
|
94
|
+
command: mysql_import_command(
|
95
|
+
dump_path: context.db_paths.local.path,
|
96
|
+
env_db_options: context.local_options[:database]
|
97
|
+
)
|
98
|
+
)
|
99
|
+
context.fail_and_return!(result.message) if result.failure?
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,90 @@
|
|
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
|
+
next context if context.database_task == false
|
34
|
+
|
35
|
+
context.logger.task 'Adapt remote DB'
|
36
|
+
|
37
|
+
unless wp_in_path?
|
38
|
+
raise UnmetPeerDependencyError, 'WP-CLI is not installed or not in your $PATH'
|
39
|
+
end
|
40
|
+
|
41
|
+
next context if simulate?(cli_options: context.cli_options)
|
42
|
+
|
43
|
+
if File.exist?(context.db_paths.local.gzipped_path)
|
44
|
+
Wordmove::Actions::RunLocalCommand.execute(
|
45
|
+
cli_options: context.cli_options,
|
46
|
+
logger: context.logger,
|
47
|
+
command: uncompress_command(file_path: context.db_paths.local.gzipped_path)
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
51
|
+
unless File.exist?(context.db_paths.local.path)
|
52
|
+
context.fail_and_return!(
|
53
|
+
"Cannot find the dump file to adapt in #{context.db_paths.local.path}"
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
result = Wordmove::Actions::RunLocalCommand.execute(
|
58
|
+
cli_options: context.cli_options,
|
59
|
+
logger: context.logger,
|
60
|
+
command: mysql_import_command(
|
61
|
+
dump_path: context.db_paths.local.path,
|
62
|
+
env_db_options: context.local_options[:database]
|
63
|
+
)
|
64
|
+
)
|
65
|
+
context.fail_and_return!(result.message) if result.failure?
|
66
|
+
|
67
|
+
if context.cli_options[:no_adapt]
|
68
|
+
context.logger.warn 'Skipping DB adapt'
|
69
|
+
next context
|
70
|
+
end
|
71
|
+
|
72
|
+
result = Wordmove::Actions::RunLocalCommand.execute(
|
73
|
+
cli_options: context.cli_options,
|
74
|
+
logger: context.logger,
|
75
|
+
command: wpcli_search_replace_command(context, :vhost)
|
76
|
+
)
|
77
|
+
context.fail_and_return!(result.message) if result.failure?
|
78
|
+
|
79
|
+
result = Wordmove::Actions::RunLocalCommand.execute(
|
80
|
+
cli_options: context.cli_options,
|
81
|
+
logger: context.logger,
|
82
|
+
command: wpcli_search_replace_command(context, :wordpress_path)
|
83
|
+
)
|
84
|
+
context.fail_and_return!(result.message) if result.failure?
|
85
|
+
|
86
|
+
context.logger.success 'Local DB adapted'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,58 @@
|
|
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| # rubocop:disable Metrics/BlockLength
|
24
|
+
next context if context.database_task == false
|
25
|
+
|
26
|
+
context.logger.task 'Backup local DB'
|
27
|
+
|
28
|
+
if simulate?(cli_options: context.cli_options)
|
29
|
+
context.logger.info 'A backup of the local DB would have been saved into ' \
|
30
|
+
"#{context.db_paths.backup.local.gzipped_path}, " \
|
31
|
+
'but you\'re simulating'
|
32
|
+
next context
|
33
|
+
end
|
34
|
+
|
35
|
+
result = Wordmove::Actions::RunLocalCommand.execute(
|
36
|
+
cli_options: context.cli_options,
|
37
|
+
logger: context.logger,
|
38
|
+
command: mysql_dump_command(
|
39
|
+
env_db_options: context.local_options[:database],
|
40
|
+
save_to_path: context.db_paths.backup.local.path
|
41
|
+
)
|
42
|
+
)
|
43
|
+
context.fail_and_return!(result.message) if result.failure?
|
44
|
+
|
45
|
+
result = Wordmove::Actions::RunLocalCommand.execute(
|
46
|
+
cli_options: context.cli_options,
|
47
|
+
logger: context.logger,
|
48
|
+
command: compress_command(file_path: context.db_paths.backup.local.path)
|
49
|
+
)
|
50
|
+
context.fail_and_return!(result.message) if result.failure?
|
51
|
+
|
52
|
+
context.logger.success(
|
53
|
+
"Backup saved at #{context.db_paths.backup.local.gzipped_path}"
|
54
|
+
)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
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,56 @@
|
|
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
|
+
next context if context.database_task == false
|
25
|
+
|
26
|
+
context.logger.task 'Backup remote DB'
|
27
|
+
|
28
|
+
if simulate?(cli_options: context.cli_options)
|
29
|
+
context.logger.info 'A backup of the remote DB would have been saved into ' \
|
30
|
+
"#{context.db_paths.backup.remote.gzipped_path}, " \
|
31
|
+
'but you\'re simulating'
|
32
|
+
next context
|
33
|
+
end
|
34
|
+
|
35
|
+
begin
|
36
|
+
result = Wordmove::Actions::RunLocalCommand.execute(
|
37
|
+
logger: context.logger,
|
38
|
+
cli_options: context.cli_options,
|
39
|
+
command: compress_command(file_path: context.db_paths.local.path)
|
40
|
+
)
|
41
|
+
raise(result.message) if result.failure?
|
42
|
+
|
43
|
+
FileUtils.mv(
|
44
|
+
context.db_paths.local.gzipped_path,
|
45
|
+
context.db_paths.backup.remote.gzipped_path
|
46
|
+
)
|
47
|
+
|
48
|
+
context.logger.success("Backup saved at #{context.db_paths.backup.remote.gzipped_path}")
|
49
|
+
rescue Errno::ENOENT, RuntimeError => e
|
50
|
+
context.fail_and_return!("Remote DB backup failed with: <#{e.message}>. Aborting.")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,72 @@
|
|
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
|
+
next context if context.database_task == false
|
23
|
+
|
24
|
+
context.logger.task 'Cleanup'
|
25
|
+
|
26
|
+
if simulate?(cli_options: context.cli_options)
|
27
|
+
context.logger.info 'No cleanup during simulation'
|
28
|
+
next context
|
29
|
+
end
|
30
|
+
|
31
|
+
result = Wordmove::Actions::DeleteLocalFile.execute(
|
32
|
+
logger: context.logger,
|
33
|
+
cli_options: context.cli_options,
|
34
|
+
file_path: context.db_paths.local.path
|
35
|
+
)
|
36
|
+
|
37
|
+
if result.failure?
|
38
|
+
context.logger.warning 'Failed to delete local file ' \
|
39
|
+
"#{context.db_paths.local.path} because: " \
|
40
|
+
"#{result.message}" \
|
41
|
+
'. Manual intervention required'
|
42
|
+
end
|
43
|
+
|
44
|
+
[
|
45
|
+
context.db_paths.ftp.remote.dump_script_path,
|
46
|
+
context.db_paths.ftp.remote.import_script_path,
|
47
|
+
context.db_paths.remote.path,
|
48
|
+
context.db_paths.ftp.remote.dumped_path
|
49
|
+
].each do |file|
|
50
|
+
begin
|
51
|
+
result = Wordmove::Actions::DeleteRemoteFile.execute(
|
52
|
+
photocopier: context.photocopier,
|
53
|
+
logger: context.logger,
|
54
|
+
cli_options: context.cli_options,
|
55
|
+
remote_file: file
|
56
|
+
)
|
57
|
+
rescue Net::FTPPermError => _e
|
58
|
+
context.logger.info "#{file} doesn't exist remotely. Nothing to cleanup"
|
59
|
+
end
|
60
|
+
|
61
|
+
if result.failure? # rubocop:disable Style/Next
|
62
|
+
context.logger.warning 'Failed to delete remote file ' \
|
63
|
+
"#{file} because: " \
|
64
|
+
"#{result.message}" \
|
65
|
+
'. Manual intervention required'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|