wordmove 5.2.1 → 6.0.0.alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) 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 +103 -0
  10. data/lib/wordmove/actions/adapt_remote_db.rb +90 -0
  11. data/lib/wordmove/actions/backup_local_db.rb +58 -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 +56 -0
  16. data/lib/wordmove/actions/ftp/cleanup_after_adapt.rb +72 -0
  17. data/lib/wordmove/actions/ftp/download_remote_db.rb +71 -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 +83 -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 +78 -0
  33. data/lib/wordmove/actions/ssh/backup_remote_db.rb +51 -0
  34. data/lib/wordmove/actions/ssh/cleanup_after_adapt.rb +56 -0
  35. data/lib/wordmove/actions/ssh/download_remote_db.rb +83 -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 +77 -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/assets/wordmove_schema_remote.yml +2 -2
  47. data/lib/wordmove/cli.rb +152 -91
  48. data/lib/wordmove/db_paths_config.rb +44 -0
  49. data/lib/wordmove/doctor/movefile.rb +8 -8
  50. data/lib/wordmove/doctor/mysql.rb +18 -15
  51. data/lib/wordmove/doctor/rsync.rb +2 -2
  52. data/lib/wordmove/doctor/ssh.rb +3 -3
  53. data/lib/wordmove/doctor/wpcli.rb +5 -5
  54. data/lib/wordmove/environments_list.rb +4 -4
  55. data/lib/wordmove/exceptions.rb +13 -0
  56. data/lib/wordmove/generators/movefile.rb +7 -5
  57. data/lib/wordmove/generators/movefile_adapter.rb +11 -5
  58. data/lib/wordmove/guardian.rb +5 -5
  59. data/lib/wordmove/hook.rb +13 -14
  60. data/lib/wordmove/logger.rb +11 -10
  61. data/lib/wordmove/movefile.rb +63 -59
  62. data/lib/wordmove/organizers/ftp/pull.rb +52 -0
  63. data/lib/wordmove/organizers/ftp/push.rb +53 -0
  64. data/lib/wordmove/organizers/ssh/pull.rb +52 -0
  65. data/lib/wordmove/organizers/ssh/push.rb +53 -0
  66. data/lib/wordmove/version.rb +1 -1
  67. data/lib/wordmove/wordpress_directory.rb +76 -8
  68. data/lib/wordmove/wpcli.rb +88 -0
  69. data/lib/wordmove.rb +33 -11
  70. data/wordmove.gemspec +37 -30
  71. metadata +139 -35
  72. data/lib/wordmove/deployer/base.rb +0 -193
  73. data/lib/wordmove/deployer/ftp.rb +0 -160
  74. data/lib/wordmove/deployer/ssh/default_sql_adapter.rb +0 -47
  75. data/lib/wordmove/deployer/ssh/wpcli_sql_adapter.rb +0 -55
  76. data/lib/wordmove/deployer/ssh.rb +0 -169
  77. data/lib/wordmove/sql_adapter/default.rb +0 -68
  78. data/lib/wordmove/sql_adapter/wpcli.rb +0 -54
  79. data/lib/wordmove/wordpress_directory/path.rb +0 -11
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wordmove
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.1
4
+ version: 6.0.0.alpha.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Verna
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: exe
14
14
  cert_chain: []
15
- date: 2020-12-13 00:00:00.000000000 Z
15
+ date: 2021-12-27 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activesupport
@@ -57,81 +57,109 @@ dependencies:
57
57
  - !ruby/object:Gem::Version
58
58
  version: 2.7.5
59
59
  - !ruby/object:Gem::Dependency
60
- name: kwalify
60
+ name: dry-configurable
61
61
  requirement: !ruby/object:Gem::Requirement
62
62
  requirements:
63
63
  - - "~>"
64
64
  - !ruby/object:Gem::Version
65
- version: '0'
65
+ version: 0.13.0
66
66
  type: :runtime
67
67
  prerelease: false
68
68
  version_requirements: !ruby/object:Gem::Requirement
69
69
  requirements:
70
70
  - - "~>"
71
71
  - !ruby/object:Gem::Version
72
- version: '0'
72
+ version: 0.13.0
73
73
  - !ruby/object:Gem::Dependency
74
- name: photocopier
74
+ name: kwalify
75
75
  requirement: !ruby/object:Gem::Requirement
76
76
  requirements:
77
- - - ">="
77
+ - - "~>"
78
78
  - !ruby/object:Gem::Version
79
- version: 1.4.0
79
+ version: 0.7.2
80
+ type: :runtime
81
+ prerelease: false
82
+ version_requirements: !ruby/object:Gem::Requirement
83
+ requirements:
80
84
  - - "~>"
81
85
  - !ruby/object:Gem::Version
82
- version: '1.4'
86
+ version: 0.7.2
87
+ - !ruby/object:Gem::Dependency
88
+ name: light-service
89
+ requirement: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - "~>"
92
+ - !ruby/object:Gem::Version
93
+ version: 0.17.0
83
94
  type: :runtime
84
95
  prerelease: false
85
96
  version_requirements: !ruby/object:Gem::Requirement
86
97
  requirements:
98
+ - - "~>"
99
+ - !ruby/object:Gem::Version
100
+ version: 0.17.0
101
+ - !ruby/object:Gem::Dependency
102
+ name: photocopier
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
106
+ - !ruby/object:Gem::Version
107
+ version: '1.4'
87
108
  - - ">="
88
109
  - !ruby/object:Gem::Version
89
110
  version: 1.4.0
111
+ type: :runtime
112
+ prerelease: false
113
+ version_requirements: !ruby/object:Gem::Requirement
114
+ requirements:
90
115
  - - "~>"
91
116
  - !ruby/object:Gem::Version
92
117
  version: '1.4'
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: 1.4.0
93
121
  - !ruby/object:Gem::Dependency
94
- name: thor
122
+ name: dry-cli
95
123
  requirement: !ruby/object:Gem::Requirement
96
124
  requirements:
97
125
  - - "~>"
98
126
  - !ruby/object:Gem::Version
99
- version: 0.20.3
127
+ version: 0.7.0
100
128
  type: :runtime
101
129
  prerelease: false
102
130
  version_requirements: !ruby/object:Gem::Requirement
103
131
  requirements:
104
132
  - - "~>"
105
133
  - !ruby/object:Gem::Version
106
- version: 0.20.3
134
+ version: 0.7.0
107
135
  - !ruby/object:Gem::Dependency
108
- name: bundler
136
+ name: dry-files
109
137
  requirement: !ruby/object:Gem::Requirement
110
138
  requirements:
111
139
  - - "~>"
112
140
  - !ruby/object:Gem::Version
113
- version: '2.0'
114
- type: :development
141
+ version: 0.1.0
142
+ type: :runtime
115
143
  prerelease: false
116
144
  version_requirements: !ruby/object:Gem::Requirement
117
145
  requirements:
118
146
  - - "~>"
119
147
  - !ruby/object:Gem::Version
120
- version: '2.0'
148
+ version: 0.1.0
121
149
  - !ruby/object:Gem::Dependency
122
- name: priscilla
150
+ name: bundler
123
151
  requirement: !ruby/object:Gem::Requirement
124
152
  requirements:
125
153
  - - "~>"
126
154
  - !ruby/object:Gem::Version
127
- version: '1.0'
155
+ version: 2.3.3
128
156
  type: :development
129
157
  prerelease: false
130
158
  version_requirements: !ruby/object:Gem::Requirement
131
159
  requirements:
132
160
  - - "~>"
133
161
  - !ruby/object:Gem::Version
134
- version: '1.0'
162
+ version: 2.3.3
135
163
  - !ruby/object:Gem::Dependency
136
164
  name: pry-byebug
137
165
  requirement: !ruby/object:Gem::Requirement
@@ -180,28 +208,70 @@ dependencies:
180
208
  requirements:
181
209
  - - "~>"
182
210
  - !ruby/object:Gem::Version
183
- version: 0.76.0
211
+ version: 1.24.0
184
212
  type: :development
185
213
  prerelease: false
186
214
  version_requirements: !ruby/object:Gem::Requirement
187
215
  requirements:
188
216
  - - "~>"
189
217
  - !ruby/object:Gem::Version
190
- version: 0.76.0
218
+ version: 1.24.0
219
+ - !ruby/object:Gem::Dependency
220
+ name: rubocop-rspec
221
+ requirement: !ruby/object:Gem::Requirement
222
+ requirements:
223
+ - - "~>"
224
+ - !ruby/object:Gem::Version
225
+ version: 2.6.0
226
+ type: :development
227
+ prerelease: false
228
+ version_requirements: !ruby/object:Gem::Requirement
229
+ requirements:
230
+ - - "~>"
231
+ - !ruby/object:Gem::Version
232
+ version: 2.6.0
191
233
  - !ruby/object:Gem::Dependency
192
234
  name: simplecov
193
235
  requirement: !ruby/object:Gem::Requirement
194
236
  requirements:
195
237
  - - "~>"
196
238
  - !ruby/object:Gem::Version
197
- version: 0.17.1
239
+ version: 0.21.2
198
240
  type: :development
199
241
  prerelease: false
200
242
  version_requirements: !ruby/object:Gem::Requirement
201
243
  requirements:
202
244
  - - "~>"
203
245
  - !ruby/object:Gem::Version
204
- version: 0.17.1
246
+ version: 0.21.2
247
+ - !ruby/object:Gem::Dependency
248
+ name: yard
249
+ requirement: !ruby/object:Gem::Requirement
250
+ requirements:
251
+ - - ">="
252
+ - !ruby/object:Gem::Version
253
+ version: '0'
254
+ type: :development
255
+ prerelease: false
256
+ version_requirements: !ruby/object:Gem::Requirement
257
+ requirements:
258
+ - - ">="
259
+ - !ruby/object:Gem::Version
260
+ version: '0'
261
+ - !ruby/object:Gem::Dependency
262
+ name: yard-activesupport-concern
263
+ requirement: !ruby/object:Gem::Requirement
264
+ requirements:
265
+ - - ">="
266
+ - !ruby/object:Gem::Version
267
+ version: '0'
268
+ type: :development
269
+ prerelease: false
270
+ version_requirements: !ruby/object:Gem::Requirement
271
+ requirements:
272
+ - - ">="
273
+ - !ruby/object:Gem::Version
274
+ version: '0'
205
275
  description: Wordmove deploys your WordPress websites at the speed of light.
206
276
  email:
207
277
  - stefano.verna@welaika.com
@@ -225,6 +295,7 @@ files:
225
295
  - ".ruby-gemset"
226
296
  - ".ruby-version"
227
297
  - ".vscode/launch.json"
298
+ - ".yardopts"
228
299
  - CHANGELOG.md
229
300
  - CONTRIBUTING.md
230
301
  - Gemfile
@@ -253,17 +324,47 @@ files:
253
324
  - deploy/deploy.sh
254
325
  - exe/wordmove
255
326
  - lib/wordmove.rb
327
+ - lib/wordmove/actions/adapt_local_db.rb
328
+ - lib/wordmove/actions/adapt_remote_db.rb
329
+ - lib/wordmove/actions/backup_local_db.rb
330
+ - lib/wordmove/actions/delete_local_file.rb
331
+ - lib/wordmove/actions/delete_remote_file.rb
332
+ - lib/wordmove/actions/filter_and_setup_tasks_to_run.rb
333
+ - lib/wordmove/actions/ftp/backup_remote_db.rb
334
+ - lib/wordmove/actions/ftp/cleanup_after_adapt.rb
335
+ - lib/wordmove/actions/ftp/download_remote_db.rb
336
+ - lib/wordmove/actions/ftp/get_directory.rb
337
+ - lib/wordmove/actions/ftp/helpers.rb
338
+ - lib/wordmove/actions/ftp/pull_wordpress.rb
339
+ - lib/wordmove/actions/ftp/push_wordpress.rb
340
+ - lib/wordmove/actions/ftp/put_and_import_dump_remotely.rb
341
+ - lib/wordmove/actions/ftp/put_directory.rb
342
+ - lib/wordmove/actions/get_file.rb
343
+ - lib/wordmove/actions/helpers.rb
344
+ - lib/wordmove/actions/put_file.rb
345
+ - lib/wordmove/actions/run_after_pull_hook.rb
346
+ - lib/wordmove/actions/run_after_push_hook.rb
347
+ - lib/wordmove/actions/run_before_pull_hook.rb
348
+ - lib/wordmove/actions/run_before_push_hook.rb
349
+ - lib/wordmove/actions/run_local_command.rb
350
+ - lib/wordmove/actions/setup_context_for_db.rb
351
+ - lib/wordmove/actions/ssh/backup_remote_db.rb
352
+ - lib/wordmove/actions/ssh/cleanup_after_adapt.rb
353
+ - lib/wordmove/actions/ssh/download_remote_db.rb
354
+ - lib/wordmove/actions/ssh/get_directory.rb
355
+ - lib/wordmove/actions/ssh/helpers.rb
356
+ - lib/wordmove/actions/ssh/pull_wordpress.rb
357
+ - lib/wordmove/actions/ssh/push_wordpress.rb
358
+ - lib/wordmove/actions/ssh/put_and_import_dump_remotely.rb
359
+ - lib/wordmove/actions/ssh/put_directory.rb
360
+ - lib/wordmove/actions/ssh/run_remote_command.rb
256
361
  - lib/wordmove/assets/dump.php.erb
257
362
  - lib/wordmove/assets/import.php.erb
258
363
  - lib/wordmove/assets/wordmove_schema_global.yml
259
364
  - lib/wordmove/assets/wordmove_schema_local.yml
260
365
  - lib/wordmove/assets/wordmove_schema_remote.yml
261
366
  - lib/wordmove/cli.rb
262
- - lib/wordmove/deployer/base.rb
263
- - lib/wordmove/deployer/ftp.rb
264
- - lib/wordmove/deployer/ssh.rb
265
- - lib/wordmove/deployer/ssh/default_sql_adapter.rb
266
- - lib/wordmove/deployer/ssh/wpcli_sql_adapter.rb
367
+ - lib/wordmove/db_paths_config.rb
267
368
  - lib/wordmove/doctor.rb
268
369
  - lib/wordmove/doctor/movefile.rb
269
370
  - lib/wordmove/doctor/mysql.rb
@@ -279,18 +380,21 @@ files:
279
380
  - lib/wordmove/hook.rb
280
381
  - lib/wordmove/logger.rb
281
382
  - lib/wordmove/movefile.rb
282
- - lib/wordmove/sql_adapter/default.rb
283
- - lib/wordmove/sql_adapter/wpcli.rb
383
+ - lib/wordmove/organizers/ftp/pull.rb
384
+ - lib/wordmove/organizers/ftp/push.rb
385
+ - lib/wordmove/organizers/ssh/pull.rb
386
+ - lib/wordmove/organizers/ssh/push.rb
284
387
  - lib/wordmove/version.rb
285
388
  - lib/wordmove/wordpress_directory.rb
286
- - lib/wordmove/wordpress_directory/path.rb
389
+ - lib/wordmove/wpcli.rb
287
390
  - pkg/wordmove-0.0.1.gem
288
391
  - pkg/wordmove-0.0.2.gem
289
392
  - wordmove.gemspec
290
393
  homepage: https://github.com/welaika/wordmove
291
394
  licenses:
292
395
  - MIT
293
- metadata: {}
396
+ metadata:
397
+ rubygems_mfa_required: 'true'
294
398
  post_install_message: |2
295
399
  Starting from version 3.0.0 `database.charset` option is no longer accepted.
296
400
  Pass the '--default-charecter-set' flag into `database.mysqldump_options` or to
@@ -309,11 +413,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
309
413
  version: 2.6.0
310
414
  required_rubygems_version: !ruby/object:Gem::Requirement
311
415
  requirements:
312
- - - ">="
416
+ - - ">"
313
417
  - !ruby/object:Gem::Version
314
- version: '0'
418
+ version: 1.3.1
315
419
  requirements: []
316
- rubygems_version: 3.0.3
420
+ rubygems_version: 3.1.2
317
421
  signing_key:
318
422
  specification_version: 4
319
423
  summary: Wordmove, Capistrano for Wordpress
@@ -1,193 +0,0 @@
1
- module Wordmove
2
- module Deployer
3
- class Base
4
- attr_reader :options
5
- attr_reader :logger
6
- attr_reader :environment
7
-
8
- class << self
9
- def deployer_for(cli_options)
10
- movefile = Wordmove::Movefile.new(cli_options[:config])
11
- movefile.load_dotenv(cli_options)
12
-
13
- options = movefile.fetch.merge! cli_options
14
- environment = movefile.environment(cli_options)
15
-
16
- return FTP.new(environment, options) if options[environment][:ftp]
17
-
18
- if options[environment][:ssh] && options[:global][:sql_adapter] == 'wpcli'
19
- return Ssh::WpcliSqlAdapter.new(environment, options)
20
- end
21
-
22
- if options[environment][:ssh] && options[:global][:sql_adapter] == 'default'
23
- return Ssh::DefaultSqlAdapter.new(environment, options)
24
- end
25
-
26
- raise NoAdapterFound, "No valid adapter found."
27
- end
28
-
29
- def current_dir
30
- '.'
31
- end
32
-
33
- def logger(secrets)
34
- Logger.new(STDOUT, secrets).tap { |l| l.level = Logger::DEBUG }
35
- end
36
- end
37
-
38
- def initialize(environment, options = {})
39
- @environment = environment.to_sym
40
- @options = options
41
-
42
- movefile_secrets = Wordmove::Movefile.new(options[:config]).secrets
43
- @logger = self.class.logger(movefile_secrets)
44
- end
45
-
46
- def push_db
47
- logger.task "Pushing Database"
48
- end
49
-
50
- def pull_db
51
- logger.task "Pulling Database"
52
- end
53
-
54
- def remote_get_directory; end
55
-
56
- def remote_put_directory; end
57
-
58
- def exclude_dir_contents(path)
59
- "#{path}/*"
60
- end
61
-
62
- def push_wordpress
63
- logger.task "Pushing wordpress core"
64
-
65
- local_path = local_options[:wordpress_path]
66
- remote_path = remote_options[:wordpress_path]
67
- exclude_wp_content = exclude_dir_contents(local_wp_content_dir.relative_path)
68
- exclude_paths = paths_to_exclude.push(exclude_wp_content)
69
-
70
- remote_put_directory(local_path, remote_path, exclude_paths)
71
- end
72
-
73
- def pull_wordpress
74
- logger.task "Pulling wordpress core"
75
-
76
- local_path = local_options[:wordpress_path]
77
- remote_path = remote_options[:wordpress_path]
78
- exclude_wp_content = exclude_dir_contents(remote_wp_content_dir.relative_path)
79
- exclude_paths = paths_to_exclude.push(exclude_wp_content)
80
-
81
- remote_get_directory(remote_path, local_path, exclude_paths)
82
- end
83
-
84
- protected
85
-
86
- def paths_to_exclude
87
- remote_options[:exclude] || []
88
- end
89
-
90
- def run(command)
91
- logger.task_step true, command
92
- return true if simulate?
93
-
94
- system(command)
95
- raise ShellCommandError, "Return code reports an error" unless $CHILD_STATUS.success?
96
- end
97
-
98
- def download(url, local_path)
99
- logger.task_step true, "download #{url} > #{local_path}"
100
-
101
- return true if simulate?
102
-
103
- File.open(local_path, 'w') do |file|
104
- file << URI.open(url).read
105
- end
106
- end
107
-
108
- def simulate?
109
- options[:simulate]
110
- end
111
-
112
- [
113
- WordpressDirectory::Path::WP_CONTENT,
114
- WordpressDirectory::Path::PLUGINS,
115
- WordpressDirectory::Path::MU_PLUGINS,
116
- WordpressDirectory::Path::THEMES,
117
- WordpressDirectory::Path::UPLOADS,
118
- WordpressDirectory::Path::LANGUAGES
119
- ].each do |type|
120
- %i[remote local].each do |location|
121
- define_method "#{location}_#{type}_dir" do
122
- options = send("#{location}_options")
123
- WordpressDirectory.new(type, options)
124
- end
125
- end
126
- end
127
-
128
- def mysql_dump_command(options, save_to_path)
129
- command = ["mysqldump"]
130
- command << "--host=#{Shellwords.escape(options[:host])}" if options[:host].present?
131
- command << "--port=#{Shellwords.escape(options[:port])}" if options[:port].present?
132
- command << "--user=#{Shellwords.escape(options[:user])}" if options[:user].present?
133
- if options[:password].present?
134
- command << "--password=#{Shellwords.escape(options[:password])}"
135
- end
136
- command << "--result-file=\"#{save_to_path}\""
137
- if options[:mysqldump_options].present?
138
- command << Shellwords.split(options[:mysqldump_options])
139
- end
140
- command << Shellwords.escape(options[:name])
141
- command.join(" ")
142
- end
143
-
144
- def mysql_import_command(dump_path, options)
145
- command = ["mysql"]
146
- command << "--host=#{Shellwords.escape(options[:host])}" if options[:host].present?
147
- command << "--port=#{Shellwords.escape(options[:port])}" if options[:port].present?
148
- command << "--user=#{Shellwords.escape(options[:user])}" if options[:user].present?
149
- if options[:password].present?
150
- command << "--password=#{Shellwords.escape(options[:password])}"
151
- end
152
- command << "--database=#{Shellwords.escape(options[:name])}"
153
- command << Shellwords.split(options[:mysql_options]) if options[:mysql_options].present?
154
- command << "--execute=\"SET autocommit=0;SOURCE #{dump_path};COMMIT\""
155
- command.join(" ")
156
- end
157
-
158
- def compress_command(path)
159
- command = ["gzip"]
160
- command << "-9"
161
- command << "-f"
162
- command << "\"#{path}\""
163
- command.join(" ")
164
- end
165
-
166
- def uncompress_command(path)
167
- command = ["gzip"]
168
- command << "-d"
169
- command << "-f"
170
- command << "\"#{path}\""
171
- command.join(" ")
172
- end
173
-
174
- def local_delete(path)
175
- logger.task_step true, "delete: '#{path}'"
176
- File.delete(path) unless simulate?
177
- end
178
-
179
- def save_local_db(local_dump_path)
180
- # dump local mysql into file
181
- run mysql_dump_command(local_options[:database], local_dump_path)
182
- end
183
-
184
- def remote_options
185
- options[environment].clone
186
- end
187
-
188
- def local_options
189
- options[:local].clone
190
- end
191
- end
192
- end
193
- end
@@ -1,160 +0,0 @@
1
- module Wordmove
2
- module Deployer
3
- class FTP < Base
4
- def initialize(environment, options)
5
- super(environment, options)
6
- ftp_options = remote_options[:ftp]
7
- @copier = Photocopier::FTP.new(ftp_options).tap { |c| c.logger = logger }
8
- end
9
-
10
- def push_db
11
- super
12
-
13
- return true if simulate?
14
-
15
- local_dump_path = local_wp_content_dir.path("dump.sql")
16
- remote_dump_path = remote_wp_content_dir.path("dump.sql")
17
- local_backup_path = local_wp_content_dir.path("remote-backup-#{Time.now.to_i}.sql")
18
-
19
- download_remote_db(local_backup_path)
20
- save_local_db(local_dump_path)
21
-
22
- # gsub sql
23
- adapt_sql(local_dump_path, local_options, remote_options)
24
- # upload it
25
- remote_put(local_dump_path, remote_dump_path)
26
-
27
- import_remote_dump
28
-
29
- # remove dump remotely
30
- remote_delete(remote_dump_path)
31
- # and locally
32
- local_delete(local_dump_path)
33
- end
34
-
35
- def pull_db
36
- super
37
-
38
- return true if simulate?
39
-
40
- local_dump_path = local_wp_content_dir.path("dump.sql")
41
- local_backup_path = local_wp_content_dir.path("local-backup-#{Time.now.to_i}.sql")
42
-
43
- save_local_db(local_backup_path)
44
- download_remote_db(local_dump_path)
45
-
46
- # gsub sql
47
- adapt_sql(local_dump_path, remote_options, local_options)
48
- # import locally
49
- run mysql_import_command(local_dump_path, local_options[:database])
50
-
51
- # and locally
52
- if options[:debug]
53
- logger.debug "Remote dump located at: #{local_dump_path}"
54
- else
55
- local_delete(local_dump_path)
56
- end
57
- end
58
-
59
- private
60
-
61
- %w[uploads themes plugins mu_plugins languages].each do |task|
62
- define_method "push_#{task}" do
63
- logger.task "Pushing #{task.titleize}"
64
- local_path = send("local_#{task}_dir").path
65
- remote_path = send("remote_#{task}_dir").path
66
- remote_put_directory(local_path, remote_path, paths_to_exclude)
67
- end
68
-
69
- define_method "pull_#{task}" do
70
- logger.task "Pulling #{task.titleize}"
71
- local_path = send("local_#{task}_dir").path
72
- remote_path = send("remote_#{task}_dir").path
73
- remote_get_directory(remote_path, local_path, paths_to_exclude)
74
- end
75
- end
76
-
77
- %w[get get_directory put_directory delete].each do |command|
78
- define_method "remote_#{command}" do |*args|
79
- logger.task_step false, "#{command}: #{args.join(' ')}"
80
- @copier.send(command, *args) unless simulate?
81
- end
82
- end
83
-
84
- def remote_put(thing, path)
85
- if File.exist?(thing)
86
- logger.task_step false, "copying #{thing} to #{path}"
87
- else
88
- logger.task_step false, "write #{path}"
89
- end
90
- @copier.put(thing, path) unless simulate?
91
- end
92
-
93
- def escape_php(string)
94
- return '' unless string
95
-
96
- # replaces \ with \\
97
- # replaces ' with \'
98
- string.gsub('\\', '\\\\\\').gsub(/[']/, '\\\\\'')
99
- end
100
-
101
- def generate_dump_script(db, password)
102
- template = ERB.new File.read(File.join(File.dirname(__FILE__), "../assets/dump.php.erb"))
103
- template.result(binding)
104
- end
105
-
106
- def generate_import_script(db, password)
107
- template = ERB.new File.read(File.join(File.dirname(__FILE__), "../assets/import.php.erb"))
108
- template.result(binding)
109
- end
110
-
111
- def download_remote_db(local_dump_path)
112
- remote_dump_script = remote_wp_content_dir.path("dump.php")
113
- # generate a secure one-time password
114
- one_time_password = SecureRandom.hex(40)
115
- # generate dump script
116
- dump_script = generate_dump_script(remote_options[:database], one_time_password)
117
- # upload the dump script
118
- remote_put(dump_script, remote_dump_script)
119
- # download the resulting dump (using the password)
120
- dump_url = "#{remote_wp_content_dir.url('dump.php')}?shared_key=#{one_time_password}"
121
- download(dump_url, local_dump_path)
122
- # cleanup remotely
123
- remote_delete(remote_dump_script)
124
- remote_delete(remote_wp_content_dir.path("dump.mysql"))
125
- end
126
-
127
- def import_remote_dump
128
- temp_path = local_wp_content_dir.path("log.html")
129
- remote_import_script_path = remote_wp_content_dir.path("import.php")
130
- # generate a secure one-time password
131
- one_time_password = SecureRandom.hex(40)
132
- # generate import script
133
- import_script = generate_import_script(remote_options[:database], one_time_password)
134
- # upload import script
135
- remote_put(import_script, remote_import_script_path)
136
- # run import script
137
- import_url = [
138
- remote_wp_content_dir.url('import.php').to_s,
139
- "?shared_key=#{one_time_password}",
140
- "&start=1&foffset=0&totalqueries=0&fn=dump.sql"
141
- ].join
142
- download(import_url, temp_path)
143
- if options[:debug]
144
- logger.debug "Operation log located at: #{temp_path}"
145
- else
146
- local_delete(temp_path)
147
- end
148
- # remove script remotely
149
- remote_delete(remote_import_script_path)
150
- end
151
-
152
- def adapt_sql(save_to_path, local, remote)
153
- return if options[:no_adapt]
154
-
155
- logger.task_step true, "Adapt dump"
156
- SqlAdapter::Default.new(save_to_path, local, remote).adapt! unless simulate?
157
- end
158
- end
159
- end
160
- end