app.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 Thomas Müller <thomas.mueller@tmit.eu>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. use OCA\DAV\AppInfo\Application;
  25. use OCA\DAV\CardDAV\CardDavBackend;
  26. use Symfony\Component\EventDispatcher\GenericEvent;
  27. $app = new Application();
  28. $app->registerHooks();
  29. \OC::$server->registerService('CardDAVSyncService', function() use ($app) {
  30. return $app->getSyncService();
  31. });
  32. $eventDispatcher = \OC::$server->getEventDispatcher();
  33. $eventDispatcher->addListener('OCP\Federation\TrustedServerEvent::remove',
  34. function(GenericEvent $event) use ($app) {
  35. /** @var CardDavBackend $cardDavBackend */
  36. $cardDavBackend = $app->getContainer()->query(CardDavBackend::class);
  37. $addressBookUri = $event->getSubject();
  38. $addressBook = $cardDavBackend->getAddressBooksByUri('principals/system/system', $addressBookUri);
  39. if (!is_null($addressBook)) {
  40. $cardDavBackend->deleteAddressBook($addressBook['id']);
  41. }
  42. }
  43. );
  44. $cm = \OC::$server->getContactsManager();
  45. $cm->register(function() use ($cm, $app) {
  46. $user = \OC::$server->getUserSession()->getUser();
  47. if (!is_null($user)) {
  48. $app->setupContactsProvider($cm, $user->getUID());
  49. }
  50. });