diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-11-16 16:29:01 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-11-16 16:29:01 +0100 |
commit | fc296aad5d2db3b95958bff23dead592332655c9 (patch) | |
tree | 7aa15bea8d6c6f721aa61a90f4720e09fe062b8a /apps/dav | |
parent | 867fd94dc663652da1465de8537f01b8c7b4db07 (diff) | |
download | nextcloud-server-fc296aad5d2db3b95958bff23dead592332655c9.tar.gz nextcloud-server-fc296aad5d2db3b95958bff23dead592332655c9.zip |
Add occ command to create a new calendar
Diffstat (limited to 'apps/dav')
-rw-r--r-- | apps/dav/appinfo/register_command.php | 2 | ||||
-rw-r--r-- | apps/dav/command/createcalendar.php | 52 |
2 files changed, 54 insertions, 0 deletions
diff --git a/apps/dav/appinfo/register_command.php b/apps/dav/appinfo/register_command.php index c996dd44063..7d57b944fb2 100644 --- a/apps/dav/appinfo/register_command.php +++ b/apps/dav/appinfo/register_command.php @@ -1,8 +1,10 @@ <?php use OCA\DAV\Command\CreateAddressBook; +use OCA\DAV\Command\CreateCalendar; $dbConnection = \OC::$server->getDatabaseConnection(); $userManager = OC::$server->getUserManager(); /** @var Symfony\Component\Console\Application $application */ $application->add(new CreateAddressBook($userManager, $dbConnection)); +$application->add(new CreateCalendar($userManager, $dbConnection)); diff --git a/apps/dav/command/createcalendar.php b/apps/dav/command/createcalendar.php new file mode 100644 index 00000000000..da4f248e51d --- /dev/null +++ b/apps/dav/command/createcalendar.php @@ -0,0 +1,52 @@ +<?php + +namespace OCA\DAV\Command; + +use OCA\DAV\CalDAV\CalDavBackend; +use OCP\IDBConnection; +use OCP\IUserManager; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class CreateCalendar extends Command { + + /** @var IUserManager */ + protected $userManager; + + /** @var \OCP\IDBConnection */ + protected $dbConnection; + + /** + * @param IUserManager $userManager + * @param IDBConnection $dbConnection + */ + function __construct(IUserManager $userManager, IDBConnection $dbConnection) { + parent::__construct(); + $this->userManager = $userManager; + $this->dbConnection = $dbConnection; + } + + protected function configure() { + $this + ->setName('dav:create-calendar') + ->setDescription('Create a dav calendar') + ->addArgument('user', + InputArgument::REQUIRED, + 'User for whom the calendar will be created') + ->addArgument('name', + InputArgument::REQUIRED, + 'Name of the calendar'); + } + + protected function execute(InputInterface $input, OutputInterface $output) { + $user = $input->getArgument('user'); + if (!$this->userManager->userExists($user)) { + throw new \InvalidArgumentException("User <$user> in unknown."); + } + $name = $input->getArgument('name'); + $caldav = new CalDavBackend($this->dbConnection); + $caldav->createCalendar("principals/$user", $name, []); + } +} |