You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CreateCalendar.php 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Thomas Citharel <tcit@tcit.fr>
  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\CalDAV\CalDavBackend;
  26. use OCA\DAV\Connector\Sabre\Principal;
  27. use OCP\IDBConnection;
  28. use OCP\IGroupManager;
  29. use OCP\IUserManager;
  30. use Symfony\Component\Console\Command\Command;
  31. use Symfony\Component\Console\Input\InputArgument;
  32. use Symfony\Component\Console\Input\InputInterface;
  33. use Symfony\Component\Console\Output\OutputInterface;
  34. class CreateCalendar extends Command {
  35. /** @var IUserManager */
  36. protected $userManager;
  37. /** @var IGroupManager $groupManager */
  38. private $groupManager;
  39. /** @var \OCP\IDBConnection */
  40. protected $dbConnection;
  41. /**
  42. * @param IUserManager $userManager
  43. * @param IGroupManager $groupManager
  44. * @param IDBConnection $dbConnection
  45. */
  46. function __construct(IUserManager $userManager, IGroupManager $groupManager, IDBConnection $dbConnection) {
  47. parent::__construct();
  48. $this->userManager = $userManager;
  49. $this->groupManager = $groupManager;
  50. $this->dbConnection = $dbConnection;
  51. }
  52. protected function configure() {
  53. $this
  54. ->setName('dav:create-calendar')
  55. ->setDescription('Create a dav calendar')
  56. ->addArgument('user',
  57. InputArgument::REQUIRED,
  58. 'User for whom the calendar will be created')
  59. ->addArgument('name',
  60. InputArgument::REQUIRED,
  61. 'Name of the calendar');
  62. }
  63. protected function execute(InputInterface $input, OutputInterface $output) {
  64. $user = $input->getArgument('user');
  65. if (!$this->userManager->userExists($user)) {
  66. throw new \InvalidArgumentException("User <$user> in unknown.");
  67. }
  68. $principalBackend = new Principal(
  69. $this->userManager,
  70. $this->groupManager
  71. );
  72. $random = \OC::$server->getSecureRandom();
  73. $dispatcher = \OC::$server->getEventDispatcher();
  74. $name = $input->getArgument('name');
  75. $caldav = new CalDavBackend($this->dbConnection, $principalBackend, $this->userManager, $this->groupManager, $random, $dispatcher);
  76. $caldav->createCalendar("principals/users/$user", $name, []);
  77. }
  78. }