Enable.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Thomas Müller <thomas.mueller@tmit.eu>
  6. *
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OC\Core\Command\User;
  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. }