@@ -73,182 +73,182 @@ |
||
| 73 | 73 | |
| 74 | 74 | class Repair implements IOutput { |
| 75 | 75 | |
| 76 | - /** @var IRepairStep[] */ |
|
| 77 | - private $repairSteps; |
|
| 78 | - |
|
| 79 | - /** @var EventDispatcherInterface */ |
|
| 80 | - private $dispatcher; |
|
| 81 | - |
|
| 82 | - /** @var string */ |
|
| 83 | - private $currentStep; |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Creates a new repair step runner |
|
| 87 | - * |
|
| 88 | - * @param IRepairStep[] $repairSteps array of RepairStep instances |
|
| 89 | - * @param EventDispatcherInterface $dispatcher |
|
| 90 | - */ |
|
| 91 | - public function __construct(array $repairSteps, EventDispatcherInterface $dispatcher) { |
|
| 92 | - $this->repairSteps = $repairSteps; |
|
| 93 | - $this->dispatcher = $dispatcher; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Run a series of repair steps for common problems |
|
| 98 | - */ |
|
| 99 | - public function run() { |
|
| 100 | - if (count($this->repairSteps) === 0) { |
|
| 101 | - $this->emit('\OC\Repair', 'info', ['No repair steps available']); |
|
| 102 | - |
|
| 103 | - return; |
|
| 104 | - } |
|
| 105 | - // run each repair step |
|
| 106 | - foreach ($this->repairSteps as $step) { |
|
| 107 | - $this->currentStep = $step->getName(); |
|
| 108 | - $this->emit('\OC\Repair', 'step', [$this->currentStep]); |
|
| 109 | - $step->run($this); |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Add repair step |
|
| 115 | - * |
|
| 116 | - * @param IRepairStep|string $repairStep repair step |
|
| 117 | - * @throws \Exception |
|
| 118 | - */ |
|
| 119 | - public function addStep($repairStep) { |
|
| 120 | - if (is_string($repairStep)) { |
|
| 121 | - try { |
|
| 122 | - $s = \OC::$server->query($repairStep); |
|
| 123 | - } catch (QueryException $e) { |
|
| 124 | - if (class_exists($repairStep)) { |
|
| 125 | - $s = new $repairStep(); |
|
| 126 | - } else { |
|
| 127 | - throw new \Exception("Repair step '$repairStep' is unknown"); |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - if ($s instanceof IRepairStep) { |
|
| 132 | - $this->repairSteps[] = $s; |
|
| 133 | - } else { |
|
| 134 | - throw new \Exception("Repair step '$repairStep' is not of type \\OCP\\Migration\\IRepairStep"); |
|
| 135 | - } |
|
| 136 | - } else { |
|
| 137 | - $this->repairSteps[] = $repairStep; |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Returns the default repair steps to be run on the |
|
| 143 | - * command line or after an upgrade. |
|
| 144 | - * |
|
| 145 | - * @return IRepairStep[] |
|
| 146 | - */ |
|
| 147 | - public static function getRepairSteps() { |
|
| 148 | - return [ |
|
| 149 | - new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->getDatabaseConnection(), false), |
|
| 150 | - new RepairMimeTypes(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), |
|
| 151 | - new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()), |
|
| 152 | - new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), |
|
| 153 | - new MoveUpdaterStepFile(\OC::$server->getConfig()), |
|
| 154 | - new FixMountStorages(\OC::$server->getDatabaseConnection()), |
|
| 155 | - new AddLogRotateJob(\OC::$server->getJobList()), |
|
| 156 | - new ClearFrontendCaches(\OC::$server->getMemCacheFactory(), \OC::$server->query(SCSSCacher::class), \OC::$server->query(JSCombiner::class)), |
|
| 157 | - new ClearGeneratedAvatarCache(\OC::$server->getConfig(), \OC::$server->query(AvatarManager::class)), |
|
| 158 | - new AddPreviewBackgroundCleanupJob(\OC::$server->getJobList()), |
|
| 159 | - new AddCleanupUpdaterBackupsJob(\OC::$server->getJobList()), |
|
| 160 | - new CleanupCardDAVPhotoCache(\OC::$server->getConfig(), \OC::$server->getAppDataDir('dav-photocache'), \OC::$server->getLogger()), |
|
| 161 | - new AddClenupLoginFlowV2BackgroundJob(\OC::$server->getJobList()), |
|
| 162 | - new RemoveLinkShares(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getGroupManager(), \OC::$server->getNotificationManager(), \OC::$server->query(ITimeFactory::class)), |
|
| 163 | - new ClearCollectionsAccessCache(\OC::$server->getConfig(), \OC::$server->query(IManager::class)), |
|
| 164 | - \OC::$server->query(ResetGeneratedAvatarFlag::class), |
|
| 165 | - \OC::$server->query(EncryptionLegacyCipher::class), |
|
| 166 | - \OC::$server->query(EncryptionMigration::class), |
|
| 167 | - \OC::$server->get(ShippedDashboardEnable::class), |
|
| 168 | - \OC::$server->get(AddBruteForceCleanupJob::class), |
|
| 169 | - \OC::$server->get(AddCheckForUserCertificatesJob::class), |
|
| 170 | - ]; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Returns expensive repair steps to be run on the |
|
| 175 | - * command line with a special option. |
|
| 176 | - * |
|
| 177 | - * @return IRepairStep[] |
|
| 178 | - */ |
|
| 179 | - public static function getExpensiveRepairSteps() { |
|
| 180 | - return [ |
|
| 181 | - new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()), |
|
| 182 | - \OC::$server->get(ValidatePhoneNumber::class), |
|
| 183 | - ]; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * Returns the repair steps to be run before an |
|
| 188 | - * upgrade. |
|
| 189 | - * |
|
| 190 | - * @return IRepairStep[] |
|
| 191 | - */ |
|
| 192 | - public static function getBeforeUpgradeRepairSteps() { |
|
| 193 | - $connection = \OC::$server->getDatabaseConnection(); |
|
| 194 | - $config = \OC::$server->getConfig(); |
|
| 195 | - $steps = [ |
|
| 196 | - new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), $connection, true), |
|
| 197 | - new SqliteAutoincrement($connection), |
|
| 198 | - new SaveAccountsTableData($connection, $config), |
|
| 199 | - new DropAccountTermsTable($connection) |
|
| 200 | - ]; |
|
| 201 | - |
|
| 202 | - return $steps; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - /** |
|
| 206 | - * @param string $scope |
|
| 207 | - * @param string $method |
|
| 208 | - * @param array $arguments |
|
| 209 | - */ |
|
| 210 | - public function emit($scope, $method, array $arguments = []) { |
|
| 211 | - if (!is_null($this->dispatcher)) { |
|
| 212 | - $this->dispatcher->dispatch("$scope::$method", |
|
| 213 | - new GenericEvent("$scope::$method", $arguments)); |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - public function info($string) { |
|
| 218 | - // for now just emit as we did in the past |
|
| 219 | - $this->emit('\OC\Repair', 'info', [$string]); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * @param string $message |
|
| 224 | - */ |
|
| 225 | - public function warning($message) { |
|
| 226 | - // for now just emit as we did in the past |
|
| 227 | - $this->emit('\OC\Repair', 'warning', [$message]); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * @param int $max |
|
| 232 | - */ |
|
| 233 | - public function startProgress($max = 0) { |
|
| 234 | - // for now just emit as we did in the past |
|
| 235 | - $this->emit('\OC\Repair', 'startProgress', [$max, $this->currentStep]); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * @param int $step |
|
| 240 | - * @param string $description |
|
| 241 | - */ |
|
| 242 | - public function advance($step = 1, $description = '') { |
|
| 243 | - // for now just emit as we did in the past |
|
| 244 | - $this->emit('\OC\Repair', 'advance', [$step, $description]); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * @param int $max |
|
| 249 | - */ |
|
| 250 | - public function finishProgress() { |
|
| 251 | - // for now just emit as we did in the past |
|
| 252 | - $this->emit('\OC\Repair', 'finishProgress', []); |
|
| 253 | - } |
|
| 76 | + /** @var IRepairStep[] */ |
|
| 77 | + private $repairSteps; |
|
| 78 | + |
|
| 79 | + /** @var EventDispatcherInterface */ |
|
| 80 | + private $dispatcher; |
|
| 81 | + |
|
| 82 | + /** @var string */ |
|
| 83 | + private $currentStep; |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Creates a new repair step runner |
|
| 87 | + * |
|
| 88 | + * @param IRepairStep[] $repairSteps array of RepairStep instances |
|
| 89 | + * @param EventDispatcherInterface $dispatcher |
|
| 90 | + */ |
|
| 91 | + public function __construct(array $repairSteps, EventDispatcherInterface $dispatcher) { |
|
| 92 | + $this->repairSteps = $repairSteps; |
|
| 93 | + $this->dispatcher = $dispatcher; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Run a series of repair steps for common problems |
|
| 98 | + */ |
|
| 99 | + public function run() { |
|
| 100 | + if (count($this->repairSteps) === 0) { |
|
| 101 | + $this->emit('\OC\Repair', 'info', ['No repair steps available']); |
|
| 102 | + |
|
| 103 | + return; |
|
| 104 | + } |
|
| 105 | + // run each repair step |
|
| 106 | + foreach ($this->repairSteps as $step) { |
|
| 107 | + $this->currentStep = $step->getName(); |
|
| 108 | + $this->emit('\OC\Repair', 'step', [$this->currentStep]); |
|
| 109 | + $step->run($this); |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Add repair step |
|
| 115 | + * |
|
| 116 | + * @param IRepairStep|string $repairStep repair step |
|
| 117 | + * @throws \Exception |
|
| 118 | + */ |
|
| 119 | + public function addStep($repairStep) { |
|
| 120 | + if (is_string($repairStep)) { |
|
| 121 | + try { |
|
| 122 | + $s = \OC::$server->query($repairStep); |
|
| 123 | + } catch (QueryException $e) { |
|
| 124 | + if (class_exists($repairStep)) { |
|
| 125 | + $s = new $repairStep(); |
|
| 126 | + } else { |
|
| 127 | + throw new \Exception("Repair step '$repairStep' is unknown"); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + if ($s instanceof IRepairStep) { |
|
| 132 | + $this->repairSteps[] = $s; |
|
| 133 | + } else { |
|
| 134 | + throw new \Exception("Repair step '$repairStep' is not of type \\OCP\\Migration\\IRepairStep"); |
|
| 135 | + } |
|
| 136 | + } else { |
|
| 137 | + $this->repairSteps[] = $repairStep; |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Returns the default repair steps to be run on the |
|
| 143 | + * command line or after an upgrade. |
|
| 144 | + * |
|
| 145 | + * @return IRepairStep[] |
|
| 146 | + */ |
|
| 147 | + public static function getRepairSteps() { |
|
| 148 | + return [ |
|
| 149 | + new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->getDatabaseConnection(), false), |
|
| 150 | + new RepairMimeTypes(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), |
|
| 151 | + new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()), |
|
| 152 | + new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), |
|
| 153 | + new MoveUpdaterStepFile(\OC::$server->getConfig()), |
|
| 154 | + new FixMountStorages(\OC::$server->getDatabaseConnection()), |
|
| 155 | + new AddLogRotateJob(\OC::$server->getJobList()), |
|
| 156 | + new ClearFrontendCaches(\OC::$server->getMemCacheFactory(), \OC::$server->query(SCSSCacher::class), \OC::$server->query(JSCombiner::class)), |
|
| 157 | + new ClearGeneratedAvatarCache(\OC::$server->getConfig(), \OC::$server->query(AvatarManager::class)), |
|
| 158 | + new AddPreviewBackgroundCleanupJob(\OC::$server->getJobList()), |
|
| 159 | + new AddCleanupUpdaterBackupsJob(\OC::$server->getJobList()), |
|
| 160 | + new CleanupCardDAVPhotoCache(\OC::$server->getConfig(), \OC::$server->getAppDataDir('dav-photocache'), \OC::$server->getLogger()), |
|
| 161 | + new AddClenupLoginFlowV2BackgroundJob(\OC::$server->getJobList()), |
|
| 162 | + new RemoveLinkShares(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getGroupManager(), \OC::$server->getNotificationManager(), \OC::$server->query(ITimeFactory::class)), |
|
| 163 | + new ClearCollectionsAccessCache(\OC::$server->getConfig(), \OC::$server->query(IManager::class)), |
|
| 164 | + \OC::$server->query(ResetGeneratedAvatarFlag::class), |
|
| 165 | + \OC::$server->query(EncryptionLegacyCipher::class), |
|
| 166 | + \OC::$server->query(EncryptionMigration::class), |
|
| 167 | + \OC::$server->get(ShippedDashboardEnable::class), |
|
| 168 | + \OC::$server->get(AddBruteForceCleanupJob::class), |
|
| 169 | + \OC::$server->get(AddCheckForUserCertificatesJob::class), |
|
| 170 | + ]; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Returns expensive repair steps to be run on the |
|
| 175 | + * command line with a special option. |
|
| 176 | + * |
|
| 177 | + * @return IRepairStep[] |
|
| 178 | + */ |
|
| 179 | + public static function getExpensiveRepairSteps() { |
|
| 180 | + return [ |
|
| 181 | + new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()), |
|
| 182 | + \OC::$server->get(ValidatePhoneNumber::class), |
|
| 183 | + ]; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * Returns the repair steps to be run before an |
|
| 188 | + * upgrade. |
|
| 189 | + * |
|
| 190 | + * @return IRepairStep[] |
|
| 191 | + */ |
|
| 192 | + public static function getBeforeUpgradeRepairSteps() { |
|
| 193 | + $connection = \OC::$server->getDatabaseConnection(); |
|
| 194 | + $config = \OC::$server->getConfig(); |
|
| 195 | + $steps = [ |
|
| 196 | + new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), $connection, true), |
|
| 197 | + new SqliteAutoincrement($connection), |
|
| 198 | + new SaveAccountsTableData($connection, $config), |
|
| 199 | + new DropAccountTermsTable($connection) |
|
| 200 | + ]; |
|
| 201 | + |
|
| 202 | + return $steps; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + /** |
|
| 206 | + * @param string $scope |
|
| 207 | + * @param string $method |
|
| 208 | + * @param array $arguments |
|
| 209 | + */ |
|
| 210 | + public function emit($scope, $method, array $arguments = []) { |
|
| 211 | + if (!is_null($this->dispatcher)) { |
|
| 212 | + $this->dispatcher->dispatch("$scope::$method", |
|
| 213 | + new GenericEvent("$scope::$method", $arguments)); |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + public function info($string) { |
|
| 218 | + // for now just emit as we did in the past |
|
| 219 | + $this->emit('\OC\Repair', 'info', [$string]); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * @param string $message |
|
| 224 | + */ |
|
| 225 | + public function warning($message) { |
|
| 226 | + // for now just emit as we did in the past |
|
| 227 | + $this->emit('\OC\Repair', 'warning', [$message]); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * @param int $max |
|
| 232 | + */ |
|
| 233 | + public function startProgress($max = 0) { |
|
| 234 | + // for now just emit as we did in the past |
|
| 235 | + $this->emit('\OC\Repair', 'startProgress', [$max, $this->currentStep]); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + /** |
|
| 239 | + * @param int $step |
|
| 240 | + * @param string $description |
|
| 241 | + */ |
|
| 242 | + public function advance($step = 1, $description = '') { |
|
| 243 | + // for now just emit as we did in the past |
|
| 244 | + $this->emit('\OC\Repair', 'advance', [$step, $description]); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * @param int $max |
|
| 249 | + */ |
|
| 250 | + public function finishProgress() { |
|
| 251 | + // for now just emit as we did in the past |
|
| 252 | + $this->emit('\OC\Repair', 'finishProgress', []); |
|
| 253 | + } |
|
| 254 | 254 | } |
@@ -30,61 +30,61 @@ |
||
| 30 | 30 | |
| 31 | 31 | class Hooks { |
| 32 | 32 | |
| 33 | - /** @var AccountManager|null */ |
|
| 34 | - private $accountManager; |
|
| 33 | + /** @var AccountManager|null */ |
|
| 34 | + private $accountManager; |
|
| 35 | 35 | |
| 36 | - /** @var LoggerInterface */ |
|
| 37 | - private $logger; |
|
| 36 | + /** @var LoggerInterface */ |
|
| 37 | + private $logger; |
|
| 38 | 38 | |
| 39 | - public function __construct(LoggerInterface $logger) { |
|
| 40 | - $this->logger = $logger; |
|
| 41 | - } |
|
| 39 | + public function __construct(LoggerInterface $logger) { |
|
| 40 | + $this->logger = $logger; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * update accounts table if email address or display name was changed from outside |
|
| 45 | - * |
|
| 46 | - * @param array $params |
|
| 47 | - */ |
|
| 48 | - public function changeUserHook($params) { |
|
| 49 | - $accountManager = $this->getAccountManager(); |
|
| 43 | + /** |
|
| 44 | + * update accounts table if email address or display name was changed from outside |
|
| 45 | + * |
|
| 46 | + * @param array $params |
|
| 47 | + */ |
|
| 48 | + public function changeUserHook($params) { |
|
| 49 | + $accountManager = $this->getAccountManager(); |
|
| 50 | 50 | |
| 51 | - /** @var IUser $user */ |
|
| 52 | - $user = isset($params['user']) ? $params['user'] : null; |
|
| 53 | - $feature = isset($params['feature']) ? $params['feature'] : null; |
|
| 54 | - $newValue = isset($params['value']) ? $params['value'] : null; |
|
| 51 | + /** @var IUser $user */ |
|
| 52 | + $user = isset($params['user']) ? $params['user'] : null; |
|
| 53 | + $feature = isset($params['feature']) ? $params['feature'] : null; |
|
| 54 | + $newValue = isset($params['value']) ? $params['value'] : null; |
|
| 55 | 55 | |
| 56 | - if (is_null($user) || is_null($feature) || is_null($newValue)) { |
|
| 57 | - $this->logger->warning('Missing expected parameters in change user hook'); |
|
| 58 | - return; |
|
| 59 | - } |
|
| 56 | + if (is_null($user) || is_null($feature) || is_null($newValue)) { |
|
| 57 | + $this->logger->warning('Missing expected parameters in change user hook'); |
|
| 58 | + return; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - $accountData = $accountManager->getUser($user); |
|
| 61 | + $accountData = $accountManager->getUser($user); |
|
| 62 | 62 | |
| 63 | - switch ($feature) { |
|
| 64 | - case 'eMailAddress': |
|
| 65 | - if ($accountData[IAccountManager::PROPERTY_EMAIL]['value'] !== $newValue) { |
|
| 66 | - $accountData[IAccountManager::PROPERTY_EMAIL]['value'] = $newValue; |
|
| 67 | - $accountManager->updateUser($user, $accountData); |
|
| 68 | - } |
|
| 69 | - break; |
|
| 70 | - case 'displayName': |
|
| 71 | - if ($accountData[IAccountManager::PROPERTY_DISPLAYNAME]['value'] !== $newValue) { |
|
| 72 | - $accountData[IAccountManager::PROPERTY_DISPLAYNAME]['value'] = $newValue; |
|
| 73 | - $accountManager->updateUser($user, $accountData); |
|
| 74 | - } |
|
| 75 | - break; |
|
| 76 | - } |
|
| 77 | - } |
|
| 63 | + switch ($feature) { |
|
| 64 | + case 'eMailAddress': |
|
| 65 | + if ($accountData[IAccountManager::PROPERTY_EMAIL]['value'] !== $newValue) { |
|
| 66 | + $accountData[IAccountManager::PROPERTY_EMAIL]['value'] = $newValue; |
|
| 67 | + $accountManager->updateUser($user, $accountData); |
|
| 68 | + } |
|
| 69 | + break; |
|
| 70 | + case 'displayName': |
|
| 71 | + if ($accountData[IAccountManager::PROPERTY_DISPLAYNAME]['value'] !== $newValue) { |
|
| 72 | + $accountData[IAccountManager::PROPERTY_DISPLAYNAME]['value'] = $newValue; |
|
| 73 | + $accountManager->updateUser($user, $accountData); |
|
| 74 | + } |
|
| 75 | + break; |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * return instance of accountManager |
|
| 81 | - * |
|
| 82 | - * @return AccountManager |
|
| 83 | - */ |
|
| 84 | - protected function getAccountManager(): AccountManager { |
|
| 85 | - if ($this->accountManager === null) { |
|
| 86 | - $this->accountManager = \OC::$server->query(AccountManager::class); |
|
| 87 | - } |
|
| 88 | - return $this->accountManager; |
|
| 89 | - } |
|
| 79 | + /** |
|
| 80 | + * return instance of accountManager |
|
| 81 | + * |
|
| 82 | + * @return AccountManager |
|
| 83 | + */ |
|
| 84 | + protected function getAccountManager(): AccountManager { |
|
| 85 | + if ($this->accountManager === null) { |
|
| 86 | + $this->accountManager = \OC::$server->query(AccountManager::class); |
|
| 87 | + } |
|
| 88 | + return $this->accountManager; |
|
| 89 | + } |
|
| 90 | 90 | } |
@@ -58,414 +58,414 @@ |
||
| 58 | 58 | */ |
| 59 | 59 | class AccountManager implements IAccountManager { |
| 60 | 60 | |
| 61 | - /** @var IDBConnection database connection */ |
|
| 62 | - private $connection; |
|
| 63 | - |
|
| 64 | - /** @var IConfig */ |
|
| 65 | - private $config; |
|
| 66 | - |
|
| 67 | - /** @var string table name */ |
|
| 68 | - private $table = 'accounts'; |
|
| 69 | - |
|
| 70 | - /** @var string table name */ |
|
| 71 | - private $dataTable = 'accounts_data'; |
|
| 72 | - |
|
| 73 | - /** @var EventDispatcherInterface */ |
|
| 74 | - private $eventDispatcher; |
|
| 75 | - |
|
| 76 | - /** @var IJobList */ |
|
| 77 | - private $jobList; |
|
| 78 | - |
|
| 79 | - /** @var LoggerInterface */ |
|
| 80 | - private $logger; |
|
| 81 | - |
|
| 82 | - public function __construct(IDBConnection $connection, |
|
| 83 | - IConfig $config, |
|
| 84 | - EventDispatcherInterface $eventDispatcher, |
|
| 85 | - IJobList $jobList, |
|
| 86 | - LoggerInterface $logger) { |
|
| 87 | - $this->connection = $connection; |
|
| 88 | - $this->config = $config; |
|
| 89 | - $this->eventDispatcher = $eventDispatcher; |
|
| 90 | - $this->jobList = $jobList; |
|
| 91 | - $this->logger = $logger; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @param string $input |
|
| 96 | - * @return string Provided phone number in E.164 format when it was a valid number |
|
| 97 | - * @throws \InvalidArgumentException When the phone number was invalid or no default region is set and the number doesn't start with a country code |
|
| 98 | - */ |
|
| 99 | - protected function parsePhoneNumber(string $input): string { |
|
| 100 | - $defaultRegion = $this->config->getSystemValueString('default_phone_region', ''); |
|
| 101 | - |
|
| 102 | - if ($defaultRegion === '') { |
|
| 103 | - // When no default region is set, only +49… numbers are valid |
|
| 104 | - if (strpos($input, '+') !== 0) { |
|
| 105 | - throw new \InvalidArgumentException(self::PROPERTY_PHONE); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - $defaultRegion = 'EN'; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - $phoneUtil = PhoneNumberUtil::getInstance(); |
|
| 112 | - try { |
|
| 113 | - $phoneNumber = $phoneUtil->parse($input, $defaultRegion); |
|
| 114 | - if ($phoneNumber instanceof PhoneNumber && $phoneUtil->isValidNumber($phoneNumber)) { |
|
| 115 | - return $phoneUtil->format($phoneNumber, PhoneNumberFormat::E164); |
|
| 116 | - } |
|
| 117 | - } catch (NumberParseException $e) { |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - throw new \InvalidArgumentException(self::PROPERTY_PHONE); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * update user record |
|
| 125 | - * |
|
| 126 | - * @param IUser $user |
|
| 127 | - * @param array $data |
|
| 128 | - * @param bool $throwOnData Set to true if you can inform the user about invalid data |
|
| 129 | - * @return array The potentially modified data (e.g. phone numbers are converted to E.164 format) |
|
| 130 | - * @throws \InvalidArgumentException Message is the property that was invalid |
|
| 131 | - */ |
|
| 132 | - public function updateUser(IUser $user, array $data, bool $throwOnData = false): array { |
|
| 133 | - $userData = $this->getUser($user); |
|
| 134 | - $updated = true; |
|
| 135 | - |
|
| 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 | - } |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - if (empty($userData)) { |
|
| 148 | - $this->insertNewUser($user, $data); |
|
| 149 | - } elseif ($userData !== $data) { |
|
| 150 | - $data = $this->checkEmailVerification($userData, $data, $user); |
|
| 151 | - $data = $this->updateVerifyStatus($userData, $data); |
|
| 152 | - $this->updateExistingUser($user, $data); |
|
| 153 | - } else { |
|
| 154 | - // nothing needs to be done if new and old data set are the same |
|
| 155 | - $updated = false; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - if ($updated) { |
|
| 159 | - $this->eventDispatcher->dispatch( |
|
| 160 | - 'OC\AccountManager::userUpdated', |
|
| 161 | - new GenericEvent($user, $data) |
|
| 162 | - ); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - return $data; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * delete user from accounts table |
|
| 170 | - * |
|
| 171 | - * @param IUser $user |
|
| 172 | - */ |
|
| 173 | - public function deleteUser(IUser $user) { |
|
| 174 | - $uid = $user->getUID(); |
|
| 175 | - $query = $this->connection->getQueryBuilder(); |
|
| 176 | - $query->delete($this->table) |
|
| 177 | - ->where($query->expr()->eq('uid', $query->createNamedParameter($uid))) |
|
| 178 | - ->execute(); |
|
| 179 | - |
|
| 180 | - $this->deleteUserData($user); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * delete user from accounts table |
|
| 185 | - * |
|
| 186 | - * @param IUser $user |
|
| 187 | - */ |
|
| 188 | - public function deleteUserData(IUser $user): void { |
|
| 189 | - $uid = $user->getUID(); |
|
| 190 | - $query = $this->connection->getQueryBuilder(); |
|
| 191 | - $query->delete($this->dataTable) |
|
| 192 | - ->where($query->expr()->eq('uid', $query->createNamedParameter($uid))) |
|
| 193 | - ->execute(); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * get stored data from a given user |
|
| 198 | - * |
|
| 199 | - * @param IUser $user |
|
| 200 | - * @return array |
|
| 201 | - */ |
|
| 202 | - public function getUser(IUser $user) { |
|
| 203 | - $uid = $user->getUID(); |
|
| 204 | - $query = $this->connection->getQueryBuilder(); |
|
| 205 | - $query->select('data') |
|
| 206 | - ->from($this->table) |
|
| 207 | - ->where($query->expr()->eq('uid', $query->createParameter('uid'))) |
|
| 208 | - ->setParameter('uid', $uid); |
|
| 209 | - $result = $query->execute(); |
|
| 210 | - $accountData = $result->fetchAll(); |
|
| 211 | - $result->closeCursor(); |
|
| 212 | - |
|
| 213 | - if (empty($accountData)) { |
|
| 214 | - $userData = $this->buildDefaultUserRecord($user); |
|
| 215 | - $this->insertNewUser($user, $userData); |
|
| 216 | - return $userData; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - $userDataArray = json_decode($accountData[0]['data'], true); |
|
| 220 | - $jsonError = json_last_error(); |
|
| 221 | - if ($userDataArray === null || $userDataArray === [] || $jsonError !== JSON_ERROR_NONE) { |
|
| 222 | - $this->logger->critical("User data of $uid contained invalid JSON (error $jsonError), hence falling back to a default user record"); |
|
| 223 | - return $this->buildDefaultUserRecord($user); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - $userDataArray = $this->addMissingDefaultValues($userDataArray); |
|
| 227 | - |
|
| 228 | - return $userDataArray; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - public function searchUsers(string $property, array $values): array { |
|
| 232 | - $query = $this->connection->getQueryBuilder(); |
|
| 233 | - $query->select('*') |
|
| 234 | - ->from($this->dataTable) |
|
| 235 | - ->where($query->expr()->eq('name', $query->createNamedParameter($property))) |
|
| 236 | - ->andWhere($query->expr()->in('value', $query->createNamedParameter($values, IQueryBuilder::PARAM_STR_ARRAY))); |
|
| 237 | - |
|
| 238 | - $result = $query->execute(); |
|
| 239 | - $matches = []; |
|
| 240 | - |
|
| 241 | - while ($row = $result->fetch()) { |
|
| 242 | - $matches[$row['value']] = $row['uid']; |
|
| 243 | - } |
|
| 244 | - $result->closeCursor(); |
|
| 245 | - |
|
| 246 | - return $matches; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * check if we need to ask the server for email verification, if yes we create a cronjob |
|
| 251 | - * |
|
| 252 | - * @param $oldData |
|
| 253 | - * @param $newData |
|
| 254 | - * @param IUser $user |
|
| 255 | - * @return array |
|
| 256 | - */ |
|
| 257 | - protected function checkEmailVerification($oldData, $newData, IUser $user) { |
|
| 258 | - if ($oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value']) { |
|
| 259 | - $this->jobList->add(VerifyUserData::class, |
|
| 260 | - [ |
|
| 261 | - 'verificationCode' => '', |
|
| 262 | - 'data' => $newData[self::PROPERTY_EMAIL]['value'], |
|
| 263 | - 'type' => self::PROPERTY_EMAIL, |
|
| 264 | - 'uid' => $user->getUID(), |
|
| 265 | - 'try' => 0, |
|
| 266 | - 'lastRun' => time() |
|
| 267 | - ] |
|
| 268 | - ); |
|
| 269 | - $newData[self::PROPERTY_EMAIL]['verified'] = self::VERIFICATION_IN_PROGRESS; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - return $newData; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * make sure that all expected data are set |
|
| 277 | - * |
|
| 278 | - * @param array $userData |
|
| 279 | - * @return array |
|
| 280 | - */ |
|
| 281 | - protected function addMissingDefaultValues(array $userData) { |
|
| 282 | - foreach ($userData as $key => $value) { |
|
| 283 | - if (!isset($userData[$key]['verified'])) { |
|
| 284 | - $userData[$key]['verified'] = self::NOT_VERIFIED; |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - return $userData; |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * reset verification status if personal data changed |
|
| 293 | - * |
|
| 294 | - * @param array $oldData |
|
| 295 | - * @param array $newData |
|
| 296 | - * @return array |
|
| 297 | - */ |
|
| 298 | - protected function updateVerifyStatus($oldData, $newData) { |
|
| 299 | - |
|
| 300 | - // which account was already verified successfully? |
|
| 301 | - $twitterVerified = isset($oldData[self::PROPERTY_TWITTER]['verified']) && $oldData[self::PROPERTY_TWITTER]['verified'] === self::VERIFIED; |
|
| 302 | - $websiteVerified = isset($oldData[self::PROPERTY_WEBSITE]['verified']) && $oldData[self::PROPERTY_WEBSITE]['verified'] === self::VERIFIED; |
|
| 303 | - $emailVerified = isset($oldData[self::PROPERTY_EMAIL]['verified']) && $oldData[self::PROPERTY_EMAIL]['verified'] === self::VERIFIED; |
|
| 304 | - |
|
| 305 | - // keep old verification status if we don't have a new one |
|
| 306 | - if (!isset($newData[self::PROPERTY_TWITTER]['verified'])) { |
|
| 307 | - // keep old verification status if value didn't changed and an old value exists |
|
| 308 | - $keepOldStatus = $newData[self::PROPERTY_TWITTER]['value'] === $oldData[self::PROPERTY_TWITTER]['value'] && isset($oldData[self::PROPERTY_TWITTER]['verified']); |
|
| 309 | - $newData[self::PROPERTY_TWITTER]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_TWITTER]['verified'] : self::NOT_VERIFIED; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - if (!isset($newData[self::PROPERTY_WEBSITE]['verified'])) { |
|
| 313 | - // keep old verification status if value didn't changed and an old value exists |
|
| 314 | - $keepOldStatus = $newData[self::PROPERTY_WEBSITE]['value'] === $oldData[self::PROPERTY_WEBSITE]['value'] && isset($oldData[self::PROPERTY_WEBSITE]['verified']); |
|
| 315 | - $newData[self::PROPERTY_WEBSITE]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_WEBSITE]['verified'] : self::NOT_VERIFIED; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - if (!isset($newData[self::PROPERTY_EMAIL]['verified'])) { |
|
| 319 | - // keep old verification status if value didn't changed and an old value exists |
|
| 320 | - $keepOldStatus = $newData[self::PROPERTY_EMAIL]['value'] === $oldData[self::PROPERTY_EMAIL]['value'] && isset($oldData[self::PROPERTY_EMAIL]['verified']); |
|
| 321 | - $newData[self::PROPERTY_EMAIL]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_EMAIL]['verified'] : self::VERIFICATION_IN_PROGRESS; |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - // reset verification status if a value from a previously verified data was changed |
|
| 325 | - if ($twitterVerified && |
|
| 326 | - $oldData[self::PROPERTY_TWITTER]['value'] !== $newData[self::PROPERTY_TWITTER]['value'] |
|
| 327 | - ) { |
|
| 328 | - $newData[self::PROPERTY_TWITTER]['verified'] = self::NOT_VERIFIED; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - if ($websiteVerified && |
|
| 332 | - $oldData[self::PROPERTY_WEBSITE]['value'] !== $newData[self::PROPERTY_WEBSITE]['value'] |
|
| 333 | - ) { |
|
| 334 | - $newData[self::PROPERTY_WEBSITE]['verified'] = self::NOT_VERIFIED; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - if ($emailVerified && |
|
| 338 | - $oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value'] |
|
| 339 | - ) { |
|
| 340 | - $newData[self::PROPERTY_EMAIL]['verified'] = self::NOT_VERIFIED; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - return $newData; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * add new user to accounts table |
|
| 348 | - * |
|
| 349 | - * @param IUser $user |
|
| 350 | - * @param array $data |
|
| 351 | - */ |
|
| 352 | - protected function insertNewUser(IUser $user, array $data): void { |
|
| 353 | - $uid = $user->getUID(); |
|
| 354 | - $jsonEncodedData = json_encode($data); |
|
| 355 | - $query = $this->connection->getQueryBuilder(); |
|
| 356 | - $query->insert($this->table) |
|
| 357 | - ->values( |
|
| 358 | - [ |
|
| 359 | - 'uid' => $query->createNamedParameter($uid), |
|
| 360 | - 'data' => $query->createNamedParameter($jsonEncodedData), |
|
| 361 | - ] |
|
| 362 | - ) |
|
| 363 | - ->execute(); |
|
| 364 | - |
|
| 365 | - $this->deleteUserData($user); |
|
| 366 | - $this->writeUserData($user, $data); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * update existing user in accounts table |
|
| 371 | - * |
|
| 372 | - * @param IUser $user |
|
| 373 | - * @param array $data |
|
| 374 | - */ |
|
| 375 | - protected function updateExistingUser(IUser $user, array $data): void { |
|
| 376 | - $uid = $user->getUID(); |
|
| 377 | - $jsonEncodedData = json_encode($data); |
|
| 378 | - $query = $this->connection->getQueryBuilder(); |
|
| 379 | - $query->update($this->table) |
|
| 380 | - ->set('data', $query->createNamedParameter($jsonEncodedData)) |
|
| 381 | - ->where($query->expr()->eq('uid', $query->createNamedParameter($uid))) |
|
| 382 | - ->execute(); |
|
| 383 | - |
|
| 384 | - $this->deleteUserData($user); |
|
| 385 | - $this->writeUserData($user, $data); |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - protected function writeUserData(IUser $user, array $data): void { |
|
| 389 | - $query = $this->connection->getQueryBuilder(); |
|
| 390 | - $query->insert($this->dataTable) |
|
| 391 | - ->values( |
|
| 392 | - [ |
|
| 393 | - 'uid' => $query->createNamedParameter($user->getUID()), |
|
| 394 | - 'name' => $query->createParameter('name'), |
|
| 395 | - 'value' => $query->createParameter('value'), |
|
| 396 | - ] |
|
| 397 | - ); |
|
| 398 | - foreach ($data as $propertyName => $property) { |
|
| 399 | - if ($propertyName === self::PROPERTY_AVATAR) { |
|
| 400 | - continue; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - $query->setParameter('name', $propertyName) |
|
| 404 | - ->setParameter('value', $property['value']); |
|
| 405 | - $query->execute(); |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * build default user record in case not data set exists yet |
|
| 411 | - * |
|
| 412 | - * @param IUser $user |
|
| 413 | - * @return array |
|
| 414 | - */ |
|
| 415 | - protected function buildDefaultUserRecord(IUser $user) { |
|
| 416 | - return [ |
|
| 417 | - self::PROPERTY_DISPLAYNAME => |
|
| 418 | - [ |
|
| 419 | - 'value' => $user->getDisplayName(), |
|
| 420 | - 'scope' => self::VISIBILITY_CONTACTS_ONLY, |
|
| 421 | - 'verified' => self::NOT_VERIFIED, |
|
| 422 | - ], |
|
| 423 | - self::PROPERTY_ADDRESS => |
|
| 424 | - [ |
|
| 425 | - 'value' => '', |
|
| 426 | - 'scope' => self::VISIBILITY_PRIVATE, |
|
| 427 | - 'verified' => self::NOT_VERIFIED, |
|
| 428 | - ], |
|
| 429 | - self::PROPERTY_WEBSITE => |
|
| 430 | - [ |
|
| 431 | - 'value' => '', |
|
| 432 | - 'scope' => self::VISIBILITY_PRIVATE, |
|
| 433 | - 'verified' => self::NOT_VERIFIED, |
|
| 434 | - ], |
|
| 435 | - self::PROPERTY_EMAIL => |
|
| 436 | - [ |
|
| 437 | - 'value' => $user->getEMailAddress(), |
|
| 438 | - 'scope' => self::VISIBILITY_CONTACTS_ONLY, |
|
| 439 | - 'verified' => self::NOT_VERIFIED, |
|
| 440 | - ], |
|
| 441 | - self::PROPERTY_AVATAR => |
|
| 442 | - [ |
|
| 443 | - 'scope' => self::VISIBILITY_CONTACTS_ONLY |
|
| 444 | - ], |
|
| 445 | - self::PROPERTY_PHONE => |
|
| 446 | - [ |
|
| 447 | - 'value' => '', |
|
| 448 | - 'scope' => self::VISIBILITY_PRIVATE, |
|
| 449 | - 'verified' => self::NOT_VERIFIED, |
|
| 450 | - ], |
|
| 451 | - self::PROPERTY_TWITTER => |
|
| 452 | - [ |
|
| 453 | - 'value' => '', |
|
| 454 | - 'scope' => self::VISIBILITY_PRIVATE, |
|
| 455 | - 'verified' => self::NOT_VERIFIED, |
|
| 456 | - ], |
|
| 457 | - ]; |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - private function parseAccountData(IUser $user, $data): Account { |
|
| 461 | - $account = new Account($user); |
|
| 462 | - foreach ($data as $property => $accountData) { |
|
| 463 | - $account->setProperty($property, $accountData['value'] ?? '', $accountData['scope'] ?? self::VISIBILITY_PRIVATE, $accountData['verified'] ?? self::NOT_VERIFIED); |
|
| 464 | - } |
|
| 465 | - return $account; |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - public function getAccount(IUser $user): IAccount { |
|
| 469 | - return $this->parseAccountData($user, $this->getUser($user)); |
|
| 470 | - } |
|
| 61 | + /** @var IDBConnection database connection */ |
|
| 62 | + private $connection; |
|
| 63 | + |
|
| 64 | + /** @var IConfig */ |
|
| 65 | + private $config; |
|
| 66 | + |
|
| 67 | + /** @var string table name */ |
|
| 68 | + private $table = 'accounts'; |
|
| 69 | + |
|
| 70 | + /** @var string table name */ |
|
| 71 | + private $dataTable = 'accounts_data'; |
|
| 72 | + |
|
| 73 | + /** @var EventDispatcherInterface */ |
|
| 74 | + private $eventDispatcher; |
|
| 75 | + |
|
| 76 | + /** @var IJobList */ |
|
| 77 | + private $jobList; |
|
| 78 | + |
|
| 79 | + /** @var LoggerInterface */ |
|
| 80 | + private $logger; |
|
| 81 | + |
|
| 82 | + public function __construct(IDBConnection $connection, |
|
| 83 | + IConfig $config, |
|
| 84 | + EventDispatcherInterface $eventDispatcher, |
|
| 85 | + IJobList $jobList, |
|
| 86 | + LoggerInterface $logger) { |
|
| 87 | + $this->connection = $connection; |
|
| 88 | + $this->config = $config; |
|
| 89 | + $this->eventDispatcher = $eventDispatcher; |
|
| 90 | + $this->jobList = $jobList; |
|
| 91 | + $this->logger = $logger; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @param string $input |
|
| 96 | + * @return string Provided phone number in E.164 format when it was a valid number |
|
| 97 | + * @throws \InvalidArgumentException When the phone number was invalid or no default region is set and the number doesn't start with a country code |
|
| 98 | + */ |
|
| 99 | + protected function parsePhoneNumber(string $input): string { |
|
| 100 | + $defaultRegion = $this->config->getSystemValueString('default_phone_region', ''); |
|
| 101 | + |
|
| 102 | + if ($defaultRegion === '') { |
|
| 103 | + // When no default region is set, only +49… numbers are valid |
|
| 104 | + if (strpos($input, '+') !== 0) { |
|
| 105 | + throw new \InvalidArgumentException(self::PROPERTY_PHONE); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + $defaultRegion = 'EN'; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + $phoneUtil = PhoneNumberUtil::getInstance(); |
|
| 112 | + try { |
|
| 113 | + $phoneNumber = $phoneUtil->parse($input, $defaultRegion); |
|
| 114 | + if ($phoneNumber instanceof PhoneNumber && $phoneUtil->isValidNumber($phoneNumber)) { |
|
| 115 | + return $phoneUtil->format($phoneNumber, PhoneNumberFormat::E164); |
|
| 116 | + } |
|
| 117 | + } catch (NumberParseException $e) { |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + throw new \InvalidArgumentException(self::PROPERTY_PHONE); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * update user record |
|
| 125 | + * |
|
| 126 | + * @param IUser $user |
|
| 127 | + * @param array $data |
|
| 128 | + * @param bool $throwOnData Set to true if you can inform the user about invalid data |
|
| 129 | + * @return array The potentially modified data (e.g. phone numbers are converted to E.164 format) |
|
| 130 | + * @throws \InvalidArgumentException Message is the property that was invalid |
|
| 131 | + */ |
|
| 132 | + public function updateUser(IUser $user, array $data, bool $throwOnData = false): array { |
|
| 133 | + $userData = $this->getUser($user); |
|
| 134 | + $updated = true; |
|
| 135 | + |
|
| 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 | + } |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + if (empty($userData)) { |
|
| 148 | + $this->insertNewUser($user, $data); |
|
| 149 | + } elseif ($userData !== $data) { |
|
| 150 | + $data = $this->checkEmailVerification($userData, $data, $user); |
|
| 151 | + $data = $this->updateVerifyStatus($userData, $data); |
|
| 152 | + $this->updateExistingUser($user, $data); |
|
| 153 | + } else { |
|
| 154 | + // nothing needs to be done if new and old data set are the same |
|
| 155 | + $updated = false; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + if ($updated) { |
|
| 159 | + $this->eventDispatcher->dispatch( |
|
| 160 | + 'OC\AccountManager::userUpdated', |
|
| 161 | + new GenericEvent($user, $data) |
|
| 162 | + ); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + return $data; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * delete user from accounts table |
|
| 170 | + * |
|
| 171 | + * @param IUser $user |
|
| 172 | + */ |
|
| 173 | + public function deleteUser(IUser $user) { |
|
| 174 | + $uid = $user->getUID(); |
|
| 175 | + $query = $this->connection->getQueryBuilder(); |
|
| 176 | + $query->delete($this->table) |
|
| 177 | + ->where($query->expr()->eq('uid', $query->createNamedParameter($uid))) |
|
| 178 | + ->execute(); |
|
| 179 | + |
|
| 180 | + $this->deleteUserData($user); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * delete user from accounts table |
|
| 185 | + * |
|
| 186 | + * @param IUser $user |
|
| 187 | + */ |
|
| 188 | + public function deleteUserData(IUser $user): void { |
|
| 189 | + $uid = $user->getUID(); |
|
| 190 | + $query = $this->connection->getQueryBuilder(); |
|
| 191 | + $query->delete($this->dataTable) |
|
| 192 | + ->where($query->expr()->eq('uid', $query->createNamedParameter($uid))) |
|
| 193 | + ->execute(); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * get stored data from a given user |
|
| 198 | + * |
|
| 199 | + * @param IUser $user |
|
| 200 | + * @return array |
|
| 201 | + */ |
|
| 202 | + public function getUser(IUser $user) { |
|
| 203 | + $uid = $user->getUID(); |
|
| 204 | + $query = $this->connection->getQueryBuilder(); |
|
| 205 | + $query->select('data') |
|
| 206 | + ->from($this->table) |
|
| 207 | + ->where($query->expr()->eq('uid', $query->createParameter('uid'))) |
|
| 208 | + ->setParameter('uid', $uid); |
|
| 209 | + $result = $query->execute(); |
|
| 210 | + $accountData = $result->fetchAll(); |
|
| 211 | + $result->closeCursor(); |
|
| 212 | + |
|
| 213 | + if (empty($accountData)) { |
|
| 214 | + $userData = $this->buildDefaultUserRecord($user); |
|
| 215 | + $this->insertNewUser($user, $userData); |
|
| 216 | + return $userData; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + $userDataArray = json_decode($accountData[0]['data'], true); |
|
| 220 | + $jsonError = json_last_error(); |
|
| 221 | + if ($userDataArray === null || $userDataArray === [] || $jsonError !== JSON_ERROR_NONE) { |
|
| 222 | + $this->logger->critical("User data of $uid contained invalid JSON (error $jsonError), hence falling back to a default user record"); |
|
| 223 | + return $this->buildDefaultUserRecord($user); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + $userDataArray = $this->addMissingDefaultValues($userDataArray); |
|
| 227 | + |
|
| 228 | + return $userDataArray; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + public function searchUsers(string $property, array $values): array { |
|
| 232 | + $query = $this->connection->getQueryBuilder(); |
|
| 233 | + $query->select('*') |
|
| 234 | + ->from($this->dataTable) |
|
| 235 | + ->where($query->expr()->eq('name', $query->createNamedParameter($property))) |
|
| 236 | + ->andWhere($query->expr()->in('value', $query->createNamedParameter($values, IQueryBuilder::PARAM_STR_ARRAY))); |
|
| 237 | + |
|
| 238 | + $result = $query->execute(); |
|
| 239 | + $matches = []; |
|
| 240 | + |
|
| 241 | + while ($row = $result->fetch()) { |
|
| 242 | + $matches[$row['value']] = $row['uid']; |
|
| 243 | + } |
|
| 244 | + $result->closeCursor(); |
|
| 245 | + |
|
| 246 | + return $matches; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * check if we need to ask the server for email verification, if yes we create a cronjob |
|
| 251 | + * |
|
| 252 | + * @param $oldData |
|
| 253 | + * @param $newData |
|
| 254 | + * @param IUser $user |
|
| 255 | + * @return array |
|
| 256 | + */ |
|
| 257 | + protected function checkEmailVerification($oldData, $newData, IUser $user) { |
|
| 258 | + if ($oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value']) { |
|
| 259 | + $this->jobList->add(VerifyUserData::class, |
|
| 260 | + [ |
|
| 261 | + 'verificationCode' => '', |
|
| 262 | + 'data' => $newData[self::PROPERTY_EMAIL]['value'], |
|
| 263 | + 'type' => self::PROPERTY_EMAIL, |
|
| 264 | + 'uid' => $user->getUID(), |
|
| 265 | + 'try' => 0, |
|
| 266 | + 'lastRun' => time() |
|
| 267 | + ] |
|
| 268 | + ); |
|
| 269 | + $newData[self::PROPERTY_EMAIL]['verified'] = self::VERIFICATION_IN_PROGRESS; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + return $newData; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * make sure that all expected data are set |
|
| 277 | + * |
|
| 278 | + * @param array $userData |
|
| 279 | + * @return array |
|
| 280 | + */ |
|
| 281 | + protected function addMissingDefaultValues(array $userData) { |
|
| 282 | + foreach ($userData as $key => $value) { |
|
| 283 | + if (!isset($userData[$key]['verified'])) { |
|
| 284 | + $userData[$key]['verified'] = self::NOT_VERIFIED; |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + return $userData; |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * reset verification status if personal data changed |
|
| 293 | + * |
|
| 294 | + * @param array $oldData |
|
| 295 | + * @param array $newData |
|
| 296 | + * @return array |
|
| 297 | + */ |
|
| 298 | + protected function updateVerifyStatus($oldData, $newData) { |
|
| 299 | + |
|
| 300 | + // which account was already verified successfully? |
|
| 301 | + $twitterVerified = isset($oldData[self::PROPERTY_TWITTER]['verified']) && $oldData[self::PROPERTY_TWITTER]['verified'] === self::VERIFIED; |
|
| 302 | + $websiteVerified = isset($oldData[self::PROPERTY_WEBSITE]['verified']) && $oldData[self::PROPERTY_WEBSITE]['verified'] === self::VERIFIED; |
|
| 303 | + $emailVerified = isset($oldData[self::PROPERTY_EMAIL]['verified']) && $oldData[self::PROPERTY_EMAIL]['verified'] === self::VERIFIED; |
|
| 304 | + |
|
| 305 | + // keep old verification status if we don't have a new one |
|
| 306 | + if (!isset($newData[self::PROPERTY_TWITTER]['verified'])) { |
|
| 307 | + // keep old verification status if value didn't changed and an old value exists |
|
| 308 | + $keepOldStatus = $newData[self::PROPERTY_TWITTER]['value'] === $oldData[self::PROPERTY_TWITTER]['value'] && isset($oldData[self::PROPERTY_TWITTER]['verified']); |
|
| 309 | + $newData[self::PROPERTY_TWITTER]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_TWITTER]['verified'] : self::NOT_VERIFIED; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + if (!isset($newData[self::PROPERTY_WEBSITE]['verified'])) { |
|
| 313 | + // keep old verification status if value didn't changed and an old value exists |
|
| 314 | + $keepOldStatus = $newData[self::PROPERTY_WEBSITE]['value'] === $oldData[self::PROPERTY_WEBSITE]['value'] && isset($oldData[self::PROPERTY_WEBSITE]['verified']); |
|
| 315 | + $newData[self::PROPERTY_WEBSITE]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_WEBSITE]['verified'] : self::NOT_VERIFIED; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + if (!isset($newData[self::PROPERTY_EMAIL]['verified'])) { |
|
| 319 | + // keep old verification status if value didn't changed and an old value exists |
|
| 320 | + $keepOldStatus = $newData[self::PROPERTY_EMAIL]['value'] === $oldData[self::PROPERTY_EMAIL]['value'] && isset($oldData[self::PROPERTY_EMAIL]['verified']); |
|
| 321 | + $newData[self::PROPERTY_EMAIL]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_EMAIL]['verified'] : self::VERIFICATION_IN_PROGRESS; |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + // reset verification status if a value from a previously verified data was changed |
|
| 325 | + if ($twitterVerified && |
|
| 326 | + $oldData[self::PROPERTY_TWITTER]['value'] !== $newData[self::PROPERTY_TWITTER]['value'] |
|
| 327 | + ) { |
|
| 328 | + $newData[self::PROPERTY_TWITTER]['verified'] = self::NOT_VERIFIED; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + if ($websiteVerified && |
|
| 332 | + $oldData[self::PROPERTY_WEBSITE]['value'] !== $newData[self::PROPERTY_WEBSITE]['value'] |
|
| 333 | + ) { |
|
| 334 | + $newData[self::PROPERTY_WEBSITE]['verified'] = self::NOT_VERIFIED; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + if ($emailVerified && |
|
| 338 | + $oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value'] |
|
| 339 | + ) { |
|
| 340 | + $newData[self::PROPERTY_EMAIL]['verified'] = self::NOT_VERIFIED; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + return $newData; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * add new user to accounts table |
|
| 348 | + * |
|
| 349 | + * @param IUser $user |
|
| 350 | + * @param array $data |
|
| 351 | + */ |
|
| 352 | + protected function insertNewUser(IUser $user, array $data): void { |
|
| 353 | + $uid = $user->getUID(); |
|
| 354 | + $jsonEncodedData = json_encode($data); |
|
| 355 | + $query = $this->connection->getQueryBuilder(); |
|
| 356 | + $query->insert($this->table) |
|
| 357 | + ->values( |
|
| 358 | + [ |
|
| 359 | + 'uid' => $query->createNamedParameter($uid), |
|
| 360 | + 'data' => $query->createNamedParameter($jsonEncodedData), |
|
| 361 | + ] |
|
| 362 | + ) |
|
| 363 | + ->execute(); |
|
| 364 | + |
|
| 365 | + $this->deleteUserData($user); |
|
| 366 | + $this->writeUserData($user, $data); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * update existing user in accounts table |
|
| 371 | + * |
|
| 372 | + * @param IUser $user |
|
| 373 | + * @param array $data |
|
| 374 | + */ |
|
| 375 | + protected function updateExistingUser(IUser $user, array $data): void { |
|
| 376 | + $uid = $user->getUID(); |
|
| 377 | + $jsonEncodedData = json_encode($data); |
|
| 378 | + $query = $this->connection->getQueryBuilder(); |
|
| 379 | + $query->update($this->table) |
|
| 380 | + ->set('data', $query->createNamedParameter($jsonEncodedData)) |
|
| 381 | + ->where($query->expr()->eq('uid', $query->createNamedParameter($uid))) |
|
| 382 | + ->execute(); |
|
| 383 | + |
|
| 384 | + $this->deleteUserData($user); |
|
| 385 | + $this->writeUserData($user, $data); |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + protected function writeUserData(IUser $user, array $data): void { |
|
| 389 | + $query = $this->connection->getQueryBuilder(); |
|
| 390 | + $query->insert($this->dataTable) |
|
| 391 | + ->values( |
|
| 392 | + [ |
|
| 393 | + 'uid' => $query->createNamedParameter($user->getUID()), |
|
| 394 | + 'name' => $query->createParameter('name'), |
|
| 395 | + 'value' => $query->createParameter('value'), |
|
| 396 | + ] |
|
| 397 | + ); |
|
| 398 | + foreach ($data as $propertyName => $property) { |
|
| 399 | + if ($propertyName === self::PROPERTY_AVATAR) { |
|
| 400 | + continue; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + $query->setParameter('name', $propertyName) |
|
| 404 | + ->setParameter('value', $property['value']); |
|
| 405 | + $query->execute(); |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * build default user record in case not data set exists yet |
|
| 411 | + * |
|
| 412 | + * @param IUser $user |
|
| 413 | + * @return array |
|
| 414 | + */ |
|
| 415 | + protected function buildDefaultUserRecord(IUser $user) { |
|
| 416 | + return [ |
|
| 417 | + self::PROPERTY_DISPLAYNAME => |
|
| 418 | + [ |
|
| 419 | + 'value' => $user->getDisplayName(), |
|
| 420 | + 'scope' => self::VISIBILITY_CONTACTS_ONLY, |
|
| 421 | + 'verified' => self::NOT_VERIFIED, |
|
| 422 | + ], |
|
| 423 | + self::PROPERTY_ADDRESS => |
|
| 424 | + [ |
|
| 425 | + 'value' => '', |
|
| 426 | + 'scope' => self::VISIBILITY_PRIVATE, |
|
| 427 | + 'verified' => self::NOT_VERIFIED, |
|
| 428 | + ], |
|
| 429 | + self::PROPERTY_WEBSITE => |
|
| 430 | + [ |
|
| 431 | + 'value' => '', |
|
| 432 | + 'scope' => self::VISIBILITY_PRIVATE, |
|
| 433 | + 'verified' => self::NOT_VERIFIED, |
|
| 434 | + ], |
|
| 435 | + self::PROPERTY_EMAIL => |
|
| 436 | + [ |
|
| 437 | + 'value' => $user->getEMailAddress(), |
|
| 438 | + 'scope' => self::VISIBILITY_CONTACTS_ONLY, |
|
| 439 | + 'verified' => self::NOT_VERIFIED, |
|
| 440 | + ], |
|
| 441 | + self::PROPERTY_AVATAR => |
|
| 442 | + [ |
|
| 443 | + 'scope' => self::VISIBILITY_CONTACTS_ONLY |
|
| 444 | + ], |
|
| 445 | + self::PROPERTY_PHONE => |
|
| 446 | + [ |
|
| 447 | + 'value' => '', |
|
| 448 | + 'scope' => self::VISIBILITY_PRIVATE, |
|
| 449 | + 'verified' => self::NOT_VERIFIED, |
|
| 450 | + ], |
|
| 451 | + self::PROPERTY_TWITTER => |
|
| 452 | + [ |
|
| 453 | + 'value' => '', |
|
| 454 | + 'scope' => self::VISIBILITY_PRIVATE, |
|
| 455 | + 'verified' => self::NOT_VERIFIED, |
|
| 456 | + ], |
|
| 457 | + ]; |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + private function parseAccountData(IUser $user, $data): Account { |
|
| 461 | + $account = new Account($user); |
|
| 462 | + foreach ($data as $property => $accountData) { |
|
| 463 | + $account->setProperty($property, $accountData['value'] ?? '', $accountData['scope'] ?? self::VISIBILITY_PRIVATE, $accountData['verified'] ?? self::NOT_VERIFIED); |
|
| 464 | + } |
|
| 465 | + return $account; |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + public function getAccount(IUser $user): IAccount { |
|
| 469 | + return $this->parseAccountData($user, $this->getUser($user)); |
|
| 470 | + } |
|
| 471 | 471 | } |
@@ -35,55 +35,55 @@ |
||
| 35 | 35 | |
| 36 | 36 | class ValidatePhoneNumber implements IRepairStep { |
| 37 | 37 | |
| 38 | - /** @var IConfig */ |
|
| 39 | - protected $config; |
|
| 40 | - /** @var IUserManager */ |
|
| 41 | - protected $userManager; |
|
| 42 | - /** @var AccountManager */ |
|
| 43 | - private $accountManager; |
|
| 38 | + /** @var IConfig */ |
|
| 39 | + protected $config; |
|
| 40 | + /** @var IUserManager */ |
|
| 41 | + protected $userManager; |
|
| 42 | + /** @var AccountManager */ |
|
| 43 | + private $accountManager; |
|
| 44 | 44 | |
| 45 | - public function __construct(IUserManager $userManager, |
|
| 46 | - AccountManager $accountManager, |
|
| 47 | - IConfig $config) { |
|
| 48 | - $this->config = $config; |
|
| 49 | - $this->userManager = $userManager; |
|
| 50 | - $this->accountManager = $accountManager; |
|
| 51 | - } |
|
| 45 | + public function __construct(IUserManager $userManager, |
|
| 46 | + AccountManager $accountManager, |
|
| 47 | + IConfig $config) { |
|
| 48 | + $this->config = $config; |
|
| 49 | + $this->userManager = $userManager; |
|
| 50 | + $this->accountManager = $accountManager; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - public function getName(): string { |
|
| 54 | - return 'Validate the phone number and store it in a known format for search'; |
|
| 55 | - } |
|
| 53 | + public function getName(): string { |
|
| 54 | + return 'Validate the phone number and store it in a known format for search'; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - private function shouldRun(): bool { |
|
| 58 | - return true; |
|
| 59 | - } |
|
| 57 | + private function shouldRun(): bool { |
|
| 58 | + return true; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - public function run(IOutput $output): void { |
|
| 62 | - if ($this->config->getSystemValueString('default_phone_region', '') === '') { |
|
| 63 | - throw new \Exception('Can not validate phone numbers without `default_phone_region` being set in the config file'); |
|
| 64 | - } |
|
| 61 | + public function run(IOutput $output): void { |
|
| 62 | + if ($this->config->getSystemValueString('default_phone_region', '') === '') { |
|
| 63 | + throw new \Exception('Can not validate phone numbers without `default_phone_region` being set in the config file'); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - $numUpdated = 0; |
|
| 67 | - $numRemoved = 0; |
|
| 66 | + $numUpdated = 0; |
|
| 67 | + $numRemoved = 0; |
|
| 68 | 68 | |
| 69 | - $this->userManager->callForSeenUsers(function (IUser $user) use (&$numUpdated, &$numRemoved) { |
|
| 70 | - $account = $this->accountManager->getUser($user); |
|
| 69 | + $this->userManager->callForSeenUsers(function (IUser $user) use (&$numUpdated, &$numRemoved) { |
|
| 70 | + $account = $this->accountManager->getUser($user); |
|
| 71 | 71 | |
| 72 | - if ($account[IAccountManager::PROPERTY_PHONE]['value'] !== '') { |
|
| 73 | - $updated = $this->accountManager->updateUser($user, $account); |
|
| 72 | + if ($account[IAccountManager::PROPERTY_PHONE]['value'] !== '') { |
|
| 73 | + $updated = $this->accountManager->updateUser($user, $account); |
|
| 74 | 74 | |
| 75 | - if ($account[IAccountManager::PROPERTY_PHONE]['value'] !== $updated[IAccountManager::PROPERTY_PHONE]['value']) { |
|
| 76 | - if ($updated[IAccountManager::PROPERTY_PHONE]['value'] === '') { |
|
| 77 | - $numRemoved++; |
|
| 78 | - } else { |
|
| 79 | - $numUpdated++; |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - }); |
|
| 75 | + if ($account[IAccountManager::PROPERTY_PHONE]['value'] !== $updated[IAccountManager::PROPERTY_PHONE]['value']) { |
|
| 76 | + if ($updated[IAccountManager::PROPERTY_PHONE]['value'] === '') { |
|
| 77 | + $numRemoved++; |
|
| 78 | + } else { |
|
| 79 | + $numUpdated++; |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + }); |
|
| 84 | 84 | |
| 85 | - if ($numRemoved > 0 || $numUpdated > 0) { |
|
| 86 | - $output->info('Updated ' . $numUpdated . ' entries and cleaned ' . $numRemoved . ' invalid phone numbers'); |
|
| 87 | - } |
|
| 88 | - } |
|
| 85 | + if ($numRemoved > 0 || $numUpdated > 0) { |
|
| 86 | + $output->info('Updated ' . $numUpdated . ' entries and cleaned ' . $numRemoved . ' invalid phone numbers'); |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | 89 | } |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | $numUpdated = 0; |
| 67 | 67 | $numRemoved = 0; |
| 68 | 68 | |
| 69 | - $this->userManager->callForSeenUsers(function (IUser $user) use (&$numUpdated, &$numRemoved) { |
|
| 69 | + $this->userManager->callForSeenUsers(function(IUser $user) use (&$numUpdated, &$numRemoved) { |
|
| 70 | 70 | $account = $this->accountManager->getUser($user); |
| 71 | 71 | |
| 72 | 72 | if ($account[IAccountManager::PROPERTY_PHONE]['value'] !== '') { |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | }); |
| 84 | 84 | |
| 85 | 85 | if ($numRemoved > 0 || $numUpdated > 0) { |
| 86 | - $output->info('Updated ' . $numUpdated . ' entries and cleaned ' . $numRemoved . ' invalid phone numbers'); |
|
| 86 | + $output->info('Updated '.$numUpdated.' entries and cleaned '.$numRemoved.' invalid phone numbers'); |
|
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | 89 | } |
@@ -37,43 +37,43 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | interface IAccountManager { |
| 39 | 39 | |
| 40 | - /** nobody can see my account details */ |
|
| 41 | - public const VISIBILITY_PRIVATE = 'private'; |
|
| 42 | - /** only contacts, especially trusted servers can see my contact details */ |
|
| 43 | - public const VISIBILITY_CONTACTS_ONLY = 'contacts'; |
|
| 44 | - /** every body ca see my contact detail, will be published to the lookup server */ |
|
| 45 | - public const VISIBILITY_PUBLIC = 'public'; |
|
| 40 | + /** nobody can see my account details */ |
|
| 41 | + public const VISIBILITY_PRIVATE = 'private'; |
|
| 42 | + /** only contacts, especially trusted servers can see my contact details */ |
|
| 43 | + public const VISIBILITY_CONTACTS_ONLY = 'contacts'; |
|
| 44 | + /** every body ca see my contact detail, will be published to the lookup server */ |
|
| 45 | + public const VISIBILITY_PUBLIC = 'public'; |
|
| 46 | 46 | |
| 47 | - public const PROPERTY_AVATAR = 'avatar'; |
|
| 48 | - public const PROPERTY_DISPLAYNAME = 'displayname'; |
|
| 49 | - public const PROPERTY_PHONE = 'phone'; |
|
| 50 | - public const PROPERTY_EMAIL = 'email'; |
|
| 51 | - public const PROPERTY_WEBSITE = 'website'; |
|
| 52 | - public const PROPERTY_ADDRESS = 'address'; |
|
| 53 | - public const PROPERTY_TWITTER = 'twitter'; |
|
| 47 | + public const PROPERTY_AVATAR = 'avatar'; |
|
| 48 | + public const PROPERTY_DISPLAYNAME = 'displayname'; |
|
| 49 | + public const PROPERTY_PHONE = 'phone'; |
|
| 50 | + public const PROPERTY_EMAIL = 'email'; |
|
| 51 | + public const PROPERTY_WEBSITE = 'website'; |
|
| 52 | + public const PROPERTY_ADDRESS = 'address'; |
|
| 53 | + public const PROPERTY_TWITTER = 'twitter'; |
|
| 54 | 54 | |
| 55 | - public const NOT_VERIFIED = '0'; |
|
| 56 | - public const VERIFICATION_IN_PROGRESS = '1'; |
|
| 57 | - public const VERIFIED = '2'; |
|
| 55 | + public const NOT_VERIFIED = '0'; |
|
| 56 | + public const VERIFICATION_IN_PROGRESS = '1'; |
|
| 57 | + public const VERIFIED = '2'; |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Get the account data for a given user |
|
| 61 | - * |
|
| 62 | - * @since 15.0.0 |
|
| 63 | - * |
|
| 64 | - * @param IUser $user |
|
| 65 | - * @return IAccount |
|
| 66 | - */ |
|
| 67 | - public function getAccount(IUser $user): IAccount; |
|
| 59 | + /** |
|
| 60 | + * Get the account data for a given user |
|
| 61 | + * |
|
| 62 | + * @since 15.0.0 |
|
| 63 | + * |
|
| 64 | + * @param IUser $user |
|
| 65 | + * @return IAccount |
|
| 66 | + */ |
|
| 67 | + public function getAccount(IUser $user): IAccount; |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * Search for users based on account data |
|
| 71 | - * |
|
| 72 | - * @param string $property |
|
| 73 | - * @param string[] $values |
|
| 74 | - * @return array |
|
| 75 | - * |
|
| 76 | - * @since 21.0.0 |
|
| 77 | - */ |
|
| 78 | - public function searchUsers(string $property, array $values): array; |
|
| 69 | + /** |
|
| 70 | + * Search for users based on account data |
|
| 71 | + * |
|
| 72 | + * @param string $property |
|
| 73 | + * @param string[] $values |
|
| 74 | + * @return array |
|
| 75 | + * |
|
| 76 | + * @since 21.0.0 |
|
| 77 | + */ |
|
| 78 | + public function searchUsers(string $property, array $values): array; |
|
| 79 | 79 | } |