1
0

CreateCalendar.php 3.1 KB

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