Skip to content

Commit

Permalink
Merge pull request #457 from welaika/doctor_improvements
Browse files Browse the repository at this point in the history
Doctor improvements
  • Loading branch information
alessandro-fazzi authored Feb 13, 2018
2 parents d97f568 + 6fb3525 commit cd93412
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 18 deletions.
53 changes: 39 additions & 14 deletions lib/wordmove/doctor/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def check!
mysql_client_doctor
mysqldump_doctor
mysql_server_doctor
mysql_database_doctor
end

private
Expand All @@ -41,30 +42,54 @@ def mysqldump_doctor
end

def mysql_server_doctor
command = ["mysql"]
command << "--host=#{Shellwords.escape(config[:host])}" if config[:host].present?
command << "--port=#{Shellwords.escape(config[:port])}" if config[:port].present?
command << "--user=#{Shellwords.escape(config[:user])}" if config[:user].present?
if config[:password].present?
command << "--password=#{Shellwords.escape(config[:password])}"
command = mysql_command

if system(command, out: File::NULL, err: File::NULL)
logger.success "Successfully connected to the MySQL server"
else
logger.error <<-LONG
We can't connect to the MySQL server using credentials
specified in the Movefile. Double check them or try
to debug your system configuration.
The command used to test was:
#{command}
LONG
end
command << "-e'QUIT'"
command = command.join(" ")
end

def mysql_database_doctor
command = mysql_command(database: config[:name])

if system(command, out: File::NULL, err: File::NULL)
logger.success "Successfully connected to the database"
else
logger.error <<~LONG
We can't connect to the database using credentials
specified in the Movefile. Double check them or try
to debug your system configuration.
logger.error <<-LONG
We can't connect to the database using credentials
specified in the Movefile, or the database does not
exists. Double check them or try to debug your
system configuration.
The command used to test was:
The command used to test was:
#{command}
#{command}
LONG
end
end

def mysql_command(database: nil)
command = ["mysql"]
command << "--host=#{Shellwords.escape(config[:host])}" if config[:host].present?
command << "--port=#{Shellwords.escape(config[:port])}" if config[:port].present?
command << "--user=#{Shellwords.escape(config[:user])}" if config[:user].present?
if config[:password].present?
command << "--password=#{Shellwords.escape(config[:password])}"
end
command << database if database.present?
command << "-e'QUIT'"
command.join(" ")
end
end
end
end
18 changes: 15 additions & 3 deletions lib/wordmove/doctor/wpcli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,22 @@ def initialize
def check!
logger.task "Checking local wp-cli installation"

if in_path? && up_to_date?
logger.success "wp-cli is correctly installed and up to date"
if in_path?
logger.success "wp-cli is correctly installed"

if up_to_date?
logger.success "wp-cli is up to date"
else
logger.error <<-LONG
wp-cli is not up to date.
Use `wp cli update` to update to the latest version.
LONG
end
else
logger.error "wp-cli is not installed (or not in your $PATH) or not up to date"
logger.error <<-LONG
wp-cli is not installed (or not in your $PATH).
Read http://wp-cli.org/#installing for installation info.
LONG
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/wordmove/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Wordmove
VERSION = "2.4.4".freeze
VERSION = "2.5.0".freeze
end
6 changes: 6 additions & 0 deletions spec/doctor/mysql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,11 @@

silence_stream(STDOUT) { doctor.check! }
end

it "calls mysql database check" do
# expect(doctor).to receive(:mysql_database_doctor)

silence_stream(STDOUT) { doctor.check! }
end
end
end

0 comments on commit cd93412

Please sign in to comment.