Make the throwing optional, so background tasks don't break

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2020-12-03 12:16:39 +01:00
parent f0ca76aefb
commit f648635758
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
3 changed files with 13 additions and 5 deletions

View File

@ -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);
}

View File

@ -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'));

View File

@ -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)) {