Completed
Push — master ( c316ed...9d6353 )
by Blizzz
30:19
created
apps/user_ldap/lib/Mapping/AbstractMapping.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 		}
79 79
 
80 80
 		$section = \str_contains($this->getTableName(), 'user') ? 'u/' : 'g/';
81
-		$this->localNameToDnCache = $this->cacheFactory->createLocal('ldap/map/' . $section);
81
+		$this->localNameToDnCache = $this->cacheFactory->createLocal('ldap/map/'.$section);
82 82
 
83 83
 		// We use the cache as well to store whether it shall be used. If the
84 84
 		// answer was no, we unset it again.
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 		$row = $result->fetch();
102 102
 		$result->closeCursor();
103 103
 
104
-		$use = (int)$row['count'] <= self::LOCAL_CACHE_OBJECT_THRESHOLD;
104
+		$use = (int) $row['count'] <= self::LOCAL_CACHE_OBJECT_THRESHOLD;
105 105
 		$this->localNameToDnCache->set('use', $use, self::LOCAL_USER_COUNT_TTL);
106 106
 		return $use;
107 107
 	}
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 	/**
176 176
 	 * Gets the LDAP DN based on the provided name.
177 177
 	 */
178
-	public function getDNByName(string $name): string|false {
178
+	public function getDNByName(string $name): string | false {
179 179
 		$dn = array_search($name, $this->cache, true);
180 180
 		if ($dn === false) {
181 181
 			$dn = $this->localNameToDnCache?->get($name);
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 	public function setDNbyUUID($fdn, $uuid) {
201 201
 		$oldDn = $this->getDnByUUID($uuid);
202 202
 		$statement = $this->dbc->prepare('
203
-			UPDATE `' . $this->getTableName() . '`
203
+			UPDATE `' . $this->getTableName().'`
204 204
 			SET `ldap_dn_hash` = ?, `ldap_dn` = ?
205 205
 			WHERE `directory_uuid` = ?
206 206
 		');
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 	 */
233 233
 	public function setUUIDbyDN($uuid, $fdn): bool {
234 234
 		$statement = $this->dbc->prepare('
235
-			UPDATE `' . $this->getTableName() . '`
235
+			UPDATE `' . $this->getTableName().'`
236 236
 			SET `directory_uuid` = ?
237 237
 			WHERE `ldap_dn_hash` = ?
238 238
 		');
@@ -335,12 +335,12 @@  discard block
 block discarded – undo
335 335
 	public function getNamesBySearch(string $search, string $prefixMatch = '', string $postfixMatch = ''): array {
336 336
 		$statement = $this->dbc->prepare('
337 337
 			SELECT `owncloud_name`
338
-			FROM `' . $this->getTableName() . '`
338
+			FROM `' . $this->getTableName().'`
339 339
 			WHERE `owncloud_name` LIKE ?
340 340
 		');
341 341
 
342 342
 		try {
343
-			$res = $statement->execute([$prefixMatch . $this->dbc->escapeLikeParameter($search) . $postfixMatch]);
343
+			$res = $statement->execute([$prefixMatch.$this->dbc->escapeLikeParameter($search).$postfixMatch]);
344 344
 		} catch (Exception $e) {
345 345
 			return [];
346 346
 		}
@@ -425,12 +425,12 @@  discard block
 block discarded – undo
425 425
 
426 426
 		try {
427 427
 			$result = $this->dbc->insertIfNotExist($this->getTableName(), $row);
428
-			if ((bool)$result === true) {
428
+			if ((bool) $result === true) {
429 429
 				$this->cache[$fdn] = $name;
430 430
 				$this->localNameToDnCache?->set($name, $fdn, self::LOCAL_CACHE_TTL);
431 431
 			}
432 432
 			// insertIfNotExist returns values as int
433
-			return (bool)$result;
433
+			return (bool) $result;
434 434
 		} catch (\Exception $e) {
435 435
 			return false;
436 436
 		}
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
 	 */
445 445
 	public function unmap($name) {
446 446
 		$statement = $this->dbc->prepare('
447
-			DELETE FROM `' . $this->getTableName() . '`
447
+			DELETE FROM `' . $this->getTableName().'`
448 448
 			WHERE `owncloud_name` = ?');
449 449
 
450 450
 		$dn = array_search($name, $this->cache);
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
 	public function clear() {
465 465
 		$sql = $this->dbc
466 466
 			->getDatabasePlatform()
467
-			->getTruncateTableSQL('`' . $this->getTableName() . '`');
467
+			->getTruncateTableSQL('`'.$this->getTableName().'`');
468 468
 		try {
469 469
 			$this->dbc->executeQuery($sql);
470 470
 			$this->localNameToDnCache?->clear();
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
 		$res = $query->executeQuery();
514 514
 		$count = $res->fetchOne();
515 515
 		$res->closeCursor();
516
-		return (int)$count;
516
+		return (int) $count;
517 517
 	}
518 518
 
519 519
 	public function countInvalidated(): int {
@@ -524,6 +524,6 @@  discard block
 block discarded – undo
524 524
 		$res = $query->executeQuery();
525 525
 		$count = $res->fetchOne();
526 526
 		$res->closeCursor();
527
-		return (int)$count;
527
+		return (int) $count;
528 528
 	}
529 529
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/User_LDAP.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 	 * @throws \Exception
69 69
 	 */
70 70
 	public function loginName2UserName($loginName, bool $forceLdapRefetch = false) {
71
-		$cacheKey = 'loginName2UserName-' . $loginName;
71
+		$cacheKey = 'loginName2UserName-'.$loginName;
72 72
 		$username = $this->access->connection->getFromCache($cacheKey);
73 73
 		$knownDn = $username ? $this->access->username2dn($username) : false;
74 74
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 		$users = $this->access->fetchUsersByLoginName($loginName, $attrs);
122 122
 		if (count($users) < 1) {
123 123
 			throw new NotOnLDAP('No user available for the given login name on '
124
-				. $this->access->connection->ldapHost . ':' . $this->access->connection->ldapPort);
124
+				. $this->access->connection->ldapHost.':'.$this->access->connection->ldapPort);
125 125
 		}
126 126
 		return $users[0];
127 127
 	}
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 
154 154
 		if (!$user instanceof User) {
155 155
 			$this->logger->warning(
156
-				'LDAP Login: Could not get user object for DN ' . $dn
156
+				'LDAP Login: Could not get user object for DN '.$dn
157 157
 				. '. Maybe the LDAP entry has no set display name attribute?',
158 158
 				['app' => 'user_ldap']
159 159
 			);
@@ -188,13 +188,13 @@  discard block
 block discarded – undo
188 188
 		$user = $this->access->userManager->get($uid);
189 189
 
190 190
 		if (!$user instanceof User) {
191
-			throw new \Exception('LDAP setPassword: Could not get user object for uid ' . $uid
191
+			throw new \Exception('LDAP setPassword: Could not get user object for uid '.$uid
192 192
 				. '. Maybe the LDAP entry has no set display name attribute?');
193 193
 		}
194 194
 		if ($user->getUsername() !== false && $this->access->setPassword($user->getDN(), $password)) {
195 195
 			$ldapDefaultPPolicyDN = $this->access->connection->ldapDefaultPPolicyDN;
196 196
 			$turnOnPasswordChange = $this->access->connection->turnOnPasswordChange;
197
-			if (!empty($ldapDefaultPPolicyDN) && ((int)$turnOnPasswordChange === 1)) {
197
+			if (!empty($ldapDefaultPPolicyDN) && ((int) $turnOnPasswordChange === 1)) {
198 198
 				//remove last password expiry warning if any
199 199
 				$notification = $this->notificationManager->createNotification();
200 200
 				$notification->setApp('user_ldap')
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 	 */
220 220
 	public function getUsers($search = '', $limit = 10, $offset = 0) {
221 221
 		$search = $this->access->escapeFilterPart($search, true);
222
-		$cachekey = 'getUsers-' . $search . '-' . $limit . '-' . $offset;
222
+		$cachekey = 'getUsers-'.$search.'-'.$limit.'-'.$offset;
223 223
 
224 224
 		//check if users are cached, if so return
225 225
 		$ldap_users = $this->access->connection->getFromCache($cachekey);
@@ -234,12 +234,12 @@  discard block
 block discarded – undo
234 234
 		}
235 235
 		$filter = $this->access->combineFilterWithAnd([
236 236
 			$this->access->connection->ldapUserFilter,
237
-			$this->access->connection->ldapUserDisplayName . '=*',
237
+			$this->access->connection->ldapUserDisplayName.'=*',
238 238
 			$this->access->getFilterPartForUserSearch($search)
239 239
 		]);
240 240
 
241 241
 		$this->logger->debug(
242
-			'getUsers: Options: search ' . $search . ' limit ' . $limit . ' offset ' . $offset . ' Filter: ' . $filter,
242
+			'getUsers: Options: search '.$search.' limit '.$limit.' offset '.$offset.' Filter: '.$filter,
243 243
 			['app' => 'user_ldap']
244 244
 		);
245 245
 		//do the search and translate results to Nextcloud names
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 			$limit, $offset);
250 250
 		$ldap_users = $this->access->nextcloudUserNames($ldap_users);
251 251
 		$this->logger->debug(
252
-			'getUsers: ' . count($ldap_users) . ' Users found',
252
+			'getUsers: '.count($ldap_users).' Users found',
253 253
 			['app' => 'user_ldap']
254 254
 		);
255 255
 
@@ -273,11 +273,11 @@  discard block
 block discarded – undo
273 273
 			return false;
274 274
 		}
275 275
 		$uid = $user instanceof User ? $user->getUsername() : $user->getOCName();
276
-		$cacheKey = 'userExistsOnLDAP' . $uid;
276
+		$cacheKey = 'userExistsOnLDAP'.$uid;
277 277
 		if (!$ignoreCache) {
278 278
 			$userExists = $this->access->connection->getFromCache($cacheKey);
279 279
 			if (!is_null($userExists)) {
280
-				return (bool)$userExists;
280
+				return (bool) $userExists;
281 281
 			}
282 282
 		}
283 283
 
@@ -320,22 +320,22 @@  discard block
 block discarded – undo
320 320
 	 * @throws \Exception when connection could not be established
321 321
 	 */
322 322
 	public function userExists($uid) {
323
-		$userExists = $this->access->connection->getFromCache('userExists' . $uid);
323
+		$userExists = $this->access->connection->getFromCache('userExists'.$uid);
324 324
 		if (!is_null($userExists)) {
325
-			return (bool)$userExists;
325
+			return (bool) $userExists;
326 326
 		}
327 327
 		$userExists = $this->access->userManager->exists($uid);
328 328
 
329 329
 		if (!$userExists) {
330 330
 			$this->logger->debug(
331
-				'No DN found for ' . $uid . ' on ' . $this->access->connection->ldapHost,
331
+				'No DN found for '.$uid.' on '.$this->access->connection->ldapHost,
332 332
 				['app' => 'user_ldap']
333 333
 			);
334
-			$this->access->connection->writeToCache('userExists' . $uid, false);
334
+			$this->access->connection->writeToCache('userExists'.$uid, false);
335 335
 			return false;
336 336
 		}
337 337
 
338
-		$this->access->connection->writeToCache('userExists' . $uid, true);
338
+		$this->access->connection->writeToCache('userExists'.$uid, true);
339 339
 		return true;
340 340
 	}
341 341
 
@@ -369,13 +369,13 @@  discard block
 block discarded – undo
369 369
 			}
370 370
 			if (!$marked) {
371 371
 				$this->logger->notice(
372
-					'User ' . $uid . ' is not marked as deleted, not cleaning up.',
372
+					'User '.$uid.' is not marked as deleted, not cleaning up.',
373 373
 					['app' => 'user_ldap']
374 374
 				);
375 375
 				return false;
376 376
 			}
377 377
 		}
378
-		$this->logger->info('Cleaning up after user ' . $uid,
378
+		$this->logger->info('Cleaning up after user '.$uid,
379 379
 			['app' => 'user_ldap']);
380 380
 
381 381
 		$this->access->getUserMapper()->unmap($uid); // we don't emit unassign signals here, since it is implicit to delete signals fired from core
@@ -402,7 +402,7 @@  discard block
 block discarded – undo
402 402
 			return $this->userPluginManager->getHome($uid);
403 403
 		}
404 404
 
405
-		$cacheKey = 'getHome' . $uid;
405
+		$cacheKey = 'getHome'.$uid;
406 406
 		$path = $this->access->connection->getFromCache($cacheKey);
407 407
 		if (!is_null($path)) {
408 408
 			return $path;
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
 		if ($user instanceof User || $user instanceof OfflineUser) {
414 414
 			$path = $user->getHomePath() ?: false;
415 415
 		} else {
416
-			throw new NoUserException($uid . ' is not a valid user anymore');
416
+			throw new NoUserException($uid.' is not a valid user anymore');
417 417
 		}
418 418
 
419 419
 		$this->access->cacheUserHome($uid, $path);
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
 			return false;
435 435
 		}
436 436
 
437
-		$cacheKey = 'getDisplayName' . $uid;
437
+		$cacheKey = 'getDisplayName'.$uid;
438 438
 		if (!is_null($displayName = $this->access->connection->getFromCache($cacheKey))) {
439 439
 			return $displayName;
440 440
 		}
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
 
462 462
 			$user = $this->access->userManager->get($uid);
463 463
 			if ($user instanceof User) {
464
-				$displayName = $user->composeAndStoreDisplayName($displayName, (string)$displayName2);
464
+				$displayName = $user->composeAndStoreDisplayName($displayName, (string) $displayName2);
465 465
 				$this->access->connection->writeToCache($cacheKey, $displayName);
466 466
 			}
467 467
 			if ($user instanceof OfflineUser) {
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
 	 * @return array an array of all displayNames (value) and the corresponding uids (key)
498 498
 	 */
499 499
 	public function getDisplayNames($search = '', $limit = null, $offset = null) {
500
-		$cacheKey = 'getDisplayNames-' . $search . '-' . $limit . '-' . $offset;
500
+		$cacheKey = 'getDisplayNames-'.$search.'-'.$limit.'-'.$offset;
501 501
 		if (!is_null($displayNames = $this->access->connection->getFromCache($cacheKey))) {
502 502
 			return $displayNames;
503 503
 		}
@@ -520,12 +520,12 @@  discard block
 block discarded – undo
520 520
 	 * compared with \OC\User\Backend::CREATE_USER etc.
521 521
 	 */
522 522
 	public function implementsActions($actions) {
523
-		return (bool)((Backend::CHECK_PASSWORD
523
+		return (bool) ((Backend::CHECK_PASSWORD
524 524
 			| Backend::GET_HOME
525 525
 			| Backend::GET_DISPLAYNAME
526 526
 			| (($this->access->connection->ldapUserAvatarRule !== 'none') ? Backend::PROVIDE_AVATAR : 0)
527 527
 			| Backend::COUNT_USERS
528
-			| (((int)$this->access->connection->turnOnPasswordChange === 1)? Backend::SET_PASSWORD :0)
528
+			| (((int) $this->access->connection->turnOnPasswordChange === 1) ? Backend::SET_PASSWORD : 0)
529 529
 			| $this->userPluginManager->getImplementedActions())
530 530
 			& $actions);
531 531
 	}
@@ -540,13 +540,13 @@  discard block
 block discarded – undo
540 540
 	/**
541 541
 	 * counts the users in LDAP
542 542
 	 */
543
-	public function countUsers(int $limit = 0): int|false {
543
+	public function countUsers(int $limit = 0): int | false {
544 544
 		if ($this->userPluginManager->implementsActions(Backend::COUNT_USERS)) {
545 545
 			return $this->userPluginManager->countUsers();
546 546
 		}
547 547
 
548 548
 		$filter = $this->access->getFilterForUserCount();
549
-		$cacheKey = 'countUsers-' . $filter . '-' . $limit;
549
+		$cacheKey = 'countUsers-'.$filter.'-'.$limit;
550 550
 		if (!is_null($entries = $this->access->connection->getFromCache($cacheKey))) {
551 551
 			return $entries;
552 552
 		}
@@ -622,13 +622,13 @@  discard block
 block discarded – undo
622 622
 					throw new \UnexpectedValueException('LDAP Plugin: Method createUser changed to return the user DN instead of boolean.');
623 623
 				}
624 624
 			}
625
-			return (bool)$dn;
625
+			return (bool) $dn;
626 626
 		}
627 627
 		return false;
628 628
 	}
629 629
 
630 630
 	public function isUserEnabled(string $uid, callable $queryDatabaseValue): bool {
631
-		if ($this->deletedUsersIndex->isUserMarked($uid) && ((int)$this->access->connection->markRemnantsAsDisabled === 1)) {
631
+		if ($this->deletedUsersIndex->isUserMarked($uid) && ((int) $this->access->connection->markRemnantsAsDisabled === 1)) {
632 632
 			return false;
633 633
 		} else {
634 634
 			return $queryDatabaseValue();
Please login to merge, or discard this patch.