From eb7cb1193ae778f21ad0d30b2e201d4917d290fc Mon Sep 17 00:00:00 2001 From: mdik Date: Thu, 19 Jul 2018 14:50:52 +0000 Subject: [PATCH] in case no email account are configured, let the hooks pass. --- lib/Hooks/UserHooks.php | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/Hooks/UserHooks.php b/lib/Hooks/UserHooks.php index 5ab60ed..b7c0374 100644 --- a/lib/Hooks/UserHooks.php +++ b/lib/Hooks/UserHooks.php @@ -145,7 +145,7 @@ class UserHooks { // immediately after the creation of the user. $firstAccountsMailAccount = $this->getUsersFirstMailAccount($user); - if ($feature === 'displayName') { + if (($firstAccountsMailAccount) and ($feature === 'displayName')) { $firstAccountsMailAccount->setName($value); $this->accountService->save($firstAccountsMailAccount); $this->logger->debug("Automatically changed sender name for mail account" @@ -160,11 +160,13 @@ class UserHooks { // account is the first one, because it was automatically created // immediately after the creation of the user. $firstAccountsMailAccount = $this->getUsersFirstMailAccount($user); - $firstAccountsMailAccount->setInboundPassword($this->encrypt($password)); - $firstAccountsMailAccount->setOutboundPassword($this->encrypt($password)); - $this->accountService->save($firstAccountsMailAccount); - $this->logger->debug("Automatically changed password for mail account of uid " - . $user->getUID() . ".", $this->logContext); + if ($firstAccountsMailAccount) { + $firstAccountsMailAccount->setInboundPassword($this->encrypt($password)); + $firstAccountsMailAccount->setOutboundPassword($this->encrypt($password)); + $this->accountService->save($firstAccountsMailAccount); + $this->logger->debug("Automatically changed password for mail account of uid " + . $user->getUID() . ".", $this->logContext); + } }; } @@ -175,10 +177,14 @@ class UserHooks { private function getUsersFirstMailAccount(\OC\User\User $user) { $accounts = $this->accountService->findByUserId($user->getUID()); - uksort($accounts, function ($a, $b) { - return ($a['account']['id'] < $b['account']['id']) ? -1 : 1; - }); + if ($accounts) { + uksort($accounts, function ($a, $b) { + return ($a['account']['id'] < $b['account']['id']) ? -1 : 1; + }); - return $accounts[0]->getMailAccount(); + return $accounts[0]->getMailAccount(); + } else { + return false; + } } -} \ No newline at end of file +}