1
0

app.php 3.8 KB

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