|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Björn Schießle <[email protected]> |
|
6
|
|
|
* @author Georg Ehrke <[email protected]> |
|
7
|
|
|
* @author Joas Schilling <[email protected]> |
|
8
|
|
|
* @author Thomas Müller <[email protected]> |
|
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
|
|
|
namespace OCA\DAV\AppInfo; |
|
26
|
|
|
|
|
27
|
|
|
use OCA\DAV\CalDAV\BirthdayService; |
|
28
|
|
|
use OCA\DAV\CardDAV\ContactsManager; |
|
29
|
|
|
use OCA\DAV\CardDAV\SyncService; |
|
30
|
|
|
use OCA\DAV\HookManager; |
|
31
|
|
|
use \OCP\AppFramework\App; |
|
32
|
|
|
use OCP\Contacts\IManager; |
|
33
|
|
|
use Symfony\Component\EventDispatcher\GenericEvent; |
|
34
|
|
|
|
|
35
|
|
|
class Application extends App { |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Application constructor. |
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct() { |
|
41
|
|
|
parent::__construct('dav'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @param IManager $contactsManager |
|
46
|
|
|
* @param string $userID |
|
47
|
|
|
*/ |
|
48
|
|
|
public function setupContactsProvider(IManager $contactsManager, $userID) { |
|
49
|
|
|
/** @var ContactsManager $cm */ |
|
50
|
|
|
$cm = $this->getContainer()->query(ContactsManager::class); |
|
51
|
|
|
$urlGenerator = $this->getContainer()->getServer()->getURLGenerator(); |
|
52
|
|
|
$cm->setupContactsProvider($contactsManager, $userID, $urlGenerator); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function registerHooks() { |
|
56
|
|
|
/** @var HookManager $hm */ |
|
57
|
|
|
$hm = $this->getContainer()->query(HookManager::class); |
|
58
|
|
|
$hm->setup(); |
|
59
|
|
|
|
|
60
|
|
View Code Duplication |
$listener = function($event) { |
|
|
|
|
|
|
61
|
|
|
if ($event instanceof GenericEvent) { |
|
|
|
|
|
|
62
|
|
|
/** @var BirthdayService $b */ |
|
63
|
|
|
$b = $this->getContainer()->query(BirthdayService::class); |
|
64
|
|
|
$b->onCardChanged( |
|
65
|
|
|
$event->getArgument('addressBookId'), |
|
66
|
|
|
$event->getArgument('cardUri'), |
|
67
|
|
|
$event->getArgument('cardData') |
|
68
|
|
|
); |
|
69
|
|
|
} |
|
70
|
|
|
}; |
|
71
|
|
|
|
|
72
|
|
|
$dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
|
73
|
|
|
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $listener); |
|
74
|
|
|
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $listener); |
|
75
|
|
View Code Duplication |
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) { |
|
|
|
|
|
|
76
|
|
|
if ($event instanceof GenericEvent) { |
|
|
|
|
|
|
77
|
|
|
/** @var BirthdayService $b */ |
|
78
|
|
|
$b = $this->getContainer()->query(BirthdayService::class); |
|
79
|
|
|
$b->onCardDeleted( |
|
80
|
|
|
$event->getArgument('addressBookId'), |
|
81
|
|
|
$event->getArgument('cardUri') |
|
82
|
|
|
); |
|
83
|
|
|
} |
|
84
|
|
|
}); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function getSyncService() { |
|
88
|
|
|
return $this->getContainer()->query(SyncService::class); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.