lastseen.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * @author Arthur Schiwon <blizzz@owncloud.com>
  4. * @author Morris Jobke <hey@morrisjobke.de>
  5. *
  6. * @copyright Copyright (c) 2015, ownCloud, Inc.
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OC\Core\Command\User;
  23. use Symfony\Component\Console\Command\Command;
  24. use Symfony\Component\Console\Input\InputInterface;
  25. use Symfony\Component\Console\Output\OutputInterface;
  26. use Symfony\Component\Console\Input\InputArgument;
  27. class LastSeen extends Command {
  28. protected function configure() {
  29. $this
  30. ->setName('user:lastseen')
  31. ->setDescription('shows when the user was logged it last time')
  32. ->addArgument(
  33. 'uid',
  34. InputArgument::REQUIRED,
  35. 'the username'
  36. );
  37. }
  38. protected function execute(InputInterface $input, OutputInterface $output) {
  39. $userManager = \OC::$server->getUserManager();
  40. $user = $userManager->get($input->getArgument('uid'));
  41. if(is_null($user)) {
  42. $output->writeln('User does not exist');
  43. return;
  44. }
  45. $lastLogin = $user->getLastLogin();
  46. if($lastLogin === 0) {
  47. $output->writeln('User ' . $user->getUID() .
  48. ' has never logged in, yet.');
  49. } else {
  50. $date = new \DateTime();
  51. $date->setTimestamp($lastLogin);
  52. $output->writeln($user->getUID() .
  53. '`s last login: ' . $date->format('d.m.Y H:i'));
  54. }
  55. }
  56. }