Delete.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. * @author Jens-Christian Fischer <jens-christian.fischer@switch.ch>
  5. * @author Joas Schilling <nickvergessen@owncloud.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  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. use Symfony\Component\Console\Input\InputArgument;
  30. class Delete extends Command {
  31. /** @var IUserManager */
  32. protected $userManager;
  33. /**
  34. * @param IUserManager $userManager
  35. */
  36. public function __construct(IUserManager $userManager) {
  37. $this->userManager = $userManager;
  38. parent::__construct();
  39. }
  40. protected function configure() {
  41. $this
  42. ->setName('user:delete')
  43. ->setDescription('deletes the specified user')
  44. ->addArgument(
  45. 'uid',
  46. InputArgument::REQUIRED,
  47. 'the username'
  48. );
  49. }
  50. protected function execute(InputInterface $input, OutputInterface $output) {
  51. $user = $this->userManager->get($input->getArgument('uid'));
  52. if (is_null($user)) {
  53. $output->writeln('<error>User does not exist</error>');
  54. return;
  55. }
  56. if ($user->delete()) {
  57. $output->writeln('<info>The specified user was deleted</info>');
  58. return;
  59. }
  60. $output->writeln('<error>The specified user could not be deleted. Please check the logs.</error>');
  61. }
  62. }