From 1d0962ab33ce9e6846479ce44381d8cdcb8ad122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Mon, 9 Dec 2024 10:27:56 +0100 Subject: [PATCH] feat(occ): Show first_seen in output of user:list --info MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also format unknown and never in a better way. Signed-off-by: Côme Chilliet --- core/Command/User/Info.php | 30 ++++++++++++------------------ core/Command/User/ListCommand.php | 13 ++++++++++++- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/core/Command/User/Info.php b/core/Command/User/Info.php index 8cd481d6b1d..6487b533fa2 100644 --- a/core/Command/User/Info.php +++ b/core/Command/User/Info.php @@ -47,22 +47,6 @@ class Info extends Base { return 1; } $groups = $this->groupManager->getUserGroupIds($user); - $firstLogin = $user->getFirstLogin(); - $lastLogin = $user->getLastLogin(); - if ($firstLogin < 0) { - $firstSeen = 'unknown'; - } elseif ($firstLogin === 0) { - $firstSeen = 'never'; - } else { - $firstSeen = date(\DateTimeInterface::ATOM, $firstLogin); // ISO-8601 - } - if ($lastLogin < 0) { - $lastSeen = 'unknown'; - } elseif ($lastLogin === 0) { - $lastSeen = 'never'; - } else { - $lastSeen = date(\DateTimeInterface::ATOM, $lastLogin); // ISO-8601 - } $data = [ 'user_id' => $user->getUID(), 'display_name' => $user->getDisplayName(), @@ -72,8 +56,8 @@ class Info extends Base { 'groups' => $groups, 'quota' => $user->getQuota(), 'storage' => $this->getStorageInfo($user), - 'first_seen' => $firstSeen, - 'last_seen' => $lastSeen, + 'first_seen' => $this->formatLoginDate($user->getFirstLogin()), + 'last_seen' => $this->formatLoginDate($user->getLastLogin()), 'user_directory' => $user->getHome(), 'backend' => $user->getBackendClassName() ]; @@ -81,6 +65,16 @@ class Info extends Base { return 0; } + private function formatLoginDate(int $timestamp): string { + if ($timestamp < 0) { + return 'unknown'; + } elseif ($timestamp === 0) { + return 'never'; + } else { + return date(\DateTimeInterface::ATOM, $timestamp); // ISO-8601 + } + } + /** * @param IUser $user * @return array diff --git a/core/Command/User/ListCommand.php b/core/Command/User/ListCommand.php index 7c4364fccbc..e7fb3de71f0 100644 --- a/core/Command/User/ListCommand.php +++ b/core/Command/User/ListCommand.php @@ -83,7 +83,8 @@ class ListCommand extends Base { 'enabled' => $user->isEnabled(), 'groups' => $groups, 'quota' => $user->getQuota(), - 'last_seen' => date(\DateTimeInterface::ATOM, $user->getLastLogin()), // ISO-8601 + 'first_seen' => $this->formatLoginDate($user->getFirstLogin()), + 'last_seen' => $this->formatLoginDate($user->getLastLogin()), 'user_directory' => $user->getHome(), 'backend' => $user->getBackendClassName() ]; @@ -93,4 +94,14 @@ class ListCommand extends Base { yield $user->getUID() => $value; } } + + private function formatLoginDate(int $timestamp): string { + if ($timestamp < 0) { + return 'unknown'; + } elseif ($timestamp === 0) { + return 'never'; + } else { + return date(\DateTimeInterface::ATOM, $timestamp); // ISO-8601 + } + } }