diff options
author | Joas Schilling <coding@schilljs.com> | 2020-12-03 12:16:39 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2020-12-07 14:19:38 +0100 |
commit | f648635758e34bab0173e02eb9b75aafc5e6a9ff (patch) | |
tree | 2864de1966f655eeef2078d14b5837821869c17f | |
parent | f0ca76aefbe7717b9555e0dffb8c9340e14bf3cf (diff) | |
download | nextcloud-server-f648635758e34bab0173e02eb9b75aafc5e6a9ff.tar.gz nextcloud-server-f648635758e34bab0173e02eb9b75aafc5e6a9ff.zip |
Make the throwing optional, so background tasks don't break
Signed-off-by: Joas Schilling <coding@schilljs.com>
-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)) { |