From 0de685c5629deb66984e536e5fd20f140228aa3f Mon Sep 17 00:00:00 2001 From: Bjoern Schiessle Date: Wed, 23 Nov 2016 23:57:20 +0100 Subject: bring back setEmailAddress for the user management Signed-off-by: Bjoern Schiessle --- lib/private/Accounts/AccountManager.php | 4 ---- lib/private/Accounts/Hooks.php | 36 +++++++++++++++++++++++++-------- 2 files changed, 28 insertions(+), 12 deletions(-) (limited to 'lib/private/Accounts') diff --git a/lib/private/Accounts/AccountManager.php b/lib/private/Accounts/AccountManager.php index 8c7cd010de1..3701421a20f 100644 --- a/lib/private/Accounts/AccountManager.php +++ b/lib/private/Accounts/AccountManager.php @@ -23,7 +23,6 @@ namespace OC\Accounts; -use OCP\IConfig; use OCP\IDBConnection; use OCP\IUser; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -63,9 +62,6 @@ class AccountManager { /** @var EventDispatcherInterface */ private $eventDispatcher; - /** @var IConfig */ - private $config; - /** * AccountManager constructor. * diff --git a/lib/private/Accounts/Hooks.php b/lib/private/Accounts/Hooks.php index 187024e5472..38e7e20485b 100644 --- a/lib/private/Accounts/Hooks.php +++ b/lib/private/Accounts/Hooks.php @@ -22,6 +22,7 @@ namespace OC\Accounts; +use OCP\ILogger; use OCP\IUser; class Hooks { @@ -29,6 +30,18 @@ class Hooks { /** @var AccountManager */ private $accountManager = null; + /** @var ILogger */ + private $logger; + + /** + * Hooks constructor. + * + * @param ILogger $logger + */ + public function __construct(ILogger $logger) { + $this->logger = $logger; + } + /** * update accounts table if email address or display name was changed from outside * @@ -36,25 +49,31 @@ class Hooks { */ public function changeUserHook($params) { - $this->instantiateAccountManager(); + $accountManager = $this->getAccountManager(); /** @var IUser $user */ - $user = $params['user']; - $feature = $params['feature']; - $newValue = $params['value']; - $accountData = $this->accountManager->getUser($user); + $user = isset($params['user']) ? $params['user'] : null; + $feature = isset($params['feature']) ? $params['feature'] : null; + $newValue = isset($params['value']) ? $params['value'] : null; + + if (is_null($user) || is_null($feature) || is_null($newValue)) { + $this->logger->warning('Missing expected parameters in change user hook'); + return; + } + + $accountData = $accountManager->getUser($user); switch ($feature) { case 'eMailAddress': if ($accountData[AccountManager::PROPERTY_EMAIL]['value'] !== $newValue) { $accountData[AccountManager::PROPERTY_EMAIL]['value'] = $newValue; - $this->accountManager->updateUser($user, $accountData); + $accountManager->updateUser($user, $accountData); } break; case 'displayName': if ($accountData[AccountManager::PROPERTY_DISPLAYNAME]['value'] !== $newValue) { $accountData[AccountManager::PROPERTY_DISPLAYNAME]['value'] = $newValue; - $this->accountManager->updateUser($user, $accountData); + $accountManager->updateUser($user, $accountData); } break; } @@ -66,13 +85,14 @@ class Hooks { * * @return AccountManager */ - protected function instantiateAccountManager() { + protected function getAccountManager() { if (is_null($this->accountManager)) { $this->accountManager = new AccountManager( \OC::$server->getDatabaseConnection(), \OC::$server->getEventDispatcher() ); } + return $this->accountManager; } } -- cgit v1.2.3