feat(users): Use -1 for unknown firstLogin instead of setting it to current date

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
pull/49377/head
Côme Chilliet 11 months ago
parent df8397e2ca
commit b995912207
No known key found for this signature in database
GPG Key ID: A3E2F658B28C760A
  1. 20
      core/Command/User/Info.php
  2. 11
      lib/private/User/User.php
  3. 2
      lib/public/IUser.php

@ -47,6 +47,22 @@ 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(),
@ -56,8 +72,8 @@ class Info extends Base {
'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()
];

@ -228,15 +228,20 @@ class User implements IUser {
$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);
}

@ -53,7 +53,7 @@ interface IUser {
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
*/

Loading…
Cancel
Save