Skip to content

Commit

Permalink
composer: Run fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
nooblag committed Sep 6, 2023
1 parent 62709c0 commit 26331cb
Showing 1 changed file with 60 additions and 64 deletions.
124 changes: 60 additions & 64 deletions core/Command/User/LastSeen.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,72 +36,68 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class LastSeen extends Base
{
public function __construct(
protected IUserManager $userManager,
) {
parent::__construct();
}
class LastSeen extends Base {
public function __construct(
protected IUserManager $userManager,
) {
parent::__construct();
}

protected function configure(): void
{
$this
->setName('user:lastseen')
->setDescription('shows when the user was logged in last time')
->addArgument(
'uid',
InputArgument::OPTIONAL,
'the username'
)
->addOption(
'all',
null,
InputOption::VALUE_NONE,
'shows a list of when all users were last logged in'
)
;
}
protected function configure(): void {
$this
->setName('user:lastseen')
->setDescription('shows when the user was logged in last time')
->addArgument(
'uid',
InputArgument::OPTIONAL,
'the username'
)
->addOption(
'all',
null,
InputOption::VALUE_NONE,
'shows a list of when all users were last logged in'
)
;
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$singleUserId = $input->getArgument('uid');
if ($singleUserId !== null) {
if (is_null($this->userManager->get($singleUserId))) {
$output->writeln('<error>User does not exist</error>');
return 1;
}
$users = $this->userManager->search($singleUserId);
} elseif ($input->getOption('all')) {
$users = $this->userManager->search('');
} else {
$output->writeln("<error>Please specify a username, or \"--all\" to list all</error>");
return 1;
}
protected function execute(InputInterface $input, OutputInterface $output): int {
$singleUserId = $input->getArgument('uid');
if ($singleUserId !== null) {
if (is_null($this->userManager->get($singleUserId))) {
$output->writeln('<error>User does not exist</error>');
return 1;
}
$users = $this->userManager->search($singleUserId);
} elseif ($input->getOption('all')) {
$users = $this->userManager->search('');
} else {
$output->writeln("<error>Please specify a username, or \"--all\" to list all</error>");
return 1;
}

foreach($users as $user) {
$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;
}
foreach($users as $user) {
$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;
}

/**
* @param string $argumentName
* @param CompletionContext $context
* @return string[]
*/
public function completeArgumentValues($argumentName, CompletionContext $context)
{
if ($argumentName === 'uid') {
return array_map(static fn (IUser $user) => $user->getUID(), $this->userManager->search($context->getCurrentWord()));
}
return [];
}
/**
* @param string $argumentName
* @param CompletionContext $context
* @return string[]
*/
public function completeArgumentValues($argumentName, CompletionContext $context) {
if ($argumentName === 'uid') {
return array_map(static fn (IUser $user) => $user->getUID(), $this->userManager->search($context->getCurrentWord()));
}
return [];
}
}

0 comments on commit 26331cb

Please sign in to comment.