Info.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Robin Appelman <robin@icewind.nl>
  4. *
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Robin Appelman <robin@icewind.nl>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OC\Core\Command\User;
  25. use OC\Core\Command\Base;
  26. use OCP\IGroupManager;
  27. use OCP\IUserManager;
  28. use Symfony\Component\Console\Input\InputArgument;
  29. use Symfony\Component\Console\Input\InputInterface;
  30. use Symfony\Component\Console\Input\InputOption;
  31. use Symfony\Component\Console\Output\OutputInterface;
  32. class Info extends Base {
  33. /** @var IUserManager */
  34. protected $userManager;
  35. /** @var IGroupManager */
  36. protected $groupManager;
  37. /**
  38. * @param IUserManager $userManager
  39. * @param IGroupManager $groupManager
  40. */
  41. public function __construct(IUserManager $userManager, IGroupManager $groupManager) {
  42. $this->userManager = $userManager;
  43. $this->groupManager = $groupManager;
  44. parent::__construct();
  45. }
  46. protected function configure() {
  47. $this
  48. ->setName('user:info')
  49. ->setDescription('show user info')
  50. ->addArgument(
  51. 'user',
  52. InputArgument::REQUIRED,
  53. 'user to show'
  54. )->addOption(
  55. 'output',
  56. null,
  57. InputOption::VALUE_OPTIONAL,
  58. 'Output format (plain, json or json_pretty, default is plain)',
  59. $this->defaultOutputFormat
  60. );
  61. }
  62. protected function execute(InputInterface $input, OutputInterface $output) {
  63. $user = $this->userManager->get($input->getArgument('user'));
  64. if (is_null($user)) {
  65. $output->writeln('<error>user not found</error>');
  66. return 1;
  67. }
  68. $groups = $this->groupManager->getUserGroupIds($user);
  69. $data = [
  70. 'user_id' => $user->getUID(),
  71. 'display_name' => $user->getDisplayName(),
  72. 'email' => $user->getEMailAddress() ? $user->getEMailAddress() : '',
  73. 'cloud_id' => $user->getCloudId(),
  74. 'enabled' => $user->isEnabled(),
  75. 'groups' => $groups,
  76. 'quota' => $user->getQuota(),
  77. 'last_seen' => date(\DateTime::ATOM, $user->getLastLogin()), // ISO-8601
  78. 'user_directory' => $user->getHome(),
  79. 'backend' => $user->getBackendClassName()
  80. ];
  81. $this->writeArrayInOutputFormat($input, $output, $data);
  82. }
  83. }