2016-01-11 16:34:17 +03:00
|
|
|
<?php
|
2020-06-18 14:28:22 +03:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-01-12 17:02:16 +03:00
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Bjoern Schiessle <bjoern@schiessle.org>
|
2020-04-29 12:57:22 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2017-11-06 22:15:27 +03:00
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Thomas Citharel <nextcloud@tcit.fr>
|
2016-01-12 17:02:16 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Tobia De Koninck <tobia@ledfan.be>
|
2016-01-12 17:02:16 +03:00
|
|
|
*
|
|
|
|
* @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,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2016-01-12 17:02:16 +03:00
|
|
|
*
|
|
|
|
*/
|
2019-11-22 22:52:10 +03:00
|
|
|
|
2016-05-12 10:42:40 +03:00
|
|
|
namespace OCA\DAV\AppInfo;
|
2016-01-11 16:34:17 +03:00
|
|
|
|
2020-06-18 14:28:22 +03:00
|
|
|
use Exception;
|
|
|
|
use OCA\DAV\BackgroundJob\UpdateCalendarResourcesRoomsBackgroundJob;
|
2016-10-13 16:34:26 +03:00
|
|
|
use OCA\DAV\CalDAV\Activity\Backend;
|
2016-11-29 18:21:36 +03:00
|
|
|
use OCA\DAV\CalDAV\Activity\Provider\Event;
|
2016-02-03 17:43:45 +03:00
|
|
|
use OCA\DAV\CalDAV\BirthdayService;
|
2020-06-18 14:28:22 +03:00
|
|
|
use OCA\DAV\CalDAV\CalDavBackend;
|
2017-11-07 03:31:28 +03:00
|
|
|
use OCA\DAV\CalDAV\CalendarManager;
|
2019-03-16 18:19:25 +03:00
|
|
|
use OCA\DAV\CalDAV\Reminder\Backend as ReminderBackend;
|
2019-08-02 17:49:53 +03:00
|
|
|
use OCA\DAV\CalDAV\Reminder\NotificationProvider\AudioProvider;
|
2019-03-16 18:19:25 +03:00
|
|
|
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;
|
2020-06-18 14:28:22 +03:00
|
|
|
use OCA\DAV\CalDAV\WebcalCaching\RefreshWebcalService;
|
2016-10-21 12:45:17 +03:00
|
|
|
use OCA\DAV\Capabilities;
|
2020-06-18 14:28:22 +03:00
|
|
|
use OCA\DAV\CardDAV\CardDavBackend;
|
2016-01-11 16:34:17 +03:00
|
|
|
use OCA\DAV\CardDAV\ContactsManager;
|
2017-05-03 15:22:02 +03:00
|
|
|
use OCA\DAV\CardDAV\PhotoCache;
|
2016-01-13 22:56:25 +03:00
|
|
|
use OCA\DAV\CardDAV\SyncService;
|
|
|
|
use OCA\DAV\HookManager;
|
2020-07-24 15:57:52 +03:00
|
|
|
use OCA\DAV\Search\ContactsSearchProvider;
|
2020-07-27 17:14:15 +03:00
|
|
|
use OCA\DAV\Search\EventsSearchProvider;
|
|
|
|
use OCA\DAV\Search\TasksSearchProvider;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\AppFramework\App;
|
2020-06-18 14:28:22 +03:00
|
|
|
use OCP\AppFramework\Bootstrap\IBootContext;
|
|
|
|
use OCP\AppFramework\Bootstrap\IBootstrap;
|
|
|
|
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
|
|
|
use OCP\AppFramework\IAppContainer;
|
2017-11-07 03:31:28 +03:00
|
|
|
use OCP\Calendar\IManager as ICalendarManager;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\Contacts\IManager as IContactsManager;
|
2020-03-08 19:33:27 +03:00
|
|
|
use OCP\IConfig;
|
2020-06-18 14:28:22 +03:00
|
|
|
use OCP\ILogger;
|
|
|
|
use OCP\IServerContainer;
|
2016-09-23 18:21:07 +03:00
|
|
|
use OCP\IUser;
|
2020-06-18 14:28:22 +03:00
|
|
|
use OCP\Notification\IManager as INotificationManager;
|
2020-07-16 11:24:12 +03:00
|
|
|
use Psr\Container\ContainerInterface;
|
2020-06-18 14:28:22 +03:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
2016-02-03 17:43:45 +03:00
|
|
|
use Symfony\Component\EventDispatcher\GenericEvent;
|
2020-06-18 14:28:22 +03:00
|
|
|
use Throwable;
|
|
|
|
use function is_null;
|
|
|
|
use function strpos;
|
2016-01-11 16:34:17 +03:00
|
|
|
|
2020-06-18 14:28:22 +03:00
|
|
|
class Application extends App implements IBootstrap {
|
2020-04-10 17:54:27 +03:00
|
|
|
public const APP_ID = 'dav';
|
2019-03-16 18:19:25 +03:00
|
|
|
|
2016-09-20 02:15:24 +03:00
|
|
|
public function __construct() {
|
2020-06-18 14:28:22 +03:00
|
|
|
parent::__construct(self::APP_ID);
|
|
|
|
}
|
2016-10-21 12:45:17 +03:00
|
|
|
|
2020-06-18 14:28:22 +03:00
|
|
|
public function register(IRegistrationContext $context): void {
|
|
|
|
$context->registerServiceAlias('CardDAVSyncService', SyncService::class);
|
2020-07-16 11:24:12 +03:00
|
|
|
$context->registerService(PhotoCache::class, function (ContainerInterface $c) {
|
2020-06-18 14:28:22 +03:00
|
|
|
/** @var IServerContainer $server */
|
2020-07-16 11:24:12 +03:00
|
|
|
$server = $c->get(IServerContainer::class);
|
2017-05-03 15:22:02 +03:00
|
|
|
|
|
|
|
return new PhotoCache(
|
2018-12-17 19:28:19 +03:00
|
|
|
$server->getAppDataDir('dav-photocache'),
|
2020-07-16 11:24:12 +03:00
|
|
|
$c->get(ILogger::class)
|
2017-05-03 15:22:02 +03:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2016-10-21 12:45:17 +03:00
|
|
|
/*
|
|
|
|
* Register capabilities
|
|
|
|
*/
|
2020-06-18 14:28:22 +03:00
|
|
|
$context->registerCapability(Capabilities::class);
|
2020-07-24 15:57:52 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Register Search Providers
|
|
|
|
*/
|
|
|
|
$context->registerSearchProvider(ContactsSearchProvider::class);
|
2020-07-27 17:14:15 +03:00
|
|
|
$context->registerSearchProvider(EventsSearchProvider::class);
|
|
|
|
$context->registerSearchProvider(TasksSearchProvider::class);
|
2016-01-11 16:34:17 +03:00
|
|
|
}
|
|
|
|
|
2020-06-18 14:28:22 +03:00
|
|
|
public function boot(IBootContext $context): void {
|
|
|
|
// Load all dav apps
|
|
|
|
\OC_App::loadApps(['dav']);
|
2016-01-11 16:34:17 +03:00
|
|
|
|
2020-06-29 17:04:17 +03:00
|
|
|
$context->injectFn([$this, 'registerHooks']);
|
|
|
|
$context->injectFn([$this, 'registerContactsManager']);
|
|
|
|
$context->injectFn([$this, 'registerCalendarManager']);
|
|
|
|
$context->injectFn([$this, 'registerNotifier']);
|
|
|
|
$context->injectFn([$this, 'registerCalendarReminders']);
|
2017-09-16 14:42:46 +03:00
|
|
|
}
|
|
|
|
|
2020-06-29 17:04:17 +03:00
|
|
|
public function registerHooks(HookManager $hm,
|
2020-06-18 14:28:22 +03:00
|
|
|
EventDispatcherInterface $dispatcher,
|
|
|
|
IAppContainer $container,
|
|
|
|
IServerContainer $serverContainer) {
|
2016-01-13 22:56:25 +03:00
|
|
|
$hm->setup();
|
2016-02-03 17:43:45 +03:00
|
|
|
|
2016-09-23 18:21:07 +03:00
|
|
|
// first time login event setup
|
|
|
|
$dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) {
|
|
|
|
if ($event instanceof GenericEvent) {
|
|
|
|
$hm->firstLogin($event->getSubject());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-06-18 14:28:22 +03:00
|
|
|
$birthdayListener = function ($event) use ($container) {
|
2016-02-03 17:43:45 +03:00
|
|
|
if ($event instanceof GenericEvent) {
|
2016-03-23 14:28:54 +03:00
|
|
|
/** @var BirthdayService $b */
|
2020-06-18 14:28:22 +03:00
|
|
|
$b = $container->query(BirthdayService::class);
|
2016-02-03 17:43:45 +03:00
|
|
|
$b->onCardChanged(
|
2020-06-18 14:28:22 +03:00
|
|
|
(int) $event->getArgument('addressBookId'),
|
|
|
|
(string) $event->getArgument('cardUri'),
|
|
|
|
(string) $event->getArgument('cardData')
|
2016-02-03 17:43:45 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-03-16 18:19:25 +03:00
|
|
|
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $birthdayListener);
|
|
|
|
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $birthdayListener);
|
2020-06-18 14:28:22 +03:00
|
|
|
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function ($event) use ($container) {
|
2016-02-03 17:43:45 +03:00
|
|
|
if ($event instanceof GenericEvent) {
|
2016-03-23 14:28:54 +03:00
|
|
|
/** @var BirthdayService $b */
|
2020-06-18 14:28:22 +03:00
|
|
|
$b = $container->query(BirthdayService::class);
|
2016-02-03 17:43:45 +03:00
|
|
|
$b->onCardDeleted(
|
2020-06-18 14:28:22 +03:00
|
|
|
(int) $event->getArgument('addressBookId'),
|
|
|
|
(string) $event->getArgument('cardUri')
|
2016-02-03 17:43:45 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2016-09-26 14:50:39 +03:00
|
|
|
|
2020-06-18 14:28:22 +03:00
|
|
|
$clearPhotoCache = function ($event) use ($container) {
|
2017-05-03 16:11:26 +03:00
|
|
|
if ($event instanceof GenericEvent) {
|
|
|
|
/** @var PhotoCache $p */
|
2020-06-18 14:28:22 +03:00
|
|
|
$p = $container->query(PhotoCache::class);
|
2017-05-03 16:11:26 +03:00
|
|
|
$p->delete(
|
|
|
|
$event->getArgument('addressBookId'),
|
|
|
|
$event->getArgument('cardUri')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache);
|
|
|
|
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache);
|
|
|
|
|
2020-06-18 14:28:22 +03:00
|
|
|
$dispatcher->addListener('OC\AccountManager::userUpdated', function (GenericEvent $event) use ($container) {
|
2016-11-11 16:36:17 +03:00
|
|
|
$user = $event->getSubject();
|
2020-06-18 14:28:22 +03:00
|
|
|
/** @var SyncService $syncService */
|
|
|
|
$syncService = $container->query(SyncService::class);
|
2016-11-11 16:36:17 +03:00
|
|
|
$syncService->updateUser($user);
|
|
|
|
});
|
|
|
|
|
2020-06-18 14:28:22 +03:00
|
|
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function (GenericEvent $event) use ($container) {
|
2016-10-13 16:34:26 +03:00
|
|
|
/** @var Backend $backend */
|
2020-06-18 14:28:22 +03:00
|
|
|
$backend = $container->query(Backend::class);
|
2016-10-13 16:34:26 +03:00
|
|
|
$backend->onCalendarAdd(
|
|
|
|
$event->getArgument('calendarData')
|
|
|
|
);
|
|
|
|
});
|
2020-06-18 14:28:22 +03:00
|
|
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function (GenericEvent $event) use ($container) {
|
2016-10-13 16:34:26 +03:00
|
|
|
/** @var Backend $backend */
|
2020-06-18 14:28:22 +03:00
|
|
|
$backend = $container->query(Backend::class);
|
2016-10-13 16:34:26 +03:00
|
|
|
$backend->onCalendarUpdate(
|
|
|
|
$event->getArgument('calendarData'),
|
|
|
|
$event->getArgument('shares'),
|
|
|
|
$event->getArgument('propertyMutations')
|
|
|
|
);
|
|
|
|
});
|
2020-06-18 14:28:22 +03:00
|
|
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function (GenericEvent $event) use ($container) {
|
2016-10-13 16:34:26 +03:00
|
|
|
/** @var Backend $backend */
|
2020-06-18 14:28:22 +03:00
|
|
|
$backend = $container->query(Backend::class);
|
2016-10-13 16:34:26 +03:00
|
|
|
$backend->onCalendarDelete(
|
|
|
|
$event->getArgument('calendarData'),
|
|
|
|
$event->getArgument('shares')
|
|
|
|
);
|
2019-03-16 18:19:25 +03:00
|
|
|
|
2020-06-18 14:28:22 +03:00
|
|
|
/** @var ReminderBackend $reminderBackend */
|
|
|
|
$reminderBackend = $container->query(ReminderBackend::class);
|
2019-03-16 18:19:25 +03:00
|
|
|
$reminderBackend->cleanRemindersForCalendar(
|
2020-06-18 14:28:22 +03:00
|
|
|
(int) $event->getArgument('calendarId')
|
2019-03-16 18:19:25 +03:00
|
|
|
);
|
2016-10-13 16:34:26 +03:00
|
|
|
});
|
2020-06-18 14:28:22 +03:00
|
|
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function (GenericEvent $event) use ($container) {
|
2016-10-13 16:34:26 +03:00
|
|
|
/** @var Backend $backend */
|
2020-06-18 14:28:22 +03:00
|
|
|
$backend = $container->query(Backend::class);
|
2016-10-13 16:34:26 +03:00
|
|
|
$backend->onCalendarUpdateShares(
|
|
|
|
$event->getArgument('calendarData'),
|
|
|
|
$event->getArgument('shares'),
|
|
|
|
$event->getArgument('add'),
|
|
|
|
$event->getArgument('remove')
|
|
|
|
);
|
2019-03-16 18:19:25 +03:00
|
|
|
|
|
|
|
// Here we should recalculate if reminders should be sent to new or old sharees
|
2017-09-20 18:33:51 +03:00
|
|
|
});
|
|
|
|
|
2020-06-18 14:28:22 +03:00
|
|
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::publishCalendar', function (GenericEvent $event) use ($container) {
|
2017-09-20 18:33:51 +03:00
|
|
|
/** @var Backend $backend */
|
2020-06-18 14:28:22 +03:00
|
|
|
$backend = $container->query(Backend::class);
|
2017-09-20 18:33:51 +03:00
|
|
|
$backend->onCalendarPublication(
|
|
|
|
$event->getArgument('calendarData'),
|
|
|
|
$event->getArgument('public')
|
|
|
|
);
|
2016-10-13 16:34:26 +03:00
|
|
|
});
|
|
|
|
|
2020-06-18 14:28:22 +03:00
|
|
|
$listener = function (GenericEvent $event, $eventName) use ($container) {
|
2016-10-13 16:34:26 +03:00
|
|
|
/** @var Backend $backend */
|
2020-06-18 14:28:22 +03:00
|
|
|
$backend = $container->query(Backend::class);
|
2016-10-13 16:34:26 +03:00
|
|
|
|
2016-11-29 18:21:36 +03:00
|
|
|
$subject = Event::SUBJECT_OBJECT_ADD;
|
2016-10-13 16:34:26 +03:00
|
|
|
if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') {
|
2016-11-29 18:21:36 +03:00
|
|
|
$subject = Event::SUBJECT_OBJECT_UPDATE;
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') {
|
2016-11-29 18:21:36 +03:00
|
|
|
$subject = Event::SUBJECT_OBJECT_DELETE;
|
2016-10-13 16:34:26 +03:00
|
|
|
}
|
|
|
|
$backend->onTouchCalendarObject(
|
|
|
|
$subject,
|
|
|
|
$event->getArgument('calendarData'),
|
|
|
|
$event->getArgument('shares'),
|
|
|
|
$event->getArgument('objectData')
|
|
|
|
);
|
2019-03-16 18:19:25 +03:00
|
|
|
|
|
|
|
/** @var ReminderService $reminderBackend */
|
2020-06-18 14:28:22 +03:00
|
|
|
$reminderService = $container->query(ReminderService::class);
|
2019-03-16 18:19:25 +03:00
|
|
|
|
|
|
|
$reminderService->onTouchCalendarObject(
|
|
|
|
$eventName,
|
|
|
|
$event->getArgument('objectData')
|
|
|
|
);
|
2016-10-13 16:34:26 +03: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);
|
2020-03-08 19:33:27 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* In case the user has set their default calendar to this one
|
|
|
|
*/
|
2020-06-18 14:28:22 +03:00
|
|
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function (GenericEvent $event) use ($serverContainer) {
|
2020-03-08 19:33:27 +03:00
|
|
|
/** @var IConfig $config */
|
2020-06-18 14:28:22 +03:00
|
|
|
$config = $serverContainer->getConfig();
|
2020-03-08 19:33:27 +03:00
|
|
|
$principalUri = $event->getArgument('calendarData')['principaluri'];
|
|
|
|
if (strpos($principalUri, 'principals/users') === 0) {
|
|
|
|
list(, $UID) = \Sabre\Uri\split($principalUri);
|
2020-04-05 21:57:26 +03:00
|
|
|
$uri = $event->getArgument('calendarData')['uri'];
|
|
|
|
if ($config->getUserValue($UID, 'dav', 'defaultCalendar') === $uri) {
|
|
|
|
$config->deleteUserValue($UID, 'dav', 'defaultCalendar');
|
|
|
|
}
|
2020-03-08 19:33:27 +03:00
|
|
|
}
|
|
|
|
});
|
2020-06-18 14:28:22 +03:00
|
|
|
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
2020-06-29 17:04:17 +03:00
|
|
|
public function registerContactsManager(IContactsManager $cm, IAppContainer $container): void {
|
2020-06-18 14:28:22 +03:00
|
|
|
$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);
|
|
|
|
}
|
|
|
|
});
|
2016-01-13 22:56:25 +03:00
|
|
|
}
|
|
|
|
|
2020-06-18 14:28:22 +03:00
|
|
|
private function setupContactsProvider(IContactsManager $contactsManager,
|
|
|
|
IAppContainer $container,
|
|
|
|
string $userID): void {
|
|
|
|
/** @var ContactsManager $cm */
|
|
|
|
$cm = $container->query(ContactsManager::class);
|
|
|
|
$urlGenerator = $container->getServer()->getURLGenerator();
|
|
|
|
$cm->setupContactsProvider($contactsManager, $userID, $urlGenerator);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function setupSystemContactsProvider(IContactsManager $contactsManager,
|
|
|
|
IAppContainer $container): void {
|
|
|
|
/** @var ContactsManager $cm */
|
|
|
|
$cm = $container->query(ContactsManager::class);
|
|
|
|
$urlGenerator = $container->getServer()->getURLGenerator();
|
|
|
|
$cm->setupSystemContactsProvider($contactsManager, $urlGenerator);
|
|
|
|
}
|
|
|
|
|
2020-06-29 17:04:17 +03:00
|
|
|
public function registerCalendarManager(ICalendarManager $calendarManager,
|
2020-06-18 14:28:22 +03:00
|
|
|
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);
|
2016-01-13 22:56:25 +03:00
|
|
|
}
|
|
|
|
|
2020-06-29 17:04:17 +03:00
|
|
|
public function registerNotifier(INotificationManager $manager): void {
|
2020-06-18 14:28:22 +03:00
|
|
|
$manager->registerNotifierService(Notifier::class);
|
2019-03-16 18:19:25 +03:00
|
|
|
}
|
|
|
|
|
2020-06-29 17:04:17 +03:00
|
|
|
public function registerCalendarReminders(NotificationProviderManager $manager,
|
2020-06-18 14:28:22 +03:00
|
|
|
ILogger $logger): void {
|
2019-03-16 18:19:25 +03:00
|
|
|
try {
|
2020-06-18 14:28:22 +03:00
|
|
|
$manager->registerProvider(AudioProvider::class);
|
|
|
|
$manager->registerProvider(EmailProvider::class);
|
|
|
|
$manager->registerProvider(PushProvider::class);
|
|
|
|
} catch (Throwable $ex) {
|
|
|
|
$logger->logException($ex);
|
2019-03-16 18:19:25 +03:00
|
|
|
}
|
|
|
|
}
|
2016-01-11 16:34:17 +03:00
|
|
|
}
|