Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Remove site host entry on delete #381

Merged
merged 3 commits into from Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/helper/class-ee-site.php
Expand Up @@ -265,6 +265,8 @@ protected function delete_site( $level, $site_url, $site_fs_path, $db_data = []
\EE::log( "[$site_url] site root removed." );
}

\EE\Site\Utils\remove_etc_hosts_entry( $site_url );

$config_file_path = EE_ROOT_DIR . '/services/nginx-proxy/conf.d/' . $site_url . '-redirect.conf';

if ( $this->fs->exists( $config_file_path ) ) {
Expand Down Expand Up @@ -1524,7 +1526,7 @@ protected function check_www_or_non_www_domain( $site_url, $site_path, $site_con
*
* [--force]
* : Force renewal.
*
*
* @subcommand ssl-verify
* @alias ssl
*/
Expand Down
17 changes: 17 additions & 0 deletions src/helper/site-utils.php
Expand Up @@ -738,3 +738,20 @@ function sysctl_parameters() {

return [];
}

/**
* Removes entry of the site from /etc/hosts
*
* @param string $site_url site name.
*
*/
function remove_etc_hosts_entry( $site_url ) {
$fs = new Filesystem();

$hosts_file = file_get_contents( '/etc/hosts' );

$site_url_escaped = preg_replace( '/\./', '\.', $site_url );
$hosts_file_new = preg_replace( "/127\.0\.0\.1\s+$site_url_escaped\n/", '', $hosts_file );

$fs->dumpFile( '/etc/hosts', $hosts_file_new );
}