diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-11-05 11:37:31 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-11-06 15:26:51 +0100 |
commit | 20e37bd38f8e1291079f3d006f6e369d826a4463 (patch) | |
tree | 98e8d4a86b6704dfd2076f2a7830dbea707e6a72 /apps | |
parent | d8e965e59ad139c3f07f300344c7ab415cfbc901 (diff) | |
download | nextcloud-server-20e37bd38f8e1291079f3d006f6e369d826a4463.tar.gz nextcloud-server-20e37bd38f8e1291079f3d006f6e369d826a4463.zip |
Adding occ command to create an addressbook
Diffstat (limited to 'apps')
-rw-r--r-- | apps/dav/appinfo/register_command.php | 8 | ||||
-rw-r--r-- | apps/dav/command/createaddressbook.php | 52 |
2 files changed, 60 insertions, 0 deletions
diff --git a/apps/dav/appinfo/register_command.php b/apps/dav/appinfo/register_command.php new file mode 100644 index 00000000000..c996dd44063 --- /dev/null +++ b/apps/dav/appinfo/register_command.php @@ -0,0 +1,8 @@ +<?php + +use OCA\DAV\Command\CreateAddressBook; + +$dbConnection = \OC::$server->getDatabaseConnection(); +$userManager = OC::$server->getUserManager(); +/** @var Symfony\Component\Console\Application $application */ +$application->add(new CreateAddressBook($userManager, $dbConnection)); diff --git a/apps/dav/command/createaddressbook.php b/apps/dav/command/createaddressbook.php new file mode 100644 index 00000000000..286871b39e2 --- /dev/null +++ b/apps/dav/command/createaddressbook.php @@ -0,0 +1,52 @@ +<?php + +namespace OCA\DAV\Command; + +use OCA\DAV\CardDAV\CardDavBackend; +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 CreateAddressBook 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-addressbook') + ->setDescription('Create a dav addressbook') + ->addArgument('user', + InputArgument::REQUIRED, + 'User for whom the addressbook will be created') + ->addArgument('name', + InputArgument::REQUIRED, + 'Name of the addressbook'); + } + + 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'); + $carddav = new CardDavBackend($this->dbConnection); + $carddav->createAddressBook("principals/$user", $name, []); + } +} |