Merge pull request #21467 from nextcloud/enhancement/dav-bootstrap
Move DAV to the new bootstrap mechanism
This commit is contained in:
commit
d523925db5
|
@ -1,127 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
||||||
*
|
|
||||||
* @author Björn Schießle <bjoern@schiessle.org>
|
|
||||||
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
|
||||||
* @author Georg Ehrke <oc.list@georgehrke.com>
|
|
||||||
* @author Joas Schilling <coding@schilljs.com>
|
|
||||||
* @author Julius Härtl <jus@bitgrid.net>
|
|
||||||
* @author Lukas Reschke <lukas@statuscode.ch>
|
|
||||||
* @author Thomas Citharel <nextcloud@tcit.fr>
|
|
||||||
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
||||||
* @author Tobia De Koninck <tobia@ledfan.be>
|
|
||||||
*
|
|
||||||
* @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/>
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
use OCA\DAV\AppInfo\Application;
|
|
||||||
use OCA\DAV\CalDAV\WebcalCaching\RefreshWebcalService;
|
|
||||||
use OCA\DAV\CardDAV\CardDavBackend;
|
|
||||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
|
||||||
|
|
||||||
\OC_App::loadApps(['dav']);
|
|
||||||
|
|
||||||
/** @var Application $app */
|
|
||||||
$app = \OC::$server->query(Application::class);
|
|
||||||
$app->registerHooks();
|
|
||||||
|
|
||||||
\OC::$server->registerService('CardDAVSyncService', function () use ($app) {
|
|
||||||
return $app->getSyncService();
|
|
||||||
});
|
|
||||||
|
|
||||||
$eventDispatcher = \OC::$server->getEventDispatcher();
|
|
||||||
|
|
||||||
$eventDispatcher->addListener('OCP\Federation\TrustedServerEvent::remove',
|
|
||||||
function (GenericEvent $event) use ($app) {
|
|
||||||
/** @var CardDavBackend $cardDavBackend */
|
|
||||||
$cardDavBackend = $app->getContainer()->query(CardDavBackend::class);
|
|
||||||
$addressBookUri = $event->getSubject();
|
|
||||||
$addressBook = $cardDavBackend->getAddressBooksByUri('principals/system/system', $addressBookUri);
|
|
||||||
if (!is_null($addressBook)) {
|
|
||||||
$cardDavBackend->deleteAddressBook($addressBook['id']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
$eventDispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createSubscription',
|
|
||||||
function (GenericEvent $event) use ($app) {
|
|
||||||
$jobList = $app->getContainer()->getServer()->getJobList();
|
|
||||||
$subscriptionData = $event->getArgument('subscriptionData');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initial subscription refetch
|
|
||||||
* @var RefreshWebcalService $refreshWebcalService
|
|
||||||
*/
|
|
||||||
$refreshWebcalService = $app->getContainer()->query(RefreshWebcalService::class);
|
|
||||||
$refreshWebcalService->refreshSubscription($subscriptionData['principaluri'], $subscriptionData['uri']);
|
|
||||||
|
|
||||||
$jobList->add(\OCA\DAV\BackgroundJob\RefreshWebcalJob::class, [
|
|
||||||
'principaluri' => $subscriptionData['principaluri'],
|
|
||||||
'uri' => $subscriptionData['uri']
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
$eventDispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteSubscription',
|
|
||||||
function (GenericEvent $event) use ($app) {
|
|
||||||
$jobList = $app->getContainer()->getServer()->getJobList();
|
|
||||||
$subscriptionData = $event->getArgument('subscriptionData');
|
|
||||||
|
|
||||||
$jobList->remove(\OCA\DAV\BackgroundJob\RefreshWebcalJob::class, [
|
|
||||||
'principaluri' => $subscriptionData['principaluri'],
|
|
||||||
'uri' => $subscriptionData['uri']
|
|
||||||
]);
|
|
||||||
|
|
||||||
/** @var \OCA\DAV\CalDAV\CalDavBackend $calDavBackend */
|
|
||||||
$calDavBackend = $app->getContainer()->query(\OCA\DAV\CalDAV\CalDavBackend::class);
|
|
||||||
$calDavBackend->purgeAllCachedEventsForSubscription($subscriptionData['id']);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
$eventHandler = function () use ($app) {
|
|
||||||
try {
|
|
||||||
$job = $app->getContainer()->query(\OCA\DAV\BackgroundJob\UpdateCalendarResourcesRoomsBackgroundJob::class);
|
|
||||||
$job->run([]);
|
|
||||||
$app->getContainer()->getServer()->getJobList()->setLastRun($job);
|
|
||||||
} catch (\Exception $ex) {
|
|
||||||
$app->getContainer()->getServer()->getLogger()->logException($ex);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
$eventDispatcher->addListener('\OCP\Calendar\Resource\ForceRefreshEvent', $eventHandler);
|
|
||||||
$eventDispatcher->addListener('\OCP\Calendar\Room\ForceRefreshEvent', $eventHandler);
|
|
||||||
|
|
||||||
$cm = \OC::$server->getContactsManager();
|
|
||||||
$cm->register(function () use ($cm, $app) {
|
|
||||||
$user = \OC::$server->getUserSession()->getUser();
|
|
||||||
if (!is_null($user)) {
|
|
||||||
$app->setupContactsProvider($cm, $user->getUID());
|
|
||||||
} else {
|
|
||||||
$app->setupSystemContactsProvider($cm);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$calendarManager = \OC::$server->getCalendarManager();
|
|
||||||
$calendarManager->register(function () use ($calendarManager, $app) {
|
|
||||||
$user = \OC::$server->getUserSession()->getUser();
|
|
||||||
if ($user !== null) {
|
|
||||||
$app->setupCalendarProvider($calendarManager, $user->getUID());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->registerNotifier();
|
|
||||||
$app->registerCalendarReminders();
|
|
|
@ -1,4 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||||
*
|
*
|
||||||
|
@ -30,10 +33,12 @@
|
||||||
|
|
||||||
namespace OCA\DAV\AppInfo;
|
namespace OCA\DAV\AppInfo;
|
||||||
|
|
||||||
use OC\AppFramework\Utility\SimpleContainer;
|
use Exception;
|
||||||
|
use OCA\DAV\BackgroundJob\UpdateCalendarResourcesRoomsBackgroundJob;
|
||||||
use OCA\DAV\CalDAV\Activity\Backend;
|
use OCA\DAV\CalDAV\Activity\Backend;
|
||||||
use OCA\DAV\CalDAV\Activity\Provider\Event;
|
use OCA\DAV\CalDAV\Activity\Provider\Event;
|
||||||
use OCA\DAV\CalDAV\BirthdayService;
|
use OCA\DAV\CalDAV\BirthdayService;
|
||||||
|
use OCA\DAV\CalDAV\CalDavBackend;
|
||||||
use OCA\DAV\CalDAV\CalendarManager;
|
use OCA\DAV\CalDAV\CalendarManager;
|
||||||
use OCA\DAV\CalDAV\Reminder\Backend as ReminderBackend;
|
use OCA\DAV\CalDAV\Reminder\Backend as ReminderBackend;
|
||||||
use OCA\DAV\CalDAV\Reminder\NotificationProvider\AudioProvider;
|
use OCA\DAV\CalDAV\Reminder\NotificationProvider\AudioProvider;
|
||||||
|
@ -42,31 +47,48 @@ use OCA\DAV\CalDAV\Reminder\NotificationProvider\PushProvider;
|
||||||
use OCA\DAV\CalDAV\Reminder\NotificationProviderManager;
|
use OCA\DAV\CalDAV\Reminder\NotificationProviderManager;
|
||||||
use OCA\DAV\CalDAV\Reminder\Notifier;
|
use OCA\DAV\CalDAV\Reminder\Notifier;
|
||||||
use OCA\DAV\CalDAV\Reminder\ReminderService;
|
use OCA\DAV\CalDAV\Reminder\ReminderService;
|
||||||
|
use OCA\DAV\CalDAV\WebcalCaching\RefreshWebcalService;
|
||||||
use OCA\DAV\Capabilities;
|
use OCA\DAV\Capabilities;
|
||||||
|
use OCA\DAV\CardDAV\CardDavBackend;
|
||||||
use OCA\DAV\CardDAV\ContactsManager;
|
use OCA\DAV\CardDAV\ContactsManager;
|
||||||
use OCA\DAV\CardDAV\PhotoCache;
|
use OCA\DAV\CardDAV\PhotoCache;
|
||||||
use OCA\DAV\CardDAV\SyncService;
|
use OCA\DAV\CardDAV\SyncService;
|
||||||
use OCA\DAV\HookManager;
|
use OCA\DAV\HookManager;
|
||||||
use OCP\AppFramework\App;
|
use OCP\AppFramework\App;
|
||||||
|
use OCP\AppFramework\Bootstrap\IBootContext;
|
||||||
|
use OCP\AppFramework\Bootstrap\IBootstrap;
|
||||||
|
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
||||||
|
use OCP\AppFramework\IAppContainer;
|
||||||
use OCP\Calendar\IManager as ICalendarManager;
|
use OCP\Calendar\IManager as ICalendarManager;
|
||||||
use OCP\Contacts\IManager as IContactsManager;
|
use OCP\Contacts\IManager as IContactsManager;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
|
use OCP\IContainer;
|
||||||
|
use OCP\ILogger;
|
||||||
|
use OCP\IServerContainer;
|
||||||
use OCP\IUser;
|
use OCP\IUser;
|
||||||
|
use OCP\Notification\IManager as INotificationManager;
|
||||||
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||||
|
use Throwable;
|
||||||
|
use function is_null;
|
||||||
|
use function strpos;
|
||||||
|
|
||||||
class Application extends App {
|
class Application extends App implements IBootstrap {
|
||||||
public const APP_ID = 'dav';
|
public const APP_ID = 'dav';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Application constructor.
|
* Application constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
parent::__construct('dav');
|
parent::__construct(self::APP_ID);
|
||||||
|
}
|
||||||
|
|
||||||
$container = $this->getContainer();
|
public function register(IRegistrationContext $context): void {
|
||||||
$server = $container->getServer();
|
$context->registerServiceAlias('CardDAVSyncService', SyncService::class);
|
||||||
|
$context->registerService(PhotoCache::class, function (IContainer $c) {
|
||||||
|
/** @var IServerContainer $server */
|
||||||
|
$server = $c->query(IServerContainer::class);
|
||||||
|
|
||||||
$container->registerService(PhotoCache::class, function (SimpleContainer $s) use ($server) {
|
|
||||||
return new PhotoCache(
|
return new PhotoCache(
|
||||||
$server->getAppDataDir('dav-photocache'),
|
$server->getAppDataDir('dav-photocache'),
|
||||||
$server->getLogger()
|
$server->getLogger()
|
||||||
|
@ -76,46 +98,42 @@ class Application extends App {
|
||||||
/*
|
/*
|
||||||
* Register capabilities
|
* Register capabilities
|
||||||
*/
|
*/
|
||||||
$container->registerCapability(Capabilities::class);
|
$context->registerCapability(Capabilities::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function boot(IBootContext $context): void {
|
||||||
* @param IContactsManager $contactsManager
|
// Load all dav apps
|
||||||
* @param string $userID
|
\OC_App::loadApps(['dav']);
|
||||||
*/
|
|
||||||
public function setupContactsProvider(IContactsManager $contactsManager, $userID) {
|
$this->registerHooks(
|
||||||
/** @var ContactsManager $cm */
|
$context->getAppContainer()->query(HookManager::class),
|
||||||
$cm = $this->getContainer()->query(ContactsManager::class);
|
$context->getServerContainer()->getEventDispatcher(),
|
||||||
$urlGenerator = $this->getContainer()->getServer()->getURLGenerator();
|
$context->getAppContainer(),
|
||||||
$cm->setupContactsProvider($contactsManager, $userID, $urlGenerator);
|
$context->getServerContainer()
|
||||||
|
);
|
||||||
|
$this->registerContactsManager(
|
||||||
|
$context->getAppContainer()->query(IContactsManager::class),
|
||||||
|
$context->getAppContainer()
|
||||||
|
);
|
||||||
|
$this->registerCalendarManager(
|
||||||
|
$context->getAppContainer()->query(ICalendarManager::class),
|
||||||
|
$context->getAppContainer()
|
||||||
|
);
|
||||||
|
$this->registerNotifier(
|
||||||
|
$context->getServerContainer()->getNotificationManager()
|
||||||
|
);
|
||||||
|
$this->registerCalendarReminders(
|
||||||
|
$context->getAppContainer()->query(NotificationProviderManager::class),
|
||||||
|
$context->getAppContainer()->query(ILogger::class)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function registerHooks(HookManager $hm,
|
||||||
* @param IContactsManager $contactsManager
|
EventDispatcherInterface $dispatcher,
|
||||||
*/
|
IAppContainer $container,
|
||||||
public function setupSystemContactsProvider(IContactsManager $contactsManager) {
|
IServerContainer $serverContainer) {
|
||||||
/** @var ContactsManager $cm */
|
|
||||||
$cm = $this->getContainer()->query(ContactsManager::class);
|
|
||||||
$urlGenerator = $this->getContainer()->getServer()->getURLGenerator();
|
|
||||||
$cm->setupSystemContactsProvider($contactsManager, $urlGenerator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param ICalendarManager $calendarManager
|
|
||||||
* @param string $userId
|
|
||||||
*/
|
|
||||||
public function setupCalendarProvider(ICalendarManager $calendarManager, $userId) {
|
|
||||||
$cm = $this->getContainer()->query(CalendarManager::class);
|
|
||||||
$cm->setupCalendarProvider($calendarManager, $userId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function registerHooks() {
|
|
||||||
/** @var HookManager $hm */
|
|
||||||
$hm = $this->getContainer()->query(HookManager::class);
|
|
||||||
$hm->setup();
|
$hm->setup();
|
||||||
|
|
||||||
$dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
|
|
||||||
|
|
||||||
// first time login event setup
|
// first time login event setup
|
||||||
$dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) {
|
$dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) {
|
||||||
if ($event instanceof GenericEvent) {
|
if ($event instanceof GenericEvent) {
|
||||||
|
@ -123,35 +141,35 @@ class Application extends App {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$birthdayListener = function ($event) {
|
$birthdayListener = function ($event) use ($container) {
|
||||||
if ($event instanceof GenericEvent) {
|
if ($event instanceof GenericEvent) {
|
||||||
/** @var BirthdayService $b */
|
/** @var BirthdayService $b */
|
||||||
$b = $this->getContainer()->query(BirthdayService::class);
|
$b = $container->query(BirthdayService::class);
|
||||||
$b->onCardChanged(
|
$b->onCardChanged(
|
||||||
$event->getArgument('addressBookId'),
|
(int) $event->getArgument('addressBookId'),
|
||||||
$event->getArgument('cardUri'),
|
(string) $event->getArgument('cardUri'),
|
||||||
$event->getArgument('cardData')
|
(string) $event->getArgument('cardData')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $birthdayListener);
|
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $birthdayListener);
|
||||||
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $birthdayListener);
|
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $birthdayListener);
|
||||||
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function ($event) {
|
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function ($event) use ($container) {
|
||||||
if ($event instanceof GenericEvent) {
|
if ($event instanceof GenericEvent) {
|
||||||
/** @var BirthdayService $b */
|
/** @var BirthdayService $b */
|
||||||
$b = $this->getContainer()->query(BirthdayService::class);
|
$b = $container->query(BirthdayService::class);
|
||||||
$b->onCardDeleted(
|
$b->onCardDeleted(
|
||||||
$event->getArgument('addressBookId'),
|
(int) $event->getArgument('addressBookId'),
|
||||||
$event->getArgument('cardUri')
|
(string) $event->getArgument('cardUri')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$clearPhotoCache = function ($event) {
|
$clearPhotoCache = function ($event) use ($container) {
|
||||||
if ($event instanceof GenericEvent) {
|
if ($event instanceof GenericEvent) {
|
||||||
/** @var PhotoCache $p */
|
/** @var PhotoCache $p */
|
||||||
$p = $this->getContainer()->query(PhotoCache::class);
|
$p = $container->query(PhotoCache::class);
|
||||||
$p->delete(
|
$p->delete(
|
||||||
$event->getArgument('addressBookId'),
|
$event->getArgument('addressBookId'),
|
||||||
$event->getArgument('cardUri')
|
$event->getArgument('cardUri')
|
||||||
|
@ -161,44 +179,46 @@ class Application extends App {
|
||||||
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache);
|
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache);
|
||||||
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache);
|
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache);
|
||||||
|
|
||||||
$dispatcher->addListener('OC\AccountManager::userUpdated', function (GenericEvent $event) {
|
$dispatcher->addListener('OC\AccountManager::userUpdated', function (GenericEvent $event) use ($container) {
|
||||||
$user = $event->getSubject();
|
$user = $event->getSubject();
|
||||||
$syncService = $this->getContainer()->query(SyncService::class);
|
/** @var SyncService $syncService */
|
||||||
|
$syncService = $container->query(SyncService::class);
|
||||||
$syncService->updateUser($user);
|
$syncService->updateUser($user);
|
||||||
});
|
});
|
||||||
|
|
||||||
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function (GenericEvent $event) {
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function (GenericEvent $event) use ($container) {
|
||||||
/** @var Backend $backend */
|
/** @var Backend $backend */
|
||||||
$backend = $this->getContainer()->query(Backend::class);
|
$backend = $container->query(Backend::class);
|
||||||
$backend->onCalendarAdd(
|
$backend->onCalendarAdd(
|
||||||
$event->getArgument('calendarData')
|
$event->getArgument('calendarData')
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function (GenericEvent $event) {
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function (GenericEvent $event) use ($container) {
|
||||||
/** @var Backend $backend */
|
/** @var Backend $backend */
|
||||||
$backend = $this->getContainer()->query(Backend::class);
|
$backend = $container->query(Backend::class);
|
||||||
$backend->onCalendarUpdate(
|
$backend->onCalendarUpdate(
|
||||||
$event->getArgument('calendarData'),
|
$event->getArgument('calendarData'),
|
||||||
$event->getArgument('shares'),
|
$event->getArgument('shares'),
|
||||||
$event->getArgument('propertyMutations')
|
$event->getArgument('propertyMutations')
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function (GenericEvent $event) {
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function (GenericEvent $event) use ($container) {
|
||||||
/** @var Backend $backend */
|
/** @var Backend $backend */
|
||||||
$backend = $this->getContainer()->query(Backend::class);
|
$backend = $container->query(Backend::class);
|
||||||
$backend->onCalendarDelete(
|
$backend->onCalendarDelete(
|
||||||
$event->getArgument('calendarData'),
|
$event->getArgument('calendarData'),
|
||||||
$event->getArgument('shares')
|
$event->getArgument('shares')
|
||||||
);
|
);
|
||||||
|
|
||||||
$reminderBackend = $this->getContainer()->query(ReminderBackend::class);
|
/** @var ReminderBackend $reminderBackend */
|
||||||
|
$reminderBackend = $container->query(ReminderBackend::class);
|
||||||
$reminderBackend->cleanRemindersForCalendar(
|
$reminderBackend->cleanRemindersForCalendar(
|
||||||
$event->getArgument('calendarId')
|
(int) $event->getArgument('calendarId')
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function (GenericEvent $event) {
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function (GenericEvent $event) use ($container) {
|
||||||
/** @var Backend $backend */
|
/** @var Backend $backend */
|
||||||
$backend = $this->getContainer()->query(Backend::class);
|
$backend = $container->query(Backend::class);
|
||||||
$backend->onCalendarUpdateShares(
|
$backend->onCalendarUpdateShares(
|
||||||
$event->getArgument('calendarData'),
|
$event->getArgument('calendarData'),
|
||||||
$event->getArgument('shares'),
|
$event->getArgument('shares'),
|
||||||
|
@ -209,18 +229,18 @@ class Application extends App {
|
||||||
// Here we should recalculate if reminders should be sent to new or old sharees
|
// Here we should recalculate if reminders should be sent to new or old sharees
|
||||||
});
|
});
|
||||||
|
|
||||||
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::publishCalendar', function (GenericEvent $event) {
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::publishCalendar', function (GenericEvent $event) use ($container) {
|
||||||
/** @var Backend $backend */
|
/** @var Backend $backend */
|
||||||
$backend = $this->getContainer()->query(Backend::class);
|
$backend = $container->query(Backend::class);
|
||||||
$backend->onCalendarPublication(
|
$backend->onCalendarPublication(
|
||||||
$event->getArgument('calendarData'),
|
$event->getArgument('calendarData'),
|
||||||
$event->getArgument('public')
|
$event->getArgument('public')
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
$listener = function (GenericEvent $event, $eventName) {
|
$listener = function (GenericEvent $event, $eventName) use ($container) {
|
||||||
/** @var Backend $backend */
|
/** @var Backend $backend */
|
||||||
$backend = $this->getContainer()->query(Backend::class);
|
$backend = $container->query(Backend::class);
|
||||||
|
|
||||||
$subject = Event::SUBJECT_OBJECT_ADD;
|
$subject = Event::SUBJECT_OBJECT_ADD;
|
||||||
if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') {
|
if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') {
|
||||||
|
@ -236,7 +256,7 @@ class Application extends App {
|
||||||
);
|
);
|
||||||
|
|
||||||
/** @var ReminderService $reminderBackend */
|
/** @var ReminderService $reminderBackend */
|
||||||
$reminderService = $this->getContainer()->query(ReminderService::class);
|
$reminderService = $container->query(ReminderService::class);
|
||||||
|
|
||||||
$reminderService->onTouchCalendarObject(
|
$reminderService->onTouchCalendarObject(
|
||||||
$eventName,
|
$eventName,
|
||||||
|
@ -250,9 +270,9 @@ class Application extends App {
|
||||||
/**
|
/**
|
||||||
* In case the user has set their default calendar to this one
|
* In case the user has set their default calendar to this one
|
||||||
*/
|
*/
|
||||||
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function (GenericEvent $event) {
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function (GenericEvent $event) use ($serverContainer) {
|
||||||
/** @var IConfig $config */
|
/** @var IConfig $config */
|
||||||
$config = $this->getContainer()->getServer()->getConfig();
|
$config = $serverContainer->getConfig();
|
||||||
$principalUri = $event->getArgument('calendarData')['principaluri'];
|
$principalUri = $event->getArgument('calendarData')['principaluri'];
|
||||||
if (strpos($principalUri, 'principals/users') === 0) {
|
if (strpos($principalUri, 'principals/users') === 0) {
|
||||||
list(, $UID) = \Sabre\Uri\split($principalUri);
|
list(, $UID) = \Sabre\Uri\split($principalUri);
|
||||||
|
@ -262,28 +282,130 @@ class Application extends App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$dispatcher->addListener('OCP\Federation\TrustedServerEvent::remove',
|
||||||
|
function (GenericEvent $event) {
|
||||||
|
/** @var CardDavBackend $cardDavBackend */
|
||||||
|
$cardDavBackend = \OC::$server->query(CardDavBackend::class);
|
||||||
|
$addressBookUri = $event->getSubject();
|
||||||
|
$addressBook = $cardDavBackend->getAddressBooksByUri('principals/system/system', $addressBookUri);
|
||||||
|
if (!is_null($addressBook)) {
|
||||||
|
$cardDavBackend->deleteAddressBook($addressBook['id']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createSubscription',
|
||||||
|
function (GenericEvent $event) use ($container, $serverContainer) {
|
||||||
|
$jobList = $serverContainer->getJobList();
|
||||||
|
$subscriptionData = $event->getArgument('subscriptionData');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initial subscription refetch
|
||||||
|
*
|
||||||
|
* @var RefreshWebcalService $refreshWebcalService
|
||||||
|
*/
|
||||||
|
$refreshWebcalService = $container->query(RefreshWebcalService::class);
|
||||||
|
$refreshWebcalService->refreshSubscription(
|
||||||
|
(string) $subscriptionData['principaluri'],
|
||||||
|
(string) $subscriptionData['uri']
|
||||||
|
);
|
||||||
|
|
||||||
|
$jobList->add(\OCA\DAV\BackgroundJob\RefreshWebcalJob::class, [
|
||||||
|
'principaluri' => $subscriptionData['principaluri'],
|
||||||
|
'uri' => $subscriptionData['uri']
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteSubscription',
|
||||||
|
function (GenericEvent $event) use ($container, $serverContainer) {
|
||||||
|
$jobList = $serverContainer->getJobList();
|
||||||
|
$subscriptionData = $event->getArgument('subscriptionData');
|
||||||
|
|
||||||
|
$jobList->remove(\OCA\DAV\BackgroundJob\RefreshWebcalJob::class, [
|
||||||
|
'principaluri' => $subscriptionData['principaluri'],
|
||||||
|
'uri' => $subscriptionData['uri']
|
||||||
|
]);
|
||||||
|
|
||||||
|
/** @var CalDavBackend $calDavBackend */
|
||||||
|
$calDavBackend = $container->query(CalDavBackend::class);
|
||||||
|
$calDavBackend->purgeAllCachedEventsForSubscription($subscriptionData['id']);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
$eventHandler = function () use ($container, $serverContainer) {
|
||||||
|
try {
|
||||||
|
/** @var UpdateCalendarResourcesRoomsBackgroundJob $job */
|
||||||
|
$job = $container->query(UpdateCalendarResourcesRoomsBackgroundJob::class);
|
||||||
|
$job->run([]);
|
||||||
|
$serverContainer->getJobList()->setLastRun($job);
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
$serverContainer->getLogger()->logException($ex);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$dispatcher->addListener('\OCP\Calendar\Resource\ForceRefreshEvent', $eventHandler);
|
||||||
|
$dispatcher->addListener('\OCP\Calendar\Room\ForceRefreshEvent', $eventHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSyncService() {
|
private function registerContactsManager(IContactsManager $cm, IAppContainer $container): void {
|
||||||
return $this->getContainer()->query(SyncService::class);
|
$cm->register(function () use ($container, $cm): void {
|
||||||
|
$user = \OC::$server->getUserSession()->getUser();
|
||||||
|
if (!is_null($user)) {
|
||||||
|
$this->setupContactsProvider($cm, $container, $user->getUID());
|
||||||
|
} else {
|
||||||
|
$this->setupSystemContactsProvider($cm, $container);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function registerNotifier():void {
|
private function setupContactsProvider(IContactsManager $contactsManager,
|
||||||
$this->getContainer()
|
IAppContainer $container,
|
||||||
->getServer()
|
string $userID): void {
|
||||||
->getNotificationManager()
|
/** @var ContactsManager $cm */
|
||||||
->registerNotifierService(Notifier::class);
|
$cm = $container->query(ContactsManager::class);
|
||||||
|
$urlGenerator = $container->getServer()->getURLGenerator();
|
||||||
|
$cm->setupContactsProvider($contactsManager, $userID, $urlGenerator);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function registerCalendarReminders():void {
|
private function setupSystemContactsProvider(IContactsManager $contactsManager,
|
||||||
|
IAppContainer $container): void {
|
||||||
|
/** @var ContactsManager $cm */
|
||||||
|
$cm = $container->query(ContactsManager::class);
|
||||||
|
$urlGenerator = $container->getServer()->getURLGenerator();
|
||||||
|
$cm->setupSystemContactsProvider($contactsManager, $urlGenerator);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function registerCalendarManager(ICalendarManager $calendarManager,
|
||||||
|
IAppContainer $container): void {
|
||||||
|
$calendarManager->register(function () use ($container, $calendarManager) {
|
||||||
|
$user = \OC::$server->getUserSession()->getUser();
|
||||||
|
if ($user !== null) {
|
||||||
|
$this->setupCalendarProvider($calendarManager, $container, $user->getUID());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function setupCalendarProvider(ICalendarManager $calendarManager,
|
||||||
|
IAppContainer $container,
|
||||||
|
$userId) {
|
||||||
|
$cm = $container->query(CalendarManager::class);
|
||||||
|
$cm->setupCalendarProvider($calendarManager, $userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function registerNotifier(INotificationManager $manager): void {
|
||||||
|
$manager->registerNotifierService(Notifier::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function registerCalendarReminders(NotificationProviderManager $manager,
|
||||||
|
ILogger $logger): void {
|
||||||
try {
|
try {
|
||||||
/** @var NotificationProviderManager $notificationProviderManager */
|
$manager->registerProvider(AudioProvider::class);
|
||||||
$notificationProviderManager = $this->getContainer()->query(NotificationProviderManager::class);
|
$manager->registerProvider(EmailProvider::class);
|
||||||
$notificationProviderManager->registerProvider(AudioProvider::class);
|
$manager->registerProvider(PushProvider::class);
|
||||||
$notificationProviderManager->registerProvider(EmailProvider::class);
|
} catch (Throwable $ex) {
|
||||||
$notificationProviderManager->registerProvider(PushProvider::class);
|
$logger->logException($ex);
|
||||||
} catch (\Exception $ex) {
|
|
||||||
$this->getContainer()->getServer()->getLogger()->logException($ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue