Report.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. * @author Joas Schilling <nickvergessen@owncloud.com>
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Thomas Müller <thomas.mueller@tmit.eu>
  7. *
  8. * @copyright Copyright (c) 2016, ownCloud, Inc.
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  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, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OC\Core\Command\User;
  25. use OCP\IUserManager;
  26. use Symfony\Component\Console\Command\Command;
  27. use Symfony\Component\Console\Input\InputInterface;
  28. use Symfony\Component\Console\Output\OutputInterface;
  29. class Report extends Command {
  30. /** @var IUserManager */
  31. protected $userManager;
  32. /**
  33. * @param IUserManager $userManager
  34. */
  35. public function __construct(IUserManager $userManager) {
  36. $this->userManager = $userManager;
  37. parent::__construct();
  38. }
  39. protected function configure() {
  40. $this
  41. ->setName('user:report')
  42. ->setDescription('shows how many users have access');
  43. }
  44. protected function execute(InputInterface $input, OutputInterface $output) {
  45. /** @var \Symfony\Component\Console\Helper\TableHelper $table */
  46. $table = $this->getHelperSet()->get('table');
  47. $table->setHeaders(array('User Report', ''));
  48. $userCountArray = $this->countUsers();
  49. if(!empty($userCountArray)) {
  50. $total = 0;
  51. $rows = array();
  52. foreach($userCountArray as $classname => $users) {
  53. $total += $users;
  54. $rows[] = array($classname, $users);
  55. }
  56. $rows[] = array(' ');
  57. $rows[] = array('total users', $total);
  58. } else {
  59. $rows[] = array('No backend enabled that supports user counting', '');
  60. }
  61. $userDirectoryCount = $this->countUserDirectories();
  62. $rows[] = array(' ');
  63. $rows[] = array('user directories', $userDirectoryCount);
  64. $table->setRows($rows);
  65. $table->render($output);
  66. }
  67. private function countUsers() {
  68. return $this->userManager->countUsers();
  69. }
  70. private function countUserDirectories() {
  71. $dataview = new \OC\Files\View('/');
  72. $userDirectories = $dataview->getDirectoryContent('/', 'httpd/unix-directory');
  73. return count($userDirectories);
  74. }
  75. }