app.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. $app = new Application();
  29. $app->registerHooks();
  30. \OC::$server->registerService('CardDAVSyncService', function() use ($app) {
  31. return $app->getSyncService();
  32. });
  33. $eventDispatcher = \OC::$server->getEventDispatcher();
  34. $eventDispatcher->addListener('OCP\Federation\TrustedServerEvent::remove',
  35. function(GenericEvent $event) use ($app) {
  36. /** @var CardDavBackend $cardDavBackend */
  37. $cardDavBackend = $app->getContainer()->query(CardDavBackend::class);
  38. $addressBookUri = $event->getSubject();
  39. $addressBook = $cardDavBackend->getAddressBooksByUri('principals/system/system', $addressBookUri);
  40. if (!is_null($addressBook)) {
  41. $cardDavBackend->deleteAddressBook($addressBook['id']);
  42. }
  43. }
  44. );
  45. $cm = \OC::$server->getContactsManager();
  46. $cm->register(function() use ($cm, $app) {
  47. $user = \OC::$server->getUserSession()->getUser();
  48. if (!is_null($user)) {
  49. $app->setupContactsProvider($cm, $user->getUID());
  50. }
  51. });