Info.php 2.7 KB

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