1111 * @package ee-cli
1212 */
1313
14+ use Composer \Console \Application ;
1415use EE \Model \Site ;
15- use \ Symfony \Component \Filesystem \ Filesystem ;
16- use \ Composer \ Console \ Application ;
17- use \ Symfony \ Component \ Console \ Input \ ArrayInput ;
16+ use Symfony \Component \Console \ Input \ ArrayInput ;
17+ use Symfony \ Component \ Filesystem \ Filesystem ;
18+ use function EE \ Site \ Utils \ auto_site_name ;
1819
1920class Admin_Tools_Command extends EE_Command {
2021
@@ -29,9 +30,9 @@ class Admin_Tools_Command extends EE_Command {
2930 private $ fs ;
3031
3132 /**
32- * @var array $db Object containing essential site related information.
33+ * @var array $site_data Object containing essential site related information.
3334 */
34- private $ db ;
35+ private $ site_data ;
3536
3637 public function __construct () {
3738
@@ -60,7 +61,7 @@ public function install() {
6061 if ( empty ( $ tools_file ) ) {
6162 EE ::error ( 'admin-tools file is empty. Can \'t proceed further. ' );
6263 }
63- $ tools = json_decode ( $ tools_file , true );
64+ $ tools = json_decode ( $ tools_file , true );
6465 $ json_error = json_last_error ();
6566 if ( $ json_error != JSON_ERROR_NONE ) {
6667 EE ::debug ( 'Json last error: ' . $ json_error );
@@ -99,41 +100,44 @@ public function install() {
99100 */
100101 public function up ( $ args , $ assoc_args ) {
101102
103+ \EE \Auth \Utils \init_global_admin_tools_auth ();
104+
102105 EE \Utils \delem_log ( 'admin-tools ' . __FUNCTION__ . ' start ' );
103- $ args = EE \ SiteUtils \ auto_site_name ( $ args , $ this ->command , __FUNCTION__ );
104- $ force = EE \Utils \get_flag_value ( $ assoc_args , 'force ' );
105- $ this ->db = Site::find ( EE \Utils \remove_trailing_slash ( $ args [0 ] ) );
106- if ( ! $ this ->db || ! $ this ->db ->site_enabled ) {
106+ $ args = auto_site_name ( $ args , $ this ->command , __FUNCTION__ );
107+ $ force = EE \Utils \get_flag_value ( $ assoc_args , 'force ' );
108+ $ this ->site_data = Site::find ( EE \Utils \remove_trailing_slash ( $ args [0 ] ) );
109+ if ( ! $ this ->site_data || ! $ this ->site_data ->site_enabled ) {
107110 EE ::error ( sprintf ( 'Site %s does not exist / is not enabled. ' , $ args [0 ] ) );
108111 }
109112
110- if ( $ this ->db ->admin_tools && ! $ force ) {
111- EE ::error ( sprintf ( 'admin-tools already seem to be enabled for %s ' , $ this ->db ->site_url ) );
113+ if ( $ this ->site_data ->admin_tools && ! $ force ) {
114+ EE ::error ( sprintf ( 'admin-tools already seem to be enabled for %s ' , $ this ->site_data ->site_url ) );
112115 }
113116
114- chdir ( $ this ->db ->site_fs_path );
117+ chdir ( $ this ->site_data ->site_fs_path );
115118
116119 $ launch = EE ::launch ( 'docker-compose config --services ' );
117120 $ services = explode ( PHP_EOL , trim ( $ launch ->stdout ) );
118121 $ min_req_services = [ 'nginx ' , 'php ' ];
119122
120123 if ( count ( array_intersect ( $ services , $ min_req_services ) ) !== count ( $ min_req_services ) ) {
121- EE ::error ( sprintf ( '%s site-type of %s-command does not support admin-tools. ' , $ this ->db ->app_sub_type , $ this ->db ->site_type ) );
124+ EE ::error ( sprintf ( '%s site-type of %s-command does not support admin-tools. ' , $ this ->site_data ->app_sub_type , $ this ->site_data ->site_type ) );
122125 }
123126
124127 if ( ! $ this ->is_installed () ) {
125128 EE ::log ( 'It seems admin-tools have not yet been installed. ' );
126129 $ this ->install ();
130+ chdir ( $ this ->site_data ->site_fs_path );
127131 }
128132
129- $ this ->move_config_file ( 'docker-compose-admin.mustache ' , $ this ->db ->site_fs_path . '/docker-compose-admin.yml ' );
133+ $ this ->move_config_file ( 'docker-compose-admin.mustache ' , $ this ->site_data ->site_fs_path . '/docker-compose-admin.yml ' );
130134
131135 if ( EE ::exec ( 'docker-compose -f docker-compose.yml -f docker-compose-admin.yml up -d nginx ' ) ) {
132- EE ::success ( sprintf ( 'admin-tools enabled for %s site. ' , $ this ->db ->site_url ) );
133- $ this ->db ->admin_tools = 1 ;
134- $ this ->db ->save ();
136+ EE ::success ( sprintf ( 'admin-tools enabled for %s site. ' , $ this ->site_data ->site_url ) );
137+ $ this ->site_data ->admin_tools = 1 ;
138+ $ this ->site_data ->save ();
135139 } else {
136- EE ::error ( sprintf ( 'Error in enabling admin-tools for %s site. Check logs. ' , $ this ->db ->site_url ) );
140+ EE ::error ( sprintf ( 'Error in enabling admin-tools for %s site. Check logs. ' , $ this ->site_data ->site_url ) );
137141 }
138142
139143 EE \Utils \delem_log ( 'admin-tools ' . __FUNCTION__ . ' stop ' );
@@ -153,21 +157,21 @@ public function up( $args, $assoc_args ) {
153157 public function down ( $ args , $ assoc_args ) {
154158
155159 EE \Utils \delem_log ( 'admin-tools ' . __FUNCTION__ . ' start ' );
156- $ args = EE \ SiteUtils \ auto_site_name ( $ args , $ this ->command , __FUNCTION__ );
157- $ force = EE \Utils \get_flag_value ( $ assoc_args , 'force ' );
158- $ this ->db = Site::find ( EE \Utils \remove_trailing_slash ( $ args [0 ] ) );
159- if ( ! $ this ->db || ! $ this ->db ->site_enabled ) {
160+ $ args = auto_site_name ( $ args , $ this ->command , __FUNCTION__ );
161+ $ force = EE \Utils \get_flag_value ( $ assoc_args , 'force ' );
162+ $ this ->site_data = Site::find ( EE \Utils \remove_trailing_slash ( $ args [0 ] ) );
163+ if ( ! $ this ->site_data || ! $ this ->site_data ->site_enabled ) {
160164 EE ::error ( sprintf ( 'Site %s does not exist / is not enabled. ' , $ args [0 ] ) );
161165 }
162166
163- if ( ! $ this ->db ->admin_tools && ! $ force ) {
164- EE ::error ( sprintf ( 'admin-tools already seem to be enabled for %s ' , $ this ->db ->site_url ) );
167+ if ( ! $ this ->site_data ->admin_tools && ! $ force ) {
168+ EE ::error ( sprintf ( 'admin-tools already seem to be enabled for %s ' , $ this ->site_data ->site_url ) );
165169 }
166170
167- EE ::docker ()::docker_compose_up ( $ this ->db ->site_fs_path , [ 'nginx ' , 'php ' ] );
168- EE ::success ( sprintf ( 'admin-tools disabled for %s site. ' , $ this ->db ->site_url ) );
169- $ this ->db ->admin_tools = 0 ;
170- $ this ->db ->save ();
171+ EE ::docker ()::docker_compose_up ( $ this ->site_data ->site_fs_path , [ 'nginx ' , 'php ' ] );
172+ EE ::success ( sprintf ( 'admin-tools disabled for %s site. ' , $ this ->site_data ->site_url ) );
173+ $ this ->site_data ->admin_tools = 0 ;
174+ $ this ->site_data ->save ();
171175 EE \Utils \delem_log ( 'admin-tools ' . __FUNCTION__ . ' stop ' );
172176 }
173177
@@ -242,12 +246,10 @@ private function move_config_file( $template_file, $config_file ) {
242246 */
243247 private function composer_install ( $ tool_path ) {
244248
245- putenv ( 'COMPOSER_HOME= ' . EE_VENDOR_DIR . '/bin/composer ' );
246249 chdir ( $ tool_path );
247- $ input = new ArrayInput ( array ( 'command ' => 'update ' ) );
248- $ application = new Application ();
249- $ application ->setAutoExit ( false );
250- $ application ->run ( $ input );
250+ EE ::log ( 'Installing dependencies. This may take a little while. ' );
251+ $ img_versions = \EE \Utils \get_image_versions ();
252+ EE ::exec ( sprintf ( 'docker run --rm -it -e USER_ID=0 -e GROUP_ID=0 --user=root -v $PWD:/var/www/htdocs easyengine/php:%s composer update ' , $ img_versions ['easyengine/php ' ] ) );
251253 }
252254
253255 /**
0 commit comments