Skip to content

Commit f543a19

Browse files
committed
Make the throwing optional, so background tasks don't break
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent a901a2b commit f543a19

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

apps/provisioning_api/lib/Controller/UsersController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ public function editUser(string $userId, string $key, string $value): DataRespon
654654
if ($userAccount[$key]['value'] !== $value) {
655655
$userAccount[$key]['value'] = $value;
656656
try {
657-
$this->accountManager->updateUser($targetUser, $userAccount);
657+
$this->accountManager->updateUser($targetUser, $userAccount, true);
658658
} catch (\InvalidArgumentException $e) {
659659
throw new OCSException('Invalid ' . $e->getMessage(), 102);
660660
}

apps/settings/lib/Controller/UsersController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ protected function saveUserSettings(IUser $user, array $data): array {
466466
}
467467

468468
try {
469-
return $this->accountManager->updateUser($user, $data);
469+
return $this->accountManager->updateUser($user, $data, true);
470470
} catch (\InvalidArgumentException $e) {
471471
if ($e->getMessage() === IAccountManager::PROPERTY_PHONE) {
472472
throw new \InvalidArgumentException($this->l10n->t('Unable to set invalid phone number'));

lib/private/Accounts/AccountManager.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,23 @@ protected function parsePhoneNumber(string $input): string {
125125
*
126126
* @param IUser $user
127127
* @param array $data
128+
* @param bool $throwOnData Set to true if you can inform the user about invalid data
128129
* @return array The potentially modified data (e.g. phone numbers are converted to E.164 format)
129130
* @throws \InvalidArgumentException Message is the property that was invalid
130131
*/
131-
public function updateUser(IUser $user, array $data): array {
132+
public function updateUser(IUser $user, array $data, bool $throwOnData = false): array {
132133
$userData = $this->getUser($user);
133134
$updated = true;
134135

135-
if (isset($data[self::PROPERTY_PHONE])) {
136-
$data[self::PROPERTY_PHONE]['value'] = $this->parsePhoneNumber($data[self::PROPERTY_PHONE]['value']);
136+
if (isset($data[self::PROPERTY_PHONE]) && $data[self::PROPERTY_PHONE]['value'] !== '') {
137+
try {
138+
$data[self::PROPERTY_PHONE]['value'] = $this->parsePhoneNumber($data[self::PROPERTY_PHONE]['value']);
139+
} catch (\InvalidArgumentException $e) {
140+
if ($throwOnData) {
141+
throw $e;
142+
}
143+
$data[self::PROPERTY_PHONE]['value'] = '';
144+
}
137145
}
138146

139147
if (empty($userData)) {

0 commit comments

Comments
 (0)