Delete.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Jens-Christian Fischer <jens-christian.fischer@switch.ch>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Morris Jobke <hey@morrisjobke.de>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  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\Input\InputArgument;
  30. use Symfony\Component\Console\Input\InputInterface;
  31. use Symfony\Component\Console\Output\OutputInterface;
  32. class Delete 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:delete')
  45. ->setDescription('deletes the specified user')
  46. ->addArgument(
  47. 'uid',
  48. InputArgument::REQUIRED,
  49. 'the username'
  50. );
  51. }
  52. protected function execute(InputInterface $input, OutputInterface $output): int {
  53. $user = $this->userManager->get($input->getArgument('uid'));
  54. if (is_null($user)) {
  55. $output->writeln('<error>User does not exist</error>');
  56. return 0;
  57. }
  58. if ($user->delete()) {
  59. $output->writeln('<info>The specified user was deleted</info>');
  60. return 0;
  61. }
  62. $output->writeln('<error>The specified user could not be deleted. Please check the logs.</error>');
  63. return 1;
  64. }
  65. }