CreateAddressBook.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  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, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCA\DAV\Command;
  25. use OCA\DAV\CardDAV\CardDavBackend;
  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\Output\OutputInterface;
  31. class CreateAddressBook extends Command {
  32. /** @var IUserManager */
  33. private $userManager;
  34. /** @var CardDavBackend */
  35. private $cardDavBackend;
  36. /**
  37. * @param IUserManager $userManager
  38. * @param CardDavBackend $cardDavBackend
  39. */
  40. function __construct(IUserManager $userManager,
  41. CardDavBackend $cardDavBackend
  42. ) {
  43. parent::__construct();
  44. $this->userManager = $userManager;
  45. $this->cardDavBackend = $cardDavBackend;
  46. }
  47. protected function configure() {
  48. $this
  49. ->setName('dav:create-addressbook')
  50. ->setDescription('Create a dav addressbook')
  51. ->addArgument('user',
  52. InputArgument::REQUIRED,
  53. 'User for whom the addressbook will be created')
  54. ->addArgument('name',
  55. InputArgument::REQUIRED,
  56. 'Name of the addressbook');
  57. }
  58. protected function execute(InputInterface $input, OutputInterface $output) {
  59. $user = $input->getArgument('user');
  60. if (!$this->userManager->userExists($user)) {
  61. throw new \InvalidArgumentException("User <$user> in unknown.");
  62. }
  63. $name = $input->getArgument('name');
  64. $this->cardDavBackend->createAddressBook("principals/users/$user", $name, []);
  65. }
  66. }