RemoveUser.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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\Command\Command;
  28. use Symfony\Component\Console\Input\InputArgument;
  29. use Symfony\Component\Console\Input\InputInterface;
  30. use Symfony\Component\Console\Input\InputOption;
  31. use Symfony\Component\Console\Output\OutputInterface;
  32. class RemoveUser extends Base {
  33. /** @var IUserManager */
  34. protected $userManager;
  35. /** @var IGroupManager */
  36. protected $groupManager;
  37. /**
  38. * @param IUserManager $userManager
  39. * @param IGroupManager $groupManager
  40. */
  41. public function __construct(IUserManager $userManager, IGroupManager $groupManager) {
  42. $this->userManager = $userManager;
  43. $this->groupManager = $groupManager;
  44. parent::__construct();
  45. }
  46. protected function configure() {
  47. $this
  48. ->setName('group:removeuser')
  49. ->setDescription('remove a user from a group')
  50. ->addArgument(
  51. 'group',
  52. InputArgument::REQUIRED,
  53. 'group to remove the user from'
  54. )->addArgument(
  55. 'user',
  56. InputArgument::REQUIRED,
  57. 'user to remove from the group'
  58. );
  59. }
  60. protected function execute(InputInterface $input, OutputInterface $output) {
  61. $group = $this->groupManager->get($input->getArgument('group'));
  62. if (is_null($group)) {
  63. $output->writeln('<error>group not found</error>');
  64. return 1;
  65. }
  66. $user = $this->userManager->get($input->getArgument('user'));
  67. if (is_null($user)) {
  68. $output->writeln('<error>user not found</error>');
  69. return 1;
  70. }
  71. $group->removeUser($user);
  72. }
  73. }