diff --git a/src/library/Server/Manager/Directadmin.php b/src/library/Server/Manager/Directadmin.php index 5c62d38ee..a91576963 100644 --- a/src/library/Server/Manager/Directadmin.php +++ b/src/library/Server/Manager/Directadmin.php @@ -85,11 +85,15 @@ class Server_Manager_Directadmin extends Server_Manager * Cancels an account on the DirectAdmin server. * This method sends a request to the server to delete the account. * + * Some DirectAdmin servers return an error for this request even though the + * deletion already succeeded, so on failure we double check whether the + * account still exists before giving up. + * * @param Server_Account $account the account to be cancelled * * @return bool returns true if the account is successfully cancelled * - * @throws Server_Exception if there is an error while sending the request to the server + * @throws Server_Exception if there is an error while sending the request to the server and the account still exists */ public function cancelAccount(Server_Account $account): bool { @@ -99,11 +103,40 @@ class Server_Manager_Directadmin extends Server_Manager 'select0' => $account->getUsername(), ]; - $this->request('API_SELECT_USERS', $fields); + try { + $this->request('API_SELECT_USERS', $fields); + } catch (Server_Exception $e) { + if ($this->accountExists($account)) { + throw $e; + } + + $this->getLog()->info("Deletion of {$account->getUsername()} reported an error, but the account no longer exists on the server."); + } return true; } + /** + * Checks whether an account still exists on the DirectAdmin server. + * If the check itself fails, the account is assumed to still exist so a + * transport, authentication, or permission error is never mistaken for a + * successful deletion. + * + * @param Server_Account $account the account to check + * + * @return bool true if the account still exists, false otherwise + */ + private function accountExists(Server_Account $account): bool + { + try { + $users = $this->request('API_SHOW_USERS'); + } catch (Server_Exception) { + return true; + } + + return in_array($account->getUsername(), $users['list'] ?? [], true); + } + /** * Returns the port number for the DirectAdmin server. * If the port is set in the configuration, verify that it's a valid port number (1 - 65535).