config = $config; $this->userManager = $userManager; $this->accountManager = $accountManager; } public function getName(): string { return 'Validate the phone number and store it in a known format for search'; } public function run(IOutput $output): void { if ($this->config->getSystemValueString('default_phone_region', '') === '') { $output->warning('Can not validate phone numbers without `default_phone_region` being set in the config file'); return; } $numUpdated = 0; $numRemoved = 0; $this->userManager->callForSeenUsers(function (IUser $user) use (&$numUpdated, &$numRemoved) { $account = $this->accountManager->getAccount($user); $property = $account->getProperty(IAccountManager::PROPERTY_PHONE); if ($property->getValue() !== '') { $this->accountManager->updateAccount($account); $updatedAccount = $this->accountManager->getAccount($user); $updatedProperty = $updatedAccount->getProperty(IAccountManager::PROPERTY_PHONE); if ($property->getValue() !== $updatedProperty->getValue()) { if ($updatedProperty->getValue() === '') { $numRemoved++; } else { $numUpdated++; } } } }); if ($numRemoved > 0 || $numUpdated > 0) { $output->info('Updated ' . $numUpdated . ' entries and cleaned ' . $numRemoved . ' invalid phone numbers'); } } }