From 91f841a3cb9f6be7bbb933596177f5ecbec0b609 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Fri, 23 Nov 2018 18:29:03 +0530 Subject: [PATCH 1/6] Update checks in running commands Signed-off-by: Riddhesh Sanghvi --- php/EE/Runner.php | 54 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/php/EE/Runner.php b/php/EE/Runner.php index c7227ae16..74eae8b57 100644 --- a/php/EE/Runner.php +++ b/php/EE/Runner.php @@ -64,27 +64,47 @@ private function init_ee() { if ( ! empty( $this->arguments ) && - ( 'help' !== $this->arguments[0] ) - && $this->arguments !== [ 'cli', 'version' ] - ) - { + ( ! in_array( $this->arguments[0], [ 'cli', 'config', 'help' ], true ) ) + ) { + $this->check_requirements(); + $this->maybe_trigger_migration(); + } + if ( [ 'cli', 'info' ] === $this->arguments && $this->check_requirements( false ) ) { + $this->maybe_trigger_migration(); + } + } - // Minimum requirement checks. - $docker_running = 'docker ps > /dev/null'; - if ( ! EE::exec( $docker_running ) ) { - EE::error( 'docker not installed or not running.' ); - } + /** + * Check EE requirements for required commands. + * + * @param bool $show_error To display error or to retutn status. + */ + public function check_requirements( $show_error = true ) { - $docker_compose_installed = 'command -v docker-compose > /dev/null'; - if ( ! EE::exec( $docker_compose_installed ) ) { - EE::error( 'EasyEngine requires docker-compose.' ); - } + $status = true; - if ( version_compare( PHP_VERSION, '7.2.0' ) < 0 ) { - EE::error( 'EasyEngine requires minimum PHP 7.2.0 to run.' ); - } + // Minimum requirement checks. + $docker_running = 'docker ps > /dev/null'; + if ( ! EE::exec( $docker_running ) ) { + $status = false; + $error = 'Docker not installed or not running.'; + } - $this->maybe_trigger_migration(); + $docker_compose_installed = 'command -v docker-compose > /dev/null'; + if ( ! EE::exec( $docker_compose_installed ) ) { + $status = false; + $error = 'EasyEngine requires docker-compose.'; + } + + if ( version_compare( PHP_VERSION, '7.2.0' ) < 0 ) { + $status = false; + $error = 'EasyEngine requires minimum PHP 7.2.0 to run.'; + } + + if ( ! $show_error ) { + return $status; + } elseif ( ! $status ) { + EE::error( $error ); } } From 30601354a67f5150cef8d0c48444277e4daecc66 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Fri, 23 Nov 2018 18:29:21 +0530 Subject: [PATCH 2/6] Run checks before replacing phar Signed-off-by: Riddhesh Sanghvi --- php/commands/src/CLI_Command.php | 1 + 1 file changed, 1 insertion(+) diff --git a/php/commands/src/CLI_Command.php b/php/commands/src/CLI_Command.php index c1bafea71..2929aae21 100644 --- a/php/commands/src/CLI_Command.php +++ b/php/commands/src/CLI_Command.php @@ -286,6 +286,7 @@ public function update( $_, $assoc_args ) { $download_url = $newest['package_url']; $md5_url = str_replace( '.phar', '.phar.md5', $download_url ); } + EE::get_runner()->check_requirements(); EE::log( sprintf( 'Downloading from %s...', $download_url ) ); $temp = \EE\Utils\get_temp_dir() . uniqid( 'ee_', true ) . '.phar'; $headers = array(); From 37dd137768eee30be5f7381afe315cbe99bf0b8c Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Fri, 23 Nov 2018 19:00:29 +0530 Subject: [PATCH 3/6] Update ci prepration of phar Signed-off-by: Riddhesh Sanghvi --- ci/prepare.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ci/prepare.sh b/ci/prepare.sh index 7ae98d55f..5f2a38056 100755 --- a/ci/prepare.sh +++ b/ci/prepare.sh @@ -10,4 +10,7 @@ if [[ "$TRAVIS_BRANCH" != $DEPLOY_BRANCH ]]; then sed -i 's/\:\ \"\(.*\)\"/\:\ \"\1-nightly\"/g' img-versions.json fi -php -dphar.readonly=0 ./utils/make-phar.php easyengine.phar --quiet \ No newline at end of file +php -dphar.readonly=0 ./utils/make-phar.php easyengine.phar --quiet + +# Checking the phar is working. +./easyengine.phar cli info \ No newline at end of file From e3cf4146b9f45ea238a9d5e409511e282122d857 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Fri, 23 Nov 2018 19:22:27 +0530 Subject: [PATCH 4/6] Update returning status Signed-off-by: Riddhesh Sanghvi --- php/EE/Runner.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/php/EE/Runner.php b/php/EE/Runner.php index 74eae8b57..8d919aa20 100644 --- a/php/EE/Runner.php +++ b/php/EE/Runner.php @@ -101,11 +101,11 @@ public function check_requirements( $show_error = true ) { $error = 'EasyEngine requires minimum PHP 7.2.0 to run.'; } - if ( ! $show_error ) { - return $status; - } elseif ( ! $status ) { + if ( $show_error && ! $status ) { EE::error( $error ); } + + return $status; } /** From 972393ade3261c241ba05f05564b9852cb583321 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Fri, 23 Nov 2018 19:31:54 +0530 Subject: [PATCH 5/6] Update self-uninstall dependency check Signed-off-by: Riddhesh Sanghvi --- php/commands/src/CLI_Command.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/php/commands/src/CLI_Command.php b/php/commands/src/CLI_Command.php index 2929aae21..a80198165 100644 --- a/php/commands/src/CLI_Command.php +++ b/php/commands/src/CLI_Command.php @@ -494,6 +494,11 @@ public function cmd_dump() { */ public function self_uninstall( $args, $assoc_args ) { + if ( ! EE::get_runner()->check_requirements( false ) ) { + EE::error( 'Unable to proceed with uninstallation. Seems there is a dependency down.', false ); + die; + } + EE::confirm( "Are you sure you want to remove EasyEngine and all its sites(along with their data)?\nThis is an irreversible action. No backup will be kept.", $assoc_args ); EE::exec( 'docker rm -f $(docker ps -aqf label=org.label-schema.vendor="EasyEngine")' ); From 73488a81f323425595133ea0de6356cb52abebf1 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Fri, 23 Nov 2018 19:49:28 +0530 Subject: [PATCH 6/6] Update to show first message Signed-off-by: Riddhesh Sanghvi --- php/EE/Runner.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/php/EE/Runner.php b/php/EE/Runner.php index 8d919aa20..99a2549b8 100644 --- a/php/EE/Runner.php +++ b/php/EE/Runner.php @@ -82,27 +82,27 @@ private function init_ee() { public function check_requirements( $show_error = true ) { $status = true; + $error = []; - // Minimum requirement checks. $docker_running = 'docker ps > /dev/null'; if ( ! EE::exec( $docker_running ) ) { - $status = false; - $error = 'Docker not installed or not running.'; + $status = false; + $error[] = 'Docker not installed or not running.'; } $docker_compose_installed = 'command -v docker-compose > /dev/null'; if ( ! EE::exec( $docker_compose_installed ) ) { - $status = false; - $error = 'EasyEngine requires docker-compose.'; + $status = false; + $error[] = 'EasyEngine requires docker-compose.'; } if ( version_compare( PHP_VERSION, '7.2.0' ) < 0 ) { - $status = false; - $error = 'EasyEngine requires minimum PHP 7.2.0 to run.'; + $status = false; + $error[] = 'EasyEngine requires minimum PHP 7.2.0 to run.'; } if ( $show_error && ! $status ) { - EE::error( $error ); + EE::error( reset( $error ) ); } return $status;