Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions lib/User/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,19 @@ public function countUsers(): int {
}

public function deleteUser($uid): bool {
if (!is_string($uid) || $uid === '') {
return false;
}

try {
$user = $this->userMapper->getUser($uid);
$this->userMapper->delete($user);
return true;
} catch (DoesNotExistException $e) {
$this->logger->info('Tried to delete non-existent user', ['uid' => $uid, 'exception' => $e]);
return false;
} catch (Exception $e) {
$this->logger->error('Failed to delete user', [ 'exception' => $e ]);
$this->logger->error('Failed to delete user', ['uid' => $uid, 'exception' => $e]);
return false;
}
}
Expand All @@ -103,29 +110,23 @@ public function getUsers($search = '', $limit = null, $offset = null): array {
) {
return [];
}
return array_map(function ($user) {
return $user->getUserId();
}, $this->userMapper->find($search, $limit, $offset));
return array_map(static fn ($user) => $user->getUserId(), $this->userMapper->find($search, $limit, $offset));
}

public function userExists($uid): bool {
if (!is_string($uid)) {
return false;
}
return $this->userMapper->userExists($uid);
return is_string($uid) && $uid !== '' && $this->userMapper->userExists($uid);
}

public function getDisplayName($uid): string {
if (!is_string($uid)) {
if (!is_string($uid) || $uid === '') {
return (string)$uid;
}
try {
$user = $this->userMapper->getUser($uid);
} catch (DoesNotExistException $e) {
return $user->getDisplayName();
} catch (DoesNotExistException) {
return $uid;
}

return $user->getDisplayName();
}

public function getDisplayNames($search = '', $limit = null, $offset = null): array {
Expand All @@ -135,6 +136,7 @@ public function getDisplayNames($search = '', $limit = null, $offset = null): ar
) {
return [];
}

return $this->userMapper->findDisplayNames($search, $limit, $offset);
}

Expand Down
Loading