Report.php 2.6 KB

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