@@ -443,21 +443,18 @@ public function create( $args, $assoc_args ) {
443443 */
444444 private function enable_object_cache () {
445445
446- $ redis_host = $ this ->site_data ['cache_host ' ];
447- $ redis_plugin_constant = 'docker-compose exec --user= \'www-data \' php wp config set --type=variable redis_server "array( \'host \'=> \'' . $ redis_host . '\', \'port \'=> 6379,)" --raw ' ;
448- $ activate_wp_redis_plugin = "docker-compose exec --user='www-data' php wp plugin install wp-redis --activate " ;
449- $ enable_redis_cache = "docker-compose exec --user='www-data' php wp redis enable " ;
450-
451- $ this ->docker_compose_exec ( $ redis_plugin_constant , 'Unable to download or activate wp-redis plugin. ' );
452- $ this ->docker_compose_exec ( $ activate_wp_redis_plugin , 'Unable to download or activate wp-redis plugin. ' );
453- $ this ->docker_compose_exec ( $ enable_redis_cache , 'Unable to enable object cache ' );
446+ $ redis_host = $ this ->site_data ['cache_host ' ];
447+ \EE_DOCKER ::docker_compose_exec ( 'wp config set --type=variable redis_server "array( \'host \'=> \'' . $ redis_host . '\', \'port \'=> 6379,)" --raw ' , 'php ' , 'bash ' , 'www-data ' );
448+ \EE_DOCKER ::docker_compose_exec ( "wp plugin install wp-redis --activate " , 'php ' , 'bash ' , 'www-data ' );
449+ \EE_DOCKER ::docker_compose_exec ( "wp redis enable " , 'php ' , 'bash ' , 'www-data ' );
454450 }
455451
456452 /**
457453 * Enable page cache.
458454 */
459455 private function enable_page_cache () {
460- $ activate_nginx_helper = 'docker-compose exec --user= \'www-data \' php wp plugin install nginx-helper --activate ' ;
456+
457+ $ activate_nginx_helper = \EE_DOCKER ::docker_compose_exec ( 'wp plugin install nginx-helper --activate ' , 'php ' , 'bash ' , 'www-data ' );
461458 $ nginx_helper_fail_msg = 'Unable to download or activate nginx-helper plugin properly. ' ;
462459 $ page_cache_key_prefix = $ this ->site_data ['site_url ' ] . '_page: ' ;
463460 $ obj_cache_key_prefix = $ this ->site_data ['site_url ' ] . '_obj: ' ;
@@ -493,35 +490,13 @@ private function enable_page_cache() {
493490 $ page_cache_key_prefix
494491 );
495492
496- $ add_hostname_constant = "docker-compose exec --user='www-data' php wp config set RT_WP_NGINX_HELPER_REDIS_HOSTNAME $ redis_host --add=true --type=constant " ;
497- $ add_port_constant = "docker-compose exec --user='www-data' php wp config set RT_WP_NGINX_HELPER_REDIS_PORT 6379 --add=true --type=constant " ;
498- $ add_prefix_constant = "docker-compose exec --user='www-data' php wp config set RT_WP_NGINX_HELPER_REDIS_PREFIX $ page_cache_key_prefix --add=true --type=constant " ;
499- $ add_cache_key_salt = "docker-compose exec --user='www-data' php wp config set WP_CACHE_KEY_SALT $ obj_cache_key_prefix --add=true --type=constant " ;
500- $ add_redis_maxttl = "docker-compose exec --user='www-data' php wp config set WP_REDIS_MAXTTL 14400 --add=true --type=constant " ;
501- $ add_plugin_data = "docker-compose exec --user='www-data' php wp $ wp_cli_params rt_wp_nginx_helper_options ' $ plugin_data' --format=json " ;
502-
503- $ this ->docker_compose_exec ( $ add_hostname_constant , $ nginx_helper_fail_msg );
504- $ this ->docker_compose_exec ( $ add_port_constant , $ nginx_helper_fail_msg );
505- $ this ->docker_compose_exec ( $ add_prefix_constant , $ nginx_helper_fail_msg );
506- $ this ->docker_compose_exec ( $ add_cache_key_salt , $ nginx_helper_fail_msg );
507- $ this ->docker_compose_exec ( $ activate_nginx_helper , $ nginx_helper_fail_msg );
508- $ this ->docker_compose_exec ( $ add_plugin_data , $ nginx_helper_fail_msg );
509- $ this ->docker_compose_exec ( $ add_redis_maxttl , $ nginx_helper_fail_msg );
510- }
511-
512- /**
513- * Execute command with fail msg.
514- *
515- * @param string $command Command to execute.
516- * @param string $fail_msg failure message.
517- */
518- private function docker_compose_exec ( $ command , $ fail_msg = '' ) {
519- if ( empty ( $ command ) ) {
520- return ;
521- }
522- if ( ! \EE ::exec ( $ command ) ) {
523- \EE ::warning ( $ fail_msg );
524- }
493+ \EE_DOCKER ::docker_compose_exec ( "wp config set RT_WP_NGINX_HELPER_REDIS_HOSTNAME $ redis_host --add=true --type=constant " , 'php ' , 'bash ' , 'www-data ' );
494+ \EE_DOCKER ::docker_compose_exec ( "wp config set RT_WP_NGINX_HELPER_REDIS_PORT 6379 --add=true --type=constant " , 'php ' , 'bash ' , 'www-data ' );
495+ \EE_DOCKER ::docker_compose_exec ( "wp config set RT_WP_NGINX_HELPER_REDIS_PREFIX $ page_cache_key_prefix --add=true --type=constant " , 'php ' , 'bash ' , 'www-data ' );
496+ \EE_DOCKER ::docker_compose_exec ( "wp config set WP_CACHE_KEY_SALT $ obj_cache_key_prefix --add=true --type=constant " , 'php ' , 'bash ' , 'www-data ' );
497+ \EE_DOCKER ::docker_compose_exec ( "wp config set WP_REDIS_MAXTTL 14400 --add=true --type=constant " , 'php ' , 'bash ' , 'www-data ' );
498+ \EE_DOCKER ::docker_compose_exec ( "wp $ wp_cli_params rt_wp_nginx_helper_options ' $ plugin_data' --format=json " , 'php ' , 'bash ' , 'www-data ' );
499+
525500 }
526501
527502 /**
@@ -532,6 +507,7 @@ private function docker_compose_exec( $command, $fail_msg = '' ) {
532507 * @return string Generated db user.
533508 */
534509 private function create_site_db_user ( string $ site_url ): string {
510+
535511 if ( strlen ( $ site_url ) > 53 ) {
536512 $ site_url = substr ( $ site_url , 0 , 53 );
537513 }
@@ -998,7 +974,7 @@ private function maybe_verify_remote_db_connection() {
998974 */
999975 private function create_site ( $ assoc_args ) {
1000976
1001- $ this ->level = 1 ;
977+ $ this ->level = 1 ;
1002978 try {
1003979 if ( 'inherit ' === $ this ->site_data ['site_ssl ' ] ) {
1004980 $ this ->check_parent_site_certs ( $ this ->site_data ['site_url ' ] );
@@ -1060,7 +1036,7 @@ private function create_site( $assoc_args ) {
10601036 }
10611037
10621038 // Reset wp-content permission which may have been changed during git clone from host machine.
1063- EE :: exec ( "docker-compose exec --user=root php chown -R www-data: $ public_dir_path/wp-content " );
1039+ \ EE_DOCKER :: docker_compose_exec ( "chown -R www-data: $ public_dir_path/wp-content " , ' php ' , ' bash ' , ' root ' );
10641040
10651041 $ this ->create_site_db_entry ();
10661042 \EE ::log ( 'Site entry created. ' );
@@ -1123,25 +1099,24 @@ private function wp_download_and_config( $assoc_args ) {
11231099 $ wp_cli_data = EE \Utils \mustache_render ( SITE_WP_TEMPLATE_ROOT . '/wp-cli.yml.mustache ' , [ 'wp_path ' => $ public_dir_path ] );
11241100 $ this ->fs ->dumpFile ( $ this ->site_data ['site_fs_path ' ] . '/app/htdocs/wp-cli.yml ' , $ wp_cli_data );
11251101
1126- EE :: exec ( sprintf ( 'docker-compose exec --user=root php mkdir -p %s ' , $ public_dir_path ) );
1102+ \ EE_DOCKER :: docker_compose_exec ( sprintf ( 'mkdir -p %s ' , $ public_dir_path ), ' php ' , ' bash ' , ' root ' );
11271103 }
11281104
1129- $ chown_command = "docker-compose exec --user=root php chown -R www-data: /var/www/ " ;
1130- \EE ::exec ( $ chown_command );
1105+ \EE_DOCKER ::docker_compose_exec ( 'chown -R www-data: /var/www/ ' , 'php ' , 'bash ' , 'root ' );
11311106
11321107 $ wp_download_path = $ this ->site_data ['site_container_fs_path ' ];
1133- $ core_download_command = "docker-compose exec --user='www-data' php wp core download --path=$ wp_download_path --locale=' $ this ->locale ' $ core_download_arguments " ;
1108+ $ core_download_command = "wp core download --path= $ wp_download_path --locale=' $ this ->locale ' $ core_download_arguments " ;
11341109
1135- if ( ! \EE :: exec ( $ core_download_command ) ) {
1110+ if ( ! \EE_DOCKER :: docker_compose_exec ( $ core_download_command, ' php ' , ' bash ' , ' www-data ' ) ) {
11361111 \EE ::error ( 'Unable to download wp core. ' , false );
11371112 }
11381113
11391114 if ( 'db ' === $ this ->site_data ['db_host ' ] ) {
11401115 $ mysql_unhealthy = true ;
1141- $ health_chk = sprintf ( "docker-compose exec --user='www-data' php mysql --user='root' --password='%s' --host='db' -e exit " , $ this ->site_data ['db_root_password ' ] );
1116+ $ health_chk = sprintf ( "mysql --user='root' --password='%s' --host='db' -e exit " , $ this ->site_data ['db_root_password ' ] );
11421117 $ count = 0 ;
11431118 while ( $ mysql_unhealthy ) {
1144- $ mysql_unhealthy = ! \EE :: exec ( $ health_chk );
1119+ $ mysql_unhealthy = ! \EE_DOCKER :: docker_compose_exec ( $ health_chk, ' php ' , ' bash ' , ' root ' );
11451120 if ( $ count ++ > 180 ) {
11461121 break ;
11471122 }
@@ -1161,7 +1136,6 @@ private function wp_download_and_config( $assoc_args ) {
11611136 . '// Use dev versions of core JS and CSS files (only needed if you are modifying these core files) '
11621137 . "\n" . 'define( \'SCRIPT_DEBUG \', false ); ' ;
11631138
1164-
11651139 if ( 'wp ' !== $ this ->site_data ['app_sub_type ' ] ) {
11661140 $ extra_php .= "\n\n// Disable cookie domain. \ndefine( 'COOKIE_DOMAIN', false ); " ;
11671141 }
@@ -1172,19 +1146,19 @@ private function wp_download_and_config( $assoc_args ) {
11721146 }
11731147
11741148 $ db_host = isset ( $ this ->site_data ['db_port ' ] ) ? $ this ->site_data ['db_host ' ] . ': ' . $ this ->site_data ['db_port ' ] : $ this ->site_data ['db_host ' ];
1175- $ wp_config_create_command = sprintf ( 'docker-compose exec --user= \' www-data \' php wp config create --dbuser= \'%s \' --dbname= \'%s \' --dbpass= \'%s \' --dbhost= \'%s \' %s --extra-php="%s" ' , $ this ->site_data ['db_user ' ], $ this ->site_data ['db_name ' ], $ this ->site_data ['db_password ' ], $ db_host , $ config_arguments , $ extra_php );
1149+ $ wp_config_create_command = sprintf ( 'wp config create --dbuser= \'%s \' --dbname= \'%s \' --dbpass= \'%s \' --dbhost= \'%s \' %s --extra-php="%s" ' , $ this ->site_data ['db_user ' ], $ this ->site_data ['db_name ' ], $ this ->site_data ['db_password ' ], $ db_host , $ config_arguments , $ extra_php );
11761150
11771151 try {
1178- if ( ! \EE :: exec ( $ wp_config_create_command ) ) {
1152+ if ( ! \EE_DOCKER :: docker_compose_exec ( $ wp_config_create_command, ' php ' , ' bash ' , ' www-data ' ) ) {
11791153 throw new \Exception ( sprintf ( 'Couldn \'t connect to %s:%s or there was issue in `wp config create`. Please check logs. ' , $ this ->site_data ['db_host ' ], $ this ->site_data ['db_port ' ] ) );
11801154 }
11811155
11821156 $ default_wp_config_path = sprintf ( '%s/wp-config.php ' , $ this ->site_data ['site_container_fs_path ' ] );
11831157 $ level_above_path = preg_replace ( '/[^\/]+$/ ' , '' , $ this ->site_data ['site_container_fs_path ' ] );
11841158 $ new_wp_config_path = sprintf ( '%swp-config.php ' , $ level_above_path );
11851159
1186- $ move_wp_config_command = sprintf ( 'docker-compose exec php mv %1$s %2$s ' , $ default_wp_config_path , $ new_wp_config_path );
1187- if ( ! EE :: exec ( $ move_wp_config_command ) ) {
1160+ $ move_wp_config_command = sprintf ( 'mv %1$s %2$s ' , $ default_wp_config_path , $ new_wp_config_path );
1161+ if ( ! \ EE_DOCKER :: docker_compose_exec ( $ move_wp_config_command, ' php ' , ' bash ' , ' www-data ' ) ) {
11881162 throw new \Exception ( sprintf ( 'Couldn \'t move wp-config.php from %1$s to %2$s ' , $ default_wp_config_path , $ new_wp_config_path ) );
11891163 }
11901164 EE ::log ( sprintf ( 'Moved %1$s to %2$s successfully ' , $ default_wp_config_path , $ new_wp_config_path ) );
@@ -1212,26 +1186,26 @@ private function install_wp() {
12121186 }
12131187
12141188 $ prefix = ( $ this ->site_data ['site_ssl ' ] ) ? 'https:// ' : 'http:// ' ;
1215- $ install_command = sprintf ( 'docker-compose exec --user= \' www-data \' php wp core %s --url= \'%s%s \' --title= \'%s \' --admin_user= \'%s \'' , $ wp_install_command , $ prefix , $ this ->site_data ['site_url ' ], $ this ->site_data ['app_admin_url ' ], $ this ->site_data ['app_admin_username ' ] );
1189+ $ install_command = sprintf ( 'wp core %s --url= \'%s%s \' --title= \'%s \' --admin_user= \'%s \'' , $ wp_install_command , $ prefix , $ this ->site_data ['site_url ' ], $ this ->site_data ['app_admin_url ' ], $ this ->site_data ['app_admin_username ' ] );
12161190 $ install_command .= $ this ->site_data ['app_admin_password ' ] ? sprintf ( ' --admin_password= \'%s \'' , $ this ->site_data ['app_admin_password ' ] ) : '' ;
12171191 $ install_command .= sprintf ( ' --admin_email= \'%s \' %s ' , $ this ->site_data ['app_admin_email ' ], $ maybe_multisite_type );
12181192
1219- $ core_install = \EE :: exec ( $ install_command , false , false , [
1193+ $ core_install = \EE_DOCKER :: docker_compose_exec ( $ install_command, ' php ' , ' bash ' , ' www-data ' , '' , false , false , [
12201194 $ this ->site_data ['app_admin_username ' ],
12211195 $ this ->site_data ['app_admin_email ' ],
12221196 $ this ->site_data ['app_admin_password ' ],
12231197 ] );
12241198
1225- EE ::exec ( 'docker-compose exec php wp rewrite structure "/%year%/%monthnum%/%day%/%postname%/" --hard ' );
1226-
12271199 if ( ! $ core_install ) {
12281200 throw new \Exception ( 'WordPress install failed. Please check logs. ' );
12291201 }
12301202
1203+ \EE_DOCKER ::docker_compose_exec ( 'wp rewrite structure "/%year%/%monthnum%/%day%/%postname%/" --hard ' , 'php ' , 'bash ' , 'www-data ' );
1204+
12311205 $ env_type = \EE ::get_runner ()->config ['env ' ];
12321206 $ env_type = in_array ( $ env_type , [ 'production ' , 'staging ' , 'development ' , 'local ' ] ) ? $ env_type : '' ;
12331207 if ( ! empty ( $ env_type ) ) {
1234- EE :: exec ( 'docker-compose exec --user= \' www-data \' php wp config set --type=constant WP_ENVIRONMENT_TYPE \'' . $ env_type . '\' ' );
1208+ \ EE_DOCKER :: docker_compose_exec ( 'wp config set --type=constant WP_ENVIRONMENT_TYPE \'' . $ env_type . '\' ' , ' php ' , ' bash ' , ' www-data ' );
12351209 }
12361210
12371211 \EE ::success ( $ prefix . $ this ->site_data ['site_url ' ] . ' has been created successfully! ' );
@@ -1380,7 +1354,7 @@ private function setup_vip( $assoc_args ) {
13801354 chdir ( $ this ->site_data ['site_fs_path ' ] );
13811355
13821356 // Reset wp-content permission which may have been changed during git clone from host machine. Making it `/var/www/htdocs/` so that it accomodates the changes of `--public-dir` input if any.
1383- EE :: exec ( " docker-compose exec --user=root php chown -R www-data: /var/www/htdocs/" );
1357+ \ EE_DOCKER :: docker_compose_exec ( ' chown -R www-data: /var/www/htdocs/ ' , ' php ' , ' bash ' , ' root ' );
13841358
13851359 \EE ::log ( "VIP Go environment setup completed. " );
13861360 }
@@ -1582,6 +1556,7 @@ public function reload( $args, $assoc_args, $whitelisted_containers = [], $reloa
15821556 *
15831557 */
15841558 public function share ( $ args , $ assoc_args ) {
1559+
15851560 parent ::share ( $ args , $ assoc_args );
15861561
15871562 $ disable = get_flag_value ( $ assoc_args , 'disable ' , false );
@@ -1594,14 +1569,14 @@ public function share( $args, $assoc_args ) {
15941569 EE ::log ( 'Running additional WordPress configurations. ' );
15951570 chdir ( $ this ->site_data ->site_fs_path );
15961571 if ( $ disable ) {
1597- EE :: exec ( 'docker-compose exec --user= \' www-data \' php wp plugin delete relative-url ' );
1598- EE :: exec ( 'docker-compose exec --user= \' www-data \' php wp config delete WP_SITEURL ' );
1599- EE :: exec ( 'docker-compose exec --user= \' www-data \' php wp config delete WP_HOME ' );
1572+ \ EE_DOCKER :: docker_compose_exec ( 'wp plugin delete relative-url ' , ' php ' , ' bash ' , ' www-data ' );
1573+ \ EE_DOCKER :: docker_compose_exec ( 'wp config delete WP_SITEURL ' , ' php ' , ' bash ' , ' www-data ' );
1574+ \ EE_DOCKER :: docker_compose_exec ( 'wp config delete WP_HOME ' , ' php ' , ' bash ' , ' www-data ' );
16001575 } else {
1601- EE :: exec ( 'docker-compose exec --user= \' www-data \' php wp plugin install relative-url --activate ' );
1576+ \ EE_DOCKER :: docker_compose_exec ( 'wp plugin install relative-url --activate ' , ' php ' , ' bash ' , ' www-data ' );
16021577 $ set_url = 'http:// \' . empty( \$_SERVER[ \'HTTP_HOST \'] ) ? \'' . $ this ->site_data ->site_url . '\' : \$_SERVER[ \'HTTP_HOST \'] ' ;
1603- EE :: exec ( 'docker-compose exec --user= \' www-data \' php wp config set --type=constant WP_SITEURL \'' . $ set_url . '\' --raw ' );
1604- EE :: exec ( 'docker-compose exec --user= \' www-data \' php wp config set --type=constant WP_HOME \'' . $ set_url . '\' --raw ' );
1578+ \ EE_DOCKER :: docker_compose_exec ( 'wp config set --type=constant WP_SITEURL \'' . $ set_url . '\' --raw ' , ' php ' , ' bash ' , ' www-data ' );
1579+ \ EE_DOCKER :: docker_compose_exec ( 'wp config set --type=constant WP_HOME \'' . $ set_url . '\' --raw ' , ' php ' , ' bash ' , ' www-data ' );
16051580 }
16061581
16071582 EE ::success ( 'WordPress configurations updated for publish. ' );
0 commit comments