wordmove 2.0.2 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +10 -1
- data/.travis.yml +1 -4
- data/.vscode/launch.json +73 -0
- data/README.mdown +21 -5
- data/lib/wordmove/assets/import.php.erb +123 -125
- data/lib/wordmove/cli.rb +2 -2
- data/lib/wordmove/deployer/base.rb +22 -20
- data/lib/wordmove/deployer/ftp.rb +1 -1
- data/lib/wordmove/deployer/ssh/default_sql_adapter.rb +47 -0
- data/lib/wordmove/deployer/ssh/wpcli_sql_adapter.rb +54 -0
- data/lib/wordmove/deployer/ssh.rb +30 -34
- data/lib/wordmove/exceptions.rb +2 -0
- data/lib/wordmove/generators/Movefile +4 -1
- data/lib/wordmove/sql_adapter/default.rb +68 -0
- data/lib/wordmove/sql_adapter/wpcli.rb +21 -0
- data/lib/wordmove/version.rb +1 -1
- data/lib/wordmove.rb +4 -1
- data/wordmove.gemspec +7 -4
- metadata +14 -12
- data/lib/wordmove/sql_adapter.rb +0 -66
data/lib/wordmove/cli.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Wordmove
|
2
2
|
class CLI < Thor
|
3
|
-
map %w
|
3
|
+
map %w[--version -v] => :__print_version
|
4
4
|
|
5
5
|
desc "--version, -v", "Print the version"
|
6
6
|
def __print_version
|
@@ -39,7 +39,7 @@ module Wordmove
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def wordpress_options
|
42
|
-
%w
|
42
|
+
%w[wordpress uploads themes plugins mu_plugins languages db]
|
43
43
|
end
|
44
44
|
|
45
45
|
def ensure_wordpress_options_presence!(options)
|
@@ -20,12 +20,20 @@ module Wordmove
|
|
20
20
|
environment = (options[:environment] || available_enviroments.first).to_sym
|
21
21
|
|
22
22
|
return FTP.new(environment, options) if options[environment][:ftp]
|
23
|
-
|
23
|
+
|
24
|
+
if options[environment][:ssh] && options[:global][:sql_adapter] == 'wpcli'
|
25
|
+
return Ssh::WpcliSqlAdapter.new(environment, options)
|
26
|
+
end
|
27
|
+
|
28
|
+
if options[environment][:ssh] && options[:global][:sql_adapter] == 'default'
|
29
|
+
return Ssh::DefaultSqlAdapter.new(environment, options)
|
30
|
+
end
|
31
|
+
|
24
32
|
raise NoAdapterFound, "No valid adapter found."
|
25
33
|
end
|
26
34
|
|
27
35
|
def extract_available_envs(options)
|
28
|
-
options.keys.map(&:to_sym) - [
|
36
|
+
options.keys.map(&:to_sym) - %i[local global]
|
29
37
|
end
|
30
38
|
|
31
39
|
def fetch_movefile(name = nil, start_dir = current_dir)
|
@@ -39,7 +47,7 @@ module Wordmove
|
|
39
47
|
|
40
48
|
found = entries.first
|
41
49
|
logger.task("Using Movefile: #{found}")
|
42
|
-
YAML.
|
50
|
+
YAML.safe_load(ERB.new(File.read(found)).result)
|
43
51
|
end
|
44
52
|
|
45
53
|
def current_dir
|
@@ -77,7 +85,7 @@ module Wordmove
|
|
77
85
|
|
78
86
|
def remote_put_directory(directory); end
|
79
87
|
|
80
|
-
%w
|
88
|
+
%w[uploads themes plugins mu_plugins languages].each do |task|
|
81
89
|
define_method "push_#{task}" do
|
82
90
|
logger.task "Pushing #{task.titleize}"
|
83
91
|
local_path = send("local_#{task}_dir").path
|
@@ -127,18 +135,19 @@ module Wordmove
|
|
127
135
|
|
128
136
|
def run(command)
|
129
137
|
logger.task_step true, command
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
138
|
+
return true if simulate?
|
139
|
+
|
140
|
+
system(command)
|
141
|
+
raise ShellCommandError, "Return code reports an error" unless $CHILD_STATUS.success?
|
134
142
|
end
|
135
143
|
|
136
144
|
def download(url, local_path)
|
137
145
|
logger.task_step true, "download #{url} > #{local_path}"
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
146
|
+
|
147
|
+
return true if simulate?
|
148
|
+
|
149
|
+
open(local_path, 'w') do |file|
|
150
|
+
file << open(url).read
|
142
151
|
end
|
143
152
|
end
|
144
153
|
|
@@ -154,7 +163,7 @@ module Wordmove
|
|
154
163
|
WordpressDirectory::Path::UPLOADS,
|
155
164
|
WordpressDirectory::Path::LANGUAGES
|
156
165
|
].each do |type|
|
157
|
-
[
|
166
|
+
%i[remote local].each do |location|
|
158
167
|
define_method "#{location}_#{type}_dir" do
|
159
168
|
options = send("#{location}_options")
|
160
169
|
WordpressDirectory.new(type, options)
|
@@ -162,13 +171,6 @@ module Wordmove
|
|
162
171
|
end
|
163
172
|
end
|
164
173
|
|
165
|
-
def adapt_sql(save_to_path, local, remote)
|
166
|
-
unless options[:no_adapt]
|
167
|
-
logger.task_step true, "adapt dump"
|
168
|
-
SqlAdapter.new(save_to_path, local, remote).adapt! unless simulate?
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
174
|
def mysql_dump_command(options, save_to_path)
|
173
175
|
command = ["mysqldump"]
|
174
176
|
command << "--host=#{Shellwords.escape(options[:host])}" if options[:host].present?
|
@@ -53,7 +53,7 @@ module Wordmove
|
|
53
53
|
|
54
54
|
private
|
55
55
|
|
56
|
-
%w
|
56
|
+
%w[get get_directory put_directory delete].each do |command|
|
57
57
|
define_method "remote_#{command}" do |*args|
|
58
58
|
logger.task_step false, "#{command}: #{args.join(' ')}"
|
59
59
|
@copier.send(command, *args) unless simulate?
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Wordmove
|
2
|
+
module Deployer
|
3
|
+
module Ssh
|
4
|
+
class DefaultSqlAdapter < SSH
|
5
|
+
private
|
6
|
+
|
7
|
+
def backup_remote_db!
|
8
|
+
download_remote_db(local_gzipped_backup_path)
|
9
|
+
end
|
10
|
+
|
11
|
+
def adapt_local_db!
|
12
|
+
save_local_db(local_dump_path)
|
13
|
+
adapt_sql(local_dump_path, local_options, remote_options)
|
14
|
+
run compress_command(local_dump_path)
|
15
|
+
import_remote_dump(local_gzipped_dump_path)
|
16
|
+
end
|
17
|
+
|
18
|
+
def after_push_cleanup!
|
19
|
+
local_delete(local_gzipped_dump_path)
|
20
|
+
end
|
21
|
+
|
22
|
+
def backup_local_db!
|
23
|
+
save_local_db(local_backup_path)
|
24
|
+
run compress_command(local_backup_path)
|
25
|
+
end
|
26
|
+
|
27
|
+
def adapt_remote_db!
|
28
|
+
download_remote_db(local_gzipped_dump_path)
|
29
|
+
run uncompress_command(local_gzipped_dump_path)
|
30
|
+
adapt_sql(local_dump_path, remote_options, local_options)
|
31
|
+
run mysql_import_command(local_dump_path, local_options[:database])
|
32
|
+
end
|
33
|
+
|
34
|
+
def after_pull_cleanup!
|
35
|
+
local_delete(local_dump_path)
|
36
|
+
end
|
37
|
+
|
38
|
+
def adapt_sql(save_to_path, local, remote)
|
39
|
+
return if options[:no_adapt]
|
40
|
+
|
41
|
+
logger.task_step true, "Adapt dump"
|
42
|
+
SqlAdapter::Default.new(save_to_path, local, remote).adapt! unless simulate?
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Wordmove
|
2
|
+
module Deployer
|
3
|
+
module Ssh
|
4
|
+
class WpcliSqlAdapter < SSH
|
5
|
+
def backup_remote_db!
|
6
|
+
download_remote_db(local_gzipped_backup_path)
|
7
|
+
end
|
8
|
+
|
9
|
+
def adapt_local_db!
|
10
|
+
save_local_db(local_dump_path)
|
11
|
+
run wpcli_search_replace(local_options, remote_options, :vhost)
|
12
|
+
run wpcli_search_replace(local_options, remote_options, :wordpress_path)
|
13
|
+
|
14
|
+
local_search_replace_dump_path = local_wp_content_dir.path("search_replace_dump.sql")
|
15
|
+
local_gzipped_search_replace_dump_path = local_search_replace_dump_path + '.gz'
|
16
|
+
|
17
|
+
save_local_db(local_search_replace_dump_path)
|
18
|
+
run compress_command(local_search_replace_dump_path)
|
19
|
+
import_remote_dump(local_gzipped_search_replace_dump_path)
|
20
|
+
local_delete(local_gzipped_search_replace_dump_path)
|
21
|
+
run mysql_import_command(local_dump_path, local_options[:database])
|
22
|
+
end
|
23
|
+
|
24
|
+
def after_push_cleanup!
|
25
|
+
local_delete(local_dump_path)
|
26
|
+
end
|
27
|
+
|
28
|
+
def backup_local_db!
|
29
|
+
save_local_db(local_backup_path)
|
30
|
+
run compress_command(local_backup_path)
|
31
|
+
end
|
32
|
+
|
33
|
+
def adapt_remote_db!
|
34
|
+
download_remote_db(local_gzipped_dump_path)
|
35
|
+
run uncompress_command(local_gzipped_dump_path)
|
36
|
+
run mysql_import_command(local_dump_path, local_options[:database])
|
37
|
+
run wpcli_search_replace(remote_options, local_options, :vhost)
|
38
|
+
run wpcli_search_replace(remote_options, local_options, :wordpress_path)
|
39
|
+
end
|
40
|
+
|
41
|
+
def after_pull_cleanup!
|
42
|
+
local_delete(local_dump_path)
|
43
|
+
end
|
44
|
+
|
45
|
+
def wpcli_search_replace(local, remote, config_key)
|
46
|
+
return if options[:no_adapt]
|
47
|
+
|
48
|
+
logger.task_step true, "adapt dump for #{config_key}"
|
49
|
+
SqlAdapter::Wpcli.new(local, remote, config_key).command unless simulate?
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -1,49 +1,42 @@
|
|
1
1
|
module Wordmove
|
2
2
|
module Deployer
|
3
3
|
class SSH < Base
|
4
|
+
attr_reader :local_dump_path,
|
5
|
+
:local_backup_path,
|
6
|
+
:local_gzipped_dump_path,
|
7
|
+
:local_gzipped_backup_path
|
8
|
+
|
4
9
|
def initialize(environment, options)
|
5
10
|
super
|
6
11
|
ssh_options = remote_options[:ssh]
|
7
12
|
@copier = Photocopier::SSH.new(ssh_options).tap { |c| c.logger = logger }
|
13
|
+
|
14
|
+
@local_dump_path = local_wp_content_dir.path("dump.sql")
|
15
|
+
@local_backup_path = local_wp_content_dir.path("local-backup-#{Time.now.to_i}.sql")
|
16
|
+
@local_gzipped_dump_path = local_dump_path + '.gz'
|
17
|
+
@local_gzipped_backup_path = local_wp_content_dir
|
18
|
+
.path("#{environment}-backup-#{Time.now.to_i}.sql.gz")
|
8
19
|
end
|
9
20
|
|
21
|
+
protected
|
22
|
+
|
10
23
|
def push_db
|
11
24
|
super
|
12
25
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
.path("#{environment}-backup-#{Time.now.to_i}.sql.gz")
|
17
|
-
|
18
|
-
download_remote_db(local_gzipped_backup_path)
|
19
|
-
|
20
|
-
save_local_db(local_dump_path)
|
21
|
-
adapt_sql(local_dump_path, local_options, remote_options)
|
22
|
-
run compress_command(local_dump_path)
|
23
|
-
import_remote_dump(local_gzipped_dump_path)
|
24
|
-
local_delete(local_gzipped_dump_path)
|
26
|
+
backup_remote_db!
|
27
|
+
adapt_local_db!
|
28
|
+
after_push_cleanup!
|
25
29
|
end
|
26
30
|
|
27
31
|
def pull_db
|
28
32
|
super
|
29
33
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
save_local_db(local_backup_path)
|
35
|
-
run compress_command(local_backup_path)
|
36
|
-
|
37
|
-
download_remote_db(local_gzipped_dump_path)
|
38
|
-
run uncompress_command(local_gzipped_dump_path)
|
39
|
-
adapt_sql(local_dump_path, remote_options, local_options)
|
40
|
-
run mysql_import_command(local_dump_path, local_options[:database])
|
41
|
-
local_delete(local_dump_path)
|
34
|
+
backup_local_db!
|
35
|
+
adapt_remote_db!
|
36
|
+
after_pull_cleanup!
|
42
37
|
end
|
43
38
|
|
44
|
-
|
45
|
-
|
46
|
-
%w(get put get_directory put_directory delete).each do |command|
|
39
|
+
%w[get put get_directory put_directory delete].each do |command|
|
47
40
|
define_method "remote_#{command}" do |*args|
|
48
41
|
logger.task_step false, "#{command}: #{args.join(' ')}"
|
49
42
|
@copier.send(command, *args) unless simulate?
|
@@ -52,13 +45,16 @@ module Wordmove
|
|
52
45
|
|
53
46
|
def remote_run(command)
|
54
47
|
logger.task_step false, command
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
48
|
+
return true if simulate?
|
49
|
+
|
50
|
+
_stdout, stderr, exit_code = @copier.exec! command
|
51
|
+
|
52
|
+
return true if exit_code.zero?
|
53
|
+
|
54
|
+
raise(
|
55
|
+
ShellCommandError,
|
56
|
+
"Error code #{exit_code} returned by command \"#{command}\": #{stderr}"
|
57
|
+
)
|
62
58
|
end
|
63
59
|
|
64
60
|
def download_remote_db(local_gizipped_dump_path)
|
data/lib/wordmove/exceptions.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
global:
|
2
|
+
sql_adapter: "default"
|
3
|
+
|
1
4
|
local:
|
2
5
|
vhost: "http://vhost.local"
|
3
6
|
wordpress_path: "<%= wordpress_path %>" # use an absolute path here
|
@@ -30,7 +33,7 @@ production:
|
|
30
33
|
- "Gemfile*"
|
31
34
|
- "Movefile"
|
32
35
|
- "wp-config.php"
|
33
|
-
- "wp-content/*.sql"
|
36
|
+
- "wp-content/*.sql.gz"
|
34
37
|
|
35
38
|
# paths: # you can customize wordpress internal paths
|
36
39
|
# wp_content: "wp-content"
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Wordmove
|
2
|
+
module SqlAdapter
|
3
|
+
class Default
|
4
|
+
attr_accessor :sql_content
|
5
|
+
attr_reader :sql_path, :source_config, :dest_config
|
6
|
+
|
7
|
+
def initialize(sql_path, source_config, dest_config)
|
8
|
+
@sql_path = sql_path
|
9
|
+
@source_config = source_config
|
10
|
+
@dest_config = dest_config
|
11
|
+
end
|
12
|
+
|
13
|
+
def sql_content
|
14
|
+
@sql_content ||= File.open(sql_path).read
|
15
|
+
end
|
16
|
+
|
17
|
+
def adapt!
|
18
|
+
replace_vhost!
|
19
|
+
replace_wordpress_path!
|
20
|
+
write_sql!
|
21
|
+
end
|
22
|
+
|
23
|
+
def replace_vhost!
|
24
|
+
source_vhost = source_config[:vhost]
|
25
|
+
dest_vhost = dest_config[:vhost]
|
26
|
+
replace_field!(source_vhost, dest_vhost)
|
27
|
+
end
|
28
|
+
|
29
|
+
def replace_wordpress_path!
|
30
|
+
source_path = source_config[:wordpress_absolute_path] || source_config[:wordpress_path]
|
31
|
+
dest_path = dest_config[:wordpress_absolute_path] || dest_config[:wordpress_path]
|
32
|
+
replace_field!(source_path, dest_path)
|
33
|
+
end
|
34
|
+
|
35
|
+
def replace_field!(source_field, dest_field)
|
36
|
+
return false unless source_field && dest_field
|
37
|
+
|
38
|
+
serialized_replace!(source_field, dest_field)
|
39
|
+
simple_replace!(source_field, dest_field)
|
40
|
+
end
|
41
|
+
|
42
|
+
def serialized_replace!(source_field, dest_field)
|
43
|
+
length_delta = source_field.length - dest_field.length
|
44
|
+
|
45
|
+
sql_content.gsub!(/s:(\d+):([\\]*['"])(.*?)\2;/) do |_|
|
46
|
+
length = Regexp.last_match(1).to_i
|
47
|
+
delimiter = Regexp.last_match(2)
|
48
|
+
string = Regexp.last_match(3)
|
49
|
+
|
50
|
+
string.gsub!(/#{Regexp.escape(source_field)}/) do |_|
|
51
|
+
length -= length_delta
|
52
|
+
dest_field
|
53
|
+
end
|
54
|
+
|
55
|
+
%(s:#{length}:#{delimiter}#{string}#{delimiter};)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def simple_replace!(source_field, dest_field)
|
60
|
+
sql_content.gsub!(source_field, dest_field)
|
61
|
+
end
|
62
|
+
|
63
|
+
def write_sql!
|
64
|
+
File.open(sql_path, 'w') { |f| f.write(sql_content) }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Wordmove
|
2
|
+
module SqlAdapter
|
3
|
+
class Wpcli
|
4
|
+
attr_accessor :sql_content
|
5
|
+
attr_reader :from, :to
|
6
|
+
|
7
|
+
def initialize(source_config, dest_config, config_key)
|
8
|
+
@from = source_config[config_key]
|
9
|
+
@to = dest_config[config_key]
|
10
|
+
end
|
11
|
+
|
12
|
+
def command
|
13
|
+
unless system('which wp > /dev/null 2>&1')
|
14
|
+
raise UnmetPeerDependencyError, "WP-CLI is not installed or not in your $PATH"
|
15
|
+
end
|
16
|
+
|
17
|
+
"wp search-replace #{from} #{to} --quiet --skip-columns=guid --all-tables"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/wordmove/version.rb
CHANGED
data/lib/wordmove.rb
CHANGED
@@ -16,7 +16,8 @@ require 'photocopier'
|
|
16
16
|
require 'wordmove/exceptions'
|
17
17
|
require 'wordmove/cli'
|
18
18
|
require 'wordmove/logger'
|
19
|
-
require 'wordmove/sql_adapter'
|
19
|
+
require 'wordmove/sql_adapter/default'
|
20
|
+
require 'wordmove/sql_adapter/wpcli'
|
20
21
|
require "wordmove/version"
|
21
22
|
require 'wordmove/wordpress_directory'
|
22
23
|
|
@@ -26,6 +27,8 @@ require 'wordmove/generators/movefile'
|
|
26
27
|
require 'wordmove/deployer/base'
|
27
28
|
require 'wordmove/deployer/ftp'
|
28
29
|
require 'wordmove/deployer/ssh'
|
30
|
+
require 'wordmove/deployer/ssh/default_sql_adapter'
|
31
|
+
require 'wordmove/deployer/ssh/wpcli_sql_adapter'
|
29
32
|
|
30
33
|
module Wordmove
|
31
34
|
end
|
data/wordmove.gemspec
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# coding: utf-8
|
2
1
|
lib = File.expand_path('../lib', __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'wordmove/version'
|
@@ -37,18 +36,22 @@ Gem::Specification.new do |spec|
|
|
37
36
|
|
38
37
|
spec.required_ruby_version = "~> 2.4.0"
|
39
38
|
|
40
|
-
spec.add_development_dependency "bundler", "
|
39
|
+
spec.add_development_dependency "bundler", ">= 1.14.6"
|
41
40
|
spec.add_development_dependency "rake", "~> 10.0"
|
42
41
|
spec.add_development_dependency "rspec", "~> 3.3"
|
43
42
|
spec.add_development_dependency "simplecov", "~> 0.9"
|
44
43
|
spec.add_development_dependency "pry-byebug", "~> 3.1"
|
45
44
|
spec.add_development_dependency "priscilla", "~> 1.0"
|
46
|
-
spec.add_development_dependency "rubocop", "~> 0.
|
45
|
+
spec.add_development_dependency "rubocop", "~> 0.49.0"
|
47
46
|
|
48
47
|
spec.post_install_message = <<-RAINBOW
|
49
48
|
Starting from 2.0.0 Wordmove will compress SQL dumps both in remote and locale environments.
|
50
49
|
If something will broke, please check if gzip executable is present locally and
|
51
50
|
remotely. We are considering obvious it's installed in any web environment.
|
52
|
-
|
51
|
+
|
52
|
+
Starting from 2.1.0 you'll need to add the global section in your Movefile:
|
53
|
+
global:
|
54
|
+
sql_adapter: "default"
|
55
|
+
Or you can spawn a new one with `wordmove init` (backup the old one!)
|
53
56
|
RAINBOW
|
54
57
|
end
|
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: 2.0
|
4
|
+
version: 2.1.0
|
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: 2017-05-
|
15
|
+
date: 2017-05-29 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: colorize
|
@@ -86,9 +86,6 @@ dependencies:
|
|
86
86
|
name: bundler
|
87
87
|
requirement: !ruby/object:Gem::Requirement
|
88
88
|
requirements:
|
89
|
-
- - "~>"
|
90
|
-
- !ruby/object:Gem::Version
|
91
|
-
version: 1.14.6
|
92
89
|
- - ">="
|
93
90
|
- !ruby/object:Gem::Version
|
94
91
|
version: 1.14.6
|
@@ -96,9 +93,6 @@ dependencies:
|
|
96
93
|
prerelease: false
|
97
94
|
version_requirements: !ruby/object:Gem::Requirement
|
98
95
|
requirements:
|
99
|
-
- - "~>"
|
100
|
-
- !ruby/object:Gem::Version
|
101
|
-
version: 1.14.6
|
102
96
|
- - ">="
|
103
97
|
- !ruby/object:Gem::Version
|
104
98
|
version: 1.14.6
|
@@ -178,14 +172,14 @@ dependencies:
|
|
178
172
|
requirements:
|
179
173
|
- - "~>"
|
180
174
|
- !ruby/object:Gem::Version
|
181
|
-
version: 0.
|
175
|
+
version: 0.49.0
|
182
176
|
type: :development
|
183
177
|
prerelease: false
|
184
178
|
version_requirements: !ruby/object:Gem::Requirement
|
185
179
|
requirements:
|
186
180
|
- - "~>"
|
187
181
|
- !ruby/object:Gem::Version
|
188
|
-
version: 0.
|
182
|
+
version: 0.49.0
|
189
183
|
description: Wordmove deploys your WordPress websites at the speed of light.
|
190
184
|
email:
|
191
185
|
- stefano.verna@welaika.com
|
@@ -204,6 +198,7 @@ files:
|
|
204
198
|
- ".ruby-gemset"
|
205
199
|
- ".ruby-version"
|
206
200
|
- ".travis.yml"
|
201
|
+
- ".vscode/launch.json"
|
207
202
|
- CHANGELOG.md
|
208
203
|
- Gemfile
|
209
204
|
- README.mdown
|
@@ -221,12 +216,15 @@ files:
|
|
221
216
|
- lib/wordmove/deployer/base.rb
|
222
217
|
- lib/wordmove/deployer/ftp.rb
|
223
218
|
- lib/wordmove/deployer/ssh.rb
|
219
|
+
- lib/wordmove/deployer/ssh/default_sql_adapter.rb
|
220
|
+
- lib/wordmove/deployer/ssh/wpcli_sql_adapter.rb
|
224
221
|
- lib/wordmove/exceptions.rb
|
225
222
|
- lib/wordmove/generators/Movefile
|
226
223
|
- lib/wordmove/generators/movefile.rb
|
227
224
|
- lib/wordmove/generators/movefile_adapter.rb
|
228
225
|
- lib/wordmove/logger.rb
|
229
|
-
- lib/wordmove/sql_adapter.rb
|
226
|
+
- lib/wordmove/sql_adapter/default.rb
|
227
|
+
- lib/wordmove/sql_adapter/wpcli.rb
|
230
228
|
- lib/wordmove/version.rb
|
231
229
|
- lib/wordmove/wordpress_directory.rb
|
232
230
|
- lib/wordmove/wordpress_directory/path.rb
|
@@ -241,7 +239,11 @@ post_install_message: |2
|
|
241
239
|
Starting from 2.0.0 Wordmove will compress SQL dumps both in remote and locale environments.
|
242
240
|
If something will broke, please check if gzip executable is present locally and
|
243
241
|
remotely. We are considering obvious it's installed in any web environment.
|
244
|
-
|
242
|
+
|
243
|
+
Starting from 2.1.0 you'll need to add the global section in your Movefile:
|
244
|
+
global:
|
245
|
+
sql_adapter: "default"
|
246
|
+
Or you can spawn a new one with `wordmove init` (backup the old one!)
|
245
247
|
rdoc_options: []
|
246
248
|
require_paths:
|
247
249
|
- lib
|
data/lib/wordmove/sql_adapter.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
module Wordmove
|
2
|
-
class SqlAdapter
|
3
|
-
attr_accessor :sql_content
|
4
|
-
attr_reader :sql_path, :source_config, :dest_config
|
5
|
-
|
6
|
-
def initialize(sql_path, source_config, dest_config)
|
7
|
-
@sql_path = sql_path
|
8
|
-
@source_config = source_config
|
9
|
-
@dest_config = dest_config
|
10
|
-
end
|
11
|
-
|
12
|
-
def sql_content
|
13
|
-
@sql_content ||= File.open(sql_path).read
|
14
|
-
end
|
15
|
-
|
16
|
-
def adapt!
|
17
|
-
replace_vhost!
|
18
|
-
replace_wordpress_path!
|
19
|
-
write_sql!
|
20
|
-
end
|
21
|
-
|
22
|
-
def replace_vhost!
|
23
|
-
source_vhost = source_config[:vhost]
|
24
|
-
dest_vhost = dest_config[:vhost]
|
25
|
-
replace_field!(source_vhost, dest_vhost)
|
26
|
-
end
|
27
|
-
|
28
|
-
def replace_wordpress_path!
|
29
|
-
source_path = source_config[:wordpress_absolute_path] || source_config[:wordpress_path]
|
30
|
-
dest_path = dest_config[:wordpress_absolute_path] || dest_config[:wordpress_path]
|
31
|
-
replace_field!(source_path, dest_path)
|
32
|
-
end
|
33
|
-
|
34
|
-
def replace_field!(source_field, dest_field)
|
35
|
-
if source_field && dest_field
|
36
|
-
serialized_replace!(source_field, dest_field)
|
37
|
-
simple_replace!(source_field, dest_field)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def serialized_replace!(source_field, dest_field)
|
42
|
-
length_delta = source_field.length - dest_field.length
|
43
|
-
|
44
|
-
sql_content.gsub!(/s:(\d+):([\\]*['"])(.*?)\2;/) do |_|
|
45
|
-
length = Regexp.last_match(1).to_i
|
46
|
-
delimiter = Regexp.last_match(2)
|
47
|
-
string = Regexp.last_match(3)
|
48
|
-
|
49
|
-
string.gsub!(/#{Regexp.escape(source_field)}/) do |_|
|
50
|
-
length -= length_delta
|
51
|
-
dest_field
|
52
|
-
end
|
53
|
-
|
54
|
-
%(s:#{length}:#{delimiter}#{string}#{delimiter};)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def simple_replace!(source_field, dest_field)
|
59
|
-
sql_content.gsub!(source_field, dest_field)
|
60
|
-
end
|
61
|
-
|
62
|
-
def write_sql!
|
63
|
-
File.open(sql_path, 'w') { |f| f.write(sql_content) }
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|