Make the throwing optional, so background tasks don't break
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
f0ca76aefb
commit
f648635758
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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'));
|
||||
|
|
|
@ -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)) {
|
||||
|
|
Loading…
Reference in New Issue