diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2016-05-12 09:42:40 +0200 |
---|---|---|
committer | Thomas Müller <DeepDiver1975@users.noreply.github.com> | 2016-05-12 09:42:40 +0200 |
commit | dd9ee10bc0699e5dcc17c3ef2181dcda01d9a69b (patch) | |
tree | 2d464fcc20ea330481e56487287aeae462ce5917 /apps/dav/lib/Command | |
parent | 4a3311f430ec6e45c62b2ebde2cae71e943f3c81 (diff) | |
download | nextcloud-server-dd9ee10bc0699e5dcc17c3ef2181dcda01d9a69b.tar.gz nextcloud-server-dd9ee10bc0699e5dcc17c3ef2181dcda01d9a69b.zip |
Move dav app to PSR-4 (#24527)
* Move Application to correct namespace and PSR-4 it
* Move dav app to PSR-4
Diffstat (limited to 'apps/dav/lib/Command')
-rw-r--r-- | apps/dav/lib/Command/CreateAddressBook.php | 77 | ||||
-rw-r--r-- | apps/dav/lib/Command/CreateCalendar.php | 81 | ||||
-rw-r--r-- | apps/dav/lib/Command/SyncBirthdayCalendar.php | 85 | ||||
-rw-r--r-- | apps/dav/lib/Command/SyncSystemAddressBook.php | 65 |
4 files changed, 308 insertions, 0 deletions
diff --git a/apps/dav/lib/Command/CreateAddressBook.php b/apps/dav/lib/Command/CreateAddressBook.php new file mode 100644 index 00000000000..48302a2b439 --- /dev/null +++ b/apps/dav/lib/Command/CreateAddressBook.php @@ -0,0 +1,77 @@ +<?php +/** + * @author Björn Schießle <schiessle@owncloud.com> + * @author Thomas Müller <thomas.mueller@tmit.eu> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ +namespace OCA\DAV\Command; + +use OCA\DAV\CardDAV\CardDavBackend; +use OCA\DAV\Connector\Sabre\Principal; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\IGroupManager; +use OCP\ILogger; +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 */ + private $userManager; + + /** @var CardDavBackend */ + private $cardDavBackend; + + /** + * @param IUserManager $userManager + * @param CardDavBackend $cardDavBackend + */ + function __construct(IUserManager $userManager, + CardDavBackend $cardDavBackend + ) { + parent::__construct(); + $this->userManager = $userManager; + $this->cardDavBackend = $cardDavBackend; + } + + 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'); + $this->cardDavBackend->createAddressBook("principals/users/$user", $name, []); + } +} diff --git a/apps/dav/lib/Command/CreateCalendar.php b/apps/dav/lib/Command/CreateCalendar.php new file mode 100644 index 00000000000..d7f82dd0e52 --- /dev/null +++ b/apps/dav/lib/Command/CreateCalendar.php @@ -0,0 +1,81 @@ +<?php +/** + * @author Thomas Müller <thomas.mueller@tmit.eu> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ +namespace OCA\DAV\Command; + +use OCA\DAV\CalDAV\CalDavBackend; +use OCA\DAV\Connector\Sabre\Principal; +use OCP\IDBConnection; +use OCP\IGroupManager; +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 IGroupManager $groupManager */ + private $groupManager; + + /** @var \OCP\IDBConnection */ + protected $dbConnection; + + /** + * @param IUserManager $userManager + * @param IDBConnection $dbConnection + */ + function __construct(IUserManager $userManager, IGroupManager $groupManager, IDBConnection $dbConnection) { + parent::__construct(); + $this->userManager = $userManager; + $this->groupManager = $groupManager; + $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."); + } + $principalBackend = new Principal( + $this->userManager, + $this->groupManager + ); + + $name = $input->getArgument('name'); + $caldav = new CalDavBackend($this->dbConnection, $principalBackend); + $caldav->createCalendar("principals/users/$user", $name, []); + } +} diff --git a/apps/dav/lib/Command/SyncBirthdayCalendar.php b/apps/dav/lib/Command/SyncBirthdayCalendar.php new file mode 100644 index 00000000000..90a73a3eeb3 --- /dev/null +++ b/apps/dav/lib/Command/SyncBirthdayCalendar.php @@ -0,0 +1,85 @@ +<?php +/** + * @author Thomas Müller <thomas.mueller@tmit.eu> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ +namespace OCA\DAV\Command; + +use OCA\DAV\CalDAV\BirthdayService; +use OCP\IUser; +use OCP\IUserManager; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Helper\ProgressBar; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class SyncBirthdayCalendar extends Command { + + /** @var BirthdayService */ + private $birthdayService; + + /** @var IUserManager */ + private $userManager; + + /** + * @param IUserManager $userManager + * @param BirthdayService $birthdayService + */ + function __construct(IUserManager $userManager, BirthdayService $birthdayService) { + parent::__construct(); + $this->birthdayService = $birthdayService; + $this->userManager = $userManager; + } + + protected function configure() { + $this + ->setName('dav:sync-birthday-calendar') + ->setDescription('Synchronizes the birthday calendar') + ->addArgument('user', + InputArgument::OPTIONAL, + 'User for whom the birthday calendar will be synchronized'); + } + + /** + * @param InputInterface $input + * @param OutputInterface $output + */ + protected function execute(InputInterface $input, OutputInterface $output) { + $user = $input->getArgument('user'); + if (!is_null($user)) { + if (!$this->userManager->userExists($user)) { + throw new \InvalidArgumentException("User <$user> in unknown."); + } + $output->writeln("Start birthday calendar sync for $user"); + $this->birthdayService->syncUser($user); + return; + } + $output->writeln("Start birthday calendar sync for all users ..."); + $p = new ProgressBar($output); + $p->start(); + $this->userManager->callForAllUsers(function($user) use ($p) { + $p->advance(); + /** @var IUser $user */ + $this->birthdayService->syncUser($user->getUID()); + }); + + $p->finish(); + $output->writeln(''); + } +} diff --git a/apps/dav/lib/Command/SyncSystemAddressBook.php b/apps/dav/lib/Command/SyncSystemAddressBook.php new file mode 100644 index 00000000000..b62a42d7b90 --- /dev/null +++ b/apps/dav/lib/Command/SyncSystemAddressBook.php @@ -0,0 +1,65 @@ +<?php +/** + * @author Thomas Müller <thomas.mueller@tmit.eu> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see <http://www.gnu.org/licenses/> + * + */ +namespace OCA\DAV\Command; + +use OCA\DAV\CardDAV\SyncService; +use OCP\IUserManager; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Helper\ProgressBar; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class SyncSystemAddressBook extends Command { + + /** @var SyncService */ + private $syncService; + + /** + * @param SyncService $syncService + */ + function __construct(SyncService $syncService) { + parent::__construct(); + $this->syncService = $syncService; + } + + protected function configure() { + $this + ->setName('dav:sync-system-addressbook') + ->setDescription('Synchronizes users to the system addressbook'); + } + + /** + * @param InputInterface $input + * @param OutputInterface $output + */ + protected function execute(InputInterface $input, OutputInterface $output) { + $output->writeln('Syncing users ...'); + $progress = new ProgressBar($output); + $progress->start(); + $this->syncService->syncInstance(function() use ($progress) { + $progress->advance(); + }); + + $progress->finish(); + $output->writeln(''); + } +} |