2016-01-11 13:34:17 +00:00
|
|
|
<?php
|
2016-01-12 14:02:16 +00:00
|
|
|
/**
|
2016-07-21 14:49:16 +00:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2017-11-06 14:56:42 +00:00
|
|
|
* @author Bjoern Schiessle <bjoern@schiessle.org>
|
2017-11-06 19:15:27 +00:00
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
2016-07-21 14:49:16 +00:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2017-11-06 14:56:42 +00:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-01-12 14:02:16 +00:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
*
|
|
|
|
* @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/>
|
|
|
|
*
|
|
|
|
*/
|
2016-05-12 07:42:40 +00:00
|
|
|
namespace OCA\DAV\AppInfo;
|
2016-01-11 13:34:17 +00:00
|
|
|
|
2017-05-03 12:22:02 +00:00
|
|
|
use OC\AppFramework\Utility\SimpleContainer;
|
2016-10-13 13:34:26 +00:00
|
|
|
use OCA\DAV\CalDAV\Activity\Backend;
|
2016-11-29 15:21:36 +00:00
|
|
|
use OCA\DAV\CalDAV\Activity\Provider\Event;
|
2016-02-03 14:43:45 +00:00
|
|
|
use OCA\DAV\CalDAV\BirthdayService;
|
2017-11-07 00:31:28 +00:00
|
|
|
use OCA\DAV\CalDAV\CalendarManager;
|
2019-03-16 15:19:25 +00:00
|
|
|
use OCA\DAV\CalDAV\Reminder\Backend as ReminderBackend;
|
|
|
|
use OCA\DAV\CalDAV\Reminder\NotificationProvider\EmailProvider;
|
|
|
|
use OCA\DAV\CalDAV\Reminder\NotificationProvider\PushProvider;
|
|
|
|
use OCA\DAV\CalDAV\Reminder\NotificationProviderManager;
|
|
|
|
use OCA\DAV\CalDAV\Reminder\Notifier;
|
|
|
|
use OCA\DAV\CalDAV\Reminder\ReminderService;
|
2016-10-21 09:45:17 +00:00
|
|
|
use OCA\DAV\Capabilities;
|
2016-01-11 13:34:17 +00:00
|
|
|
use OCA\DAV\CardDAV\ContactsManager;
|
2017-05-03 12:22:02 +00:00
|
|
|
use OCA\DAV\CardDAV\PhotoCache;
|
2016-01-13 19:56:25 +00:00
|
|
|
use OCA\DAV\CardDAV\SyncService;
|
|
|
|
use OCA\DAV\HookManager;
|
2016-01-11 13:34:17 +00:00
|
|
|
use \OCP\AppFramework\App;
|
2017-11-07 00:31:28 +00:00
|
|
|
use OCP\Contacts\IManager as IContactsManager;
|
|
|
|
use OCP\Calendar\IManager as ICalendarManager;
|
2016-09-23 15:21:07 +00:00
|
|
|
use OCP\IUser;
|
2016-02-03 14:43:45 +00:00
|
|
|
use Symfony\Component\EventDispatcher\GenericEvent;
|
2016-01-11 13:34:17 +00:00
|
|
|
|
|
|
|
class Application extends App {
|
|
|
|
|
2019-03-16 15:19:25 +00:00
|
|
|
const APP_ID = 'dav';
|
|
|
|
|
2016-01-11 13:34:17 +00:00
|
|
|
/**
|
|
|
|
* Application constructor.
|
|
|
|
*/
|
2016-09-19 23:15:24 +00:00
|
|
|
public function __construct() {
|
|
|
|
parent::__construct('dav');
|
2016-10-21 09:45:17 +00:00
|
|
|
|
2017-05-03 12:22:02 +00:00
|
|
|
$container = $this->getContainer();
|
|
|
|
$server = $container->getServer();
|
|
|
|
|
|
|
|
$container->registerService(PhotoCache::class, function(SimpleContainer $s) use ($server) {
|
|
|
|
return new PhotoCache(
|
2018-12-17 16:28:19 +00:00
|
|
|
$server->getAppDataDir('dav-photocache'),
|
|
|
|
$server->getLogger()
|
2017-05-03 12:22:02 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2016-10-21 09:45:17 +00:00
|
|
|
/*
|
|
|
|
* Register capabilities
|
|
|
|
*/
|
2017-05-03 12:22:02 +00:00
|
|
|
$container->registerCapability(Capabilities::class);
|
2016-01-11 13:34:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-11-07 00:31:28 +00:00
|
|
|
* @param IContactsManager $contactsManager
|
2016-01-11 13:34:17 +00:00
|
|
|
* @param string $userID
|
|
|
|
*/
|
2017-11-07 00:31:28 +00:00
|
|
|
public function setupContactsProvider(IContactsManager $contactsManager, $userID) {
|
2016-01-11 13:34:17 +00:00
|
|
|
/** @var ContactsManager $cm */
|
2016-09-19 23:15:24 +00:00
|
|
|
$cm = $this->getContainer()->query(ContactsManager::class);
|
2016-06-21 13:25:44 +00:00
|
|
|
$urlGenerator = $this->getContainer()->getServer()->getURLGenerator();
|
|
|
|
$cm->setupContactsProvider($contactsManager, $userID, $urlGenerator);
|
2016-01-11 13:34:17 +00:00
|
|
|
}
|
|
|
|
|
2017-09-16 11:42:46 +00:00
|
|
|
/**
|
2019-03-06 10:06:03 +00:00
|
|
|
* @param IContactsManager $contactsManager
|
2017-09-16 11:42:46 +00:00
|
|
|
*/
|
|
|
|
public function setupSystemContactsProvider(IContactsManager $contactsManager) {
|
|
|
|
/** @var ContactsManager $cm */
|
|
|
|
$cm = $this->getContainer()->query(ContactsManager::class);
|
|
|
|
$urlGenerator = $this->getContainer()->getServer()->getURLGenerator();
|
|
|
|
$cm->setupSystemContactsProvider($contactsManager, $urlGenerator);
|
|
|
|
}
|
|
|
|
|
2017-11-07 00:31:28 +00:00
|
|
|
/**
|
|
|
|
* @param ICalendarManager $calendarManager
|
|
|
|
* @param string $userId
|
|
|
|
*/
|
|
|
|
public function setupCalendarProvider(ICalendarManager $calendarManager, $userId) {
|
|
|
|
$cm = $this->getContainer()->query(CalendarManager::class);
|
|
|
|
$cm->setupCalendarProvider($calendarManager, $userId);
|
|
|
|
}
|
|
|
|
|
2016-01-13 19:56:25 +00:00
|
|
|
public function registerHooks() {
|
|
|
|
/** @var HookManager $hm */
|
2016-09-19 23:15:24 +00:00
|
|
|
$hm = $this->getContainer()->query(HookManager::class);
|
2016-01-13 19:56:25 +00:00
|
|
|
$hm->setup();
|
2016-02-03 14:43:45 +00:00
|
|
|
|
2016-09-23 15:21:07 +00:00
|
|
|
$dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
|
|
|
|
|
|
|
|
// first time login event setup
|
|
|
|
$dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) {
|
|
|
|
if ($event instanceof GenericEvent) {
|
|
|
|
$hm->firstLogin($event->getSubject());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-03-16 15:19:25 +00:00
|
|
|
$birthdayListener = function ($event) {
|
2016-02-03 14:43:45 +00:00
|
|
|
if ($event instanceof GenericEvent) {
|
2016-03-23 11:28:54 +00:00
|
|
|
/** @var BirthdayService $b */
|
2016-09-19 23:15:24 +00:00
|
|
|
$b = $this->getContainer()->query(BirthdayService::class);
|
2016-02-03 14:43:45 +00:00
|
|
|
$b->onCardChanged(
|
|
|
|
$event->getArgument('addressBookId'),
|
|
|
|
$event->getArgument('cardUri'),
|
|
|
|
$event->getArgument('cardData')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-03-16 15:19:25 +00:00
|
|
|
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $birthdayListener);
|
|
|
|
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $birthdayListener);
|
|
|
|
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function ($event) {
|
2016-02-03 14:43:45 +00:00
|
|
|
if ($event instanceof GenericEvent) {
|
2016-03-23 11:28:54 +00:00
|
|
|
/** @var BirthdayService $b */
|
2016-09-19 23:15:24 +00:00
|
|
|
$b = $this->getContainer()->query(BirthdayService::class);
|
2016-02-03 14:43:45 +00:00
|
|
|
$b->onCardDeleted(
|
|
|
|
$event->getArgument('addressBookId'),
|
|
|
|
$event->getArgument('cardUri')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2016-09-26 11:50:39 +00:00
|
|
|
|
2017-05-03 13:11:26 +00:00
|
|
|
$clearPhotoCache = function($event) {
|
|
|
|
if ($event instanceof GenericEvent) {
|
|
|
|
/** @var PhotoCache $p */
|
|
|
|
$p = $this->getContainer()->query(PhotoCache::class);
|
|
|
|
$p->delete(
|
|
|
|
$event->getArgument('addressBookId'),
|
|
|
|
$event->getArgument('cardUri')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache);
|
|
|
|
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache);
|
|
|
|
|
2016-11-11 13:36:17 +00:00
|
|
|
$dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) {
|
|
|
|
$user = $event->getSubject();
|
|
|
|
$syncService = $this->getContainer()->query(SyncService::class);
|
|
|
|
$syncService->updateUser($user);
|
|
|
|
});
|
|
|
|
|
2016-10-13 13:34:26 +00:00
|
|
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function(GenericEvent $event) {
|
|
|
|
/** @var Backend $backend */
|
|
|
|
$backend = $this->getContainer()->query(Backend::class);
|
|
|
|
$backend->onCalendarAdd(
|
|
|
|
$event->getArgument('calendarData')
|
|
|
|
);
|
|
|
|
});
|
|
|
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function(GenericEvent $event) {
|
|
|
|
/** @var Backend $backend */
|
|
|
|
$backend = $this->getContainer()->query(Backend::class);
|
|
|
|
$backend->onCalendarUpdate(
|
|
|
|
$event->getArgument('calendarData'),
|
|
|
|
$event->getArgument('shares'),
|
|
|
|
$event->getArgument('propertyMutations')
|
|
|
|
);
|
|
|
|
});
|
|
|
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function(GenericEvent $event) {
|
|
|
|
/** @var Backend $backend */
|
|
|
|
$backend = $this->getContainer()->query(Backend::class);
|
|
|
|
$backend->onCalendarDelete(
|
|
|
|
$event->getArgument('calendarData'),
|
|
|
|
$event->getArgument('shares')
|
|
|
|
);
|
2019-03-16 15:19:25 +00:00
|
|
|
|
|
|
|
$reminderBackend = $this->getContainer()->query(ReminderBackend::class);
|
|
|
|
$reminderBackend->cleanRemindersForCalendar(
|
|
|
|
$event->getArgument('calendarId')
|
|
|
|
);
|
2016-10-13 13:34:26 +00:00
|
|
|
});
|
|
|
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function(GenericEvent $event) {
|
|
|
|
/** @var Backend $backend */
|
|
|
|
$backend = $this->getContainer()->query(Backend::class);
|
|
|
|
$backend->onCalendarUpdateShares(
|
|
|
|
$event->getArgument('calendarData'),
|
|
|
|
$event->getArgument('shares'),
|
|
|
|
$event->getArgument('add'),
|
|
|
|
$event->getArgument('remove')
|
|
|
|
);
|
2019-03-16 15:19:25 +00:00
|
|
|
|
|
|
|
// Here we should recalculate if reminders should be sent to new or old sharees
|
2017-09-20 15:33:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::publishCalendar', function(GenericEvent $event) {
|
|
|
|
/** @var Backend $backend */
|
|
|
|
$backend = $this->getContainer()->query(Backend::class);
|
|
|
|
$backend->onCalendarPublication(
|
|
|
|
$event->getArgument('calendarData'),
|
|
|
|
$event->getArgument('public')
|
|
|
|
);
|
2016-10-13 13:34:26 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
$listener = function(GenericEvent $event, $eventName) {
|
|
|
|
/** @var Backend $backend */
|
|
|
|
$backend = $this->getContainer()->query(Backend::class);
|
|
|
|
|
2016-11-29 15:21:36 +00:00
|
|
|
$subject = Event::SUBJECT_OBJECT_ADD;
|
2016-10-13 13:34:26 +00:00
|
|
|
if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') {
|
2016-11-29 15:21:36 +00:00
|
|
|
$subject = Event::SUBJECT_OBJECT_UPDATE;
|
2016-10-13 13:34:26 +00:00
|
|
|
} else if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') {
|
2016-11-29 15:21:36 +00:00
|
|
|
$subject = Event::SUBJECT_OBJECT_DELETE;
|
2016-10-13 13:34:26 +00:00
|
|
|
}
|
|
|
|
$backend->onTouchCalendarObject(
|
|
|
|
$subject,
|
|
|
|
$event->getArgument('calendarData'),
|
|
|
|
$event->getArgument('shares'),
|
|
|
|
$event->getArgument('objectData')
|
|
|
|
);
|
2019-03-16 15:19:25 +00:00
|
|
|
|
|
|
|
/** @var ReminderService $reminderBackend */
|
|
|
|
$reminderService= $this->getContainer()->query(ReminderService::class);
|
|
|
|
|
|
|
|
$reminderService->onTouchCalendarObject(
|
|
|
|
$eventName,
|
|
|
|
$event->getArgument('calendarData'),
|
|
|
|
$event->getArgument('shares'),
|
|
|
|
$event->getArgument('objectData')
|
|
|
|
);
|
2016-10-13 13:34:26 +00:00
|
|
|
};
|
|
|
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener);
|
|
|
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener);
|
|
|
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener);
|
2016-01-13 19:56:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getSyncService() {
|
2016-09-19 23:15:24 +00:00
|
|
|
return $this->getContainer()->query(SyncService::class);
|
2016-01-13 19:56:25 +00:00
|
|
|
}
|
|
|
|
|
2019-03-16 15:19:25 +00:00
|
|
|
public function registerNotifier() {
|
|
|
|
$this->getContainer()->getServer()->getNotificationManager()->registerNotifier(function() {
|
|
|
|
return $this->getContainer()->query(Notifier::class);
|
|
|
|
}, function() {
|
|
|
|
$l = $this->getContainer()->getServer()->getL10NFactory()->get(self::APP_ID);
|
|
|
|
return [
|
|
|
|
'id' => self::APP_ID,
|
|
|
|
'name' => $l->t('Calendars and Contacts'),
|
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function registerCalendarReminders(): void
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
/** @var NotificationProviderManager $notificationProviderManager */
|
|
|
|
$notificationProviderManager = $this->getContainer()->query(NotificationProviderManager::class);
|
|
|
|
$notificationProviderManager->registerProvider(EmailProvider::class);
|
|
|
|
$notificationProviderManager->registerProvider(PushProvider::class);
|
|
|
|
} catch(\Exception $ex) {
|
|
|
|
$this->getContainer()->getServer()->getLogger()->logException($ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-11 13:34:17 +00:00
|
|
|
}
|