diff options
author | Joas Schilling <coding@schilljs.com> | 2024-03-13 10:24:22 +0100 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2024-03-14 08:40:22 +0100 |
commit | 813406322bd6b972a78ab388d5d685f60ea5009a (patch) | |
tree | 5c090310044cf862063f35e49a93d7cafb3121e2 /core/Command/User | |
parent | d1e3c0278d1ef4d59c835ad727a42f3c0369b3c8 (diff) | |
download | nextcloud-server-813406322bd6b972a78ab388d5d685f60ea5009a.tar.gz nextcloud-server-813406322bd6b972a78ab388d5d685f60ea5009a.zip |
fix: Use IUserManager::callForAllUsers() to save memory
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'core/Command/User')
-rw-r--r-- | core/Command/User/LastSeen.php | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/core/Command/User/LastSeen.php b/core/Command/User/LastSeen.php index 8a47ad8837a..d78d8661ecf 100644 --- a/core/Command/User/LastSeen.php +++ b/core/Command/User/LastSeen.php @@ -59,7 +59,7 @@ class LastSeen extends Base { ; } - protected function execute(InputInterface $input, OutputInterface $output): int { + protected function execute(InputInterface $input, OutputInterface $output): int { $singleUserId = $input->getArgument('uid'); if ($singleUserId) { $user = $this->userManager->get($singleUserId); @@ -67,13 +67,34 @@ class LastSeen extends Base { $output->writeln('<error>User does not exist</error>'); return 1; } - $users = [$user]; - } elseif ($input->getOption('all')) { - $users = $this->userManager->search(''); - } else { + + $lastLogin = $user->getLastLogin(); + if ($lastLogin === 0) { + $output->writeln($user->getUID() . ' has never logged in.'); + } else { + $date = new \DateTime(); + $date->setTimestamp($lastLogin); + $output->writeln($user->getUID() . "'s last login: " . $date->format('Y-m-d H:i')); + } + + return 0; + } + + if (!$input->getOption('all')) { $output->writeln("<error>Please specify a username, or \"--all\" to list all</error>"); return 1; } + + $this->userManager->callForAllUsers(static function (IUser $user) use ($output) { + $lastLogin = $user->getLastLogin(); + if ($lastLogin === 0) { + $output->writeln($user->getUID() . ' has never logged in.'); + } else { + $date = new \DateTime(); + $date->setTimestamp($lastLogin); + $output->writeln($user->getUID() . "'s last login: " . $date->format('Y-m-d H:i')); + } + }); return 0; } |