diff --git a/core/Command/User/Info.php b/core/Command/User/Info.php index de2fd99652c76..8cd481d6b1d5b 100644 --- a/core/Command/User/Info.php +++ b/core/Command/User/Info.php @@ -47,6 +47,22 @@ protected function execute(InputInterface $input, OutputInterface $output): int 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(), @@ -56,8 +72,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int 'groups' => $groups, 'quota' => $user->getQuota(), 'storage' => $this->getStorageInfo($user), - 'first_seen' => date(\DateTimeInterface::ATOM, $user->getFirstLogin()), // ISO-8601 - 'last_seen' => date(\DateTimeInterface::ATOM, $user->getLastLogin()), // ISO-8601 + 'first_seen' => $firstSeen, + 'last_seen' => $lastSeen, 'user_directory' => $user->getHome(), 'backend' => $user->getBackendClassName() ]; diff --git a/lib/private/User/User.php b/lib/private/User/User.php index 311f057be545b..3d5c13d44318d 100644 --- a/lib/private/User/User.php +++ b/lib/private/User/User.php @@ -228,15 +228,20 @@ public function updateLastLoginTimestamp(): bool { $previousLogin = $this->getLastLogin(); $firstLogin = $this->getFirstLogin(); $now = time(); - $firstTimeLogin = $firstLogin === 0; + $firstTimeLogin = $previousLogin === 0; if ($now - $previousLogin > 60) { $this->lastLogin = $now; $this->config->setUserValue($this->uid, 'login', 'lastLogin', (string)$this->lastLogin); } - if ($firstTimeLogin) { - $this->firstLogin = $now; + if ($firstLogin === 0) { + if ($firstTimeLogin) { + $this->firstLogin = $now; + } else { + /* Unknown first login, most likely was before upgrade to Nextcloud 31 */ + $this->firstLogin = -1; + } $this->config->setUserValue($this->uid, 'login', 'firstLogin', (string)$this->firstLogin); } diff --git a/lib/public/IUser.php b/lib/public/IUser.php index f87fd8398e67e..b4808ec045a4d 100644 --- a/lib/public/IUser.php +++ b/lib/public/IUser.php @@ -53,7 +53,7 @@ public function setDisplayName($displayName); public function getLastLogin(): int; /** - * Returns the timestamp of the user's first login or 0 if the user did never login + * Returns the timestamp of the user's first login, 0 if the user did never login, or -1 if the data is unknown (first login was on an older version) * * @since 31.0.0 */