RemoveUser.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Robin Appelman <robin@icewind.nl>
  4. *
  5. * @author Robin Appelman <robin@icewind.nl>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace OC\Core\Command\Group;
  24. use OC\Core\Command\Base;
  25. use OCP\IGroupManager;
  26. use OCP\IUserManager;
  27. use Symfony\Component\Console\Input\InputArgument;
  28. use Symfony\Component\Console\Input\InputInterface;
  29. use Symfony\Component\Console\Output\OutputInterface;
  30. class RemoveUser extends Base {
  31. /** @var IUserManager */
  32. protected $userManager;
  33. /** @var IGroupManager */
  34. protected $groupManager;
  35. /**
  36. * @param IUserManager $userManager
  37. * @param IGroupManager $groupManager
  38. */
  39. public function __construct(IUserManager $userManager, IGroupManager $groupManager) {
  40. $this->userManager = $userManager;
  41. $this->groupManager = $groupManager;
  42. parent::__construct();
  43. }
  44. protected function configure() {
  45. $this
  46. ->setName('group:removeuser')
  47. ->setDescription('remove a user from a group')
  48. ->addArgument(
  49. 'group',
  50. InputArgument::REQUIRED,
  51. 'group to remove the user from'
  52. )->addArgument(
  53. 'user',
  54. InputArgument::REQUIRED,
  55. 'user to remove from the group'
  56. );
  57. }
  58. protected function execute(InputInterface $input, OutputInterface $output) {
  59. $group = $this->groupManager->get($input->getArgument('group'));
  60. if (is_null($group)) {
  61. $output->writeln('<error>group not found</error>');
  62. return 1;
  63. }
  64. $user = $this->userManager->get($input->getArgument('user'));
  65. if (is_null($user)) {
  66. $output->writeln('<error>user not found</error>');
  67. return 1;
  68. }
  69. $group->removeUser($user);
  70. }
  71. }