You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

showremnants.php 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 OCA\user_ldap\Command;
  23. use Symfony\Component\Console\Command\Command;
  24. use Symfony\Component\Console\Input\InputInterface;
  25. use Symfony\Component\Console\Output\OutputInterface;
  26. use OCA\user_ldap\lib\user\DeletedUsersIndex;
  27. use OCP\IDateTimeFormatter;
  28. class ShowRemnants extends Command {
  29. /** @var \OCA\User_LDAP\lib\User\DeletedUsersIndex */
  30. protected $dui;
  31. /** @var \OCP\IDateTimeFormatter */
  32. protected $dateFormatter;
  33. /**
  34. * @param OCA\user_ldap\lib\user\DeletedUsersIndex $dui
  35. * @param OCP\IDateTimeFormatter $dateFormatter
  36. */
  37. public function __construct(DeletedUsersIndex $dui, IDateTimeFormatter $dateFormatter) {
  38. $this->dui = $dui;
  39. $this->dateFormatter = $dateFormatter;
  40. parent::__construct();
  41. }
  42. protected function configure() {
  43. $this
  44. ->setName('ldap:show-remnants')
  45. ->setDescription('shows which users are not available on LDAP anymore, but have remnants in ownCloud.')
  46. ;
  47. }
  48. /**
  49. * executes the command, i.e. creeates and outputs a table of LDAP users marked as deleted
  50. *
  51. * {@inheritdoc}
  52. */
  53. protected function execute(InputInterface $input, OutputInterface $output) {
  54. /** @var \Symfony\Component\Console\Helper\Table $table */
  55. $table = $this->getHelperSet()->get('table');
  56. $table->setHeaders(array(
  57. 'ownCloud name', 'Display Name', 'LDAP UID', 'LDAP DN', 'Last Login',
  58. 'Dir', 'Sharer'));
  59. $rows = array();
  60. $resultSet = $this->dui->getUsers();
  61. foreach($resultSet as $user) {
  62. $hAS = $user->getHasActiveShares() ? 'Y' : 'N';
  63. $lastLogin = ($user->getLastLogin() > 0) ?
  64. $this->dateFormatter->formatDate($user->getLastLogin()) : '-';
  65. $rows[] = array(
  66. $user->getOCName(),
  67. $user->getDisplayName(),
  68. $user->getUid(),
  69. $user->getDN(),
  70. $lastLogin,
  71. $user->getHomePath(),
  72. $hAS
  73. );
  74. }
  75. $table->setRows($rows);
  76. $table->render($output);
  77. }
  78. }