@@ -83,210 +83,210 @@ |
||
| 83 | 83 | |
| 84 | 84 | class Repair implements IOutput { |
| 85 | 85 | |
| 86 | - /** @var IRepairStep[] */ |
|
| 87 | - private $repairSteps; |
|
| 86 | + /** @var IRepairStep[] */ |
|
| 87 | + private $repairSteps; |
|
| 88 | 88 | |
| 89 | - /** @var EventDispatcherInterface */ |
|
| 90 | - private $dispatcher; |
|
| 89 | + /** @var EventDispatcherInterface */ |
|
| 90 | + private $dispatcher; |
|
| 91 | 91 | |
| 92 | - /** @var string */ |
|
| 93 | - private $currentStep; |
|
| 92 | + /** @var string */ |
|
| 93 | + private $currentStep; |
|
| 94 | 94 | |
| 95 | - private $logger; |
|
| 95 | + private $logger; |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * Creates a new repair step runner |
|
| 99 | - * |
|
| 100 | - * @param IRepairStep[] $repairSteps array of RepairStep instances |
|
| 101 | - * @param EventDispatcherInterface $dispatcher |
|
| 102 | - */ |
|
| 103 | - public function __construct(array $repairSteps, EventDispatcherInterface $dispatcher, LoggerInterface $logger) { |
|
| 104 | - $this->repairSteps = $repairSteps; |
|
| 105 | - $this->dispatcher = $dispatcher; |
|
| 106 | - $this->logger = $logger; |
|
| 107 | - } |
|
| 97 | + /** |
|
| 98 | + * Creates a new repair step runner |
|
| 99 | + * |
|
| 100 | + * @param IRepairStep[] $repairSteps array of RepairStep instances |
|
| 101 | + * @param EventDispatcherInterface $dispatcher |
|
| 102 | + */ |
|
| 103 | + public function __construct(array $repairSteps, EventDispatcherInterface $dispatcher, LoggerInterface $logger) { |
|
| 104 | + $this->repairSteps = $repairSteps; |
|
| 105 | + $this->dispatcher = $dispatcher; |
|
| 106 | + $this->logger = $logger; |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Run a series of repair steps for common problems |
|
| 111 | - */ |
|
| 112 | - public function run() { |
|
| 113 | - if (count($this->repairSteps) === 0) { |
|
| 114 | - $this->emit('\OC\Repair', 'info', ['No repair steps available']); |
|
| 109 | + /** |
|
| 110 | + * Run a series of repair steps for common problems |
|
| 111 | + */ |
|
| 112 | + public function run() { |
|
| 113 | + if (count($this->repairSteps) === 0) { |
|
| 114 | + $this->emit('\OC\Repair', 'info', ['No repair steps available']); |
|
| 115 | 115 | |
| 116 | - return; |
|
| 117 | - } |
|
| 118 | - // run each repair step |
|
| 119 | - foreach ($this->repairSteps as $step) { |
|
| 120 | - $this->currentStep = $step->getName(); |
|
| 121 | - $this->emit('\OC\Repair', 'step', [$this->currentStep]); |
|
| 122 | - try { |
|
| 123 | - $step->run($this); |
|
| 124 | - } catch (\Exception $e) { |
|
| 125 | - $this->logger->error("Exception while executing repair step " . $step->getName(), ['exception' => $e]); |
|
| 126 | - $this->emit('\OC\Repair', 'error', [$e->getMessage()]); |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - } |
|
| 116 | + return; |
|
| 117 | + } |
|
| 118 | + // run each repair step |
|
| 119 | + foreach ($this->repairSteps as $step) { |
|
| 120 | + $this->currentStep = $step->getName(); |
|
| 121 | + $this->emit('\OC\Repair', 'step', [$this->currentStep]); |
|
| 122 | + try { |
|
| 123 | + $step->run($this); |
|
| 124 | + } catch (\Exception $e) { |
|
| 125 | + $this->logger->error("Exception while executing repair step " . $step->getName(), ['exception' => $e]); |
|
| 126 | + $this->emit('\OC\Repair', 'error', [$e->getMessage()]); |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * Add repair step |
|
| 133 | - * |
|
| 134 | - * @param IRepairStep|string $repairStep repair step |
|
| 135 | - * @throws \Exception |
|
| 136 | - */ |
|
| 137 | - public function addStep($repairStep) { |
|
| 138 | - if (is_string($repairStep)) { |
|
| 139 | - try { |
|
| 140 | - $s = \OC::$server->query($repairStep); |
|
| 141 | - } catch (QueryException $e) { |
|
| 142 | - if (class_exists($repairStep)) { |
|
| 143 | - $s = new $repairStep(); |
|
| 144 | - } else { |
|
| 145 | - throw new \Exception("Repair step '$repairStep' is unknown"); |
|
| 146 | - } |
|
| 147 | - } |
|
| 131 | + /** |
|
| 132 | + * Add repair step |
|
| 133 | + * |
|
| 134 | + * @param IRepairStep|string $repairStep repair step |
|
| 135 | + * @throws \Exception |
|
| 136 | + */ |
|
| 137 | + public function addStep($repairStep) { |
|
| 138 | + if (is_string($repairStep)) { |
|
| 139 | + try { |
|
| 140 | + $s = \OC::$server->query($repairStep); |
|
| 141 | + } catch (QueryException $e) { |
|
| 142 | + if (class_exists($repairStep)) { |
|
| 143 | + $s = new $repairStep(); |
|
| 144 | + } else { |
|
| 145 | + throw new \Exception("Repair step '$repairStep' is unknown"); |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - if ($s instanceof IRepairStep) { |
|
| 150 | - $this->repairSteps[] = $s; |
|
| 151 | - } else { |
|
| 152 | - throw new \Exception("Repair step '$repairStep' is not of type \\OCP\\Migration\\IRepairStep"); |
|
| 153 | - } |
|
| 154 | - } else { |
|
| 155 | - $this->repairSteps[] = $repairStep; |
|
| 156 | - } |
|
| 157 | - } |
|
| 149 | + if ($s instanceof IRepairStep) { |
|
| 150 | + $this->repairSteps[] = $s; |
|
| 151 | + } else { |
|
| 152 | + throw new \Exception("Repair step '$repairStep' is not of type \\OCP\\Migration\\IRepairStep"); |
|
| 153 | + } |
|
| 154 | + } else { |
|
| 155 | + $this->repairSteps[] = $repairStep; |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - /** |
|
| 160 | - * Returns the default repair steps to be run on the |
|
| 161 | - * command line or after an upgrade. |
|
| 162 | - * |
|
| 163 | - * @return IRepairStep[] |
|
| 164 | - */ |
|
| 165 | - public static function getRepairSteps() { |
|
| 166 | - return [ |
|
| 167 | - new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->getDatabaseConnection(), false), |
|
| 168 | - new RepairMimeTypes(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), |
|
| 169 | - new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()), |
|
| 170 | - new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), |
|
| 171 | - new MoveUpdaterStepFile(\OC::$server->getConfig()), |
|
| 172 | - new MoveAvatars( |
|
| 173 | - \OC::$server->getJobList(), |
|
| 174 | - \OC::$server->getConfig() |
|
| 175 | - ), |
|
| 176 | - new CleanPreviews( |
|
| 177 | - \OC::$server->getJobList(), |
|
| 178 | - \OC::$server->getUserManager(), |
|
| 179 | - \OC::$server->getConfig() |
|
| 180 | - ), |
|
| 181 | - new FixMountStorages(\OC::$server->getDatabaseConnection()), |
|
| 182 | - new UpdateLanguageCodes(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()), |
|
| 183 | - new InstallCoreBundle( |
|
| 184 | - \OC::$server->query(BundleFetcher::class), |
|
| 185 | - \OC::$server->getConfig(), |
|
| 186 | - \OC::$server->query(Installer::class) |
|
| 187 | - ), |
|
| 188 | - new AddLogRotateJob(\OC::$server->getJobList()), |
|
| 189 | - new ClearFrontendCaches(\OC::$server->getMemCacheFactory(), \OC::$server->query(SCSSCacher::class), \OC::$server->query(JSCombiner::class)), |
|
| 190 | - new ClearGeneratedAvatarCache(\OC::$server->getConfig(), \OC::$server->query(AvatarManager::class)), |
|
| 191 | - new AddPreviewBackgroundCleanupJob(\OC::$server->getJobList()), |
|
| 192 | - new AddCleanupUpdaterBackupsJob(\OC::$server->getJobList()), |
|
| 193 | - new CleanupCardDAVPhotoCache(\OC::$server->getConfig(), \OC::$server->getAppDataDir('dav-photocache'), \OC::$server->getLogger()), |
|
| 194 | - new AddClenupLoginFlowV2BackgroundJob(\OC::$server->getJobList()), |
|
| 195 | - new RemoveLinkShares(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getGroupManager(), \OC::$server->getNotificationManager(), \OC::$server->query(ITimeFactory::class)), |
|
| 196 | - new ClearCollectionsAccessCache(\OC::$server->getConfig(), \OC::$server->query(IManager::class)), |
|
| 197 | - \OC::$server->query(ResetGeneratedAvatarFlag::class), |
|
| 198 | - \OC::$server->query(EncryptionLegacyCipher::class), |
|
| 199 | - \OC::$server->query(EncryptionMigration::class), |
|
| 200 | - \OC::$server->get(ShippedDashboardEnable::class), |
|
| 201 | - \OC::$server->get(AddBruteForceCleanupJob::class), |
|
| 202 | - \OC::$server->get(AddCheckForUserCertificatesJob::class), |
|
| 203 | - \OC::$server->get(RepairDavShares::class), |
|
| 204 | - \OC::$server->get(LookupServerSendCheck::class), |
|
| 205 | - ]; |
|
| 206 | - } |
|
| 159 | + /** |
|
| 160 | + * Returns the default repair steps to be run on the |
|
| 161 | + * command line or after an upgrade. |
|
| 162 | + * |
|
| 163 | + * @return IRepairStep[] |
|
| 164 | + */ |
|
| 165 | + public static function getRepairSteps() { |
|
| 166 | + return [ |
|
| 167 | + new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->getDatabaseConnection(), false), |
|
| 168 | + new RepairMimeTypes(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), |
|
| 169 | + new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()), |
|
| 170 | + new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), |
|
| 171 | + new MoveUpdaterStepFile(\OC::$server->getConfig()), |
|
| 172 | + new MoveAvatars( |
|
| 173 | + \OC::$server->getJobList(), |
|
| 174 | + \OC::$server->getConfig() |
|
| 175 | + ), |
|
| 176 | + new CleanPreviews( |
|
| 177 | + \OC::$server->getJobList(), |
|
| 178 | + \OC::$server->getUserManager(), |
|
| 179 | + \OC::$server->getConfig() |
|
| 180 | + ), |
|
| 181 | + new FixMountStorages(\OC::$server->getDatabaseConnection()), |
|
| 182 | + new UpdateLanguageCodes(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()), |
|
| 183 | + new InstallCoreBundle( |
|
| 184 | + \OC::$server->query(BundleFetcher::class), |
|
| 185 | + \OC::$server->getConfig(), |
|
| 186 | + \OC::$server->query(Installer::class) |
|
| 187 | + ), |
|
| 188 | + new AddLogRotateJob(\OC::$server->getJobList()), |
|
| 189 | + new ClearFrontendCaches(\OC::$server->getMemCacheFactory(), \OC::$server->query(SCSSCacher::class), \OC::$server->query(JSCombiner::class)), |
|
| 190 | + new ClearGeneratedAvatarCache(\OC::$server->getConfig(), \OC::$server->query(AvatarManager::class)), |
|
| 191 | + new AddPreviewBackgroundCleanupJob(\OC::$server->getJobList()), |
|
| 192 | + new AddCleanupUpdaterBackupsJob(\OC::$server->getJobList()), |
|
| 193 | + new CleanupCardDAVPhotoCache(\OC::$server->getConfig(), \OC::$server->getAppDataDir('dav-photocache'), \OC::$server->getLogger()), |
|
| 194 | + new AddClenupLoginFlowV2BackgroundJob(\OC::$server->getJobList()), |
|
| 195 | + new RemoveLinkShares(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getGroupManager(), \OC::$server->getNotificationManager(), \OC::$server->query(ITimeFactory::class)), |
|
| 196 | + new ClearCollectionsAccessCache(\OC::$server->getConfig(), \OC::$server->query(IManager::class)), |
|
| 197 | + \OC::$server->query(ResetGeneratedAvatarFlag::class), |
|
| 198 | + \OC::$server->query(EncryptionLegacyCipher::class), |
|
| 199 | + \OC::$server->query(EncryptionMigration::class), |
|
| 200 | + \OC::$server->get(ShippedDashboardEnable::class), |
|
| 201 | + \OC::$server->get(AddBruteForceCleanupJob::class), |
|
| 202 | + \OC::$server->get(AddCheckForUserCertificatesJob::class), |
|
| 203 | + \OC::$server->get(RepairDavShares::class), |
|
| 204 | + \OC::$server->get(LookupServerSendCheck::class), |
|
| 205 | + ]; |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - /** |
|
| 209 | - * Returns expensive repair steps to be run on the |
|
| 210 | - * command line with a special option. |
|
| 211 | - * |
|
| 212 | - * @return IRepairStep[] |
|
| 213 | - */ |
|
| 214 | - public static function getExpensiveRepairSteps() { |
|
| 215 | - return [ |
|
| 216 | - new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()), |
|
| 217 | - \OC::$server->get(ValidatePhoneNumber::class), |
|
| 218 | - ]; |
|
| 219 | - } |
|
| 208 | + /** |
|
| 209 | + * Returns expensive repair steps to be run on the |
|
| 210 | + * command line with a special option. |
|
| 211 | + * |
|
| 212 | + * @return IRepairStep[] |
|
| 213 | + */ |
|
| 214 | + public static function getExpensiveRepairSteps() { |
|
| 215 | + return [ |
|
| 216 | + new OldGroupMembershipShares(\OC::$server->getDatabaseConnection(), \OC::$server->getGroupManager()), |
|
| 217 | + \OC::$server->get(ValidatePhoneNumber::class), |
|
| 218 | + ]; |
|
| 219 | + } |
|
| 220 | 220 | |
| 221 | - /** |
|
| 222 | - * Returns the repair steps to be run before an |
|
| 223 | - * upgrade. |
|
| 224 | - * |
|
| 225 | - * @return IRepairStep[] |
|
| 226 | - */ |
|
| 227 | - public static function getBeforeUpgradeRepairSteps() { |
|
| 228 | - /** @var Connection $connection */ |
|
| 229 | - $connection = \OC::$server->get(Connection::class); |
|
| 230 | - /** @var ConnectionAdapter $connectionAdapter */ |
|
| 231 | - $connectionAdapter = \OC::$server->get(ConnectionAdapter::class); |
|
| 232 | - $config = \OC::$server->getConfig(); |
|
| 233 | - $steps = [ |
|
| 234 | - new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), $connectionAdapter, true), |
|
| 235 | - new SqliteAutoincrement($connection), |
|
| 236 | - new SaveAccountsTableData($connectionAdapter, $config), |
|
| 237 | - new DropAccountTermsTable($connectionAdapter), |
|
| 238 | - ]; |
|
| 221 | + /** |
|
| 222 | + * Returns the repair steps to be run before an |
|
| 223 | + * upgrade. |
|
| 224 | + * |
|
| 225 | + * @return IRepairStep[] |
|
| 226 | + */ |
|
| 227 | + public static function getBeforeUpgradeRepairSteps() { |
|
| 228 | + /** @var Connection $connection */ |
|
| 229 | + $connection = \OC::$server->get(Connection::class); |
|
| 230 | + /** @var ConnectionAdapter $connectionAdapter */ |
|
| 231 | + $connectionAdapter = \OC::$server->get(ConnectionAdapter::class); |
|
| 232 | + $config = \OC::$server->getConfig(); |
|
| 233 | + $steps = [ |
|
| 234 | + new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), $connectionAdapter, true), |
|
| 235 | + new SqliteAutoincrement($connection), |
|
| 236 | + new SaveAccountsTableData($connectionAdapter, $config), |
|
| 237 | + new DropAccountTermsTable($connectionAdapter), |
|
| 238 | + ]; |
|
| 239 | 239 | |
| 240 | - return $steps; |
|
| 241 | - } |
|
| 240 | + return $steps; |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - /** |
|
| 244 | - * @param string $scope |
|
| 245 | - * @param string $method |
|
| 246 | - * @param array $arguments |
|
| 247 | - */ |
|
| 248 | - public function emit($scope, $method, array $arguments = []) { |
|
| 249 | - if (!is_null($this->dispatcher)) { |
|
| 250 | - $this->dispatcher->dispatch("$scope::$method", |
|
| 251 | - new GenericEvent("$scope::$method", $arguments)); |
|
| 252 | - } |
|
| 253 | - } |
|
| 243 | + /** |
|
| 244 | + * @param string $scope |
|
| 245 | + * @param string $method |
|
| 246 | + * @param array $arguments |
|
| 247 | + */ |
|
| 248 | + public function emit($scope, $method, array $arguments = []) { |
|
| 249 | + if (!is_null($this->dispatcher)) { |
|
| 250 | + $this->dispatcher->dispatch("$scope::$method", |
|
| 251 | + new GenericEvent("$scope::$method", $arguments)); |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - public function info($string) { |
|
| 256 | - // for now just emit as we did in the past |
|
| 257 | - $this->emit('\OC\Repair', 'info', [$string]); |
|
| 258 | - } |
|
| 255 | + public function info($string) { |
|
| 256 | + // for now just emit as we did in the past |
|
| 257 | + $this->emit('\OC\Repair', 'info', [$string]); |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | - /** |
|
| 261 | - * @param string $message |
|
| 262 | - */ |
|
| 263 | - public function warning($message) { |
|
| 264 | - // for now just emit as we did in the past |
|
| 265 | - $this->emit('\OC\Repair', 'warning', [$message]); |
|
| 266 | - } |
|
| 260 | + /** |
|
| 261 | + * @param string $message |
|
| 262 | + */ |
|
| 263 | + public function warning($message) { |
|
| 264 | + // for now just emit as we did in the past |
|
| 265 | + $this->emit('\OC\Repair', 'warning', [$message]); |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - /** |
|
| 269 | - * @param int $max |
|
| 270 | - */ |
|
| 271 | - public function startProgress($max = 0) { |
|
| 272 | - // for now just emit as we did in the past |
|
| 273 | - $this->emit('\OC\Repair', 'startProgress', [$max, $this->currentStep]); |
|
| 274 | - } |
|
| 268 | + /** |
|
| 269 | + * @param int $max |
|
| 270 | + */ |
|
| 271 | + public function startProgress($max = 0) { |
|
| 272 | + // for now just emit as we did in the past |
|
| 273 | + $this->emit('\OC\Repair', 'startProgress', [$max, $this->currentStep]); |
|
| 274 | + } |
|
| 275 | 275 | |
| 276 | - /** |
|
| 277 | - * @param int $step |
|
| 278 | - * @param string $description |
|
| 279 | - */ |
|
| 280 | - public function advance($step = 1, $description = '') { |
|
| 281 | - // for now just emit as we did in the past |
|
| 282 | - $this->emit('\OC\Repair', 'advance', [$step, $description]); |
|
| 283 | - } |
|
| 276 | + /** |
|
| 277 | + * @param int $step |
|
| 278 | + * @param string $description |
|
| 279 | + */ |
|
| 280 | + public function advance($step = 1, $description = '') { |
|
| 281 | + // for now just emit as we did in the past |
|
| 282 | + $this->emit('\OC\Repair', 'advance', [$step, $description]); |
|
| 283 | + } |
|
| 284 | 284 | |
| 285 | - /** |
|
| 286 | - * @param int $max |
|
| 287 | - */ |
|
| 288 | - public function finishProgress() { |
|
| 289 | - // for now just emit as we did in the past |
|
| 290 | - $this->emit('\OC\Repair', 'finishProgress', []); |
|
| 291 | - } |
|
| 285 | + /** |
|
| 286 | + * @param int $max |
|
| 287 | + */ |
|
| 288 | + public function finishProgress() { |
|
| 289 | + // for now just emit as we did in the past |
|
| 290 | + $this->emit('\OC\Repair', 'finishProgress', []); |
|
| 291 | + } |
|
| 292 | 292 | } |
@@ -34,29 +34,29 @@ |
||
| 34 | 34 | |
| 35 | 35 | class LookupServerSendCheck implements IRepairStep { |
| 36 | 36 | |
| 37 | - /** @var IJobList */ |
|
| 38 | - private $jobList; |
|
| 37 | + /** @var IJobList */ |
|
| 38 | + private $jobList; |
|
| 39 | 39 | |
| 40 | - /** @var IConfig */ |
|
| 41 | - private $config; |
|
| 40 | + /** @var IConfig */ |
|
| 41 | + private $config; |
|
| 42 | 42 | |
| 43 | - public function __construct(IJobList $jobList, IConfig $config) { |
|
| 44 | - $this->jobList = $jobList; |
|
| 45 | - $this->config = $config; |
|
| 46 | - } |
|
| 43 | + public function __construct(IJobList $jobList, IConfig $config) { |
|
| 44 | + $this->jobList = $jobList; |
|
| 45 | + $this->config = $config; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - public function getName(): string { |
|
| 49 | - return 'Add background job to set the lookup server share state for users'; |
|
| 50 | - } |
|
| 48 | + public function getName(): string { |
|
| 49 | + return 'Add background job to set the lookup server share state for users'; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - private function shouldRun(): bool { |
|
| 53 | - $versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0.0'); |
|
| 52 | + private function shouldRun(): bool { |
|
| 53 | + $versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0.0'); |
|
| 54 | 54 | |
| 55 | - // was added to 22.0.0.3 |
|
| 56 | - return version_compare($versionFromBeforeUpdate, '22.0.0.3', '<'); |
|
| 57 | - } |
|
| 55 | + // was added to 22.0.0.3 |
|
| 56 | + return version_compare($versionFromBeforeUpdate, '22.0.0.3', '<'); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - public function run(IOutput $output): void { |
|
| 60 | - $this->jobList->add(LookupServerSendCheckBackgroundJob::class); |
|
| 61 | - } |
|
| 59 | + public function run(IOutput $output): void { |
|
| 60 | + $this->jobList->add(LookupServerSendCheckBackgroundJob::class); |
|
| 61 | + } |
|
| 62 | 62 | } |
@@ -33,19 +33,19 @@ |
||
| 33 | 33 | |
| 34 | 34 | class LookupServerSendCheckBackgroundJob extends QueuedJob { |
| 35 | 35 | |
| 36 | - /** @var IConfig */ |
|
| 37 | - protected $config; |
|
| 38 | - /** @var IUserManager */ |
|
| 39 | - private $userManager; |
|
| 40 | - |
|
| 41 | - public function __construct(IConfig $config, IUserManager $userManager) { |
|
| 42 | - $this->config = $config; |
|
| 43 | - $this->userManager = $userManager; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - public function run($arguments) { |
|
| 47 | - $this->userManager->callForSeenUsers(function (IUser $user) { |
|
| 48 | - $this->config->setUserValue($user->getUID(), 'lookup_server_connector', 'dataSend', '1'); |
|
| 49 | - }); |
|
| 50 | - } |
|
| 36 | + /** @var IConfig */ |
|
| 37 | + protected $config; |
|
| 38 | + /** @var IUserManager */ |
|
| 39 | + private $userManager; |
|
| 40 | + |
|
| 41 | + public function __construct(IConfig $config, IUserManager $userManager) { |
|
| 42 | + $this->config = $config; |
|
| 43 | + $this->userManager = $userManager; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + public function run($arguments) { |
|
| 47 | + $this->userManager->callForSeenUsers(function (IUser $user) { |
|
| 48 | + $this->config->setUserValue($user->getUID(), 'lookup_server_connector', 'dataSend', '1'); |
|
| 49 | + }); |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -44,7 +44,7 @@ |
||
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | public function run($arguments) { |
| 47 | - $this->userManager->callForSeenUsers(function (IUser $user) { |
|
| 47 | + $this->userManager->callForSeenUsers(function(IUser $user) { |
|
| 48 | 48 | $this->config->setUserValue($user->getUID(), 'lookup_server_connector', 'dataSend', '1'); |
| 49 | 49 | }); |
| 50 | 50 | } |
@@ -44,186 +44,186 @@ |
||
| 44 | 44 | use OCP\IUserManager; |
| 45 | 45 | |
| 46 | 46 | class RetryJob extends Job { |
| 47 | - /** @var IClientService */ |
|
| 48 | - private $clientService; |
|
| 49 | - /** @var string */ |
|
| 50 | - private $lookupServer; |
|
| 51 | - /** @var IConfig */ |
|
| 52 | - private $config; |
|
| 53 | - /** @var IUserManager */ |
|
| 54 | - private $userManager; |
|
| 55 | - /** @var IAccountManager */ |
|
| 56 | - private $accountManager; |
|
| 57 | - /** @var Signer */ |
|
| 58 | - private $signer; |
|
| 59 | - /** @var int */ |
|
| 60 | - protected $retries = 0; |
|
| 61 | - /** @var bool */ |
|
| 62 | - protected $retainJob = false; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @param ITimeFactory $time |
|
| 66 | - * @param IClientService $clientService |
|
| 67 | - * @param IConfig $config |
|
| 68 | - * @param IUserManager $userManager |
|
| 69 | - * @param IAccountManager $accountManager |
|
| 70 | - * @param Signer $signer |
|
| 71 | - */ |
|
| 72 | - public function __construct(ITimeFactory $time, |
|
| 73 | - IClientService $clientService, |
|
| 74 | - IConfig $config, |
|
| 75 | - IUserManager $userManager, |
|
| 76 | - IAccountManager $accountManager, |
|
| 77 | - Signer $signer) { |
|
| 78 | - parent::__construct($time); |
|
| 79 | - $this->clientService = $clientService; |
|
| 80 | - $this->config = $config; |
|
| 81 | - $this->userManager = $userManager; |
|
| 82 | - $this->accountManager = $accountManager; |
|
| 83 | - $this->signer = $signer; |
|
| 84 | - |
|
| 85 | - $this->lookupServer = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); |
|
| 86 | - if (!empty($this->lookupServer)) { |
|
| 87 | - $this->lookupServer = rtrim($this->lookupServer, '/'); |
|
| 88 | - $this->lookupServer .= '/users'; |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * run the job, then remove it from the jobList |
|
| 94 | - * |
|
| 95 | - * @param IJobList $jobList |
|
| 96 | - * @param ILogger|null $logger |
|
| 97 | - */ |
|
| 98 | - public function execute(IJobList $jobList, ILogger $logger = null): void { |
|
| 99 | - if (!isset($this->argument['userId'])) { |
|
| 100 | - // Old background job without user id, just drop it. |
|
| 101 | - $jobList->remove($this, $this->argument); |
|
| 102 | - return; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $this->retries = (int) $this->config->getUserValue($this->argument['userId'], 'lookup_server_connector', 'update_retries', 0); |
|
| 106 | - |
|
| 107 | - if ($this->shouldRemoveBackgroundJob()) { |
|
| 108 | - $jobList->remove($this, $this->argument); |
|
| 109 | - return; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - if ($this->shouldRun()) { |
|
| 113 | - parent::execute($jobList, $logger); |
|
| 114 | - if (!$this->retainJob) { |
|
| 115 | - $jobList->remove($this, $this->argument); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Check if we should kill the background job: |
|
| 122 | - * |
|
| 123 | - * - internet connection is disabled |
|
| 124 | - * - no valid lookup server URL given |
|
| 125 | - * - lookup server was disabled by the admin |
|
| 126 | - * - max retries are reached (set to 5) |
|
| 127 | - * |
|
| 128 | - * @return bool |
|
| 129 | - */ |
|
| 130 | - protected function shouldRemoveBackgroundJob(): bool { |
|
| 131 | - return $this->config->getSystemValueBool('has_internet_connection', true) === false || |
|
| 132 | - $this->config->getSystemValueString('lookup_server', 'https://lookup.nextcloud.com') === '' || |
|
| 133 | - $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes') !== 'yes' || |
|
| 134 | - $this->retries >= 5; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - protected function shouldRun(): bool { |
|
| 138 | - $delay = 100 * 6 ** $this->retries; |
|
| 139 | - return ($this->time->getTime() - $this->lastRun) > $delay; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - protected function run($argument): void { |
|
| 143 | - $user = $this->userManager->get($this->argument['userId']); |
|
| 144 | - if (!$user instanceof IUser) { |
|
| 145 | - // User does not exist anymore |
|
| 146 | - return; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - $data = $this->getUserAccountData($user); |
|
| 150 | - $signedData = $this->signer->sign('lookupserver', $data, $user); |
|
| 151 | - $client = $this->clientService->newClient(); |
|
| 152 | - |
|
| 153 | - try { |
|
| 154 | - if (count($data) === 1) { |
|
| 155 | - $dataOnLookupServer = $this->config->getUserValue($user->getUID(), 'lookup_server_connector', 'dataSend', '0') === '1'; |
|
| 156 | - |
|
| 157 | - if (!$dataOnLookupServer) { |
|
| 158 | - // We never send data to the lookupserver so no need to delete it |
|
| 159 | - return; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - // There is data on the lookup server so we must delete it |
|
| 163 | - $client->delete($this->lookupServer, |
|
| 164 | - [ |
|
| 165 | - 'body' => json_encode($signedData), |
|
| 166 | - 'timeout' => 10, |
|
| 167 | - 'connect_timeout' => 3, |
|
| 168 | - ] |
|
| 169 | - ); |
|
| 170 | - |
|
| 171 | - $this->config->setUserValue($user->getUID(), 'lookup_server_connector', 'dataSend', '0'); |
|
| 172 | - } else { |
|
| 173 | - $client->post($this->lookupServer, |
|
| 174 | - [ |
|
| 175 | - 'body' => json_encode($signedData), |
|
| 176 | - 'timeout' => 10, |
|
| 177 | - 'connect_timeout' => 3, |
|
| 178 | - ] |
|
| 179 | - ); |
|
| 180 | - $this->config->setUserValue($user->getUID(), 'lookup_server_connector', 'dataSend', '1'); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - // Reset retry counter |
|
| 184 | - $this->config->deleteUserValue( |
|
| 185 | - $user->getUID(), |
|
| 186 | - 'lookup_server_connector', |
|
| 187 | - 'update_retries' |
|
| 188 | - ); |
|
| 189 | - } catch (\Exception $e) { |
|
| 190 | - // An error occurred, retry later |
|
| 191 | - $this->retainJob = true; |
|
| 192 | - $this->config->setUserValue( |
|
| 193 | - $user->getUID(), |
|
| 194 | - 'lookup_server_connector', |
|
| 195 | - 'update_retries', |
|
| 196 | - $this->retries + 1 |
|
| 197 | - ); |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - protected function getUserAccountData(IUser $user): array { |
|
| 202 | - $account = $this->accountManager->getAccount($user); |
|
| 203 | - |
|
| 204 | - $publicData = []; |
|
| 205 | - foreach ($account->getProperties() as $property) { |
|
| 206 | - if ($property->getScope() === IAccountManager::SCOPE_PUBLISHED) { |
|
| 207 | - $publicData[$property->getName()] = $property->getValue(); |
|
| 208 | - } |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - $data = ['federationId' => $user->getCloudId()]; |
|
| 212 | - if (!empty($publicData)) { |
|
| 213 | - $data['name'] = $publicData[IAccountManager::PROPERTY_DISPLAYNAME]['value'] ?? ''; |
|
| 214 | - $data['email'] = $publicData[IAccountManager::PROPERTY_EMAIL]['value'] ?? ''; |
|
| 215 | - $data['address'] = $publicData[IAccountManager::PROPERTY_ADDRESS]['value'] ?? ''; |
|
| 216 | - $data['website'] = $publicData[IAccountManager::PROPERTY_WEBSITE]['value'] ?? ''; |
|
| 217 | - $data['twitter'] = $publicData[IAccountManager::PROPERTY_TWITTER]['value'] ?? ''; |
|
| 218 | - $data['phone'] = $publicData[IAccountManager::PROPERTY_PHONE]['value'] ?? ''; |
|
| 219 | - $data['twitter_signature'] = $publicData[IAccountManager::PROPERTY_TWITTER]['signature'] ?? ''; |
|
| 220 | - $data['website_signature'] = $publicData[IAccountManager::PROPERTY_WEBSITE]['signature'] ?? ''; |
|
| 221 | - $data['verificationStatus'] = [ |
|
| 222 | - IAccountManager::PROPERTY_WEBSITE => $publicData[IAccountManager::PROPERTY_WEBSITE]['verified'] ?? '', |
|
| 223 | - IAccountManager::PROPERTY_TWITTER => $publicData[IAccountManager::PROPERTY_TWITTER]['verified'] ?? '', |
|
| 224 | - ]; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - return $data; |
|
| 228 | - } |
|
| 47 | + /** @var IClientService */ |
|
| 48 | + private $clientService; |
|
| 49 | + /** @var string */ |
|
| 50 | + private $lookupServer; |
|
| 51 | + /** @var IConfig */ |
|
| 52 | + private $config; |
|
| 53 | + /** @var IUserManager */ |
|
| 54 | + private $userManager; |
|
| 55 | + /** @var IAccountManager */ |
|
| 56 | + private $accountManager; |
|
| 57 | + /** @var Signer */ |
|
| 58 | + private $signer; |
|
| 59 | + /** @var int */ |
|
| 60 | + protected $retries = 0; |
|
| 61 | + /** @var bool */ |
|
| 62 | + protected $retainJob = false; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @param ITimeFactory $time |
|
| 66 | + * @param IClientService $clientService |
|
| 67 | + * @param IConfig $config |
|
| 68 | + * @param IUserManager $userManager |
|
| 69 | + * @param IAccountManager $accountManager |
|
| 70 | + * @param Signer $signer |
|
| 71 | + */ |
|
| 72 | + public function __construct(ITimeFactory $time, |
|
| 73 | + IClientService $clientService, |
|
| 74 | + IConfig $config, |
|
| 75 | + IUserManager $userManager, |
|
| 76 | + IAccountManager $accountManager, |
|
| 77 | + Signer $signer) { |
|
| 78 | + parent::__construct($time); |
|
| 79 | + $this->clientService = $clientService; |
|
| 80 | + $this->config = $config; |
|
| 81 | + $this->userManager = $userManager; |
|
| 82 | + $this->accountManager = $accountManager; |
|
| 83 | + $this->signer = $signer; |
|
| 84 | + |
|
| 85 | + $this->lookupServer = $config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com'); |
|
| 86 | + if (!empty($this->lookupServer)) { |
|
| 87 | + $this->lookupServer = rtrim($this->lookupServer, '/'); |
|
| 88 | + $this->lookupServer .= '/users'; |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * run the job, then remove it from the jobList |
|
| 94 | + * |
|
| 95 | + * @param IJobList $jobList |
|
| 96 | + * @param ILogger|null $logger |
|
| 97 | + */ |
|
| 98 | + public function execute(IJobList $jobList, ILogger $logger = null): void { |
|
| 99 | + if (!isset($this->argument['userId'])) { |
|
| 100 | + // Old background job without user id, just drop it. |
|
| 101 | + $jobList->remove($this, $this->argument); |
|
| 102 | + return; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $this->retries = (int) $this->config->getUserValue($this->argument['userId'], 'lookup_server_connector', 'update_retries', 0); |
|
| 106 | + |
|
| 107 | + if ($this->shouldRemoveBackgroundJob()) { |
|
| 108 | + $jobList->remove($this, $this->argument); |
|
| 109 | + return; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + if ($this->shouldRun()) { |
|
| 113 | + parent::execute($jobList, $logger); |
|
| 114 | + if (!$this->retainJob) { |
|
| 115 | + $jobList->remove($this, $this->argument); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Check if we should kill the background job: |
|
| 122 | + * |
|
| 123 | + * - internet connection is disabled |
|
| 124 | + * - no valid lookup server URL given |
|
| 125 | + * - lookup server was disabled by the admin |
|
| 126 | + * - max retries are reached (set to 5) |
|
| 127 | + * |
|
| 128 | + * @return bool |
|
| 129 | + */ |
|
| 130 | + protected function shouldRemoveBackgroundJob(): bool { |
|
| 131 | + return $this->config->getSystemValueBool('has_internet_connection', true) === false || |
|
| 132 | + $this->config->getSystemValueString('lookup_server', 'https://lookup.nextcloud.com') === '' || |
|
| 133 | + $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes') !== 'yes' || |
|
| 134 | + $this->retries >= 5; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + protected function shouldRun(): bool { |
|
| 138 | + $delay = 100 * 6 ** $this->retries; |
|
| 139 | + return ($this->time->getTime() - $this->lastRun) > $delay; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + protected function run($argument): void { |
|
| 143 | + $user = $this->userManager->get($this->argument['userId']); |
|
| 144 | + if (!$user instanceof IUser) { |
|
| 145 | + // User does not exist anymore |
|
| 146 | + return; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + $data = $this->getUserAccountData($user); |
|
| 150 | + $signedData = $this->signer->sign('lookupserver', $data, $user); |
|
| 151 | + $client = $this->clientService->newClient(); |
|
| 152 | + |
|
| 153 | + try { |
|
| 154 | + if (count($data) === 1) { |
|
| 155 | + $dataOnLookupServer = $this->config->getUserValue($user->getUID(), 'lookup_server_connector', 'dataSend', '0') === '1'; |
|
| 156 | + |
|
| 157 | + if (!$dataOnLookupServer) { |
|
| 158 | + // We never send data to the lookupserver so no need to delete it |
|
| 159 | + return; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + // There is data on the lookup server so we must delete it |
|
| 163 | + $client->delete($this->lookupServer, |
|
| 164 | + [ |
|
| 165 | + 'body' => json_encode($signedData), |
|
| 166 | + 'timeout' => 10, |
|
| 167 | + 'connect_timeout' => 3, |
|
| 168 | + ] |
|
| 169 | + ); |
|
| 170 | + |
|
| 171 | + $this->config->setUserValue($user->getUID(), 'lookup_server_connector', 'dataSend', '0'); |
|
| 172 | + } else { |
|
| 173 | + $client->post($this->lookupServer, |
|
| 174 | + [ |
|
| 175 | + 'body' => json_encode($signedData), |
|
| 176 | + 'timeout' => 10, |
|
| 177 | + 'connect_timeout' => 3, |
|
| 178 | + ] |
|
| 179 | + ); |
|
| 180 | + $this->config->setUserValue($user->getUID(), 'lookup_server_connector', 'dataSend', '1'); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + // Reset retry counter |
|
| 184 | + $this->config->deleteUserValue( |
|
| 185 | + $user->getUID(), |
|
| 186 | + 'lookup_server_connector', |
|
| 187 | + 'update_retries' |
|
| 188 | + ); |
|
| 189 | + } catch (\Exception $e) { |
|
| 190 | + // An error occurred, retry later |
|
| 191 | + $this->retainJob = true; |
|
| 192 | + $this->config->setUserValue( |
|
| 193 | + $user->getUID(), |
|
| 194 | + 'lookup_server_connector', |
|
| 195 | + 'update_retries', |
|
| 196 | + $this->retries + 1 |
|
| 197 | + ); |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + protected function getUserAccountData(IUser $user): array { |
|
| 202 | + $account = $this->accountManager->getAccount($user); |
|
| 203 | + |
|
| 204 | + $publicData = []; |
|
| 205 | + foreach ($account->getProperties() as $property) { |
|
| 206 | + if ($property->getScope() === IAccountManager::SCOPE_PUBLISHED) { |
|
| 207 | + $publicData[$property->getName()] = $property->getValue(); |
|
| 208 | + } |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + $data = ['federationId' => $user->getCloudId()]; |
|
| 212 | + if (!empty($publicData)) { |
|
| 213 | + $data['name'] = $publicData[IAccountManager::PROPERTY_DISPLAYNAME]['value'] ?? ''; |
|
| 214 | + $data['email'] = $publicData[IAccountManager::PROPERTY_EMAIL]['value'] ?? ''; |
|
| 215 | + $data['address'] = $publicData[IAccountManager::PROPERTY_ADDRESS]['value'] ?? ''; |
|
| 216 | + $data['website'] = $publicData[IAccountManager::PROPERTY_WEBSITE]['value'] ?? ''; |
|
| 217 | + $data['twitter'] = $publicData[IAccountManager::PROPERTY_TWITTER]['value'] ?? ''; |
|
| 218 | + $data['phone'] = $publicData[IAccountManager::PROPERTY_PHONE]['value'] ?? ''; |
|
| 219 | + $data['twitter_signature'] = $publicData[IAccountManager::PROPERTY_TWITTER]['signature'] ?? ''; |
|
| 220 | + $data['website_signature'] = $publicData[IAccountManager::PROPERTY_WEBSITE]['signature'] ?? ''; |
|
| 221 | + $data['verificationStatus'] = [ |
|
| 222 | + IAccountManager::PROPERTY_WEBSITE => $publicData[IAccountManager::PROPERTY_WEBSITE]['verified'] ?? '', |
|
| 223 | + IAccountManager::PROPERTY_TWITTER => $publicData[IAccountManager::PROPERTY_TWITTER]['verified'] ?? '', |
|
| 224 | + ]; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + return $data; |
|
| 228 | + } |
|
| 229 | 229 | } |