|
|
|
|
@ -26,7 +26,6 @@ declare(strict_types=1); |
|
|
|
|
|
|
|
|
|
namespace OC\Repair\NC21; |
|
|
|
|
|
|
|
|
|
use OC\Accounts\AccountManager; |
|
|
|
|
use OCP\Accounts\IAccountManager; |
|
|
|
|
use OCP\IConfig; |
|
|
|
|
use OCP\IUser; |
|
|
|
|
@ -40,11 +39,11 @@ class ValidatePhoneNumber implements IRepairStep { |
|
|
|
|
protected $config; |
|
|
|
|
/** @var IUserManager */ |
|
|
|
|
protected $userManager; |
|
|
|
|
/** @var AccountManager */ |
|
|
|
|
/** @var IAccountManager */ |
|
|
|
|
private $accountManager; |
|
|
|
|
|
|
|
|
|
public function __construct(IUserManager $userManager, |
|
|
|
|
AccountManager $accountManager, |
|
|
|
|
IAccountManager $accountManager, |
|
|
|
|
IConfig $config) { |
|
|
|
|
$this->config = $config; |
|
|
|
|
$this->userManager = $userManager; |
|
|
|
|
@ -55,10 +54,6 @@ class ValidatePhoneNumber implements IRepairStep { |
|
|
|
|
return 'Validate the phone number and store it in a known format for search'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private function shouldRun(): bool { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function run(IOutput $output): void { |
|
|
|
|
if ($this->config->getSystemValueString('default_phone_region', '') === '') { |
|
|
|
|
throw new \Exception('Can not validate phone numbers without `default_phone_region` being set in the config file'); |
|
|
|
|
@ -68,13 +63,16 @@ class ValidatePhoneNumber implements IRepairStep { |
|
|
|
|
$numRemoved = 0; |
|
|
|
|
|
|
|
|
|
$this->userManager->callForSeenUsers(function (IUser $user) use (&$numUpdated, &$numRemoved) { |
|
|
|
|
$account = $this->accountManager->getUser($user); |
|
|
|
|
$account = $this->accountManager->getAccount($user); |
|
|
|
|
$property = $account->getProperty(IAccountManager::PROPERTY_PHONE); |
|
|
|
|
|
|
|
|
|
if ($account[IAccountManager::PROPERTY_PHONE]['value'] !== '') { |
|
|
|
|
$updated = $this->accountManager->updateUser($user, $account); |
|
|
|
|
if ($property->getValue() !== '') { |
|
|
|
|
$this->accountManager->updateAccount($account); |
|
|
|
|
$updatedAccount = $this->accountManager->getAccount($user); |
|
|
|
|
$updatedProperty = $updatedAccount->getProperty(IAccountManager::PROPERTY_PHONE); |
|
|
|
|
|
|
|
|
|
if ($account[IAccountManager::PROPERTY_PHONE]['value'] !== $updated[IAccountManager::PROPERTY_PHONE]['value']) { |
|
|
|
|
if ($updated[IAccountManager::PROPERTY_PHONE]['value'] === '') { |
|
|
|
|
if ($property->getValue() !== $updatedProperty->getValue()) { |
|
|
|
|
if ($updatedProperty->getValue() === '') { |
|
|
|
|
$numRemoved++; |
|
|
|
|
} else { |
|
|
|
|
$numUpdated++; |
|
|
|
|
|