Fix deletion of users when no mail account is present

Instead of catching a null reference for non-existing mail accounts, it seems
to be easier to only get the mail acccount when we actually want to do
something with it. Since we are only intersted in the change of the display
name, the retreival of the user account has been moved to that if-branch.
This also seems more like a Nextcloud bug, since it fails on errors of hooks.
This commit is contained in:
Alexey Abel 2018-12-14 16:29:57 +01:00
parent d66507d818
commit 61e3c854e6
1 changed files with 4 additions and 5 deletions

View File

@ -140,12 +140,11 @@ class UserHooks {
private function changeUserCallbackFunction() {
return function (\OC\User\User $user, string $feature, string $value) {
// The assumption is made that the automatically created mail
// account is the first one, because it was automatically created
// immediately after the creation of the user.
$firstAccountsMailAccount = $this->getUsersFirstMailAccount($user);
if ($feature === 'displayName') {
// The assumption is made that the automatically created mail
// account is the first one, because it was automatically created
// immediately after the creation of the user.
$firstAccountsMailAccount = $this->getUsersFirstMailAccount($user);
$firstAccountsMailAccount->setName($value);
$this->accountService->save($firstAccountsMailAccount);
$this->logger->debug("Automatically changed sender name for mail account"