From 61e3c854e68aac27ede70d45c4f021c93499e5b1 Mon Sep 17 00:00:00 2001 From: Alexey Abel Date: Fri, 14 Dec 2018 16:29:57 +0100 Subject: [PATCH] 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. --- lib/Hooks/UserHooks.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/Hooks/UserHooks.php b/lib/Hooks/UserHooks.php index ce0383b..dcd6a4e 100644 --- a/lib/Hooks/UserHooks.php +++ b/lib/Hooks/UserHooks.php @@ -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"