Report.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. * @author Thomas Müller <thomas.mueller@tmit.eu>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. namespace OC\Core\Command\User;
  28. use OCP\IUserManager;
  29. use Symfony\Component\Console\Command\Command;
  30. use Symfony\Component\Console\Helper\Table;
  31. use Symfony\Component\Console\Input\InputInterface;
  32. use Symfony\Component\Console\Output\OutputInterface;
  33. class Report extends Command {
  34. /** @var IUserManager */
  35. protected $userManager;
  36. /**
  37. * @param IUserManager $userManager
  38. */
  39. public function __construct(IUserManager $userManager) {
  40. $this->userManager = $userManager;
  41. parent::__construct();
  42. }
  43. protected function configure() {
  44. $this
  45. ->setName('user:report')
  46. ->setDescription('shows how many users have access');
  47. }
  48. protected function execute(InputInterface $input, OutputInterface $output): int {
  49. $table = new Table($output);
  50. $table->setHeaders(['User Report', '']);
  51. $userCountArray = $this->countUsers();
  52. if (!empty($userCountArray)) {
  53. $total = 0;
  54. $rows = [];
  55. foreach ($userCountArray as $classname => $users) {
  56. $total += $users;
  57. $rows[] = [$classname, $users];
  58. }
  59. $rows[] = [' '];
  60. $rows[] = ['total users', $total];
  61. } else {
  62. $rows[] = ['No backend enabled that supports user counting', ''];
  63. }
  64. $userDirectoryCount = $this->countUserDirectories();
  65. $rows[] = [' '];
  66. $rows[] = ['user directories', $userDirectoryCount];
  67. $table->setRows($rows);
  68. $table->render();
  69. return 0;
  70. }
  71. private function countUsers() {
  72. return $this->userManager->countUsers();
  73. }
  74. private function countUserDirectories() {
  75. $dataview = new \OC\Files\View('/');
  76. $userDirectories = $dataview->getDirectoryContent('/', 'httpd/unix-directory');
  77. return count($userDirectories);
  78. }
  79. }