Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions src/helper/class-ee-site.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,22 +300,29 @@ public function enable( $args, $assoc_args ) {
}

$success = false;
if ( \EE::docker()::docker_compose_up( $this->site_data->site_fs_path, ['nginx'] ) ) {

$postfix_exists = EE::docker()::service_exists( 'postfix', $this->site_data->site_fs_path );
$containers_to_start = $postfix_exists ? [ 'nginx' ] : [ 'nginx', 'postfix' ];

if ( \EE::docker()::docker_compose_up( $this->site_data->site_fs_path, $containers_to_start ) ) {
$this->site_data->site_enabled = 1;
$this->site_data->save();
$success = true;
}

$site_data_array = (array) $this->site_data;
$this->site_data = reset( $site_data_array );
$this->www_ssl_wrapper();
$this->www_ssl_wrapper( $containers_to_start, true );

if ( $postfix_exists ) {
\EE\Site\Utils\configure_postfix( $this->site_data['site_url'], $this->site_data['site_fs_path'] );
}

if ( true === (bool) $this->site_data['admin_tools'] ) {
EE::runcommand( 'admin-tools enable ' . $this->site_data['site_url'] . ' --force' );
}

if( true === (bool) $this->site_data['mailhog_enabled'] ) {
if ( true === (bool) $this->site_data['mailhog_enabled'] ) {
EE::runcommand( 'mailhog enable ' . $this->site_data['site_url'] );
}

Expand Down Expand Up @@ -471,7 +478,7 @@ private function reload_services( $services, $reload_commands ) {
* @throws EE\ExitException
* @throws \Exception
*/
protected function www_ssl_wrapper( $containers_to_start = [] ) {
protected function www_ssl_wrapper( $containers_to_start = [], $site_enable = false ) {
/**
* This adds http www redirection which is needed for issuing cert for a site.
* i.e. when you create example.com site, certs are issued for example.com and www.example.com
Expand All @@ -497,14 +504,16 @@ protected function www_ssl_wrapper( $containers_to_start = [] ) {
}

if ( $this->site_data['site_ssl'] ) {
$this->init_ssl( $this->site_data['site_url'], $this->site_data['site_fs_path'], $this->site_data['site_ssl'], $this->site_data['site_ssl_wildcard'] );
if ( ! $site_enable ) {
$this->init_ssl( $this->site_data['site_url'], $this->site_data['site_fs_path'], $this->site_data['site_ssl'], $this->site_data['site_ssl_wildcard'] );

if ( $is_www_or_non_www_pointed ) {
\EE\Site\Utils\add_site_redirects( $this->site_data['site_url'], true, 'inherit' === $this->site_data['site_ssl'], $is_www_or_non_www_pointed );
$this->dump_docker_compose_yml( [ 'nohttps' => false ] );
\EE\Site\Utils\start_site_containers( $this->site_data['site_fs_path'], $containers_to_start );
}

$this->dump_docker_compose_yml( [ 'nohttps' => false ] );
\EE\Site\Utils\start_site_containers( $this->site_data['site_fs_path'], $containers_to_start );
if ( $is_www_or_non_www_pointed ) {
\EE\Site\Utils\add_site_redirects( $this->site_data['site_url'], true, 'inherit' === $this->site_data['site_ssl'] );
}

\EE\Site\Utils\reload_global_nginx_proxy();
}
Expand Down