|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Bjoern Schiessle <[email protected]> |
|
6
|
|
|
* @author Georg Ehrke <[email protected]> |
|
7
|
|
|
* @author Joas Schilling <[email protected]> |
|
8
|
|
|
* @author Roeland Jago Douma <[email protected]> |
|
9
|
|
|
* @author Thomas Müller <[email protected]> |
|
10
|
|
|
* |
|
11
|
|
|
* @license AGPL-3.0 |
|
12
|
|
|
* |
|
13
|
|
|
* This code is free software: you can redistribute it and/or modify |
|
14
|
|
|
* it under the terms of the GNU Affero General Public License, version 3, |
|
15
|
|
|
* as published by the Free Software Foundation. |
|
16
|
|
|
* |
|
17
|
|
|
* This program is distributed in the hope that it will be useful, |
|
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20
|
|
|
* GNU Affero General Public License for more details. |
|
21
|
|
|
* |
|
22
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3, |
|
23
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/> |
|
24
|
|
|
* |
|
25
|
|
|
*/ |
|
26
|
|
|
namespace OCA\DAV\AppInfo; |
|
27
|
|
|
|
|
28
|
|
|
use OC\AppFramework\Utility\SimpleContainer; |
|
29
|
|
|
use OCA\DAV\CalDAV\Activity\Backend; |
|
30
|
|
|
use OCA\DAV\CalDAV\Activity\Provider\Event; |
|
31
|
|
|
use OCA\DAV\CalDAV\BirthdayService; |
|
32
|
|
|
use OCA\DAV\CalDAV\CalendarManager; |
|
33
|
|
|
use OCA\DAV\Capabilities; |
|
34
|
|
|
use OCA\DAV\CardDAV\ContactsManager; |
|
35
|
|
|
use OCA\DAV\CardDAV\PhotoCache; |
|
36
|
|
|
use OCA\DAV\CardDAV\SyncService; |
|
37
|
|
|
use OCA\DAV\HookManager; |
|
38
|
|
|
use \OCP\AppFramework\App; |
|
39
|
|
|
use OCP\Contacts\IManager as IContactsManager; |
|
40
|
|
|
use OCP\Calendar\IManager as ICalendarManager; |
|
41
|
|
|
use OCP\IUser; |
|
42
|
|
|
use Symfony\Component\EventDispatcher\GenericEvent; |
|
43
|
|
|
|
|
44
|
|
|
class Application extends App { |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Application constructor. |
|
48
|
|
|
*/ |
|
49
|
|
|
public function __construct() { |
|
50
|
|
|
parent::__construct('dav'); |
|
51
|
|
|
|
|
52
|
|
|
$container = $this->getContainer(); |
|
53
|
|
|
$server = $container->getServer(); |
|
54
|
|
|
|
|
55
|
|
|
$container->registerService(PhotoCache::class, function(SimpleContainer $s) use ($server) { |
|
|
|
|
|
|
56
|
|
|
return new PhotoCache( |
|
57
|
|
|
$server->getAppDataDir('dav-photocache') |
|
58
|
|
|
); |
|
59
|
|
|
}); |
|
60
|
|
|
|
|
61
|
|
|
/* |
|
62
|
|
|
* Register capabilities |
|
63
|
|
|
*/ |
|
64
|
|
|
$container->registerCapability(Capabilities::class); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param IContactsManager $contactsManager |
|
69
|
|
|
* @param string $userID |
|
70
|
|
|
*/ |
|
71
|
|
|
public function setupContactsProvider(IContactsManager $contactsManager, $userID) { |
|
72
|
|
|
/** @var ContactsManager $cm */ |
|
73
|
|
|
$cm = $this->getContainer()->query(ContactsManager::class); |
|
74
|
|
|
$urlGenerator = $this->getContainer()->getServer()->getURLGenerator(); |
|
75
|
|
|
$cm->setupContactsProvider($contactsManager, $userID, $urlGenerator); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param ICalendarManager $calendarManager |
|
80
|
|
|
* @param string $userId |
|
81
|
|
|
*/ |
|
82
|
|
|
public function setupCalendarProvider(ICalendarManager $calendarManager, $userId) { |
|
83
|
|
|
$cm = $this->getContainer()->query(CalendarManager::class); |
|
84
|
|
|
$cm->setupCalendarProvider($calendarManager, $userId); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function registerHooks() { |
|
88
|
|
|
/** @var HookManager $hm */ |
|
89
|
|
|
$hm = $this->getContainer()->query(HookManager::class); |
|
90
|
|
|
$hm->setup(); |
|
91
|
|
|
|
|
92
|
|
|
$dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
|
93
|
|
|
|
|
94
|
|
|
// first time login event setup |
|
95
|
|
|
$dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) { |
|
96
|
|
|
if ($event instanceof GenericEvent) { |
|
|
|
|
|
|
97
|
|
|
$hm->firstLogin($event->getSubject()); |
|
98
|
|
|
} |
|
99
|
|
|
}); |
|
100
|
|
|
|
|
101
|
|
|
// carddav/caldav sync event setup |
|
102
|
|
View Code Duplication |
$listener = function($event) { |
|
103
|
|
|
if ($event instanceof GenericEvent) { |
|
|
|
|
|
|
104
|
|
|
/** @var BirthdayService $b */ |
|
105
|
|
|
$b = $this->getContainer()->query(BirthdayService::class); |
|
106
|
|
|
$b->onCardChanged( |
|
107
|
|
|
$event->getArgument('addressBookId'), |
|
108
|
|
|
$event->getArgument('cardUri'), |
|
109
|
|
|
$event->getArgument('cardData') |
|
110
|
|
|
); |
|
111
|
|
|
} |
|
112
|
|
|
}; |
|
113
|
|
|
|
|
114
|
|
|
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $listener); |
|
115
|
|
|
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $listener); |
|
116
|
|
View Code Duplication |
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) { |
|
117
|
|
|
if ($event instanceof GenericEvent) { |
|
|
|
|
|
|
118
|
|
|
/** @var BirthdayService $b */ |
|
119
|
|
|
$b = $this->getContainer()->query(BirthdayService::class); |
|
120
|
|
|
$b->onCardDeleted( |
|
121
|
|
|
$event->getArgument('addressBookId'), |
|
122
|
|
|
$event->getArgument('cardUri') |
|
123
|
|
|
); |
|
124
|
|
|
} |
|
125
|
|
|
}); |
|
126
|
|
|
|
|
127
|
|
|
$clearPhotoCache = function($event) { |
|
128
|
|
|
if ($event instanceof GenericEvent) { |
|
|
|
|
|
|
129
|
|
|
/** @var PhotoCache $p */ |
|
130
|
|
|
$p = $this->getContainer()->query(PhotoCache::class); |
|
131
|
|
|
$p->delete( |
|
132
|
|
|
$event->getArgument('addressBookId'), |
|
133
|
|
|
$event->getArgument('cardUri') |
|
134
|
|
|
); |
|
135
|
|
|
} |
|
136
|
|
|
}; |
|
137
|
|
|
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache); |
|
138
|
|
|
$dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache); |
|
139
|
|
|
|
|
140
|
|
|
$dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) { |
|
141
|
|
|
$user = $event->getSubject(); |
|
142
|
|
|
$syncService = $this->getContainer()->query(SyncService::class); |
|
143
|
|
|
$syncService->updateUser($user); |
|
144
|
|
|
}); |
|
145
|
|
|
|
|
146
|
|
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function(GenericEvent $event) { |
|
147
|
|
|
/** @var Backend $backend */ |
|
148
|
|
|
$backend = $this->getContainer()->query(Backend::class); |
|
149
|
|
|
$backend->onCalendarAdd( |
|
150
|
|
|
$event->getArgument('calendarData') |
|
151
|
|
|
); |
|
152
|
|
|
}); |
|
153
|
|
View Code Duplication |
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function(GenericEvent $event) { |
|
154
|
|
|
/** @var Backend $backend */ |
|
155
|
|
|
$backend = $this->getContainer()->query(Backend::class); |
|
156
|
|
|
$backend->onCalendarUpdate( |
|
157
|
|
|
$event->getArgument('calendarData'), |
|
158
|
|
|
$event->getArgument('shares'), |
|
159
|
|
|
$event->getArgument('propertyMutations') |
|
160
|
|
|
); |
|
161
|
|
|
}); |
|
162
|
|
View Code Duplication |
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function(GenericEvent $event) { |
|
163
|
|
|
/** @var Backend $backend */ |
|
164
|
|
|
$backend = $this->getContainer()->query(Backend::class); |
|
165
|
|
|
$backend->onCalendarDelete( |
|
166
|
|
|
$event->getArgument('calendarData'), |
|
167
|
|
|
$event->getArgument('shares') |
|
168
|
|
|
); |
|
169
|
|
|
}); |
|
170
|
|
View Code Duplication |
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function(GenericEvent $event) { |
|
171
|
|
|
/** @var Backend $backend */ |
|
172
|
|
|
$backend = $this->getContainer()->query(Backend::class); |
|
173
|
|
|
$backend->onCalendarUpdateShares( |
|
174
|
|
|
$event->getArgument('calendarData'), |
|
175
|
|
|
$event->getArgument('shares'), |
|
176
|
|
|
$event->getArgument('add'), |
|
177
|
|
|
$event->getArgument('remove') |
|
178
|
|
|
); |
|
179
|
|
|
}); |
|
180
|
|
|
|
|
181
|
|
|
$listener = function(GenericEvent $event, $eventName) { |
|
182
|
|
|
/** @var Backend $backend */ |
|
183
|
|
|
$backend = $this->getContainer()->query(Backend::class); |
|
184
|
|
|
|
|
185
|
|
|
$subject = Event::SUBJECT_OBJECT_ADD; |
|
186
|
|
|
if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') { |
|
187
|
|
|
$subject = Event::SUBJECT_OBJECT_UPDATE; |
|
188
|
|
|
} else if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') { |
|
189
|
|
|
$subject = Event::SUBJECT_OBJECT_DELETE; |
|
190
|
|
|
} |
|
191
|
|
|
$backend->onTouchCalendarObject( |
|
192
|
|
|
$subject, |
|
193
|
|
|
$event->getArgument('calendarData'), |
|
194
|
|
|
$event->getArgument('shares'), |
|
195
|
|
|
$event->getArgument('objectData') |
|
196
|
|
|
); |
|
197
|
|
|
}; |
|
198
|
|
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener); |
|
199
|
|
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener); |
|
200
|
|
|
$dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
public function getSyncService() { |
|
204
|
|
|
return $this->getContainer()->query(SyncService::class); |
|
205
|
|
|
} |
|
206
|
|
|
|
|
207
|
|
|
} |
|
208
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.