|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Björn Schießle <[email protected]> |
|
4
|
|
|
* @author Joas Schilling <[email protected]> |
|
5
|
|
|
* @author Thomas Müller <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
8
|
|
|
* @license AGPL-3.0 |
|
9
|
|
|
* |
|
10
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
11
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
12
|
|
|
* as published by the Free Software Foundation. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU Affero General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
20
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
21
|
|
|
* |
|
22
|
|
|
*/ |
|
23
|
|
|
namespace OCA\DAV\AppInfo; |
|
24
|
|
|
|
|
25
|
|
|
use OCA\DAV\CalDAV\BirthdayService; |
|
26
|
|
|
use OCA\DAV\CalDAV\CalDavBackend; |
|
27
|
|
|
use OCA\DAV\CardDAV\CardDavBackend; |
|
28
|
|
|
use OCA\DAV\CardDAV\ContactsManager; |
|
29
|
|
|
use OCA\DAV\CardDAV\SyncJob; |
|
30
|
|
|
use OCA\DAV\CardDAV\SyncService; |
|
31
|
|
|
use OCA\DAV\Connector\Sabre\Principal; |
|
32
|
|
|
use OCA\DAV\DAV\GroupPrincipalBackend; |
|
33
|
|
|
use OCA\DAV\HookManager; |
|
34
|
|
|
use OCA\DAV\Migration\Classification; |
|
35
|
|
|
use OCA\DAV\Migration\GenerateBirthdays; |
|
36
|
|
|
use \OCP\AppFramework\App; |
|
37
|
|
|
use OCP\AppFramework\IAppContainer; |
|
38
|
|
|
use OCP\Contacts\IManager; |
|
39
|
|
|
use OCP\IUser; |
|
40
|
|
|
use Sabre\VObject\Reader; |
|
41
|
|
|
use Symfony\Component\EventDispatcher\GenericEvent; |
|
42
|
|
|
|
|
43
|
|
|
class Application extends App { |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Application constructor. |
|
47
|
|
|
* |
|
48
|
|
|
* @param array $urlParams |
|
49
|
|
|
*/ |
|
50
|
|
|
public function __construct (array $urlParams=array()) { |
|
51
|
|
|
parent::__construct('dav', $urlParams); |
|
52
|
|
|
|
|
53
|
|
|
$container = $this->getContainer(); |
|
54
|
|
|
$container->registerService('ContactsManager', function($c) { |
|
55
|
|
|
/** @var IAppContainer $c */ |
|
56
|
|
|
return new ContactsManager( |
|
57
|
|
|
$c->query('CardDavBackend') |
|
58
|
|
|
); |
|
59
|
|
|
}); |
|
60
|
|
|
|
|
61
|
|
|
$container->registerService('HookManager', function($c) { |
|
62
|
|
|
/** @var IAppContainer $c */ |
|
63
|
|
|
return new HookManager( |
|
64
|
|
|
$c->getServer()->getUserManager(), |
|
65
|
|
|
$c->query('SyncService'), |
|
66
|
|
|
$c->query('CalDavBackend'), |
|
67
|
|
|
$c->query('CardDavBackend') |
|
68
|
|
|
); |
|
69
|
|
|
}); |
|
70
|
|
|
|
|
71
|
|
|
$container->registerService('SyncService', function($c) { |
|
72
|
|
|
/** @var IAppContainer $c */ |
|
73
|
|
|
return new SyncService( |
|
74
|
|
|
$c->query('CardDavBackend'), |
|
75
|
|
|
$c->getServer()->getUserManager(), |
|
76
|
|
|
$c->getServer()->getLogger() |
|
77
|
|
|
); |
|
78
|
|
|
}); |
|
79
|
|
|
|
|
80
|
|
|
$container->registerService('CardDavBackend', function($c) { |
|
81
|
|
|
/** @var IAppContainer $c */ |
|
82
|
|
|
$db = $c->getServer()->getDatabaseConnection(); |
|
83
|
|
|
$dispatcher = $c->getServer()->getEventDispatcher(); |
|
84
|
|
|
$principal = new Principal( |
|
85
|
|
|
$c->getServer()->getUserManager(), |
|
86
|
|
|
$c->getServer()->getGroupManager() |
|
87
|
|
|
); |
|
88
|
|
|
return new CardDavBackend($db, $principal, $dispatcher); |
|
89
|
|
|
}); |
|
90
|
|
|
|
|
91
|
|
|
$container->registerService('CalDavBackend', function($c) { |
|
92
|
|
|
/** @var IAppContainer $c */ |
|
93
|
|
|
$db = $c->getServer()->getDatabaseConnection(); |
|
94
|
|
|
$principal = new Principal( |
|
95
|
|
|
$c->getServer()->getUserManager(), |
|
96
|
|
|
$c->getServer()->getGroupManager() |
|
97
|
|
|
); |
|
98
|
|
|
return new CalDavBackend($db, $principal); |
|
99
|
|
|
}); |
|
100
|
|
|
|
|
101
|
|
|
$container->registerService('BirthdayService', function($c) { |
|
102
|
|
|
/** @var IAppContainer $c */ |
|
103
|
|
|
$g = new GroupPrincipalBackend( |
|
104
|
|
|
$c->getServer()->getGroupManager() |
|
105
|
|
|
); |
|
106
|
|
|
return new BirthdayService( |
|
107
|
|
|
$c->query('CalDavBackend'), |
|
108
|
|
|
$c->query('CardDavBackend'), |
|
109
|
|
|
$g |
|
110
|
|
|
); |
|
111
|
|
|
}); |
|
112
|
|
|
|
|
113
|
|
|
$container->registerService('OCA\DAV\Migration\Classification', function ($c) { |
|
114
|
|
|
/** @var IAppContainer $c */ |
|
115
|
|
|
return new Classification( |
|
116
|
|
|
$c->query('CalDavBackend'), |
|
117
|
|
|
$c->getServer()->getUserManager() |
|
118
|
|
|
); |
|
119
|
|
|
}); |
|
120
|
|
|
|
|
121
|
|
|
$container->registerService('OCA\DAV\Migration\GenerateBirthdays', function ($c) { |
|
122
|
|
|
/** @var IAppContainer $c */ |
|
123
|
|
|
/** @var BirthdayService $b */ |
|
124
|
|
|
$b = $c->query('BirthdayService'); |
|
125
|
|
|
return new GenerateBirthdays( |
|
126
|
|
|
$b, |
|
127
|
|
|
$c->getServer()->getUserManager() |
|
128
|
|
|
); |
|
129
|
|
|
}); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
/** |
|
133
|
|
|
* @param IManager $contactsManager |
|
134
|
|
|
* @param string $userID |
|
135
|
|
|
*/ |
|
136
|
|
|
public function setupContactsProvider(IManager $contactsManager, $userID) { |
|
137
|
|
|
/** @var ContactsManager $cm */ |
|
138
|
|
|
$cm = $this->getContainer()->query('ContactsManager'); |
|
139
|
|
|
$cm->setupContactsProvider($contactsManager, $userID); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
public function registerHooks() { |
|
143
|
|
|
/** @var HookManager $hm */ |
|
144
|
|
|
$hm = $this->getContainer()->query('HookManager'); |
|
145
|
|
|
$hm->setup(); |
|
146
|
|
|
|
|
147
|
|
View Code Duplication |
$listener = function($event) { |
|
|
|
|
|
|
148
|
|
|
if ($event instanceof GenericEvent) { |
|
|
|
|
|
|
149
|
|
|
/** @var BirthdayService $b */ |
|
150
|
|
|
$b = $this->getContainer()->query('BirthdayService'); |
|
151
|
|
|
$b->onCardChanged( |
|
152
|
|
|
$event->getArgument('addressBookId'), |
|
153
|
|
|
$event->getArgument('cardUri'), |
|
154
|
|
|
$event->getArgument('cardData') |
|
155
|
|
|
); |
|
156
|
|
|
} |
|
157
|
|
|
}; |
|
158
|
|
|
|
|
159
|
|
|
$dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
|
160
|
|
|
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $listener); |
|
161
|
|
|
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $listener); |
|
162
|
|
View Code Duplication |
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) { |
|
|
|
|
|
|
163
|
|
|
if ($event instanceof GenericEvent) { |
|
|
|
|
|
|
164
|
|
|
/** @var BirthdayService $b */ |
|
165
|
|
|
$b = $this->getContainer()->query('BirthdayService'); |
|
166
|
|
|
$b->onCardDeleted( |
|
167
|
|
|
$event->getArgument('addressBookId'), |
|
168
|
|
|
$event->getArgument('cardUri') |
|
169
|
|
|
); |
|
170
|
|
|
} |
|
171
|
|
|
}); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
public function getSyncService() { |
|
175
|
|
|
return $this->getContainer()->query('SyncService'); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
} |
|
179
|
|
|
|
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.