ShowRemnants.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author scolebrook <scolebrook@mac.com>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCA\User_LDAP\Command;
  26. use Symfony\Component\Console\Command\Command;
  27. use Symfony\Component\Console\Input\InputInterface;
  28. use Symfony\Component\Console\Input\InputOption;
  29. use Symfony\Component\Console\Output\OutputInterface;
  30. use OCA\User_LDAP\User\DeletedUsersIndex;
  31. use OCP\IDateTimeFormatter;
  32. class ShowRemnants extends Command {
  33. /** @var \OCA\User_LDAP\User\DeletedUsersIndex */
  34. protected $dui;
  35. /** @var \OCP\IDateTimeFormatter */
  36. protected $dateFormatter;
  37. /**
  38. * @param DeletedUsersIndex $dui
  39. * @param IDateTimeFormatter $dateFormatter
  40. */
  41. public function __construct(DeletedUsersIndex $dui, IDateTimeFormatter $dateFormatter) {
  42. $this->dui = $dui;
  43. $this->dateFormatter = $dateFormatter;
  44. parent::__construct();
  45. }
  46. protected function configure() {
  47. $this
  48. ->setName('ldap:show-remnants')
  49. ->setDescription('shows which users are not available on LDAP anymore, but have remnants in ownCloud.')
  50. ->addOption('json', null, InputOption::VALUE_NONE, 'return JSON array instead of pretty table.');
  51. }
  52. /**
  53. * executes the command, i.e. creeates and outputs a table of LDAP users marked as deleted
  54. *
  55. * {@inheritdoc}
  56. */
  57. protected function execute(InputInterface $input, OutputInterface $output) {
  58. /** @var \Symfony\Component\Console\Helper\Table $table */
  59. $table = $this->getHelperSet()->get('table');
  60. $table->setHeaders(array(
  61. 'ownCloud name', 'Display Name', 'LDAP UID', 'LDAP DN', 'Last Login',
  62. 'Dir', 'Sharer'));
  63. $rows = array();
  64. $resultSet = $this->dui->getUsers();
  65. foreach($resultSet as $user) {
  66. $hAS = $user->getHasActiveShares() ? 'Y' : 'N';
  67. $lastLogin = ($user->getLastLogin() > 0) ?
  68. $this->dateFormatter->formatDate($user->getLastLogin()) : '-';
  69. $rows[] = array('ocName' => $user->getOCName(),
  70. 'displayName' => $user->getDisplayName(),
  71. 'uid' => $user->getUID(),
  72. 'dn' => $user->getDN(),
  73. 'lastLogin' => $lastLogin,
  74. 'homePath' => $user->getHomePath(),
  75. 'sharer' => $hAS
  76. );
  77. }
  78. if ($input->getOption('json')) {
  79. $output->writeln(json_encode($rows));
  80. } else {
  81. $table->setRows($rows);
  82. $table->render($output);
  83. }
  84. }
  85. }