Add.php 1.9 KB

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