From c2a4d5474f1b3d103e44768c692670fce7e971f3 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Thu, 30 Aug 2018 18:32:20 +0530 Subject: [PATCH 1/5] Update function acc to new namespace and add doc comment Signed-off-by: Riddhesh Sanghvi --- src/Shell_Command.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Shell_Command.php b/src/Shell_Command.php index 504c711..eb4725e 100644 --- a/src/Shell_Command.php +++ b/src/Shell_Command.php @@ -13,6 +13,7 @@ use EE\Utils; use EE\Model\Site; +use function EE\Site\Utils\auto_site_name; class Shell_Command extends EE_Command { @@ -26,7 +27,7 @@ class Shell_Command extends EE_Command { */ public function __invoke( $args ) { EE\Utils\delem_log( 'ee shell start' ); - $args = EE\SiteUtils\auto_site_name( $args, 'shell', '' ); + $args = auto_site_name( $args, 'shell', '' ); $site_name = EE\Utils\remove_trailing_slash( $args[0] ); $site = Site::find( $site_name, [ 'site_enabled', 'site_fs_path' ] ); @@ -40,6 +41,12 @@ public function __invoke( $args ) { EE\Utils\delem_log( 'ee shell end' ); } + /** + * Run the command to open shell. + * + * @param string $cmd Command to be executed to open shell. + * @param null|array $descriptors File descriptors for proc. + */ private function run( $cmd, $descriptors = null ) { EE\Utils\check_proc_available( 'ee_shell' ); if ( ! $descriptors ) { From f9e1400518bbbb07fcd931415647f3bbfc476b62 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Thu, 30 Aug 2018 18:43:23 +0530 Subject: [PATCH 2/5] Add php container exsits check and update comments Signed-off-by: Riddhesh Sanghvi --- src/Shell_Command.php | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/Shell_Command.php b/src/Shell_Command.php index eb4725e..59b740b 100644 --- a/src/Shell_Command.php +++ b/src/Shell_Command.php @@ -1,12 +1,12 @@ site_enabled ) { EE::error( "Site $site_name does not exist or is not enabled." ); } chdir( $site->site_fs_path ); + $this->check_shell_available( 'php', $site ); $this->run( "docker-compose exec --user='www-data' php bash" ); EE\Utils\delem_log( 'ee shell end' ); } @@ -64,4 +65,21 @@ private function run( $cmd, $descriptors = null ) { } } + /** + * Function to check if container supporting shell is present in docker-compose.yml or not. + * + * @param string $shell_container Container to be checked. + * @param Object $site Contains relevant site info. + */ + private function check_shell_available( $shell_container, $site ) { + + $launch = EE::launch( 'docker-compose config --services' ); + $services = explode( PHP_EOL, trim( $launch->stdout ) ); + if ( ! in_array( $shell_container, $services, true ) ) { + EE::debug( 'Site type: ' . $site->site_type ); + EE::debug( 'Site command: ' . $site->app_sub_type ); + EE::error( sprintf( '%s site does not have support to launch %s shell.', $shell_container, $site->site_url ) ); + } + } + } From 7953962b84ed94322ae6ba5dbc465cef29149a2a Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Thu, 30 Aug 2018 19:06:46 +0530 Subject: [PATCH 3/5] Update comment Signed-off-by: Riddhesh Sanghvi --- src/Shell_Command.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Shell_Command.php b/src/Shell_Command.php index 59b740b..7247552 100644 --- a/src/Shell_Command.php +++ b/src/Shell_Command.php @@ -1,5 +1,9 @@ site_url ) ); } } - } From ae26969943b89355011a508cb6c9a62f090c3d65 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Thu, 30 Aug 2018 19:18:45 +0530 Subject: [PATCH 4/5] Fix variable in sprintf Signed-off-by: Riddhesh Sanghvi --- src/Shell_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Shell_Command.php b/src/Shell_Command.php index 7247552..0748db2 100644 --- a/src/Shell_Command.php +++ b/src/Shell_Command.php @@ -79,7 +79,7 @@ private function check_shell_available( $shell_container, $site ) { if ( ! in_array( $shell_container, $services, true ) ) { EE::debug( 'Site type: ' . $site->site_type ); EE::debug( 'Site command: ' . $site->app_sub_type ); - EE::error( sprintf( '%s site does not have support to launch %s shell.', $shell_container, $site->site_url ) ); + EE::error( sprintf( '%s site does not have support to launch %s shell.', $site->site_url, $shell_container ) ); } } } From 398aafceee77985b07d00e3d41163fa4b25c86f2 Mon Sep 17 00:00:00 2001 From: Riddhesh Sanghvi Date: Thu, 30 Aug 2018 20:04:09 +0530 Subject: [PATCH 5/5] Update to early invocation Signed-off-by: Riddhesh Sanghvi --- src/Shell_Command.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Shell_Command.php b/src/Shell_Command.php index 0748db2..9205939 100644 --- a/src/Shell_Command.php +++ b/src/Shell_Command.php @@ -76,10 +76,11 @@ private function check_shell_available( $shell_container, $site ) { $launch = EE::launch( 'docker-compose config --services' ); $services = explode( PHP_EOL, trim( $launch->stdout ) ); - if ( ! in_array( $shell_container, $services, true ) ) { - EE::debug( 'Site type: ' . $site->site_type ); - EE::debug( 'Site command: ' . $site->app_sub_type ); - EE::error( sprintf( '%s site does not have support to launch %s shell.', $site->site_url, $shell_container ) ); + if ( in_array( $shell_container, $services, true ) ) { + return; } + EE::debug( 'Site type: ' . $site->site_type ); + EE::debug( 'Site command: ' . $site->app_sub_type ); + EE::error( sprintf( '%s site does not have support to launch %s shell.', $site->site_url, $shell_container ) ); } }