From 9ddbc04298ab6465562aafe95fd9d35712cb5ef2 Mon Sep 17 00:00:00 2001 From: Alessandro Fazzi Date: Tue, 13 Feb 2018 13:36:38 +0100 Subject: [PATCH 1/3] improve doctor mysql to check both server and database connection --- lib/wordmove/doctor/mysql.rb | 53 ++++++++++++++++++++++++++---------- spec/doctor/mysql_spec.rb | 6 ++++ 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/lib/wordmove/doctor/mysql.rb b/lib/wordmove/doctor/mysql.rb index 41ddfea..be1e5e4 100644 --- a/lib/wordmove/doctor/mysql.rb +++ b/lib/wordmove/doctor/mysql.rb @@ -20,6 +20,7 @@ def check! mysql_client_doctor mysqldump_doctor mysql_server_doctor + mysql_database_doctor end private @@ -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 diff --git a/spec/doctor/mysql_spec.rb b/spec/doctor/mysql_spec.rb index 4ccfbb0..cc2df56 100644 --- a/spec/doctor/mysql_spec.rb +++ b/spec/doctor/mysql_spec.rb @@ -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 From 664c0850859af87815f969abc7d464d997d1e914 Mon Sep 17 00:00:00 2001 From: Alessandro Fazzi Date: Tue, 13 Feb 2018 13:37:47 +0100 Subject: [PATCH 2/3] doctor wpcli discerns not_installed from not_up_to_date errors --- lib/wordmove/doctor/wpcli.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/wordmove/doctor/wpcli.rb b/lib/wordmove/doctor/wpcli.rb index def4f54..4a16a73 100644 --- a/lib/wordmove/doctor/wpcli.rb +++ b/lib/wordmove/doctor/wpcli.rb @@ -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 From 6fb3525fb5340a4244d208a3a9f6b1a15d949015 Mon Sep 17 00:00:00 2001 From: Alessandro Fazzi Date: Tue, 13 Feb 2018 13:37:57 +0100 Subject: [PATCH 3/3] bump version --- lib/wordmove/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/wordmove/version.rb b/lib/wordmove/version.rb index c284080..c65b5f7 100644 --- a/lib/wordmove/version.rb +++ b/lib/wordmove/version.rb @@ -1,3 +1,3 @@ module Wordmove - VERSION = "2.4.4".freeze + VERSION = "2.5.0".freeze end