Skip to content

Commit 0f76a18

Browse files
authored
Merge branch 'develop' into fix/wildcard-db-entry
2 parents 44719d3 + 0a8e1f9 commit 0f76a18

File tree

4 files changed

+41
-36
lines changed

4 files changed

+41
-36
lines changed

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ Performs basic site functions in easyengine.
1818
Runs the site creation.
1919

2020
```bash
21-
ee site create example.com # install wordpress without any page caching (default)
22-
ee site create example.com --type=wp # install wordpress without any page caching
23-
ee site create example.com --type=wp --wpredis # install wordpress with page caching
24-
ee site create example.com --type=wp --wpsubir # install wpmu-subdirectory without any page caching
25-
ee site create example.com --type=wp --wpsubir --wpredis # install wpmu-subdirectory with page caching
26-
ee site create example.com --type=wp --wpsubdom # install wpmu-subdomain without any page caching
27-
ee site create example.com --type=wp --wpsubdom --wpredis # install wpmu-subdomain with page cache
21+
ee site create example.com # install wordpress without any page caching (default)
22+
ee site create example.com --type=wp # install wordpress without any page caching
23+
ee site create example.com --type=wp --cache # install wordpress with page caching
24+
ee site create example.com --type=wp --mu=wpsubdir # install wpmu-subdirectory without any page caching
25+
ee site create example.com --type=wp --mu=wpsubdir --cache # install wpmu-subdirectory with page caching
26+
ee site create example.com --type=wp --mu=subdom # install wpmu-subdomain without any page caching
27+
ee site create example.com --type=wp --mu=subdom --cache # install wpmu-subdomain with page cache
2828
```
2929

3030
Let's Encrypt SSL
3131
```bash
3232
# Enable SSL using Let’s Encrypt (You can add --letsencrypt along with any other flag.)
33-
ee site create example.com [--letsencrypt|--le]
34-
ee site create example.com --le # install wordpress without any page caching + letsencrypt ssl
35-
ee site create example.com --wpredis --le # install wordpress with page caching + letsencrypt ssl
36-
ee site create example.com --wpsubdom --le # install wordpress wpmu-subdomain + wildcard letsencrypt ssl
33+
ee site create example.com --type=wp [--letsencrypt|--le]
34+
ee site create example.com --type=wp --le # install wordpress without any page caching + letsencrypt ssl
35+
ee site create example.com --type=wp --cache --le # install wordpress with page caching + letsencrypt ssl
36+
ee site create example.com --type=wp --mu=subdom --le # install wordpress wpmu-subdomain + wildcard letsencrypt ssl
3737
```
3838

3939
## delete

features/site.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Feature: Site Command
2626
| HTTP/1.1 200 OK |
2727

2828
Scenario: Create wpsubdir site successfully
29-
When I run 'bin/ee site create wpsubdir.test --type=wp --wpsubdir'
29+
When I run 'bin/ee site create wpsubdir.test --type=wp --mu=subdir'
3030
And I create subsite '1' in 'wpsubdir.test'
3131
Then The site 'wpsubdir.test' should have webroot
3232
And The site 'wpsubdir.test' should have WordPress
@@ -36,7 +36,7 @@ Feature: Site Command
3636
| HTTP/1.1 200 OK |
3737

3838
Scenario: Create wpsubdom site successfully
39-
When I run 'bin/ee site create wpsubdom.test --type=wp --wpsubdom'
39+
When I run 'bin/ee site create wpsubdom.test --type=wp --mu=subdom'
4040
And I create subsite '1' in 'wpsubdom.test'
4141
Then The site 'wpsubdom.test' should have webroot
4242
And The site 'wpsubdom.test' should have WordPress

src/Site_WP_Command.php

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,14 @@ public function __construct() {
112112
* [--wp]
113113
* : WordPress website.
114114
*
115-
* [--wpredis]
116-
* : Use redis for WordPress.
115+
* [--cache]
116+
* : Use redis cache for WordPress.
117117
*
118-
* [--wpsubdir]
118+
*
119+
* [--mu=<subdir>]
119120
* : WordPress sub-dir Multi-site.
120121
*
121-
* [--wpsubdom]
122+
* [--mu=<subdom>]
122123
* : WordPress sub-domain Multi-site.
123124
*
124125
* [--title=<title>]
@@ -191,17 +192,20 @@ public function create( $args, $assoc_args ) {
191192
$this->logger->debug( 'args:', $args );
192193
$this->logger->debug( 'assoc_args:', empty( $assoc_args ) ? array( 'NULL' ) : $assoc_args );
193194
$this->site['name'] = strtolower( EE\Utils\remove_trailing_slash( $args[0] ) );
194-
$this->site['type'] = EE\Utils\get_type( $assoc_args, [ 'wp', 'wpsubdom', 'wpsubdir' ], 'wp' );
195-
if ( false === $this->site['type'] ) {
196-
EE::error( 'Invalid arguments' );
195+
196+
$mu = EE\Utils\get_flag_value( $assoc_args, 'mu' );
197+
198+
if ( isset( $assoc_args['mu'] ) && ! in_array( $mu, [ 'subdom', 'subdir' ], true ) ) {
199+
EE::error( "Unrecognized multi-site parameter: $mu. Only `--mu=subdom` and `--mu=subdir` are supported." );
197200
}
201+
$this->site['type'] = $mu ?? 'wp';
198202

199203
if ( EE::db()::site_in_db( $this->site['name'] ) ) {
200204
EE::error( sprintf( "Site %1\$s already exists. If you want to re-create it please delete the older one using:\n`ee site delete %1\$s`", $this->site['name'] ) );
201205
}
202206

203207
$this->proxy_type = EE_PROXY_TYPE;
204-
$this->cache_type = empty( $assoc_args['wpredis'] ) ? 'none' : 'wpredis';
208+
$this->cache_type = EE\Utils\get_flag_value( $assoc_args, 'cache' );
205209
$this->le = EE\Utils\get_flag_value( $assoc_args, 'letsencrypt' );
206210
$this->site['title'] = EE\Utils\get_flag_value( $assoc_args, 'title', $this->site['name'] );
207211
$this->site['user'] = EE\Utils\get_flag_value( $assoc_args, 'admin_user', 'admin' );
@@ -260,7 +264,7 @@ public function info( $args ) {
260264
[ 'DB User', $this->db['user'] ],
261265
[ 'DB Password', $this->db['pass'] ],
262266
[ 'E-Mail', $this->site['email'] ],
263-
[ 'Cache Type', $this->cache_type ],
267+
[ 'Cache', $this->cache_type ? 'Enabled' : 'none' ],
264268
[ 'SSL', $ssl ],
265269
];
266270

@@ -284,15 +288,15 @@ private function configure_site_files() {
284288
$site_conf_env = $this->site['root'] . '/.env';
285289
$site_nginx_default_conf = $site_conf_dir . '/nginx/default.conf';
286290
$site_php_ini = $site_conf_dir . '/php-fpm/php.ini';
287-
$server_name = ( 'wpsubdom' === $this->site['type'] ) ? $this->site['name'] . ' *.' . $this->site['name'] : $this->site['name'];
291+
$server_name = ( 'subdom' === $this->site['type'] ) ? $this->site['name'] . ' *.' . $this->site['name'] : $this->site['name'];
288292
$process_user = posix_getpwuid( posix_geteuid() );
289293

290294
EE::log( 'Creating WordPress site ' . $this->site['name'] );
291295
EE::log( 'Copying configuration files.' );
292296

293297
$filter = [];
294298
$filter[] = $this->site['type'];
295-
$filter[] = $this->cache_type;
299+
$filter[] = $this->cache_type ? 'redis' : 'none';
296300
$filter[] = $this->le;
297301
$filter[] = $this->db['host'];
298302
$site_docker = new Site_WP_Docker();
@@ -339,19 +343,19 @@ private function configure_site_files() {
339343
/**
340344
* Function to generate default.conf from mustache templates.
341345
*
342-
* @param string $site_type Type of site (wpsubdom, wpredis etc..).
343-
* @param string $cache_type Type of cache(wpredis or none).
344-
* @param string $server_name Name of server to use in virtual_host.
346+
* @param string $site_type Type of site (subdom, subdir etc..).
347+
* @param boolean $cache_type Cache enabled or not.
348+
* @param string $server_name Name of server to use in virtual_host.
345349
*
346350
* @return string Parsed mustache template string output.
347351
*/
348352
private function generate_default_conf( $site_type, $cache_type, $server_name ) {
349353

350354
$default_conf_data['site_type'] = $site_type;
351355
$default_conf_data['server_name'] = $server_name;
352-
$default_conf_data['include_php_conf'] = $cache_type !== 'wpredis';
353-
$default_conf_data['include_wpsubdir_conf'] = $site_type === 'wpsubdir';
354-
$default_conf_data['include_redis_conf'] = $cache_type === 'wpredis';
356+
$default_conf_data['include_php_conf'] = ! $cache_type;
357+
$default_conf_data['include_wpsubdir_conf'] = $site_type === 'subdir';
358+
$default_conf_data['include_redis_conf'] = $cache_type;
355359

356360
return EE\Utils\mustache_render( SITE_WP_TEMPLATE_ROOT . '/config/nginx/default.conf.mustache', $default_conf_data );
357361
}
@@ -415,7 +419,8 @@ private function create_site( $assoc_args ) {
415419
}
416420

417421
if ( $this->le ) {
418-
$this->init_le();
422+
$wildcard = 'subdom' === $this->site['type'] ? true : false;
423+
$this->init_le( $this->site['name'], $this->site['root'], $wildcard );
419424
}
420425
$this->info( [ $this->site['name'] ], [] );
421426
$this->create_site_db_entry();
@@ -520,9 +525,9 @@ private function install_wp() {
520525
$wp_install_command = 'install';
521526
$maybe_multisite_type = '';
522527

523-
if ( 'wpsubdom' === $this->site['type'] || 'wpsubdir' === $this->site['type'] ) {
528+
if ( 'subdom' === $this->site['type'] || 'subdir' === $this->site['type'] ) {
524529
$wp_install_command = 'multisite-install';
525-
$maybe_multisite_type = $this->site['type'] === 'wpsubdom' ? '--subdomains' : '';
530+
$maybe_multisite_type = $this->site['type'] === 'subdom' ? '--subdomains' : '';
526531
}
527532

528533
$install_command = sprintf( 'docker-compose exec --user=\'www-data\' php wp core %s --url=\'%s\' --title=\'%s\' --admin_user=\'%s\'', $wp_install_command, $this->site['name'], $this->site['title'], $this->site['user'] );
@@ -550,7 +555,7 @@ private function create_site_db_entry() {
550555
'site_title' => $this->site['title'],
551556
'site_command' => $this->command,
552557
'proxy_type' => $this->proxy_type,
553-
'cache_type' => $this->cache_type,
558+
'cache_type' => (int) $this->cache_type,
554559
'site_path' => $this->site['root'],
555560
'db_name' => $this->db['name'],
556561
'db_user' => $this->db['user'],

src/Site_WP_Docker.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function generate_docker_compose_yml( array $filters = [] ) {
8181
$nginx['depends_on'] = [ 'name' => 'php' ];
8282
$nginx['restart'] = $restart_default;
8383

84-
$v_host = in_array( 'wpsubdom', $filters, true ) ? 'VIRTUAL_HOST=${VIRTUAL_HOST},*.${VIRTUAL_HOST}' : 'VIRTUAL_HOST';
84+
$v_host = in_array( 'subdom', $filters, true ) ? 'VIRTUAL_HOST=${VIRTUAL_HOST},*.${VIRTUAL_HOST}' : 'VIRTUAL_HOST';
8585

8686
$nginx['environment'] = [
8787
'env' => [
@@ -161,7 +161,7 @@ public function generate_docker_compose_yml( array $filters = [] ) {
161161
//$base[] = $mailhog;
162162
$base[] = $phpmyadmin;
163163

164-
if ( in_array( 'wpredis', $filters, true ) ) {
164+
if ( in_array( 'redis', $filters, true ) ) {
165165
$base[] = $redis;
166166
}
167167

0 commit comments

Comments
 (0)