Passed
Push — master ( 456412...602de2 )
by Joas
13:17 queued 10s
created
apps/provisioning_api/lib/Controller/UsersController.php 2 patches
Indentation   +1032 added lines, -1032 removed lines patch added patch discarded remove patch
@@ -74,1036 +74,1036 @@
 block discarded – undo
74 74
 
75 75
 class UsersController extends AUserData {
76 76
 
77
-	/** @var IAppManager */
78
-	private $appManager;
79
-	/** @var IURLGenerator */
80
-	protected $urlGenerator;
81
-	/** @var LoggerInterface */
82
-	private $logger;
83
-	/** @var IFactory */
84
-	protected $l10nFactory;
85
-	/** @var NewUserMailHelper */
86
-	private $newUserMailHelper;
87
-	/** @var ISecureRandom */
88
-	private $secureRandom;
89
-	/** @var RemoteWipe */
90
-	private $remoteWipe;
91
-	/** @var KnownUserService */
92
-	private $knownUserService;
93
-	/** @var IEventDispatcher */
94
-	private $eventDispatcher;
95
-
96
-	public function __construct(string $appName,
97
-								IRequest $request,
98
-								IUserManager $userManager,
99
-								IConfig $config,
100
-								IAppManager $appManager,
101
-								IGroupManager $groupManager,
102
-								IUserSession $userSession,
103
-								AccountManager $accountManager,
104
-								IURLGenerator $urlGenerator,
105
-								LoggerInterface $logger,
106
-								IFactory $l10nFactory,
107
-								NewUserMailHelper $newUserMailHelper,
108
-								ISecureRandom $secureRandom,
109
-								RemoteWipe $remoteWipe,
110
-								KnownUserService $knownUserService,
111
-								IEventDispatcher $eventDispatcher) {
112
-		parent::__construct($appName,
113
-							$request,
114
-							$userManager,
115
-							$config,
116
-							$groupManager,
117
-							$userSession,
118
-							$accountManager,
119
-							$l10nFactory);
120
-
121
-		$this->appManager = $appManager;
122
-		$this->urlGenerator = $urlGenerator;
123
-		$this->logger = $logger;
124
-		$this->l10nFactory = $l10nFactory;
125
-		$this->newUserMailHelper = $newUserMailHelper;
126
-		$this->secureRandom = $secureRandom;
127
-		$this->remoteWipe = $remoteWipe;
128
-		$this->knownUserService = $knownUserService;
129
-		$this->eventDispatcher = $eventDispatcher;
130
-	}
131
-
132
-	/**
133
-	 * @NoAdminRequired
134
-	 *
135
-	 * returns a list of users
136
-	 *
137
-	 * @param string $search
138
-	 * @param int $limit
139
-	 * @param int $offset
140
-	 * @return DataResponse
141
-	 */
142
-	public function getUsers(string $search = '', int $limit = null, int $offset = 0): DataResponse {
143
-		$user = $this->userSession->getUser();
144
-		$users = [];
145
-
146
-		// Admin? Or SubAdmin?
147
-		$uid = $user->getUID();
148
-		$subAdminManager = $this->groupManager->getSubAdmin();
149
-		if ($this->groupManager->isAdmin($uid)) {
150
-			$users = $this->userManager->search($search, $limit, $offset);
151
-		} elseif ($subAdminManager->isSubAdmin($user)) {
152
-			$subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user);
153
-			foreach ($subAdminOfGroups as $key => $group) {
154
-				$subAdminOfGroups[$key] = $group->getGID();
155
-			}
156
-
157
-			$users = [];
158
-			foreach ($subAdminOfGroups as $group) {
159
-				$users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search, $limit, $offset));
160
-			}
161
-		}
162
-
163
-		$users = array_keys($users);
164
-
165
-		return new DataResponse([
166
-			'users' => $users
167
-		]);
168
-	}
169
-
170
-	/**
171
-	 * @NoAdminRequired
172
-	 *
173
-	 * returns a list of users and their data
174
-	 */
175
-	public function getUsersDetails(string $search = '', int $limit = null, int $offset = 0): DataResponse {
176
-		$currentUser = $this->userSession->getUser();
177
-		$users = [];
178
-
179
-		// Admin? Or SubAdmin?
180
-		$uid = $currentUser->getUID();
181
-		$subAdminManager = $this->groupManager->getSubAdmin();
182
-		if ($this->groupManager->isAdmin($uid)) {
183
-			$users = $this->userManager->search($search, $limit, $offset);
184
-			$users = array_keys($users);
185
-		} elseif ($subAdminManager->isSubAdmin($currentUser)) {
186
-			$subAdminOfGroups = $subAdminManager->getSubAdminsGroups($currentUser);
187
-			foreach ($subAdminOfGroups as $key => $group) {
188
-				$subAdminOfGroups[$key] = $group->getGID();
189
-			}
190
-
191
-			$users = [];
192
-			foreach ($subAdminOfGroups as $group) {
193
-				$users[] = array_keys($this->groupManager->displayNamesInGroup($group, $search, $limit, $offset));
194
-			}
195
-			$users = array_merge(...$users);
196
-		}
197
-
198
-		$usersDetails = [];
199
-		foreach ($users as $userId) {
200
-			$userId = (string) $userId;
201
-			$userData = $this->getUserData($userId);
202
-			// Do not insert empty entry
203
-			if (!empty($userData)) {
204
-				$usersDetails[$userId] = $userData;
205
-			} else {
206
-				// Logged user does not have permissions to see this user
207
-				// only showing its id
208
-				$usersDetails[$userId] = ['id' => $userId];
209
-			}
210
-		}
211
-
212
-		return new DataResponse([
213
-			'users' => $usersDetails
214
-		]);
215
-	}
216
-
217
-
218
-	/**
219
-	 * @NoAdminRequired
220
-	 * @NoSubAdminRequired
221
-	 *
222
-	 * @param string $location
223
-	 * @param array $search
224
-	 * @return DataResponse
225
-	 */
226
-	public function searchByPhoneNumbers(string $location, array $search): DataResponse {
227
-		$phoneUtil = PhoneNumberUtil::getInstance();
228
-
229
-		if ($phoneUtil->getCountryCodeForRegion($location) === 0) {
230
-			// Not a valid region code
231
-			return new DataResponse([], Http::STATUS_BAD_REQUEST);
232
-		}
233
-
234
-		/** @var IUser $user */
235
-		$user = $this->userSession->getUser();
236
-		$knownTo = $user->getUID();
237
-
238
-		$normalizedNumberToKey = [];
239
-		foreach ($search as $key => $phoneNumbers) {
240
-			foreach ($phoneNumbers as $phone) {
241
-				try {
242
-					$phoneNumber = $phoneUtil->parse($phone, $location);
243
-					if ($phoneNumber instanceof PhoneNumber && $phoneUtil->isValidNumber($phoneNumber)) {
244
-						$normalizedNumber = $phoneUtil->format($phoneNumber, PhoneNumberFormat::E164);
245
-						$normalizedNumberToKey[$normalizedNumber] = (string) $key;
246
-					}
247
-				} catch (NumberParseException $e) {
248
-				}
249
-			}
250
-		}
251
-
252
-		$phoneNumbers = array_keys($normalizedNumberToKey);
253
-
254
-		if (empty($phoneNumbers)) {
255
-			return new DataResponse();
256
-		}
257
-
258
-		// Cleanup all previous entries and only allow new matches
259
-		$this->knownUserService->deleteKnownTo($knownTo);
260
-
261
-		$userMatches = $this->accountManager->searchUsers(IAccountManager::PROPERTY_PHONE, $phoneNumbers);
262
-
263
-		if (empty($userMatches)) {
264
-			return new DataResponse();
265
-		}
266
-
267
-		$cloudUrl = rtrim($this->urlGenerator->getAbsoluteURL('/'), '/');
268
-		if (strpos($cloudUrl, 'http://') === 0) {
269
-			$cloudUrl = substr($cloudUrl, strlen('http://'));
270
-		} elseif (strpos($cloudUrl, 'https://') === 0) {
271
-			$cloudUrl = substr($cloudUrl, strlen('https://'));
272
-		}
273
-
274
-		$matches = [];
275
-		foreach ($userMatches as $phone => $userId) {
276
-			// Not using the ICloudIdManager as that would run a search for each contact to find the display name in the address book
277
-			$matches[$normalizedNumberToKey[$phone]] = $userId . '@' . $cloudUrl;
278
-			$this->knownUserService->storeIsKnownToUser($knownTo, $userId);
279
-		}
280
-
281
-		return new DataResponse($matches);
282
-	}
283
-
284
-	/**
285
-	 * @throws OCSException
286
-	 */
287
-	private function createNewUserId(): string {
288
-		$attempts = 0;
289
-		do {
290
-			$uidCandidate = $this->secureRandom->generate(10, ISecureRandom::CHAR_HUMAN_READABLE);
291
-			if (!$this->userManager->userExists($uidCandidate)) {
292
-				return $uidCandidate;
293
-			}
294
-			$attempts++;
295
-		} while ($attempts < 10);
296
-		throw new OCSException('Could not create non-existing user id', 111);
297
-	}
298
-
299
-	/**
300
-	 * @PasswordConfirmationRequired
301
-	 * @NoAdminRequired
302
-	 *
303
-	 * @param string $userid
304
-	 * @param string $password
305
-	 * @param string $displayName
306
-	 * @param string $email
307
-	 * @param array $groups
308
-	 * @param array $subadmin
309
-	 * @param string $quota
310
-	 * @param string $language
311
-	 * @return DataResponse
312
-	 * @throws OCSException
313
-	 */
314
-	public function addUser(string $userid,
315
-							string $password = '',
316
-							string $displayName = '',
317
-							string $email = '',
318
-							array $groups = [],
319
-							array $subadmin = [],
320
-							string $quota = '',
321
-							string $language = ''): DataResponse {
322
-		$user = $this->userSession->getUser();
323
-		$isAdmin = $this->groupManager->isAdmin($user->getUID());
324
-		$subAdminManager = $this->groupManager->getSubAdmin();
325
-
326
-		if (empty($userid) && $this->config->getAppValue('core', 'newUser.generateUserID', 'no') === 'yes') {
327
-			$userid = $this->createNewUserId();
328
-		}
329
-
330
-		if ($this->userManager->userExists($userid)) {
331
-			$this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']);
332
-			throw new OCSException('User already exists', 102);
333
-		}
334
-
335
-		if ($groups !== []) {
336
-			foreach ($groups as $group) {
337
-				if (!$this->groupManager->groupExists($group)) {
338
-					throw new OCSException('group '.$group.' does not exist', 104);
339
-				}
340
-				if (!$isAdmin && !$subAdminManager->isSubAdminOfGroup($user, $this->groupManager->get($group))) {
341
-					throw new OCSException('insufficient privileges for group '. $group, 105);
342
-				}
343
-			}
344
-		} else {
345
-			if (!$isAdmin) {
346
-				throw new OCSException('no group specified (required for subadmins)', 106);
347
-			}
348
-		}
349
-
350
-		$subadminGroups = [];
351
-		if ($subadmin !== []) {
352
-			foreach ($subadmin as $groupid) {
353
-				$group = $this->groupManager->get($groupid);
354
-				// Check if group exists
355
-				if ($group === null) {
356
-					throw new OCSException('Subadmin group does not exist',  102);
357
-				}
358
-				// Check if trying to make subadmin of admin group
359
-				if ($group->getGID() === 'admin') {
360
-					throw new OCSException('Cannot create subadmins for admin group', 103);
361
-				}
362
-				// Check if has permission to promote subadmins
363
-				if (!$subAdminManager->isSubAdminOfGroup($user, $group) && !$isAdmin) {
364
-					throw new OCSForbiddenException('No permissions to promote subadmins');
365
-				}
366
-				$subadminGroups[] = $group;
367
-			}
368
-		}
369
-
370
-		$generatePasswordResetToken = false;
371
-		if ($password === '') {
372
-			if ($email === '') {
373
-				throw new OCSException('To send a password link to the user an email address is required.', 108);
374
-			}
375
-
376
-			$passwordEvent = new GenerateSecurePasswordEvent();
377
-			$this->eventDispatcher->dispatchTyped($passwordEvent);
378
-
379
-			$password = $passwordEvent->getPassword();
380
-			if ($password === null) {
381
-				// Fallback: ensure to pass password_policy in any case
382
-				$password = $this->secureRandom->generate(10)
383
-					. $this->secureRandom->generate(1, ISecureRandom::CHAR_UPPER)
384
-					. $this->secureRandom->generate(1, ISecureRandom::CHAR_LOWER)
385
-					. $this->secureRandom->generate(1, ISecureRandom::CHAR_DIGITS)
386
-					. $this->secureRandom->generate(1, ISecureRandom::CHAR_SYMBOLS);
387
-			}
388
-			$generatePasswordResetToken = true;
389
-		}
390
-
391
-		if ($email === '' && $this->config->getAppValue('core', 'newUser.requireEmail', 'no') === 'yes') {
392
-			throw new OCSException('Required email address was not provided', 110);
393
-		}
394
-
395
-		try {
396
-			$newUser = $this->userManager->createUser($userid, $password);
397
-			$this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']);
398
-
399
-			foreach ($groups as $group) {
400
-				$this->groupManager->get($group)->addUser($newUser);
401
-				$this->logger->info('Added userid ' . $userid . ' to group ' . $group, ['app' => 'ocs_api']);
402
-			}
403
-			foreach ($subadminGroups as $group) {
404
-				$subAdminManager->createSubAdmin($newUser, $group);
405
-			}
406
-
407
-			if ($displayName !== '') {
408
-				$this->editUser($userid, 'display', $displayName);
409
-			}
410
-
411
-			if ($quota !== '') {
412
-				$this->editUser($userid, 'quota', $quota);
413
-			}
414
-
415
-			if ($language !== '') {
416
-				$this->editUser($userid, 'language', $language);
417
-			}
418
-
419
-			// Send new user mail only if a mail is set
420
-			if ($email !== '') {
421
-				$newUser->setEMailAddress($email);
422
-				if ($this->config->getAppValue('core', 'newUser.sendEmail', 'yes') === 'yes') {
423
-					try {
424
-						$emailTemplate = $this->newUserMailHelper->generateTemplate($newUser, $generatePasswordResetToken);
425
-						$this->newUserMailHelper->sendMail($newUser, $emailTemplate);
426
-					} catch (\Exception $e) {
427
-						// Mail could be failing hard or just be plain not configured
428
-						// Logging error as it is the hardest of the two
429
-						$this->logger->error("Unable to send the invitation mail to $email",
430
-							[
431
-								'app' => 'ocs_api',
432
-								'exception' => $e,
433
-							]
434
-						);
435
-					}
436
-				}
437
-			}
438
-
439
-			return new DataResponse(['id' => $userid]);
440
-		} catch (HintException $e) {
441
-			$this->logger->warning('Failed addUser attempt with hint exception.',
442
-				[
443
-					'app' => 'ocs_api',
444
-					'exception' => $e,
445
-				]
446
-			);
447
-			throw new OCSException($e->getHint(), 107);
448
-		} catch (OCSException $e) {
449
-			$this->logger->warning('Failed addUser attempt with ocs exeption.',
450
-				[
451
-					'app' => 'ocs_api',
452
-					'exception' => $e,
453
-				]
454
-			);
455
-			throw $e;
456
-		} catch (\InvalidArgumentException $e) {
457
-			$this->logger->error('Failed addUser attempt with invalid argument exeption.',
458
-				[
459
-					'app' => 'ocs_api',
460
-					'exception' => $e,
461
-				]
462
-			);
463
-			throw new OCSException($e->getMessage(), 101);
464
-		} catch (\Exception $e) {
465
-			$this->logger->error('Failed addUser attempt with exception.',
466
-				[
467
-					'app' => 'ocs_api',
468
-					'exception' => $e
469
-				]
470
-			);
471
-			throw new OCSException('Bad request', 101);
472
-		}
473
-	}
474
-
475
-	/**
476
-	 * @NoAdminRequired
477
-	 * @NoSubAdminRequired
478
-	 *
479
-	 * gets user info
480
-	 *
481
-	 * @param string $userId
482
-	 * @return DataResponse
483
-	 * @throws OCSException
484
-	 */
485
-	public function getUser(string $userId): DataResponse {
486
-		$includeScopes = false;
487
-		$currentUser = $this->userSession->getUser();
488
-		if ($currentUser && $currentUser->getUID() === $userId) {
489
-			$includeScopes = true;
490
-		}
491
-
492
-		$data = $this->getUserData($userId, $includeScopes);
493
-		// getUserData returns empty array if not enough permissions
494
-		if (empty($data)) {
495
-			throw new OCSException('', OCSController::RESPOND_UNAUTHORISED);
496
-		}
497
-		return new DataResponse($data);
498
-	}
499
-
500
-	/**
501
-	 * @NoAdminRequired
502
-	 * @NoSubAdminRequired
503
-	 *
504
-	 * gets user info from the currently logged in user
505
-	 *
506
-	 * @return DataResponse
507
-	 * @throws OCSException
508
-	 */
509
-	public function getCurrentUser(): DataResponse {
510
-		$user = $this->userSession->getUser();
511
-		if ($user) {
512
-			$data = $this->getUserData($user->getUID(), true);
513
-			// rename "displayname" to "display-name" only for this call to keep
514
-			// the API stable.
515
-			$data['display-name'] = $data['displayname'];
516
-			unset($data['displayname']);
517
-			return new DataResponse($data);
518
-		}
519
-
520
-		throw new OCSException('', OCSController::RESPOND_UNAUTHORISED);
521
-	}
522
-
523
-	/**
524
-	 * @NoAdminRequired
525
-	 * @NoSubAdminRequired
526
-	 */
527
-	public function getEditableFields(): DataResponse {
528
-		$permittedFields = [];
529
-
530
-		// Editing self (display, email)
531
-		if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
532
-			$permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME;
533
-			$permittedFields[] = IAccountManager::PROPERTY_EMAIL;
534
-		}
535
-
536
-		$permittedFields[] = IAccountManager::PROPERTY_PHONE;
537
-		$permittedFields[] = IAccountManager::PROPERTY_ADDRESS;
538
-		$permittedFields[] = IAccountManager::PROPERTY_WEBSITE;
539
-		$permittedFields[] = IAccountManager::PROPERTY_TWITTER;
540
-
541
-		return new DataResponse($permittedFields);
542
-	}
543
-
544
-	/**
545
-	 * @NoAdminRequired
546
-	 * @NoSubAdminRequired
547
-	 * @PasswordConfirmationRequired
548
-	 *
549
-	 * edit users
550
-	 *
551
-	 * @param string $userId
552
-	 * @param string $key
553
-	 * @param string $value
554
-	 * @return DataResponse
555
-	 * @throws OCSException
556
-	 */
557
-	public function editUser(string $userId, string $key, string $value): DataResponse {
558
-		$currentLoggedInUser = $this->userSession->getUser();
559
-
560
-		$targetUser = $this->userManager->get($userId);
561
-		if ($targetUser === null) {
562
-			throw new OCSException('', OCSController::RESPOND_UNAUTHORISED);
563
-		}
564
-
565
-		$permittedFields = [];
566
-		if ($targetUser->getUID() === $currentLoggedInUser->getUID()) {
567
-			// Editing self (display, email)
568
-			if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
569
-				$permittedFields[] = 'display';
570
-				$permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME;
571
-				$permittedFields[] = IAccountManager::PROPERTY_EMAIL;
572
-			}
573
-
574
-			$permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME . self::SCOPE_SUFFIX;
575
-			$permittedFields[] = IAccountManager::PROPERTY_EMAIL . self::SCOPE_SUFFIX;
576
-
577
-			$permittedFields[] = 'password';
578
-			if ($this->config->getSystemValue('force_language', false) === false ||
579
-				$this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
580
-				$permittedFields[] = 'language';
581
-			}
582
-
583
-			if ($this->config->getSystemValue('force_locale', false) === false ||
584
-				$this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
585
-				$permittedFields[] = 'locale';
586
-			}
587
-
588
-			$permittedFields[] = IAccountManager::PROPERTY_PHONE;
589
-			$permittedFields[] = IAccountManager::PROPERTY_ADDRESS;
590
-			$permittedFields[] = IAccountManager::PROPERTY_WEBSITE;
591
-			$permittedFields[] = IAccountManager::PROPERTY_TWITTER;
592
-			$permittedFields[] = IAccountManager::PROPERTY_PHONE . self::SCOPE_SUFFIX;
593
-			$permittedFields[] = IAccountManager::PROPERTY_ADDRESS . self::SCOPE_SUFFIX;
594
-			$permittedFields[] = IAccountManager::PROPERTY_WEBSITE . self::SCOPE_SUFFIX;
595
-			$permittedFields[] = IAccountManager::PROPERTY_TWITTER . self::SCOPE_SUFFIX;
596
-
597
-			$permittedFields[] = IAccountManager::PROPERTY_AVATAR . self::SCOPE_SUFFIX;
598
-
599
-			// If admin they can edit their own quota
600
-			if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
601
-				$permittedFields[] = 'quota';
602
-			}
603
-		} else {
604
-			// Check if admin / subadmin
605
-			$subAdminManager = $this->groupManager->getSubAdmin();
606
-			if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())
607
-			|| $subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
608
-				// They have permissions over the user
609
-				$permittedFields[] = 'display';
610
-				$permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME;
611
-				$permittedFields[] = IAccountManager::PROPERTY_EMAIL;
612
-				$permittedFields[] = 'password';
613
-				$permittedFields[] = 'language';
614
-				$permittedFields[] = 'locale';
615
-				$permittedFields[] = IAccountManager::PROPERTY_PHONE;
616
-				$permittedFields[] = IAccountManager::PROPERTY_ADDRESS;
617
-				$permittedFields[] = IAccountManager::PROPERTY_WEBSITE;
618
-				$permittedFields[] = IAccountManager::PROPERTY_TWITTER;
619
-				$permittedFields[] = 'quota';
620
-			} else {
621
-				// No rights
622
-				throw new OCSException('', OCSController::RESPOND_UNAUTHORISED);
623
-			}
624
-		}
625
-		// Check if permitted to edit this field
626
-		if (!in_array($key, $permittedFields)) {
627
-			throw new OCSException('', OCSController::RESPOND_UNAUTHORISED);
628
-		}
629
-		// Process the edit
630
-		switch ($key) {
631
-			case 'display':
632
-			case IAccountManager::PROPERTY_DISPLAYNAME:
633
-				$targetUser->setDisplayName($value);
634
-				break;
635
-			case 'quota':
636
-				$quota = $value;
637
-				if ($quota !== 'none' && $quota !== 'default') {
638
-					if (is_numeric($quota)) {
639
-						$quota = (float) $quota;
640
-					} else {
641
-						$quota = \OCP\Util::computerFileSize($quota);
642
-					}
643
-					if ($quota === false) {
644
-						throw new OCSException('Invalid quota value '.$value, 103);
645
-					}
646
-					if ($quota === -1) {
647
-						$quota = 'none';
648
-					} else {
649
-						$quota = \OCP\Util::humanFileSize($quota);
650
-					}
651
-				}
652
-				$targetUser->setQuota($quota);
653
-				break;
654
-			case 'password':
655
-				try {
656
-					if (!$targetUser->canChangePassword()) {
657
-						throw new OCSException('Setting the password is not supported by the users backend', 103);
658
-					}
659
-					$targetUser->setPassword($value);
660
-				} catch (HintException $e) { // password policy error
661
-					throw new OCSException($e->getMessage(), 103);
662
-				}
663
-				break;
664
-			case 'language':
665
-				$languagesCodes = $this->l10nFactory->findAvailableLanguages();
666
-				if (!in_array($value, $languagesCodes, true) && $value !== 'en') {
667
-					throw new OCSException('Invalid language', 102);
668
-				}
669
-				$this->config->setUserValue($targetUser->getUID(), 'core', 'lang', $value);
670
-				break;
671
-			case 'locale':
672
-				if (!$this->l10nFactory->localeExists($value)) {
673
-					throw new OCSException('Invalid locale', 102);
674
-				}
675
-				$this->config->setUserValue($targetUser->getUID(), 'core', 'locale', $value);
676
-				break;
677
-			case IAccountManager::PROPERTY_EMAIL:
678
-				if (filter_var($value, FILTER_VALIDATE_EMAIL) || $value === '') {
679
-					$targetUser->setEMailAddress($value);
680
-				} else {
681
-					throw new OCSException('', 102);
682
-				}
683
-				break;
684
-			case IAccountManager::PROPERTY_PHONE:
685
-			case IAccountManager::PROPERTY_ADDRESS:
686
-			case IAccountManager::PROPERTY_WEBSITE:
687
-			case IAccountManager::PROPERTY_TWITTER:
688
-				$userAccount = $this->accountManager->getUser($targetUser);
689
-				if ($userAccount[$key]['value'] !== $value) {
690
-					$userAccount[$key]['value'] = $value;
691
-					try {
692
-						$this->accountManager->updateUser($targetUser, $userAccount, true);
693
-
694
-						if ($key === IAccountManager::PROPERTY_PHONE) {
695
-							$this->knownUserService->deleteByContactUserId($targetUser->getUID());
696
-						}
697
-					} catch (\InvalidArgumentException $e) {
698
-						throw new OCSException('Invalid ' . $e->getMessage(), 102);
699
-					}
700
-				}
701
-				break;
702
-			case IAccountManager::PROPERTY_DISPLAYNAME . self::SCOPE_SUFFIX:
703
-			case IAccountManager::PROPERTY_EMAIL . self::SCOPE_SUFFIX:
704
-			case IAccountManager::PROPERTY_PHONE . self::SCOPE_SUFFIX:
705
-			case IAccountManager::PROPERTY_ADDRESS . self::SCOPE_SUFFIX:
706
-			case IAccountManager::PROPERTY_WEBSITE . self::SCOPE_SUFFIX:
707
-			case IAccountManager::PROPERTY_TWITTER . self::SCOPE_SUFFIX:
708
-			case IAccountManager::PROPERTY_AVATAR . self::SCOPE_SUFFIX:
709
-				$propertyName = substr($key, 0, strlen($key) - strlen(self::SCOPE_SUFFIX));
710
-				$userAccount = $this->accountManager->getUser($targetUser);
711
-				if ($userAccount[$propertyName]['scope'] !== $value) {
712
-					$userAccount[$propertyName]['scope'] = $value;
713
-					try {
714
-						$this->accountManager->updateUser($targetUser, $userAccount, true);
715
-					} catch (\InvalidArgumentException $e) {
716
-						throw new OCSException('Invalid ' . $e->getMessage(), 102);
717
-					}
718
-				}
719
-				break;
720
-			default:
721
-				throw new OCSException('', 103);
722
-		}
723
-		return new DataResponse();
724
-	}
725
-
726
-	/**
727
-	 * @PasswordConfirmationRequired
728
-	 * @NoAdminRequired
729
-	 *
730
-	 * @param string $userId
731
-	 *
732
-	 * @return DataResponse
733
-	 *
734
-	 * @throws OCSException
735
-	 */
736
-	public function wipeUserDevices(string $userId): DataResponse {
737
-		/** @var IUser $currentLoggedInUser */
738
-		$currentLoggedInUser = $this->userSession->getUser();
739
-
740
-		$targetUser = $this->userManager->get($userId);
741
-
742
-		if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) {
743
-			throw new OCSException('', 101);
744
-		}
745
-
746
-		// If not permitted
747
-		$subAdminManager = $this->groupManager->getSubAdmin();
748
-		if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
749
-			throw new OCSException('', OCSController::RESPOND_UNAUTHORISED);
750
-		}
751
-
752
-		$this->remoteWipe->markAllTokensForWipe($targetUser);
753
-
754
-		return new DataResponse();
755
-	}
756
-
757
-	/**
758
-	 * @PasswordConfirmationRequired
759
-	 * @NoAdminRequired
760
-	 *
761
-	 * @param string $userId
762
-	 * @return DataResponse
763
-	 * @throws OCSException
764
-	 */
765
-	public function deleteUser(string $userId): DataResponse {
766
-		$currentLoggedInUser = $this->userSession->getUser();
767
-
768
-		$targetUser = $this->userManager->get($userId);
769
-
770
-		if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) {
771
-			throw new OCSException('', 101);
772
-		}
773
-
774
-		// If not permitted
775
-		$subAdminManager = $this->groupManager->getSubAdmin();
776
-		if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
777
-			throw new OCSException('', OCSController::RESPOND_UNAUTHORISED);
778
-		}
779
-
780
-		// Go ahead with the delete
781
-		if ($targetUser->delete()) {
782
-			return new DataResponse();
783
-		} else {
784
-			throw new OCSException('', 101);
785
-		}
786
-	}
787
-
788
-	/**
789
-	 * @PasswordConfirmationRequired
790
-	 * @NoAdminRequired
791
-	 *
792
-	 * @param string $userId
793
-	 * @return DataResponse
794
-	 * @throws OCSException
795
-	 * @throws OCSForbiddenException
796
-	 */
797
-	public function disableUser(string $userId): DataResponse {
798
-		return $this->setEnabled($userId, false);
799
-	}
800
-
801
-	/**
802
-	 * @PasswordConfirmationRequired
803
-	 * @NoAdminRequired
804
-	 *
805
-	 * @param string $userId
806
-	 * @return DataResponse
807
-	 * @throws OCSException
808
-	 * @throws OCSForbiddenException
809
-	 */
810
-	public function enableUser(string $userId): DataResponse {
811
-		return $this->setEnabled($userId, true);
812
-	}
813
-
814
-	/**
815
-	 * @param string $userId
816
-	 * @param bool $value
817
-	 * @return DataResponse
818
-	 * @throws OCSException
819
-	 */
820
-	private function setEnabled(string $userId, bool $value): DataResponse {
821
-		$currentLoggedInUser = $this->userSession->getUser();
822
-
823
-		$targetUser = $this->userManager->get($userId);
824
-		if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) {
825
-			throw new OCSException('', 101);
826
-		}
827
-
828
-		// If not permitted
829
-		$subAdminManager = $this->groupManager->getSubAdmin();
830
-		if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
831
-			throw new OCSException('', OCSController::RESPOND_UNAUTHORISED);
832
-		}
833
-
834
-		// enable/disable the user now
835
-		$targetUser->setEnabled($value);
836
-		return new DataResponse();
837
-	}
838
-
839
-	/**
840
-	 * @NoAdminRequired
841
-	 * @NoSubAdminRequired
842
-	 *
843
-	 * @param string $userId
844
-	 * @return DataResponse
845
-	 * @throws OCSException
846
-	 */
847
-	public function getUsersGroups(string $userId): DataResponse {
848
-		$loggedInUser = $this->userSession->getUser();
849
-
850
-		$targetUser = $this->userManager->get($userId);
851
-		if ($targetUser === null) {
852
-			throw new OCSException('', OCSController::RESPOND_NOT_FOUND);
853
-		}
854
-
855
-		if ($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) {
856
-			// Self lookup or admin lookup
857
-			return new DataResponse([
858
-				'groups' => $this->groupManager->getUserGroupIds($targetUser)
859
-			]);
860
-		} else {
861
-			$subAdminManager = $this->groupManager->getSubAdmin();
862
-
863
-			// Looking up someone else
864
-			if ($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) {
865
-				// Return the group that the method caller is subadmin of for the user in question
866
-				/** @var IGroup[] $getSubAdminsGroups */
867
-				$getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser);
868
-				foreach ($getSubAdminsGroups as $key => $group) {
869
-					$getSubAdminsGroups[$key] = $group->getGID();
870
-				}
871
-				$groups = array_intersect(
872
-					$getSubAdminsGroups,
873
-					$this->groupManager->getUserGroupIds($targetUser)
874
-				);
875
-				return new DataResponse(['groups' => $groups]);
876
-			} else {
877
-				// Not permitted
878
-				throw new OCSException('', OCSController::RESPOND_UNAUTHORISED);
879
-			}
880
-		}
881
-	}
882
-
883
-	/**
884
-	 * @PasswordConfirmationRequired
885
-	 * @NoAdminRequired
886
-	 *
887
-	 * @param string $userId
888
-	 * @param string $groupid
889
-	 * @return DataResponse
890
-	 * @throws OCSException
891
-	 */
892
-	public function addToGroup(string $userId, string $groupid = ''): DataResponse {
893
-		if ($groupid === '') {
894
-			throw new OCSException('', 101);
895
-		}
896
-
897
-		$group = $this->groupManager->get($groupid);
898
-		$targetUser = $this->userManager->get($userId);
899
-		if ($group === null) {
900
-			throw new OCSException('', 102);
901
-		}
902
-		if ($targetUser === null) {
903
-			throw new OCSException('', 103);
904
-		}
905
-
906
-		// If they're not an admin, check they are a subadmin of the group in question
907
-		$loggedInUser = $this->userSession->getUser();
908
-		$subAdminManager = $this->groupManager->getSubAdmin();
909
-		if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) {
910
-			throw new OCSException('', 104);
911
-		}
912
-
913
-		// Add user to group
914
-		$group->addUser($targetUser);
915
-		return new DataResponse();
916
-	}
917
-
918
-	/**
919
-	 * @PasswordConfirmationRequired
920
-	 * @NoAdminRequired
921
-	 *
922
-	 * @param string $userId
923
-	 * @param string $groupid
924
-	 * @return DataResponse
925
-	 * @throws OCSException
926
-	 */
927
-	public function removeFromGroup(string $userId, string $groupid): DataResponse {
928
-		$loggedInUser = $this->userSession->getUser();
929
-
930
-		if ($groupid === null || trim($groupid) === '') {
931
-			throw new OCSException('', 101);
932
-		}
933
-
934
-		$group = $this->groupManager->get($groupid);
935
-		if ($group === null) {
936
-			throw new OCSException('', 102);
937
-		}
938
-
939
-		$targetUser = $this->userManager->get($userId);
940
-		if ($targetUser === null) {
941
-			throw new OCSException('', 103);
942
-		}
943
-
944
-		// If they're not an admin, check they are a subadmin of the group in question
945
-		$subAdminManager = $this->groupManager->getSubAdmin();
946
-		if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) {
947
-			throw new OCSException('', 104);
948
-		}
949
-
950
-		// Check they aren't removing themselves from 'admin' or their 'subadmin; group
951
-		if ($targetUser->getUID() === $loggedInUser->getUID()) {
952
-			if ($this->groupManager->isAdmin($loggedInUser->getUID())) {
953
-				if ($group->getGID() === 'admin') {
954
-					throw new OCSException('Cannot remove yourself from the admin group', 105);
955
-				}
956
-			} else {
957
-				// Not an admin, so the user must be a subadmin of this group, but that is not allowed.
958
-				throw new OCSException('Cannot remove yourself from this group as you are a SubAdmin', 105);
959
-			}
960
-		} elseif (!$this->groupManager->isAdmin($loggedInUser->getUID())) {
961
-			/** @var IGroup[] $subAdminGroups */
962
-			$subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser);
963
-			$subAdminGroups = array_map(function (IGroup $subAdminGroup) {
964
-				return $subAdminGroup->getGID();
965
-			}, $subAdminGroups);
966
-			$userGroups = $this->groupManager->getUserGroupIds($targetUser);
967
-			$userSubAdminGroups = array_intersect($subAdminGroups, $userGroups);
968
-
969
-			if (count($userSubAdminGroups) <= 1) {
970
-				// Subadmin must not be able to remove a user from all their subadmin groups.
971
-				throw new OCSException('Not viable to remove user from the last group you are SubAdmin of', 105);
972
-			}
973
-		}
974
-
975
-		// Remove user from group
976
-		$group->removeUser($targetUser);
977
-		return new DataResponse();
978
-	}
979
-
980
-	/**
981
-	 * Creates a subadmin
982
-	 *
983
-	 * @PasswordConfirmationRequired
984
-	 *
985
-	 * @param string $userId
986
-	 * @param string $groupid
987
-	 * @return DataResponse
988
-	 * @throws OCSException
989
-	 */
990
-	public function addSubAdmin(string $userId, string $groupid): DataResponse {
991
-		$group = $this->groupManager->get($groupid);
992
-		$user = $this->userManager->get($userId);
993
-
994
-		// Check if the user exists
995
-		if ($user === null) {
996
-			throw new OCSException('User does not exist', 101);
997
-		}
998
-		// Check if group exists
999
-		if ($group === null) {
1000
-			throw new OCSException('Group does not exist',  102);
1001
-		}
1002
-		// Check if trying to make subadmin of admin group
1003
-		if ($group->getGID() === 'admin') {
1004
-			throw new OCSException('Cannot create subadmins for admin group', 103);
1005
-		}
1006
-
1007
-		$subAdminManager = $this->groupManager->getSubAdmin();
1008
-
1009
-		// We cannot be subadmin twice
1010
-		if ($subAdminManager->isSubAdminOfGroup($user, $group)) {
1011
-			return new DataResponse();
1012
-		}
1013
-		// Go
1014
-		$subAdminManager->createSubAdmin($user, $group);
1015
-		return new DataResponse();
1016
-	}
1017
-
1018
-	/**
1019
-	 * Removes a subadmin from a group
1020
-	 *
1021
-	 * @PasswordConfirmationRequired
1022
-	 *
1023
-	 * @param string $userId
1024
-	 * @param string $groupid
1025
-	 * @return DataResponse
1026
-	 * @throws OCSException
1027
-	 */
1028
-	public function removeSubAdmin(string $userId, string $groupid): DataResponse {
1029
-		$group = $this->groupManager->get($groupid);
1030
-		$user = $this->userManager->get($userId);
1031
-		$subAdminManager = $this->groupManager->getSubAdmin();
1032
-
1033
-		// Check if the user exists
1034
-		if ($user === null) {
1035
-			throw new OCSException('User does not exist', 101);
1036
-		}
1037
-		// Check if the group exists
1038
-		if ($group === null) {
1039
-			throw new OCSException('Group does not exist', 101);
1040
-		}
1041
-		// Check if they are a subadmin of this said group
1042
-		if (!$subAdminManager->isSubAdminOfGroup($user, $group)) {
1043
-			throw new OCSException('User is not a subadmin of this group', 102);
1044
-		}
1045
-
1046
-		// Go
1047
-		$subAdminManager->deleteSubAdmin($user, $group);
1048
-		return new DataResponse();
1049
-	}
1050
-
1051
-	/**
1052
-	 * Get the groups a user is a subadmin of
1053
-	 *
1054
-	 * @param string $userId
1055
-	 * @return DataResponse
1056
-	 * @throws OCSException
1057
-	 */
1058
-	public function getUserSubAdminGroups(string $userId): DataResponse {
1059
-		$groups = $this->getUserSubAdminGroupsData($userId);
1060
-		return new DataResponse($groups);
1061
-	}
1062
-
1063
-	/**
1064
-	 * @NoAdminRequired
1065
-	 * @PasswordConfirmationRequired
1066
-	 *
1067
-	 * resend welcome message
1068
-	 *
1069
-	 * @param string $userId
1070
-	 * @return DataResponse
1071
-	 * @throws OCSException
1072
-	 */
1073
-	public function resendWelcomeMessage(string $userId): DataResponse {
1074
-		$currentLoggedInUser = $this->userSession->getUser();
1075
-
1076
-		$targetUser = $this->userManager->get($userId);
1077
-		if ($targetUser === null) {
1078
-			throw new OCSException('', OCSController::RESPOND_NOT_FOUND);
1079
-		}
1080
-
1081
-		// Check if admin / subadmin
1082
-		$subAdminManager = $this->groupManager->getSubAdmin();
1083
-		if (!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)
1084
-			&& !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
1085
-			// No rights
1086
-			throw new OCSException('', OCSController::RESPOND_UNAUTHORISED);
1087
-		}
1088
-
1089
-		$email = $targetUser->getEMailAddress();
1090
-		if ($email === '' || $email === null) {
1091
-			throw new OCSException('Email address not available', 101);
1092
-		}
1093
-
1094
-		try {
1095
-			$emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false);
1096
-			$this->newUserMailHelper->sendMail($targetUser, $emailTemplate);
1097
-		} catch (\Exception $e) {
1098
-			$this->logger->error("Can't send new user mail to $email",
1099
-				[
1100
-					'app' => 'settings',
1101
-					'exception' => $e,
1102
-				]
1103
-			);
1104
-			throw new OCSException('Sending email failed', 102);
1105
-		}
1106
-
1107
-		return new DataResponse();
1108
-	}
77
+    /** @var IAppManager */
78
+    private $appManager;
79
+    /** @var IURLGenerator */
80
+    protected $urlGenerator;
81
+    /** @var LoggerInterface */
82
+    private $logger;
83
+    /** @var IFactory */
84
+    protected $l10nFactory;
85
+    /** @var NewUserMailHelper */
86
+    private $newUserMailHelper;
87
+    /** @var ISecureRandom */
88
+    private $secureRandom;
89
+    /** @var RemoteWipe */
90
+    private $remoteWipe;
91
+    /** @var KnownUserService */
92
+    private $knownUserService;
93
+    /** @var IEventDispatcher */
94
+    private $eventDispatcher;
95
+
96
+    public function __construct(string $appName,
97
+                                IRequest $request,
98
+                                IUserManager $userManager,
99
+                                IConfig $config,
100
+                                IAppManager $appManager,
101
+                                IGroupManager $groupManager,
102
+                                IUserSession $userSession,
103
+                                AccountManager $accountManager,
104
+                                IURLGenerator $urlGenerator,
105
+                                LoggerInterface $logger,
106
+                                IFactory $l10nFactory,
107
+                                NewUserMailHelper $newUserMailHelper,
108
+                                ISecureRandom $secureRandom,
109
+                                RemoteWipe $remoteWipe,
110
+                                KnownUserService $knownUserService,
111
+                                IEventDispatcher $eventDispatcher) {
112
+        parent::__construct($appName,
113
+                            $request,
114
+                            $userManager,
115
+                            $config,
116
+                            $groupManager,
117
+                            $userSession,
118
+                            $accountManager,
119
+                            $l10nFactory);
120
+
121
+        $this->appManager = $appManager;
122
+        $this->urlGenerator = $urlGenerator;
123
+        $this->logger = $logger;
124
+        $this->l10nFactory = $l10nFactory;
125
+        $this->newUserMailHelper = $newUserMailHelper;
126
+        $this->secureRandom = $secureRandom;
127
+        $this->remoteWipe = $remoteWipe;
128
+        $this->knownUserService = $knownUserService;
129
+        $this->eventDispatcher = $eventDispatcher;
130
+    }
131
+
132
+    /**
133
+     * @NoAdminRequired
134
+     *
135
+     * returns a list of users
136
+     *
137
+     * @param string $search
138
+     * @param int $limit
139
+     * @param int $offset
140
+     * @return DataResponse
141
+     */
142
+    public function getUsers(string $search = '', int $limit = null, int $offset = 0): DataResponse {
143
+        $user = $this->userSession->getUser();
144
+        $users = [];
145
+
146
+        // Admin? Or SubAdmin?
147
+        $uid = $user->getUID();
148
+        $subAdminManager = $this->groupManager->getSubAdmin();
149
+        if ($this->groupManager->isAdmin($uid)) {
150
+            $users = $this->userManager->search($search, $limit, $offset);
151
+        } elseif ($subAdminManager->isSubAdmin($user)) {
152
+            $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($user);
153
+            foreach ($subAdminOfGroups as $key => $group) {
154
+                $subAdminOfGroups[$key] = $group->getGID();
155
+            }
156
+
157
+            $users = [];
158
+            foreach ($subAdminOfGroups as $group) {
159
+                $users = array_merge($users, $this->groupManager->displayNamesInGroup($group, $search, $limit, $offset));
160
+            }
161
+        }
162
+
163
+        $users = array_keys($users);
164
+
165
+        return new DataResponse([
166
+            'users' => $users
167
+        ]);
168
+    }
169
+
170
+    /**
171
+     * @NoAdminRequired
172
+     *
173
+     * returns a list of users and their data
174
+     */
175
+    public function getUsersDetails(string $search = '', int $limit = null, int $offset = 0): DataResponse {
176
+        $currentUser = $this->userSession->getUser();
177
+        $users = [];
178
+
179
+        // Admin? Or SubAdmin?
180
+        $uid = $currentUser->getUID();
181
+        $subAdminManager = $this->groupManager->getSubAdmin();
182
+        if ($this->groupManager->isAdmin($uid)) {
183
+            $users = $this->userManager->search($search, $limit, $offset);
184
+            $users = array_keys($users);
185
+        } elseif ($subAdminManager->isSubAdmin($currentUser)) {
186
+            $subAdminOfGroups = $subAdminManager->getSubAdminsGroups($currentUser);
187
+            foreach ($subAdminOfGroups as $key => $group) {
188
+                $subAdminOfGroups[$key] = $group->getGID();
189
+            }
190
+
191
+            $users = [];
192
+            foreach ($subAdminOfGroups as $group) {
193
+                $users[] = array_keys($this->groupManager->displayNamesInGroup($group, $search, $limit, $offset));
194
+            }
195
+            $users = array_merge(...$users);
196
+        }
197
+
198
+        $usersDetails = [];
199
+        foreach ($users as $userId) {
200
+            $userId = (string) $userId;
201
+            $userData = $this->getUserData($userId);
202
+            // Do not insert empty entry
203
+            if (!empty($userData)) {
204
+                $usersDetails[$userId] = $userData;
205
+            } else {
206
+                // Logged user does not have permissions to see this user
207
+                // only showing its id
208
+                $usersDetails[$userId] = ['id' => $userId];
209
+            }
210
+        }
211
+
212
+        return new DataResponse([
213
+            'users' => $usersDetails
214
+        ]);
215
+    }
216
+
217
+
218
+    /**
219
+     * @NoAdminRequired
220
+     * @NoSubAdminRequired
221
+     *
222
+     * @param string $location
223
+     * @param array $search
224
+     * @return DataResponse
225
+     */
226
+    public function searchByPhoneNumbers(string $location, array $search): DataResponse {
227
+        $phoneUtil = PhoneNumberUtil::getInstance();
228
+
229
+        if ($phoneUtil->getCountryCodeForRegion($location) === 0) {
230
+            // Not a valid region code
231
+            return new DataResponse([], Http::STATUS_BAD_REQUEST);
232
+        }
233
+
234
+        /** @var IUser $user */
235
+        $user = $this->userSession->getUser();
236
+        $knownTo = $user->getUID();
237
+
238
+        $normalizedNumberToKey = [];
239
+        foreach ($search as $key => $phoneNumbers) {
240
+            foreach ($phoneNumbers as $phone) {
241
+                try {
242
+                    $phoneNumber = $phoneUtil->parse($phone, $location);
243
+                    if ($phoneNumber instanceof PhoneNumber && $phoneUtil->isValidNumber($phoneNumber)) {
244
+                        $normalizedNumber = $phoneUtil->format($phoneNumber, PhoneNumberFormat::E164);
245
+                        $normalizedNumberToKey[$normalizedNumber] = (string) $key;
246
+                    }
247
+                } catch (NumberParseException $e) {
248
+                }
249
+            }
250
+        }
251
+
252
+        $phoneNumbers = array_keys($normalizedNumberToKey);
253
+
254
+        if (empty($phoneNumbers)) {
255
+            return new DataResponse();
256
+        }
257
+
258
+        // Cleanup all previous entries and only allow new matches
259
+        $this->knownUserService->deleteKnownTo($knownTo);
260
+
261
+        $userMatches = $this->accountManager->searchUsers(IAccountManager::PROPERTY_PHONE, $phoneNumbers);
262
+
263
+        if (empty($userMatches)) {
264
+            return new DataResponse();
265
+        }
266
+
267
+        $cloudUrl = rtrim($this->urlGenerator->getAbsoluteURL('/'), '/');
268
+        if (strpos($cloudUrl, 'http://') === 0) {
269
+            $cloudUrl = substr($cloudUrl, strlen('http://'));
270
+        } elseif (strpos($cloudUrl, 'https://') === 0) {
271
+            $cloudUrl = substr($cloudUrl, strlen('https://'));
272
+        }
273
+
274
+        $matches = [];
275
+        foreach ($userMatches as $phone => $userId) {
276
+            // Not using the ICloudIdManager as that would run a search for each contact to find the display name in the address book
277
+            $matches[$normalizedNumberToKey[$phone]] = $userId . '@' . $cloudUrl;
278
+            $this->knownUserService->storeIsKnownToUser($knownTo, $userId);
279
+        }
280
+
281
+        return new DataResponse($matches);
282
+    }
283
+
284
+    /**
285
+     * @throws OCSException
286
+     */
287
+    private function createNewUserId(): string {
288
+        $attempts = 0;
289
+        do {
290
+            $uidCandidate = $this->secureRandom->generate(10, ISecureRandom::CHAR_HUMAN_READABLE);
291
+            if (!$this->userManager->userExists($uidCandidate)) {
292
+                return $uidCandidate;
293
+            }
294
+            $attempts++;
295
+        } while ($attempts < 10);
296
+        throw new OCSException('Could not create non-existing user id', 111);
297
+    }
298
+
299
+    /**
300
+     * @PasswordConfirmationRequired
301
+     * @NoAdminRequired
302
+     *
303
+     * @param string $userid
304
+     * @param string $password
305
+     * @param string $displayName
306
+     * @param string $email
307
+     * @param array $groups
308
+     * @param array $subadmin
309
+     * @param string $quota
310
+     * @param string $language
311
+     * @return DataResponse
312
+     * @throws OCSException
313
+     */
314
+    public function addUser(string $userid,
315
+                            string $password = '',
316
+                            string $displayName = '',
317
+                            string $email = '',
318
+                            array $groups = [],
319
+                            array $subadmin = [],
320
+                            string $quota = '',
321
+                            string $language = ''): DataResponse {
322
+        $user = $this->userSession->getUser();
323
+        $isAdmin = $this->groupManager->isAdmin($user->getUID());
324
+        $subAdminManager = $this->groupManager->getSubAdmin();
325
+
326
+        if (empty($userid) && $this->config->getAppValue('core', 'newUser.generateUserID', 'no') === 'yes') {
327
+            $userid = $this->createNewUserId();
328
+        }
329
+
330
+        if ($this->userManager->userExists($userid)) {
331
+            $this->logger->error('Failed addUser attempt: User already exists.', ['app' => 'ocs_api']);
332
+            throw new OCSException('User already exists', 102);
333
+        }
334
+
335
+        if ($groups !== []) {
336
+            foreach ($groups as $group) {
337
+                if (!$this->groupManager->groupExists($group)) {
338
+                    throw new OCSException('group '.$group.' does not exist', 104);
339
+                }
340
+                if (!$isAdmin && !$subAdminManager->isSubAdminOfGroup($user, $this->groupManager->get($group))) {
341
+                    throw new OCSException('insufficient privileges for group '. $group, 105);
342
+                }
343
+            }
344
+        } else {
345
+            if (!$isAdmin) {
346
+                throw new OCSException('no group specified (required for subadmins)', 106);
347
+            }
348
+        }
349
+
350
+        $subadminGroups = [];
351
+        if ($subadmin !== []) {
352
+            foreach ($subadmin as $groupid) {
353
+                $group = $this->groupManager->get($groupid);
354
+                // Check if group exists
355
+                if ($group === null) {
356
+                    throw new OCSException('Subadmin group does not exist',  102);
357
+                }
358
+                // Check if trying to make subadmin of admin group
359
+                if ($group->getGID() === 'admin') {
360
+                    throw new OCSException('Cannot create subadmins for admin group', 103);
361
+                }
362
+                // Check if has permission to promote subadmins
363
+                if (!$subAdminManager->isSubAdminOfGroup($user, $group) && !$isAdmin) {
364
+                    throw new OCSForbiddenException('No permissions to promote subadmins');
365
+                }
366
+                $subadminGroups[] = $group;
367
+            }
368
+        }
369
+
370
+        $generatePasswordResetToken = false;
371
+        if ($password === '') {
372
+            if ($email === '') {
373
+                throw new OCSException('To send a password link to the user an email address is required.', 108);
374
+            }
375
+
376
+            $passwordEvent = new GenerateSecurePasswordEvent();
377
+            $this->eventDispatcher->dispatchTyped($passwordEvent);
378
+
379
+            $password = $passwordEvent->getPassword();
380
+            if ($password === null) {
381
+                // Fallback: ensure to pass password_policy in any case
382
+                $password = $this->secureRandom->generate(10)
383
+                    . $this->secureRandom->generate(1, ISecureRandom::CHAR_UPPER)
384
+                    . $this->secureRandom->generate(1, ISecureRandom::CHAR_LOWER)
385
+                    . $this->secureRandom->generate(1, ISecureRandom::CHAR_DIGITS)
386
+                    . $this->secureRandom->generate(1, ISecureRandom::CHAR_SYMBOLS);
387
+            }
388
+            $generatePasswordResetToken = true;
389
+        }
390
+
391
+        if ($email === '' && $this->config->getAppValue('core', 'newUser.requireEmail', 'no') === 'yes') {
392
+            throw new OCSException('Required email address was not provided', 110);
393
+        }
394
+
395
+        try {
396
+            $newUser = $this->userManager->createUser($userid, $password);
397
+            $this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']);
398
+
399
+            foreach ($groups as $group) {
400
+                $this->groupManager->get($group)->addUser($newUser);
401
+                $this->logger->info('Added userid ' . $userid . ' to group ' . $group, ['app' => 'ocs_api']);
402
+            }
403
+            foreach ($subadminGroups as $group) {
404
+                $subAdminManager->createSubAdmin($newUser, $group);
405
+            }
406
+
407
+            if ($displayName !== '') {
408
+                $this->editUser($userid, 'display', $displayName);
409
+            }
410
+
411
+            if ($quota !== '') {
412
+                $this->editUser($userid, 'quota', $quota);
413
+            }
414
+
415
+            if ($language !== '') {
416
+                $this->editUser($userid, 'language', $language);
417
+            }
418
+
419
+            // Send new user mail only if a mail is set
420
+            if ($email !== '') {
421
+                $newUser->setEMailAddress($email);
422
+                if ($this->config->getAppValue('core', 'newUser.sendEmail', 'yes') === 'yes') {
423
+                    try {
424
+                        $emailTemplate = $this->newUserMailHelper->generateTemplate($newUser, $generatePasswordResetToken);
425
+                        $this->newUserMailHelper->sendMail($newUser, $emailTemplate);
426
+                    } catch (\Exception $e) {
427
+                        // Mail could be failing hard or just be plain not configured
428
+                        // Logging error as it is the hardest of the two
429
+                        $this->logger->error("Unable to send the invitation mail to $email",
430
+                            [
431
+                                'app' => 'ocs_api',
432
+                                'exception' => $e,
433
+                            ]
434
+                        );
435
+                    }
436
+                }
437
+            }
438
+
439
+            return new DataResponse(['id' => $userid]);
440
+        } catch (HintException $e) {
441
+            $this->logger->warning('Failed addUser attempt with hint exception.',
442
+                [
443
+                    'app' => 'ocs_api',
444
+                    'exception' => $e,
445
+                ]
446
+            );
447
+            throw new OCSException($e->getHint(), 107);
448
+        } catch (OCSException $e) {
449
+            $this->logger->warning('Failed addUser attempt with ocs exeption.',
450
+                [
451
+                    'app' => 'ocs_api',
452
+                    'exception' => $e,
453
+                ]
454
+            );
455
+            throw $e;
456
+        } catch (\InvalidArgumentException $e) {
457
+            $this->logger->error('Failed addUser attempt with invalid argument exeption.',
458
+                [
459
+                    'app' => 'ocs_api',
460
+                    'exception' => $e,
461
+                ]
462
+            );
463
+            throw new OCSException($e->getMessage(), 101);
464
+        } catch (\Exception $e) {
465
+            $this->logger->error('Failed addUser attempt with exception.',
466
+                [
467
+                    'app' => 'ocs_api',
468
+                    'exception' => $e
469
+                ]
470
+            );
471
+            throw new OCSException('Bad request', 101);
472
+        }
473
+    }
474
+
475
+    /**
476
+     * @NoAdminRequired
477
+     * @NoSubAdminRequired
478
+     *
479
+     * gets user info
480
+     *
481
+     * @param string $userId
482
+     * @return DataResponse
483
+     * @throws OCSException
484
+     */
485
+    public function getUser(string $userId): DataResponse {
486
+        $includeScopes = false;
487
+        $currentUser = $this->userSession->getUser();
488
+        if ($currentUser && $currentUser->getUID() === $userId) {
489
+            $includeScopes = true;
490
+        }
491
+
492
+        $data = $this->getUserData($userId, $includeScopes);
493
+        // getUserData returns empty array if not enough permissions
494
+        if (empty($data)) {
495
+            throw new OCSException('', OCSController::RESPOND_UNAUTHORISED);
496
+        }
497
+        return new DataResponse($data);
498
+    }
499
+
500
+    /**
501
+     * @NoAdminRequired
502
+     * @NoSubAdminRequired
503
+     *
504
+     * gets user info from the currently logged in user
505
+     *
506
+     * @return DataResponse
507
+     * @throws OCSException
508
+     */
509
+    public function getCurrentUser(): DataResponse {
510
+        $user = $this->userSession->getUser();
511
+        if ($user) {
512
+            $data = $this->getUserData($user->getUID(), true);
513
+            // rename "displayname" to "display-name" only for this call to keep
514
+            // the API stable.
515
+            $data['display-name'] = $data['displayname'];
516
+            unset($data['displayname']);
517
+            return new DataResponse($data);
518
+        }
519
+
520
+        throw new OCSException('', OCSController::RESPOND_UNAUTHORISED);
521
+    }
522
+
523
+    /**
524
+     * @NoAdminRequired
525
+     * @NoSubAdminRequired
526
+     */
527
+    public function getEditableFields(): DataResponse {
528
+        $permittedFields = [];
529
+
530
+        // Editing self (display, email)
531
+        if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
532
+            $permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME;
533
+            $permittedFields[] = IAccountManager::PROPERTY_EMAIL;
534
+        }
535
+
536
+        $permittedFields[] = IAccountManager::PROPERTY_PHONE;
537
+        $permittedFields[] = IAccountManager::PROPERTY_ADDRESS;
538
+        $permittedFields[] = IAccountManager::PROPERTY_WEBSITE;
539
+        $permittedFields[] = IAccountManager::PROPERTY_TWITTER;
540
+
541
+        return new DataResponse($permittedFields);
542
+    }
543
+
544
+    /**
545
+     * @NoAdminRequired
546
+     * @NoSubAdminRequired
547
+     * @PasswordConfirmationRequired
548
+     *
549
+     * edit users
550
+     *
551
+     * @param string $userId
552
+     * @param string $key
553
+     * @param string $value
554
+     * @return DataResponse
555
+     * @throws OCSException
556
+     */
557
+    public function editUser(string $userId, string $key, string $value): DataResponse {
558
+        $currentLoggedInUser = $this->userSession->getUser();
559
+
560
+        $targetUser = $this->userManager->get($userId);
561
+        if ($targetUser === null) {
562
+            throw new OCSException('', OCSController::RESPOND_UNAUTHORISED);
563
+        }
564
+
565
+        $permittedFields = [];
566
+        if ($targetUser->getUID() === $currentLoggedInUser->getUID()) {
567
+            // Editing self (display, email)
568
+            if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
569
+                $permittedFields[] = 'display';
570
+                $permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME;
571
+                $permittedFields[] = IAccountManager::PROPERTY_EMAIL;
572
+            }
573
+
574
+            $permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME . self::SCOPE_SUFFIX;
575
+            $permittedFields[] = IAccountManager::PROPERTY_EMAIL . self::SCOPE_SUFFIX;
576
+
577
+            $permittedFields[] = 'password';
578
+            if ($this->config->getSystemValue('force_language', false) === false ||
579
+                $this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
580
+                $permittedFields[] = 'language';
581
+            }
582
+
583
+            if ($this->config->getSystemValue('force_locale', false) === false ||
584
+                $this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
585
+                $permittedFields[] = 'locale';
586
+            }
587
+
588
+            $permittedFields[] = IAccountManager::PROPERTY_PHONE;
589
+            $permittedFields[] = IAccountManager::PROPERTY_ADDRESS;
590
+            $permittedFields[] = IAccountManager::PROPERTY_WEBSITE;
591
+            $permittedFields[] = IAccountManager::PROPERTY_TWITTER;
592
+            $permittedFields[] = IAccountManager::PROPERTY_PHONE . self::SCOPE_SUFFIX;
593
+            $permittedFields[] = IAccountManager::PROPERTY_ADDRESS . self::SCOPE_SUFFIX;
594
+            $permittedFields[] = IAccountManager::PROPERTY_WEBSITE . self::SCOPE_SUFFIX;
595
+            $permittedFields[] = IAccountManager::PROPERTY_TWITTER . self::SCOPE_SUFFIX;
596
+
597
+            $permittedFields[] = IAccountManager::PROPERTY_AVATAR . self::SCOPE_SUFFIX;
598
+
599
+            // If admin they can edit their own quota
600
+            if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
601
+                $permittedFields[] = 'quota';
602
+            }
603
+        } else {
604
+            // Check if admin / subadmin
605
+            $subAdminManager = $this->groupManager->getSubAdmin();
606
+            if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())
607
+            || $subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
608
+                // They have permissions over the user
609
+                $permittedFields[] = 'display';
610
+                $permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME;
611
+                $permittedFields[] = IAccountManager::PROPERTY_EMAIL;
612
+                $permittedFields[] = 'password';
613
+                $permittedFields[] = 'language';
614
+                $permittedFields[] = 'locale';
615
+                $permittedFields[] = IAccountManager::PROPERTY_PHONE;
616
+                $permittedFields[] = IAccountManager::PROPERTY_ADDRESS;
617
+                $permittedFields[] = IAccountManager::PROPERTY_WEBSITE;
618
+                $permittedFields[] = IAccountManager::PROPERTY_TWITTER;
619
+                $permittedFields[] = 'quota';
620
+            } else {
621
+                // No rights
622
+                throw new OCSException('', OCSController::RESPOND_UNAUTHORISED);
623
+            }
624
+        }
625
+        // Check if permitted to edit this field
626
+        if (!in_array($key, $permittedFields)) {
627
+            throw new OCSException('', OCSController::RESPOND_UNAUTHORISED);
628
+        }
629
+        // Process the edit
630
+        switch ($key) {
631
+            case 'display':
632
+            case IAccountManager::PROPERTY_DISPLAYNAME:
633
+                $targetUser->setDisplayName($value);
634
+                break;
635
+            case 'quota':
636
+                $quota = $value;
637
+                if ($quota !== 'none' && $quota !== 'default') {
638
+                    if (is_numeric($quota)) {
639
+                        $quota = (float) $quota;
640
+                    } else {
641
+                        $quota = \OCP\Util::computerFileSize($quota);
642
+                    }
643
+                    if ($quota === false) {
644
+                        throw new OCSException('Invalid quota value '.$value, 103);
645
+                    }
646
+                    if ($quota === -1) {
647
+                        $quota = 'none';
648
+                    } else {
649
+                        $quota = \OCP\Util::humanFileSize($quota);
650
+                    }
651
+                }
652
+                $targetUser->setQuota($quota);
653
+                break;
654
+            case 'password':
655
+                try {
656
+                    if (!$targetUser->canChangePassword()) {
657
+                        throw new OCSException('Setting the password is not supported by the users backend', 103);
658
+                    }
659
+                    $targetUser->setPassword($value);
660
+                } catch (HintException $e) { // password policy error
661
+                    throw new OCSException($e->getMessage(), 103);
662
+                }
663
+                break;
664
+            case 'language':
665
+                $languagesCodes = $this->l10nFactory->findAvailableLanguages();
666
+                if (!in_array($value, $languagesCodes, true) && $value !== 'en') {
667
+                    throw new OCSException('Invalid language', 102);
668
+                }
669
+                $this->config->setUserValue($targetUser->getUID(), 'core', 'lang', $value);
670
+                break;
671
+            case 'locale':
672
+                if (!$this->l10nFactory->localeExists($value)) {
673
+                    throw new OCSException('Invalid locale', 102);
674
+                }
675
+                $this->config->setUserValue($targetUser->getUID(), 'core', 'locale', $value);
676
+                break;
677
+            case IAccountManager::PROPERTY_EMAIL:
678
+                if (filter_var($value, FILTER_VALIDATE_EMAIL) || $value === '') {
679
+                    $targetUser->setEMailAddress($value);
680
+                } else {
681
+                    throw new OCSException('', 102);
682
+                }
683
+                break;
684
+            case IAccountManager::PROPERTY_PHONE:
685
+            case IAccountManager::PROPERTY_ADDRESS:
686
+            case IAccountManager::PROPERTY_WEBSITE:
687
+            case IAccountManager::PROPERTY_TWITTER:
688
+                $userAccount = $this->accountManager->getUser($targetUser);
689
+                if ($userAccount[$key]['value'] !== $value) {
690
+                    $userAccount[$key]['value'] = $value;
691
+                    try {
692
+                        $this->accountManager->updateUser($targetUser, $userAccount, true);
693
+
694
+                        if ($key === IAccountManager::PROPERTY_PHONE) {
695
+                            $this->knownUserService->deleteByContactUserId($targetUser->getUID());
696
+                        }
697
+                    } catch (\InvalidArgumentException $e) {
698
+                        throw new OCSException('Invalid ' . $e->getMessage(), 102);
699
+                    }
700
+                }
701
+                break;
702
+            case IAccountManager::PROPERTY_DISPLAYNAME . self::SCOPE_SUFFIX:
703
+            case IAccountManager::PROPERTY_EMAIL . self::SCOPE_SUFFIX:
704
+            case IAccountManager::PROPERTY_PHONE . self::SCOPE_SUFFIX:
705
+            case IAccountManager::PROPERTY_ADDRESS . self::SCOPE_SUFFIX:
706
+            case IAccountManager::PROPERTY_WEBSITE . self::SCOPE_SUFFIX:
707
+            case IAccountManager::PROPERTY_TWITTER . self::SCOPE_SUFFIX:
708
+            case IAccountManager::PROPERTY_AVATAR . self::SCOPE_SUFFIX:
709
+                $propertyName = substr($key, 0, strlen($key) - strlen(self::SCOPE_SUFFIX));
710
+                $userAccount = $this->accountManager->getUser($targetUser);
711
+                if ($userAccount[$propertyName]['scope'] !== $value) {
712
+                    $userAccount[$propertyName]['scope'] = $value;
713
+                    try {
714
+                        $this->accountManager->updateUser($targetUser, $userAccount, true);
715
+                    } catch (\InvalidArgumentException $e) {
716
+                        throw new OCSException('Invalid ' . $e->getMessage(), 102);
717
+                    }
718
+                }
719
+                break;
720
+            default:
721
+                throw new OCSException('', 103);
722
+        }
723
+        return new DataResponse();
724
+    }
725
+
726
+    /**
727
+     * @PasswordConfirmationRequired
728
+     * @NoAdminRequired
729
+     *
730
+     * @param string $userId
731
+     *
732
+     * @return DataResponse
733
+     *
734
+     * @throws OCSException
735
+     */
736
+    public function wipeUserDevices(string $userId): DataResponse {
737
+        /** @var IUser $currentLoggedInUser */
738
+        $currentLoggedInUser = $this->userSession->getUser();
739
+
740
+        $targetUser = $this->userManager->get($userId);
741
+
742
+        if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) {
743
+            throw new OCSException('', 101);
744
+        }
745
+
746
+        // If not permitted
747
+        $subAdminManager = $this->groupManager->getSubAdmin();
748
+        if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
749
+            throw new OCSException('', OCSController::RESPOND_UNAUTHORISED);
750
+        }
751
+
752
+        $this->remoteWipe->markAllTokensForWipe($targetUser);
753
+
754
+        return new DataResponse();
755
+    }
756
+
757
+    /**
758
+     * @PasswordConfirmationRequired
759
+     * @NoAdminRequired
760
+     *
761
+     * @param string $userId
762
+     * @return DataResponse
763
+     * @throws OCSException
764
+     */
765
+    public function deleteUser(string $userId): DataResponse {
766
+        $currentLoggedInUser = $this->userSession->getUser();
767
+
768
+        $targetUser = $this->userManager->get($userId);
769
+
770
+        if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) {
771
+            throw new OCSException('', 101);
772
+        }
773
+
774
+        // If not permitted
775
+        $subAdminManager = $this->groupManager->getSubAdmin();
776
+        if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
777
+            throw new OCSException('', OCSController::RESPOND_UNAUTHORISED);
778
+        }
779
+
780
+        // Go ahead with the delete
781
+        if ($targetUser->delete()) {
782
+            return new DataResponse();
783
+        } else {
784
+            throw new OCSException('', 101);
785
+        }
786
+    }
787
+
788
+    /**
789
+     * @PasswordConfirmationRequired
790
+     * @NoAdminRequired
791
+     *
792
+     * @param string $userId
793
+     * @return DataResponse
794
+     * @throws OCSException
795
+     * @throws OCSForbiddenException
796
+     */
797
+    public function disableUser(string $userId): DataResponse {
798
+        return $this->setEnabled($userId, false);
799
+    }
800
+
801
+    /**
802
+     * @PasswordConfirmationRequired
803
+     * @NoAdminRequired
804
+     *
805
+     * @param string $userId
806
+     * @return DataResponse
807
+     * @throws OCSException
808
+     * @throws OCSForbiddenException
809
+     */
810
+    public function enableUser(string $userId): DataResponse {
811
+        return $this->setEnabled($userId, true);
812
+    }
813
+
814
+    /**
815
+     * @param string $userId
816
+     * @param bool $value
817
+     * @return DataResponse
818
+     * @throws OCSException
819
+     */
820
+    private function setEnabled(string $userId, bool $value): DataResponse {
821
+        $currentLoggedInUser = $this->userSession->getUser();
822
+
823
+        $targetUser = $this->userManager->get($userId);
824
+        if ($targetUser === null || $targetUser->getUID() === $currentLoggedInUser->getUID()) {
825
+            throw new OCSException('', 101);
826
+        }
827
+
828
+        // If not permitted
829
+        $subAdminManager = $this->groupManager->getSubAdmin();
830
+        if (!$this->groupManager->isAdmin($currentLoggedInUser->getUID()) && !$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)) {
831
+            throw new OCSException('', OCSController::RESPOND_UNAUTHORISED);
832
+        }
833
+
834
+        // enable/disable the user now
835
+        $targetUser->setEnabled($value);
836
+        return new DataResponse();
837
+    }
838
+
839
+    /**
840
+     * @NoAdminRequired
841
+     * @NoSubAdminRequired
842
+     *
843
+     * @param string $userId
844
+     * @return DataResponse
845
+     * @throws OCSException
846
+     */
847
+    public function getUsersGroups(string $userId): DataResponse {
848
+        $loggedInUser = $this->userSession->getUser();
849
+
850
+        $targetUser = $this->userManager->get($userId);
851
+        if ($targetUser === null) {
852
+            throw new OCSException('', OCSController::RESPOND_NOT_FOUND);
853
+        }
854
+
855
+        if ($targetUser->getUID() === $loggedInUser->getUID() || $this->groupManager->isAdmin($loggedInUser->getUID())) {
856
+            // Self lookup or admin lookup
857
+            return new DataResponse([
858
+                'groups' => $this->groupManager->getUserGroupIds($targetUser)
859
+            ]);
860
+        } else {
861
+            $subAdminManager = $this->groupManager->getSubAdmin();
862
+
863
+            // Looking up someone else
864
+            if ($subAdminManager->isUserAccessible($loggedInUser, $targetUser)) {
865
+                // Return the group that the method caller is subadmin of for the user in question
866
+                /** @var IGroup[] $getSubAdminsGroups */
867
+                $getSubAdminsGroups = $subAdminManager->getSubAdminsGroups($loggedInUser);
868
+                foreach ($getSubAdminsGroups as $key => $group) {
869
+                    $getSubAdminsGroups[$key] = $group->getGID();
870
+                }
871
+                $groups = array_intersect(
872
+                    $getSubAdminsGroups,
873
+                    $this->groupManager->getUserGroupIds($targetUser)
874
+                );
875
+                return new DataResponse(['groups' => $groups]);
876
+            } else {
877
+                // Not permitted
878
+                throw new OCSException('', OCSController::RESPOND_UNAUTHORISED);
879
+            }
880
+        }
881
+    }
882
+
883
+    /**
884
+     * @PasswordConfirmationRequired
885
+     * @NoAdminRequired
886
+     *
887
+     * @param string $userId
888
+     * @param string $groupid
889
+     * @return DataResponse
890
+     * @throws OCSException
891
+     */
892
+    public function addToGroup(string $userId, string $groupid = ''): DataResponse {
893
+        if ($groupid === '') {
894
+            throw new OCSException('', 101);
895
+        }
896
+
897
+        $group = $this->groupManager->get($groupid);
898
+        $targetUser = $this->userManager->get($userId);
899
+        if ($group === null) {
900
+            throw new OCSException('', 102);
901
+        }
902
+        if ($targetUser === null) {
903
+            throw new OCSException('', 103);
904
+        }
905
+
906
+        // If they're not an admin, check they are a subadmin of the group in question
907
+        $loggedInUser = $this->userSession->getUser();
908
+        $subAdminManager = $this->groupManager->getSubAdmin();
909
+        if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) {
910
+            throw new OCSException('', 104);
911
+        }
912
+
913
+        // Add user to group
914
+        $group->addUser($targetUser);
915
+        return new DataResponse();
916
+    }
917
+
918
+    /**
919
+     * @PasswordConfirmationRequired
920
+     * @NoAdminRequired
921
+     *
922
+     * @param string $userId
923
+     * @param string $groupid
924
+     * @return DataResponse
925
+     * @throws OCSException
926
+     */
927
+    public function removeFromGroup(string $userId, string $groupid): DataResponse {
928
+        $loggedInUser = $this->userSession->getUser();
929
+
930
+        if ($groupid === null || trim($groupid) === '') {
931
+            throw new OCSException('', 101);
932
+        }
933
+
934
+        $group = $this->groupManager->get($groupid);
935
+        if ($group === null) {
936
+            throw new OCSException('', 102);
937
+        }
938
+
939
+        $targetUser = $this->userManager->get($userId);
940
+        if ($targetUser === null) {
941
+            throw new OCSException('', 103);
942
+        }
943
+
944
+        // If they're not an admin, check they are a subadmin of the group in question
945
+        $subAdminManager = $this->groupManager->getSubAdmin();
946
+        if (!$this->groupManager->isAdmin($loggedInUser->getUID()) && !$subAdminManager->isSubAdminOfGroup($loggedInUser, $group)) {
947
+            throw new OCSException('', 104);
948
+        }
949
+
950
+        // Check they aren't removing themselves from 'admin' or their 'subadmin; group
951
+        if ($targetUser->getUID() === $loggedInUser->getUID()) {
952
+            if ($this->groupManager->isAdmin($loggedInUser->getUID())) {
953
+                if ($group->getGID() === 'admin') {
954
+                    throw new OCSException('Cannot remove yourself from the admin group', 105);
955
+                }
956
+            } else {
957
+                // Not an admin, so the user must be a subadmin of this group, but that is not allowed.
958
+                throw new OCSException('Cannot remove yourself from this group as you are a SubAdmin', 105);
959
+            }
960
+        } elseif (!$this->groupManager->isAdmin($loggedInUser->getUID())) {
961
+            /** @var IGroup[] $subAdminGroups */
962
+            $subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser);
963
+            $subAdminGroups = array_map(function (IGroup $subAdminGroup) {
964
+                return $subAdminGroup->getGID();
965
+            }, $subAdminGroups);
966
+            $userGroups = $this->groupManager->getUserGroupIds($targetUser);
967
+            $userSubAdminGroups = array_intersect($subAdminGroups, $userGroups);
968
+
969
+            if (count($userSubAdminGroups) <= 1) {
970
+                // Subadmin must not be able to remove a user from all their subadmin groups.
971
+                throw new OCSException('Not viable to remove user from the last group you are SubAdmin of', 105);
972
+            }
973
+        }
974
+
975
+        // Remove user from group
976
+        $group->removeUser($targetUser);
977
+        return new DataResponse();
978
+    }
979
+
980
+    /**
981
+     * Creates a subadmin
982
+     *
983
+     * @PasswordConfirmationRequired
984
+     *
985
+     * @param string $userId
986
+     * @param string $groupid
987
+     * @return DataResponse
988
+     * @throws OCSException
989
+     */
990
+    public function addSubAdmin(string $userId, string $groupid): DataResponse {
991
+        $group = $this->groupManager->get($groupid);
992
+        $user = $this->userManager->get($userId);
993
+
994
+        // Check if the user exists
995
+        if ($user === null) {
996
+            throw new OCSException('User does not exist', 101);
997
+        }
998
+        // Check if group exists
999
+        if ($group === null) {
1000
+            throw new OCSException('Group does not exist',  102);
1001
+        }
1002
+        // Check if trying to make subadmin of admin group
1003
+        if ($group->getGID() === 'admin') {
1004
+            throw new OCSException('Cannot create subadmins for admin group', 103);
1005
+        }
1006
+
1007
+        $subAdminManager = $this->groupManager->getSubAdmin();
1008
+
1009
+        // We cannot be subadmin twice
1010
+        if ($subAdminManager->isSubAdminOfGroup($user, $group)) {
1011
+            return new DataResponse();
1012
+        }
1013
+        // Go
1014
+        $subAdminManager->createSubAdmin($user, $group);
1015
+        return new DataResponse();
1016
+    }
1017
+
1018
+    /**
1019
+     * Removes a subadmin from a group
1020
+     *
1021
+     * @PasswordConfirmationRequired
1022
+     *
1023
+     * @param string $userId
1024
+     * @param string $groupid
1025
+     * @return DataResponse
1026
+     * @throws OCSException
1027
+     */
1028
+    public function removeSubAdmin(string $userId, string $groupid): DataResponse {
1029
+        $group = $this->groupManager->get($groupid);
1030
+        $user = $this->userManager->get($userId);
1031
+        $subAdminManager = $this->groupManager->getSubAdmin();
1032
+
1033
+        // Check if the user exists
1034
+        if ($user === null) {
1035
+            throw new OCSException('User does not exist', 101);
1036
+        }
1037
+        // Check if the group exists
1038
+        if ($group === null) {
1039
+            throw new OCSException('Group does not exist', 101);
1040
+        }
1041
+        // Check if they are a subadmin of this said group
1042
+        if (!$subAdminManager->isSubAdminOfGroup($user, $group)) {
1043
+            throw new OCSException('User is not a subadmin of this group', 102);
1044
+        }
1045
+
1046
+        // Go
1047
+        $subAdminManager->deleteSubAdmin($user, $group);
1048
+        return new DataResponse();
1049
+    }
1050
+
1051
+    /**
1052
+     * Get the groups a user is a subadmin of
1053
+     *
1054
+     * @param string $userId
1055
+     * @return DataResponse
1056
+     * @throws OCSException
1057
+     */
1058
+    public function getUserSubAdminGroups(string $userId): DataResponse {
1059
+        $groups = $this->getUserSubAdminGroupsData($userId);
1060
+        return new DataResponse($groups);
1061
+    }
1062
+
1063
+    /**
1064
+     * @NoAdminRequired
1065
+     * @PasswordConfirmationRequired
1066
+     *
1067
+     * resend welcome message
1068
+     *
1069
+     * @param string $userId
1070
+     * @return DataResponse
1071
+     * @throws OCSException
1072
+     */
1073
+    public function resendWelcomeMessage(string $userId): DataResponse {
1074
+        $currentLoggedInUser = $this->userSession->getUser();
1075
+
1076
+        $targetUser = $this->userManager->get($userId);
1077
+        if ($targetUser === null) {
1078
+            throw new OCSException('', OCSController::RESPOND_NOT_FOUND);
1079
+        }
1080
+
1081
+        // Check if admin / subadmin
1082
+        $subAdminManager = $this->groupManager->getSubAdmin();
1083
+        if (!$subAdminManager->isUserAccessible($currentLoggedInUser, $targetUser)
1084
+            && !$this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
1085
+            // No rights
1086
+            throw new OCSException('', OCSController::RESPOND_UNAUTHORISED);
1087
+        }
1088
+
1089
+        $email = $targetUser->getEMailAddress();
1090
+        if ($email === '' || $email === null) {
1091
+            throw new OCSException('Email address not available', 101);
1092
+        }
1093
+
1094
+        try {
1095
+            $emailTemplate = $this->newUserMailHelper->generateTemplate($targetUser, false);
1096
+            $this->newUserMailHelper->sendMail($targetUser, $emailTemplate);
1097
+        } catch (\Exception $e) {
1098
+            $this->logger->error("Can't send new user mail to $email",
1099
+                [
1100
+                    'app' => 'settings',
1101
+                    'exception' => $e,
1102
+                ]
1103
+            );
1104
+            throw new OCSException('Sending email failed', 102);
1105
+        }
1106
+
1107
+        return new DataResponse();
1108
+    }
1109 1109
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
 		$matches = [];
275 275
 		foreach ($userMatches as $phone => $userId) {
276 276
 			// Not using the ICloudIdManager as that would run a search for each contact to find the display name in the address book
277
-			$matches[$normalizedNumberToKey[$phone]] = $userId . '@' . $cloudUrl;
277
+			$matches[$normalizedNumberToKey[$phone]] = $userId.'@'.$cloudUrl;
278 278
 			$this->knownUserService->storeIsKnownToUser($knownTo, $userId);
279 279
 		}
280 280
 
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
 					throw new OCSException('group '.$group.' does not exist', 104);
339 339
 				}
340 340
 				if (!$isAdmin && !$subAdminManager->isSubAdminOfGroup($user, $this->groupManager->get($group))) {
341
-					throw new OCSException('insufficient privileges for group '. $group, 105);
341
+					throw new OCSException('insufficient privileges for group '.$group, 105);
342 342
 				}
343 343
 			}
344 344
 		} else {
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 				$group = $this->groupManager->get($groupid);
354 354
 				// Check if group exists
355 355
 				if ($group === null) {
356
-					throw new OCSException('Subadmin group does not exist',  102);
356
+					throw new OCSException('Subadmin group does not exist', 102);
357 357
 				}
358 358
 				// Check if trying to make subadmin of admin group
359 359
 				if ($group->getGID() === 'admin') {
@@ -394,11 +394,11 @@  discard block
 block discarded – undo
394 394
 
395 395
 		try {
396 396
 			$newUser = $this->userManager->createUser($userid, $password);
397
-			$this->logger->info('Successful addUser call with userid: ' . $userid, ['app' => 'ocs_api']);
397
+			$this->logger->info('Successful addUser call with userid: '.$userid, ['app' => 'ocs_api']);
398 398
 
399 399
 			foreach ($groups as $group) {
400 400
 				$this->groupManager->get($group)->addUser($newUser);
401
-				$this->logger->info('Added userid ' . $userid . ' to group ' . $group, ['app' => 'ocs_api']);
401
+				$this->logger->info('Added userid '.$userid.' to group '.$group, ['app' => 'ocs_api']);
402 402
 			}
403 403
 			foreach ($subadminGroups as $group) {
404 404
 				$subAdminManager->createSubAdmin($newUser, $group);
@@ -571,8 +571,8 @@  discard block
 block discarded – undo
571 571
 				$permittedFields[] = IAccountManager::PROPERTY_EMAIL;
572 572
 			}
573 573
 
574
-			$permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME . self::SCOPE_SUFFIX;
575
-			$permittedFields[] = IAccountManager::PROPERTY_EMAIL . self::SCOPE_SUFFIX;
574
+			$permittedFields[] = IAccountManager::PROPERTY_DISPLAYNAME.self::SCOPE_SUFFIX;
575
+			$permittedFields[] = IAccountManager::PROPERTY_EMAIL.self::SCOPE_SUFFIX;
576 576
 
577 577
 			$permittedFields[] = 'password';
578 578
 			if ($this->config->getSystemValue('force_language', false) === false ||
@@ -589,12 +589,12 @@  discard block
 block discarded – undo
589 589
 			$permittedFields[] = IAccountManager::PROPERTY_ADDRESS;
590 590
 			$permittedFields[] = IAccountManager::PROPERTY_WEBSITE;
591 591
 			$permittedFields[] = IAccountManager::PROPERTY_TWITTER;
592
-			$permittedFields[] = IAccountManager::PROPERTY_PHONE . self::SCOPE_SUFFIX;
593
-			$permittedFields[] = IAccountManager::PROPERTY_ADDRESS . self::SCOPE_SUFFIX;
594
-			$permittedFields[] = IAccountManager::PROPERTY_WEBSITE . self::SCOPE_SUFFIX;
595
-			$permittedFields[] = IAccountManager::PROPERTY_TWITTER . self::SCOPE_SUFFIX;
592
+			$permittedFields[] = IAccountManager::PROPERTY_PHONE.self::SCOPE_SUFFIX;
593
+			$permittedFields[] = IAccountManager::PROPERTY_ADDRESS.self::SCOPE_SUFFIX;
594
+			$permittedFields[] = IAccountManager::PROPERTY_WEBSITE.self::SCOPE_SUFFIX;
595
+			$permittedFields[] = IAccountManager::PROPERTY_TWITTER.self::SCOPE_SUFFIX;
596 596
 
597
-			$permittedFields[] = IAccountManager::PROPERTY_AVATAR . self::SCOPE_SUFFIX;
597
+			$permittedFields[] = IAccountManager::PROPERTY_AVATAR.self::SCOPE_SUFFIX;
598 598
 
599 599
 			// If admin they can edit their own quota
600 600
 			if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())) {
@@ -695,17 +695,17 @@  discard block
 block discarded – undo
695 695
 							$this->knownUserService->deleteByContactUserId($targetUser->getUID());
696 696
 						}
697 697
 					} catch (\InvalidArgumentException $e) {
698
-						throw new OCSException('Invalid ' . $e->getMessage(), 102);
698
+						throw new OCSException('Invalid '.$e->getMessage(), 102);
699 699
 					}
700 700
 				}
701 701
 				break;
702
-			case IAccountManager::PROPERTY_DISPLAYNAME . self::SCOPE_SUFFIX:
703
-			case IAccountManager::PROPERTY_EMAIL . self::SCOPE_SUFFIX:
704
-			case IAccountManager::PROPERTY_PHONE . self::SCOPE_SUFFIX:
705
-			case IAccountManager::PROPERTY_ADDRESS . self::SCOPE_SUFFIX:
706
-			case IAccountManager::PROPERTY_WEBSITE . self::SCOPE_SUFFIX:
707
-			case IAccountManager::PROPERTY_TWITTER . self::SCOPE_SUFFIX:
708
-			case IAccountManager::PROPERTY_AVATAR . self::SCOPE_SUFFIX:
702
+			case IAccountManager::PROPERTY_DISPLAYNAME.self::SCOPE_SUFFIX:
703
+			case IAccountManager::PROPERTY_EMAIL.self::SCOPE_SUFFIX:
704
+			case IAccountManager::PROPERTY_PHONE.self::SCOPE_SUFFIX:
705
+			case IAccountManager::PROPERTY_ADDRESS.self::SCOPE_SUFFIX:
706
+			case IAccountManager::PROPERTY_WEBSITE.self::SCOPE_SUFFIX:
707
+			case IAccountManager::PROPERTY_TWITTER.self::SCOPE_SUFFIX:
708
+			case IAccountManager::PROPERTY_AVATAR.self::SCOPE_SUFFIX:
709 709
 				$propertyName = substr($key, 0, strlen($key) - strlen(self::SCOPE_SUFFIX));
710 710
 				$userAccount = $this->accountManager->getUser($targetUser);
711 711
 				if ($userAccount[$propertyName]['scope'] !== $value) {
@@ -713,7 +713,7 @@  discard block
 block discarded – undo
713 713
 					try {
714 714
 						$this->accountManager->updateUser($targetUser, $userAccount, true);
715 715
 					} catch (\InvalidArgumentException $e) {
716
-						throw new OCSException('Invalid ' . $e->getMessage(), 102);
716
+						throw new OCSException('Invalid '.$e->getMessage(), 102);
717 717
 					}
718 718
 				}
719 719
 				break;
@@ -960,7 +960,7 @@  discard block
 block discarded – undo
960 960
 		} elseif (!$this->groupManager->isAdmin($loggedInUser->getUID())) {
961 961
 			/** @var IGroup[] $subAdminGroups */
962 962
 			$subAdminGroups = $subAdminManager->getSubAdminsGroups($loggedInUser);
963
-			$subAdminGroups = array_map(function (IGroup $subAdminGroup) {
963
+			$subAdminGroups = array_map(function(IGroup $subAdminGroup) {
964 964
 				return $subAdminGroup->getGID();
965 965
 			}, $subAdminGroups);
966 966
 			$userGroups = $this->groupManager->getUserGroupIds($targetUser);
@@ -997,7 +997,7 @@  discard block
 block discarded – undo
997 997
 		}
998 998
 		// Check if group exists
999 999
 		if ($group === null) {
1000
-			throw new OCSException('Group does not exist',  102);
1000
+			throw new OCSException('Group does not exist', 102);
1001 1001
 		}
1002 1002
 		// Check if trying to make subadmin of admin group
1003 1003
 		if ($group->getGID() === 'admin') {
Please login to merge, or discard this patch.
apps/provisioning_api/lib/Controller/AUserData.php 2 patches
Indentation   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -51,190 +51,190 @@
 block discarded – undo
51 51
 use OCP\User\Backend\ISetPasswordBackend;
52 52
 
53 53
 abstract class AUserData extends OCSController {
54
-	public const SCOPE_SUFFIX = 'Scope';
55
-
56
-	/** @var IUserManager */
57
-	protected $userManager;
58
-	/** @var IConfig */
59
-	protected $config;
60
-	/** @var IGroupManager|Manager */ // FIXME Requires a method that is not on the interface
61
-	protected $groupManager;
62
-	/** @var IUserSession */
63
-	protected $userSession;
64
-	/** @var AccountManager */
65
-	protected $accountManager;
66
-	/** @var IFactory */
67
-	protected $l10nFactory;
68
-
69
-	public function __construct(string $appName,
70
-								IRequest $request,
71
-								IUserManager $userManager,
72
-								IConfig $config,
73
-								IGroupManager $groupManager,
74
-								IUserSession $userSession,
75
-								AccountManager $accountManager,
76
-								IFactory $l10nFactory) {
77
-		parent::__construct($appName, $request);
78
-
79
-		$this->userManager = $userManager;
80
-		$this->config = $config;
81
-		$this->groupManager = $groupManager;
82
-		$this->userSession = $userSession;
83
-		$this->accountManager = $accountManager;
84
-		$this->l10nFactory = $l10nFactory;
85
-	}
86
-
87
-	/**
88
-	 * creates a array with all user data
89
-	 *
90
-	 * @param string $userId
91
-	 * @param bool $includeScopes
92
-	 * @return array
93
-	 * @throws NotFoundException
94
-	 * @throws OCSException
95
-	 * @throws OCSNotFoundException
96
-	 */
97
-	protected function getUserData(string $userId, bool $includeScopes = false): array {
98
-		$currentLoggedInUser = $this->userSession->getUser();
99
-
100
-		$data = [];
101
-
102
-		// Check if the target user exists
103
-		$targetUserObject = $this->userManager->get($userId);
104
-		if ($targetUserObject === null) {
105
-			throw new OCSNotFoundException('User does not exist');
106
-		}
107
-
108
-		// Should be at least Admin Or SubAdmin!
109
-		if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())
110
-			|| $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) {
111
-			$data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true') === 'true';
112
-		} else {
113
-			// Check they are looking up themselves
114
-			if ($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) {
115
-				return $data;
116
-			}
117
-		}
118
-
119
-		// Get groups data
120
-		$userAccount = $this->accountManager->getAccount($targetUserObject);
121
-		$groups = $this->groupManager->getUserGroups($targetUserObject);
122
-		$gids = [];
123
-		foreach ($groups as $group) {
124
-			$gids[] = $group->getGID();
125
-		}
126
-
127
-		try {
128
-			# might be thrown by LDAP due to handling of users disappears
129
-			# from the external source (reasons unknown to us)
130
-			# cf. https://github.com/nextcloud/server/issues/12991
131
-			$data['storageLocation'] = $targetUserObject->getHome();
132
-		} catch (NoUserException $e) {
133
-			throw new OCSNotFoundException($e->getMessage(), $e);
134
-		}
135
-
136
-		// Find the data
137
-		$data['id'] = $targetUserObject->getUID();
138
-		$data['lastLogin'] = $targetUserObject->getLastLogin() * 1000;
139
-		$data['backend'] = $targetUserObject->getBackendClassName();
140
-		$data['subadmin'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID());
141
-		$data['quota'] = $this->fillStorageInfo($targetUserObject->getUID());
142
-
143
-		if ($includeScopes) {
144
-			$data[IAccountManager::PROPERTY_AVATAR . self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_AVATAR)->getScope();
145
-		}
146
-
147
-		$data[IAccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress();
148
-		if ($includeScopes) {
149
-			$data[IAccountManager::PROPERTY_EMAIL . self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_EMAIL)->getScope();
150
-		}
151
-		$data[IAccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName();
152
-		if ($includeScopes) {
153
-			$data[IAccountManager::PROPERTY_DISPLAYNAME . self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_DISPLAYNAME)->getScope();
154
-		}
155
-
156
-		foreach ([
157
-			IAccountManager::PROPERTY_PHONE,
158
-			IAccountManager::PROPERTY_ADDRESS,
159
-			IAccountManager::PROPERTY_WEBSITE,
160
-			IAccountManager::PROPERTY_TWITTER,
161
-		] as $propertyName) {
162
-			$property = $userAccount->getProperty($propertyName);
163
-			$data[$propertyName] = $property->getValue();
164
-			if ($includeScopes) {
165
-				$data[$propertyName . self::SCOPE_SUFFIX] = $property->getScope();
166
-			}
167
-		}
168
-
169
-		$data['groups'] = $gids;
170
-		$data['language'] = $this->l10nFactory->getUserLanguage($targetUserObject);
171
-		$data['locale'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'locale');
172
-
173
-		$backend = $targetUserObject->getBackend();
174
-		$data['backendCapabilities'] = [
175
-			'setDisplayName' => $backend instanceof ISetDisplayNameBackend || $backend->implementsActions(Backend::SET_DISPLAYNAME),
176
-			'setPassword' => $backend instanceof ISetPasswordBackend || $backend->implementsActions(Backend::SET_PASSWORD),
177
-		];
178
-
179
-		return $data;
180
-	}
181
-
182
-	/**
183
-	 * Get the groups a user is a subadmin of
184
-	 *
185
-	 * @param string $userId
186
-	 * @return array
187
-	 * @throws OCSException
188
-	 */
189
-	protected function getUserSubAdminGroupsData(string $userId): array {
190
-		$user = $this->userManager->get($userId);
191
-		// Check if the user exists
192
-		if ($user === null) {
193
-			throw new OCSNotFoundException('User does not exist');
194
-		}
195
-
196
-		// Get the subadmin groups
197
-		$subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user);
198
-		$groups = [];
199
-		foreach ($subAdminGroups as $key => $group) {
200
-			$groups[] = $group->getGID();
201
-		}
202
-
203
-		return $groups;
204
-	}
205
-
206
-	/**
207
-	 * @param string $userId
208
-	 * @return array
209
-	 * @throws OCSException
210
-	 */
211
-	protected function fillStorageInfo(string $userId): array {
212
-		try {
213
-			\OC_Util::tearDownFS();
214
-			\OC_Util::setupFS($userId);
215
-			$storage = OC_Helper::getStorageInfo('/');
216
-			$data = [
217
-				'free' => $storage['free'],
218
-				'used' => $storage['used'],
219
-				'total' => $storage['total'],
220
-				'relative' => $storage['relative'],
221
-				'quota' => $storage['quota'],
222
-			];
223
-		} catch (NotFoundException $ex) {
224
-			// User fs is not setup yet
225
-			$user = $this->userManager->get($userId);
226
-			if ($user === null) {
227
-				throw new OCSException('User does not exist', 101);
228
-			}
229
-			$quota = $user->getQuota();
230
-			if ($quota !== 'none') {
231
-				$quota = OC_Helper::computerFileSize($quota);
232
-			}
233
-			$data = [
234
-				'quota' => $quota !== false ? $quota : 'none',
235
-				'used' => 0
236
-			];
237
-		}
238
-		return $data;
239
-	}
54
+    public const SCOPE_SUFFIX = 'Scope';
55
+
56
+    /** @var IUserManager */
57
+    protected $userManager;
58
+    /** @var IConfig */
59
+    protected $config;
60
+    /** @var IGroupManager|Manager */ // FIXME Requires a method that is not on the interface
61
+    protected $groupManager;
62
+    /** @var IUserSession */
63
+    protected $userSession;
64
+    /** @var AccountManager */
65
+    protected $accountManager;
66
+    /** @var IFactory */
67
+    protected $l10nFactory;
68
+
69
+    public function __construct(string $appName,
70
+                                IRequest $request,
71
+                                IUserManager $userManager,
72
+                                IConfig $config,
73
+                                IGroupManager $groupManager,
74
+                                IUserSession $userSession,
75
+                                AccountManager $accountManager,
76
+                                IFactory $l10nFactory) {
77
+        parent::__construct($appName, $request);
78
+
79
+        $this->userManager = $userManager;
80
+        $this->config = $config;
81
+        $this->groupManager = $groupManager;
82
+        $this->userSession = $userSession;
83
+        $this->accountManager = $accountManager;
84
+        $this->l10nFactory = $l10nFactory;
85
+    }
86
+
87
+    /**
88
+     * creates a array with all user data
89
+     *
90
+     * @param string $userId
91
+     * @param bool $includeScopes
92
+     * @return array
93
+     * @throws NotFoundException
94
+     * @throws OCSException
95
+     * @throws OCSNotFoundException
96
+     */
97
+    protected function getUserData(string $userId, bool $includeScopes = false): array {
98
+        $currentLoggedInUser = $this->userSession->getUser();
99
+
100
+        $data = [];
101
+
102
+        // Check if the target user exists
103
+        $targetUserObject = $this->userManager->get($userId);
104
+        if ($targetUserObject === null) {
105
+            throw new OCSNotFoundException('User does not exist');
106
+        }
107
+
108
+        // Should be at least Admin Or SubAdmin!
109
+        if ($this->groupManager->isAdmin($currentLoggedInUser->getUID())
110
+            || $this->groupManager->getSubAdmin()->isUserAccessible($currentLoggedInUser, $targetUserObject)) {
111
+            $data['enabled'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true') === 'true';
112
+        } else {
113
+            // Check they are looking up themselves
114
+            if ($currentLoggedInUser->getUID() !== $targetUserObject->getUID()) {
115
+                return $data;
116
+            }
117
+        }
118
+
119
+        // Get groups data
120
+        $userAccount = $this->accountManager->getAccount($targetUserObject);
121
+        $groups = $this->groupManager->getUserGroups($targetUserObject);
122
+        $gids = [];
123
+        foreach ($groups as $group) {
124
+            $gids[] = $group->getGID();
125
+        }
126
+
127
+        try {
128
+            # might be thrown by LDAP due to handling of users disappears
129
+            # from the external source (reasons unknown to us)
130
+            # cf. https://github.com/nextcloud/server/issues/12991
131
+            $data['storageLocation'] = $targetUserObject->getHome();
132
+        } catch (NoUserException $e) {
133
+            throw new OCSNotFoundException($e->getMessage(), $e);
134
+        }
135
+
136
+        // Find the data
137
+        $data['id'] = $targetUserObject->getUID();
138
+        $data['lastLogin'] = $targetUserObject->getLastLogin() * 1000;
139
+        $data['backend'] = $targetUserObject->getBackendClassName();
140
+        $data['subadmin'] = $this->getUserSubAdminGroupsData($targetUserObject->getUID());
141
+        $data['quota'] = $this->fillStorageInfo($targetUserObject->getUID());
142
+
143
+        if ($includeScopes) {
144
+            $data[IAccountManager::PROPERTY_AVATAR . self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_AVATAR)->getScope();
145
+        }
146
+
147
+        $data[IAccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress();
148
+        if ($includeScopes) {
149
+            $data[IAccountManager::PROPERTY_EMAIL . self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_EMAIL)->getScope();
150
+        }
151
+        $data[IAccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName();
152
+        if ($includeScopes) {
153
+            $data[IAccountManager::PROPERTY_DISPLAYNAME . self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_DISPLAYNAME)->getScope();
154
+        }
155
+
156
+        foreach ([
157
+            IAccountManager::PROPERTY_PHONE,
158
+            IAccountManager::PROPERTY_ADDRESS,
159
+            IAccountManager::PROPERTY_WEBSITE,
160
+            IAccountManager::PROPERTY_TWITTER,
161
+        ] as $propertyName) {
162
+            $property = $userAccount->getProperty($propertyName);
163
+            $data[$propertyName] = $property->getValue();
164
+            if ($includeScopes) {
165
+                $data[$propertyName . self::SCOPE_SUFFIX] = $property->getScope();
166
+            }
167
+        }
168
+
169
+        $data['groups'] = $gids;
170
+        $data['language'] = $this->l10nFactory->getUserLanguage($targetUserObject);
171
+        $data['locale'] = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'locale');
172
+
173
+        $backend = $targetUserObject->getBackend();
174
+        $data['backendCapabilities'] = [
175
+            'setDisplayName' => $backend instanceof ISetDisplayNameBackend || $backend->implementsActions(Backend::SET_DISPLAYNAME),
176
+            'setPassword' => $backend instanceof ISetPasswordBackend || $backend->implementsActions(Backend::SET_PASSWORD),
177
+        ];
178
+
179
+        return $data;
180
+    }
181
+
182
+    /**
183
+     * Get the groups a user is a subadmin of
184
+     *
185
+     * @param string $userId
186
+     * @return array
187
+     * @throws OCSException
188
+     */
189
+    protected function getUserSubAdminGroupsData(string $userId): array {
190
+        $user = $this->userManager->get($userId);
191
+        // Check if the user exists
192
+        if ($user === null) {
193
+            throw new OCSNotFoundException('User does not exist');
194
+        }
195
+
196
+        // Get the subadmin groups
197
+        $subAdminGroups = $this->groupManager->getSubAdmin()->getSubAdminsGroups($user);
198
+        $groups = [];
199
+        foreach ($subAdminGroups as $key => $group) {
200
+            $groups[] = $group->getGID();
201
+        }
202
+
203
+        return $groups;
204
+    }
205
+
206
+    /**
207
+     * @param string $userId
208
+     * @return array
209
+     * @throws OCSException
210
+     */
211
+    protected function fillStorageInfo(string $userId): array {
212
+        try {
213
+            \OC_Util::tearDownFS();
214
+            \OC_Util::setupFS($userId);
215
+            $storage = OC_Helper::getStorageInfo('/');
216
+            $data = [
217
+                'free' => $storage['free'],
218
+                'used' => $storage['used'],
219
+                'total' => $storage['total'],
220
+                'relative' => $storage['relative'],
221
+                'quota' => $storage['quota'],
222
+            ];
223
+        } catch (NotFoundException $ex) {
224
+            // User fs is not setup yet
225
+            $user = $this->userManager->get($userId);
226
+            if ($user === null) {
227
+                throw new OCSException('User does not exist', 101);
228
+            }
229
+            $quota = $user->getQuota();
230
+            if ($quota !== 'none') {
231
+                $quota = OC_Helper::computerFileSize($quota);
232
+            }
233
+            $data = [
234
+                'quota' => $quota !== false ? $quota : 'none',
235
+                'used' => 0
236
+            ];
237
+        }
238
+        return $data;
239
+    }
240 240
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -141,16 +141,16 @@  discard block
 block discarded – undo
141 141
 		$data['quota'] = $this->fillStorageInfo($targetUserObject->getUID());
142 142
 
143 143
 		if ($includeScopes) {
144
-			$data[IAccountManager::PROPERTY_AVATAR . self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_AVATAR)->getScope();
144
+			$data[IAccountManager::PROPERTY_AVATAR.self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_AVATAR)->getScope();
145 145
 		}
146 146
 
147 147
 		$data[IAccountManager::PROPERTY_EMAIL] = $targetUserObject->getEMailAddress();
148 148
 		if ($includeScopes) {
149
-			$data[IAccountManager::PROPERTY_EMAIL . self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_EMAIL)->getScope();
149
+			$data[IAccountManager::PROPERTY_EMAIL.self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_EMAIL)->getScope();
150 150
 		}
151 151
 		$data[IAccountManager::PROPERTY_DISPLAYNAME] = $targetUserObject->getDisplayName();
152 152
 		if ($includeScopes) {
153
-			$data[IAccountManager::PROPERTY_DISPLAYNAME . self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_DISPLAYNAME)->getScope();
153
+			$data[IAccountManager::PROPERTY_DISPLAYNAME.self::SCOPE_SUFFIX] = $userAccount->getProperty(IAccountManager::PROPERTY_DISPLAYNAME)->getScope();
154 154
 		}
155 155
 
156 156
 		foreach ([
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 			$property = $userAccount->getProperty($propertyName);
163 163
 			$data[$propertyName] = $property->getValue();
164 164
 			if ($includeScopes) {
165
-				$data[$propertyName . self::SCOPE_SUFFIX] = $property->getScope();
165
+				$data[$propertyName.self::SCOPE_SUFFIX] = $property->getScope();
166 166
 			}
167 167
 		}
168 168
 
Please login to merge, or discard this patch.
lib/public/Accounts/IAccountManager.php 1 patch
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -38,86 +38,86 @@
 block discarded – undo
38 38
  */
39 39
 interface IAccountManager {
40 40
 
41
-	/**
42
-	 * Contact details visible locally only
43
-	 *
44
-	 * @since 21.0.1
45
-	 */
46
-	public const SCOPE_PRIVATE = 'v2-private';
47
-
48
-	/**
49
-	 * Contact details visible locally and through public link access on local instance
50
-	 *
51
-	 * @since 21.0.1
52
-	 */
53
-	public const SCOPE_LOCAL = 'v2-local';
54
-
55
-	/**
56
-	 * Contact details visible locally, through public link access and on trusted federated servers.
57
-	 *
58
-	 * @since 21.0.1
59
-	 */
60
-	public const SCOPE_FEDERATED = 'v2-federated';
61
-
62
-	/**
63
-	 * Contact details visible locally, through public link access, on trusted federated servers
64
-	 * and published to the public lookup server.
65
-	 *
66
-	 * @since 21.0.1
67
-	 */
68
-	public const SCOPE_PUBLISHED = 'v2-published';
69
-
70
-	/**
71
-	 * Contact details only visible locally
72
-	 *
73
-	 * @deprecated 21.0.1
74
-	 */
75
-	public const VISIBILITY_PRIVATE = 'private';
76
-
77
-	/**
78
-	 * Contact details visible on trusted federated servers.
79
-	 *
80
-	 * @deprecated 21.0.1
81
-	 */
82
-	public const VISIBILITY_CONTACTS_ONLY = 'contacts';
83
-
84
-	/**
85
-	 * Contact details visible on trusted federated servers and in the public lookup server.
86
-	 *
87
-	 * @deprecated 21.0.1
88
-	 */
89
-	public const VISIBILITY_PUBLIC = 'public';
90
-
91
-	public const PROPERTY_AVATAR = 'avatar';
92
-	public const PROPERTY_DISPLAYNAME = 'displayname';
93
-	public const PROPERTY_PHONE = 'phone';
94
-	public const PROPERTY_EMAIL = 'email';
95
-	public const PROPERTY_WEBSITE = 'website';
96
-	public const PROPERTY_ADDRESS = 'address';
97
-	public const PROPERTY_TWITTER = 'twitter';
98
-
99
-	public const NOT_VERIFIED = '0';
100
-	public const VERIFICATION_IN_PROGRESS = '1';
101
-	public const VERIFIED = '2';
102
-
103
-	/**
104
-	 * Get the account data for a given user
105
-	 *
106
-	 * @since 15.0.0
107
-	 *
108
-	 * @param IUser $user
109
-	 * @return IAccount
110
-	 */
111
-	public function getAccount(IUser $user): IAccount;
112
-
113
-	/**
114
-	 * Search for users based on account data
115
-	 *
116
-	 * @param string $property
117
-	 * @param string[] $values
118
-	 * @return array
119
-	 *
120
-	 * @since 21.0.0
121
-	 */
122
-	public function searchUsers(string $property, array $values): array;
41
+    /**
42
+     * Contact details visible locally only
43
+     *
44
+     * @since 21.0.1
45
+     */
46
+    public const SCOPE_PRIVATE = 'v2-private';
47
+
48
+    /**
49
+     * Contact details visible locally and through public link access on local instance
50
+     *
51
+     * @since 21.0.1
52
+     */
53
+    public const SCOPE_LOCAL = 'v2-local';
54
+
55
+    /**
56
+     * Contact details visible locally, through public link access and on trusted federated servers.
57
+     *
58
+     * @since 21.0.1
59
+     */
60
+    public const SCOPE_FEDERATED = 'v2-federated';
61
+
62
+    /**
63
+     * Contact details visible locally, through public link access, on trusted federated servers
64
+     * and published to the public lookup server.
65
+     *
66
+     * @since 21.0.1
67
+     */
68
+    public const SCOPE_PUBLISHED = 'v2-published';
69
+
70
+    /**
71
+     * Contact details only visible locally
72
+     *
73
+     * @deprecated 21.0.1
74
+     */
75
+    public const VISIBILITY_PRIVATE = 'private';
76
+
77
+    /**
78
+     * Contact details visible on trusted federated servers.
79
+     *
80
+     * @deprecated 21.0.1
81
+     */
82
+    public const VISIBILITY_CONTACTS_ONLY = 'contacts';
83
+
84
+    /**
85
+     * Contact details visible on trusted federated servers and in the public lookup server.
86
+     *
87
+     * @deprecated 21.0.1
88
+     */
89
+    public const VISIBILITY_PUBLIC = 'public';
90
+
91
+    public const PROPERTY_AVATAR = 'avatar';
92
+    public const PROPERTY_DISPLAYNAME = 'displayname';
93
+    public const PROPERTY_PHONE = 'phone';
94
+    public const PROPERTY_EMAIL = 'email';
95
+    public const PROPERTY_WEBSITE = 'website';
96
+    public const PROPERTY_ADDRESS = 'address';
97
+    public const PROPERTY_TWITTER = 'twitter';
98
+
99
+    public const NOT_VERIFIED = '0';
100
+    public const VERIFICATION_IN_PROGRESS = '1';
101
+    public const VERIFIED = '2';
102
+
103
+    /**
104
+     * Get the account data for a given user
105
+     *
106
+     * @since 15.0.0
107
+     *
108
+     * @param IUser $user
109
+     * @return IAccount
110
+     */
111
+    public function getAccount(IUser $user): IAccount;
112
+
113
+    /**
114
+     * Search for users based on account data
115
+     *
116
+     * @param string $property
117
+     * @param string[] $values
118
+     * @return array
119
+     *
120
+     * @since 21.0.0
121
+     */
122
+    public function searchUsers(string $property, array $values): array;
123 123
 }
Please login to merge, or discard this patch.
lib/private/Avatar/PlaceholderAvatar.php 2 patches
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -47,137 +47,137 @@
 block discarded – undo
47 47
  * for faster retrieval, unlike the GuestAvatar.
48 48
  */
49 49
 class PlaceholderAvatar extends Avatar {
50
-	/** @var ISimpleFolder */
51
-	private $folder;
52
-
53
-	/** @var User */
54
-	private $user;
55
-
56
-	/**
57
-	 * UserAvatar constructor.
58
-	 *
59
-	 * @param IConfig $config The configuration
60
-	 * @param ISimpleFolder $folder The avatar files folder
61
-	 * @param IL10N $l The localization helper
62
-	 * @param User $user The user this class manages the avatar for
63
-	 * @param ILogger $logger The logger
64
-	 */
65
-	public function __construct(
66
-		ISimpleFolder $folder,
67
-		$user,
68
-		ILogger $logger) {
69
-		parent::__construct($logger);
70
-
71
-		$this->folder = $folder;
72
-		$this->user = $user;
73
-	}
74
-
75
-	/**
76
-	 * Check if an avatar exists for the user
77
-	 *
78
-	 * @return bool
79
-	 */
80
-	public function exists() {
81
-		return true;
82
-	}
83
-
84
-	/**
85
-	 * Sets the users avatar.
86
-	 *
87
-	 * @param IImage|resource|string $data An image object, imagedata or path to set a new avatar
88
-	 * @throws \Exception if the provided file is not a jpg or png image
89
-	 * @throws \Exception if the provided image is not valid
90
-	 * @throws NotSquareException if the image is not square
91
-	 * @return void
92
-	 */
93
-	public function set($data) {
94
-		// unimplemented for placeholder avatars
95
-	}
96
-
97
-	/**
98
-	 * Removes the users avatar.
99
-	 */
100
-	public function remove(bool $silent = false) {
101
-		$avatars = $this->folder->getDirectoryListing();
102
-
103
-		foreach ($avatars as $avatar) {
104
-			$avatar->delete();
105
-		}
106
-	}
107
-
108
-	/**
109
-	 * Returns the avatar for an user.
110
-	 *
111
-	 * If there is no avatar file yet, one is generated.
112
-	 *
113
-	 * @param int $size
114
-	 * @return ISimpleFile
115
-	 * @throws NotFoundException
116
-	 * @throws \OCP\Files\NotPermittedException
117
-	 * @throws \OCP\PreConditionNotMetException
118
-	 */
119
-	public function getFile($size) {
120
-		$size = (int) $size;
121
-
122
-		$ext = 'png';
123
-
124
-		if ($size === -1) {
125
-			$path = 'avatar-placeholder.' . $ext;
126
-		} else {
127
-			$path = 'avatar-placeholder.' . $size . '.' . $ext;
128
-		}
129
-
130
-		try {
131
-			$file = $this->folder->getFile($path);
132
-		} catch (NotFoundException $e) {
133
-			if ($size <= 0) {
134
-				throw new NotFoundException;
135
-			}
136
-
137
-			if (!$data = $this->generateAvatarFromSvg($size)) {
138
-				$data = $this->generateAvatar($this->getDisplayName(), $size);
139
-			}
140
-
141
-			try {
142
-				$file = $this->folder->newFile($path);
143
-				$file->putContent($data);
144
-			} catch (NotPermittedException $e) {
145
-				$this->logger->error('Failed to save avatar placeholder for ' . $this->user->getUID());
146
-				throw new NotFoundException();
147
-			}
148
-		}
149
-
150
-		return $file;
151
-	}
152
-
153
-	/**
154
-	 * Returns the user display name.
155
-	 *
156
-	 * @return string
157
-	 */
158
-	public function getDisplayName(): string {
159
-		return $this->user->getDisplayName();
160
-	}
161
-
162
-	/**
163
-	 * Handles user changes.
164
-	 *
165
-	 * @param string $feature The changed feature
166
-	 * @param mixed $oldValue The previous value
167
-	 * @param mixed $newValue The new value
168
-	 * @throws NotPermittedException
169
-	 * @throws \OCP\PreConditionNotMetException
170
-	 */
171
-	public function userChanged($feature, $oldValue, $newValue) {
172
-		$this->remove();
173
-	}
174
-
175
-	/**
176
-	 * Check if the avatar of a user is a custom uploaded one
177
-	 *
178
-	 * @return bool
179
-	 */
180
-	public function isCustomAvatar(): bool {
181
-		return false;
182
-	}
50
+    /** @var ISimpleFolder */
51
+    private $folder;
52
+
53
+    /** @var User */
54
+    private $user;
55
+
56
+    /**
57
+     * UserAvatar constructor.
58
+     *
59
+     * @param IConfig $config The configuration
60
+     * @param ISimpleFolder $folder The avatar files folder
61
+     * @param IL10N $l The localization helper
62
+     * @param User $user The user this class manages the avatar for
63
+     * @param ILogger $logger The logger
64
+     */
65
+    public function __construct(
66
+        ISimpleFolder $folder,
67
+        $user,
68
+        ILogger $logger) {
69
+        parent::__construct($logger);
70
+
71
+        $this->folder = $folder;
72
+        $this->user = $user;
73
+    }
74
+
75
+    /**
76
+     * Check if an avatar exists for the user
77
+     *
78
+     * @return bool
79
+     */
80
+    public function exists() {
81
+        return true;
82
+    }
83
+
84
+    /**
85
+     * Sets the users avatar.
86
+     *
87
+     * @param IImage|resource|string $data An image object, imagedata or path to set a new avatar
88
+     * @throws \Exception if the provided file is not a jpg or png image
89
+     * @throws \Exception if the provided image is not valid
90
+     * @throws NotSquareException if the image is not square
91
+     * @return void
92
+     */
93
+    public function set($data) {
94
+        // unimplemented for placeholder avatars
95
+    }
96
+
97
+    /**
98
+     * Removes the users avatar.
99
+     */
100
+    public function remove(bool $silent = false) {
101
+        $avatars = $this->folder->getDirectoryListing();
102
+
103
+        foreach ($avatars as $avatar) {
104
+            $avatar->delete();
105
+        }
106
+    }
107
+
108
+    /**
109
+     * Returns the avatar for an user.
110
+     *
111
+     * If there is no avatar file yet, one is generated.
112
+     *
113
+     * @param int $size
114
+     * @return ISimpleFile
115
+     * @throws NotFoundException
116
+     * @throws \OCP\Files\NotPermittedException
117
+     * @throws \OCP\PreConditionNotMetException
118
+     */
119
+    public function getFile($size) {
120
+        $size = (int) $size;
121
+
122
+        $ext = 'png';
123
+
124
+        if ($size === -1) {
125
+            $path = 'avatar-placeholder.' . $ext;
126
+        } else {
127
+            $path = 'avatar-placeholder.' . $size . '.' . $ext;
128
+        }
129
+
130
+        try {
131
+            $file = $this->folder->getFile($path);
132
+        } catch (NotFoundException $e) {
133
+            if ($size <= 0) {
134
+                throw new NotFoundException;
135
+            }
136
+
137
+            if (!$data = $this->generateAvatarFromSvg($size)) {
138
+                $data = $this->generateAvatar($this->getDisplayName(), $size);
139
+            }
140
+
141
+            try {
142
+                $file = $this->folder->newFile($path);
143
+                $file->putContent($data);
144
+            } catch (NotPermittedException $e) {
145
+                $this->logger->error('Failed to save avatar placeholder for ' . $this->user->getUID());
146
+                throw new NotFoundException();
147
+            }
148
+        }
149
+
150
+        return $file;
151
+    }
152
+
153
+    /**
154
+     * Returns the user display name.
155
+     *
156
+     * @return string
157
+     */
158
+    public function getDisplayName(): string {
159
+        return $this->user->getDisplayName();
160
+    }
161
+
162
+    /**
163
+     * Handles user changes.
164
+     *
165
+     * @param string $feature The changed feature
166
+     * @param mixed $oldValue The previous value
167
+     * @param mixed $newValue The new value
168
+     * @throws NotPermittedException
169
+     * @throws \OCP\PreConditionNotMetException
170
+     */
171
+    public function userChanged($feature, $oldValue, $newValue) {
172
+        $this->remove();
173
+    }
174
+
175
+    /**
176
+     * Check if the avatar of a user is a custom uploaded one
177
+     *
178
+     * @return bool
179
+     */
180
+    public function isCustomAvatar(): bool {
181
+        return false;
182
+    }
183 183
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -122,9 +122,9 @@  discard block
 block discarded – undo
122 122
 		$ext = 'png';
123 123
 
124 124
 		if ($size === -1) {
125
-			$path = 'avatar-placeholder.' . $ext;
125
+			$path = 'avatar-placeholder.'.$ext;
126 126
 		} else {
127
-			$path = 'avatar-placeholder.' . $size . '.' . $ext;
127
+			$path = 'avatar-placeholder.'.$size.'.'.$ext;
128 128
 		}
129 129
 
130 130
 		try {
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 				$file = $this->folder->newFile($path);
143 143
 				$file->putContent($data);
144 144
 			} catch (NotPermittedException $e) {
145
-				$this->logger->error('Failed to save avatar placeholder for ' . $this->user->getUID());
145
+				$this->logger->error('Failed to save avatar placeholder for '.$this->user->getUID());
146 146
 				throw new NotFoundException();
147 147
 			}
148 148
 		}
Please login to merge, or discard this patch.
lib/private/Avatar/AvatarManager.php 1 patch
Indentation   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -53,145 +53,145 @@
 block discarded – undo
53 53
  */
54 54
 class AvatarManager implements IAvatarManager {
55 55
 
56
-	/** @var IUserSession */
57
-	private $userSession;
58
-
59
-	/** @var Manager */
60
-	private $userManager;
61
-
62
-	/** @var IAppData */
63
-	private $appData;
64
-
65
-	/** @var IL10N */
66
-	private $l;
67
-
68
-	/** @var ILogger  */
69
-	private $logger;
70
-
71
-	/** @var IConfig */
72
-	private $config;
73
-
74
-	/** @var IAccountManager */
75
-	private $accountManager;
76
-
77
-	/** @var KnownUserService */
78
-	private $knownUserService;
79
-
80
-	/**
81
-	 * AvatarManager constructor.
82
-	 *
83
-	 * @param Manager $userManager
84
-	 * @param IAppData $appData
85
-	 * @param IL10N $l
86
-	 * @param ILogger $logger
87
-	 * @param IConfig $config
88
-	 * @param IUserSession $userSession
89
-	 */
90
-	public function __construct(
91
-			IUserSession $userSession,
92
-			Manager $userManager,
93
-			IAppData $appData,
94
-			IL10N $l,
95
-			ILogger $logger,
96
-			IConfig $config,
97
-			IAccountManager $accountManager,
98
-			KnownUserService $knownUserService
99
-	) {
100
-		$this->userSession = $userSession;
101
-		$this->userManager = $userManager;
102
-		$this->appData = $appData;
103
-		$this->l = $l;
104
-		$this->logger = $logger;
105
-		$this->config = $config;
106
-		$this->accountManager = $accountManager;
107
-		$this->knownUserService = $knownUserService;
108
-	}
109
-
110
-	/**
111
-	 * return a user specific instance of \OCP\IAvatar
112
-	 * @see \OCP\IAvatar
113
-	 * @param string $userId the ownCloud user id
114
-	 * @return \OCP\IAvatar
115
-	 * @throws \Exception In case the username is potentially dangerous
116
-	 * @throws NotFoundException In case there is no user folder yet
117
-	 */
118
-	public function getAvatar(string $userId) : IAvatar {
119
-		$user = $this->userManager->get($userId);
120
-		if ($user === null) {
121
-			throw new \Exception('user does not exist');
122
-		}
123
-
124
-		// sanitize userID - fixes casing issue (needed for the filesystem stuff that is done below)
125
-		$userId = $user->getUID();
126
-
127
-		$requestingUser = null;
128
-		if ($this->userSession !== null) {
129
-			$requestingUser = $this->userSession->getUser();
130
-		}
131
-
132
-		try {
133
-			$folder = $this->appData->getFolder($userId);
134
-		} catch (NotFoundException $e) {
135
-			$folder = $this->appData->newFolder($userId);
136
-		}
137
-
138
-		$account = $this->accountManager->getAccount($user);
139
-		$avatarProperties = $account->getProperty(IAccountManager::PROPERTY_AVATAR);
140
-		$avatarScope = $avatarProperties->getScope();
141
-
142
-		if (
143
-			// v2-private scope hides the avatar from public access and from unknown users
144
-			$avatarScope === IAccountManager::SCOPE_PRIVATE
145
-			&& (
146
-				// accessing from public link
147
-				$requestingUser === null
148
-				// logged in, but unknown to user
149
-				|| !$this->knownUserService->isKnownToUser($requestingUser->getUID(), $userId)
150
-			)) {
151
-			// use a placeholder avatar which caches the generated images
152
-			return new PlaceholderAvatar($folder, $user, $this->logger);
153
-		}
154
-
155
-		return new UserAvatar($folder, $this->l, $user, $this->logger, $this->config);
156
-	}
157
-
158
-	/**
159
-	 * Clear generated avatars
160
-	 */
161
-	public function clearCachedAvatars() {
162
-		$users = $this->config->getUsersForUserValue('avatar', 'generated', 'true');
163
-		foreach ($users as $userId) {
164
-			try {
165
-				$folder = $this->appData->getFolder($userId);
166
-				$folder->delete();
167
-			} catch (NotFoundException $e) {
168
-				$this->logger->debug("No cache for the user $userId. Ignoring...");
169
-			}
170
-			$this->config->setUserValue($userId, 'avatar', 'generated', 'false');
171
-		}
172
-	}
173
-
174
-	public function deleteUserAvatar(string $userId): void {
175
-		try {
176
-			$folder = $this->appData->getFolder($userId);
177
-			$folder->delete();
178
-		} catch (NotFoundException $e) {
179
-			$this->logger->debug("No cache for the user $userId. Ignoring avatar deletion");
180
-		} catch (NotPermittedException $e) {
181
-			$this->logger->error("Unable to delete user avatars for $userId. gnoring avatar deletion");
182
-		} catch (NoUserException $e) {
183
-			$this->logger->debug("User $userId not found. gnoring avatar deletion");
184
-		}
185
-		$this->config->deleteUserValue($userId, 'avatar', 'generated');
186
-	}
187
-
188
-	/**
189
-	 * Returns a GuestAvatar.
190
-	 *
191
-	 * @param string $name The guest name, e.g. "Albert".
192
-	 * @return IAvatar
193
-	 */
194
-	public function getGuestAvatar(string $name): IAvatar {
195
-		return new GuestAvatar($name, $this->logger);
196
-	}
56
+    /** @var IUserSession */
57
+    private $userSession;
58
+
59
+    /** @var Manager */
60
+    private $userManager;
61
+
62
+    /** @var IAppData */
63
+    private $appData;
64
+
65
+    /** @var IL10N */
66
+    private $l;
67
+
68
+    /** @var ILogger  */
69
+    private $logger;
70
+
71
+    /** @var IConfig */
72
+    private $config;
73
+
74
+    /** @var IAccountManager */
75
+    private $accountManager;
76
+
77
+    /** @var KnownUserService */
78
+    private $knownUserService;
79
+
80
+    /**
81
+     * AvatarManager constructor.
82
+     *
83
+     * @param Manager $userManager
84
+     * @param IAppData $appData
85
+     * @param IL10N $l
86
+     * @param ILogger $logger
87
+     * @param IConfig $config
88
+     * @param IUserSession $userSession
89
+     */
90
+    public function __construct(
91
+            IUserSession $userSession,
92
+            Manager $userManager,
93
+            IAppData $appData,
94
+            IL10N $l,
95
+            ILogger $logger,
96
+            IConfig $config,
97
+            IAccountManager $accountManager,
98
+            KnownUserService $knownUserService
99
+    ) {
100
+        $this->userSession = $userSession;
101
+        $this->userManager = $userManager;
102
+        $this->appData = $appData;
103
+        $this->l = $l;
104
+        $this->logger = $logger;
105
+        $this->config = $config;
106
+        $this->accountManager = $accountManager;
107
+        $this->knownUserService = $knownUserService;
108
+    }
109
+
110
+    /**
111
+     * return a user specific instance of \OCP\IAvatar
112
+     * @see \OCP\IAvatar
113
+     * @param string $userId the ownCloud user id
114
+     * @return \OCP\IAvatar
115
+     * @throws \Exception In case the username is potentially dangerous
116
+     * @throws NotFoundException In case there is no user folder yet
117
+     */
118
+    public function getAvatar(string $userId) : IAvatar {
119
+        $user = $this->userManager->get($userId);
120
+        if ($user === null) {
121
+            throw new \Exception('user does not exist');
122
+        }
123
+
124
+        // sanitize userID - fixes casing issue (needed for the filesystem stuff that is done below)
125
+        $userId = $user->getUID();
126
+
127
+        $requestingUser = null;
128
+        if ($this->userSession !== null) {
129
+            $requestingUser = $this->userSession->getUser();
130
+        }
131
+
132
+        try {
133
+            $folder = $this->appData->getFolder($userId);
134
+        } catch (NotFoundException $e) {
135
+            $folder = $this->appData->newFolder($userId);
136
+        }
137
+
138
+        $account = $this->accountManager->getAccount($user);
139
+        $avatarProperties = $account->getProperty(IAccountManager::PROPERTY_AVATAR);
140
+        $avatarScope = $avatarProperties->getScope();
141
+
142
+        if (
143
+            // v2-private scope hides the avatar from public access and from unknown users
144
+            $avatarScope === IAccountManager::SCOPE_PRIVATE
145
+            && (
146
+                // accessing from public link
147
+                $requestingUser === null
148
+                // logged in, but unknown to user
149
+                || !$this->knownUserService->isKnownToUser($requestingUser->getUID(), $userId)
150
+            )) {
151
+            // use a placeholder avatar which caches the generated images
152
+            return new PlaceholderAvatar($folder, $user, $this->logger);
153
+        }
154
+
155
+        return new UserAvatar($folder, $this->l, $user, $this->logger, $this->config);
156
+    }
157
+
158
+    /**
159
+     * Clear generated avatars
160
+     */
161
+    public function clearCachedAvatars() {
162
+        $users = $this->config->getUsersForUserValue('avatar', 'generated', 'true');
163
+        foreach ($users as $userId) {
164
+            try {
165
+                $folder = $this->appData->getFolder($userId);
166
+                $folder->delete();
167
+            } catch (NotFoundException $e) {
168
+                $this->logger->debug("No cache for the user $userId. Ignoring...");
169
+            }
170
+            $this->config->setUserValue($userId, 'avatar', 'generated', 'false');
171
+        }
172
+    }
173
+
174
+    public function deleteUserAvatar(string $userId): void {
175
+        try {
176
+            $folder = $this->appData->getFolder($userId);
177
+            $folder->delete();
178
+        } catch (NotFoundException $e) {
179
+            $this->logger->debug("No cache for the user $userId. Ignoring avatar deletion");
180
+        } catch (NotPermittedException $e) {
181
+            $this->logger->error("Unable to delete user avatars for $userId. gnoring avatar deletion");
182
+        } catch (NoUserException $e) {
183
+            $this->logger->debug("User $userId not found. gnoring avatar deletion");
184
+        }
185
+        $this->config->deleteUserValue($userId, 'avatar', 'generated');
186
+    }
187
+
188
+    /**
189
+     * Returns a GuestAvatar.
190
+     *
191
+     * @param string $name The guest name, e.g. "Albert".
192
+     * @return IAvatar
193
+     */
194
+    public function getGuestAvatar(string $name): IAvatar {
195
+        return new GuestAvatar($name, $this->logger);
196
+    }
197 197
 }
Please login to merge, or discard this patch.
lib/private/Avatar/UserAvatar.php 1 patch
Indentation   +290 added lines, -290 removed lines patch added patch discarded remove patch
@@ -45,294 +45,294 @@
 block discarded – undo
45 45
  * This class represents a registered user's avatar.
46 46
  */
47 47
 class UserAvatar extends Avatar {
48
-	/** @var IConfig */
49
-	private $config;
50
-
51
-	/** @var ISimpleFolder */
52
-	private $folder;
53
-
54
-	/** @var IL10N */
55
-	private $l;
56
-
57
-	/** @var User */
58
-	private $user;
59
-
60
-	/**
61
-	 * UserAvatar constructor.
62
-	 *
63
-	 * @param IConfig $config The configuration
64
-	 * @param ISimpleFolder $folder The avatar files folder
65
-	 * @param IL10N $l The localization helper
66
-	 * @param User $user The user this class manages the avatar for
67
-	 * @param ILogger $logger The logger
68
-	 */
69
-	public function __construct(
70
-		ISimpleFolder $folder,
71
-		IL10N $l,
72
-		$user,
73
-		ILogger $logger,
74
-		IConfig $config) {
75
-		parent::__construct($logger);
76
-		$this->folder = $folder;
77
-		$this->l = $l;
78
-		$this->user = $user;
79
-		$this->config = $config;
80
-	}
81
-
82
-	/**
83
-	 * Check if an avatar exists for the user
84
-	 *
85
-	 * @return bool
86
-	 */
87
-	public function exists() {
88
-		return $this->folder->fileExists('avatar.jpg') || $this->folder->fileExists('avatar.png');
89
-	}
90
-
91
-	/**
92
-	 * Sets the users avatar.
93
-	 *
94
-	 * @param IImage|resource|string $data An image object, imagedata or path to set a new avatar
95
-	 * @throws \Exception if the provided file is not a jpg or png image
96
-	 * @throws \Exception if the provided image is not valid
97
-	 * @throws NotSquareException if the image is not square
98
-	 * @return void
99
-	 */
100
-	public function set($data) {
101
-		$img = $this->getAvatarImage($data);
102
-		$data = $img->data();
103
-
104
-		$this->validateAvatar($img);
105
-
106
-		$this->remove(true);
107
-		$type = $this->getAvatarImageType($img);
108
-		$file = $this->folder->newFile('avatar.' . $type);
109
-		$file->putContent($data);
110
-
111
-		try {
112
-			$generated = $this->folder->getFile('generated');
113
-			$generated->delete();
114
-		} catch (NotFoundException $e) {
115
-			//
116
-		}
117
-
118
-		$this->config->setUserValue($this->user->getUID(), 'avatar', 'generated', 'false');
119
-		$this->user->triggerChange('avatar', $file);
120
-	}
121
-
122
-	/**
123
-	 * Returns an image from several sources.
124
-	 *
125
-	 * @param IImage|resource|string $data An image object, imagedata or path to the avatar
126
-	 * @return IImage
127
-	 */
128
-	private function getAvatarImage($data) {
129
-		if ($data instanceof IImage) {
130
-			return $data;
131
-		}
132
-
133
-		$img = new OC_Image();
134
-		if (is_resource($data) && get_resource_type($data) === 'gd') {
135
-			$img->setResource($data);
136
-		} elseif (is_resource($data)) {
137
-			$img->loadFromFileHandle($data);
138
-		} else {
139
-			try {
140
-				// detect if it is a path or maybe the images as string
141
-				$result = @realpath($data);
142
-				if ($result === false || $result === null) {
143
-					$img->loadFromData($data);
144
-				} else {
145
-					$img->loadFromFile($data);
146
-				}
147
-			} catch (\Error $e) {
148
-				$img->loadFromData($data);
149
-			}
150
-		}
151
-
152
-		return $img;
153
-	}
154
-
155
-	/**
156
-	 * Returns the avatar image type.
157
-	 *
158
-	 * @param IImage $avatar
159
-	 * @return string
160
-	 */
161
-	private function getAvatarImageType(IImage $avatar) {
162
-		$type = substr($avatar->mimeType(), -3);
163
-		if ($type === 'peg') {
164
-			$type = 'jpg';
165
-		}
166
-		return $type;
167
-	}
168
-
169
-	/**
170
-	 * Validates an avatar image:
171
-	 * - must be "png" or "jpg"
172
-	 * - must be "valid"
173
-	 * - must be in square format
174
-	 *
175
-	 * @param IImage $avatar The avatar to validate
176
-	 * @throws \Exception if the provided file is not a jpg or png image
177
-	 * @throws \Exception if the provided image is not valid
178
-	 * @throws NotSquareException if the image is not square
179
-	 */
180
-	private function validateAvatar(IImage $avatar) {
181
-		$type = $this->getAvatarImageType($avatar);
182
-
183
-		if ($type !== 'jpg' && $type !== 'png') {
184
-			throw new \Exception($this->l->t('Unknown filetype'));
185
-		}
186
-
187
-		if (!$avatar->valid()) {
188
-			throw new \Exception($this->l->t('Invalid image'));
189
-		}
190
-
191
-		if (!($avatar->height() === $avatar->width())) {
192
-			throw new NotSquareException($this->l->t('Avatar image is not square'));
193
-		}
194
-	}
195
-
196
-	/**
197
-	 * Removes the users avatar.
198
-	 * @return void
199
-	 * @throws \OCP\Files\NotPermittedException
200
-	 * @throws \OCP\PreConditionNotMetException
201
-	 */
202
-	public function remove(bool $silent = false) {
203
-		$avatars = $this->folder->getDirectoryListing();
204
-
205
-		$this->config->setUserValue($this->user->getUID(), 'avatar', 'version',
206
-			(int) $this->config->getUserValue($this->user->getUID(), 'avatar', 'version', 0) + 1);
207
-
208
-		foreach ($avatars as $avatar) {
209
-			$avatar->delete();
210
-		}
211
-		$this->config->setUserValue($this->user->getUID(), 'avatar', 'generated', 'true');
212
-		if (!$silent) {
213
-			$this->user->triggerChange('avatar', '');
214
-		}
215
-	}
216
-
217
-	/**
218
-	 * Get the extension of the avatar. If there is no avatar throw Exception
219
-	 *
220
-	 * @return string
221
-	 * @throws NotFoundException
222
-	 */
223
-	private function getExtension() {
224
-		if ($this->folder->fileExists('avatar.jpg')) {
225
-			return 'jpg';
226
-		} elseif ($this->folder->fileExists('avatar.png')) {
227
-			return 'png';
228
-		}
229
-		throw new NotFoundException;
230
-	}
231
-
232
-	/**
233
-	 * Returns the avatar for an user.
234
-	 *
235
-	 * If there is no avatar file yet, one is generated.
236
-	 *
237
-	 * @param int $size
238
-	 * @return ISimpleFile
239
-	 * @throws NotFoundException
240
-	 * @throws \OCP\Files\NotPermittedException
241
-	 * @throws \OCP\PreConditionNotMetException
242
-	 */
243
-	public function getFile($size) {
244
-		$size = (int) $size;
245
-
246
-		try {
247
-			$ext = $this->getExtension();
248
-		} catch (NotFoundException $e) {
249
-			if (!$data = $this->generateAvatarFromSvg(1024)) {
250
-				$data = $this->generateAvatar($this->getDisplayName(), 1024);
251
-			}
252
-			$avatar = $this->folder->newFile('avatar.png');
253
-			$avatar->putContent($data);
254
-			$ext = 'png';
255
-
256
-			$this->folder->newFile('generated', '');
257
-			$this->config->setUserValue($this->user->getUID(), 'avatar', 'generated', 'true');
258
-		}
259
-
260
-		if ($size === -1) {
261
-			$path = 'avatar.' . $ext;
262
-		} else {
263
-			$path = 'avatar.' . $size . '.' . $ext;
264
-		}
265
-
266
-		try {
267
-			$file = $this->folder->getFile($path);
268
-		} catch (NotFoundException $e) {
269
-			if ($size <= 0) {
270
-				throw new NotFoundException;
271
-			}
272
-
273
-			// TODO: rework to integrate with the PlaceholderAvatar in a compatible way
274
-			if ($this->folder->fileExists('generated')) {
275
-				if (!$data = $this->generateAvatarFromSvg($size)) {
276
-					$data = $this->generateAvatar($this->getDisplayName(), $size);
277
-				}
278
-			} else {
279
-				$avatar = new OC_Image();
280
-				$file = $this->folder->getFile('avatar.' . $ext);
281
-				$avatar->loadFromData($file->getContent());
282
-				$avatar->resize($size);
283
-				$data = $avatar->data();
284
-			}
285
-
286
-			try {
287
-				$file = $this->folder->newFile($path);
288
-				$file->putContent($data);
289
-			} catch (NotPermittedException $e) {
290
-				$this->logger->error('Failed to save avatar for ' . $this->user->getUID());
291
-				throw new NotFoundException();
292
-			}
293
-		}
294
-
295
-		if ($this->config->getUserValue($this->user->getUID(), 'avatar', 'generated', null) === null) {
296
-			$generated = $this->folder->fileExists('generated') ? 'true' : 'false';
297
-			$this->config->setUserValue($this->user->getUID(), 'avatar', 'generated', $generated);
298
-		}
299
-
300
-		return $file;
301
-	}
302
-
303
-	/**
304
-	 * Returns the user display name.
305
-	 *
306
-	 * @return string
307
-	 */
308
-	public function getDisplayName(): string {
309
-		return $this->user->getDisplayName();
310
-	}
311
-
312
-	/**
313
-	 * Handles user changes.
314
-	 *
315
-	 * @param string $feature The changed feature
316
-	 * @param mixed $oldValue The previous value
317
-	 * @param mixed $newValue The new value
318
-	 * @throws NotPermittedException
319
-	 * @throws \OCP\PreConditionNotMetException
320
-	 */
321
-	public function userChanged($feature, $oldValue, $newValue) {
322
-		// If the avatar is not generated (so an uploaded image) we skip this
323
-		if (!$this->folder->fileExists('generated')) {
324
-			return;
325
-		}
326
-
327
-		$this->remove();
328
-	}
329
-
330
-	/**
331
-	 * Check if the avatar of a user is a custom uploaded one
332
-	 *
333
-	 * @return bool
334
-	 */
335
-	public function isCustomAvatar(): bool {
336
-		return $this->config->getUserValue($this->user->getUID(), 'avatar', 'generated', 'false') !== 'true';
337
-	}
48
+    /** @var IConfig */
49
+    private $config;
50
+
51
+    /** @var ISimpleFolder */
52
+    private $folder;
53
+
54
+    /** @var IL10N */
55
+    private $l;
56
+
57
+    /** @var User */
58
+    private $user;
59
+
60
+    /**
61
+     * UserAvatar constructor.
62
+     *
63
+     * @param IConfig $config The configuration
64
+     * @param ISimpleFolder $folder The avatar files folder
65
+     * @param IL10N $l The localization helper
66
+     * @param User $user The user this class manages the avatar for
67
+     * @param ILogger $logger The logger
68
+     */
69
+    public function __construct(
70
+        ISimpleFolder $folder,
71
+        IL10N $l,
72
+        $user,
73
+        ILogger $logger,
74
+        IConfig $config) {
75
+        parent::__construct($logger);
76
+        $this->folder = $folder;
77
+        $this->l = $l;
78
+        $this->user = $user;
79
+        $this->config = $config;
80
+    }
81
+
82
+    /**
83
+     * Check if an avatar exists for the user
84
+     *
85
+     * @return bool
86
+     */
87
+    public function exists() {
88
+        return $this->folder->fileExists('avatar.jpg') || $this->folder->fileExists('avatar.png');
89
+    }
90
+
91
+    /**
92
+     * Sets the users avatar.
93
+     *
94
+     * @param IImage|resource|string $data An image object, imagedata or path to set a new avatar
95
+     * @throws \Exception if the provided file is not a jpg or png image
96
+     * @throws \Exception if the provided image is not valid
97
+     * @throws NotSquareException if the image is not square
98
+     * @return void
99
+     */
100
+    public function set($data) {
101
+        $img = $this->getAvatarImage($data);
102
+        $data = $img->data();
103
+
104
+        $this->validateAvatar($img);
105
+
106
+        $this->remove(true);
107
+        $type = $this->getAvatarImageType($img);
108
+        $file = $this->folder->newFile('avatar.' . $type);
109
+        $file->putContent($data);
110
+
111
+        try {
112
+            $generated = $this->folder->getFile('generated');
113
+            $generated->delete();
114
+        } catch (NotFoundException $e) {
115
+            //
116
+        }
117
+
118
+        $this->config->setUserValue($this->user->getUID(), 'avatar', 'generated', 'false');
119
+        $this->user->triggerChange('avatar', $file);
120
+    }
121
+
122
+    /**
123
+     * Returns an image from several sources.
124
+     *
125
+     * @param IImage|resource|string $data An image object, imagedata or path to the avatar
126
+     * @return IImage
127
+     */
128
+    private function getAvatarImage($data) {
129
+        if ($data instanceof IImage) {
130
+            return $data;
131
+        }
132
+
133
+        $img = new OC_Image();
134
+        if (is_resource($data) && get_resource_type($data) === 'gd') {
135
+            $img->setResource($data);
136
+        } elseif (is_resource($data)) {
137
+            $img->loadFromFileHandle($data);
138
+        } else {
139
+            try {
140
+                // detect if it is a path or maybe the images as string
141
+                $result = @realpath($data);
142
+                if ($result === false || $result === null) {
143
+                    $img->loadFromData($data);
144
+                } else {
145
+                    $img->loadFromFile($data);
146
+                }
147
+            } catch (\Error $e) {
148
+                $img->loadFromData($data);
149
+            }
150
+        }
151
+
152
+        return $img;
153
+    }
154
+
155
+    /**
156
+     * Returns the avatar image type.
157
+     *
158
+     * @param IImage $avatar
159
+     * @return string
160
+     */
161
+    private function getAvatarImageType(IImage $avatar) {
162
+        $type = substr($avatar->mimeType(), -3);
163
+        if ($type === 'peg') {
164
+            $type = 'jpg';
165
+        }
166
+        return $type;
167
+    }
168
+
169
+    /**
170
+     * Validates an avatar image:
171
+     * - must be "png" or "jpg"
172
+     * - must be "valid"
173
+     * - must be in square format
174
+     *
175
+     * @param IImage $avatar The avatar to validate
176
+     * @throws \Exception if the provided file is not a jpg or png image
177
+     * @throws \Exception if the provided image is not valid
178
+     * @throws NotSquareException if the image is not square
179
+     */
180
+    private function validateAvatar(IImage $avatar) {
181
+        $type = $this->getAvatarImageType($avatar);
182
+
183
+        if ($type !== 'jpg' && $type !== 'png') {
184
+            throw new \Exception($this->l->t('Unknown filetype'));
185
+        }
186
+
187
+        if (!$avatar->valid()) {
188
+            throw new \Exception($this->l->t('Invalid image'));
189
+        }
190
+
191
+        if (!($avatar->height() === $avatar->width())) {
192
+            throw new NotSquareException($this->l->t('Avatar image is not square'));
193
+        }
194
+    }
195
+
196
+    /**
197
+     * Removes the users avatar.
198
+     * @return void
199
+     * @throws \OCP\Files\NotPermittedException
200
+     * @throws \OCP\PreConditionNotMetException
201
+     */
202
+    public function remove(bool $silent = false) {
203
+        $avatars = $this->folder->getDirectoryListing();
204
+
205
+        $this->config->setUserValue($this->user->getUID(), 'avatar', 'version',
206
+            (int) $this->config->getUserValue($this->user->getUID(), 'avatar', 'version', 0) + 1);
207
+
208
+        foreach ($avatars as $avatar) {
209
+            $avatar->delete();
210
+        }
211
+        $this->config->setUserValue($this->user->getUID(), 'avatar', 'generated', 'true');
212
+        if (!$silent) {
213
+            $this->user->triggerChange('avatar', '');
214
+        }
215
+    }
216
+
217
+    /**
218
+     * Get the extension of the avatar. If there is no avatar throw Exception
219
+     *
220
+     * @return string
221
+     * @throws NotFoundException
222
+     */
223
+    private function getExtension() {
224
+        if ($this->folder->fileExists('avatar.jpg')) {
225
+            return 'jpg';
226
+        } elseif ($this->folder->fileExists('avatar.png')) {
227
+            return 'png';
228
+        }
229
+        throw new NotFoundException;
230
+    }
231
+
232
+    /**
233
+     * Returns the avatar for an user.
234
+     *
235
+     * If there is no avatar file yet, one is generated.
236
+     *
237
+     * @param int $size
238
+     * @return ISimpleFile
239
+     * @throws NotFoundException
240
+     * @throws \OCP\Files\NotPermittedException
241
+     * @throws \OCP\PreConditionNotMetException
242
+     */
243
+    public function getFile($size) {
244
+        $size = (int) $size;
245
+
246
+        try {
247
+            $ext = $this->getExtension();
248
+        } catch (NotFoundException $e) {
249
+            if (!$data = $this->generateAvatarFromSvg(1024)) {
250
+                $data = $this->generateAvatar($this->getDisplayName(), 1024);
251
+            }
252
+            $avatar = $this->folder->newFile('avatar.png');
253
+            $avatar->putContent($data);
254
+            $ext = 'png';
255
+
256
+            $this->folder->newFile('generated', '');
257
+            $this->config->setUserValue($this->user->getUID(), 'avatar', 'generated', 'true');
258
+        }
259
+
260
+        if ($size === -1) {
261
+            $path = 'avatar.' . $ext;
262
+        } else {
263
+            $path = 'avatar.' . $size . '.' . $ext;
264
+        }
265
+
266
+        try {
267
+            $file = $this->folder->getFile($path);
268
+        } catch (NotFoundException $e) {
269
+            if ($size <= 0) {
270
+                throw new NotFoundException;
271
+            }
272
+
273
+            // TODO: rework to integrate with the PlaceholderAvatar in a compatible way
274
+            if ($this->folder->fileExists('generated')) {
275
+                if (!$data = $this->generateAvatarFromSvg($size)) {
276
+                    $data = $this->generateAvatar($this->getDisplayName(), $size);
277
+                }
278
+            } else {
279
+                $avatar = new OC_Image();
280
+                $file = $this->folder->getFile('avatar.' . $ext);
281
+                $avatar->loadFromData($file->getContent());
282
+                $avatar->resize($size);
283
+                $data = $avatar->data();
284
+            }
285
+
286
+            try {
287
+                $file = $this->folder->newFile($path);
288
+                $file->putContent($data);
289
+            } catch (NotPermittedException $e) {
290
+                $this->logger->error('Failed to save avatar for ' . $this->user->getUID());
291
+                throw new NotFoundException();
292
+            }
293
+        }
294
+
295
+        if ($this->config->getUserValue($this->user->getUID(), 'avatar', 'generated', null) === null) {
296
+            $generated = $this->folder->fileExists('generated') ? 'true' : 'false';
297
+            $this->config->setUserValue($this->user->getUID(), 'avatar', 'generated', $generated);
298
+        }
299
+
300
+        return $file;
301
+    }
302
+
303
+    /**
304
+     * Returns the user display name.
305
+     *
306
+     * @return string
307
+     */
308
+    public function getDisplayName(): string {
309
+        return $this->user->getDisplayName();
310
+    }
311
+
312
+    /**
313
+     * Handles user changes.
314
+     *
315
+     * @param string $feature The changed feature
316
+     * @param mixed $oldValue The previous value
317
+     * @param mixed $newValue The new value
318
+     * @throws NotPermittedException
319
+     * @throws \OCP\PreConditionNotMetException
320
+     */
321
+    public function userChanged($feature, $oldValue, $newValue) {
322
+        // If the avatar is not generated (so an uploaded image) we skip this
323
+        if (!$this->folder->fileExists('generated')) {
324
+            return;
325
+        }
326
+
327
+        $this->remove();
328
+    }
329
+
330
+    /**
331
+     * Check if the avatar of a user is a custom uploaded one
332
+     *
333
+     * @return bool
334
+     */
335
+    public function isCustomAvatar(): bool {
336
+        return $this->config->getUserValue($this->user->getUID(), 'avatar', 'generated', 'false') !== 'true';
337
+    }
338 338
 }
Please login to merge, or discard this patch.
lib/private/Accounts/AccountManager.php 1 patch
Indentation   +452 added lines, -452 removed lines patch added patch discarded remove patch
@@ -58,456 +58,456 @@
 block discarded – undo
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
-		$allowedScopes = [
148
-			self::SCOPE_PRIVATE,
149
-			self::SCOPE_LOCAL,
150
-			self::SCOPE_FEDERATED,
151
-			self::SCOPE_PUBLISHED,
152
-			self::VISIBILITY_PRIVATE,
153
-			self::VISIBILITY_CONTACTS_ONLY,
154
-			self::VISIBILITY_PUBLIC,
155
-		];
156
-
157
-		// validate and convert scope values
158
-		foreach ($data as $propertyName => $propertyData) {
159
-			if (isset($propertyData['scope'])) {
160
-				if ($throwOnData && !in_array($propertyData['scope'], $allowedScopes, true)) {
161
-					throw new \InvalidArgumentException('scope');
162
-				}
163
-
164
-				if (
165
-					$propertyData['scope'] === self::SCOPE_PRIVATE
166
-					&& ($propertyName === self::PROPERTY_DISPLAYNAME || $propertyName === self::PROPERTY_EMAIL)
167
-				) {
168
-					if ($throwOnData) {
169
-						// v2-private is not available for these fields
170
-						throw new \InvalidArgumentException('scope');
171
-					} else {
172
-						// default to local
173
-						$data[$propertyName]['scope'] = self::SCOPE_LOCAL;
174
-					}
175
-				} else {
176
-					// migrate scope values to the new format
177
-					// invalid scopes are mapped to a default value
178
-					$data[$propertyName]['scope'] = AccountProperty::mapScopeToV2($propertyData['scope']);
179
-				}
180
-			}
181
-		}
182
-
183
-		if (empty($userData)) {
184
-			$this->insertNewUser($user, $data);
185
-		} elseif ($userData !== $data) {
186
-			$data = $this->checkEmailVerification($userData, $data, $user);
187
-			$data = $this->updateVerifyStatus($userData, $data);
188
-			$this->updateExistingUser($user, $data);
189
-		} else {
190
-			// nothing needs to be done if new and old data set are the same
191
-			$updated = false;
192
-		}
193
-
194
-		if ($updated) {
195
-			$this->eventDispatcher->dispatch(
196
-				'OC\AccountManager::userUpdated',
197
-				new GenericEvent($user, $data)
198
-			);
199
-		}
200
-
201
-		return $data;
202
-	}
203
-
204
-	/**
205
-	 * delete user from accounts table
206
-	 *
207
-	 * @param IUser $user
208
-	 */
209
-	public function deleteUser(IUser $user) {
210
-		$uid = $user->getUID();
211
-		$query = $this->connection->getQueryBuilder();
212
-		$query->delete($this->table)
213
-			->where($query->expr()->eq('uid', $query->createNamedParameter($uid)))
214
-			->execute();
215
-
216
-		$this->deleteUserData($user);
217
-	}
218
-
219
-	/**
220
-	 * delete user from accounts table
221
-	 *
222
-	 * @param IUser $user
223
-	 */
224
-	public function deleteUserData(IUser $user): void {
225
-		$uid = $user->getUID();
226
-		$query = $this->connection->getQueryBuilder();
227
-		$query->delete($this->dataTable)
228
-			->where($query->expr()->eq('uid', $query->createNamedParameter($uid)))
229
-			->execute();
230
-	}
231
-
232
-	/**
233
-	 * get stored data from a given user
234
-	 *
235
-	 * @param IUser $user
236
-	 * @return array
237
-	 *
238
-	 * @deprecated use getAccount instead to make sure migrated properties work correctly
239
-	 */
240
-	public function getUser(IUser $user) {
241
-		$uid = $user->getUID();
242
-		$query = $this->connection->getQueryBuilder();
243
-		$query->select('data')
244
-			->from($this->table)
245
-			->where($query->expr()->eq('uid', $query->createParameter('uid')))
246
-			->setParameter('uid', $uid);
247
-		$result = $query->execute();
248
-		$accountData = $result->fetchAll();
249
-		$result->closeCursor();
250
-
251
-		if (empty($accountData)) {
252
-			$userData = $this->buildDefaultUserRecord($user);
253
-			$this->insertNewUser($user, $userData);
254
-			return $userData;
255
-		}
256
-
257
-		$userDataArray = json_decode($accountData[0]['data'], true);
258
-		$jsonError = json_last_error();
259
-		if ($userDataArray === null || $userDataArray === [] || $jsonError !== JSON_ERROR_NONE) {
260
-			$this->logger->critical("User data of $uid contained invalid JSON (error $jsonError), hence falling back to a default user record");
261
-			return $this->buildDefaultUserRecord($user);
262
-		}
263
-
264
-		$userDataArray = $this->addMissingDefaultValues($userDataArray);
265
-
266
-		return $userDataArray;
267
-	}
268
-
269
-	public function searchUsers(string $property, array $values): array {
270
-		$chunks = array_chunk($values, 500);
271
-		$query = $this->connection->getQueryBuilder();
272
-		$query->select('*')
273
-			->from($this->dataTable)
274
-			->where($query->expr()->eq('name', $query->createNamedParameter($property)))
275
-			->andWhere($query->expr()->in('value', $query->createParameter('values')));
276
-
277
-		$matches = [];
278
-		foreach ($chunks as $chunk) {
279
-			$query->setParameter('values', $chunk, IQueryBuilder::PARAM_STR_ARRAY);
280
-			$result = $query->execute();
281
-
282
-			while ($row = $result->fetch()) {
283
-				$matches[$row['value']] = $row['uid'];
284
-			}
285
-			$result->closeCursor();
286
-		}
287
-
288
-		return $matches;
289
-	}
290
-
291
-	/**
292
-	 * check if we need to ask the server for email verification, if yes we create a cronjob
293
-	 *
294
-	 * @param $oldData
295
-	 * @param $newData
296
-	 * @param IUser $user
297
-	 * @return array
298
-	 */
299
-	protected function checkEmailVerification($oldData, $newData, IUser $user) {
300
-		if ($oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value']) {
301
-			$this->jobList->add(VerifyUserData::class,
302
-				[
303
-					'verificationCode' => '',
304
-					'data' => $newData[self::PROPERTY_EMAIL]['value'],
305
-					'type' => self::PROPERTY_EMAIL,
306
-					'uid' => $user->getUID(),
307
-					'try' => 0,
308
-					'lastRun' => time()
309
-				]
310
-			);
311
-			$newData[self::PROPERTY_EMAIL]['verified'] = self::VERIFICATION_IN_PROGRESS;
312
-		}
313
-
314
-		return $newData;
315
-	}
316
-
317
-	/**
318
-	 * make sure that all expected data are set
319
-	 *
320
-	 * @param array $userData
321
-	 * @return array
322
-	 */
323
-	protected function addMissingDefaultValues(array $userData) {
324
-		foreach ($userData as $key => $value) {
325
-			if (!isset($userData[$key]['verified'])) {
326
-				$userData[$key]['verified'] = self::NOT_VERIFIED;
327
-			}
328
-		}
329
-
330
-		return $userData;
331
-	}
332
-
333
-	/**
334
-	 * reset verification status if personal data changed
335
-	 *
336
-	 * @param array $oldData
337
-	 * @param array $newData
338
-	 * @return array
339
-	 */
340
-	protected function updateVerifyStatus($oldData, $newData) {
341
-
342
-		// which account was already verified successfully?
343
-		$twitterVerified = isset($oldData[self::PROPERTY_TWITTER]['verified']) && $oldData[self::PROPERTY_TWITTER]['verified'] === self::VERIFIED;
344
-		$websiteVerified = isset($oldData[self::PROPERTY_WEBSITE]['verified']) && $oldData[self::PROPERTY_WEBSITE]['verified'] === self::VERIFIED;
345
-		$emailVerified = isset($oldData[self::PROPERTY_EMAIL]['verified']) && $oldData[self::PROPERTY_EMAIL]['verified'] === self::VERIFIED;
346
-
347
-		// keep old verification status if we don't have a new one
348
-		if (!isset($newData[self::PROPERTY_TWITTER]['verified'])) {
349
-			// keep old verification status if value didn't changed and an old value exists
350
-			$keepOldStatus = $newData[self::PROPERTY_TWITTER]['value'] === $oldData[self::PROPERTY_TWITTER]['value'] && isset($oldData[self::PROPERTY_TWITTER]['verified']);
351
-			$newData[self::PROPERTY_TWITTER]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_TWITTER]['verified'] : self::NOT_VERIFIED;
352
-		}
353
-
354
-		if (!isset($newData[self::PROPERTY_WEBSITE]['verified'])) {
355
-			// keep old verification status if value didn't changed and an old value exists
356
-			$keepOldStatus = $newData[self::PROPERTY_WEBSITE]['value'] === $oldData[self::PROPERTY_WEBSITE]['value'] && isset($oldData[self::PROPERTY_WEBSITE]['verified']);
357
-			$newData[self::PROPERTY_WEBSITE]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_WEBSITE]['verified'] : self::NOT_VERIFIED;
358
-		}
359
-
360
-		if (!isset($newData[self::PROPERTY_EMAIL]['verified'])) {
361
-			// keep old verification status if value didn't changed and an old value exists
362
-			$keepOldStatus = $newData[self::PROPERTY_EMAIL]['value'] === $oldData[self::PROPERTY_EMAIL]['value'] && isset($oldData[self::PROPERTY_EMAIL]['verified']);
363
-			$newData[self::PROPERTY_EMAIL]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_EMAIL]['verified'] : self::VERIFICATION_IN_PROGRESS;
364
-		}
365
-
366
-		// reset verification status if a value from a previously verified data was changed
367
-		if ($twitterVerified &&
368
-			$oldData[self::PROPERTY_TWITTER]['value'] !== $newData[self::PROPERTY_TWITTER]['value']
369
-		) {
370
-			$newData[self::PROPERTY_TWITTER]['verified'] = self::NOT_VERIFIED;
371
-		}
372
-
373
-		if ($websiteVerified &&
374
-			$oldData[self::PROPERTY_WEBSITE]['value'] !== $newData[self::PROPERTY_WEBSITE]['value']
375
-		) {
376
-			$newData[self::PROPERTY_WEBSITE]['verified'] = self::NOT_VERIFIED;
377
-		}
378
-
379
-		if ($emailVerified &&
380
-			$oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value']
381
-		) {
382
-			$newData[self::PROPERTY_EMAIL]['verified'] = self::NOT_VERIFIED;
383
-		}
384
-
385
-		return $newData;
386
-	}
387
-
388
-	/**
389
-	 * add new user to accounts table
390
-	 *
391
-	 * @param IUser $user
392
-	 * @param array $data
393
-	 */
394
-	protected function insertNewUser(IUser $user, array $data): void {
395
-		$uid = $user->getUID();
396
-		$jsonEncodedData = json_encode($data);
397
-		$query = $this->connection->getQueryBuilder();
398
-		$query->insert($this->table)
399
-			->values(
400
-				[
401
-					'uid' => $query->createNamedParameter($uid),
402
-					'data' => $query->createNamedParameter($jsonEncodedData),
403
-				]
404
-			)
405
-			->execute();
406
-
407
-		$this->deleteUserData($user);
408
-		$this->writeUserData($user, $data);
409
-	}
410
-
411
-	/**
412
-	 * update existing user in accounts table
413
-	 *
414
-	 * @param IUser $user
415
-	 * @param array $data
416
-	 */
417
-	protected function updateExistingUser(IUser $user, array $data): void {
418
-		$uid = $user->getUID();
419
-		$jsonEncodedData = json_encode($data);
420
-		$query = $this->connection->getQueryBuilder();
421
-		$query->update($this->table)
422
-			->set('data', $query->createNamedParameter($jsonEncodedData))
423
-			->where($query->expr()->eq('uid', $query->createNamedParameter($uid)))
424
-			->execute();
425
-
426
-		$this->deleteUserData($user);
427
-		$this->writeUserData($user, $data);
428
-	}
429
-
430
-	protected function writeUserData(IUser $user, array $data): void {
431
-		$query = $this->connection->getQueryBuilder();
432
-		$query->insert($this->dataTable)
433
-			->values(
434
-				[
435
-					'uid' => $query->createNamedParameter($user->getUID()),
436
-					'name' => $query->createParameter('name'),
437
-					'value' => $query->createParameter('value'),
438
-				]
439
-			);
440
-		foreach ($data as $propertyName => $property) {
441
-			if ($propertyName === self::PROPERTY_AVATAR) {
442
-				continue;
443
-			}
444
-
445
-			$query->setParameter('name', $propertyName)
446
-				->setParameter('value', $property['value'] ?? '');
447
-			$query->execute();
448
-		}
449
-	}
450
-
451
-	/**
452
-	 * build default user record in case not data set exists yet
453
-	 *
454
-	 * @param IUser $user
455
-	 * @return array
456
-	 */
457
-	protected function buildDefaultUserRecord(IUser $user) {
458
-		return [
459
-			self::PROPERTY_DISPLAYNAME =>
460
-				[
461
-					'value' => $user->getDisplayName(),
462
-					'scope' => self::SCOPE_FEDERATED,
463
-					'verified' => self::NOT_VERIFIED,
464
-				],
465
-			self::PROPERTY_ADDRESS =>
466
-				[
467
-					'value' => '',
468
-					'scope' => self::SCOPE_LOCAL,
469
-					'verified' => self::NOT_VERIFIED,
470
-				],
471
-			self::PROPERTY_WEBSITE =>
472
-				[
473
-					'value' => '',
474
-					'scope' => self::SCOPE_LOCAL,
475
-					'verified' => self::NOT_VERIFIED,
476
-				],
477
-			self::PROPERTY_EMAIL =>
478
-				[
479
-					'value' => $user->getEMailAddress(),
480
-					'scope' => self::SCOPE_FEDERATED,
481
-					'verified' => self::NOT_VERIFIED,
482
-				],
483
-			self::PROPERTY_AVATAR =>
484
-				[
485
-					'scope' => self::SCOPE_FEDERATED
486
-				],
487
-			self::PROPERTY_PHONE =>
488
-				[
489
-					'value' => '',
490
-					'scope' => self::SCOPE_LOCAL,
491
-					'verified' => self::NOT_VERIFIED,
492
-				],
493
-			self::PROPERTY_TWITTER =>
494
-				[
495
-					'value' => '',
496
-					'scope' => self::SCOPE_LOCAL,
497
-					'verified' => self::NOT_VERIFIED,
498
-				],
499
-		];
500
-	}
501
-
502
-	private function parseAccountData(IUser $user, $data): Account {
503
-		$account = new Account($user);
504
-		foreach ($data as $property => $accountData) {
505
-			$account->setProperty($property, $accountData['value'] ?? '', $accountData['scope'] ?? self::SCOPE_LOCAL, $accountData['verified'] ?? self::NOT_VERIFIED);
506
-		}
507
-		return $account;
508
-	}
509
-
510
-	public function getAccount(IUser $user): IAccount {
511
-		return $this->parseAccountData($user, $this->getUser($user));
512
-	}
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
+        $allowedScopes = [
148
+            self::SCOPE_PRIVATE,
149
+            self::SCOPE_LOCAL,
150
+            self::SCOPE_FEDERATED,
151
+            self::SCOPE_PUBLISHED,
152
+            self::VISIBILITY_PRIVATE,
153
+            self::VISIBILITY_CONTACTS_ONLY,
154
+            self::VISIBILITY_PUBLIC,
155
+        ];
156
+
157
+        // validate and convert scope values
158
+        foreach ($data as $propertyName => $propertyData) {
159
+            if (isset($propertyData['scope'])) {
160
+                if ($throwOnData && !in_array($propertyData['scope'], $allowedScopes, true)) {
161
+                    throw new \InvalidArgumentException('scope');
162
+                }
163
+
164
+                if (
165
+                    $propertyData['scope'] === self::SCOPE_PRIVATE
166
+                    && ($propertyName === self::PROPERTY_DISPLAYNAME || $propertyName === self::PROPERTY_EMAIL)
167
+                ) {
168
+                    if ($throwOnData) {
169
+                        // v2-private is not available for these fields
170
+                        throw new \InvalidArgumentException('scope');
171
+                    } else {
172
+                        // default to local
173
+                        $data[$propertyName]['scope'] = self::SCOPE_LOCAL;
174
+                    }
175
+                } else {
176
+                    // migrate scope values to the new format
177
+                    // invalid scopes are mapped to a default value
178
+                    $data[$propertyName]['scope'] = AccountProperty::mapScopeToV2($propertyData['scope']);
179
+                }
180
+            }
181
+        }
182
+
183
+        if (empty($userData)) {
184
+            $this->insertNewUser($user, $data);
185
+        } elseif ($userData !== $data) {
186
+            $data = $this->checkEmailVerification($userData, $data, $user);
187
+            $data = $this->updateVerifyStatus($userData, $data);
188
+            $this->updateExistingUser($user, $data);
189
+        } else {
190
+            // nothing needs to be done if new and old data set are the same
191
+            $updated = false;
192
+        }
193
+
194
+        if ($updated) {
195
+            $this->eventDispatcher->dispatch(
196
+                'OC\AccountManager::userUpdated',
197
+                new GenericEvent($user, $data)
198
+            );
199
+        }
200
+
201
+        return $data;
202
+    }
203
+
204
+    /**
205
+     * delete user from accounts table
206
+     *
207
+     * @param IUser $user
208
+     */
209
+    public function deleteUser(IUser $user) {
210
+        $uid = $user->getUID();
211
+        $query = $this->connection->getQueryBuilder();
212
+        $query->delete($this->table)
213
+            ->where($query->expr()->eq('uid', $query->createNamedParameter($uid)))
214
+            ->execute();
215
+
216
+        $this->deleteUserData($user);
217
+    }
218
+
219
+    /**
220
+     * delete user from accounts table
221
+     *
222
+     * @param IUser $user
223
+     */
224
+    public function deleteUserData(IUser $user): void {
225
+        $uid = $user->getUID();
226
+        $query = $this->connection->getQueryBuilder();
227
+        $query->delete($this->dataTable)
228
+            ->where($query->expr()->eq('uid', $query->createNamedParameter($uid)))
229
+            ->execute();
230
+    }
231
+
232
+    /**
233
+     * get stored data from a given user
234
+     *
235
+     * @param IUser $user
236
+     * @return array
237
+     *
238
+     * @deprecated use getAccount instead to make sure migrated properties work correctly
239
+     */
240
+    public function getUser(IUser $user) {
241
+        $uid = $user->getUID();
242
+        $query = $this->connection->getQueryBuilder();
243
+        $query->select('data')
244
+            ->from($this->table)
245
+            ->where($query->expr()->eq('uid', $query->createParameter('uid')))
246
+            ->setParameter('uid', $uid);
247
+        $result = $query->execute();
248
+        $accountData = $result->fetchAll();
249
+        $result->closeCursor();
250
+
251
+        if (empty($accountData)) {
252
+            $userData = $this->buildDefaultUserRecord($user);
253
+            $this->insertNewUser($user, $userData);
254
+            return $userData;
255
+        }
256
+
257
+        $userDataArray = json_decode($accountData[0]['data'], true);
258
+        $jsonError = json_last_error();
259
+        if ($userDataArray === null || $userDataArray === [] || $jsonError !== JSON_ERROR_NONE) {
260
+            $this->logger->critical("User data of $uid contained invalid JSON (error $jsonError), hence falling back to a default user record");
261
+            return $this->buildDefaultUserRecord($user);
262
+        }
263
+
264
+        $userDataArray = $this->addMissingDefaultValues($userDataArray);
265
+
266
+        return $userDataArray;
267
+    }
268
+
269
+    public function searchUsers(string $property, array $values): array {
270
+        $chunks = array_chunk($values, 500);
271
+        $query = $this->connection->getQueryBuilder();
272
+        $query->select('*')
273
+            ->from($this->dataTable)
274
+            ->where($query->expr()->eq('name', $query->createNamedParameter($property)))
275
+            ->andWhere($query->expr()->in('value', $query->createParameter('values')));
276
+
277
+        $matches = [];
278
+        foreach ($chunks as $chunk) {
279
+            $query->setParameter('values', $chunk, IQueryBuilder::PARAM_STR_ARRAY);
280
+            $result = $query->execute();
281
+
282
+            while ($row = $result->fetch()) {
283
+                $matches[$row['value']] = $row['uid'];
284
+            }
285
+            $result->closeCursor();
286
+        }
287
+
288
+        return $matches;
289
+    }
290
+
291
+    /**
292
+     * check if we need to ask the server for email verification, if yes we create a cronjob
293
+     *
294
+     * @param $oldData
295
+     * @param $newData
296
+     * @param IUser $user
297
+     * @return array
298
+     */
299
+    protected function checkEmailVerification($oldData, $newData, IUser $user) {
300
+        if ($oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value']) {
301
+            $this->jobList->add(VerifyUserData::class,
302
+                [
303
+                    'verificationCode' => '',
304
+                    'data' => $newData[self::PROPERTY_EMAIL]['value'],
305
+                    'type' => self::PROPERTY_EMAIL,
306
+                    'uid' => $user->getUID(),
307
+                    'try' => 0,
308
+                    'lastRun' => time()
309
+                ]
310
+            );
311
+            $newData[self::PROPERTY_EMAIL]['verified'] = self::VERIFICATION_IN_PROGRESS;
312
+        }
313
+
314
+        return $newData;
315
+    }
316
+
317
+    /**
318
+     * make sure that all expected data are set
319
+     *
320
+     * @param array $userData
321
+     * @return array
322
+     */
323
+    protected function addMissingDefaultValues(array $userData) {
324
+        foreach ($userData as $key => $value) {
325
+            if (!isset($userData[$key]['verified'])) {
326
+                $userData[$key]['verified'] = self::NOT_VERIFIED;
327
+            }
328
+        }
329
+
330
+        return $userData;
331
+    }
332
+
333
+    /**
334
+     * reset verification status if personal data changed
335
+     *
336
+     * @param array $oldData
337
+     * @param array $newData
338
+     * @return array
339
+     */
340
+    protected function updateVerifyStatus($oldData, $newData) {
341
+
342
+        // which account was already verified successfully?
343
+        $twitterVerified = isset($oldData[self::PROPERTY_TWITTER]['verified']) && $oldData[self::PROPERTY_TWITTER]['verified'] === self::VERIFIED;
344
+        $websiteVerified = isset($oldData[self::PROPERTY_WEBSITE]['verified']) && $oldData[self::PROPERTY_WEBSITE]['verified'] === self::VERIFIED;
345
+        $emailVerified = isset($oldData[self::PROPERTY_EMAIL]['verified']) && $oldData[self::PROPERTY_EMAIL]['verified'] === self::VERIFIED;
346
+
347
+        // keep old verification status if we don't have a new one
348
+        if (!isset($newData[self::PROPERTY_TWITTER]['verified'])) {
349
+            // keep old verification status if value didn't changed and an old value exists
350
+            $keepOldStatus = $newData[self::PROPERTY_TWITTER]['value'] === $oldData[self::PROPERTY_TWITTER]['value'] && isset($oldData[self::PROPERTY_TWITTER]['verified']);
351
+            $newData[self::PROPERTY_TWITTER]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_TWITTER]['verified'] : self::NOT_VERIFIED;
352
+        }
353
+
354
+        if (!isset($newData[self::PROPERTY_WEBSITE]['verified'])) {
355
+            // keep old verification status if value didn't changed and an old value exists
356
+            $keepOldStatus = $newData[self::PROPERTY_WEBSITE]['value'] === $oldData[self::PROPERTY_WEBSITE]['value'] && isset($oldData[self::PROPERTY_WEBSITE]['verified']);
357
+            $newData[self::PROPERTY_WEBSITE]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_WEBSITE]['verified'] : self::NOT_VERIFIED;
358
+        }
359
+
360
+        if (!isset($newData[self::PROPERTY_EMAIL]['verified'])) {
361
+            // keep old verification status if value didn't changed and an old value exists
362
+            $keepOldStatus = $newData[self::PROPERTY_EMAIL]['value'] === $oldData[self::PROPERTY_EMAIL]['value'] && isset($oldData[self::PROPERTY_EMAIL]['verified']);
363
+            $newData[self::PROPERTY_EMAIL]['verified'] = $keepOldStatus ? $oldData[self::PROPERTY_EMAIL]['verified'] : self::VERIFICATION_IN_PROGRESS;
364
+        }
365
+
366
+        // reset verification status if a value from a previously verified data was changed
367
+        if ($twitterVerified &&
368
+            $oldData[self::PROPERTY_TWITTER]['value'] !== $newData[self::PROPERTY_TWITTER]['value']
369
+        ) {
370
+            $newData[self::PROPERTY_TWITTER]['verified'] = self::NOT_VERIFIED;
371
+        }
372
+
373
+        if ($websiteVerified &&
374
+            $oldData[self::PROPERTY_WEBSITE]['value'] !== $newData[self::PROPERTY_WEBSITE]['value']
375
+        ) {
376
+            $newData[self::PROPERTY_WEBSITE]['verified'] = self::NOT_VERIFIED;
377
+        }
378
+
379
+        if ($emailVerified &&
380
+            $oldData[self::PROPERTY_EMAIL]['value'] !== $newData[self::PROPERTY_EMAIL]['value']
381
+        ) {
382
+            $newData[self::PROPERTY_EMAIL]['verified'] = self::NOT_VERIFIED;
383
+        }
384
+
385
+        return $newData;
386
+    }
387
+
388
+    /**
389
+     * add new user to accounts table
390
+     *
391
+     * @param IUser $user
392
+     * @param array $data
393
+     */
394
+    protected function insertNewUser(IUser $user, array $data): void {
395
+        $uid = $user->getUID();
396
+        $jsonEncodedData = json_encode($data);
397
+        $query = $this->connection->getQueryBuilder();
398
+        $query->insert($this->table)
399
+            ->values(
400
+                [
401
+                    'uid' => $query->createNamedParameter($uid),
402
+                    'data' => $query->createNamedParameter($jsonEncodedData),
403
+                ]
404
+            )
405
+            ->execute();
406
+
407
+        $this->deleteUserData($user);
408
+        $this->writeUserData($user, $data);
409
+    }
410
+
411
+    /**
412
+     * update existing user in accounts table
413
+     *
414
+     * @param IUser $user
415
+     * @param array $data
416
+     */
417
+    protected function updateExistingUser(IUser $user, array $data): void {
418
+        $uid = $user->getUID();
419
+        $jsonEncodedData = json_encode($data);
420
+        $query = $this->connection->getQueryBuilder();
421
+        $query->update($this->table)
422
+            ->set('data', $query->createNamedParameter($jsonEncodedData))
423
+            ->where($query->expr()->eq('uid', $query->createNamedParameter($uid)))
424
+            ->execute();
425
+
426
+        $this->deleteUserData($user);
427
+        $this->writeUserData($user, $data);
428
+    }
429
+
430
+    protected function writeUserData(IUser $user, array $data): void {
431
+        $query = $this->connection->getQueryBuilder();
432
+        $query->insert($this->dataTable)
433
+            ->values(
434
+                [
435
+                    'uid' => $query->createNamedParameter($user->getUID()),
436
+                    'name' => $query->createParameter('name'),
437
+                    'value' => $query->createParameter('value'),
438
+                ]
439
+            );
440
+        foreach ($data as $propertyName => $property) {
441
+            if ($propertyName === self::PROPERTY_AVATAR) {
442
+                continue;
443
+            }
444
+
445
+            $query->setParameter('name', $propertyName)
446
+                ->setParameter('value', $property['value'] ?? '');
447
+            $query->execute();
448
+        }
449
+    }
450
+
451
+    /**
452
+     * build default user record in case not data set exists yet
453
+     *
454
+     * @param IUser $user
455
+     * @return array
456
+     */
457
+    protected function buildDefaultUserRecord(IUser $user) {
458
+        return [
459
+            self::PROPERTY_DISPLAYNAME =>
460
+                [
461
+                    'value' => $user->getDisplayName(),
462
+                    'scope' => self::SCOPE_FEDERATED,
463
+                    'verified' => self::NOT_VERIFIED,
464
+                ],
465
+            self::PROPERTY_ADDRESS =>
466
+                [
467
+                    'value' => '',
468
+                    'scope' => self::SCOPE_LOCAL,
469
+                    'verified' => self::NOT_VERIFIED,
470
+                ],
471
+            self::PROPERTY_WEBSITE =>
472
+                [
473
+                    'value' => '',
474
+                    'scope' => self::SCOPE_LOCAL,
475
+                    'verified' => self::NOT_VERIFIED,
476
+                ],
477
+            self::PROPERTY_EMAIL =>
478
+                [
479
+                    'value' => $user->getEMailAddress(),
480
+                    'scope' => self::SCOPE_FEDERATED,
481
+                    'verified' => self::NOT_VERIFIED,
482
+                ],
483
+            self::PROPERTY_AVATAR =>
484
+                [
485
+                    'scope' => self::SCOPE_FEDERATED
486
+                ],
487
+            self::PROPERTY_PHONE =>
488
+                [
489
+                    'value' => '',
490
+                    'scope' => self::SCOPE_LOCAL,
491
+                    'verified' => self::NOT_VERIFIED,
492
+                ],
493
+            self::PROPERTY_TWITTER =>
494
+                [
495
+                    'value' => '',
496
+                    'scope' => self::SCOPE_LOCAL,
497
+                    'verified' => self::NOT_VERIFIED,
498
+                ],
499
+        ];
500
+    }
501
+
502
+    private function parseAccountData(IUser $user, $data): Account {
503
+        $account = new Account($user);
504
+        foreach ($data as $property => $accountData) {
505
+            $account->setProperty($property, $accountData['value'] ?? '', $accountData['scope'] ?? self::SCOPE_LOCAL, $accountData['verified'] ?? self::NOT_VERIFIED);
506
+        }
507
+        return $account;
508
+    }
509
+
510
+    public function getAccount(IUser $user): IAccount {
511
+        return $this->parseAccountData($user, $this->getUser($user));
512
+    }
513 513
 }
Please login to merge, or discard this patch.
lib/private/Accounts/AccountProperty.php 2 patches
Indentation   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -31,128 +31,128 @@
 block discarded – undo
31 31
 
32 32
 class AccountProperty implements IAccountProperty {
33 33
 
34
-	/** @var string */
35
-	private $name;
36
-	/** @var string */
37
-	private $value;
38
-	/** @var string */
39
-	private $scope;
40
-	/** @var string */
41
-	private $verified;
42
-
43
-	public function __construct(string $name, string $value, string $scope, string $verified) {
44
-		$this->name = $name;
45
-		$this->value = $value;
46
-		$this->scope = $this->mapScopeToV2($scope);
47
-		$this->verified = $verified;
48
-	}
49
-
50
-	public function jsonSerialize() {
51
-		return [
52
-			'name' => $this->getName(),
53
-			'value' => $this->getValue(),
54
-			'scope' => $this->getScope(),
55
-			'verified' => $this->getVerified()
56
-		];
57
-	}
58
-
59
-	/**
60
-	 * Set the value of a property
61
-	 *
62
-	 * @since 15.0.0
63
-	 *
64
-	 * @param string $value
65
-	 * @return IAccountProperty
66
-	 */
67
-	public function setValue(string $value): IAccountProperty {
68
-		$this->value = $value;
69
-		return $this;
70
-	}
71
-
72
-	/**
73
-	 * Set the scope of a property
74
-	 *
75
-	 * @since 15.0.0
76
-	 *
77
-	 * @param string $scope
78
-	 * @return IAccountProperty
79
-	 */
80
-	public function setScope(string $scope): IAccountProperty {
81
-		$this->scope = $this->mapScopeToV2($scope);
82
-		return $this;
83
-	}
84
-
85
-	/**
86
-	 * Set the verification status of a property
87
-	 *
88
-	 * @since 15.0.0
89
-	 *
90
-	 * @param string $verified
91
-	 * @return IAccountProperty
92
-	 */
93
-	public function setVerified(string $verified): IAccountProperty {
94
-		$this->verified = $verified;
95
-		return $this;
96
-	}
97
-
98
-	/**
99
-	 * Get the name of a property
100
-	 *
101
-	 * @since 15.0.0
102
-	 *
103
-	 * @return string
104
-	 */
105
-	public function getName(): string {
106
-		return $this->name;
107
-	}
108
-
109
-	/**
110
-	 * Get the value of a property
111
-	 *
112
-	 * @since 15.0.0
113
-	 *
114
-	 * @return string
115
-	 */
116
-	public function getValue(): string {
117
-		return $this->value;
118
-	}
119
-
120
-	/**
121
-	 * Get the scope of a property
122
-	 *
123
-	 * @since 15.0.0
124
-	 *
125
-	 * @return string
126
-	 */
127
-	public function getScope(): string {
128
-		return $this->scope;
129
-	}
130
-
131
-	public static function mapScopeToV2($scope) {
132
-		if (strpos($scope, 'v2-') === 0) {
133
-			return $scope;
134
-		}
135
-
136
-		switch ($scope) {
137
-		case IAccountManager::VISIBILITY_PRIVATE:
138
-			return IAccountManager::SCOPE_LOCAL;
139
-		case IAccountManager::VISIBILITY_CONTACTS_ONLY:
140
-			return IAccountManager::SCOPE_FEDERATED;
141
-		case IAccountManager::VISIBILITY_PUBLIC:
142
-			return IAccountManager::SCOPE_PUBLISHED;
143
-		}
144
-
145
-		return IAccountManager::SCOPE_LOCAL;
146
-	}
147
-
148
-	/**
149
-	 * Get the verification status of a property
150
-	 *
151
-	 * @since 15.0.0
152
-	 *
153
-	 * @return string
154
-	 */
155
-	public function getVerified(): string {
156
-		return $this->verified;
157
-	}
34
+    /** @var string */
35
+    private $name;
36
+    /** @var string */
37
+    private $value;
38
+    /** @var string */
39
+    private $scope;
40
+    /** @var string */
41
+    private $verified;
42
+
43
+    public function __construct(string $name, string $value, string $scope, string $verified) {
44
+        $this->name = $name;
45
+        $this->value = $value;
46
+        $this->scope = $this->mapScopeToV2($scope);
47
+        $this->verified = $verified;
48
+    }
49
+
50
+    public function jsonSerialize() {
51
+        return [
52
+            'name' => $this->getName(),
53
+            'value' => $this->getValue(),
54
+            'scope' => $this->getScope(),
55
+            'verified' => $this->getVerified()
56
+        ];
57
+    }
58
+
59
+    /**
60
+     * Set the value of a property
61
+     *
62
+     * @since 15.0.0
63
+     *
64
+     * @param string $value
65
+     * @return IAccountProperty
66
+     */
67
+    public function setValue(string $value): IAccountProperty {
68
+        $this->value = $value;
69
+        return $this;
70
+    }
71
+
72
+    /**
73
+     * Set the scope of a property
74
+     *
75
+     * @since 15.0.0
76
+     *
77
+     * @param string $scope
78
+     * @return IAccountProperty
79
+     */
80
+    public function setScope(string $scope): IAccountProperty {
81
+        $this->scope = $this->mapScopeToV2($scope);
82
+        return $this;
83
+    }
84
+
85
+    /**
86
+     * Set the verification status of a property
87
+     *
88
+     * @since 15.0.0
89
+     *
90
+     * @param string $verified
91
+     * @return IAccountProperty
92
+     */
93
+    public function setVerified(string $verified): IAccountProperty {
94
+        $this->verified = $verified;
95
+        return $this;
96
+    }
97
+
98
+    /**
99
+     * Get the name of a property
100
+     *
101
+     * @since 15.0.0
102
+     *
103
+     * @return string
104
+     */
105
+    public function getName(): string {
106
+        return $this->name;
107
+    }
108
+
109
+    /**
110
+     * Get the value of a property
111
+     *
112
+     * @since 15.0.0
113
+     *
114
+     * @return string
115
+     */
116
+    public function getValue(): string {
117
+        return $this->value;
118
+    }
119
+
120
+    /**
121
+     * Get the scope of a property
122
+     *
123
+     * @since 15.0.0
124
+     *
125
+     * @return string
126
+     */
127
+    public function getScope(): string {
128
+        return $this->scope;
129
+    }
130
+
131
+    public static function mapScopeToV2($scope) {
132
+        if (strpos($scope, 'v2-') === 0) {
133
+            return $scope;
134
+        }
135
+
136
+        switch ($scope) {
137
+        case IAccountManager::VISIBILITY_PRIVATE:
138
+            return IAccountManager::SCOPE_LOCAL;
139
+        case IAccountManager::VISIBILITY_CONTACTS_ONLY:
140
+            return IAccountManager::SCOPE_FEDERATED;
141
+        case IAccountManager::VISIBILITY_PUBLIC:
142
+            return IAccountManager::SCOPE_PUBLISHED;
143
+        }
144
+
145
+        return IAccountManager::SCOPE_LOCAL;
146
+    }
147
+
148
+    /**
149
+     * Get the verification status of a property
150
+     *
151
+     * @since 15.0.0
152
+     *
153
+     * @return string
154
+     */
155
+    public function getVerified(): string {
156
+        return $this->verified;
157
+    }
158 158
 }
Please login to merge, or discard this patch.
Switch Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -134,12 +134,12 @@
 block discarded – undo
134 134
 		}
135 135
 
136 136
 		switch ($scope) {
137
-		case IAccountManager::VISIBILITY_PRIVATE:
138
-			return IAccountManager::SCOPE_LOCAL;
139
-		case IAccountManager::VISIBILITY_CONTACTS_ONLY:
140
-			return IAccountManager::SCOPE_FEDERATED;
141
-		case IAccountManager::VISIBILITY_PUBLIC:
142
-			return IAccountManager::SCOPE_PUBLISHED;
137
+		    case IAccountManager::VISIBILITY_PRIVATE:
138
+			    return IAccountManager::SCOPE_LOCAL;
139
+		    case IAccountManager::VISIBILITY_CONTACTS_ONLY:
140
+			    return IAccountManager::SCOPE_FEDERATED;
141
+		    case IAccountManager::VISIBILITY_PUBLIC:
142
+			    return IAccountManager::SCOPE_PUBLISHED;
143 143
 		}
144 144
 
145 145
 		return IAccountManager::SCOPE_LOCAL;
Please login to merge, or discard this patch.
lib/private/Server.php 2 patches
Indentation   +2035 added lines, -2035 removed lines patch added patch discarded remove patch
@@ -253,2044 +253,2044 @@
 block discarded – undo
253 253
  */
254 254
 class Server extends ServerContainer implements IServerContainer {
255 255
 
256
-	/** @var string */
257
-	private $webRoot;
258
-
259
-	/**
260
-	 * @param string $webRoot
261
-	 * @param \OC\Config $config
262
-	 */
263
-	public function __construct($webRoot, \OC\Config $config) {
264
-		parent::__construct();
265
-		$this->webRoot = $webRoot;
266
-
267
-		// To find out if we are running from CLI or not
268
-		$this->registerParameter('isCLI', \OC::$CLI);
269
-		$this->registerParameter('serverRoot', \OC::$SERVERROOT);
270
-
271
-		$this->registerService(ContainerInterface::class, function (ContainerInterface $c) {
272
-			return $c;
273
-		});
274
-		$this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) {
275
-			return $c;
276
-		});
277
-
278
-		$this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
279
-		/** @deprecated 19.0.0 */
280
-		$this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class);
281
-
282
-		$this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class);
283
-		/** @deprecated 19.0.0 */
284
-		$this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class);
285
-
286
-		$this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class);
287
-		/** @deprecated 19.0.0 */
288
-		$this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class);
289
-
290
-		$this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
291
-		/** @deprecated 19.0.0 */
292
-		$this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class);
293
-
294
-		$this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class);
295
-		$this->registerAlias(ITemplateManager::class, TemplateManager::class);
296
-
297
-		$this->registerAlias(IActionFactory::class, ActionFactory::class);
298
-
299
-		$this->registerService(View::class, function (Server $c) {
300
-			return new View();
301
-		}, false);
302
-
303
-		$this->registerService(IPreview::class, function (ContainerInterface $c) {
304
-			return new PreviewManager(
305
-				$c->get(\OCP\IConfig::class),
306
-				$c->get(IRootFolder::class),
307
-				new \OC\Preview\Storage\Root(
308
-					$c->get(IRootFolder::class),
309
-					$c->get(SystemConfig::class)
310
-				),
311
-				$c->get(SymfonyAdapter::class),
312
-				$c->get(GeneratorHelper::class),
313
-				$c->get(ISession::class)->get('user_id')
314
-			);
315
-		});
316
-		/** @deprecated 19.0.0 */
317
-		$this->registerDeprecatedAlias('PreviewManager', IPreview::class);
318
-
319
-		$this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) {
320
-			return new \OC\Preview\Watcher(
321
-				new \OC\Preview\Storage\Root(
322
-					$c->get(IRootFolder::class),
323
-					$c->get(SystemConfig::class)
324
-				)
325
-			);
326
-		});
327
-
328
-		$this->registerService(\OCP\Encryption\IManager::class, function (Server $c) {
329
-			$view = new View();
330
-			$util = new Encryption\Util(
331
-				$view,
332
-				$c->get(IUserManager::class),
333
-				$c->get(IGroupManager::class),
334
-				$c->get(\OCP\IConfig::class)
335
-			);
336
-			return new Encryption\Manager(
337
-				$c->get(\OCP\IConfig::class),
338
-				$c->get(ILogger::class),
339
-				$c->getL10N('core'),
340
-				new View(),
341
-				$util,
342
-				new ArrayCache()
343
-			);
344
-		});
345
-		/** @deprecated 19.0.0 */
346
-		$this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class);
347
-
348
-		/** @deprecated 21.0.0 */
349
-		$this->registerDeprecatedAlias('EncryptionFileHelper', IFile::class);
350
-		$this->registerService(IFile::class, function (ContainerInterface $c) {
351
-			$util = new Encryption\Util(
352
-				new View(),
353
-				$c->get(IUserManager::class),
354
-				$c->get(IGroupManager::class),
355
-				$c->get(\OCP\IConfig::class)
356
-			);
357
-			return new Encryption\File(
358
-				$util,
359
-				$c->get(IRootFolder::class),
360
-				$c->get(\OCP\Share\IManager::class)
361
-			);
362
-		});
363
-
364
-		/** @deprecated 21.0.0 */
365
-		$this->registerDeprecatedAlias('EncryptionKeyStorage', IStorage::class);
366
-		$this->registerService(IStorage::class, function (ContainerInterface $c) {
367
-			$view = new View();
368
-			$util = new Encryption\Util(
369
-				$view,
370
-				$c->get(IUserManager::class),
371
-				$c->get(IGroupManager::class),
372
-				$c->get(\OCP\IConfig::class)
373
-			);
374
-
375
-			return new Encryption\Keys\Storage(
376
-				$view,
377
-				$util,
378
-				$c->get(ICrypto::class),
379
-				$c->get(\OCP\IConfig::class)
380
-			);
381
-		});
382
-		/** @deprecated 20.0.0 */
383
-		$this->registerDeprecatedAlias('TagMapper', TagMapper::class);
384
-
385
-		$this->registerAlias(\OCP\ITagManager::class, TagManager::class);
386
-		/** @deprecated 19.0.0 */
387
-		$this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class);
388
-
389
-		$this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) {
390
-			/** @var \OCP\IConfig $config */
391
-			$config = $c->get(\OCP\IConfig::class);
392
-			$factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
393
-			return new $factoryClass($this);
394
-		});
395
-		$this->registerService(ISystemTagManager::class, function (ContainerInterface $c) {
396
-			return $c->get('SystemTagManagerFactory')->getManager();
397
-		});
398
-		/** @deprecated 19.0.0 */
399
-		$this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class);
400
-
401
-		$this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) {
402
-			return $c->get('SystemTagManagerFactory')->getObjectMapper();
403
-		});
404
-		$this->registerService('RootFolder', function (ContainerInterface $c) {
405
-			$manager = \OC\Files\Filesystem::getMountManager(null);
406
-			$view = new View();
407
-			$root = new Root(
408
-				$manager,
409
-				$view,
410
-				null,
411
-				$c->get(IUserMountCache::class),
412
-				$this->get(ILogger::class),
413
-				$this->get(IUserManager::class)
414
-			);
415
-
416
-			$previewConnector = new \OC\Preview\WatcherConnector(
417
-				$root,
418
-				$c->get(SystemConfig::class)
419
-			);
420
-			$previewConnector->connectWatcher();
421
-
422
-			return $root;
423
-		});
424
-		$this->registerService(HookConnector::class, function (ContainerInterface $c) {
425
-			return new HookConnector(
426
-				$c->get(IRootFolder::class),
427
-				new View(),
428
-				$c->get(\OC\EventDispatcher\SymfonyAdapter::class),
429
-				$c->get(IEventDispatcher::class)
430
-			);
431
-		});
432
-
433
-		/** @deprecated 19.0.0 */
434
-		$this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class);
435
-
436
-		$this->registerService(IRootFolder::class, function (ContainerInterface $c) {
437
-			return new LazyRoot(function () use ($c) {
438
-				return $c->get('RootFolder');
439
-			});
440
-		});
441
-		/** @deprecated 19.0.0 */
442
-		$this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class);
443
-
444
-		/** @deprecated 19.0.0 */
445
-		$this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class);
446
-		$this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
447
-
448
-		$this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) {
449
-			$groupManager = new \OC\Group\Manager($this->get(IUserManager::class), $c->get(SymfonyAdapter::class), $this->get(ILogger::class));
450
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
451
-				/** @var IEventDispatcher $dispatcher */
452
-				$dispatcher = $this->get(IEventDispatcher::class);
453
-				$dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid));
454
-			});
455
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) {
456
-				/** @var IEventDispatcher $dispatcher */
457
-				$dispatcher = $this->get(IEventDispatcher::class);
458
-				$dispatcher->dispatchTyped(new GroupCreatedEvent($group));
459
-			});
460
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
461
-				/** @var IEventDispatcher $dispatcher */
462
-				$dispatcher = $this->get(IEventDispatcher::class);
463
-				$dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group));
464
-			});
465
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
466
-				/** @var IEventDispatcher $dispatcher */
467
-				$dispatcher = $this->get(IEventDispatcher::class);
468
-				$dispatcher->dispatchTyped(new GroupDeletedEvent($group));
469
-			});
470
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
471
-				/** @var IEventDispatcher $dispatcher */
472
-				$dispatcher = $this->get(IEventDispatcher::class);
473
-				$dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user));
474
-			});
475
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
476
-				/** @var IEventDispatcher $dispatcher */
477
-				$dispatcher = $this->get(IEventDispatcher::class);
478
-				$dispatcher->dispatchTyped(new UserAddedEvent($group, $user));
479
-			});
480
-			$groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
481
-				/** @var IEventDispatcher $dispatcher */
482
-				$dispatcher = $this->get(IEventDispatcher::class);
483
-				$dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user));
484
-			});
485
-			$groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
486
-				/** @var IEventDispatcher $dispatcher */
487
-				$dispatcher = $this->get(IEventDispatcher::class);
488
-				$dispatcher->dispatchTyped(new UserRemovedEvent($group, $user));
489
-			});
490
-			return $groupManager;
491
-		});
492
-		/** @deprecated 19.0.0 */
493
-		$this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class);
494
-
495
-		$this->registerService(Store::class, function (ContainerInterface $c) {
496
-			$session = $c->get(ISession::class);
497
-			if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
498
-				$tokenProvider = $c->get(IProvider::class);
499
-			} else {
500
-				$tokenProvider = null;
501
-			}
502
-			$logger = $c->get(LoggerInterface::class);
503
-			return new Store($session, $logger, $tokenProvider);
504
-		});
505
-		$this->registerAlias(IStore::class, Store::class);
506
-		$this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
507
-
508
-		$this->registerService(\OC\User\Session::class, function (Server $c) {
509
-			$manager = $c->get(IUserManager::class);
510
-			$session = new \OC\Session\Memory('');
511
-			$timeFactory = new TimeFactory();
512
-			// Token providers might require a working database. This code
513
-			// might however be called when ownCloud is not yet setup.
514
-			if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
515
-				$defaultTokenProvider = $c->get(IProvider::class);
516
-			} else {
517
-				$defaultTokenProvider = null;
518
-			}
519
-
520
-			$legacyDispatcher = $c->get(SymfonyAdapter::class);
521
-
522
-			$userSession = new \OC\User\Session(
523
-				$manager,
524
-				$session,
525
-				$timeFactory,
526
-				$defaultTokenProvider,
527
-				$c->get(\OCP\IConfig::class),
528
-				$c->get(ISecureRandom::class),
529
-				$c->getLockdownManager(),
530
-				$c->get(ILogger::class),
531
-				$c->get(IEventDispatcher::class)
532
-			);
533
-			/** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */
534
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
535
-				\OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]);
536
-			});
537
-			/** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */
538
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
539
-				/** @var \OC\User\User $user */
540
-				\OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]);
541
-			});
542
-			/** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */
543
-			$userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) {
544
-				/** @var \OC\User\User $user */
545
-				\OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]);
546
-				$legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
547
-			});
548
-			/** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */
549
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
550
-				/** @var \OC\User\User $user */
551
-				\OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]);
552
-			});
553
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
554
-				/** @var \OC\User\User $user */
555
-				\OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
556
-
557
-				/** @var IEventDispatcher $dispatcher */
558
-				$dispatcher = $this->get(IEventDispatcher::class);
559
-				$dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword));
560
-			});
561
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
562
-				/** @var \OC\User\User $user */
563
-				\OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
564
-
565
-				/** @var IEventDispatcher $dispatcher */
566
-				$dispatcher = $this->get(IEventDispatcher::class);
567
-				$dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword));
568
-			});
569
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
570
-				\OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]);
571
-
572
-				/** @var IEventDispatcher $dispatcher */
573
-				$dispatcher = $this->get(IEventDispatcher::class);
574
-				$dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password));
575
-			});
576
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) {
577
-				/** @var \OC\User\User $user */
578
-				\OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]);
579
-
580
-				/** @var IEventDispatcher $dispatcher */
581
-				$dispatcher = $this->get(IEventDispatcher::class);
582
-				$dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin));
583
-			});
584
-			$userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) {
585
-				/** @var IEventDispatcher $dispatcher */
586
-				$dispatcher = $this->get(IEventDispatcher::class);
587
-				$dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid));
588
-			});
589
-			$userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
590
-				/** @var \OC\User\User $user */
591
-				\OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]);
592
-
593
-				/** @var IEventDispatcher $dispatcher */
594
-				$dispatcher = $this->get(IEventDispatcher::class);
595
-				$dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password));
596
-			});
597
-			$userSession->listen('\OC\User', 'logout', function ($user) {
598
-				\OC_Hook::emit('OC_User', 'logout', []);
599
-
600
-				/** @var IEventDispatcher $dispatcher */
601
-				$dispatcher = $this->get(IEventDispatcher::class);
602
-				$dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user));
603
-			});
604
-			$userSession->listen('\OC\User', 'postLogout', function ($user) {
605
-				/** @var IEventDispatcher $dispatcher */
606
-				$dispatcher = $this->get(IEventDispatcher::class);
607
-				$dispatcher->dispatchTyped(new UserLoggedOutEvent($user));
608
-			});
609
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
610
-				/** @var \OC\User\User $user */
611
-				\OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]);
612
-
613
-				/** @var IEventDispatcher $dispatcher */
614
-				$dispatcher = $this->get(IEventDispatcher::class);
615
-				$dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue));
616
-			});
617
-			return $userSession;
618
-		});
619
-		$this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class);
620
-		/** @deprecated 19.0.0 */
621
-		$this->registerDeprecatedAlias('UserSession', \OC\User\Session::class);
622
-
623
-		$this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class);
624
-
625
-		$this->registerAlias(INavigationManager::class, \OC\NavigationManager::class);
626
-		/** @deprecated 19.0.0 */
627
-		$this->registerDeprecatedAlias('NavigationManager', INavigationManager::class);
628
-
629
-		/** @deprecated 19.0.0 */
630
-		$this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class);
631
-		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
632
-
633
-		$this->registerService(\OC\SystemConfig::class, function ($c) use ($config) {
634
-			return new \OC\SystemConfig($config);
635
-		});
636
-		/** @deprecated 19.0.0 */
637
-		$this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class);
638
-
639
-		/** @deprecated 19.0.0 */
640
-		$this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class);
641
-		$this->registerAlias(IAppConfig::class, \OC\AppConfig::class);
642
-
643
-		$this->registerService(IFactory::class, function (Server $c) {
644
-			return new \OC\L10N\Factory(
645
-				$c->get(\OCP\IConfig::class),
646
-				$c->getRequest(),
647
-				$c->get(IUserSession::class),
648
-				\OC::$SERVERROOT
649
-			);
650
-		});
651
-		/** @deprecated 19.0.0 */
652
-		$this->registerDeprecatedAlias('L10NFactory', IFactory::class);
653
-
654
-		$this->registerAlias(IURLGenerator::class, URLGenerator::class);
655
-		/** @deprecated 19.0.0 */
656
-		$this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class);
657
-
658
-		/** @deprecated 19.0.0 */
659
-		$this->registerDeprecatedAlias('AppFetcher', AppFetcher::class);
660
-		/** @deprecated 19.0.0 */
661
-		$this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class);
662
-
663
-		$this->registerService(ICache::class, function ($c) {
664
-			return new Cache\File();
665
-		});
666
-		/** @deprecated 19.0.0 */
667
-		$this->registerDeprecatedAlias('UserCache', ICache::class);
668
-
669
-		$this->registerService(Factory::class, function (Server $c) {
670
-			$arrayCacheFactory = new \OC\Memcache\Factory('', $c->get(ILogger::class),
671
-				ArrayCache::class,
672
-				ArrayCache::class,
673
-				ArrayCache::class
674
-			);
675
-			/** @var \OCP\IConfig $config */
676
-			$config = $c->get(\OCP\IConfig::class);
677
-
678
-			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
679
-				$v = \OC_App::getAppVersions();
680
-				$v['core'] = implode(',', \OC_Util::getVersion());
681
-				$version = implode(',', $v);
682
-				$instanceId = \OC_Util::getInstanceId();
683
-				$path = \OC::$SERVERROOT;
684
-				$prefix = md5($instanceId . '-' . $version . '-' . $path);
685
-				return new \OC\Memcache\Factory($prefix, $c->get(ILogger::class),
686
-					$config->getSystemValue('memcache.local', null),
687
-					$config->getSystemValue('memcache.distributed', null),
688
-					$config->getSystemValue('memcache.locking', null)
689
-				);
690
-			}
691
-			return $arrayCacheFactory;
692
-		});
693
-		/** @deprecated 19.0.0 */
694
-		$this->registerDeprecatedAlias('MemCacheFactory', Factory::class);
695
-		$this->registerAlias(ICacheFactory::class, Factory::class);
696
-
697
-		$this->registerService('RedisFactory', function (Server $c) {
698
-			$systemConfig = $c->get(SystemConfig::class);
699
-			return new RedisFactory($systemConfig);
700
-		});
701
-
702
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
703
-			$l10n = $this->get(IFactory::class)->get('lib');
704
-			return new \OC\Activity\Manager(
705
-				$c->getRequest(),
706
-				$c->get(IUserSession::class),
707
-				$c->get(\OCP\IConfig::class),
708
-				$c->get(IValidator::class),
709
-				$l10n
710
-			);
711
-		});
712
-		/** @deprecated 19.0.0 */
713
-		$this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class);
714
-
715
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
716
-			return new \OC\Activity\EventMerger(
717
-				$c->getL10N('lib')
718
-			);
719
-		});
720
-		$this->registerAlias(IValidator::class, Validator::class);
721
-
722
-		$this->registerService(AvatarManager::class, function (Server $c) {
723
-			return new AvatarManager(
724
-				$c->get(IUserSession::class),
725
-				$c->get(\OC\User\Manager::class),
726
-				$c->getAppDataDir('avatar'),
727
-				$c->getL10N('lib'),
728
-				$c->get(ILogger::class),
729
-				$c->get(\OCP\IConfig::class),
730
-				$c->get(IAccountManager::class),
731
-				$c->get(KnownUserService::class)
732
-			);
733
-		});
734
-		$this->registerAlias(IAvatarManager::class, AvatarManager::class);
735
-		/** @deprecated 19.0.0 */
736
-		$this->registerDeprecatedAlias('AvatarManager', AvatarManager::class);
737
-
738
-		$this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
739
-		$this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class);
740
-
741
-		$this->registerService(\OC\Log::class, function (Server $c) {
742
-			$logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file');
743
-			$factory = new LogFactory($c, $this->get(SystemConfig::class));
744
-			$logger = $factory->get($logType);
745
-			$registry = $c->get(\OCP\Support\CrashReport\IRegistry::class);
746
-
747
-			return new Log($logger, $this->get(SystemConfig::class), null, $registry);
748
-		});
749
-		$this->registerAlias(ILogger::class, \OC\Log::class);
750
-		/** @deprecated 19.0.0 */
751
-		$this->registerDeprecatedAlias('Logger', \OC\Log::class);
752
-		// PSR-3 logger
753
-		$this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class);
754
-
755
-		$this->registerService(ILogFactory::class, function (Server $c) {
756
-			return new LogFactory($c, $this->get(SystemConfig::class));
757
-		});
758
-
759
-		$this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class);
760
-		/** @deprecated 19.0.0 */
761
-		$this->registerDeprecatedAlias('JobList', IJobList::class);
762
-
763
-		$this->registerService(Router::class, function (Server $c) {
764
-			$cacheFactory = $c->get(ICacheFactory::class);
765
-			$logger = $c->get(ILogger::class);
766
-			if ($cacheFactory->isLocalCacheAvailable()) {
767
-				$router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger);
768
-			} else {
769
-				$router = new \OC\Route\Router($logger);
770
-			}
771
-			return $router;
772
-		});
773
-		$this->registerAlias(IRouter::class, Router::class);
774
-		/** @deprecated 19.0.0 */
775
-		$this->registerDeprecatedAlias('Router', IRouter::class);
776
-
777
-		$this->registerAlias(ISearch::class, Search::class);
778
-		/** @deprecated 19.0.0 */
779
-		$this->registerDeprecatedAlias('Search', ISearch::class);
780
-
781
-		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
782
-			return new \OC\Security\RateLimiting\Backend\MemoryCache(
783
-				$this->get(ICacheFactory::class),
784
-				new \OC\AppFramework\Utility\TimeFactory()
785
-			);
786
-		});
787
-
788
-		$this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class);
789
-		/** @deprecated 19.0.0 */
790
-		$this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
791
-
792
-		$this->registerAlias(ICrypto::class, Crypto::class);
793
-		/** @deprecated 19.0.0 */
794
-		$this->registerDeprecatedAlias('Crypto', ICrypto::class);
795
-
796
-		$this->registerAlias(IHasher::class, Hasher::class);
797
-		/** @deprecated 19.0.0 */
798
-		$this->registerDeprecatedAlias('Hasher', IHasher::class);
799
-
800
-		$this->registerAlias(ICredentialsManager::class, CredentialsManager::class);
801
-		/** @deprecated 19.0.0 */
802
-		$this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class);
803
-
804
-		$this->registerAlias(IDBConnection::class, ConnectionAdapter::class);
805
-		$this->registerService(Connection::class, function (Server $c) {
806
-			$systemConfig = $c->get(SystemConfig::class);
807
-			$factory = new \OC\DB\ConnectionFactory($systemConfig);
808
-			$type = $systemConfig->getValue('dbtype', 'sqlite');
809
-			if (!$factory->isValidType($type)) {
810
-				throw new \OC\DatabaseException('Invalid database type');
811
-			}
812
-			$connectionParams = $factory->createConnectionParams();
813
-			$connection = $factory->getConnection($type, $connectionParams);
814
-			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
815
-			return $connection;
816
-		});
817
-		/** @deprecated 19.0.0 */
818
-		$this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class);
819
-
820
-		$this->registerAlias(ICertificateManager::class, CertificateManager::class);
821
-		$this->registerAlias(IClientService::class, ClientService::class);
822
-		$this->registerDeprecatedAlias('HttpClientService', IClientService::class);
823
-		$this->registerService(IEventLogger::class, function (ContainerInterface $c) {
824
-			$eventLogger = new EventLogger();
825
-			if ($c->get(SystemConfig::class)->getValue('debug', false)) {
826
-				// In debug mode, module is being activated by default
827
-				$eventLogger->activate();
828
-			}
829
-			return $eventLogger;
830
-		});
831
-		/** @deprecated 19.0.0 */
832
-		$this->registerDeprecatedAlias('EventLogger', IEventLogger::class);
833
-
834
-		$this->registerService(IQueryLogger::class, function (ContainerInterface $c) {
835
-			$queryLogger = new QueryLogger();
836
-			if ($c->get(SystemConfig::class)->getValue('debug', false)) {
837
-				// In debug mode, module is being activated by default
838
-				$queryLogger->activate();
839
-			}
840
-			return $queryLogger;
841
-		});
842
-		/** @deprecated 19.0.0 */
843
-		$this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class);
844
-
845
-		/** @deprecated 19.0.0 */
846
-		$this->registerDeprecatedAlias('TempManager', TempManager::class);
847
-		$this->registerAlias(ITempManager::class, TempManager::class);
848
-
849
-		$this->registerService(AppManager::class, function (ContainerInterface $c) {
850
-			// TODO: use auto-wiring
851
-			return new \OC\App\AppManager(
852
-				$c->get(IUserSession::class),
853
-				$c->get(\OCP\IConfig::class),
854
-				$c->get(\OC\AppConfig::class),
855
-				$c->get(IGroupManager::class),
856
-				$c->get(ICacheFactory::class),
857
-				$c->get(SymfonyAdapter::class),
858
-				$c->get(ILogger::class)
859
-			);
860
-		});
861
-		/** @deprecated 19.0.0 */
862
-		$this->registerDeprecatedAlias('AppManager', AppManager::class);
863
-		$this->registerAlias(IAppManager::class, AppManager::class);
864
-
865
-		$this->registerAlias(IDateTimeZone::class, DateTimeZone::class);
866
-		/** @deprecated 19.0.0 */
867
-		$this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class);
868
-
869
-		$this->registerService(IDateTimeFormatter::class, function (Server $c) {
870
-			$language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null);
871
-
872
-			return new DateTimeFormatter(
873
-				$c->get(IDateTimeZone::class)->getTimeZone(),
874
-				$c->getL10N('lib', $language)
875
-			);
876
-		});
877
-		/** @deprecated 19.0.0 */
878
-		$this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class);
879
-
880
-		$this->registerService(IUserMountCache::class, function (ContainerInterface $c) {
881
-			$mountCache = new UserMountCache(
882
-				$c->get(IDBConnection::class),
883
-				$c->get(IUserManager::class),
884
-				$c->get(ILogger::class)
885
-			);
886
-			$listener = new UserMountCacheListener($mountCache);
887
-			$listener->listen($c->get(IUserManager::class));
888
-			return $mountCache;
889
-		});
890
-		/** @deprecated 19.0.0 */
891
-		$this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class);
892
-
893
-		$this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) {
894
-			$loader = \OC\Files\Filesystem::getLoader();
895
-			$mountCache = $c->get(IUserMountCache::class);
896
-			$manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
897
-
898
-			// builtin providers
899
-
900
-			$config = $c->get(\OCP\IConfig::class);
901
-			$logger = $c->get(ILogger::class);
902
-			$manager->registerProvider(new CacheMountProvider($config));
903
-			$manager->registerHomeProvider(new LocalHomeMountProvider());
904
-			$manager->registerHomeProvider(new ObjectHomeMountProvider($config));
905
-			$manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config));
906
-
907
-			return $manager;
908
-		});
909
-		/** @deprecated 19.0.0 */
910
-		$this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class);
911
-
912
-		/** @deprecated 20.0.0 */
913
-		$this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class);
914
-		$this->registerService(IBus::class, function (ContainerInterface $c) {
915
-			$busClass = $c->get(\OCP\IConfig::class)->getSystemValue('commandbus');
916
-			if ($busClass) {
917
-				[$app, $class] = explode('::', $busClass, 2);
918
-				if ($c->get(IAppManager::class)->isInstalled($app)) {
919
-					\OC_App::loadApp($app);
920
-					return $c->get($class);
921
-				} else {
922
-					throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
923
-				}
924
-			} else {
925
-				$jobList = $c->get(IJobList::class);
926
-				return new CronBus($jobList);
927
-			}
928
-		});
929
-		$this->registerDeprecatedAlias('AsyncCommandBus', IBus::class);
930
-		/** @deprecated 20.0.0 */
931
-		$this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class);
932
-		/** @deprecated 19.0.0 */
933
-		$this->registerDeprecatedAlias('Throttler', Throttler::class);
934
-		$this->registerService('IntegrityCodeChecker', function (ContainerInterface $c) {
935
-			// IConfig and IAppManager requires a working database. This code
936
-			// might however be called when ownCloud is not yet setup.
937
-			if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
938
-				$config = $c->get(\OCP\IConfig::class);
939
-				$appManager = $c->get(IAppManager::class);
940
-			} else {
941
-				$config = null;
942
-				$appManager = null;
943
-			}
944
-
945
-			return new Checker(
946
-				new EnvironmentHelper(),
947
-				new FileAccessHelper(),
948
-				new AppLocator(),
949
-				$config,
950
-				$c->get(ICacheFactory::class),
951
-				$appManager,
952
-				$c->get(IMimeTypeDetector::class)
953
-			);
954
-		});
955
-		$this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) {
956
-			if (isset($this['urlParams'])) {
957
-				$urlParams = $this['urlParams'];
958
-			} else {
959
-				$urlParams = [];
960
-			}
961
-
962
-			if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
963
-				&& in_array('fakeinput', stream_get_wrappers())
964
-			) {
965
-				$stream = 'fakeinput://data';
966
-			} else {
967
-				$stream = 'php://input';
968
-			}
969
-
970
-			return new Request(
971
-				[
972
-					'get' => $_GET,
973
-					'post' => $_POST,
974
-					'files' => $_FILES,
975
-					'server' => $_SERVER,
976
-					'env' => $_ENV,
977
-					'cookies' => $_COOKIE,
978
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
979
-						? $_SERVER['REQUEST_METHOD']
980
-						: '',
981
-					'urlParams' => $urlParams,
982
-				],
983
-				$this->get(ISecureRandom::class),
984
-				$this->get(\OCP\IConfig::class),
985
-				$this->get(CsrfTokenManager::class),
986
-				$stream
987
-			);
988
-		});
989
-		/** @deprecated 19.0.0 */
990
-		$this->registerDeprecatedAlias('Request', \OCP\IRequest::class);
991
-
992
-		$this->registerService(IMailer::class, function (Server $c) {
993
-			return new Mailer(
994
-				$c->get(\OCP\IConfig::class),
995
-				$c->get(ILogger::class),
996
-				$c->get(Defaults::class),
997
-				$c->get(IURLGenerator::class),
998
-				$c->getL10N('lib'),
999
-				$c->get(IEventDispatcher::class),
1000
-				$c->get(IFactory::class)
1001
-			);
1002
-		});
1003
-		/** @deprecated 19.0.0 */
1004
-		$this->registerDeprecatedAlias('Mailer', IMailer::class);
1005
-
1006
-		$this->registerService('LDAPProvider', function (ContainerInterface $c) {
1007
-			$config = $c->get(\OCP\IConfig::class);
1008
-			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
1009
-			if (is_null($factoryClass)) {
1010
-				throw new \Exception('ldapProviderFactory not set');
1011
-			}
1012
-			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
1013
-			$factory = new $factoryClass($this);
1014
-			return $factory->getLDAPProvider();
1015
-		});
1016
-		$this->registerService(ILockingProvider::class, function (ContainerInterface $c) {
1017
-			$ini = $c->get(IniGetWrapper::class);
1018
-			$config = $c->get(\OCP\IConfig::class);
1019
-			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
1020
-			if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
1021
-				/** @var \OC\Memcache\Factory $memcacheFactory */
1022
-				$memcacheFactory = $c->get(ICacheFactory::class);
1023
-				$memcache = $memcacheFactory->createLocking('lock');
1024
-				if (!($memcache instanceof \OC\Memcache\NullCache)) {
1025
-					return new MemcacheLockingProvider($memcache, $ttl);
1026
-				}
1027
-				return new DBLockingProvider(
1028
-					$c->get(IDBConnection::class),
1029
-					$c->get(ILogger::class),
1030
-					new TimeFactory(),
1031
-					$ttl,
1032
-					!\OC::$CLI
1033
-				);
1034
-			}
1035
-			return new NoopLockingProvider();
1036
-		});
1037
-		/** @deprecated 19.0.0 */
1038
-		$this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class);
1039
-
1040
-		$this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class);
1041
-		/** @deprecated 19.0.0 */
1042
-		$this->registerDeprecatedAlias('MountManager', IMountManager::class);
1043
-
1044
-		$this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) {
1045
-			return new \OC\Files\Type\Detection(
1046
-				$c->get(IURLGenerator::class),
1047
-				$c->get(ILogger::class),
1048
-				\OC::$configDir,
1049
-				\OC::$SERVERROOT . '/resources/config/'
1050
-			);
1051
-		});
1052
-		/** @deprecated 19.0.0 */
1053
-		$this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class);
1054
-
1055
-		$this->registerAlias(IMimeTypeLoader::class, Loader::class);
1056
-		/** @deprecated 19.0.0 */
1057
-		$this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class);
1058
-		$this->registerService(BundleFetcher::class, function () {
1059
-			return new BundleFetcher($this->getL10N('lib'));
1060
-		});
1061
-		$this->registerAlias(\OCP\Notification\IManager::class, Manager::class);
1062
-		/** @deprecated 19.0.0 */
1063
-		$this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class);
1064
-
1065
-		$this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) {
1066
-			$manager = new CapabilitiesManager($c->get(ILogger::class));
1067
-			$manager->registerCapability(function () use ($c) {
1068
-				return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class));
1069
-			});
1070
-			$manager->registerCapability(function () use ($c) {
1071
-				return $c->get(\OC\Security\Bruteforce\Capabilities::class);
1072
-			});
1073
-			return $manager;
1074
-		});
1075
-		/** @deprecated 19.0.0 */
1076
-		$this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class);
1077
-
1078
-		$this->registerService(ICommentsManager::class, function (Server $c) {
1079
-			$config = $c->get(\OCP\IConfig::class);
1080
-			$factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
1081
-			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
1082
-			$factory = new $factoryClass($this);
1083
-			$manager = $factory->getManager();
1084
-
1085
-			$manager->registerDisplayNameResolver('user', function ($id) use ($c) {
1086
-				$manager = $c->get(IUserManager::class);
1087
-				$user = $manager->get($id);
1088
-				if (is_null($user)) {
1089
-					$l = $c->getL10N('core');
1090
-					$displayName = $l->t('Unknown user');
1091
-				} else {
1092
-					$displayName = $user->getDisplayName();
1093
-				}
1094
-				return $displayName;
1095
-			});
1096
-
1097
-			return $manager;
1098
-		});
1099
-		/** @deprecated 19.0.0 */
1100
-		$this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class);
1101
-
1102
-		$this->registerAlias(\OC_Defaults::class, 'ThemingDefaults');
1103
-		$this->registerService('ThemingDefaults', function (Server $c) {
1104
-			/*
256
+    /** @var string */
257
+    private $webRoot;
258
+
259
+    /**
260
+     * @param string $webRoot
261
+     * @param \OC\Config $config
262
+     */
263
+    public function __construct($webRoot, \OC\Config $config) {
264
+        parent::__construct();
265
+        $this->webRoot = $webRoot;
266
+
267
+        // To find out if we are running from CLI or not
268
+        $this->registerParameter('isCLI', \OC::$CLI);
269
+        $this->registerParameter('serverRoot', \OC::$SERVERROOT);
270
+
271
+        $this->registerService(ContainerInterface::class, function (ContainerInterface $c) {
272
+            return $c;
273
+        });
274
+        $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) {
275
+            return $c;
276
+        });
277
+
278
+        $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
279
+        /** @deprecated 19.0.0 */
280
+        $this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class);
281
+
282
+        $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class);
283
+        /** @deprecated 19.0.0 */
284
+        $this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class);
285
+
286
+        $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class);
287
+        /** @deprecated 19.0.0 */
288
+        $this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class);
289
+
290
+        $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
291
+        /** @deprecated 19.0.0 */
292
+        $this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class);
293
+
294
+        $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class);
295
+        $this->registerAlias(ITemplateManager::class, TemplateManager::class);
296
+
297
+        $this->registerAlias(IActionFactory::class, ActionFactory::class);
298
+
299
+        $this->registerService(View::class, function (Server $c) {
300
+            return new View();
301
+        }, false);
302
+
303
+        $this->registerService(IPreview::class, function (ContainerInterface $c) {
304
+            return new PreviewManager(
305
+                $c->get(\OCP\IConfig::class),
306
+                $c->get(IRootFolder::class),
307
+                new \OC\Preview\Storage\Root(
308
+                    $c->get(IRootFolder::class),
309
+                    $c->get(SystemConfig::class)
310
+                ),
311
+                $c->get(SymfonyAdapter::class),
312
+                $c->get(GeneratorHelper::class),
313
+                $c->get(ISession::class)->get('user_id')
314
+            );
315
+        });
316
+        /** @deprecated 19.0.0 */
317
+        $this->registerDeprecatedAlias('PreviewManager', IPreview::class);
318
+
319
+        $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) {
320
+            return new \OC\Preview\Watcher(
321
+                new \OC\Preview\Storage\Root(
322
+                    $c->get(IRootFolder::class),
323
+                    $c->get(SystemConfig::class)
324
+                )
325
+            );
326
+        });
327
+
328
+        $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) {
329
+            $view = new View();
330
+            $util = new Encryption\Util(
331
+                $view,
332
+                $c->get(IUserManager::class),
333
+                $c->get(IGroupManager::class),
334
+                $c->get(\OCP\IConfig::class)
335
+            );
336
+            return new Encryption\Manager(
337
+                $c->get(\OCP\IConfig::class),
338
+                $c->get(ILogger::class),
339
+                $c->getL10N('core'),
340
+                new View(),
341
+                $util,
342
+                new ArrayCache()
343
+            );
344
+        });
345
+        /** @deprecated 19.0.0 */
346
+        $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class);
347
+
348
+        /** @deprecated 21.0.0 */
349
+        $this->registerDeprecatedAlias('EncryptionFileHelper', IFile::class);
350
+        $this->registerService(IFile::class, function (ContainerInterface $c) {
351
+            $util = new Encryption\Util(
352
+                new View(),
353
+                $c->get(IUserManager::class),
354
+                $c->get(IGroupManager::class),
355
+                $c->get(\OCP\IConfig::class)
356
+            );
357
+            return new Encryption\File(
358
+                $util,
359
+                $c->get(IRootFolder::class),
360
+                $c->get(\OCP\Share\IManager::class)
361
+            );
362
+        });
363
+
364
+        /** @deprecated 21.0.0 */
365
+        $this->registerDeprecatedAlias('EncryptionKeyStorage', IStorage::class);
366
+        $this->registerService(IStorage::class, function (ContainerInterface $c) {
367
+            $view = new View();
368
+            $util = new Encryption\Util(
369
+                $view,
370
+                $c->get(IUserManager::class),
371
+                $c->get(IGroupManager::class),
372
+                $c->get(\OCP\IConfig::class)
373
+            );
374
+
375
+            return new Encryption\Keys\Storage(
376
+                $view,
377
+                $util,
378
+                $c->get(ICrypto::class),
379
+                $c->get(\OCP\IConfig::class)
380
+            );
381
+        });
382
+        /** @deprecated 20.0.0 */
383
+        $this->registerDeprecatedAlias('TagMapper', TagMapper::class);
384
+
385
+        $this->registerAlias(\OCP\ITagManager::class, TagManager::class);
386
+        /** @deprecated 19.0.0 */
387
+        $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class);
388
+
389
+        $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) {
390
+            /** @var \OCP\IConfig $config */
391
+            $config = $c->get(\OCP\IConfig::class);
392
+            $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
393
+            return new $factoryClass($this);
394
+        });
395
+        $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) {
396
+            return $c->get('SystemTagManagerFactory')->getManager();
397
+        });
398
+        /** @deprecated 19.0.0 */
399
+        $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class);
400
+
401
+        $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) {
402
+            return $c->get('SystemTagManagerFactory')->getObjectMapper();
403
+        });
404
+        $this->registerService('RootFolder', function (ContainerInterface $c) {
405
+            $manager = \OC\Files\Filesystem::getMountManager(null);
406
+            $view = new View();
407
+            $root = new Root(
408
+                $manager,
409
+                $view,
410
+                null,
411
+                $c->get(IUserMountCache::class),
412
+                $this->get(ILogger::class),
413
+                $this->get(IUserManager::class)
414
+            );
415
+
416
+            $previewConnector = new \OC\Preview\WatcherConnector(
417
+                $root,
418
+                $c->get(SystemConfig::class)
419
+            );
420
+            $previewConnector->connectWatcher();
421
+
422
+            return $root;
423
+        });
424
+        $this->registerService(HookConnector::class, function (ContainerInterface $c) {
425
+            return new HookConnector(
426
+                $c->get(IRootFolder::class),
427
+                new View(),
428
+                $c->get(\OC\EventDispatcher\SymfonyAdapter::class),
429
+                $c->get(IEventDispatcher::class)
430
+            );
431
+        });
432
+
433
+        /** @deprecated 19.0.0 */
434
+        $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class);
435
+
436
+        $this->registerService(IRootFolder::class, function (ContainerInterface $c) {
437
+            return new LazyRoot(function () use ($c) {
438
+                return $c->get('RootFolder');
439
+            });
440
+        });
441
+        /** @deprecated 19.0.0 */
442
+        $this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class);
443
+
444
+        /** @deprecated 19.0.0 */
445
+        $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class);
446
+        $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
447
+
448
+        $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) {
449
+            $groupManager = new \OC\Group\Manager($this->get(IUserManager::class), $c->get(SymfonyAdapter::class), $this->get(ILogger::class));
450
+            $groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
451
+                /** @var IEventDispatcher $dispatcher */
452
+                $dispatcher = $this->get(IEventDispatcher::class);
453
+                $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid));
454
+            });
455
+            $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) {
456
+                /** @var IEventDispatcher $dispatcher */
457
+                $dispatcher = $this->get(IEventDispatcher::class);
458
+                $dispatcher->dispatchTyped(new GroupCreatedEvent($group));
459
+            });
460
+            $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
461
+                /** @var IEventDispatcher $dispatcher */
462
+                $dispatcher = $this->get(IEventDispatcher::class);
463
+                $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group));
464
+            });
465
+            $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
466
+                /** @var IEventDispatcher $dispatcher */
467
+                $dispatcher = $this->get(IEventDispatcher::class);
468
+                $dispatcher->dispatchTyped(new GroupDeletedEvent($group));
469
+            });
470
+            $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
471
+                /** @var IEventDispatcher $dispatcher */
472
+                $dispatcher = $this->get(IEventDispatcher::class);
473
+                $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user));
474
+            });
475
+            $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
476
+                /** @var IEventDispatcher $dispatcher */
477
+                $dispatcher = $this->get(IEventDispatcher::class);
478
+                $dispatcher->dispatchTyped(new UserAddedEvent($group, $user));
479
+            });
480
+            $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
481
+                /** @var IEventDispatcher $dispatcher */
482
+                $dispatcher = $this->get(IEventDispatcher::class);
483
+                $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user));
484
+            });
485
+            $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
486
+                /** @var IEventDispatcher $dispatcher */
487
+                $dispatcher = $this->get(IEventDispatcher::class);
488
+                $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user));
489
+            });
490
+            return $groupManager;
491
+        });
492
+        /** @deprecated 19.0.0 */
493
+        $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class);
494
+
495
+        $this->registerService(Store::class, function (ContainerInterface $c) {
496
+            $session = $c->get(ISession::class);
497
+            if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
498
+                $tokenProvider = $c->get(IProvider::class);
499
+            } else {
500
+                $tokenProvider = null;
501
+            }
502
+            $logger = $c->get(LoggerInterface::class);
503
+            return new Store($session, $logger, $tokenProvider);
504
+        });
505
+        $this->registerAlias(IStore::class, Store::class);
506
+        $this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
507
+
508
+        $this->registerService(\OC\User\Session::class, function (Server $c) {
509
+            $manager = $c->get(IUserManager::class);
510
+            $session = new \OC\Session\Memory('');
511
+            $timeFactory = new TimeFactory();
512
+            // Token providers might require a working database. This code
513
+            // might however be called when ownCloud is not yet setup.
514
+            if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
515
+                $defaultTokenProvider = $c->get(IProvider::class);
516
+            } else {
517
+                $defaultTokenProvider = null;
518
+            }
519
+
520
+            $legacyDispatcher = $c->get(SymfonyAdapter::class);
521
+
522
+            $userSession = new \OC\User\Session(
523
+                $manager,
524
+                $session,
525
+                $timeFactory,
526
+                $defaultTokenProvider,
527
+                $c->get(\OCP\IConfig::class),
528
+                $c->get(ISecureRandom::class),
529
+                $c->getLockdownManager(),
530
+                $c->get(ILogger::class),
531
+                $c->get(IEventDispatcher::class)
532
+            );
533
+            /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */
534
+            $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
535
+                \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]);
536
+            });
537
+            /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */
538
+            $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
539
+                /** @var \OC\User\User $user */
540
+                \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]);
541
+            });
542
+            /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */
543
+            $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) {
544
+                /** @var \OC\User\User $user */
545
+                \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]);
546
+                $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
547
+            });
548
+            /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */
549
+            $userSession->listen('\OC\User', 'postDelete', function ($user) {
550
+                /** @var \OC\User\User $user */
551
+                \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]);
552
+            });
553
+            $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
554
+                /** @var \OC\User\User $user */
555
+                \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
556
+
557
+                /** @var IEventDispatcher $dispatcher */
558
+                $dispatcher = $this->get(IEventDispatcher::class);
559
+                $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword));
560
+            });
561
+            $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
562
+                /** @var \OC\User\User $user */
563
+                \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
564
+
565
+                /** @var IEventDispatcher $dispatcher */
566
+                $dispatcher = $this->get(IEventDispatcher::class);
567
+                $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword));
568
+            });
569
+            $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
570
+                \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]);
571
+
572
+                /** @var IEventDispatcher $dispatcher */
573
+                $dispatcher = $this->get(IEventDispatcher::class);
574
+                $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password));
575
+            });
576
+            $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) {
577
+                /** @var \OC\User\User $user */
578
+                \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]);
579
+
580
+                /** @var IEventDispatcher $dispatcher */
581
+                $dispatcher = $this->get(IEventDispatcher::class);
582
+                $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin));
583
+            });
584
+            $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) {
585
+                /** @var IEventDispatcher $dispatcher */
586
+                $dispatcher = $this->get(IEventDispatcher::class);
587
+                $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid));
588
+            });
589
+            $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
590
+                /** @var \OC\User\User $user */
591
+                \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]);
592
+
593
+                /** @var IEventDispatcher $dispatcher */
594
+                $dispatcher = $this->get(IEventDispatcher::class);
595
+                $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password));
596
+            });
597
+            $userSession->listen('\OC\User', 'logout', function ($user) {
598
+                \OC_Hook::emit('OC_User', 'logout', []);
599
+
600
+                /** @var IEventDispatcher $dispatcher */
601
+                $dispatcher = $this->get(IEventDispatcher::class);
602
+                $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user));
603
+            });
604
+            $userSession->listen('\OC\User', 'postLogout', function ($user) {
605
+                /** @var IEventDispatcher $dispatcher */
606
+                $dispatcher = $this->get(IEventDispatcher::class);
607
+                $dispatcher->dispatchTyped(new UserLoggedOutEvent($user));
608
+            });
609
+            $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
610
+                /** @var \OC\User\User $user */
611
+                \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]);
612
+
613
+                /** @var IEventDispatcher $dispatcher */
614
+                $dispatcher = $this->get(IEventDispatcher::class);
615
+                $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue));
616
+            });
617
+            return $userSession;
618
+        });
619
+        $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class);
620
+        /** @deprecated 19.0.0 */
621
+        $this->registerDeprecatedAlias('UserSession', \OC\User\Session::class);
622
+
623
+        $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class);
624
+
625
+        $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class);
626
+        /** @deprecated 19.0.0 */
627
+        $this->registerDeprecatedAlias('NavigationManager', INavigationManager::class);
628
+
629
+        /** @deprecated 19.0.0 */
630
+        $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class);
631
+        $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
632
+
633
+        $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) {
634
+            return new \OC\SystemConfig($config);
635
+        });
636
+        /** @deprecated 19.0.0 */
637
+        $this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class);
638
+
639
+        /** @deprecated 19.0.0 */
640
+        $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class);
641
+        $this->registerAlias(IAppConfig::class, \OC\AppConfig::class);
642
+
643
+        $this->registerService(IFactory::class, function (Server $c) {
644
+            return new \OC\L10N\Factory(
645
+                $c->get(\OCP\IConfig::class),
646
+                $c->getRequest(),
647
+                $c->get(IUserSession::class),
648
+                \OC::$SERVERROOT
649
+            );
650
+        });
651
+        /** @deprecated 19.0.0 */
652
+        $this->registerDeprecatedAlias('L10NFactory', IFactory::class);
653
+
654
+        $this->registerAlias(IURLGenerator::class, URLGenerator::class);
655
+        /** @deprecated 19.0.0 */
656
+        $this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class);
657
+
658
+        /** @deprecated 19.0.0 */
659
+        $this->registerDeprecatedAlias('AppFetcher', AppFetcher::class);
660
+        /** @deprecated 19.0.0 */
661
+        $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class);
662
+
663
+        $this->registerService(ICache::class, function ($c) {
664
+            return new Cache\File();
665
+        });
666
+        /** @deprecated 19.0.0 */
667
+        $this->registerDeprecatedAlias('UserCache', ICache::class);
668
+
669
+        $this->registerService(Factory::class, function (Server $c) {
670
+            $arrayCacheFactory = new \OC\Memcache\Factory('', $c->get(ILogger::class),
671
+                ArrayCache::class,
672
+                ArrayCache::class,
673
+                ArrayCache::class
674
+            );
675
+            /** @var \OCP\IConfig $config */
676
+            $config = $c->get(\OCP\IConfig::class);
677
+
678
+            if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
679
+                $v = \OC_App::getAppVersions();
680
+                $v['core'] = implode(',', \OC_Util::getVersion());
681
+                $version = implode(',', $v);
682
+                $instanceId = \OC_Util::getInstanceId();
683
+                $path = \OC::$SERVERROOT;
684
+                $prefix = md5($instanceId . '-' . $version . '-' . $path);
685
+                return new \OC\Memcache\Factory($prefix, $c->get(ILogger::class),
686
+                    $config->getSystemValue('memcache.local', null),
687
+                    $config->getSystemValue('memcache.distributed', null),
688
+                    $config->getSystemValue('memcache.locking', null)
689
+                );
690
+            }
691
+            return $arrayCacheFactory;
692
+        });
693
+        /** @deprecated 19.0.0 */
694
+        $this->registerDeprecatedAlias('MemCacheFactory', Factory::class);
695
+        $this->registerAlias(ICacheFactory::class, Factory::class);
696
+
697
+        $this->registerService('RedisFactory', function (Server $c) {
698
+            $systemConfig = $c->get(SystemConfig::class);
699
+            return new RedisFactory($systemConfig);
700
+        });
701
+
702
+        $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
703
+            $l10n = $this->get(IFactory::class)->get('lib');
704
+            return new \OC\Activity\Manager(
705
+                $c->getRequest(),
706
+                $c->get(IUserSession::class),
707
+                $c->get(\OCP\IConfig::class),
708
+                $c->get(IValidator::class),
709
+                $l10n
710
+            );
711
+        });
712
+        /** @deprecated 19.0.0 */
713
+        $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class);
714
+
715
+        $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
716
+            return new \OC\Activity\EventMerger(
717
+                $c->getL10N('lib')
718
+            );
719
+        });
720
+        $this->registerAlias(IValidator::class, Validator::class);
721
+
722
+        $this->registerService(AvatarManager::class, function (Server $c) {
723
+            return new AvatarManager(
724
+                $c->get(IUserSession::class),
725
+                $c->get(\OC\User\Manager::class),
726
+                $c->getAppDataDir('avatar'),
727
+                $c->getL10N('lib'),
728
+                $c->get(ILogger::class),
729
+                $c->get(\OCP\IConfig::class),
730
+                $c->get(IAccountManager::class),
731
+                $c->get(KnownUserService::class)
732
+            );
733
+        });
734
+        $this->registerAlias(IAvatarManager::class, AvatarManager::class);
735
+        /** @deprecated 19.0.0 */
736
+        $this->registerDeprecatedAlias('AvatarManager', AvatarManager::class);
737
+
738
+        $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
739
+        $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class);
740
+
741
+        $this->registerService(\OC\Log::class, function (Server $c) {
742
+            $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file');
743
+            $factory = new LogFactory($c, $this->get(SystemConfig::class));
744
+            $logger = $factory->get($logType);
745
+            $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class);
746
+
747
+            return new Log($logger, $this->get(SystemConfig::class), null, $registry);
748
+        });
749
+        $this->registerAlias(ILogger::class, \OC\Log::class);
750
+        /** @deprecated 19.0.0 */
751
+        $this->registerDeprecatedAlias('Logger', \OC\Log::class);
752
+        // PSR-3 logger
753
+        $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class);
754
+
755
+        $this->registerService(ILogFactory::class, function (Server $c) {
756
+            return new LogFactory($c, $this->get(SystemConfig::class));
757
+        });
758
+
759
+        $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class);
760
+        /** @deprecated 19.0.0 */
761
+        $this->registerDeprecatedAlias('JobList', IJobList::class);
762
+
763
+        $this->registerService(Router::class, function (Server $c) {
764
+            $cacheFactory = $c->get(ICacheFactory::class);
765
+            $logger = $c->get(ILogger::class);
766
+            if ($cacheFactory->isLocalCacheAvailable()) {
767
+                $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger);
768
+            } else {
769
+                $router = new \OC\Route\Router($logger);
770
+            }
771
+            return $router;
772
+        });
773
+        $this->registerAlias(IRouter::class, Router::class);
774
+        /** @deprecated 19.0.0 */
775
+        $this->registerDeprecatedAlias('Router', IRouter::class);
776
+
777
+        $this->registerAlias(ISearch::class, Search::class);
778
+        /** @deprecated 19.0.0 */
779
+        $this->registerDeprecatedAlias('Search', ISearch::class);
780
+
781
+        $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
782
+            return new \OC\Security\RateLimiting\Backend\MemoryCache(
783
+                $this->get(ICacheFactory::class),
784
+                new \OC\AppFramework\Utility\TimeFactory()
785
+            );
786
+        });
787
+
788
+        $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class);
789
+        /** @deprecated 19.0.0 */
790
+        $this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
791
+
792
+        $this->registerAlias(ICrypto::class, Crypto::class);
793
+        /** @deprecated 19.0.0 */
794
+        $this->registerDeprecatedAlias('Crypto', ICrypto::class);
795
+
796
+        $this->registerAlias(IHasher::class, Hasher::class);
797
+        /** @deprecated 19.0.0 */
798
+        $this->registerDeprecatedAlias('Hasher', IHasher::class);
799
+
800
+        $this->registerAlias(ICredentialsManager::class, CredentialsManager::class);
801
+        /** @deprecated 19.0.0 */
802
+        $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class);
803
+
804
+        $this->registerAlias(IDBConnection::class, ConnectionAdapter::class);
805
+        $this->registerService(Connection::class, function (Server $c) {
806
+            $systemConfig = $c->get(SystemConfig::class);
807
+            $factory = new \OC\DB\ConnectionFactory($systemConfig);
808
+            $type = $systemConfig->getValue('dbtype', 'sqlite');
809
+            if (!$factory->isValidType($type)) {
810
+                throw new \OC\DatabaseException('Invalid database type');
811
+            }
812
+            $connectionParams = $factory->createConnectionParams();
813
+            $connection = $factory->getConnection($type, $connectionParams);
814
+            $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
815
+            return $connection;
816
+        });
817
+        /** @deprecated 19.0.0 */
818
+        $this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class);
819
+
820
+        $this->registerAlias(ICertificateManager::class, CertificateManager::class);
821
+        $this->registerAlias(IClientService::class, ClientService::class);
822
+        $this->registerDeprecatedAlias('HttpClientService', IClientService::class);
823
+        $this->registerService(IEventLogger::class, function (ContainerInterface $c) {
824
+            $eventLogger = new EventLogger();
825
+            if ($c->get(SystemConfig::class)->getValue('debug', false)) {
826
+                // In debug mode, module is being activated by default
827
+                $eventLogger->activate();
828
+            }
829
+            return $eventLogger;
830
+        });
831
+        /** @deprecated 19.0.0 */
832
+        $this->registerDeprecatedAlias('EventLogger', IEventLogger::class);
833
+
834
+        $this->registerService(IQueryLogger::class, function (ContainerInterface $c) {
835
+            $queryLogger = new QueryLogger();
836
+            if ($c->get(SystemConfig::class)->getValue('debug', false)) {
837
+                // In debug mode, module is being activated by default
838
+                $queryLogger->activate();
839
+            }
840
+            return $queryLogger;
841
+        });
842
+        /** @deprecated 19.0.0 */
843
+        $this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class);
844
+
845
+        /** @deprecated 19.0.0 */
846
+        $this->registerDeprecatedAlias('TempManager', TempManager::class);
847
+        $this->registerAlias(ITempManager::class, TempManager::class);
848
+
849
+        $this->registerService(AppManager::class, function (ContainerInterface $c) {
850
+            // TODO: use auto-wiring
851
+            return new \OC\App\AppManager(
852
+                $c->get(IUserSession::class),
853
+                $c->get(\OCP\IConfig::class),
854
+                $c->get(\OC\AppConfig::class),
855
+                $c->get(IGroupManager::class),
856
+                $c->get(ICacheFactory::class),
857
+                $c->get(SymfonyAdapter::class),
858
+                $c->get(ILogger::class)
859
+            );
860
+        });
861
+        /** @deprecated 19.0.0 */
862
+        $this->registerDeprecatedAlias('AppManager', AppManager::class);
863
+        $this->registerAlias(IAppManager::class, AppManager::class);
864
+
865
+        $this->registerAlias(IDateTimeZone::class, DateTimeZone::class);
866
+        /** @deprecated 19.0.0 */
867
+        $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class);
868
+
869
+        $this->registerService(IDateTimeFormatter::class, function (Server $c) {
870
+            $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null);
871
+
872
+            return new DateTimeFormatter(
873
+                $c->get(IDateTimeZone::class)->getTimeZone(),
874
+                $c->getL10N('lib', $language)
875
+            );
876
+        });
877
+        /** @deprecated 19.0.0 */
878
+        $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class);
879
+
880
+        $this->registerService(IUserMountCache::class, function (ContainerInterface $c) {
881
+            $mountCache = new UserMountCache(
882
+                $c->get(IDBConnection::class),
883
+                $c->get(IUserManager::class),
884
+                $c->get(ILogger::class)
885
+            );
886
+            $listener = new UserMountCacheListener($mountCache);
887
+            $listener->listen($c->get(IUserManager::class));
888
+            return $mountCache;
889
+        });
890
+        /** @deprecated 19.0.0 */
891
+        $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class);
892
+
893
+        $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) {
894
+            $loader = \OC\Files\Filesystem::getLoader();
895
+            $mountCache = $c->get(IUserMountCache::class);
896
+            $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
897
+
898
+            // builtin providers
899
+
900
+            $config = $c->get(\OCP\IConfig::class);
901
+            $logger = $c->get(ILogger::class);
902
+            $manager->registerProvider(new CacheMountProvider($config));
903
+            $manager->registerHomeProvider(new LocalHomeMountProvider());
904
+            $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
905
+            $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config));
906
+
907
+            return $manager;
908
+        });
909
+        /** @deprecated 19.0.0 */
910
+        $this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class);
911
+
912
+        /** @deprecated 20.0.0 */
913
+        $this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class);
914
+        $this->registerService(IBus::class, function (ContainerInterface $c) {
915
+            $busClass = $c->get(\OCP\IConfig::class)->getSystemValue('commandbus');
916
+            if ($busClass) {
917
+                [$app, $class] = explode('::', $busClass, 2);
918
+                if ($c->get(IAppManager::class)->isInstalled($app)) {
919
+                    \OC_App::loadApp($app);
920
+                    return $c->get($class);
921
+                } else {
922
+                    throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
923
+                }
924
+            } else {
925
+                $jobList = $c->get(IJobList::class);
926
+                return new CronBus($jobList);
927
+            }
928
+        });
929
+        $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class);
930
+        /** @deprecated 20.0.0 */
931
+        $this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class);
932
+        /** @deprecated 19.0.0 */
933
+        $this->registerDeprecatedAlias('Throttler', Throttler::class);
934
+        $this->registerService('IntegrityCodeChecker', function (ContainerInterface $c) {
935
+            // IConfig and IAppManager requires a working database. This code
936
+            // might however be called when ownCloud is not yet setup.
937
+            if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
938
+                $config = $c->get(\OCP\IConfig::class);
939
+                $appManager = $c->get(IAppManager::class);
940
+            } else {
941
+                $config = null;
942
+                $appManager = null;
943
+            }
944
+
945
+            return new Checker(
946
+                new EnvironmentHelper(),
947
+                new FileAccessHelper(),
948
+                new AppLocator(),
949
+                $config,
950
+                $c->get(ICacheFactory::class),
951
+                $appManager,
952
+                $c->get(IMimeTypeDetector::class)
953
+            );
954
+        });
955
+        $this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) {
956
+            if (isset($this['urlParams'])) {
957
+                $urlParams = $this['urlParams'];
958
+            } else {
959
+                $urlParams = [];
960
+            }
961
+
962
+            if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
963
+                && in_array('fakeinput', stream_get_wrappers())
964
+            ) {
965
+                $stream = 'fakeinput://data';
966
+            } else {
967
+                $stream = 'php://input';
968
+            }
969
+
970
+            return new Request(
971
+                [
972
+                    'get' => $_GET,
973
+                    'post' => $_POST,
974
+                    'files' => $_FILES,
975
+                    'server' => $_SERVER,
976
+                    'env' => $_ENV,
977
+                    'cookies' => $_COOKIE,
978
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
979
+                        ? $_SERVER['REQUEST_METHOD']
980
+                        : '',
981
+                    'urlParams' => $urlParams,
982
+                ],
983
+                $this->get(ISecureRandom::class),
984
+                $this->get(\OCP\IConfig::class),
985
+                $this->get(CsrfTokenManager::class),
986
+                $stream
987
+            );
988
+        });
989
+        /** @deprecated 19.0.0 */
990
+        $this->registerDeprecatedAlias('Request', \OCP\IRequest::class);
991
+
992
+        $this->registerService(IMailer::class, function (Server $c) {
993
+            return new Mailer(
994
+                $c->get(\OCP\IConfig::class),
995
+                $c->get(ILogger::class),
996
+                $c->get(Defaults::class),
997
+                $c->get(IURLGenerator::class),
998
+                $c->getL10N('lib'),
999
+                $c->get(IEventDispatcher::class),
1000
+                $c->get(IFactory::class)
1001
+            );
1002
+        });
1003
+        /** @deprecated 19.0.0 */
1004
+        $this->registerDeprecatedAlias('Mailer', IMailer::class);
1005
+
1006
+        $this->registerService('LDAPProvider', function (ContainerInterface $c) {
1007
+            $config = $c->get(\OCP\IConfig::class);
1008
+            $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
1009
+            if (is_null($factoryClass)) {
1010
+                throw new \Exception('ldapProviderFactory not set');
1011
+            }
1012
+            /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
1013
+            $factory = new $factoryClass($this);
1014
+            return $factory->getLDAPProvider();
1015
+        });
1016
+        $this->registerService(ILockingProvider::class, function (ContainerInterface $c) {
1017
+            $ini = $c->get(IniGetWrapper::class);
1018
+            $config = $c->get(\OCP\IConfig::class);
1019
+            $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
1020
+            if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
1021
+                /** @var \OC\Memcache\Factory $memcacheFactory */
1022
+                $memcacheFactory = $c->get(ICacheFactory::class);
1023
+                $memcache = $memcacheFactory->createLocking('lock');
1024
+                if (!($memcache instanceof \OC\Memcache\NullCache)) {
1025
+                    return new MemcacheLockingProvider($memcache, $ttl);
1026
+                }
1027
+                return new DBLockingProvider(
1028
+                    $c->get(IDBConnection::class),
1029
+                    $c->get(ILogger::class),
1030
+                    new TimeFactory(),
1031
+                    $ttl,
1032
+                    !\OC::$CLI
1033
+                );
1034
+            }
1035
+            return new NoopLockingProvider();
1036
+        });
1037
+        /** @deprecated 19.0.0 */
1038
+        $this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class);
1039
+
1040
+        $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class);
1041
+        /** @deprecated 19.0.0 */
1042
+        $this->registerDeprecatedAlias('MountManager', IMountManager::class);
1043
+
1044
+        $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) {
1045
+            return new \OC\Files\Type\Detection(
1046
+                $c->get(IURLGenerator::class),
1047
+                $c->get(ILogger::class),
1048
+                \OC::$configDir,
1049
+                \OC::$SERVERROOT . '/resources/config/'
1050
+            );
1051
+        });
1052
+        /** @deprecated 19.0.0 */
1053
+        $this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class);
1054
+
1055
+        $this->registerAlias(IMimeTypeLoader::class, Loader::class);
1056
+        /** @deprecated 19.0.0 */
1057
+        $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class);
1058
+        $this->registerService(BundleFetcher::class, function () {
1059
+            return new BundleFetcher($this->getL10N('lib'));
1060
+        });
1061
+        $this->registerAlias(\OCP\Notification\IManager::class, Manager::class);
1062
+        /** @deprecated 19.0.0 */
1063
+        $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class);
1064
+
1065
+        $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) {
1066
+            $manager = new CapabilitiesManager($c->get(ILogger::class));
1067
+            $manager->registerCapability(function () use ($c) {
1068
+                return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class));
1069
+            });
1070
+            $manager->registerCapability(function () use ($c) {
1071
+                return $c->get(\OC\Security\Bruteforce\Capabilities::class);
1072
+            });
1073
+            return $manager;
1074
+        });
1075
+        /** @deprecated 19.0.0 */
1076
+        $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class);
1077
+
1078
+        $this->registerService(ICommentsManager::class, function (Server $c) {
1079
+            $config = $c->get(\OCP\IConfig::class);
1080
+            $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
1081
+            /** @var \OCP\Comments\ICommentsManagerFactory $factory */
1082
+            $factory = new $factoryClass($this);
1083
+            $manager = $factory->getManager();
1084
+
1085
+            $manager->registerDisplayNameResolver('user', function ($id) use ($c) {
1086
+                $manager = $c->get(IUserManager::class);
1087
+                $user = $manager->get($id);
1088
+                if (is_null($user)) {
1089
+                    $l = $c->getL10N('core');
1090
+                    $displayName = $l->t('Unknown user');
1091
+                } else {
1092
+                    $displayName = $user->getDisplayName();
1093
+                }
1094
+                return $displayName;
1095
+            });
1096
+
1097
+            return $manager;
1098
+        });
1099
+        /** @deprecated 19.0.0 */
1100
+        $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class);
1101
+
1102
+        $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults');
1103
+        $this->registerService('ThemingDefaults', function (Server $c) {
1104
+            /*
1105 1105
 			 * Dark magic for autoloader.
1106 1106
 			 * If we do a class_exists it will try to load the class which will
1107 1107
 			 * make composer cache the result. Resulting in errors when enabling
1108 1108
 			 * the theming app.
1109 1109
 			 */
1110
-			$prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
1111
-			if (isset($prefixes['OCA\\Theming\\'])) {
1112
-				$classExists = true;
1113
-			} else {
1114
-				$classExists = false;
1115
-			}
1116
-
1117
-			if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValue('installed', false) && $c->get(IAppManager::class)->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
1118
-				return new ThemingDefaults(
1119
-					$c->get(\OCP\IConfig::class),
1120
-					$c->getL10N('theming'),
1121
-					$c->get(IURLGenerator::class),
1122
-					$c->get(ICacheFactory::class),
1123
-					new Util($c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming')),
1124
-					new ImageManager(
1125
-						$c->get(\OCP\IConfig::class),
1126
-						$c->getAppDataDir('theming'),
1127
-						$c->get(IURLGenerator::class),
1128
-						$this->get(ICacheFactory::class),
1129
-						$this->get(ILogger::class),
1130
-						$this->get(ITempManager::class)
1131
-					),
1132
-					$c->get(IAppManager::class),
1133
-					$c->get(INavigationManager::class)
1134
-				);
1135
-			}
1136
-			return new \OC_Defaults();
1137
-		});
1138
-		$this->registerService(JSCombiner::class, function (Server $c) {
1139
-			return new JSCombiner(
1140
-				$c->getAppDataDir('js'),
1141
-				$c->get(IURLGenerator::class),
1142
-				$this->get(ICacheFactory::class),
1143
-				$c->get(SystemConfig::class),
1144
-				$c->get(ILogger::class)
1145
-			);
1146
-		});
1147
-		$this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class);
1148
-		/** @deprecated 19.0.0 */
1149
-		$this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class);
1150
-		$this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class);
1151
-
1152
-		$this->registerService('CryptoWrapper', function (ContainerInterface $c) {
1153
-			// FIXME: Instantiiated here due to cyclic dependency
1154
-			$request = new Request(
1155
-				[
1156
-					'get' => $_GET,
1157
-					'post' => $_POST,
1158
-					'files' => $_FILES,
1159
-					'server' => $_SERVER,
1160
-					'env' => $_ENV,
1161
-					'cookies' => $_COOKIE,
1162
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
1163
-						? $_SERVER['REQUEST_METHOD']
1164
-						: null,
1165
-				],
1166
-				$c->get(ISecureRandom::class),
1167
-				$c->get(\OCP\IConfig::class)
1168
-			);
1169
-
1170
-			return new CryptoWrapper(
1171
-				$c->get(\OCP\IConfig::class),
1172
-				$c->get(ICrypto::class),
1173
-				$c->get(ISecureRandom::class),
1174
-				$request
1175
-			);
1176
-		});
1177
-		/** @deprecated 19.0.0 */
1178
-		$this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class);
1179
-		$this->registerService(SessionStorage::class, function (ContainerInterface $c) {
1180
-			return new SessionStorage($c->get(ISession::class));
1181
-		});
1182
-		$this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class);
1183
-		/** @deprecated 19.0.0 */
1184
-		$this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class);
1185
-
1186
-		$this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) {
1187
-			$config = $c->get(\OCP\IConfig::class);
1188
-			$factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
1189
-			/** @var \OCP\Share\IProviderFactory $factory */
1190
-			$factory = new $factoryClass($this);
1191
-
1192
-			$manager = new \OC\Share20\Manager(
1193
-				$c->get(ILogger::class),
1194
-				$c->get(\OCP\IConfig::class),
1195
-				$c->get(ISecureRandom::class),
1196
-				$c->get(IHasher::class),
1197
-				$c->get(IMountManager::class),
1198
-				$c->get(IGroupManager::class),
1199
-				$c->getL10N('lib'),
1200
-				$c->get(IFactory::class),
1201
-				$factory,
1202
-				$c->get(IUserManager::class),
1203
-				$c->get(IRootFolder::class),
1204
-				$c->get(SymfonyAdapter::class),
1205
-				$c->get(IMailer::class),
1206
-				$c->get(IURLGenerator::class),
1207
-				$c->get('ThemingDefaults'),
1208
-				$c->get(IEventDispatcher::class)
1209
-			);
1210
-
1211
-			return $manager;
1212
-		});
1213
-		/** @deprecated 19.0.0 */
1214
-		$this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class);
1215
-
1216
-		$this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) {
1217
-			$instance = new Collaboration\Collaborators\Search($c);
1218
-
1219
-			// register default plugins
1220
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
1221
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
1222
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
1223
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
1224
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]);
1225
-
1226
-			return $instance;
1227
-		});
1228
-		/** @deprecated 19.0.0 */
1229
-		$this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
1230
-		$this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class);
1231
-
1232
-		$this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
1233
-
1234
-		$this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class);
1235
-		$this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class);
1236
-
1237
-		$this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class);
1238
-		$this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class);
1239
-		$this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) {
1240
-			return new \OC\Files\AppData\Factory(
1241
-				$c->get(IRootFolder::class),
1242
-				$c->get(SystemConfig::class)
1243
-			);
1244
-		});
1245
-
1246
-		$this->registerService('LockdownManager', function (ContainerInterface $c) {
1247
-			return new LockdownManager(function () use ($c) {
1248
-				return $c->get(ISession::class);
1249
-			});
1250
-		});
1251
-
1252
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) {
1253
-			return new DiscoveryService(
1254
-				$c->get(ICacheFactory::class),
1255
-				$c->get(IClientService::class)
1256
-			);
1257
-		});
1258
-
1259
-		$this->registerService(ICloudIdManager::class, function (ContainerInterface $c) {
1260
-			return new CloudIdManager($c->get(\OCP\Contacts\IManager::class));
1261
-		});
1262
-
1263
-		$this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class);
1264
-
1265
-		$this->registerService(ICloudFederationProviderManager::class, function (ContainerInterface $c) {
1266
-			return new CloudFederationProviderManager(
1267
-				$c->get(IAppManager::class),
1268
-				$c->get(IClientService::class),
1269
-				$c->get(ICloudIdManager::class),
1270
-				$c->get(ILogger::class)
1271
-			);
1272
-		});
1273
-
1274
-		$this->registerService(ICloudFederationFactory::class, function (Server $c) {
1275
-			return new CloudFederationFactory();
1276
-		});
1277
-
1278
-		$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1279
-		/** @deprecated 19.0.0 */
1280
-		$this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1281
-
1282
-		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1283
-		/** @deprecated 19.0.0 */
1284
-		$this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1285
-
1286
-		$this->registerService(Defaults::class, function (Server $c) {
1287
-			return new Defaults(
1288
-				$c->getThemingDefaults()
1289
-			);
1290
-		});
1291
-		/** @deprecated 19.0.0 */
1292
-		$this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class);
1293
-
1294
-		$this->registerService(\OCP\ISession::class, function (ContainerInterface $c) {
1295
-			return $c->get(\OCP\IUserSession::class)->getSession();
1296
-		}, false);
1297
-
1298
-		$this->registerService(IShareHelper::class, function (ContainerInterface $c) {
1299
-			return new ShareHelper(
1300
-				$c->get(\OCP\Share\IManager::class)
1301
-			);
1302
-		});
1303
-
1304
-		$this->registerService(Installer::class, function (ContainerInterface $c) {
1305
-			return new Installer(
1306
-				$c->get(AppFetcher::class),
1307
-				$c->get(IClientService::class),
1308
-				$c->get(ITempManager::class),
1309
-				$c->get(ILogger::class),
1310
-				$c->get(\OCP\IConfig::class),
1311
-				\OC::$CLI
1312
-			);
1313
-		});
1314
-
1315
-		$this->registerService(IApiFactory::class, function (ContainerInterface $c) {
1316
-			return new ApiFactory($c->get(IClientService::class));
1317
-		});
1318
-
1319
-		$this->registerService(IInstanceFactory::class, function (ContainerInterface $c) {
1320
-			$memcacheFactory = $c->get(ICacheFactory::class);
1321
-			return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class));
1322
-		});
1323
-
1324
-		$this->registerAlias(IContactsStore::class, ContactsStore::class);
1325
-		$this->registerAlias(IAccountManager::class, AccountManager::class);
1326
-
1327
-		$this->registerAlias(IStorageFactory::class, StorageFactory::class);
1328
-
1329
-		$this->registerAlias(IDashboardManager::class, DashboardManager::class);
1330
-		$this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class);
1331
-		$this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class);
1332
-
1333
-		$this->registerAlias(ISubAdmin::class, SubAdmin::class);
1334
-
1335
-		$this->registerAlias(IInitialStateService::class, InitialStateService::class);
1336
-
1337
-		$this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class);
1338
-
1339
-		$this->connectDispatcher();
1340
-	}
1341
-
1342
-	public function boot() {
1343
-		/** @var HookConnector $hookConnector */
1344
-		$hookConnector = $this->get(HookConnector::class);
1345
-		$hookConnector->viewToNode();
1346
-	}
1347
-
1348
-	/**
1349
-	 * @return \OCP\Calendar\IManager
1350
-	 * @deprecated 20.0.0
1351
-	 */
1352
-	public function getCalendarManager() {
1353
-		return $this->get(\OC\Calendar\Manager::class);
1354
-	}
1355
-
1356
-	/**
1357
-	 * @return \OCP\Calendar\Resource\IManager
1358
-	 * @deprecated 20.0.0
1359
-	 */
1360
-	public function getCalendarResourceBackendManager() {
1361
-		return $this->get(\OC\Calendar\Resource\Manager::class);
1362
-	}
1363
-
1364
-	/**
1365
-	 * @return \OCP\Calendar\Room\IManager
1366
-	 * @deprecated 20.0.0
1367
-	 */
1368
-	public function getCalendarRoomBackendManager() {
1369
-		return $this->get(\OC\Calendar\Room\Manager::class);
1370
-	}
1371
-
1372
-	private function connectDispatcher() {
1373
-		$dispatcher = $this->get(SymfonyAdapter::class);
1374
-
1375
-		// Delete avatar on user deletion
1376
-		$dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) {
1377
-			$logger = $this->get(ILogger::class);
1378
-			$manager = $this->getAvatarManager();
1379
-			/** @var IUser $user */
1380
-			$user = $e->getSubject();
1381
-
1382
-			try {
1383
-				$avatar = $manager->getAvatar($user->getUID());
1384
-				$avatar->remove();
1385
-			} catch (NotFoundException $e) {
1386
-				// no avatar to remove
1387
-			} catch (\Exception $e) {
1388
-				// Ignore exceptions
1389
-				$logger->info('Could not cleanup avatar of ' . $user->getUID());
1390
-			}
1391
-		});
1392
-
1393
-		$dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
1394
-			$manager = $this->getAvatarManager();
1395
-			/** @var IUser $user */
1396
-			$user = $e->getSubject();
1397
-			$feature = $e->getArgument('feature');
1398
-			$oldValue = $e->getArgument('oldValue');
1399
-			$value = $e->getArgument('value');
1400
-
1401
-			// We only change the avatar on display name changes
1402
-			if ($feature !== 'displayName') {
1403
-				return;
1404
-			}
1405
-
1406
-			try {
1407
-				$avatar = $manager->getAvatar($user->getUID());
1408
-				$avatar->userChanged($feature, $oldValue, $value);
1409
-			} catch (NotFoundException $e) {
1410
-				// no avatar to remove
1411
-			}
1412
-		});
1413
-
1414
-		/** @var IEventDispatcher $eventDispatched */
1415
-		$eventDispatched = $this->get(IEventDispatcher::class);
1416
-		$eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class);
1417
-		$eventDispatched->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class);
1418
-	}
1419
-
1420
-	/**
1421
-	 * @return \OCP\Contacts\IManager
1422
-	 * @deprecated 20.0.0
1423
-	 */
1424
-	public function getContactsManager() {
1425
-		return $this->get(\OCP\Contacts\IManager::class);
1426
-	}
1427
-
1428
-	/**
1429
-	 * @return \OC\Encryption\Manager
1430
-	 * @deprecated 20.0.0
1431
-	 */
1432
-	public function getEncryptionManager() {
1433
-		return $this->get(\OCP\Encryption\IManager::class);
1434
-	}
1435
-
1436
-	/**
1437
-	 * @return \OC\Encryption\File
1438
-	 * @deprecated 20.0.0
1439
-	 */
1440
-	public function getEncryptionFilesHelper() {
1441
-		return $this->get(IFile::class);
1442
-	}
1443
-
1444
-	/**
1445
-	 * @return \OCP\Encryption\Keys\IStorage
1446
-	 * @deprecated 20.0.0
1447
-	 */
1448
-	public function getEncryptionKeyStorage() {
1449
-		return $this->get(IStorage::class);
1450
-	}
1451
-
1452
-	/**
1453
-	 * The current request object holding all information about the request
1454
-	 * currently being processed is returned from this method.
1455
-	 * In case the current execution was not initiated by a web request null is returned
1456
-	 *
1457
-	 * @return \OCP\IRequest
1458
-	 * @deprecated 20.0.0
1459
-	 */
1460
-	public function getRequest() {
1461
-		return $this->get(IRequest::class);
1462
-	}
1463
-
1464
-	/**
1465
-	 * Returns the preview manager which can create preview images for a given file
1466
-	 *
1467
-	 * @return IPreview
1468
-	 * @deprecated 20.0.0
1469
-	 */
1470
-	public function getPreviewManager() {
1471
-		return $this->get(IPreview::class);
1472
-	}
1473
-
1474
-	/**
1475
-	 * Returns the tag manager which can get and set tags for different object types
1476
-	 *
1477
-	 * @see \OCP\ITagManager::load()
1478
-	 * @return ITagManager
1479
-	 * @deprecated 20.0.0
1480
-	 */
1481
-	public function getTagManager() {
1482
-		return $this->get(ITagManager::class);
1483
-	}
1484
-
1485
-	/**
1486
-	 * Returns the system-tag manager
1487
-	 *
1488
-	 * @return ISystemTagManager
1489
-	 *
1490
-	 * @since 9.0.0
1491
-	 * @deprecated 20.0.0
1492
-	 */
1493
-	public function getSystemTagManager() {
1494
-		return $this->get(ISystemTagManager::class);
1495
-	}
1496
-
1497
-	/**
1498
-	 * Returns the system-tag object mapper
1499
-	 *
1500
-	 * @return ISystemTagObjectMapper
1501
-	 *
1502
-	 * @since 9.0.0
1503
-	 * @deprecated 20.0.0
1504
-	 */
1505
-	public function getSystemTagObjectMapper() {
1506
-		return $this->get(ISystemTagObjectMapper::class);
1507
-	}
1508
-
1509
-	/**
1510
-	 * Returns the avatar manager, used for avatar functionality
1511
-	 *
1512
-	 * @return IAvatarManager
1513
-	 * @deprecated 20.0.0
1514
-	 */
1515
-	public function getAvatarManager() {
1516
-		return $this->get(IAvatarManager::class);
1517
-	}
1518
-
1519
-	/**
1520
-	 * Returns the root folder of ownCloud's data directory
1521
-	 *
1522
-	 * @return IRootFolder
1523
-	 * @deprecated 20.0.0
1524
-	 */
1525
-	public function getRootFolder() {
1526
-		return $this->get(IRootFolder::class);
1527
-	}
1528
-
1529
-	/**
1530
-	 * Returns the root folder of ownCloud's data directory
1531
-	 * This is the lazy variant so this gets only initialized once it
1532
-	 * is actually used.
1533
-	 *
1534
-	 * @return IRootFolder
1535
-	 * @deprecated 20.0.0
1536
-	 */
1537
-	public function getLazyRootFolder() {
1538
-		return $this->get(IRootFolder::class);
1539
-	}
1540
-
1541
-	/**
1542
-	 * Returns a view to ownCloud's files folder
1543
-	 *
1544
-	 * @param string $userId user ID
1545
-	 * @return \OCP\Files\Folder|null
1546
-	 * @deprecated 20.0.0
1547
-	 */
1548
-	public function getUserFolder($userId = null) {
1549
-		if ($userId === null) {
1550
-			$user = $this->get(IUserSession::class)->getUser();
1551
-			if (!$user) {
1552
-				return null;
1553
-			}
1554
-			$userId = $user->getUID();
1555
-		}
1556
-		$root = $this->get(IRootFolder::class);
1557
-		return $root->getUserFolder($userId);
1558
-	}
1559
-
1560
-	/**
1561
-	 * @return \OC\User\Manager
1562
-	 * @deprecated 20.0.0
1563
-	 */
1564
-	public function getUserManager() {
1565
-		return $this->get(IUserManager::class);
1566
-	}
1567
-
1568
-	/**
1569
-	 * @return \OC\Group\Manager
1570
-	 * @deprecated 20.0.0
1571
-	 */
1572
-	public function getGroupManager() {
1573
-		return $this->get(IGroupManager::class);
1574
-	}
1575
-
1576
-	/**
1577
-	 * @return \OC\User\Session
1578
-	 * @deprecated 20.0.0
1579
-	 */
1580
-	public function getUserSession() {
1581
-		return $this->get(IUserSession::class);
1582
-	}
1583
-
1584
-	/**
1585
-	 * @return \OCP\ISession
1586
-	 * @deprecated 20.0.0
1587
-	 */
1588
-	public function getSession() {
1589
-		return $this->get(IUserSession::class)->getSession();
1590
-	}
1591
-
1592
-	/**
1593
-	 * @param \OCP\ISession $session
1594
-	 */
1595
-	public function setSession(\OCP\ISession $session) {
1596
-		$this->get(SessionStorage::class)->setSession($session);
1597
-		$this->get(IUserSession::class)->setSession($session);
1598
-		$this->get(Store::class)->setSession($session);
1599
-	}
1600
-
1601
-	/**
1602
-	 * @return \OC\Authentication\TwoFactorAuth\Manager
1603
-	 * @deprecated 20.0.0
1604
-	 */
1605
-	public function getTwoFactorAuthManager() {
1606
-		return $this->get(\OC\Authentication\TwoFactorAuth\Manager::class);
1607
-	}
1608
-
1609
-	/**
1610
-	 * @return \OC\NavigationManager
1611
-	 * @deprecated 20.0.0
1612
-	 */
1613
-	public function getNavigationManager() {
1614
-		return $this->get(INavigationManager::class);
1615
-	}
1616
-
1617
-	/**
1618
-	 * @return \OCP\IConfig
1619
-	 * @deprecated 20.0.0
1620
-	 */
1621
-	public function getConfig() {
1622
-		return $this->get(AllConfig::class);
1623
-	}
1624
-
1625
-	/**
1626
-	 * @return \OC\SystemConfig
1627
-	 * @deprecated 20.0.0
1628
-	 */
1629
-	public function getSystemConfig() {
1630
-		return $this->get(SystemConfig::class);
1631
-	}
1632
-
1633
-	/**
1634
-	 * Returns the app config manager
1635
-	 *
1636
-	 * @return IAppConfig
1637
-	 * @deprecated 20.0.0
1638
-	 */
1639
-	public function getAppConfig() {
1640
-		return $this->get(IAppConfig::class);
1641
-	}
1642
-
1643
-	/**
1644
-	 * @return IFactory
1645
-	 * @deprecated 20.0.0
1646
-	 */
1647
-	public function getL10NFactory() {
1648
-		return $this->get(IFactory::class);
1649
-	}
1650
-
1651
-	/**
1652
-	 * get an L10N instance
1653
-	 *
1654
-	 * @param string $app appid
1655
-	 * @param string $lang
1656
-	 * @return IL10N
1657
-	 * @deprecated 20.0.0
1658
-	 */
1659
-	public function getL10N($app, $lang = null) {
1660
-		return $this->get(IFactory::class)->get($app, $lang);
1661
-	}
1662
-
1663
-	/**
1664
-	 * @return IURLGenerator
1665
-	 * @deprecated 20.0.0
1666
-	 */
1667
-	public function getURLGenerator() {
1668
-		return $this->get(IURLGenerator::class);
1669
-	}
1670
-
1671
-	/**
1672
-	 * @return AppFetcher
1673
-	 * @deprecated 20.0.0
1674
-	 */
1675
-	public function getAppFetcher() {
1676
-		return $this->get(AppFetcher::class);
1677
-	}
1678
-
1679
-	/**
1680
-	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1681
-	 * getMemCacheFactory() instead.
1682
-	 *
1683
-	 * @return ICache
1684
-	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1685
-	 */
1686
-	public function getCache() {
1687
-		return $this->get(ICache::class);
1688
-	}
1689
-
1690
-	/**
1691
-	 * Returns an \OCP\CacheFactory instance
1692
-	 *
1693
-	 * @return \OCP\ICacheFactory
1694
-	 * @deprecated 20.0.0
1695
-	 */
1696
-	public function getMemCacheFactory() {
1697
-		return $this->get(ICacheFactory::class);
1698
-	}
1699
-
1700
-	/**
1701
-	 * Returns an \OC\RedisFactory instance
1702
-	 *
1703
-	 * @return \OC\RedisFactory
1704
-	 * @deprecated 20.0.0
1705
-	 */
1706
-	public function getGetRedisFactory() {
1707
-		return $this->get('RedisFactory');
1708
-	}
1709
-
1710
-
1711
-	/**
1712
-	 * Returns the current session
1713
-	 *
1714
-	 * @return \OCP\IDBConnection
1715
-	 * @deprecated 20.0.0
1716
-	 */
1717
-	public function getDatabaseConnection() {
1718
-		return $this->get(IDBConnection::class);
1719
-	}
1720
-
1721
-	/**
1722
-	 * Returns the activity manager
1723
-	 *
1724
-	 * @return \OCP\Activity\IManager
1725
-	 * @deprecated 20.0.0
1726
-	 */
1727
-	public function getActivityManager() {
1728
-		return $this->get(\OCP\Activity\IManager::class);
1729
-	}
1730
-
1731
-	/**
1732
-	 * Returns an job list for controlling background jobs
1733
-	 *
1734
-	 * @return IJobList
1735
-	 * @deprecated 20.0.0
1736
-	 */
1737
-	public function getJobList() {
1738
-		return $this->get(IJobList::class);
1739
-	}
1740
-
1741
-	/**
1742
-	 * Returns a logger instance
1743
-	 *
1744
-	 * @return ILogger
1745
-	 * @deprecated 20.0.0
1746
-	 */
1747
-	public function getLogger() {
1748
-		return $this->get(ILogger::class);
1749
-	}
1750
-
1751
-	/**
1752
-	 * @return ILogFactory
1753
-	 * @throws \OCP\AppFramework\QueryException
1754
-	 * @deprecated 20.0.0
1755
-	 */
1756
-	public function getLogFactory() {
1757
-		return $this->get(ILogFactory::class);
1758
-	}
1759
-
1760
-	/**
1761
-	 * Returns a router for generating and matching urls
1762
-	 *
1763
-	 * @return IRouter
1764
-	 * @deprecated 20.0.0
1765
-	 */
1766
-	public function getRouter() {
1767
-		return $this->get(IRouter::class);
1768
-	}
1769
-
1770
-	/**
1771
-	 * Returns a search instance
1772
-	 *
1773
-	 * @return ISearch
1774
-	 * @deprecated 20.0.0
1775
-	 */
1776
-	public function getSearch() {
1777
-		return $this->get(ISearch::class);
1778
-	}
1779
-
1780
-	/**
1781
-	 * Returns a SecureRandom instance
1782
-	 *
1783
-	 * @return \OCP\Security\ISecureRandom
1784
-	 * @deprecated 20.0.0
1785
-	 */
1786
-	public function getSecureRandom() {
1787
-		return $this->get(ISecureRandom::class);
1788
-	}
1789
-
1790
-	/**
1791
-	 * Returns a Crypto instance
1792
-	 *
1793
-	 * @return ICrypto
1794
-	 * @deprecated 20.0.0
1795
-	 */
1796
-	public function getCrypto() {
1797
-		return $this->get(ICrypto::class);
1798
-	}
1799
-
1800
-	/**
1801
-	 * Returns a Hasher instance
1802
-	 *
1803
-	 * @return IHasher
1804
-	 * @deprecated 20.0.0
1805
-	 */
1806
-	public function getHasher() {
1807
-		return $this->get(IHasher::class);
1808
-	}
1809
-
1810
-	/**
1811
-	 * Returns a CredentialsManager instance
1812
-	 *
1813
-	 * @return ICredentialsManager
1814
-	 * @deprecated 20.0.0
1815
-	 */
1816
-	public function getCredentialsManager() {
1817
-		return $this->get(ICredentialsManager::class);
1818
-	}
1819
-
1820
-	/**
1821
-	 * Get the certificate manager
1822
-	 *
1823
-	 * @return \OCP\ICertificateManager
1824
-	 */
1825
-	public function getCertificateManager() {
1826
-		return $this->get(ICertificateManager::class);
1827
-	}
1828
-
1829
-	/**
1830
-	 * Returns an instance of the HTTP client service
1831
-	 *
1832
-	 * @return IClientService
1833
-	 * @deprecated 20.0.0
1834
-	 */
1835
-	public function getHTTPClientService() {
1836
-		return $this->get(IClientService::class);
1837
-	}
1838
-
1839
-	/**
1840
-	 * Create a new event source
1841
-	 *
1842
-	 * @return \OCP\IEventSource
1843
-	 * @deprecated 20.0.0
1844
-	 */
1845
-	public function createEventSource() {
1846
-		return new \OC_EventSource();
1847
-	}
1848
-
1849
-	/**
1850
-	 * Get the active event logger
1851
-	 *
1852
-	 * The returned logger only logs data when debug mode is enabled
1853
-	 *
1854
-	 * @return IEventLogger
1855
-	 * @deprecated 20.0.0
1856
-	 */
1857
-	public function getEventLogger() {
1858
-		return $this->get(IEventLogger::class);
1859
-	}
1860
-
1861
-	/**
1862
-	 * Get the active query logger
1863
-	 *
1864
-	 * The returned logger only logs data when debug mode is enabled
1865
-	 *
1866
-	 * @return IQueryLogger
1867
-	 * @deprecated 20.0.0
1868
-	 */
1869
-	public function getQueryLogger() {
1870
-		return $this->get(IQueryLogger::class);
1871
-	}
1872
-
1873
-	/**
1874
-	 * Get the manager for temporary files and folders
1875
-	 *
1876
-	 * @return \OCP\ITempManager
1877
-	 * @deprecated 20.0.0
1878
-	 */
1879
-	public function getTempManager() {
1880
-		return $this->get(ITempManager::class);
1881
-	}
1882
-
1883
-	/**
1884
-	 * Get the app manager
1885
-	 *
1886
-	 * @return \OCP\App\IAppManager
1887
-	 * @deprecated 20.0.0
1888
-	 */
1889
-	public function getAppManager() {
1890
-		return $this->get(IAppManager::class);
1891
-	}
1892
-
1893
-	/**
1894
-	 * Creates a new mailer
1895
-	 *
1896
-	 * @return IMailer
1897
-	 * @deprecated 20.0.0
1898
-	 */
1899
-	public function getMailer() {
1900
-		return $this->get(IMailer::class);
1901
-	}
1902
-
1903
-	/**
1904
-	 * Get the webroot
1905
-	 *
1906
-	 * @return string
1907
-	 * @deprecated 20.0.0
1908
-	 */
1909
-	public function getWebRoot() {
1910
-		return $this->webRoot;
1911
-	}
1912
-
1913
-	/**
1914
-	 * @return \OC\OCSClient
1915
-	 * @deprecated 20.0.0
1916
-	 */
1917
-	public function getOcsClient() {
1918
-		return $this->get('OcsClient');
1919
-	}
1920
-
1921
-	/**
1922
-	 * @return IDateTimeZone
1923
-	 * @deprecated 20.0.0
1924
-	 */
1925
-	public function getDateTimeZone() {
1926
-		return $this->get(IDateTimeZone::class);
1927
-	}
1928
-
1929
-	/**
1930
-	 * @return IDateTimeFormatter
1931
-	 * @deprecated 20.0.0
1932
-	 */
1933
-	public function getDateTimeFormatter() {
1934
-		return $this->get(IDateTimeFormatter::class);
1935
-	}
1936
-
1937
-	/**
1938
-	 * @return IMountProviderCollection
1939
-	 * @deprecated 20.0.0
1940
-	 */
1941
-	public function getMountProviderCollection() {
1942
-		return $this->get(IMountProviderCollection::class);
1943
-	}
1944
-
1945
-	/**
1946
-	 * Get the IniWrapper
1947
-	 *
1948
-	 * @return IniGetWrapper
1949
-	 * @deprecated 20.0.0
1950
-	 */
1951
-	public function getIniWrapper() {
1952
-		return $this->get(IniGetWrapper::class);
1953
-	}
1954
-
1955
-	/**
1956
-	 * @return \OCP\Command\IBus
1957
-	 * @deprecated 20.0.0
1958
-	 */
1959
-	public function getCommandBus() {
1960
-		return $this->get(IBus::class);
1961
-	}
1962
-
1963
-	/**
1964
-	 * Get the trusted domain helper
1965
-	 *
1966
-	 * @return TrustedDomainHelper
1967
-	 * @deprecated 20.0.0
1968
-	 */
1969
-	public function getTrustedDomainHelper() {
1970
-		return $this->get(TrustedDomainHelper::class);
1971
-	}
1972
-
1973
-	/**
1974
-	 * Get the locking provider
1975
-	 *
1976
-	 * @return ILockingProvider
1977
-	 * @since 8.1.0
1978
-	 * @deprecated 20.0.0
1979
-	 */
1980
-	public function getLockingProvider() {
1981
-		return $this->get(ILockingProvider::class);
1982
-	}
1983
-
1984
-	/**
1985
-	 * @return IMountManager
1986
-	 * @deprecated 20.0.0
1987
-	 **/
1988
-	public function getMountManager() {
1989
-		return $this->get(IMountManager::class);
1990
-	}
1991
-
1992
-	/**
1993
-	 * @return IUserMountCache
1994
-	 * @deprecated 20.0.0
1995
-	 */
1996
-	public function getUserMountCache() {
1997
-		return $this->get(IUserMountCache::class);
1998
-	}
1999
-
2000
-	/**
2001
-	 * Get the MimeTypeDetector
2002
-	 *
2003
-	 * @return IMimeTypeDetector
2004
-	 * @deprecated 20.0.0
2005
-	 */
2006
-	public function getMimeTypeDetector() {
2007
-		return $this->get(IMimeTypeDetector::class);
2008
-	}
2009
-
2010
-	/**
2011
-	 * Get the MimeTypeLoader
2012
-	 *
2013
-	 * @return IMimeTypeLoader
2014
-	 * @deprecated 20.0.0
2015
-	 */
2016
-	public function getMimeTypeLoader() {
2017
-		return $this->get(IMimeTypeLoader::class);
2018
-	}
2019
-
2020
-	/**
2021
-	 * Get the manager of all the capabilities
2022
-	 *
2023
-	 * @return CapabilitiesManager
2024
-	 * @deprecated 20.0.0
2025
-	 */
2026
-	public function getCapabilitiesManager() {
2027
-		return $this->get(CapabilitiesManager::class);
2028
-	}
2029
-
2030
-	/**
2031
-	 * Get the EventDispatcher
2032
-	 *
2033
-	 * @return EventDispatcherInterface
2034
-	 * @since 8.2.0
2035
-	 * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher
2036
-	 */
2037
-	public function getEventDispatcher() {
2038
-		return $this->get(\OC\EventDispatcher\SymfonyAdapter::class);
2039
-	}
2040
-
2041
-	/**
2042
-	 * Get the Notification Manager
2043
-	 *
2044
-	 * @return \OCP\Notification\IManager
2045
-	 * @since 8.2.0
2046
-	 * @deprecated 20.0.0
2047
-	 */
2048
-	public function getNotificationManager() {
2049
-		return $this->get(\OCP\Notification\IManager::class);
2050
-	}
2051
-
2052
-	/**
2053
-	 * @return ICommentsManager
2054
-	 * @deprecated 20.0.0
2055
-	 */
2056
-	public function getCommentsManager() {
2057
-		return $this->get(ICommentsManager::class);
2058
-	}
2059
-
2060
-	/**
2061
-	 * @return \OCA\Theming\ThemingDefaults
2062
-	 * @deprecated 20.0.0
2063
-	 */
2064
-	public function getThemingDefaults() {
2065
-		return $this->get('ThemingDefaults');
2066
-	}
2067
-
2068
-	/**
2069
-	 * @return \OC\IntegrityCheck\Checker
2070
-	 * @deprecated 20.0.0
2071
-	 */
2072
-	public function getIntegrityCodeChecker() {
2073
-		return $this->get('IntegrityCodeChecker');
2074
-	}
2075
-
2076
-	/**
2077
-	 * @return \OC\Session\CryptoWrapper
2078
-	 * @deprecated 20.0.0
2079
-	 */
2080
-	public function getSessionCryptoWrapper() {
2081
-		return $this->get('CryptoWrapper');
2082
-	}
2083
-
2084
-	/**
2085
-	 * @return CsrfTokenManager
2086
-	 * @deprecated 20.0.0
2087
-	 */
2088
-	public function getCsrfTokenManager() {
2089
-		return $this->get(CsrfTokenManager::class);
2090
-	}
2091
-
2092
-	/**
2093
-	 * @return Throttler
2094
-	 * @deprecated 20.0.0
2095
-	 */
2096
-	public function getBruteForceThrottler() {
2097
-		return $this->get(Throttler::class);
2098
-	}
2099
-
2100
-	/**
2101
-	 * @return IContentSecurityPolicyManager
2102
-	 * @deprecated 20.0.0
2103
-	 */
2104
-	public function getContentSecurityPolicyManager() {
2105
-		return $this->get(ContentSecurityPolicyManager::class);
2106
-	}
2107
-
2108
-	/**
2109
-	 * @return ContentSecurityPolicyNonceManager
2110
-	 * @deprecated 20.0.0
2111
-	 */
2112
-	public function getContentSecurityPolicyNonceManager() {
2113
-		return $this->get(ContentSecurityPolicyNonceManager::class);
2114
-	}
2115
-
2116
-	/**
2117
-	 * Not a public API as of 8.2, wait for 9.0
2118
-	 *
2119
-	 * @return \OCA\Files_External\Service\BackendService
2120
-	 * @deprecated 20.0.0
2121
-	 */
2122
-	public function getStoragesBackendService() {
2123
-		return $this->get(BackendService::class);
2124
-	}
2125
-
2126
-	/**
2127
-	 * Not a public API as of 8.2, wait for 9.0
2128
-	 *
2129
-	 * @return \OCA\Files_External\Service\GlobalStoragesService
2130
-	 * @deprecated 20.0.0
2131
-	 */
2132
-	public function getGlobalStoragesService() {
2133
-		return $this->get(GlobalStoragesService::class);
2134
-	}
2135
-
2136
-	/**
2137
-	 * Not a public API as of 8.2, wait for 9.0
2138
-	 *
2139
-	 * @return \OCA\Files_External\Service\UserGlobalStoragesService
2140
-	 * @deprecated 20.0.0
2141
-	 */
2142
-	public function getUserGlobalStoragesService() {
2143
-		return $this->get(UserGlobalStoragesService::class);
2144
-	}
2145
-
2146
-	/**
2147
-	 * Not a public API as of 8.2, wait for 9.0
2148
-	 *
2149
-	 * @return \OCA\Files_External\Service\UserStoragesService
2150
-	 * @deprecated 20.0.0
2151
-	 */
2152
-	public function getUserStoragesService() {
2153
-		return $this->get(UserStoragesService::class);
2154
-	}
2155
-
2156
-	/**
2157
-	 * @return \OCP\Share\IManager
2158
-	 * @deprecated 20.0.0
2159
-	 */
2160
-	public function getShareManager() {
2161
-		return $this->get(\OCP\Share\IManager::class);
2162
-	}
2163
-
2164
-	/**
2165
-	 * @return \OCP\Collaboration\Collaborators\ISearch
2166
-	 * @deprecated 20.0.0
2167
-	 */
2168
-	public function getCollaboratorSearch() {
2169
-		return $this->get(\OCP\Collaboration\Collaborators\ISearch::class);
2170
-	}
2171
-
2172
-	/**
2173
-	 * @return \OCP\Collaboration\AutoComplete\IManager
2174
-	 * @deprecated 20.0.0
2175
-	 */
2176
-	public function getAutoCompleteManager() {
2177
-		return $this->get(IManager::class);
2178
-	}
2179
-
2180
-	/**
2181
-	 * Returns the LDAP Provider
2182
-	 *
2183
-	 * @return \OCP\LDAP\ILDAPProvider
2184
-	 * @deprecated 20.0.0
2185
-	 */
2186
-	public function getLDAPProvider() {
2187
-		return $this->get('LDAPProvider');
2188
-	}
2189
-
2190
-	/**
2191
-	 * @return \OCP\Settings\IManager
2192
-	 * @deprecated 20.0.0
2193
-	 */
2194
-	public function getSettingsManager() {
2195
-		return $this->get(\OC\Settings\Manager::class);
2196
-	}
2197
-
2198
-	/**
2199
-	 * @return \OCP\Files\IAppData
2200
-	 * @deprecated 20.0.0
2201
-	 */
2202
-	public function getAppDataDir($app) {
2203
-		/** @var \OC\Files\AppData\Factory $factory */
2204
-		$factory = $this->get(\OC\Files\AppData\Factory::class);
2205
-		return $factory->get($app);
2206
-	}
2207
-
2208
-	/**
2209
-	 * @return \OCP\Lockdown\ILockdownManager
2210
-	 * @deprecated 20.0.0
2211
-	 */
2212
-	public function getLockdownManager() {
2213
-		return $this->get('LockdownManager');
2214
-	}
2215
-
2216
-	/**
2217
-	 * @return \OCP\Federation\ICloudIdManager
2218
-	 * @deprecated 20.0.0
2219
-	 */
2220
-	public function getCloudIdManager() {
2221
-		return $this->get(ICloudIdManager::class);
2222
-	}
2223
-
2224
-	/**
2225
-	 * @return \OCP\GlobalScale\IConfig
2226
-	 * @deprecated 20.0.0
2227
-	 */
2228
-	public function getGlobalScaleConfig() {
2229
-		return $this->get(IConfig::class);
2230
-	}
2231
-
2232
-	/**
2233
-	 * @return \OCP\Federation\ICloudFederationProviderManager
2234
-	 * @deprecated 20.0.0
2235
-	 */
2236
-	public function getCloudFederationProviderManager() {
2237
-		return $this->get(ICloudFederationProviderManager::class);
2238
-	}
2239
-
2240
-	/**
2241
-	 * @return \OCP\Remote\Api\IApiFactory
2242
-	 * @deprecated 20.0.0
2243
-	 */
2244
-	public function getRemoteApiFactory() {
2245
-		return $this->get(IApiFactory::class);
2246
-	}
2247
-
2248
-	/**
2249
-	 * @return \OCP\Federation\ICloudFederationFactory
2250
-	 * @deprecated 20.0.0
2251
-	 */
2252
-	public function getCloudFederationFactory() {
2253
-		return $this->get(ICloudFederationFactory::class);
2254
-	}
2255
-
2256
-	/**
2257
-	 * @return \OCP\Remote\IInstanceFactory
2258
-	 * @deprecated 20.0.0
2259
-	 */
2260
-	public function getRemoteInstanceFactory() {
2261
-		return $this->get(IInstanceFactory::class);
2262
-	}
2263
-
2264
-	/**
2265
-	 * @return IStorageFactory
2266
-	 * @deprecated 20.0.0
2267
-	 */
2268
-	public function getStorageFactory() {
2269
-		return $this->get(IStorageFactory::class);
2270
-	}
2271
-
2272
-	/**
2273
-	 * Get the Preview GeneratorHelper
2274
-	 *
2275
-	 * @return GeneratorHelper
2276
-	 * @since 17.0.0
2277
-	 * @deprecated 20.0.0
2278
-	 */
2279
-	public function getGeneratorHelper() {
2280
-		return $this->get(\OC\Preview\GeneratorHelper::class);
2281
-	}
2282
-
2283
-	private function registerDeprecatedAlias(string $alias, string $target) {
2284
-		$this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) {
2285
-			try {
2286
-				/** @var ILogger $logger */
2287
-				$logger = $container->get(ILogger::class);
2288
-				$logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']);
2289
-			} catch (ContainerExceptionInterface $e) {
2290
-				// Could not get logger. Continue
2291
-			}
2292
-
2293
-			return $container->get($target);
2294
-		}, false);
2295
-	}
1110
+            $prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
1111
+            if (isset($prefixes['OCA\\Theming\\'])) {
1112
+                $classExists = true;
1113
+            } else {
1114
+                $classExists = false;
1115
+            }
1116
+
1117
+            if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValue('installed', false) && $c->get(IAppManager::class)->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
1118
+                return new ThemingDefaults(
1119
+                    $c->get(\OCP\IConfig::class),
1120
+                    $c->getL10N('theming'),
1121
+                    $c->get(IURLGenerator::class),
1122
+                    $c->get(ICacheFactory::class),
1123
+                    new Util($c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming')),
1124
+                    new ImageManager(
1125
+                        $c->get(\OCP\IConfig::class),
1126
+                        $c->getAppDataDir('theming'),
1127
+                        $c->get(IURLGenerator::class),
1128
+                        $this->get(ICacheFactory::class),
1129
+                        $this->get(ILogger::class),
1130
+                        $this->get(ITempManager::class)
1131
+                    ),
1132
+                    $c->get(IAppManager::class),
1133
+                    $c->get(INavigationManager::class)
1134
+                );
1135
+            }
1136
+            return new \OC_Defaults();
1137
+        });
1138
+        $this->registerService(JSCombiner::class, function (Server $c) {
1139
+            return new JSCombiner(
1140
+                $c->getAppDataDir('js'),
1141
+                $c->get(IURLGenerator::class),
1142
+                $this->get(ICacheFactory::class),
1143
+                $c->get(SystemConfig::class),
1144
+                $c->get(ILogger::class)
1145
+            );
1146
+        });
1147
+        $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class);
1148
+        /** @deprecated 19.0.0 */
1149
+        $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class);
1150
+        $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class);
1151
+
1152
+        $this->registerService('CryptoWrapper', function (ContainerInterface $c) {
1153
+            // FIXME: Instantiiated here due to cyclic dependency
1154
+            $request = new Request(
1155
+                [
1156
+                    'get' => $_GET,
1157
+                    'post' => $_POST,
1158
+                    'files' => $_FILES,
1159
+                    'server' => $_SERVER,
1160
+                    'env' => $_ENV,
1161
+                    'cookies' => $_COOKIE,
1162
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
1163
+                        ? $_SERVER['REQUEST_METHOD']
1164
+                        : null,
1165
+                ],
1166
+                $c->get(ISecureRandom::class),
1167
+                $c->get(\OCP\IConfig::class)
1168
+            );
1169
+
1170
+            return new CryptoWrapper(
1171
+                $c->get(\OCP\IConfig::class),
1172
+                $c->get(ICrypto::class),
1173
+                $c->get(ISecureRandom::class),
1174
+                $request
1175
+            );
1176
+        });
1177
+        /** @deprecated 19.0.0 */
1178
+        $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class);
1179
+        $this->registerService(SessionStorage::class, function (ContainerInterface $c) {
1180
+            return new SessionStorage($c->get(ISession::class));
1181
+        });
1182
+        $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class);
1183
+        /** @deprecated 19.0.0 */
1184
+        $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class);
1185
+
1186
+        $this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) {
1187
+            $config = $c->get(\OCP\IConfig::class);
1188
+            $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
1189
+            /** @var \OCP\Share\IProviderFactory $factory */
1190
+            $factory = new $factoryClass($this);
1191
+
1192
+            $manager = new \OC\Share20\Manager(
1193
+                $c->get(ILogger::class),
1194
+                $c->get(\OCP\IConfig::class),
1195
+                $c->get(ISecureRandom::class),
1196
+                $c->get(IHasher::class),
1197
+                $c->get(IMountManager::class),
1198
+                $c->get(IGroupManager::class),
1199
+                $c->getL10N('lib'),
1200
+                $c->get(IFactory::class),
1201
+                $factory,
1202
+                $c->get(IUserManager::class),
1203
+                $c->get(IRootFolder::class),
1204
+                $c->get(SymfonyAdapter::class),
1205
+                $c->get(IMailer::class),
1206
+                $c->get(IURLGenerator::class),
1207
+                $c->get('ThemingDefaults'),
1208
+                $c->get(IEventDispatcher::class)
1209
+            );
1210
+
1211
+            return $manager;
1212
+        });
1213
+        /** @deprecated 19.0.0 */
1214
+        $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class);
1215
+
1216
+        $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) {
1217
+            $instance = new Collaboration\Collaborators\Search($c);
1218
+
1219
+            // register default plugins
1220
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
1221
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
1222
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
1223
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
1224
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]);
1225
+
1226
+            return $instance;
1227
+        });
1228
+        /** @deprecated 19.0.0 */
1229
+        $this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
1230
+        $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class);
1231
+
1232
+        $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
1233
+
1234
+        $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class);
1235
+        $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class);
1236
+
1237
+        $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class);
1238
+        $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class);
1239
+        $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) {
1240
+            return new \OC\Files\AppData\Factory(
1241
+                $c->get(IRootFolder::class),
1242
+                $c->get(SystemConfig::class)
1243
+            );
1244
+        });
1245
+
1246
+        $this->registerService('LockdownManager', function (ContainerInterface $c) {
1247
+            return new LockdownManager(function () use ($c) {
1248
+                return $c->get(ISession::class);
1249
+            });
1250
+        });
1251
+
1252
+        $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) {
1253
+            return new DiscoveryService(
1254
+                $c->get(ICacheFactory::class),
1255
+                $c->get(IClientService::class)
1256
+            );
1257
+        });
1258
+
1259
+        $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) {
1260
+            return new CloudIdManager($c->get(\OCP\Contacts\IManager::class));
1261
+        });
1262
+
1263
+        $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class);
1264
+
1265
+        $this->registerService(ICloudFederationProviderManager::class, function (ContainerInterface $c) {
1266
+            return new CloudFederationProviderManager(
1267
+                $c->get(IAppManager::class),
1268
+                $c->get(IClientService::class),
1269
+                $c->get(ICloudIdManager::class),
1270
+                $c->get(ILogger::class)
1271
+            );
1272
+        });
1273
+
1274
+        $this->registerService(ICloudFederationFactory::class, function (Server $c) {
1275
+            return new CloudFederationFactory();
1276
+        });
1277
+
1278
+        $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1279
+        /** @deprecated 19.0.0 */
1280
+        $this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1281
+
1282
+        $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1283
+        /** @deprecated 19.0.0 */
1284
+        $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1285
+
1286
+        $this->registerService(Defaults::class, function (Server $c) {
1287
+            return new Defaults(
1288
+                $c->getThemingDefaults()
1289
+            );
1290
+        });
1291
+        /** @deprecated 19.0.0 */
1292
+        $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class);
1293
+
1294
+        $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) {
1295
+            return $c->get(\OCP\IUserSession::class)->getSession();
1296
+        }, false);
1297
+
1298
+        $this->registerService(IShareHelper::class, function (ContainerInterface $c) {
1299
+            return new ShareHelper(
1300
+                $c->get(\OCP\Share\IManager::class)
1301
+            );
1302
+        });
1303
+
1304
+        $this->registerService(Installer::class, function (ContainerInterface $c) {
1305
+            return new Installer(
1306
+                $c->get(AppFetcher::class),
1307
+                $c->get(IClientService::class),
1308
+                $c->get(ITempManager::class),
1309
+                $c->get(ILogger::class),
1310
+                $c->get(\OCP\IConfig::class),
1311
+                \OC::$CLI
1312
+            );
1313
+        });
1314
+
1315
+        $this->registerService(IApiFactory::class, function (ContainerInterface $c) {
1316
+            return new ApiFactory($c->get(IClientService::class));
1317
+        });
1318
+
1319
+        $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) {
1320
+            $memcacheFactory = $c->get(ICacheFactory::class);
1321
+            return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class));
1322
+        });
1323
+
1324
+        $this->registerAlias(IContactsStore::class, ContactsStore::class);
1325
+        $this->registerAlias(IAccountManager::class, AccountManager::class);
1326
+
1327
+        $this->registerAlias(IStorageFactory::class, StorageFactory::class);
1328
+
1329
+        $this->registerAlias(IDashboardManager::class, DashboardManager::class);
1330
+        $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class);
1331
+        $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class);
1332
+
1333
+        $this->registerAlias(ISubAdmin::class, SubAdmin::class);
1334
+
1335
+        $this->registerAlias(IInitialStateService::class, InitialStateService::class);
1336
+
1337
+        $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class);
1338
+
1339
+        $this->connectDispatcher();
1340
+    }
1341
+
1342
+    public function boot() {
1343
+        /** @var HookConnector $hookConnector */
1344
+        $hookConnector = $this->get(HookConnector::class);
1345
+        $hookConnector->viewToNode();
1346
+    }
1347
+
1348
+    /**
1349
+     * @return \OCP\Calendar\IManager
1350
+     * @deprecated 20.0.0
1351
+     */
1352
+    public function getCalendarManager() {
1353
+        return $this->get(\OC\Calendar\Manager::class);
1354
+    }
1355
+
1356
+    /**
1357
+     * @return \OCP\Calendar\Resource\IManager
1358
+     * @deprecated 20.0.0
1359
+     */
1360
+    public function getCalendarResourceBackendManager() {
1361
+        return $this->get(\OC\Calendar\Resource\Manager::class);
1362
+    }
1363
+
1364
+    /**
1365
+     * @return \OCP\Calendar\Room\IManager
1366
+     * @deprecated 20.0.0
1367
+     */
1368
+    public function getCalendarRoomBackendManager() {
1369
+        return $this->get(\OC\Calendar\Room\Manager::class);
1370
+    }
1371
+
1372
+    private function connectDispatcher() {
1373
+        $dispatcher = $this->get(SymfonyAdapter::class);
1374
+
1375
+        // Delete avatar on user deletion
1376
+        $dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) {
1377
+            $logger = $this->get(ILogger::class);
1378
+            $manager = $this->getAvatarManager();
1379
+            /** @var IUser $user */
1380
+            $user = $e->getSubject();
1381
+
1382
+            try {
1383
+                $avatar = $manager->getAvatar($user->getUID());
1384
+                $avatar->remove();
1385
+            } catch (NotFoundException $e) {
1386
+                // no avatar to remove
1387
+            } catch (\Exception $e) {
1388
+                // Ignore exceptions
1389
+                $logger->info('Could not cleanup avatar of ' . $user->getUID());
1390
+            }
1391
+        });
1392
+
1393
+        $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
1394
+            $manager = $this->getAvatarManager();
1395
+            /** @var IUser $user */
1396
+            $user = $e->getSubject();
1397
+            $feature = $e->getArgument('feature');
1398
+            $oldValue = $e->getArgument('oldValue');
1399
+            $value = $e->getArgument('value');
1400
+
1401
+            // We only change the avatar on display name changes
1402
+            if ($feature !== 'displayName') {
1403
+                return;
1404
+            }
1405
+
1406
+            try {
1407
+                $avatar = $manager->getAvatar($user->getUID());
1408
+                $avatar->userChanged($feature, $oldValue, $value);
1409
+            } catch (NotFoundException $e) {
1410
+                // no avatar to remove
1411
+            }
1412
+        });
1413
+
1414
+        /** @var IEventDispatcher $eventDispatched */
1415
+        $eventDispatched = $this->get(IEventDispatcher::class);
1416
+        $eventDispatched->addServiceListener(LoginFailed::class, LoginFailedListener::class);
1417
+        $eventDispatched->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class);
1418
+    }
1419
+
1420
+    /**
1421
+     * @return \OCP\Contacts\IManager
1422
+     * @deprecated 20.0.0
1423
+     */
1424
+    public function getContactsManager() {
1425
+        return $this->get(\OCP\Contacts\IManager::class);
1426
+    }
1427
+
1428
+    /**
1429
+     * @return \OC\Encryption\Manager
1430
+     * @deprecated 20.0.0
1431
+     */
1432
+    public function getEncryptionManager() {
1433
+        return $this->get(\OCP\Encryption\IManager::class);
1434
+    }
1435
+
1436
+    /**
1437
+     * @return \OC\Encryption\File
1438
+     * @deprecated 20.0.0
1439
+     */
1440
+    public function getEncryptionFilesHelper() {
1441
+        return $this->get(IFile::class);
1442
+    }
1443
+
1444
+    /**
1445
+     * @return \OCP\Encryption\Keys\IStorage
1446
+     * @deprecated 20.0.0
1447
+     */
1448
+    public function getEncryptionKeyStorage() {
1449
+        return $this->get(IStorage::class);
1450
+    }
1451
+
1452
+    /**
1453
+     * The current request object holding all information about the request
1454
+     * currently being processed is returned from this method.
1455
+     * In case the current execution was not initiated by a web request null is returned
1456
+     *
1457
+     * @return \OCP\IRequest
1458
+     * @deprecated 20.0.0
1459
+     */
1460
+    public function getRequest() {
1461
+        return $this->get(IRequest::class);
1462
+    }
1463
+
1464
+    /**
1465
+     * Returns the preview manager which can create preview images for a given file
1466
+     *
1467
+     * @return IPreview
1468
+     * @deprecated 20.0.0
1469
+     */
1470
+    public function getPreviewManager() {
1471
+        return $this->get(IPreview::class);
1472
+    }
1473
+
1474
+    /**
1475
+     * Returns the tag manager which can get and set tags for different object types
1476
+     *
1477
+     * @see \OCP\ITagManager::load()
1478
+     * @return ITagManager
1479
+     * @deprecated 20.0.0
1480
+     */
1481
+    public function getTagManager() {
1482
+        return $this->get(ITagManager::class);
1483
+    }
1484
+
1485
+    /**
1486
+     * Returns the system-tag manager
1487
+     *
1488
+     * @return ISystemTagManager
1489
+     *
1490
+     * @since 9.0.0
1491
+     * @deprecated 20.0.0
1492
+     */
1493
+    public function getSystemTagManager() {
1494
+        return $this->get(ISystemTagManager::class);
1495
+    }
1496
+
1497
+    /**
1498
+     * Returns the system-tag object mapper
1499
+     *
1500
+     * @return ISystemTagObjectMapper
1501
+     *
1502
+     * @since 9.0.0
1503
+     * @deprecated 20.0.0
1504
+     */
1505
+    public function getSystemTagObjectMapper() {
1506
+        return $this->get(ISystemTagObjectMapper::class);
1507
+    }
1508
+
1509
+    /**
1510
+     * Returns the avatar manager, used for avatar functionality
1511
+     *
1512
+     * @return IAvatarManager
1513
+     * @deprecated 20.0.0
1514
+     */
1515
+    public function getAvatarManager() {
1516
+        return $this->get(IAvatarManager::class);
1517
+    }
1518
+
1519
+    /**
1520
+     * Returns the root folder of ownCloud's data directory
1521
+     *
1522
+     * @return IRootFolder
1523
+     * @deprecated 20.0.0
1524
+     */
1525
+    public function getRootFolder() {
1526
+        return $this->get(IRootFolder::class);
1527
+    }
1528
+
1529
+    /**
1530
+     * Returns the root folder of ownCloud's data directory
1531
+     * This is the lazy variant so this gets only initialized once it
1532
+     * is actually used.
1533
+     *
1534
+     * @return IRootFolder
1535
+     * @deprecated 20.0.0
1536
+     */
1537
+    public function getLazyRootFolder() {
1538
+        return $this->get(IRootFolder::class);
1539
+    }
1540
+
1541
+    /**
1542
+     * Returns a view to ownCloud's files folder
1543
+     *
1544
+     * @param string $userId user ID
1545
+     * @return \OCP\Files\Folder|null
1546
+     * @deprecated 20.0.0
1547
+     */
1548
+    public function getUserFolder($userId = null) {
1549
+        if ($userId === null) {
1550
+            $user = $this->get(IUserSession::class)->getUser();
1551
+            if (!$user) {
1552
+                return null;
1553
+            }
1554
+            $userId = $user->getUID();
1555
+        }
1556
+        $root = $this->get(IRootFolder::class);
1557
+        return $root->getUserFolder($userId);
1558
+    }
1559
+
1560
+    /**
1561
+     * @return \OC\User\Manager
1562
+     * @deprecated 20.0.0
1563
+     */
1564
+    public function getUserManager() {
1565
+        return $this->get(IUserManager::class);
1566
+    }
1567
+
1568
+    /**
1569
+     * @return \OC\Group\Manager
1570
+     * @deprecated 20.0.0
1571
+     */
1572
+    public function getGroupManager() {
1573
+        return $this->get(IGroupManager::class);
1574
+    }
1575
+
1576
+    /**
1577
+     * @return \OC\User\Session
1578
+     * @deprecated 20.0.0
1579
+     */
1580
+    public function getUserSession() {
1581
+        return $this->get(IUserSession::class);
1582
+    }
1583
+
1584
+    /**
1585
+     * @return \OCP\ISession
1586
+     * @deprecated 20.0.0
1587
+     */
1588
+    public function getSession() {
1589
+        return $this->get(IUserSession::class)->getSession();
1590
+    }
1591
+
1592
+    /**
1593
+     * @param \OCP\ISession $session
1594
+     */
1595
+    public function setSession(\OCP\ISession $session) {
1596
+        $this->get(SessionStorage::class)->setSession($session);
1597
+        $this->get(IUserSession::class)->setSession($session);
1598
+        $this->get(Store::class)->setSession($session);
1599
+    }
1600
+
1601
+    /**
1602
+     * @return \OC\Authentication\TwoFactorAuth\Manager
1603
+     * @deprecated 20.0.0
1604
+     */
1605
+    public function getTwoFactorAuthManager() {
1606
+        return $this->get(\OC\Authentication\TwoFactorAuth\Manager::class);
1607
+    }
1608
+
1609
+    /**
1610
+     * @return \OC\NavigationManager
1611
+     * @deprecated 20.0.0
1612
+     */
1613
+    public function getNavigationManager() {
1614
+        return $this->get(INavigationManager::class);
1615
+    }
1616
+
1617
+    /**
1618
+     * @return \OCP\IConfig
1619
+     * @deprecated 20.0.0
1620
+     */
1621
+    public function getConfig() {
1622
+        return $this->get(AllConfig::class);
1623
+    }
1624
+
1625
+    /**
1626
+     * @return \OC\SystemConfig
1627
+     * @deprecated 20.0.0
1628
+     */
1629
+    public function getSystemConfig() {
1630
+        return $this->get(SystemConfig::class);
1631
+    }
1632
+
1633
+    /**
1634
+     * Returns the app config manager
1635
+     *
1636
+     * @return IAppConfig
1637
+     * @deprecated 20.0.0
1638
+     */
1639
+    public function getAppConfig() {
1640
+        return $this->get(IAppConfig::class);
1641
+    }
1642
+
1643
+    /**
1644
+     * @return IFactory
1645
+     * @deprecated 20.0.0
1646
+     */
1647
+    public function getL10NFactory() {
1648
+        return $this->get(IFactory::class);
1649
+    }
1650
+
1651
+    /**
1652
+     * get an L10N instance
1653
+     *
1654
+     * @param string $app appid
1655
+     * @param string $lang
1656
+     * @return IL10N
1657
+     * @deprecated 20.0.0
1658
+     */
1659
+    public function getL10N($app, $lang = null) {
1660
+        return $this->get(IFactory::class)->get($app, $lang);
1661
+    }
1662
+
1663
+    /**
1664
+     * @return IURLGenerator
1665
+     * @deprecated 20.0.0
1666
+     */
1667
+    public function getURLGenerator() {
1668
+        return $this->get(IURLGenerator::class);
1669
+    }
1670
+
1671
+    /**
1672
+     * @return AppFetcher
1673
+     * @deprecated 20.0.0
1674
+     */
1675
+    public function getAppFetcher() {
1676
+        return $this->get(AppFetcher::class);
1677
+    }
1678
+
1679
+    /**
1680
+     * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1681
+     * getMemCacheFactory() instead.
1682
+     *
1683
+     * @return ICache
1684
+     * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1685
+     */
1686
+    public function getCache() {
1687
+        return $this->get(ICache::class);
1688
+    }
1689
+
1690
+    /**
1691
+     * Returns an \OCP\CacheFactory instance
1692
+     *
1693
+     * @return \OCP\ICacheFactory
1694
+     * @deprecated 20.0.0
1695
+     */
1696
+    public function getMemCacheFactory() {
1697
+        return $this->get(ICacheFactory::class);
1698
+    }
1699
+
1700
+    /**
1701
+     * Returns an \OC\RedisFactory instance
1702
+     *
1703
+     * @return \OC\RedisFactory
1704
+     * @deprecated 20.0.0
1705
+     */
1706
+    public function getGetRedisFactory() {
1707
+        return $this->get('RedisFactory');
1708
+    }
1709
+
1710
+
1711
+    /**
1712
+     * Returns the current session
1713
+     *
1714
+     * @return \OCP\IDBConnection
1715
+     * @deprecated 20.0.0
1716
+     */
1717
+    public function getDatabaseConnection() {
1718
+        return $this->get(IDBConnection::class);
1719
+    }
1720
+
1721
+    /**
1722
+     * Returns the activity manager
1723
+     *
1724
+     * @return \OCP\Activity\IManager
1725
+     * @deprecated 20.0.0
1726
+     */
1727
+    public function getActivityManager() {
1728
+        return $this->get(\OCP\Activity\IManager::class);
1729
+    }
1730
+
1731
+    /**
1732
+     * Returns an job list for controlling background jobs
1733
+     *
1734
+     * @return IJobList
1735
+     * @deprecated 20.0.0
1736
+     */
1737
+    public function getJobList() {
1738
+        return $this->get(IJobList::class);
1739
+    }
1740
+
1741
+    /**
1742
+     * Returns a logger instance
1743
+     *
1744
+     * @return ILogger
1745
+     * @deprecated 20.0.0
1746
+     */
1747
+    public function getLogger() {
1748
+        return $this->get(ILogger::class);
1749
+    }
1750
+
1751
+    /**
1752
+     * @return ILogFactory
1753
+     * @throws \OCP\AppFramework\QueryException
1754
+     * @deprecated 20.0.0
1755
+     */
1756
+    public function getLogFactory() {
1757
+        return $this->get(ILogFactory::class);
1758
+    }
1759
+
1760
+    /**
1761
+     * Returns a router for generating and matching urls
1762
+     *
1763
+     * @return IRouter
1764
+     * @deprecated 20.0.0
1765
+     */
1766
+    public function getRouter() {
1767
+        return $this->get(IRouter::class);
1768
+    }
1769
+
1770
+    /**
1771
+     * Returns a search instance
1772
+     *
1773
+     * @return ISearch
1774
+     * @deprecated 20.0.0
1775
+     */
1776
+    public function getSearch() {
1777
+        return $this->get(ISearch::class);
1778
+    }
1779
+
1780
+    /**
1781
+     * Returns a SecureRandom instance
1782
+     *
1783
+     * @return \OCP\Security\ISecureRandom
1784
+     * @deprecated 20.0.0
1785
+     */
1786
+    public function getSecureRandom() {
1787
+        return $this->get(ISecureRandom::class);
1788
+    }
1789
+
1790
+    /**
1791
+     * Returns a Crypto instance
1792
+     *
1793
+     * @return ICrypto
1794
+     * @deprecated 20.0.0
1795
+     */
1796
+    public function getCrypto() {
1797
+        return $this->get(ICrypto::class);
1798
+    }
1799
+
1800
+    /**
1801
+     * Returns a Hasher instance
1802
+     *
1803
+     * @return IHasher
1804
+     * @deprecated 20.0.0
1805
+     */
1806
+    public function getHasher() {
1807
+        return $this->get(IHasher::class);
1808
+    }
1809
+
1810
+    /**
1811
+     * Returns a CredentialsManager instance
1812
+     *
1813
+     * @return ICredentialsManager
1814
+     * @deprecated 20.0.0
1815
+     */
1816
+    public function getCredentialsManager() {
1817
+        return $this->get(ICredentialsManager::class);
1818
+    }
1819
+
1820
+    /**
1821
+     * Get the certificate manager
1822
+     *
1823
+     * @return \OCP\ICertificateManager
1824
+     */
1825
+    public function getCertificateManager() {
1826
+        return $this->get(ICertificateManager::class);
1827
+    }
1828
+
1829
+    /**
1830
+     * Returns an instance of the HTTP client service
1831
+     *
1832
+     * @return IClientService
1833
+     * @deprecated 20.0.0
1834
+     */
1835
+    public function getHTTPClientService() {
1836
+        return $this->get(IClientService::class);
1837
+    }
1838
+
1839
+    /**
1840
+     * Create a new event source
1841
+     *
1842
+     * @return \OCP\IEventSource
1843
+     * @deprecated 20.0.0
1844
+     */
1845
+    public function createEventSource() {
1846
+        return new \OC_EventSource();
1847
+    }
1848
+
1849
+    /**
1850
+     * Get the active event logger
1851
+     *
1852
+     * The returned logger only logs data when debug mode is enabled
1853
+     *
1854
+     * @return IEventLogger
1855
+     * @deprecated 20.0.0
1856
+     */
1857
+    public function getEventLogger() {
1858
+        return $this->get(IEventLogger::class);
1859
+    }
1860
+
1861
+    /**
1862
+     * Get the active query logger
1863
+     *
1864
+     * The returned logger only logs data when debug mode is enabled
1865
+     *
1866
+     * @return IQueryLogger
1867
+     * @deprecated 20.0.0
1868
+     */
1869
+    public function getQueryLogger() {
1870
+        return $this->get(IQueryLogger::class);
1871
+    }
1872
+
1873
+    /**
1874
+     * Get the manager for temporary files and folders
1875
+     *
1876
+     * @return \OCP\ITempManager
1877
+     * @deprecated 20.0.0
1878
+     */
1879
+    public function getTempManager() {
1880
+        return $this->get(ITempManager::class);
1881
+    }
1882
+
1883
+    /**
1884
+     * Get the app manager
1885
+     *
1886
+     * @return \OCP\App\IAppManager
1887
+     * @deprecated 20.0.0
1888
+     */
1889
+    public function getAppManager() {
1890
+        return $this->get(IAppManager::class);
1891
+    }
1892
+
1893
+    /**
1894
+     * Creates a new mailer
1895
+     *
1896
+     * @return IMailer
1897
+     * @deprecated 20.0.0
1898
+     */
1899
+    public function getMailer() {
1900
+        return $this->get(IMailer::class);
1901
+    }
1902
+
1903
+    /**
1904
+     * Get the webroot
1905
+     *
1906
+     * @return string
1907
+     * @deprecated 20.0.0
1908
+     */
1909
+    public function getWebRoot() {
1910
+        return $this->webRoot;
1911
+    }
1912
+
1913
+    /**
1914
+     * @return \OC\OCSClient
1915
+     * @deprecated 20.0.0
1916
+     */
1917
+    public function getOcsClient() {
1918
+        return $this->get('OcsClient');
1919
+    }
1920
+
1921
+    /**
1922
+     * @return IDateTimeZone
1923
+     * @deprecated 20.0.0
1924
+     */
1925
+    public function getDateTimeZone() {
1926
+        return $this->get(IDateTimeZone::class);
1927
+    }
1928
+
1929
+    /**
1930
+     * @return IDateTimeFormatter
1931
+     * @deprecated 20.0.0
1932
+     */
1933
+    public function getDateTimeFormatter() {
1934
+        return $this->get(IDateTimeFormatter::class);
1935
+    }
1936
+
1937
+    /**
1938
+     * @return IMountProviderCollection
1939
+     * @deprecated 20.0.0
1940
+     */
1941
+    public function getMountProviderCollection() {
1942
+        return $this->get(IMountProviderCollection::class);
1943
+    }
1944
+
1945
+    /**
1946
+     * Get the IniWrapper
1947
+     *
1948
+     * @return IniGetWrapper
1949
+     * @deprecated 20.0.0
1950
+     */
1951
+    public function getIniWrapper() {
1952
+        return $this->get(IniGetWrapper::class);
1953
+    }
1954
+
1955
+    /**
1956
+     * @return \OCP\Command\IBus
1957
+     * @deprecated 20.0.0
1958
+     */
1959
+    public function getCommandBus() {
1960
+        return $this->get(IBus::class);
1961
+    }
1962
+
1963
+    /**
1964
+     * Get the trusted domain helper
1965
+     *
1966
+     * @return TrustedDomainHelper
1967
+     * @deprecated 20.0.0
1968
+     */
1969
+    public function getTrustedDomainHelper() {
1970
+        return $this->get(TrustedDomainHelper::class);
1971
+    }
1972
+
1973
+    /**
1974
+     * Get the locking provider
1975
+     *
1976
+     * @return ILockingProvider
1977
+     * @since 8.1.0
1978
+     * @deprecated 20.0.0
1979
+     */
1980
+    public function getLockingProvider() {
1981
+        return $this->get(ILockingProvider::class);
1982
+    }
1983
+
1984
+    /**
1985
+     * @return IMountManager
1986
+     * @deprecated 20.0.0
1987
+     **/
1988
+    public function getMountManager() {
1989
+        return $this->get(IMountManager::class);
1990
+    }
1991
+
1992
+    /**
1993
+     * @return IUserMountCache
1994
+     * @deprecated 20.0.0
1995
+     */
1996
+    public function getUserMountCache() {
1997
+        return $this->get(IUserMountCache::class);
1998
+    }
1999
+
2000
+    /**
2001
+     * Get the MimeTypeDetector
2002
+     *
2003
+     * @return IMimeTypeDetector
2004
+     * @deprecated 20.0.0
2005
+     */
2006
+    public function getMimeTypeDetector() {
2007
+        return $this->get(IMimeTypeDetector::class);
2008
+    }
2009
+
2010
+    /**
2011
+     * Get the MimeTypeLoader
2012
+     *
2013
+     * @return IMimeTypeLoader
2014
+     * @deprecated 20.0.0
2015
+     */
2016
+    public function getMimeTypeLoader() {
2017
+        return $this->get(IMimeTypeLoader::class);
2018
+    }
2019
+
2020
+    /**
2021
+     * Get the manager of all the capabilities
2022
+     *
2023
+     * @return CapabilitiesManager
2024
+     * @deprecated 20.0.0
2025
+     */
2026
+    public function getCapabilitiesManager() {
2027
+        return $this->get(CapabilitiesManager::class);
2028
+    }
2029
+
2030
+    /**
2031
+     * Get the EventDispatcher
2032
+     *
2033
+     * @return EventDispatcherInterface
2034
+     * @since 8.2.0
2035
+     * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher
2036
+     */
2037
+    public function getEventDispatcher() {
2038
+        return $this->get(\OC\EventDispatcher\SymfonyAdapter::class);
2039
+    }
2040
+
2041
+    /**
2042
+     * Get the Notification Manager
2043
+     *
2044
+     * @return \OCP\Notification\IManager
2045
+     * @since 8.2.0
2046
+     * @deprecated 20.0.0
2047
+     */
2048
+    public function getNotificationManager() {
2049
+        return $this->get(\OCP\Notification\IManager::class);
2050
+    }
2051
+
2052
+    /**
2053
+     * @return ICommentsManager
2054
+     * @deprecated 20.0.0
2055
+     */
2056
+    public function getCommentsManager() {
2057
+        return $this->get(ICommentsManager::class);
2058
+    }
2059
+
2060
+    /**
2061
+     * @return \OCA\Theming\ThemingDefaults
2062
+     * @deprecated 20.0.0
2063
+     */
2064
+    public function getThemingDefaults() {
2065
+        return $this->get('ThemingDefaults');
2066
+    }
2067
+
2068
+    /**
2069
+     * @return \OC\IntegrityCheck\Checker
2070
+     * @deprecated 20.0.0
2071
+     */
2072
+    public function getIntegrityCodeChecker() {
2073
+        return $this->get('IntegrityCodeChecker');
2074
+    }
2075
+
2076
+    /**
2077
+     * @return \OC\Session\CryptoWrapper
2078
+     * @deprecated 20.0.0
2079
+     */
2080
+    public function getSessionCryptoWrapper() {
2081
+        return $this->get('CryptoWrapper');
2082
+    }
2083
+
2084
+    /**
2085
+     * @return CsrfTokenManager
2086
+     * @deprecated 20.0.0
2087
+     */
2088
+    public function getCsrfTokenManager() {
2089
+        return $this->get(CsrfTokenManager::class);
2090
+    }
2091
+
2092
+    /**
2093
+     * @return Throttler
2094
+     * @deprecated 20.0.0
2095
+     */
2096
+    public function getBruteForceThrottler() {
2097
+        return $this->get(Throttler::class);
2098
+    }
2099
+
2100
+    /**
2101
+     * @return IContentSecurityPolicyManager
2102
+     * @deprecated 20.0.0
2103
+     */
2104
+    public function getContentSecurityPolicyManager() {
2105
+        return $this->get(ContentSecurityPolicyManager::class);
2106
+    }
2107
+
2108
+    /**
2109
+     * @return ContentSecurityPolicyNonceManager
2110
+     * @deprecated 20.0.0
2111
+     */
2112
+    public function getContentSecurityPolicyNonceManager() {
2113
+        return $this->get(ContentSecurityPolicyNonceManager::class);
2114
+    }
2115
+
2116
+    /**
2117
+     * Not a public API as of 8.2, wait for 9.0
2118
+     *
2119
+     * @return \OCA\Files_External\Service\BackendService
2120
+     * @deprecated 20.0.0
2121
+     */
2122
+    public function getStoragesBackendService() {
2123
+        return $this->get(BackendService::class);
2124
+    }
2125
+
2126
+    /**
2127
+     * Not a public API as of 8.2, wait for 9.0
2128
+     *
2129
+     * @return \OCA\Files_External\Service\GlobalStoragesService
2130
+     * @deprecated 20.0.0
2131
+     */
2132
+    public function getGlobalStoragesService() {
2133
+        return $this->get(GlobalStoragesService::class);
2134
+    }
2135
+
2136
+    /**
2137
+     * Not a public API as of 8.2, wait for 9.0
2138
+     *
2139
+     * @return \OCA\Files_External\Service\UserGlobalStoragesService
2140
+     * @deprecated 20.0.0
2141
+     */
2142
+    public function getUserGlobalStoragesService() {
2143
+        return $this->get(UserGlobalStoragesService::class);
2144
+    }
2145
+
2146
+    /**
2147
+     * Not a public API as of 8.2, wait for 9.0
2148
+     *
2149
+     * @return \OCA\Files_External\Service\UserStoragesService
2150
+     * @deprecated 20.0.0
2151
+     */
2152
+    public function getUserStoragesService() {
2153
+        return $this->get(UserStoragesService::class);
2154
+    }
2155
+
2156
+    /**
2157
+     * @return \OCP\Share\IManager
2158
+     * @deprecated 20.0.0
2159
+     */
2160
+    public function getShareManager() {
2161
+        return $this->get(\OCP\Share\IManager::class);
2162
+    }
2163
+
2164
+    /**
2165
+     * @return \OCP\Collaboration\Collaborators\ISearch
2166
+     * @deprecated 20.0.0
2167
+     */
2168
+    public function getCollaboratorSearch() {
2169
+        return $this->get(\OCP\Collaboration\Collaborators\ISearch::class);
2170
+    }
2171
+
2172
+    /**
2173
+     * @return \OCP\Collaboration\AutoComplete\IManager
2174
+     * @deprecated 20.0.0
2175
+     */
2176
+    public function getAutoCompleteManager() {
2177
+        return $this->get(IManager::class);
2178
+    }
2179
+
2180
+    /**
2181
+     * Returns the LDAP Provider
2182
+     *
2183
+     * @return \OCP\LDAP\ILDAPProvider
2184
+     * @deprecated 20.0.0
2185
+     */
2186
+    public function getLDAPProvider() {
2187
+        return $this->get('LDAPProvider');
2188
+    }
2189
+
2190
+    /**
2191
+     * @return \OCP\Settings\IManager
2192
+     * @deprecated 20.0.0
2193
+     */
2194
+    public function getSettingsManager() {
2195
+        return $this->get(\OC\Settings\Manager::class);
2196
+    }
2197
+
2198
+    /**
2199
+     * @return \OCP\Files\IAppData
2200
+     * @deprecated 20.0.0
2201
+     */
2202
+    public function getAppDataDir($app) {
2203
+        /** @var \OC\Files\AppData\Factory $factory */
2204
+        $factory = $this->get(\OC\Files\AppData\Factory::class);
2205
+        return $factory->get($app);
2206
+    }
2207
+
2208
+    /**
2209
+     * @return \OCP\Lockdown\ILockdownManager
2210
+     * @deprecated 20.0.0
2211
+     */
2212
+    public function getLockdownManager() {
2213
+        return $this->get('LockdownManager');
2214
+    }
2215
+
2216
+    /**
2217
+     * @return \OCP\Federation\ICloudIdManager
2218
+     * @deprecated 20.0.0
2219
+     */
2220
+    public function getCloudIdManager() {
2221
+        return $this->get(ICloudIdManager::class);
2222
+    }
2223
+
2224
+    /**
2225
+     * @return \OCP\GlobalScale\IConfig
2226
+     * @deprecated 20.0.0
2227
+     */
2228
+    public function getGlobalScaleConfig() {
2229
+        return $this->get(IConfig::class);
2230
+    }
2231
+
2232
+    /**
2233
+     * @return \OCP\Federation\ICloudFederationProviderManager
2234
+     * @deprecated 20.0.0
2235
+     */
2236
+    public function getCloudFederationProviderManager() {
2237
+        return $this->get(ICloudFederationProviderManager::class);
2238
+    }
2239
+
2240
+    /**
2241
+     * @return \OCP\Remote\Api\IApiFactory
2242
+     * @deprecated 20.0.0
2243
+     */
2244
+    public function getRemoteApiFactory() {
2245
+        return $this->get(IApiFactory::class);
2246
+    }
2247
+
2248
+    /**
2249
+     * @return \OCP\Federation\ICloudFederationFactory
2250
+     * @deprecated 20.0.0
2251
+     */
2252
+    public function getCloudFederationFactory() {
2253
+        return $this->get(ICloudFederationFactory::class);
2254
+    }
2255
+
2256
+    /**
2257
+     * @return \OCP\Remote\IInstanceFactory
2258
+     * @deprecated 20.0.0
2259
+     */
2260
+    public function getRemoteInstanceFactory() {
2261
+        return $this->get(IInstanceFactory::class);
2262
+    }
2263
+
2264
+    /**
2265
+     * @return IStorageFactory
2266
+     * @deprecated 20.0.0
2267
+     */
2268
+    public function getStorageFactory() {
2269
+        return $this->get(IStorageFactory::class);
2270
+    }
2271
+
2272
+    /**
2273
+     * Get the Preview GeneratorHelper
2274
+     *
2275
+     * @return GeneratorHelper
2276
+     * @since 17.0.0
2277
+     * @deprecated 20.0.0
2278
+     */
2279
+    public function getGeneratorHelper() {
2280
+        return $this->get(\OC\Preview\GeneratorHelper::class);
2281
+    }
2282
+
2283
+    private function registerDeprecatedAlias(string $alias, string $target) {
2284
+        $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) {
2285
+            try {
2286
+                /** @var ILogger $logger */
2287
+                $logger = $container->get(ILogger::class);
2288
+                $logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']);
2289
+            } catch (ContainerExceptionInterface $e) {
2290
+                // Could not get logger. Continue
2291
+            }
2292
+
2293
+            return $container->get($target);
2294
+        }, false);
2295
+    }
2296 2296
 }
Please login to merge, or discard this patch.
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -268,10 +268,10 @@  discard block
 block discarded – undo
268 268
 		$this->registerParameter('isCLI', \OC::$CLI);
269 269
 		$this->registerParameter('serverRoot', \OC::$SERVERROOT);
270 270
 
271
-		$this->registerService(ContainerInterface::class, function (ContainerInterface $c) {
271
+		$this->registerService(ContainerInterface::class, function(ContainerInterface $c) {
272 272
 			return $c;
273 273
 		});
274
-		$this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) {
274
+		$this->registerService(\OCP\IServerContainer::class, function(ContainerInterface $c) {
275 275
 			return $c;
276 276
 		});
277 277
 
@@ -296,11 +296,11 @@  discard block
 block discarded – undo
296 296
 
297 297
 		$this->registerAlias(IActionFactory::class, ActionFactory::class);
298 298
 
299
-		$this->registerService(View::class, function (Server $c) {
299
+		$this->registerService(View::class, function(Server $c) {
300 300
 			return new View();
301 301
 		}, false);
302 302
 
303
-		$this->registerService(IPreview::class, function (ContainerInterface $c) {
303
+		$this->registerService(IPreview::class, function(ContainerInterface $c) {
304 304
 			return new PreviewManager(
305 305
 				$c->get(\OCP\IConfig::class),
306 306
 				$c->get(IRootFolder::class),
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 		/** @deprecated 19.0.0 */
317 317
 		$this->registerDeprecatedAlias('PreviewManager', IPreview::class);
318 318
 
319
-		$this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) {
319
+		$this->registerService(\OC\Preview\Watcher::class, function(ContainerInterface $c) {
320 320
 			return new \OC\Preview\Watcher(
321 321
 				new \OC\Preview\Storage\Root(
322 322
 					$c->get(IRootFolder::class),
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 			);
326 326
 		});
327 327
 
328
-		$this->registerService(\OCP\Encryption\IManager::class, function (Server $c) {
328
+		$this->registerService(\OCP\Encryption\IManager::class, function(Server $c) {
329 329
 			$view = new View();
330 330
 			$util = new Encryption\Util(
331 331
 				$view,
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 
348 348
 		/** @deprecated 21.0.0 */
349 349
 		$this->registerDeprecatedAlias('EncryptionFileHelper', IFile::class);
350
-		$this->registerService(IFile::class, function (ContainerInterface $c) {
350
+		$this->registerService(IFile::class, function(ContainerInterface $c) {
351 351
 			$util = new Encryption\Util(
352 352
 				new View(),
353 353
 				$c->get(IUserManager::class),
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
 
364 364
 		/** @deprecated 21.0.0 */
365 365
 		$this->registerDeprecatedAlias('EncryptionKeyStorage', IStorage::class);
366
-		$this->registerService(IStorage::class, function (ContainerInterface $c) {
366
+		$this->registerService(IStorage::class, function(ContainerInterface $c) {
367 367
 			$view = new View();
368 368
 			$util = new Encryption\Util(
369 369
 				$view,
@@ -386,22 +386,22 @@  discard block
 block discarded – undo
386 386
 		/** @deprecated 19.0.0 */
387 387
 		$this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class);
388 388
 
389
-		$this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) {
389
+		$this->registerService('SystemTagManagerFactory', function(ContainerInterface $c) {
390 390
 			/** @var \OCP\IConfig $config */
391 391
 			$config = $c->get(\OCP\IConfig::class);
392 392
 			$factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
393 393
 			return new $factoryClass($this);
394 394
 		});
395
-		$this->registerService(ISystemTagManager::class, function (ContainerInterface $c) {
395
+		$this->registerService(ISystemTagManager::class, function(ContainerInterface $c) {
396 396
 			return $c->get('SystemTagManagerFactory')->getManager();
397 397
 		});
398 398
 		/** @deprecated 19.0.0 */
399 399
 		$this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class);
400 400
 
401
-		$this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) {
401
+		$this->registerService(ISystemTagObjectMapper::class, function(ContainerInterface $c) {
402 402
 			return $c->get('SystemTagManagerFactory')->getObjectMapper();
403 403
 		});
404
-		$this->registerService('RootFolder', function (ContainerInterface $c) {
404
+		$this->registerService('RootFolder', function(ContainerInterface $c) {
405 405
 			$manager = \OC\Files\Filesystem::getMountManager(null);
406 406
 			$view = new View();
407 407
 			$root = new Root(
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
 
422 422
 			return $root;
423 423
 		});
424
-		$this->registerService(HookConnector::class, function (ContainerInterface $c) {
424
+		$this->registerService(HookConnector::class, function(ContainerInterface $c) {
425 425
 			return new HookConnector(
426 426
 				$c->get(IRootFolder::class),
427 427
 				new View(),
@@ -433,8 +433,8 @@  discard block
 block discarded – undo
433 433
 		/** @deprecated 19.0.0 */
434 434
 		$this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class);
435 435
 
436
-		$this->registerService(IRootFolder::class, function (ContainerInterface $c) {
437
-			return new LazyRoot(function () use ($c) {
436
+		$this->registerService(IRootFolder::class, function(ContainerInterface $c) {
437
+			return new LazyRoot(function() use ($c) {
438 438
 				return $c->get('RootFolder');
439 439
 			});
440 440
 		});
@@ -445,44 +445,44 @@  discard block
 block discarded – undo
445 445
 		$this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class);
446 446
 		$this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
447 447
 
448
-		$this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) {
448
+		$this->registerService(\OCP\IGroupManager::class, function(ContainerInterface $c) {
449 449
 			$groupManager = new \OC\Group\Manager($this->get(IUserManager::class), $c->get(SymfonyAdapter::class), $this->get(ILogger::class));
450
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
450
+			$groupManager->listen('\OC\Group', 'preCreate', function($gid) {
451 451
 				/** @var IEventDispatcher $dispatcher */
452 452
 				$dispatcher = $this->get(IEventDispatcher::class);
453 453
 				$dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid));
454 454
 			});
455
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) {
455
+			$groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $group) {
456 456
 				/** @var IEventDispatcher $dispatcher */
457 457
 				$dispatcher = $this->get(IEventDispatcher::class);
458 458
 				$dispatcher->dispatchTyped(new GroupCreatedEvent($group));
459 459
 			});
460
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
460
+			$groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) {
461 461
 				/** @var IEventDispatcher $dispatcher */
462 462
 				$dispatcher = $this->get(IEventDispatcher::class);
463 463
 				$dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group));
464 464
 			});
465
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
465
+			$groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) {
466 466
 				/** @var IEventDispatcher $dispatcher */
467 467
 				$dispatcher = $this->get(IEventDispatcher::class);
468 468
 				$dispatcher->dispatchTyped(new GroupDeletedEvent($group));
469 469
 			});
470
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
470
+			$groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) {
471 471
 				/** @var IEventDispatcher $dispatcher */
472 472
 				$dispatcher = $this->get(IEventDispatcher::class);
473 473
 				$dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user));
474 474
 			});
475
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
475
+			$groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) {
476 476
 				/** @var IEventDispatcher $dispatcher */
477 477
 				$dispatcher = $this->get(IEventDispatcher::class);
478 478
 				$dispatcher->dispatchTyped(new UserAddedEvent($group, $user));
479 479
 			});
480
-			$groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
480
+			$groupManager->listen('\OC\Group', 'preRemoveUser', function(\OC\Group\Group $group, \OC\User\User $user) {
481 481
 				/** @var IEventDispatcher $dispatcher */
482 482
 				$dispatcher = $this->get(IEventDispatcher::class);
483 483
 				$dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user));
484 484
 			});
485
-			$groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
485
+			$groupManager->listen('\OC\Group', 'postRemoveUser', function(\OC\Group\Group $group, \OC\User\User $user) {
486 486
 				/** @var IEventDispatcher $dispatcher */
487 487
 				$dispatcher = $this->get(IEventDispatcher::class);
488 488
 				$dispatcher->dispatchTyped(new UserRemovedEvent($group, $user));
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
 		/** @deprecated 19.0.0 */
493 493
 		$this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class);
494 494
 
495
-		$this->registerService(Store::class, function (ContainerInterface $c) {
495
+		$this->registerService(Store::class, function(ContainerInterface $c) {
496 496
 			$session = $c->get(ISession::class);
497 497
 			if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
498 498
 				$tokenProvider = $c->get(IProvider::class);
@@ -505,7 +505,7 @@  discard block
 block discarded – undo
505 505
 		$this->registerAlias(IStore::class, Store::class);
506 506
 		$this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
507 507
 
508
-		$this->registerService(\OC\User\Session::class, function (Server $c) {
508
+		$this->registerService(\OC\User\Session::class, function(Server $c) {
509 509
 			$manager = $c->get(IUserManager::class);
510 510
 			$session = new \OC\Session\Memory('');
511 511
 			$timeFactory = new TimeFactory();
@@ -531,26 +531,26 @@  discard block
 block discarded – undo
531 531
 				$c->get(IEventDispatcher::class)
532 532
 			);
533 533
 			/** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */
534
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
534
+			$userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) {
535 535
 				\OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]);
536 536
 			});
537 537
 			/** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */
538
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
538
+			$userSession->listen('\OC\User', 'postCreateUser', function($user, $password) {
539 539
 				/** @var \OC\User\User $user */
540 540
 				\OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]);
541 541
 			});
542 542
 			/** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */
543
-			$userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) {
543
+			$userSession->listen('\OC\User', 'preDelete', function($user) use ($legacyDispatcher) {
544 544
 				/** @var \OC\User\User $user */
545 545
 				\OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]);
546 546
 				$legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
547 547
 			});
548 548
 			/** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */
549
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
549
+			$userSession->listen('\OC\User', 'postDelete', function($user) {
550 550
 				/** @var \OC\User\User $user */
551 551
 				\OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]);
552 552
 			});
553
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
553
+			$userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) {
554 554
 				/** @var \OC\User\User $user */
555 555
 				\OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
556 556
 
@@ -558,7 +558,7 @@  discard block
 block discarded – undo
558 558
 				$dispatcher = $this->get(IEventDispatcher::class);
559 559
 				$dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword));
560 560
 			});
561
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
561
+			$userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) {
562 562
 				/** @var \OC\User\User $user */
563 563
 				\OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
564 564
 
@@ -566,14 +566,14 @@  discard block
 block discarded – undo
566 566
 				$dispatcher = $this->get(IEventDispatcher::class);
567 567
 				$dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword));
568 568
 			});
569
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
569
+			$userSession->listen('\OC\User', 'preLogin', function($uid, $password) {
570 570
 				\OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]);
571 571
 
572 572
 				/** @var IEventDispatcher $dispatcher */
573 573
 				$dispatcher = $this->get(IEventDispatcher::class);
574 574
 				$dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password));
575 575
 			});
576
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) {
576
+			$userSession->listen('\OC\User', 'postLogin', function($user, $loginName, $password, $isTokenLogin) {
577 577
 				/** @var \OC\User\User $user */
578 578
 				\OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]);
579 579
 
@@ -581,12 +581,12 @@  discard block
 block discarded – undo
581 581
 				$dispatcher = $this->get(IEventDispatcher::class);
582 582
 				$dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin));
583 583
 			});
584
-			$userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) {
584
+			$userSession->listen('\OC\User', 'preRememberedLogin', function($uid) {
585 585
 				/** @var IEventDispatcher $dispatcher */
586 586
 				$dispatcher = $this->get(IEventDispatcher::class);
587 587
 				$dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid));
588 588
 			});
589
-			$userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
589
+			$userSession->listen('\OC\User', 'postRememberedLogin', function($user, $password) {
590 590
 				/** @var \OC\User\User $user */
591 591
 				\OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]);
592 592
 
@@ -594,19 +594,19 @@  discard block
 block discarded – undo
594 594
 				$dispatcher = $this->get(IEventDispatcher::class);
595 595
 				$dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password));
596 596
 			});
597
-			$userSession->listen('\OC\User', 'logout', function ($user) {
597
+			$userSession->listen('\OC\User', 'logout', function($user) {
598 598
 				\OC_Hook::emit('OC_User', 'logout', []);
599 599
 
600 600
 				/** @var IEventDispatcher $dispatcher */
601 601
 				$dispatcher = $this->get(IEventDispatcher::class);
602 602
 				$dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user));
603 603
 			});
604
-			$userSession->listen('\OC\User', 'postLogout', function ($user) {
604
+			$userSession->listen('\OC\User', 'postLogout', function($user) {
605 605
 				/** @var IEventDispatcher $dispatcher */
606 606
 				$dispatcher = $this->get(IEventDispatcher::class);
607 607
 				$dispatcher->dispatchTyped(new UserLoggedOutEvent($user));
608 608
 			});
609
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
609
+			$userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) {
610 610
 				/** @var \OC\User\User $user */
611 611
 				\OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]);
612 612
 
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
 		$this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class);
631 631
 		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
632 632
 
633
-		$this->registerService(\OC\SystemConfig::class, function ($c) use ($config) {
633
+		$this->registerService(\OC\SystemConfig::class, function($c) use ($config) {
634 634
 			return new \OC\SystemConfig($config);
635 635
 		});
636 636
 		/** @deprecated 19.0.0 */
@@ -640,7 +640,7 @@  discard block
 block discarded – undo
640 640
 		$this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class);
641 641
 		$this->registerAlias(IAppConfig::class, \OC\AppConfig::class);
642 642
 
643
-		$this->registerService(IFactory::class, function (Server $c) {
643
+		$this->registerService(IFactory::class, function(Server $c) {
644 644
 			return new \OC\L10N\Factory(
645 645
 				$c->get(\OCP\IConfig::class),
646 646
 				$c->getRequest(),
@@ -660,13 +660,13 @@  discard block
 block discarded – undo
660 660
 		/** @deprecated 19.0.0 */
661 661
 		$this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class);
662 662
 
663
-		$this->registerService(ICache::class, function ($c) {
663
+		$this->registerService(ICache::class, function($c) {
664 664
 			return new Cache\File();
665 665
 		});
666 666
 		/** @deprecated 19.0.0 */
667 667
 		$this->registerDeprecatedAlias('UserCache', ICache::class);
668 668
 
669
-		$this->registerService(Factory::class, function (Server $c) {
669
+		$this->registerService(Factory::class, function(Server $c) {
670 670
 			$arrayCacheFactory = new \OC\Memcache\Factory('', $c->get(ILogger::class),
671 671
 				ArrayCache::class,
672 672
 				ArrayCache::class,
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
 				$version = implode(',', $v);
682 682
 				$instanceId = \OC_Util::getInstanceId();
683 683
 				$path = \OC::$SERVERROOT;
684
-				$prefix = md5($instanceId . '-' . $version . '-' . $path);
684
+				$prefix = md5($instanceId.'-'.$version.'-'.$path);
685 685
 				return new \OC\Memcache\Factory($prefix, $c->get(ILogger::class),
686 686
 					$config->getSystemValue('memcache.local', null),
687 687
 					$config->getSystemValue('memcache.distributed', null),
@@ -694,12 +694,12 @@  discard block
 block discarded – undo
694 694
 		$this->registerDeprecatedAlias('MemCacheFactory', Factory::class);
695 695
 		$this->registerAlias(ICacheFactory::class, Factory::class);
696 696
 
697
-		$this->registerService('RedisFactory', function (Server $c) {
697
+		$this->registerService('RedisFactory', function(Server $c) {
698 698
 			$systemConfig = $c->get(SystemConfig::class);
699 699
 			return new RedisFactory($systemConfig);
700 700
 		});
701 701
 
702
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
702
+		$this->registerService(\OCP\Activity\IManager::class, function(Server $c) {
703 703
 			$l10n = $this->get(IFactory::class)->get('lib');
704 704
 			return new \OC\Activity\Manager(
705 705
 				$c->getRequest(),
@@ -712,14 +712,14 @@  discard block
 block discarded – undo
712 712
 		/** @deprecated 19.0.0 */
713 713
 		$this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class);
714 714
 
715
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
715
+		$this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) {
716 716
 			return new \OC\Activity\EventMerger(
717 717
 				$c->getL10N('lib')
718 718
 			);
719 719
 		});
720 720
 		$this->registerAlias(IValidator::class, Validator::class);
721 721
 
722
-		$this->registerService(AvatarManager::class, function (Server $c) {
722
+		$this->registerService(AvatarManager::class, function(Server $c) {
723 723
 			return new AvatarManager(
724 724
 				$c->get(IUserSession::class),
725 725
 				$c->get(\OC\User\Manager::class),
@@ -738,7 +738,7 @@  discard block
 block discarded – undo
738 738
 		$this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
739 739
 		$this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class);
740 740
 
741
-		$this->registerService(\OC\Log::class, function (Server $c) {
741
+		$this->registerService(\OC\Log::class, function(Server $c) {
742 742
 			$logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file');
743 743
 			$factory = new LogFactory($c, $this->get(SystemConfig::class));
744 744
 			$logger = $factory->get($logType);
@@ -752,7 +752,7 @@  discard block
 block discarded – undo
752 752
 		// PSR-3 logger
753 753
 		$this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class);
754 754
 
755
-		$this->registerService(ILogFactory::class, function (Server $c) {
755
+		$this->registerService(ILogFactory::class, function(Server $c) {
756 756
 			return new LogFactory($c, $this->get(SystemConfig::class));
757 757
 		});
758 758
 
@@ -760,7 +760,7 @@  discard block
 block discarded – undo
760 760
 		/** @deprecated 19.0.0 */
761 761
 		$this->registerDeprecatedAlias('JobList', IJobList::class);
762 762
 
763
-		$this->registerService(Router::class, function (Server $c) {
763
+		$this->registerService(Router::class, function(Server $c) {
764 764
 			$cacheFactory = $c->get(ICacheFactory::class);
765 765
 			$logger = $c->get(ILogger::class);
766 766
 			if ($cacheFactory->isLocalCacheAvailable()) {
@@ -778,7 +778,7 @@  discard block
 block discarded – undo
778 778
 		/** @deprecated 19.0.0 */
779 779
 		$this->registerDeprecatedAlias('Search', ISearch::class);
780 780
 
781
-		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
781
+		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) {
782 782
 			return new \OC\Security\RateLimiting\Backend\MemoryCache(
783 783
 				$this->get(ICacheFactory::class),
784 784
 				new \OC\AppFramework\Utility\TimeFactory()
@@ -802,7 +802,7 @@  discard block
 block discarded – undo
802 802
 		$this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class);
803 803
 
804 804
 		$this->registerAlias(IDBConnection::class, ConnectionAdapter::class);
805
-		$this->registerService(Connection::class, function (Server $c) {
805
+		$this->registerService(Connection::class, function(Server $c) {
806 806
 			$systemConfig = $c->get(SystemConfig::class);
807 807
 			$factory = new \OC\DB\ConnectionFactory($systemConfig);
808 808
 			$type = $systemConfig->getValue('dbtype', 'sqlite');
@@ -820,7 +820,7 @@  discard block
 block discarded – undo
820 820
 		$this->registerAlias(ICertificateManager::class, CertificateManager::class);
821 821
 		$this->registerAlias(IClientService::class, ClientService::class);
822 822
 		$this->registerDeprecatedAlias('HttpClientService', IClientService::class);
823
-		$this->registerService(IEventLogger::class, function (ContainerInterface $c) {
823
+		$this->registerService(IEventLogger::class, function(ContainerInterface $c) {
824 824
 			$eventLogger = new EventLogger();
825 825
 			if ($c->get(SystemConfig::class)->getValue('debug', false)) {
826 826
 				// In debug mode, module is being activated by default
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
 		/** @deprecated 19.0.0 */
832 832
 		$this->registerDeprecatedAlias('EventLogger', IEventLogger::class);
833 833
 
834
-		$this->registerService(IQueryLogger::class, function (ContainerInterface $c) {
834
+		$this->registerService(IQueryLogger::class, function(ContainerInterface $c) {
835 835
 			$queryLogger = new QueryLogger();
836 836
 			if ($c->get(SystemConfig::class)->getValue('debug', false)) {
837 837
 				// In debug mode, module is being activated by default
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
 		$this->registerDeprecatedAlias('TempManager', TempManager::class);
847 847
 		$this->registerAlias(ITempManager::class, TempManager::class);
848 848
 
849
-		$this->registerService(AppManager::class, function (ContainerInterface $c) {
849
+		$this->registerService(AppManager::class, function(ContainerInterface $c) {
850 850
 			// TODO: use auto-wiring
851 851
 			return new \OC\App\AppManager(
852 852
 				$c->get(IUserSession::class),
@@ -866,7 +866,7 @@  discard block
 block discarded – undo
866 866
 		/** @deprecated 19.0.0 */
867 867
 		$this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class);
868 868
 
869
-		$this->registerService(IDateTimeFormatter::class, function (Server $c) {
869
+		$this->registerService(IDateTimeFormatter::class, function(Server $c) {
870 870
 			$language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null);
871 871
 
872 872
 			return new DateTimeFormatter(
@@ -877,7 +877,7 @@  discard block
 block discarded – undo
877 877
 		/** @deprecated 19.0.0 */
878 878
 		$this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class);
879 879
 
880
-		$this->registerService(IUserMountCache::class, function (ContainerInterface $c) {
880
+		$this->registerService(IUserMountCache::class, function(ContainerInterface $c) {
881 881
 			$mountCache = new UserMountCache(
882 882
 				$c->get(IDBConnection::class),
883 883
 				$c->get(IUserManager::class),
@@ -890,7 +890,7 @@  discard block
 block discarded – undo
890 890
 		/** @deprecated 19.0.0 */
891 891
 		$this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class);
892 892
 
893
-		$this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) {
893
+		$this->registerService(IMountProviderCollection::class, function(ContainerInterface $c) {
894 894
 			$loader = \OC\Files\Filesystem::getLoader();
895 895
 			$mountCache = $c->get(IUserMountCache::class);
896 896
 			$manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
@@ -911,7 +911,7 @@  discard block
 block discarded – undo
911 911
 
912 912
 		/** @deprecated 20.0.0 */
913 913
 		$this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class);
914
-		$this->registerService(IBus::class, function (ContainerInterface $c) {
914
+		$this->registerService(IBus::class, function(ContainerInterface $c) {
915 915
 			$busClass = $c->get(\OCP\IConfig::class)->getSystemValue('commandbus');
916 916
 			if ($busClass) {
917 917
 				[$app, $class] = explode('::', $busClass, 2);
@@ -931,7 +931,7 @@  discard block
 block discarded – undo
931 931
 		$this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class);
932 932
 		/** @deprecated 19.0.0 */
933 933
 		$this->registerDeprecatedAlias('Throttler', Throttler::class);
934
-		$this->registerService('IntegrityCodeChecker', function (ContainerInterface $c) {
934
+		$this->registerService('IntegrityCodeChecker', function(ContainerInterface $c) {
935 935
 			// IConfig and IAppManager requires a working database. This code
936 936
 			// might however be called when ownCloud is not yet setup.
937 937
 			if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
@@ -952,7 +952,7 @@  discard block
 block discarded – undo
952 952
 				$c->get(IMimeTypeDetector::class)
953 953
 			);
954 954
 		});
955
-		$this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) {
955
+		$this->registerService(\OCP\IRequest::class, function(ContainerInterface $c) {
956 956
 			if (isset($this['urlParams'])) {
957 957
 				$urlParams = $this['urlParams'];
958 958
 			} else {
@@ -989,7 +989,7 @@  discard block
 block discarded – undo
989 989
 		/** @deprecated 19.0.0 */
990 990
 		$this->registerDeprecatedAlias('Request', \OCP\IRequest::class);
991 991
 
992
-		$this->registerService(IMailer::class, function (Server $c) {
992
+		$this->registerService(IMailer::class, function(Server $c) {
993 993
 			return new Mailer(
994 994
 				$c->get(\OCP\IConfig::class),
995 995
 				$c->get(ILogger::class),
@@ -1003,7 +1003,7 @@  discard block
 block discarded – undo
1003 1003
 		/** @deprecated 19.0.0 */
1004 1004
 		$this->registerDeprecatedAlias('Mailer', IMailer::class);
1005 1005
 
1006
-		$this->registerService('LDAPProvider', function (ContainerInterface $c) {
1006
+		$this->registerService('LDAPProvider', function(ContainerInterface $c) {
1007 1007
 			$config = $c->get(\OCP\IConfig::class);
1008 1008
 			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
1009 1009
 			if (is_null($factoryClass)) {
@@ -1013,7 +1013,7 @@  discard block
 block discarded – undo
1013 1013
 			$factory = new $factoryClass($this);
1014 1014
 			return $factory->getLDAPProvider();
1015 1015
 		});
1016
-		$this->registerService(ILockingProvider::class, function (ContainerInterface $c) {
1016
+		$this->registerService(ILockingProvider::class, function(ContainerInterface $c) {
1017 1017
 			$ini = $c->get(IniGetWrapper::class);
1018 1018
 			$config = $c->get(\OCP\IConfig::class);
1019 1019
 			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
@@ -1041,12 +1041,12 @@  discard block
 block discarded – undo
1041 1041
 		/** @deprecated 19.0.0 */
1042 1042
 		$this->registerDeprecatedAlias('MountManager', IMountManager::class);
1043 1043
 
1044
-		$this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) {
1044
+		$this->registerService(IMimeTypeDetector::class, function(ContainerInterface $c) {
1045 1045
 			return new \OC\Files\Type\Detection(
1046 1046
 				$c->get(IURLGenerator::class),
1047 1047
 				$c->get(ILogger::class),
1048 1048
 				\OC::$configDir,
1049
-				\OC::$SERVERROOT . '/resources/config/'
1049
+				\OC::$SERVERROOT.'/resources/config/'
1050 1050
 			);
1051 1051
 		});
1052 1052
 		/** @deprecated 19.0.0 */
@@ -1055,19 +1055,19 @@  discard block
 block discarded – undo
1055 1055
 		$this->registerAlias(IMimeTypeLoader::class, Loader::class);
1056 1056
 		/** @deprecated 19.0.0 */
1057 1057
 		$this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class);
1058
-		$this->registerService(BundleFetcher::class, function () {
1058
+		$this->registerService(BundleFetcher::class, function() {
1059 1059
 			return new BundleFetcher($this->getL10N('lib'));
1060 1060
 		});
1061 1061
 		$this->registerAlias(\OCP\Notification\IManager::class, Manager::class);
1062 1062
 		/** @deprecated 19.0.0 */
1063 1063
 		$this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class);
1064 1064
 
1065
-		$this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) {
1065
+		$this->registerService(CapabilitiesManager::class, function(ContainerInterface $c) {
1066 1066
 			$manager = new CapabilitiesManager($c->get(ILogger::class));
1067
-			$manager->registerCapability(function () use ($c) {
1067
+			$manager->registerCapability(function() use ($c) {
1068 1068
 				return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class));
1069 1069
 			});
1070
-			$manager->registerCapability(function () use ($c) {
1070
+			$manager->registerCapability(function() use ($c) {
1071 1071
 				return $c->get(\OC\Security\Bruteforce\Capabilities::class);
1072 1072
 			});
1073 1073
 			return $manager;
@@ -1075,14 +1075,14 @@  discard block
 block discarded – undo
1075 1075
 		/** @deprecated 19.0.0 */
1076 1076
 		$this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class);
1077 1077
 
1078
-		$this->registerService(ICommentsManager::class, function (Server $c) {
1078
+		$this->registerService(ICommentsManager::class, function(Server $c) {
1079 1079
 			$config = $c->get(\OCP\IConfig::class);
1080 1080
 			$factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
1081 1081
 			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
1082 1082
 			$factory = new $factoryClass($this);
1083 1083
 			$manager = $factory->getManager();
1084 1084
 
1085
-			$manager->registerDisplayNameResolver('user', function ($id) use ($c) {
1085
+			$manager->registerDisplayNameResolver('user', function($id) use ($c) {
1086 1086
 				$manager = $c->get(IUserManager::class);
1087 1087
 				$user = $manager->get($id);
1088 1088
 				if (is_null($user)) {
@@ -1100,7 +1100,7 @@  discard block
 block discarded – undo
1100 1100
 		$this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class);
1101 1101
 
1102 1102
 		$this->registerAlias(\OC_Defaults::class, 'ThemingDefaults');
1103
-		$this->registerService('ThemingDefaults', function (Server $c) {
1103
+		$this->registerService('ThemingDefaults', function(Server $c) {
1104 1104
 			/*
1105 1105
 			 * Dark magic for autoloader.
1106 1106
 			 * If we do a class_exists it will try to load the class which will
@@ -1135,7 +1135,7 @@  discard block
 block discarded – undo
1135 1135
 			}
1136 1136
 			return new \OC_Defaults();
1137 1137
 		});
1138
-		$this->registerService(JSCombiner::class, function (Server $c) {
1138
+		$this->registerService(JSCombiner::class, function(Server $c) {
1139 1139
 			return new JSCombiner(
1140 1140
 				$c->getAppDataDir('js'),
1141 1141
 				$c->get(IURLGenerator::class),
@@ -1149,7 +1149,7 @@  discard block
 block discarded – undo
1149 1149
 		$this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class);
1150 1150
 		$this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class);
1151 1151
 
1152
-		$this->registerService('CryptoWrapper', function (ContainerInterface $c) {
1152
+		$this->registerService('CryptoWrapper', function(ContainerInterface $c) {
1153 1153
 			// FIXME: Instantiiated here due to cyclic dependency
1154 1154
 			$request = new Request(
1155 1155
 				[
@@ -1176,14 +1176,14 @@  discard block
 block discarded – undo
1176 1176
 		});
1177 1177
 		/** @deprecated 19.0.0 */
1178 1178
 		$this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class);
1179
-		$this->registerService(SessionStorage::class, function (ContainerInterface $c) {
1179
+		$this->registerService(SessionStorage::class, function(ContainerInterface $c) {
1180 1180
 			return new SessionStorage($c->get(ISession::class));
1181 1181
 		});
1182 1182
 		$this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class);
1183 1183
 		/** @deprecated 19.0.0 */
1184 1184
 		$this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class);
1185 1185
 
1186
-		$this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) {
1186
+		$this->registerService(\OCP\Share\IManager::class, function(IServerContainer $c) {
1187 1187
 			$config = $c->get(\OCP\IConfig::class);
1188 1188
 			$factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
1189 1189
 			/** @var \OCP\Share\IProviderFactory $factory */
@@ -1213,7 +1213,7 @@  discard block
 block discarded – undo
1213 1213
 		/** @deprecated 19.0.0 */
1214 1214
 		$this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class);
1215 1215
 
1216
-		$this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) {
1216
+		$this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) {
1217 1217
 			$instance = new Collaboration\Collaborators\Search($c);
1218 1218
 
1219 1219
 			// register default plugins
@@ -1236,33 +1236,33 @@  discard block
 block discarded – undo
1236 1236
 
1237 1237
 		$this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class);
1238 1238
 		$this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class);
1239
-		$this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) {
1239
+		$this->registerService(\OC\Files\AppData\Factory::class, function(ContainerInterface $c) {
1240 1240
 			return new \OC\Files\AppData\Factory(
1241 1241
 				$c->get(IRootFolder::class),
1242 1242
 				$c->get(SystemConfig::class)
1243 1243
 			);
1244 1244
 		});
1245 1245
 
1246
-		$this->registerService('LockdownManager', function (ContainerInterface $c) {
1247
-			return new LockdownManager(function () use ($c) {
1246
+		$this->registerService('LockdownManager', function(ContainerInterface $c) {
1247
+			return new LockdownManager(function() use ($c) {
1248 1248
 				return $c->get(ISession::class);
1249 1249
 			});
1250 1250
 		});
1251 1251
 
1252
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) {
1252
+		$this->registerService(\OCP\OCS\IDiscoveryService::class, function(ContainerInterface $c) {
1253 1253
 			return new DiscoveryService(
1254 1254
 				$c->get(ICacheFactory::class),
1255 1255
 				$c->get(IClientService::class)
1256 1256
 			);
1257 1257
 		});
1258 1258
 
1259
-		$this->registerService(ICloudIdManager::class, function (ContainerInterface $c) {
1259
+		$this->registerService(ICloudIdManager::class, function(ContainerInterface $c) {
1260 1260
 			return new CloudIdManager($c->get(\OCP\Contacts\IManager::class));
1261 1261
 		});
1262 1262
 
1263 1263
 		$this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class);
1264 1264
 
1265
-		$this->registerService(ICloudFederationProviderManager::class, function (ContainerInterface $c) {
1265
+		$this->registerService(ICloudFederationProviderManager::class, function(ContainerInterface $c) {
1266 1266
 			return new CloudFederationProviderManager(
1267 1267
 				$c->get(IAppManager::class),
1268 1268
 				$c->get(IClientService::class),
@@ -1271,7 +1271,7 @@  discard block
 block discarded – undo
1271 1271
 			);
1272 1272
 		});
1273 1273
 
1274
-		$this->registerService(ICloudFederationFactory::class, function (Server $c) {
1274
+		$this->registerService(ICloudFederationFactory::class, function(Server $c) {
1275 1275
 			return new CloudFederationFactory();
1276 1276
 		});
1277 1277
 
@@ -1283,7 +1283,7 @@  discard block
 block discarded – undo
1283 1283
 		/** @deprecated 19.0.0 */
1284 1284
 		$this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1285 1285
 
1286
-		$this->registerService(Defaults::class, function (Server $c) {
1286
+		$this->registerService(Defaults::class, function(Server $c) {
1287 1287
 			return new Defaults(
1288 1288
 				$c->getThemingDefaults()
1289 1289
 			);
@@ -1291,17 +1291,17 @@  discard block
 block discarded – undo
1291 1291
 		/** @deprecated 19.0.0 */
1292 1292
 		$this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class);
1293 1293
 
1294
-		$this->registerService(\OCP\ISession::class, function (ContainerInterface $c) {
1294
+		$this->registerService(\OCP\ISession::class, function(ContainerInterface $c) {
1295 1295
 			return $c->get(\OCP\IUserSession::class)->getSession();
1296 1296
 		}, false);
1297 1297
 
1298
-		$this->registerService(IShareHelper::class, function (ContainerInterface $c) {
1298
+		$this->registerService(IShareHelper::class, function(ContainerInterface $c) {
1299 1299
 			return new ShareHelper(
1300 1300
 				$c->get(\OCP\Share\IManager::class)
1301 1301
 			);
1302 1302
 		});
1303 1303
 
1304
-		$this->registerService(Installer::class, function (ContainerInterface $c) {
1304
+		$this->registerService(Installer::class, function(ContainerInterface $c) {
1305 1305
 			return new Installer(
1306 1306
 				$c->get(AppFetcher::class),
1307 1307
 				$c->get(IClientService::class),
@@ -1312,11 +1312,11 @@  discard block
 block discarded – undo
1312 1312
 			);
1313 1313
 		});
1314 1314
 
1315
-		$this->registerService(IApiFactory::class, function (ContainerInterface $c) {
1315
+		$this->registerService(IApiFactory::class, function(ContainerInterface $c) {
1316 1316
 			return new ApiFactory($c->get(IClientService::class));
1317 1317
 		});
1318 1318
 
1319
-		$this->registerService(IInstanceFactory::class, function (ContainerInterface $c) {
1319
+		$this->registerService(IInstanceFactory::class, function(ContainerInterface $c) {
1320 1320
 			$memcacheFactory = $c->get(ICacheFactory::class);
1321 1321
 			return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class));
1322 1322
 		});
@@ -1373,7 +1373,7 @@  discard block
 block discarded – undo
1373 1373
 		$dispatcher = $this->get(SymfonyAdapter::class);
1374 1374
 
1375 1375
 		// Delete avatar on user deletion
1376
-		$dispatcher->addListener('OCP\IUser::preDelete', function (GenericEvent $e) {
1376
+		$dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) {
1377 1377
 			$logger = $this->get(ILogger::class);
1378 1378
 			$manager = $this->getAvatarManager();
1379 1379
 			/** @var IUser $user */
@@ -1386,11 +1386,11 @@  discard block
 block discarded – undo
1386 1386
 				// no avatar to remove
1387 1387
 			} catch (\Exception $e) {
1388 1388
 				// Ignore exceptions
1389
-				$logger->info('Could not cleanup avatar of ' . $user->getUID());
1389
+				$logger->info('Could not cleanup avatar of '.$user->getUID());
1390 1390
 			}
1391 1391
 		});
1392 1392
 
1393
-		$dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
1393
+		$dispatcher->addListener('OCP\IUser::changeUser', function(GenericEvent $e) {
1394 1394
 			$manager = $this->getAvatarManager();
1395 1395
 			/** @var IUser $user */
1396 1396
 			$user = $e->getSubject();
@@ -2281,11 +2281,11 @@  discard block
 block discarded – undo
2281 2281
 	}
2282 2282
 
2283 2283
 	private function registerDeprecatedAlias(string $alias, string $target) {
2284
-		$this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) {
2284
+		$this->registerService($alias, function(ContainerInterface $container) use ($target, $alias) {
2285 2285
 			try {
2286 2286
 				/** @var ILogger $logger */
2287 2287
 				$logger = $container->get(ILogger::class);
2288
-				$logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']);
2288
+				$logger->debug('The requested alias "'.$alias.'" is deprecated. Please request "'.$target.'" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']);
2289 2289
 			} catch (ContainerExceptionInterface $e) {
2290 2290
 				// Could not get logger. Continue
2291 2291
 			}
Please login to merge, or discard this patch.