Skip to content

Commit 7df36c7

Browse files
Merge pull request #1309 from mrrobot47/update/checks
Update checks and migration triggering
2 parents 8dd4da2 + 73488a8 commit 7df36c7

File tree

3 files changed

+47
-18
lines changed

3 files changed

+47
-18
lines changed

ci/prepare.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ if [[ "$TRAVIS_BRANCH" != $DEPLOY_BRANCH ]]; then
1010
sed -i 's/\:\ \"\(.*\)\"/\:\ \"\1-nightly\"/g' img-versions.json
1111
fi
1212

13-
php -dphar.readonly=0 ./utils/make-phar.php easyengine.phar --quiet
13+
php -dphar.readonly=0 ./utils/make-phar.php easyengine.phar --quiet
14+
15+
# Checking the phar is working.
16+
./easyengine.phar cli info

php/EE/Runner.php

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,28 +64,48 @@ private function init_ee() {
6464

6565
if (
6666
! empty( $this->arguments ) &&
67-
( 'help' !== $this->arguments[0] )
68-
&& $this->arguments !== [ 'cli', 'version' ]
69-
)
70-
{
67+
( ! in_array( $this->arguments[0], [ 'cli', 'config', 'help' ], true ) )
68+
) {
69+
$this->check_requirements();
70+
$this->maybe_trigger_migration();
71+
}
72+
if ( [ 'cli', 'info' ] === $this->arguments && $this->check_requirements( false ) ) {
73+
$this->maybe_trigger_migration();
74+
}
75+
}
7176

72-
// Minimum requirement checks.
73-
$docker_running = 'docker ps > /dev/null';
74-
if ( ! EE::exec( $docker_running ) ) {
75-
EE::error( 'docker not installed or not running.' );
76-
}
77+
/**
78+
* Check EE requirements for required commands.
79+
*
80+
* @param bool $show_error To display error or to retutn status.
81+
*/
82+
public function check_requirements( $show_error = true ) {
7783

78-
$docker_compose_installed = 'command -v docker-compose > /dev/null';
79-
if ( ! EE::exec( $docker_compose_installed ) ) {
80-
EE::error( 'EasyEngine requires docker-compose.' );
81-
}
84+
$status = true;
85+
$error = [];
8286

83-
if ( version_compare( PHP_VERSION, '7.2.0' ) < 0 ) {
84-
EE::error( 'EasyEngine requires minimum PHP 7.2.0 to run.' );
85-
}
87+
$docker_running = 'docker ps > /dev/null';
88+
if ( ! EE::exec( $docker_running ) ) {
89+
$status = false;
90+
$error[] = 'Docker not installed or not running.';
91+
}
8692

87-
$this->maybe_trigger_migration();
93+
$docker_compose_installed = 'command -v docker-compose > /dev/null';
94+
if ( ! EE::exec( $docker_compose_installed ) ) {
95+
$status = false;
96+
$error[] = 'EasyEngine requires docker-compose.';
8897
}
98+
99+
if ( version_compare( PHP_VERSION, '7.2.0' ) < 0 ) {
100+
$status = false;
101+
$error[] = 'EasyEngine requires minimum PHP 7.2.0 to run.';
102+
}
103+
104+
if ( $show_error && ! $status ) {
105+
EE::error( reset( $error ) );
106+
}
107+
108+
return $status;
89109
}
90110

91111
/**

php/commands/src/CLI_Command.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ public function update( $_, $assoc_args ) {
286286
$download_url = $newest['package_url'];
287287
$md5_url = str_replace( '.phar', '.phar.md5', $download_url );
288288
}
289+
EE::get_runner()->check_requirements();
289290
EE::log( sprintf( 'Downloading from %s...', $download_url ) );
290291
$temp = \EE\Utils\get_temp_dir() . uniqid( 'ee_', true ) . '.phar';
291292
$headers = array();
@@ -493,6 +494,11 @@ public function cmd_dump() {
493494
*/
494495
public function self_uninstall( $args, $assoc_args ) {
495496

497+
if ( ! EE::get_runner()->check_requirements( false ) ) {
498+
EE::error( 'Unable to proceed with uninstallation. Seems there is a dependency down.', false );
499+
die;
500+
}
501+
496502
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 );
497503

498504
EE::exec( 'docker rm -f $(docker ps -aqf label=org.label-schema.vendor="EasyEngine")' );

0 commit comments

Comments
 (0)