CreateCalendar.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Thomas Citharel <nextcloud@tcit.fr>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OCA\DAV\Command;
  27. use OC\KnownUser\KnownUserService;
  28. use OCA\DAV\CalDAV\CalDavBackend;
  29. use OCA\DAV\CalDAV\Proxy\ProxyMapper;
  30. use OCA\DAV\CalDAV\Sharing\Backend;
  31. use OCA\DAV\Connector\Sabre\Principal;
  32. use OCP\Accounts\IAccountManager;
  33. use OCP\EventDispatcher\IEventDispatcher;
  34. use OCP\IConfig;
  35. use OCP\IDBConnection;
  36. use OCP\IGroupManager;
  37. use OCP\IUserManager;
  38. use Psr\Log\LoggerInterface;
  39. use Symfony\Component\Console\Command\Command;
  40. use Symfony\Component\Console\Input\InputArgument;
  41. use Symfony\Component\Console\Input\InputInterface;
  42. use Symfony\Component\Console\Output\OutputInterface;
  43. class CreateCalendar extends Command {
  44. public function __construct(
  45. protected IUserManager $userManager,
  46. private IGroupManager $groupManager,
  47. protected IDBConnection $dbConnection,
  48. ) {
  49. parent::__construct();
  50. }
  51. protected function configure(): void {
  52. $this
  53. ->setName('dav:create-calendar')
  54. ->setDescription('Create a dav calendar')
  55. ->addArgument('user',
  56. InputArgument::REQUIRED,
  57. 'User for whom the calendar will be created')
  58. ->addArgument('name',
  59. InputArgument::REQUIRED,
  60. 'Name of the calendar');
  61. }
  62. protected function execute(InputInterface $input, OutputInterface $output): int {
  63. $user = $input->getArgument('user');
  64. if (!$this->userManager->userExists($user)) {
  65. throw new \InvalidArgumentException("User <$user> in unknown.");
  66. }
  67. $principalBackend = new Principal(
  68. $this->userManager,
  69. $this->groupManager,
  70. \OC::$server->get(IAccountManager::class),
  71. \OC::$server->getShareManager(),
  72. \OC::$server->getUserSession(),
  73. \OC::$server->getAppManager(),
  74. \OC::$server->query(ProxyMapper::class),
  75. \OC::$server->get(KnownUserService::class),
  76. \OC::$server->getConfig(),
  77. \OC::$server->getL10NFactory(),
  78. );
  79. $random = \OC::$server->getSecureRandom();
  80. $logger = \OC::$server->get(LoggerInterface::class);
  81. $dispatcher = \OC::$server->get(IEventDispatcher::class);
  82. $config = \OC::$server->get(IConfig::class);
  83. $name = $input->getArgument('name');
  84. $caldav = new CalDavBackend(
  85. $this->dbConnection,
  86. $principalBackend,
  87. $this->userManager,
  88. $random,
  89. $logger,
  90. $dispatcher,
  91. $config,
  92. \OC::$server->get(Backend::class),
  93. );
  94. $caldav->createCalendar("principals/users/$user", $name, []);
  95. return self::SUCCESS;
  96. }
  97. }