diff options
-rw-r--r-- | apps/provisioning_api/lib/Controller/UsersController.php | 2 | ||||
-rw-r--r-- | apps/settings/lib/Controller/UsersController.php | 2 | ||||
-rw-r--r-- | lib/private/Accounts/AccountManager.php | 14 |
3 files changed, 13 insertions, 5 deletions
diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index edb1fc5121a..18baa07a395 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -655,7 +655,7 @@ class UsersController extends AUserData { if ($userAccount[$key]['value'] !== $value) { $userAccount[$key]['value'] = $value; try { - $this->accountManager->updateUser($targetUser, $userAccount); + $this->accountManager->updateUser($targetUser, $userAccount, true); } catch (\InvalidArgumentException $e) { throw new OCSException('Invalid ' . $e->getMessage(), 102); } diff --git a/apps/settings/lib/Controller/UsersController.php b/apps/settings/lib/Controller/UsersController.php index 5b3c1574f96..dba5ec69b2b 100644 --- a/apps/settings/lib/Controller/UsersController.php +++ b/apps/settings/lib/Controller/UsersController.php @@ -466,7 +466,7 @@ class UsersController extends Controller { } try { - return $this->accountManager->updateUser($user, $data); + return $this->accountManager->updateUser($user, $data, true); } catch (\InvalidArgumentException $e) { if ($e->getMessage() === IAccountManager::PROPERTY_PHONE) { throw new \InvalidArgumentException($this->l10n->t('Unable to set invalid phone number')); diff --git a/lib/private/Accounts/AccountManager.php b/lib/private/Accounts/AccountManager.php index 8640ce269ea..05feaf87b8f 100644 --- a/lib/private/Accounts/AccountManager.php +++ b/lib/private/Accounts/AccountManager.php @@ -125,15 +125,23 @@ class AccountManager implements IAccountManager { * * @param IUser $user * @param array $data + * @param bool $throwOnData Set to true if you can inform the user about invalid data * @return array The potentially modified data (e.g. phone numbers are converted to E.164 format) * @throws \InvalidArgumentException Message is the property that was invalid */ - public function updateUser(IUser $user, array $data): array { + public function updateUser(IUser $user, array $data, bool $throwOnData = false): array { $userData = $this->getUser($user); $updated = true; - if (isset($data[self::PROPERTY_PHONE])) { - $data[self::PROPERTY_PHONE]['value'] = $this->parsePhoneNumber($data[self::PROPERTY_PHONE]['value']); + if (isset($data[self::PROPERTY_PHONE]) && $data[self::PROPERTY_PHONE]['value'] !== '') { + try { + $data[self::PROPERTY_PHONE]['value'] = $this->parsePhoneNumber($data[self::PROPERTY_PHONE]['value']); + } catch (\InvalidArgumentException $e) { + if ($throwOnData) { + throw $e; + } + $data[self::PROPERTY_PHONE]['value'] = ''; + } } if (empty($userData)) { |