Implement account deletion

This commit is contained in:
Lexi / Zoe 2021-09-16 20:54:21 +02:00
parent 2ccee2169b
commit 930726432e
Signed by: binaryDiv
GPG key ID: F8D4956E224DA232
11 changed files with 130 additions and 28 deletions

View file

@ -212,7 +212,7 @@ class AccountHandler
// Remove existing alias for new username (if wanted)
if ($editData->getUsernameReplaceAlias() && $aliasNeedsToBeReplaced) {
$this->aliasRepository->removeAlias($accountId, $newUsername);
$this->aliasRepository->deleteAlias($accountId, $newUsername);
}
// Commit database transaction
@ -238,4 +238,31 @@ class AccountHandler
'aliases' => $aliases,
];
}
public function deleteAccount(int $accountId): array
{
// Check if account exists
try {
$account = $this->accountRepository->fetchAccountById($accountId);
} catch (AccountNotFoundException $e) {
throw new InputValidationError('Account with ID ' . $accountId . ' does not exist!');
}
// Start database transaction
$this->accountRepository->beginTransaction();
// Delete all aliases associated with this account
$deleteAliasCount = $this->aliasRepository->deleteAllAliasesForUserId($accountId);
// Delete account from database
$this->accountRepository->deleteAccountWithId($accountId);
// Commit database transaction
$this->accountRepository->commitTransaction();
return [
'username' => $account->getUsername(),
'deleted_alias_count' => $deleteAliasCount,
];
}
}