Skip to content

Commit

Permalink
fix: Use IUserManager::callForAllUsers() to save memory
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Mar 13, 2024
1 parent d1e3c02 commit f2d4d9b
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions core/Command/User/LastSeen.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,34 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$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;
}

Expand Down

0 comments on commit f2d4d9b

Please sign in to comment.