diff --git a/src/helper/class-ee-site.php b/src/helper/class-ee-site.php index 95a2701d..2cad657b 100644 --- a/src/helper/class-ee-site.php +++ b/src/helper/class-ee-site.php @@ -8,6 +8,8 @@ use EE\Model\Cron; use EE\Model\Site; use EE\Model\Option; +use EE\Model\Auth; +use EE\Model\Whitelist; use Symfony\Component\Filesystem\Filesystem; use function EE\Site\Cloner\Utils\check_site_access; use function EE\Site\Cloner\Utils\copy_site_db; @@ -363,6 +365,32 @@ protected function delete_site( $level, $site_url, $site_fs_path, $db_data = [] } } + $site_auth_file = EE_ROOT_DIR . '/services/nginx-proxy/htpasswd/' . $site_url; + if ( $this->fs->exists( $site_auth_file ) ) { + try { + $this->fs->remove( $site_auth_file ); + } catch ( \Exception $e ) { + \EE::warning( $e ); + } + reload_global_nginx_proxy(); + } + + $whitelists = Whitelist::where( [ + 'site_url' => $site_url, + ] ); + + foreach ( $whitelists as $whitelist ) { + $whitelist->delete(); + } + + $auths = Auth::where( [ + 'site_url' => $site_url, + ] ); + + foreach ( $auths as $auth ) { + $auth->delete(); + } + if ( Site::find( $site_url )->delete() ) { \EE::log( 'Removed database entry.' ); } else {