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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 <tcit@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\CardDAV\CardDavBackend;
  32. use Symfony\Component\EventDispatcher\GenericEvent;
  33. \OC_App::loadApps(['dav']);
  34. /** @var Application $app */
  35. $app = \OC::$server->query(Application::class);
  36. $app->registerHooks();
  37. \OC::$server->registerService('CardDAVSyncService', function() use ($app) {
  38. return $app->getSyncService();
  39. });
  40. $eventDispatcher = \OC::$server->getEventDispatcher();
  41. $eventDispatcher->addListener('OCP\Federation\TrustedServerEvent::remove',
  42. function(GenericEvent $event) use ($app) {
  43. /** @var CardDavBackend $cardDavBackend */
  44. $cardDavBackend = $app->getContainer()->query(CardDavBackend::class);
  45. $addressBookUri = $event->getSubject();
  46. $addressBook = $cardDavBackend->getAddressBooksByUri('principals/system/system', $addressBookUri);
  47. if (!is_null($addressBook)) {
  48. $cardDavBackend->deleteAddressBook($addressBook['id']);
  49. }
  50. }
  51. );
  52. $eventDispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createSubscription',
  53. function(GenericEvent $event) use ($app) {
  54. $jobList = $app->getContainer()->getServer()->getJobList();
  55. $subscriptionData = $event->getArgument('subscriptionData');
  56. $jobList->add(\OCA\DAV\BackgroundJob\RefreshWebcalJob::class, [
  57. 'principaluri' => $subscriptionData['principaluri'],
  58. 'uri' => $subscriptionData['uri']
  59. ]);
  60. }
  61. );
  62. $eventDispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteSubscription',
  63. function(GenericEvent $event) use ($app) {
  64. $jobList = $app->getContainer()->getServer()->getJobList();
  65. $subscriptionData = $event->getArgument('subscriptionData');
  66. $jobList->remove(\OCA\DAV\BackgroundJob\RefreshWebcalJob::class, [
  67. 'principaluri' => $subscriptionData['principaluri'],
  68. 'uri' => $subscriptionData['uri']
  69. ]);
  70. /** @var \OCA\DAV\CalDAV\CalDavBackend $calDavBackend */
  71. $calDavBackend = $app->getContainer()->query(\OCA\DAV\CalDAV\CalDavBackend::class);
  72. $calDavBackend->purgeAllCachedEventsForSubscription($subscriptionData['id']);
  73. }
  74. );
  75. $eventHandler = function() use ($app) {
  76. try {
  77. $job = $app->getContainer()->query(\OCA\DAV\BackgroundJob\UpdateCalendarResourcesRoomsBackgroundJob::class);
  78. $job->run([]);
  79. $app->getContainer()->getServer()->getJobList()->setLastRun($job);
  80. } catch(\Exception $ex) {
  81. $app->getContainer()->getServer()->getLogger()->logException($ex);
  82. }
  83. };
  84. $eventDispatcher->addListener('\OCP\Calendar\Resource\ForceRefreshEvent', $eventHandler);
  85. $eventDispatcher->addListener('\OCP\Calendar\Room\ForceRefreshEvent', $eventHandler);
  86. $cm = \OC::$server->getContactsManager();
  87. $cm->register(function() use ($cm, $app) {
  88. $user = \OC::$server->getUserSession()->getUser();
  89. if (!is_null($user)) {
  90. $app->setupContactsProvider($cm, $user->getUID());
  91. } else {
  92. $app->setupSystemContactsProvider($cm);
  93. }
  94. });
  95. $calendarManager = \OC::$server->getCalendarManager();
  96. $calendarManager->register(function() use ($calendarManager, $app) {
  97. $user = \OC::$server->getUserSession()->getUser();
  98. if ($user !== null) {
  99. $app->setupCalendarProvider($calendarManager, $user->getUID());
  100. }
  101. });
  102. $app->registerNotifier();
  103. $app->registerCalendarReminders();