Implement account deletion
This commit is contained in:
parent
2ccee2169b
commit
930726432e
11 changed files with 130 additions and 28 deletions
|
|
@ -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,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue