Skip to content

Commit

Permalink
Merge pull request #381 from kirtangajjar/fix/host-entry-removal
Browse files Browse the repository at this point in the history
🐛 Remove site host entry on delete
  • Loading branch information
mrrobot47 committed Jun 28, 2021
2 parents ea2ec06 + 0a426f4 commit cf2b84d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
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 );
}

0 comments on commit cf2b84d

Please sign in to comment.