You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

app.php 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Georg Ehrke <oc.list@georgehrke.com>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Julius Härtl <jus@bitgrid.net>
  10. * @author Lukas Reschke <lukas@statuscode.ch>
  11. * @author Thomas Citharel <nextcloud@tcit.fr>
  12. * @author Thomas Müller <thomas.mueller@tmit.eu>
  13. * @author Tobia De Koninck <tobia@ledfan.be>
  14. *
  15. * @license AGPL-3.0
  16. *
  17. * This code is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License, version 3,
  19. * as published by the Free Software Foundation.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License, version 3,
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>
  28. *
  29. */
  30. use OCA\DAV\AppInfo\Application;
  31. use OCA\DAV\CalDAV\WebcalCaching\RefreshWebcalService;
  32. use OCA\DAV\CardDAV\CardDavBackend;
  33. use Symfony\Component\EventDispatcher\GenericEvent;
  34. \OC_App::loadApps(['dav']);
  35. /** @var Application $app */
  36. $app = \OC::$server->query(Application::class);
  37. $app->registerHooks();
  38. \OC::$server->registerService('CardDAVSyncService', function() use ($app) {
  39. return $app->getSyncService();
  40. });
  41. $eventDispatcher = \OC::$server->getEventDispatcher();
  42. $eventDispatcher->addListener('OCP\Federation\TrustedServerEvent::remove',
  43. function(GenericEvent $event) use ($app) {
  44. /** @var CardDavBackend $cardDavBackend */
  45. $cardDavBackend = $app->getContainer()->query(CardDavBackend::class);
  46. $addressBookUri = $event->getSubject();
  47. $addressBook = $cardDavBackend->getAddressBooksByUri('principals/system/system', $addressBookUri);
  48. if (!is_null($addressBook)) {
  49. $cardDavBackend->deleteAddressBook($addressBook['id']);
  50. }
  51. }
  52. );
  53. $eventDispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createSubscription',
  54. function(GenericEvent $event) use ($app) {
  55. $jobList = $app->getContainer()->getServer()->getJobList();
  56. $subscriptionData = $event->getArgument('subscriptionData');
  57. /**
  58. * Initial subscription refetch
  59. * @var RefreshWebcalService $refreshWebcalService
  60. */
  61. $refreshWebcalService = $app->getContainer()->query(RefreshWebcalService::class);
  62. $refreshWebcalService->refreshSubscription($subscriptionData['principaluri'], $subscriptionData['uri']);
  63. $jobList->add(\OCA\DAV\BackgroundJob\RefreshWebcalJob::class, [
  64. 'principaluri' => $subscriptionData['principaluri'],
  65. 'uri' => $subscriptionData['uri']
  66. ]);
  67. }
  68. );
  69. $eventDispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteSubscription',
  70. function(GenericEvent $event) use ($app) {
  71. $jobList = $app->getContainer()->getServer()->getJobList();
  72. $subscriptionData = $event->getArgument('subscriptionData');
  73. $jobList->remove(\OCA\DAV\BackgroundJob\RefreshWebcalJob::class, [
  74. 'principaluri' => $subscriptionData['principaluri'],
  75. 'uri' => $subscriptionData['uri']
  76. ]);
  77. /** @var \OCA\DAV\CalDAV\CalDavBackend $calDavBackend */
  78. $calDavBackend = $app->getContainer()->query(\OCA\DAV\CalDAV\CalDavBackend::class);
  79. $calDavBackend->purgeAllCachedEventsForSubscription($subscriptionData['id']);
  80. }
  81. );
  82. $eventHandler = function() use ($app) {
  83. try {
  84. $job = $app->getContainer()->query(\OCA\DAV\BackgroundJob\UpdateCalendarResourcesRoomsBackgroundJob::class);
  85. $job->run([]);
  86. $app->getContainer()->getServer()->getJobList()->setLastRun($job);
  87. } catch(\Exception $ex) {
  88. $app->getContainer()->getServer()->getLogger()->logException($ex);
  89. }
  90. };
  91. $eventDispatcher->addListener('\OCP\Calendar\Resource\ForceRefreshEvent', $eventHandler);
  92. $eventDispatcher->addListener('\OCP\Calendar\Room\ForceRefreshEvent', $eventHandler);
  93. $cm = \OC::$server->getContactsManager();
  94. $cm->register(function() use ($cm, $app) {
  95. $user = \OC::$server->getUserSession()->getUser();
  96. if (!is_null($user)) {
  97. $app->setupContactsProvider($cm, $user->getUID());
  98. } else {
  99. $app->setupSystemContactsProvider($cm);
  100. }
  101. });
  102. $calendarManager = \OC::$server->getCalendarManager();
  103. $calendarManager->register(function() use ($calendarManager, $app) {
  104. $user = \OC::$server->getUserSession()->getUser();
  105. if ($user !== null) {
  106. $app->setupCalendarProvider($calendarManager, $user->getUID());
  107. }
  108. });
  109. $app->registerNotifier();
  110. $app->registerCalendarReminders();