mirror of
https://github.com/nextcloud/server.git
synced 2026-06-12 10:10:49 -04:00
feat(users): Use -1 for unknown firstLogin instead of setting it to current date
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
parent
7e44535206
commit
fd366a6d8f
3 changed files with 27 additions and 6 deletions
|
|
@ -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…
Reference in a new issue