Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: Use IUserManager::callForAllUsers() to save memory
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Mar 14, 2024
commit 813406322bd6b972a78ab388d5d685f60ea5009a
31 changes: 26 additions & 5 deletions core/Command/User/LastSeen.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,42 @@ protected function configure(): void {
;
}

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);
if (is_null($user)) {
$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