Enable.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * @author Thomas Müller <thomas.mueller@tmit.eu>
  4. *
  5. * @copyright Copyright (c) 2016, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace OC\Core\Command\User;
  22. use OCP\IUser;
  23. use OCP\IUserManager;
  24. use Symfony\Component\Console\Command\Command;
  25. use Symfony\Component\Console\Input\InputInterface;
  26. use Symfony\Component\Console\Output\OutputInterface;
  27. use Symfony\Component\Console\Input\InputArgument;
  28. class Enable extends Command {
  29. /** @var IUserManager */
  30. protected $userManager;
  31. /**
  32. * @param IUserManager $userManager
  33. */
  34. public function __construct(IUserManager $userManager) {
  35. $this->userManager = $userManager;
  36. parent::__construct();
  37. }
  38. protected function configure() {
  39. $this
  40. ->setName('user:enable')
  41. ->setDescription('enables the specified user')
  42. ->addArgument(
  43. 'uid',
  44. InputArgument::REQUIRED,
  45. 'the username'
  46. );
  47. }
  48. protected function execute(InputInterface $input, OutputInterface $output) {
  49. $user = $this->userManager->get($input->getArgument('uid'));
  50. if (is_null($user)) {
  51. $output->writeln('<error>User does not exist</error>');
  52. return;
  53. }
  54. $user->setEnabled(true);
  55. $output->writeln('<info>The specified user is enabled</info>');
  56. }
  57. }