createcalendar.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * @author Thomas Müller <thomas.mueller@tmit.eu>
  4. *
  5. * @copyright Copyright (c) 2016, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace OCA\DAV\Command;
  22. use OCA\DAV\CalDAV\CalDavBackend;
  23. use OCA\DAV\Connector\Sabre\Principal;
  24. use OCP\IDBConnection;
  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\Output\OutputInterface;
  31. class CreateCalendar extends Command {
  32. /** @var IUserManager */
  33. protected $userManager;
  34. /** @var IGroupManager $groupManager */
  35. private $groupManager;
  36. /** @var \OCP\IDBConnection */
  37. protected $dbConnection;
  38. /**
  39. * @param IUserManager $userManager
  40. * @param IDBConnection $dbConnection
  41. */
  42. function __construct(IUserManager $userManager, IGroupManager $groupManager, IDBConnection $dbConnection) {
  43. parent::__construct();
  44. $this->userManager = $userManager;
  45. $this->groupManager = $groupManager;
  46. $this->dbConnection = $dbConnection;
  47. }
  48. protected function configure() {
  49. $this
  50. ->setName('dav:create-calendar')
  51. ->setDescription('Create a dav calendar')
  52. ->addArgument('user',
  53. InputArgument::REQUIRED,
  54. 'User for whom the calendar will be created')
  55. ->addArgument('name',
  56. InputArgument::REQUIRED,
  57. 'Name of the calendar');
  58. }
  59. protected function execute(InputInterface $input, OutputInterface $output) {
  60. $user = $input->getArgument('user');
  61. if (!$this->userManager->userExists($user)) {
  62. throw new \InvalidArgumentException("User <$user> in unknown.");
  63. }
  64. $principalBackend = new Principal(
  65. $this->userManager,
  66. $this->groupManager
  67. );
  68. $name = $input->getArgument('name');
  69. $caldav = new CalDavBackend($this->dbConnection, $principalBackend);
  70. $caldav->createCalendar("principals/users/$user", $name, []);
  71. }
  72. }