@@ -443,21 +443,18 @@ public function create( $args, $assoc_args ) {
443
443
*/
444
444
private function enable_object_cache () {
445
445
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 ' );
454
450
}
455
451
456
452
/**
457
453
* Enable page cache.
458
454
*/
459
455
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 ' );
461
458
$ nginx_helper_fail_msg = 'Unable to download or activate nginx-helper plugin properly. ' ;
462
459
$ page_cache_key_prefix = $ this ->site_data ['site_url ' ] . '_page: ' ;
463
460
$ obj_cache_key_prefix = $ this ->site_data ['site_url ' ] . '_obj: ' ;
@@ -493,35 +490,13 @@ private function enable_page_cache() {
493
490
$ page_cache_key_prefix
494
491
);
495
492
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
+
525
500
}
526
501
527
502
/**
@@ -532,6 +507,7 @@ private function docker_compose_exec( $command, $fail_msg = '' ) {
532
507
* @return string Generated db user.
533
508
*/
534
509
private function create_site_db_user ( string $ site_url ): string {
510
+
535
511
if ( strlen ( $ site_url ) > 53 ) {
536
512
$ site_url = substr ( $ site_url , 0 , 53 );
537
513
}
@@ -998,7 +974,7 @@ private function maybe_verify_remote_db_connection() {
998
974
*/
999
975
private function create_site ( $ assoc_args ) {
1000
976
1001
- $ this ->level = 1 ;
977
+ $ this ->level = 1 ;
1002
978
try {
1003
979
if ( 'inherit ' === $ this ->site_data ['site_ssl ' ] ) {
1004
980
$ this ->check_parent_site_certs ( $ this ->site_data ['site_url ' ] );
@@ -1060,7 +1036,7 @@ private function create_site( $assoc_args ) {
1060
1036
}
1061
1037
1062
1038
// 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 ' );
1064
1040
1065
1041
$ this ->create_site_db_entry ();
1066
1042
\EE ::log ( 'Site entry created. ' );
@@ -1123,25 +1099,24 @@ private function wp_download_and_config( $assoc_args ) {
1123
1099
$ wp_cli_data = EE \Utils \mustache_render ( SITE_WP_TEMPLATE_ROOT . '/wp-cli.yml.mustache ' , [ 'wp_path ' => $ public_dir_path ] );
1124
1100
$ this ->fs ->dumpFile ( $ this ->site_data ['site_fs_path ' ] . '/app/htdocs/wp-cli.yml ' , $ wp_cli_data );
1125
1101
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 ' );
1127
1103
}
1128
1104
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 ' );
1131
1106
1132
1107
$ 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 " ;
1134
1109
1135
- if ( ! \EE :: exec ( $ core_download_command ) ) {
1110
+ if ( ! \EE_DOCKER :: docker_compose_exec ( $ core_download_command, ' php ' , ' bash ' , ' www-data ' ) ) {
1136
1111
\EE ::error ( 'Unable to download wp core. ' , false );
1137
1112
}
1138
1113
1139
1114
if ( 'db ' === $ this ->site_data ['db_host ' ] ) {
1140
1115
$ 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 ' ] );
1142
1117
$ count = 0 ;
1143
1118
while ( $ mysql_unhealthy ) {
1144
- $ mysql_unhealthy = ! \EE :: exec ( $ health_chk );
1119
+ $ mysql_unhealthy = ! \EE_DOCKER :: docker_compose_exec ( $ health_chk, ' php ' , ' bash ' , ' root ' );
1145
1120
if ( $ count ++ > 180 ) {
1146
1121
break ;
1147
1122
}
@@ -1161,7 +1136,6 @@ private function wp_download_and_config( $assoc_args ) {
1161
1136
. '// Use dev versions of core JS and CSS files (only needed if you are modifying these core files) '
1162
1137
. "\n" . 'define( \'SCRIPT_DEBUG \', false ); ' ;
1163
1138
1164
-
1165
1139
if ( 'wp ' !== $ this ->site_data ['app_sub_type ' ] ) {
1166
1140
$ extra_php .= "\n\n// Disable cookie domain. \ndefine( 'COOKIE_DOMAIN', false ); " ;
1167
1141
}
@@ -1172,19 +1146,19 @@ private function wp_download_and_config( $assoc_args ) {
1172
1146
}
1173
1147
1174
1148
$ 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 );
1176
1150
1177
1151
try {
1178
- if ( ! \EE :: exec ( $ wp_config_create_command ) ) {
1152
+ if ( ! \EE_DOCKER :: docker_compose_exec ( $ wp_config_create_command, ' php ' , ' bash ' , ' www-data ' ) ) {
1179
1153
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 ' ] ) );
1180
1154
}
1181
1155
1182
1156
$ default_wp_config_path = sprintf ( '%s/wp-config.php ' , $ this ->site_data ['site_container_fs_path ' ] );
1183
1157
$ level_above_path = preg_replace ( '/[^\/]+$/ ' , '' , $ this ->site_data ['site_container_fs_path ' ] );
1184
1158
$ new_wp_config_path = sprintf ( '%swp-config.php ' , $ level_above_path );
1185
1159
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 ' ) ) {
1188
1162
throw new \Exception ( sprintf ( 'Couldn \'t move wp-config.php from %1$s to %2$s ' , $ default_wp_config_path , $ new_wp_config_path ) );
1189
1163
}
1190
1164
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() {
1212
1186
}
1213
1187
1214
1188
$ 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 ' ] );
1216
1190
$ install_command .= $ this ->site_data ['app_admin_password ' ] ? sprintf ( ' --admin_password= \'%s \'' , $ this ->site_data ['app_admin_password ' ] ) : '' ;
1217
1191
$ install_command .= sprintf ( ' --admin_email= \'%s \' %s ' , $ this ->site_data ['app_admin_email ' ], $ maybe_multisite_type );
1218
1192
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 , [
1220
1194
$ this ->site_data ['app_admin_username ' ],
1221
1195
$ this ->site_data ['app_admin_email ' ],
1222
1196
$ this ->site_data ['app_admin_password ' ],
1223
1197
] );
1224
1198
1225
- EE ::exec ( 'docker-compose exec php wp rewrite structure "/%year%/%monthnum%/%day%/%postname%/" --hard ' );
1226
-
1227
1199
if ( ! $ core_install ) {
1228
1200
throw new \Exception ( 'WordPress install failed. Please check logs. ' );
1229
1201
}
1230
1202
1203
+ \EE_DOCKER ::docker_compose_exec ( 'wp rewrite structure "/%year%/%monthnum%/%day%/%postname%/" --hard ' , 'php ' , 'bash ' , 'www-data ' );
1204
+
1231
1205
$ env_type = \EE ::get_runner ()->config ['env ' ];
1232
1206
$ env_type = in_array ( $ env_type , [ 'production ' , 'staging ' , 'development ' , 'local ' ] ) ? $ env_type : '' ;
1233
1207
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 ' );
1235
1209
}
1236
1210
1237
1211
\EE ::success ( $ prefix . $ this ->site_data ['site_url ' ] . ' has been created successfully! ' );
@@ -1380,7 +1354,7 @@ private function setup_vip( $assoc_args ) {
1380
1354
chdir ( $ this ->site_data ['site_fs_path ' ] );
1381
1355
1382
1356
// 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 ' );
1384
1358
1385
1359
\EE ::log ( "VIP Go environment setup completed. " );
1386
1360
}
@@ -1582,6 +1556,7 @@ public function reload( $args, $assoc_args, $whitelisted_containers = [], $reloa
1582
1556
*
1583
1557
*/
1584
1558
public function share ( $ args , $ assoc_args ) {
1559
+
1585
1560
parent ::share ( $ args , $ assoc_args );
1586
1561
1587
1562
$ disable = get_flag_value ( $ assoc_args , 'disable ' , false );
@@ -1594,14 +1569,14 @@ public function share( $args, $assoc_args ) {
1594
1569
EE ::log ( 'Running additional WordPress configurations. ' );
1595
1570
chdir ( $ this ->site_data ->site_fs_path );
1596
1571
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 ' );
1600
1575
} 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 ' );
1602
1577
$ 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 ' );
1605
1580
}
1606
1581
1607
1582
EE ::success ( 'WordPress configurations updated for publish. ' );
0 commit comments