summaryrefslogtreecommitdiffstats
path: root/apps/dav/appinfo
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2016-02-19 12:33:19 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-02-19 12:33:19 +0100
commitffc29503939ae34338108a50aaaba20e1ec1ad75 (patch)
treea791cede35c6575bf54a761a27a4c77d3c8ef2ba /apps/dav/appinfo
parentae2304f23f04f1d6c84f2a049a4b0fdc0c9023c6 (diff)
parentd8de7d1e73f303c71a3cf1dea43fb67f3606700d (diff)
downloadnextcloud-server-ffc29503939ae34338108a50aaaba20e1ec1ad75.tar.gz
nextcloud-server-ffc29503939ae34338108a50aaaba20e1ec1ad75.zip
Merge pull request #22198 from owncloud/birthday-calendar
Sync a users contacts birthday to the users birthday calendar
Diffstat (limited to 'apps/dav/appinfo')
-rw-r--r--apps/dav/appinfo/application.php39
-rw-r--r--apps/dav/appinfo/register_command.php6
2 files changed, 40 insertions, 5 deletions
diff --git a/apps/dav/appinfo/application.php b/apps/dav/appinfo/application.php
index 28b9a833456..7a201e1dd78 100644
--- a/apps/dav/appinfo/application.php
+++ b/apps/dav/appinfo/application.php
@@ -20,6 +20,7 @@
*/
namespace OCA\Dav\AppInfo;
+use OCA\DAV\CalDAV\BirthdayService;
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CardDAV\CardDavBackend;
use OCA\DAV\CardDAV\ContactsManager;
@@ -34,6 +35,7 @@ use \OCP\AppFramework\App;
use OCP\AppFramework\IAppContainer;
use OCP\Contacts\IManager;
use OCP\IUser;
+use Symfony\Component\EventDispatcher\GenericEvent;
class Application extends App {
@@ -74,12 +76,12 @@ class Application extends App {
$container->registerService('CardDavBackend', function($c) {
/** @var IAppContainer $c */
$db = $c->getServer()->getDatabaseConnection();
- $logger = $c->getServer()->getLogger();
+ $dispatcher = $c->getServer()->getEventDispatcher();
$principal = new \OCA\DAV\Connector\Sabre\Principal(
$c->getServer()->getUserManager(),
$c->getServer()->getGroupManager()
);
- return new CardDavBackend($db, $principal, $logger);
+ return new CardDavBackend($db, $principal, $dispatcher);
});
$container->registerService('CalDavBackend', function($c) {
@@ -109,6 +111,15 @@ class Application extends App {
$c->query('CalDavBackend')
);
});
+
+ $container->registerService('BirthdayService', function($c) {
+ /** @var IAppContainer $c */
+ return new BirthdayService(
+ $c->query('CalDavBackend'),
+ $c->query('CardDavBackend')
+ );
+
+ });
}
/**
@@ -125,6 +136,30 @@ class Application extends App {
/** @var HookManager $hm */
$hm = $this->getContainer()->query('HookManager');
$hm->setup();
+
+ $listener = function($event) {
+ if ($event instanceof GenericEvent) {
+ $b = $this->getContainer()->query('BirthdayService');
+ $b->onCardChanged(
+ $event->getArgument('addressBookId'),
+ $event->getArgument('cardUri'),
+ $event->getArgument('cardData')
+ );
+ }
+ };
+
+ $dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
+ $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $listener);
+ $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $listener);
+ $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) {
+ if ($event instanceof GenericEvent) {
+ $b = $this->getContainer()->query('BirthdayService');
+ $b->onCardDeleted(
+ $event->getArgument('addressBookId'),
+ $event->getArgument('cardUri')
+ );
+ }
+ });
}
public function getSyncService() {
diff --git a/apps/dav/appinfo/register_command.php b/apps/dav/appinfo/register_command.php
index 4981cab9264..e07f6b4a25b 100644
--- a/apps/dav/appinfo/register_command.php
+++ b/apps/dav/appinfo/register_command.php
@@ -24,21 +24,21 @@ use OCA\DAV\Command\CreateAddressBook;
use OCA\DAV\Command\CreateCalendar;
use OCA\Dav\Command\MigrateAddressbooks;
use OCA\Dav\Command\MigrateCalendars;
+use OCA\DAV\Command\SyncBirthdayCalendar;
use OCA\DAV\Command\SyncSystemAddressBook;
-$config = \OC::$server->getConfig();
$dbConnection = \OC::$server->getDatabaseConnection();
$userManager = OC::$server->getUserManager();
$groupManager = OC::$server->getGroupManager();
$config = \OC::$server->getConfig();
-$logger = \OC::$server->getLogger();
$app = new Application();
/** @var Symfony\Component\Console\Application $application */
-$application->add(new CreateAddressBook($userManager, $groupManager, $dbConnection, $logger));
$application->add(new CreateCalendar($userManager, $groupManager, $dbConnection));
+$application->add(new CreateAddressBook($userManager, $app->getContainer()->query('CardDavBackend')));
$application->add(new SyncSystemAddressBook($app->getSyncService()));
+$application->add(new SyncBirthdayCalendar($userManager, $app->getContainer()->query('BirthdayService')));
// the occ tool is *for now* only available in debug mode for developers to test
if ($config->getSystemValue('debug', false)){