CreateAddressBook.php 2.3 KB

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