@@ -41,180 +41,180 @@ |
||
41 | 41 | |
42 | 42 | class Application extends App { |
43 | 43 | |
44 | - /** |
|
45 | - * Application constructor. |
|
46 | - */ |
|
47 | - public function __construct() { |
|
48 | - parent::__construct('dav'); |
|
49 | - |
|
50 | - $container = $this->getContainer(); |
|
51 | - $server = $container->getServer(); |
|
52 | - |
|
53 | - $container->registerService(PhotoCache::class, function(SimpleContainer $s) use ($server) { |
|
54 | - return new PhotoCache( |
|
55 | - $server->getAppDataDir('dav-photocache') |
|
56 | - ); |
|
57 | - }); |
|
58 | - |
|
59 | - /* |
|
44 | + /** |
|
45 | + * Application constructor. |
|
46 | + */ |
|
47 | + public function __construct() { |
|
48 | + parent::__construct('dav'); |
|
49 | + |
|
50 | + $container = $this->getContainer(); |
|
51 | + $server = $container->getServer(); |
|
52 | + |
|
53 | + $container->registerService(PhotoCache::class, function(SimpleContainer $s) use ($server) { |
|
54 | + return new PhotoCache( |
|
55 | + $server->getAppDataDir('dav-photocache') |
|
56 | + ); |
|
57 | + }); |
|
58 | + |
|
59 | + /* |
|
60 | 60 | * Register capabilities |
61 | 61 | */ |
62 | - $container->registerCapability(Capabilities::class); |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * @param IManager $contactsManager |
|
67 | - * @param string $userID |
|
68 | - */ |
|
69 | - public function setupContactsProvider(IManager $contactsManager, $userID) { |
|
70 | - /** @var ContactsManager $cm */ |
|
71 | - $cm = $this->getContainer()->query(ContactsManager::class); |
|
72 | - $urlGenerator = $this->getContainer()->getServer()->getURLGenerator(); |
|
73 | - $cm->setupContactsProvider($contactsManager, $userID, $urlGenerator); |
|
74 | - } |
|
75 | - |
|
76 | - public function registerHooks() { |
|
77 | - /** @var HookManager $hm */ |
|
78 | - $hm = $this->getContainer()->query(HookManager::class); |
|
79 | - $hm->setup(); |
|
80 | - |
|
81 | - $dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
|
82 | - |
|
83 | - // first time login event setup |
|
84 | - $dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) { |
|
85 | - if ($event instanceof GenericEvent) { |
|
86 | - $hm->firstLogin($event->getSubject()); |
|
87 | - } |
|
88 | - }); |
|
89 | - |
|
90 | - $birthdayListener = function ($event) { |
|
91 | - if ($event instanceof GenericEvent) { |
|
92 | - /** @var BirthdayService $b */ |
|
93 | - $b = $this->getContainer()->query(BirthdayService::class); |
|
94 | - $b->onCardChanged( |
|
95 | - $event->getArgument('addressBookId'), |
|
96 | - $event->getArgument('cardUri'), |
|
97 | - $event->getArgument('cardData') |
|
98 | - ); |
|
99 | - } |
|
100 | - }; |
|
101 | - |
|
102 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $birthdayListener); |
|
103 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $birthdayListener); |
|
104 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function ($event) { |
|
105 | - if ($event instanceof GenericEvent) { |
|
106 | - /** @var BirthdayService $b */ |
|
107 | - $b = $this->getContainer()->query(BirthdayService::class); |
|
108 | - $b->onCardDeleted( |
|
109 | - $event->getArgument('addressBookId'), |
|
110 | - $event->getArgument('cardUri') |
|
111 | - ); |
|
112 | - } |
|
113 | - }); |
|
114 | - |
|
115 | - $clearPhotoCache = function($event) { |
|
116 | - if ($event instanceof GenericEvent) { |
|
117 | - /** @var PhotoCache $p */ |
|
118 | - $p = $this->getContainer()->query(PhotoCache::class); |
|
119 | - $p->delete( |
|
120 | - $event->getArgument('addressBookId'), |
|
121 | - $event->getArgument('cardUri') |
|
122 | - ); |
|
123 | - } |
|
124 | - }; |
|
125 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache); |
|
126 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache); |
|
127 | - |
|
128 | - $dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) { |
|
129 | - $user = $event->getSubject(); |
|
130 | - $syncService = $this->getContainer()->query(SyncService::class); |
|
131 | - $syncService->updateUser($user); |
|
132 | - }); |
|
133 | - |
|
134 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function(GenericEvent $event) { |
|
135 | - /** @var Backend $backend */ |
|
136 | - $backend = $this->getContainer()->query(Backend::class); |
|
137 | - $backend->onCalendarAdd( |
|
138 | - $event->getArgument('calendarData') |
|
139 | - ); |
|
140 | - }); |
|
141 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function(GenericEvent $event) { |
|
142 | - /** @var Backend $backend */ |
|
143 | - $backend = $this->getContainer()->query(Backend::class); |
|
144 | - $backend->onCalendarUpdate( |
|
145 | - $event->getArgument('calendarData'), |
|
146 | - $event->getArgument('shares'), |
|
147 | - $event->getArgument('propertyMutations') |
|
148 | - ); |
|
149 | - }); |
|
150 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function(GenericEvent $event) { |
|
151 | - /** @var Backend $backend */ |
|
152 | - $backend = $this->getContainer()->query(Backend::class); |
|
153 | - $backend->onCalendarDelete( |
|
154 | - $event->getArgument('calendarData'), |
|
155 | - $event->getArgument('shares') |
|
156 | - ); |
|
157 | - }); |
|
158 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function(GenericEvent $event) { |
|
159 | - /** @var Backend $backend */ |
|
160 | - $backend = $this->getContainer()->query(Backend::class); |
|
161 | - $backend->onCalendarUpdateShares( |
|
162 | - $event->getArgument('calendarData'), |
|
163 | - $event->getArgument('shares'), |
|
164 | - $event->getArgument('add'), |
|
165 | - $event->getArgument('remove') |
|
166 | - ); |
|
167 | - }); |
|
168 | - |
|
169 | - $listener = function(GenericEvent $event, $eventName) { |
|
170 | - /** @var Backend $backend */ |
|
171 | - $backend = $this->getContainer()->query(Backend::class); |
|
172 | - |
|
173 | - $subject = Event::SUBJECT_OBJECT_ADD; |
|
174 | - if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') { |
|
175 | - $subject = Event::SUBJECT_OBJECT_UPDATE; |
|
176 | - } else if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') { |
|
177 | - $subject = Event::SUBJECT_OBJECT_DELETE; |
|
178 | - } |
|
179 | - $backend->onTouchCalendarObject( |
|
180 | - $subject, |
|
181 | - $event->getArgument('calendarData'), |
|
182 | - $event->getArgument('shares'), |
|
183 | - $event->getArgument('objectData') |
|
184 | - ); |
|
185 | - }; |
|
186 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener); |
|
187 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener); |
|
188 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener); |
|
189 | - |
|
190 | - $reminderListener = function ($event) { |
|
191 | - if ($event instanceof GenericEvent) { |
|
192 | - /** @var ReminderService $m */ |
|
193 | - $m = $this->getContainer()->query(ReminderService::class); |
|
194 | - $m->onCalendarObjectChanged( |
|
195 | - $event->getArgument('calendarId'), |
|
196 | - $event->getArgument('objectUri'), |
|
197 | - $event->getArgument('calendarData') |
|
198 | - ); |
|
199 | - } |
|
200 | - }; |
|
201 | - |
|
202 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDAVBackend::createCalendarObject', $reminderListener); |
|
203 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDAVBackend::updateCalendarObject', $reminderListener); |
|
204 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDAVBackend::deleteCalendarObject', function ($event) { |
|
205 | - if ($event instanceof GenericEvent) { |
|
206 | - /** @var ReminderService $m */ |
|
207 | - $m = $this->getContainer()->query(ReminderService::class); |
|
208 | - $m->onCalendarObjectDeleted( |
|
209 | - $event->getArgument('calendarId'), |
|
210 | - $event->getArgument('objectUri') |
|
211 | - ); |
|
212 | - } |
|
213 | - }); |
|
214 | - } |
|
215 | - |
|
216 | - public function getSyncService() { |
|
217 | - return $this->getContainer()->query(SyncService::class); |
|
218 | - } |
|
62 | + $container->registerCapability(Capabilities::class); |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * @param IManager $contactsManager |
|
67 | + * @param string $userID |
|
68 | + */ |
|
69 | + public function setupContactsProvider(IManager $contactsManager, $userID) { |
|
70 | + /** @var ContactsManager $cm */ |
|
71 | + $cm = $this->getContainer()->query(ContactsManager::class); |
|
72 | + $urlGenerator = $this->getContainer()->getServer()->getURLGenerator(); |
|
73 | + $cm->setupContactsProvider($contactsManager, $userID, $urlGenerator); |
|
74 | + } |
|
75 | + |
|
76 | + public function registerHooks() { |
|
77 | + /** @var HookManager $hm */ |
|
78 | + $hm = $this->getContainer()->query(HookManager::class); |
|
79 | + $hm->setup(); |
|
80 | + |
|
81 | + $dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
|
82 | + |
|
83 | + // first time login event setup |
|
84 | + $dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) { |
|
85 | + if ($event instanceof GenericEvent) { |
|
86 | + $hm->firstLogin($event->getSubject()); |
|
87 | + } |
|
88 | + }); |
|
89 | + |
|
90 | + $birthdayListener = function ($event) { |
|
91 | + if ($event instanceof GenericEvent) { |
|
92 | + /** @var BirthdayService $b */ |
|
93 | + $b = $this->getContainer()->query(BirthdayService::class); |
|
94 | + $b->onCardChanged( |
|
95 | + $event->getArgument('addressBookId'), |
|
96 | + $event->getArgument('cardUri'), |
|
97 | + $event->getArgument('cardData') |
|
98 | + ); |
|
99 | + } |
|
100 | + }; |
|
101 | + |
|
102 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $birthdayListener); |
|
103 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $birthdayListener); |
|
104 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function ($event) { |
|
105 | + if ($event instanceof GenericEvent) { |
|
106 | + /** @var BirthdayService $b */ |
|
107 | + $b = $this->getContainer()->query(BirthdayService::class); |
|
108 | + $b->onCardDeleted( |
|
109 | + $event->getArgument('addressBookId'), |
|
110 | + $event->getArgument('cardUri') |
|
111 | + ); |
|
112 | + } |
|
113 | + }); |
|
114 | + |
|
115 | + $clearPhotoCache = function($event) { |
|
116 | + if ($event instanceof GenericEvent) { |
|
117 | + /** @var PhotoCache $p */ |
|
118 | + $p = $this->getContainer()->query(PhotoCache::class); |
|
119 | + $p->delete( |
|
120 | + $event->getArgument('addressBookId'), |
|
121 | + $event->getArgument('cardUri') |
|
122 | + ); |
|
123 | + } |
|
124 | + }; |
|
125 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache); |
|
126 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache); |
|
127 | + |
|
128 | + $dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) { |
|
129 | + $user = $event->getSubject(); |
|
130 | + $syncService = $this->getContainer()->query(SyncService::class); |
|
131 | + $syncService->updateUser($user); |
|
132 | + }); |
|
133 | + |
|
134 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function(GenericEvent $event) { |
|
135 | + /** @var Backend $backend */ |
|
136 | + $backend = $this->getContainer()->query(Backend::class); |
|
137 | + $backend->onCalendarAdd( |
|
138 | + $event->getArgument('calendarData') |
|
139 | + ); |
|
140 | + }); |
|
141 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function(GenericEvent $event) { |
|
142 | + /** @var Backend $backend */ |
|
143 | + $backend = $this->getContainer()->query(Backend::class); |
|
144 | + $backend->onCalendarUpdate( |
|
145 | + $event->getArgument('calendarData'), |
|
146 | + $event->getArgument('shares'), |
|
147 | + $event->getArgument('propertyMutations') |
|
148 | + ); |
|
149 | + }); |
|
150 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function(GenericEvent $event) { |
|
151 | + /** @var Backend $backend */ |
|
152 | + $backend = $this->getContainer()->query(Backend::class); |
|
153 | + $backend->onCalendarDelete( |
|
154 | + $event->getArgument('calendarData'), |
|
155 | + $event->getArgument('shares') |
|
156 | + ); |
|
157 | + }); |
|
158 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function(GenericEvent $event) { |
|
159 | + /** @var Backend $backend */ |
|
160 | + $backend = $this->getContainer()->query(Backend::class); |
|
161 | + $backend->onCalendarUpdateShares( |
|
162 | + $event->getArgument('calendarData'), |
|
163 | + $event->getArgument('shares'), |
|
164 | + $event->getArgument('add'), |
|
165 | + $event->getArgument('remove') |
|
166 | + ); |
|
167 | + }); |
|
168 | + |
|
169 | + $listener = function(GenericEvent $event, $eventName) { |
|
170 | + /** @var Backend $backend */ |
|
171 | + $backend = $this->getContainer()->query(Backend::class); |
|
172 | + |
|
173 | + $subject = Event::SUBJECT_OBJECT_ADD; |
|
174 | + if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') { |
|
175 | + $subject = Event::SUBJECT_OBJECT_UPDATE; |
|
176 | + } else if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') { |
|
177 | + $subject = Event::SUBJECT_OBJECT_DELETE; |
|
178 | + } |
|
179 | + $backend->onTouchCalendarObject( |
|
180 | + $subject, |
|
181 | + $event->getArgument('calendarData'), |
|
182 | + $event->getArgument('shares'), |
|
183 | + $event->getArgument('objectData') |
|
184 | + ); |
|
185 | + }; |
|
186 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener); |
|
187 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener); |
|
188 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener); |
|
189 | + |
|
190 | + $reminderListener = function ($event) { |
|
191 | + if ($event instanceof GenericEvent) { |
|
192 | + /** @var ReminderService $m */ |
|
193 | + $m = $this->getContainer()->query(ReminderService::class); |
|
194 | + $m->onCalendarObjectChanged( |
|
195 | + $event->getArgument('calendarId'), |
|
196 | + $event->getArgument('objectUri'), |
|
197 | + $event->getArgument('calendarData') |
|
198 | + ); |
|
199 | + } |
|
200 | + }; |
|
201 | + |
|
202 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDAVBackend::createCalendarObject', $reminderListener); |
|
203 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDAVBackend::updateCalendarObject', $reminderListener); |
|
204 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDAVBackend::deleteCalendarObject', function ($event) { |
|
205 | + if ($event instanceof GenericEvent) { |
|
206 | + /** @var ReminderService $m */ |
|
207 | + $m = $this->getContainer()->query(ReminderService::class); |
|
208 | + $m->onCalendarObjectDeleted( |
|
209 | + $event->getArgument('calendarId'), |
|
210 | + $event->getArgument('objectUri') |
|
211 | + ); |
|
212 | + } |
|
213 | + }); |
|
214 | + } |
|
215 | + |
|
216 | + public function getSyncService() { |
|
217 | + return $this->getContainer()->query(SyncService::class); |
|
218 | + } |
|
219 | 219 | |
220 | 220 | } |
@@ -81,13 +81,13 @@ discard block |
||
81 | 81 | $dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
82 | 82 | |
83 | 83 | // first time login event setup |
84 | - $dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) { |
|
84 | + $dispatcher->addListener(IUser::class.'::firstLogin', function($event) use ($hm) { |
|
85 | 85 | if ($event instanceof GenericEvent) { |
86 | 86 | $hm->firstLogin($event->getSubject()); |
87 | 87 | } |
88 | 88 | }); |
89 | 89 | |
90 | - $birthdayListener = function ($event) { |
|
90 | + $birthdayListener = function($event) { |
|
91 | 91 | if ($event instanceof GenericEvent) { |
92 | 92 | /** @var BirthdayService $b */ |
93 | 93 | $b = $this->getContainer()->query(BirthdayService::class); |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | |
102 | 102 | $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $birthdayListener); |
103 | 103 | $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $birthdayListener); |
104 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function ($event) { |
|
104 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) { |
|
105 | 105 | if ($event instanceof GenericEvent) { |
106 | 106 | /** @var BirthdayService $b */ |
107 | 107 | $b = $this->getContainer()->query(BirthdayService::class); |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener); |
188 | 188 | $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener); |
189 | 189 | |
190 | - $reminderListener = function ($event) { |
|
190 | + $reminderListener = function($event) { |
|
191 | 191 | if ($event instanceof GenericEvent) { |
192 | 192 | /** @var ReminderService $m */ |
193 | 193 | $m = $this->getContainer()->query(ReminderService::class); |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | |
202 | 202 | $dispatcher->addListener('\OCA\DAV\CalDAV\CalDAVBackend::createCalendarObject', $reminderListener); |
203 | 203 | $dispatcher->addListener('\OCA\DAV\CalDAV\CalDAVBackend::updateCalendarObject', $reminderListener); |
204 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDAVBackend::deleteCalendarObject', function ($event) { |
|
204 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDAVBackend::deleteCalendarObject', function($event) { |
|
205 | 205 | if ($event instanceof GenericEvent) { |
206 | 206 | /** @var ReminderService $m */ |
207 | 207 | $m = $this->getContainer()->query(ReminderService::class); |
@@ -37,90 +37,90 @@ |
||
37 | 37 | |
38 | 38 | class RootCollection extends SimpleCollection { |
39 | 39 | |
40 | - public function __construct() { |
|
41 | - $config = \OC::$server->getConfig(); |
|
42 | - $random = \OC::$server->getSecureRandom(); |
|
43 | - $userManager = \OC::$server->getUserManager(); |
|
44 | - $db = \OC::$server->getDatabaseConnection(); |
|
45 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
46 | - $userPrincipalBackend = new Principal( |
|
47 | - $userManager, |
|
48 | - \OC::$server->getGroupManager() |
|
49 | - ); |
|
50 | - $groupPrincipalBackend = new GroupPrincipalBackend( |
|
51 | - \OC::$server->getGroupManager() |
|
52 | - ); |
|
53 | - // as soon as debug mode is enabled we allow listing of principals |
|
54 | - $disableListing = !$config->getSystemValue('debug', false); |
|
40 | + public function __construct() { |
|
41 | + $config = \OC::$server->getConfig(); |
|
42 | + $random = \OC::$server->getSecureRandom(); |
|
43 | + $userManager = \OC::$server->getUserManager(); |
|
44 | + $db = \OC::$server->getDatabaseConnection(); |
|
45 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
46 | + $userPrincipalBackend = new Principal( |
|
47 | + $userManager, |
|
48 | + \OC::$server->getGroupManager() |
|
49 | + ); |
|
50 | + $groupPrincipalBackend = new GroupPrincipalBackend( |
|
51 | + \OC::$server->getGroupManager() |
|
52 | + ); |
|
53 | + // as soon as debug mode is enabled we allow listing of principals |
|
54 | + $disableListing = !$config->getSystemValue('debug', false); |
|
55 | 55 | |
56 | - // setup the first level of the dav tree |
|
57 | - $userPrincipals = new Collection($userPrincipalBackend, 'principals/users'); |
|
58 | - $userPrincipals->disableListing = $disableListing; |
|
59 | - $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups'); |
|
60 | - $groupPrincipals->disableListing = $disableListing; |
|
61 | - $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system'); |
|
62 | - $systemPrincipals->disableListing = $disableListing; |
|
63 | - $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); |
|
64 | - $filesCollection->disableListing = $disableListing; |
|
65 | - $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $config, $random, $dispatcher); |
|
66 | - $calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users'); |
|
67 | - $calendarRoot->disableListing = $disableListing; |
|
68 | - $publicCalendarRoot = new PublicCalendarRoot($caldavBackend); |
|
69 | - $publicCalendarRoot->disableListing = $disableListing; |
|
56 | + // setup the first level of the dav tree |
|
57 | + $userPrincipals = new Collection($userPrincipalBackend, 'principals/users'); |
|
58 | + $userPrincipals->disableListing = $disableListing; |
|
59 | + $groupPrincipals = new Collection($groupPrincipalBackend, 'principals/groups'); |
|
60 | + $groupPrincipals->disableListing = $disableListing; |
|
61 | + $systemPrincipals = new Collection(new SystemPrincipalBackend(), 'principals/system'); |
|
62 | + $systemPrincipals->disableListing = $disableListing; |
|
63 | + $filesCollection = new Files\RootCollection($userPrincipalBackend, 'principals/users'); |
|
64 | + $filesCollection->disableListing = $disableListing; |
|
65 | + $caldavBackend = new CalDavBackend($db, $userPrincipalBackend, $userManager, $config, $random, $dispatcher); |
|
66 | + $calendarRoot = new CalendarRoot($userPrincipalBackend, $caldavBackend, 'principals/users'); |
|
67 | + $calendarRoot->disableListing = $disableListing; |
|
68 | + $publicCalendarRoot = new PublicCalendarRoot($caldavBackend); |
|
69 | + $publicCalendarRoot->disableListing = $disableListing; |
|
70 | 70 | |
71 | - $systemTagCollection = new SystemTag\SystemTagsByIdCollection( |
|
72 | - \OC::$server->getSystemTagManager(), |
|
73 | - \OC::$server->getUserSession(), |
|
74 | - \OC::$server->getGroupManager() |
|
75 | - ); |
|
76 | - $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection( |
|
77 | - \OC::$server->getSystemTagManager(), |
|
78 | - \OC::$server->getSystemTagObjectMapper(), |
|
79 | - \OC::$server->getUserSession(), |
|
80 | - \OC::$server->getGroupManager(), |
|
81 | - \OC::$server->getEventDispatcher() |
|
82 | - ); |
|
83 | - $commentsCollection = new Comments\RootCollection( |
|
84 | - \OC::$server->getCommentsManager(), |
|
85 | - \OC::$server->getUserManager(), |
|
86 | - \OC::$server->getUserSession(), |
|
87 | - \OC::$server->getEventDispatcher(), |
|
88 | - \OC::$server->getLogger() |
|
89 | - ); |
|
71 | + $systemTagCollection = new SystemTag\SystemTagsByIdCollection( |
|
72 | + \OC::$server->getSystemTagManager(), |
|
73 | + \OC::$server->getUserSession(), |
|
74 | + \OC::$server->getGroupManager() |
|
75 | + ); |
|
76 | + $systemTagRelationsCollection = new SystemTag\SystemTagsRelationsCollection( |
|
77 | + \OC::$server->getSystemTagManager(), |
|
78 | + \OC::$server->getSystemTagObjectMapper(), |
|
79 | + \OC::$server->getUserSession(), |
|
80 | + \OC::$server->getGroupManager(), |
|
81 | + \OC::$server->getEventDispatcher() |
|
82 | + ); |
|
83 | + $commentsCollection = new Comments\RootCollection( |
|
84 | + \OC::$server->getCommentsManager(), |
|
85 | + \OC::$server->getUserManager(), |
|
86 | + \OC::$server->getUserSession(), |
|
87 | + \OC::$server->getEventDispatcher(), |
|
88 | + \OC::$server->getLogger() |
|
89 | + ); |
|
90 | 90 | |
91 | - $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, \OC::$server->getUserManager(), $dispatcher); |
|
92 | - $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, 'principals/users'); |
|
93 | - $usersAddressBookRoot->disableListing = $disableListing; |
|
91 | + $usersCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, \OC::$server->getUserManager(), $dispatcher); |
|
92 | + $usersAddressBookRoot = new AddressBookRoot($userPrincipalBackend, $usersCardDavBackend, 'principals/users'); |
|
93 | + $usersAddressBookRoot->disableListing = $disableListing; |
|
94 | 94 | |
95 | - $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, \OC::$server->getUserManager(), $dispatcher); |
|
96 | - $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, 'principals/system'); |
|
97 | - $systemAddressBookRoot->disableListing = $disableListing; |
|
95 | + $systemCardDavBackend = new CardDavBackend($db, $userPrincipalBackend, \OC::$server->getUserManager(), $dispatcher); |
|
96 | + $systemAddressBookRoot = new AddressBookRoot(new SystemPrincipalBackend(), $systemCardDavBackend, 'principals/system'); |
|
97 | + $systemAddressBookRoot->disableListing = $disableListing; |
|
98 | 98 | |
99 | - $uploadCollection = new Upload\RootCollection($userPrincipalBackend, 'principals/users'); |
|
100 | - $uploadCollection->disableListing = $disableListing; |
|
99 | + $uploadCollection = new Upload\RootCollection($userPrincipalBackend, 'principals/users'); |
|
100 | + $uploadCollection->disableListing = $disableListing; |
|
101 | 101 | |
102 | - $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users'); |
|
103 | - $avatarCollection->disableListing = $disableListing; |
|
102 | + $avatarCollection = new Avatars\RootCollection($userPrincipalBackend, 'principals/users'); |
|
103 | + $avatarCollection->disableListing = $disableListing; |
|
104 | 104 | |
105 | - $children = [ |
|
106 | - new SimpleCollection('principals', [ |
|
107 | - $userPrincipals, |
|
108 | - $groupPrincipals, |
|
109 | - $systemPrincipals]), |
|
110 | - $filesCollection, |
|
111 | - $calendarRoot, |
|
112 | - $publicCalendarRoot, |
|
113 | - new SimpleCollection('addressbooks', [ |
|
114 | - $usersAddressBookRoot, |
|
115 | - $systemAddressBookRoot]), |
|
116 | - $systemTagCollection, |
|
117 | - $systemTagRelationsCollection, |
|
118 | - $commentsCollection, |
|
119 | - $uploadCollection, |
|
120 | - $avatarCollection |
|
121 | - ]; |
|
105 | + $children = [ |
|
106 | + new SimpleCollection('principals', [ |
|
107 | + $userPrincipals, |
|
108 | + $groupPrincipals, |
|
109 | + $systemPrincipals]), |
|
110 | + $filesCollection, |
|
111 | + $calendarRoot, |
|
112 | + $publicCalendarRoot, |
|
113 | + new SimpleCollection('addressbooks', [ |
|
114 | + $usersAddressBookRoot, |
|
115 | + $systemAddressBookRoot]), |
|
116 | + $systemTagCollection, |
|
117 | + $systemTagRelationsCollection, |
|
118 | + $commentsCollection, |
|
119 | + $uploadCollection, |
|
120 | + $avatarCollection |
|
121 | + ]; |
|
122 | 122 | |
123 | - parent::__construct('root', $children); |
|
124 | - } |
|
123 | + parent::__construct('root', $children); |
|
124 | + } |
|
125 | 125 | |
126 | 126 | } |
@@ -63,2164 +63,2164 @@ |
||
63 | 63 | */ |
64 | 64 | class CalDavBackend extends AbstractBackend implements SyncSupport, SubscriptionSupport, SchedulingSupport { |
65 | 65 | |
66 | - const PERSONAL_CALENDAR_URI = 'personal'; |
|
67 | - const PERSONAL_CALENDAR_NAME = 'Personal'; |
|
68 | - |
|
69 | - /** |
|
70 | - * We need to specify a max date, because we need to stop *somewhere* |
|
71 | - * |
|
72 | - * On 32 bit system the maximum for a signed integer is 2147483647, so |
|
73 | - * MAX_DATE cannot be higher than date('Y-m-d', 2147483647) which results |
|
74 | - * in 2038-01-19 to avoid problems when the date is converted |
|
75 | - * to a unix timestamp. |
|
76 | - */ |
|
77 | - const MAX_DATE = '2038-01-01'; |
|
78 | - |
|
79 | - const ACCESS_PUBLIC = 4; |
|
80 | - const CLASSIFICATION_PUBLIC = 0; |
|
81 | - const CLASSIFICATION_PRIVATE = 1; |
|
82 | - const CLASSIFICATION_CONFIDENTIAL = 2; |
|
83 | - |
|
84 | - /** |
|
85 | - * List of CalDAV properties, and how they map to database field names |
|
86 | - * Add your own properties by simply adding on to this array. |
|
87 | - * |
|
88 | - * Note that only string-based properties are supported here. |
|
89 | - * |
|
90 | - * @var array |
|
91 | - */ |
|
92 | - public $propertyMap = [ |
|
93 | - '{DAV:}displayname' => 'displayname', |
|
94 | - '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'description', |
|
95 | - '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => 'timezone', |
|
96 | - '{http://apple.com/ns/ical/}calendar-order' => 'calendarorder', |
|
97 | - '{http://apple.com/ns/ical/}calendar-color' => 'calendarcolor', |
|
98 | - ]; |
|
99 | - |
|
100 | - /** |
|
101 | - * List of subscription properties, and how they map to database field names. |
|
102 | - * |
|
103 | - * @var array |
|
104 | - */ |
|
105 | - public $subscriptionPropertyMap = [ |
|
106 | - '{DAV:}displayname' => 'displayname', |
|
107 | - '{http://apple.com/ns/ical/}refreshrate' => 'refreshrate', |
|
108 | - '{http://apple.com/ns/ical/}calendar-order' => 'calendarorder', |
|
109 | - '{http://apple.com/ns/ical/}calendar-color' => 'calendarcolor', |
|
110 | - '{http://calendarserver.org/ns/}subscribed-strip-todos' => 'striptodos', |
|
111 | - '{http://calendarserver.org/ns/}subscribed-strip-alarms' => 'stripalarms', |
|
112 | - '{http://calendarserver.org/ns/}subscribed-strip-attachments' => 'stripattachments', |
|
113 | - ]; |
|
114 | - |
|
115 | - /** @var array properties to index */ |
|
116 | - public static $indexProperties = ['CATEGORIES', 'COMMENT', 'DESCRIPTION', |
|
117 | - 'LOCATION', 'RESOURCES', 'STATUS', 'SUMMARY', 'ATTENDEE', 'CONTACT', |
|
118 | - 'ORGANIZER']; |
|
119 | - |
|
120 | - /** @var array parameters to index */ |
|
121 | - public static $indexParameters = [ |
|
122 | - 'ATTENDEE' => ['CN'], |
|
123 | - 'ORGANIZER' => ['CN'], |
|
124 | - ]; |
|
125 | - |
|
126 | - /** |
|
127 | - * @var string[] Map of uid => display name |
|
128 | - */ |
|
129 | - protected $userDisplayNames; |
|
130 | - |
|
131 | - /** @var IDBConnection */ |
|
132 | - private $db; |
|
133 | - |
|
134 | - /** @var Backend */ |
|
135 | - private $sharingBackend; |
|
136 | - |
|
137 | - /** @var Principal */ |
|
138 | - private $principalBackend; |
|
139 | - |
|
140 | - /** @var IUserManager */ |
|
141 | - private $userManager; |
|
142 | - |
|
143 | - /** @var ISecureRandom */ |
|
144 | - private $random; |
|
145 | - |
|
146 | - /** @var EventDispatcherInterface */ |
|
147 | - private $dispatcher; |
|
148 | - |
|
149 | - /** @var bool */ |
|
150 | - private $legacyEndpoint; |
|
151 | - |
|
152 | - /** @var string */ |
|
153 | - private $dbObjectPropertiesTable = 'calendarobjects_props'; |
|
154 | - |
|
155 | - /** |
|
156 | - * CalDavBackend constructor. |
|
157 | - * |
|
158 | - * @param IDBConnection $db |
|
159 | - * @param Principal $principalBackend |
|
160 | - * @param IUserManager $userManager |
|
161 | - * @param IConfig $config |
|
162 | - * @param ISecureRandom $random |
|
163 | - * @param EventDispatcherInterface $dispatcher |
|
164 | - * @param bool $legacyEndpoint |
|
165 | - */ |
|
166 | - public function __construct(IDBConnection $db, |
|
167 | - Principal $principalBackend, |
|
168 | - IUserManager $userManager, |
|
169 | - IConfig $config, |
|
170 | - ISecureRandom $random, |
|
171 | - EventDispatcherInterface $dispatcher, |
|
172 | - $legacyEndpoint = false) { |
|
173 | - $this->db = $db; |
|
174 | - $this->principalBackend = $principalBackend; |
|
175 | - $this->userManager = $userManager; |
|
176 | - $this->sharingBackend = new Backend($this->db, $principalBackend, 'calendar'); |
|
177 | - $this->random = $random; |
|
178 | - $this->dispatcher = $dispatcher; |
|
179 | - $this->legacyEndpoint = $legacyEndpoint; |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * Return the number of calendars for a principal |
|
184 | - * |
|
185 | - * By default this excludes the automatically generated birthday calendar |
|
186 | - * |
|
187 | - * @param $principalUri |
|
188 | - * @param bool $excludeBirthday |
|
189 | - * @return int |
|
190 | - */ |
|
191 | - public function getCalendarsForUserCount($principalUri, $excludeBirthday = true) { |
|
192 | - $principalUri = $this->convertPrincipal($principalUri, true); |
|
193 | - $query = $this->db->getQueryBuilder(); |
|
194 | - $query->select($query->createFunction('COUNT(*)')) |
|
195 | - ->from('calendars') |
|
196 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))); |
|
197 | - |
|
198 | - if ($excludeBirthday) { |
|
199 | - $query->andWhere($query->expr()->neq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))); |
|
200 | - } |
|
201 | - |
|
202 | - return (int)$query->execute()->fetchColumn(); |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * Returns a list of calendars for a principal. |
|
207 | - * |
|
208 | - * Every project is an array with the following keys: |
|
209 | - * * id, a unique id that will be used by other functions to modify the |
|
210 | - * calendar. This can be the same as the uri or a database key. |
|
211 | - * * uri, which the basename of the uri with which the calendar is |
|
212 | - * accessed. |
|
213 | - * * principaluri. The owner of the calendar. Almost always the same as |
|
214 | - * principalUri passed to this method. |
|
215 | - * |
|
216 | - * Furthermore it can contain webdav properties in clark notation. A very |
|
217 | - * common one is '{DAV:}displayname'. |
|
218 | - * |
|
219 | - * Many clients also require: |
|
220 | - * {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set |
|
221 | - * For this property, you can just return an instance of |
|
222 | - * Sabre\CalDAV\Property\SupportedCalendarComponentSet. |
|
223 | - * |
|
224 | - * If you return {http://sabredav.org/ns}read-only and set the value to 1, |
|
225 | - * ACL will automatically be put in read-only mode. |
|
226 | - * |
|
227 | - * @param string $principalUri |
|
228 | - * @return array |
|
229 | - */ |
|
230 | - function getCalendarsForUser($principalUri) { |
|
231 | - $principalUriOriginal = $principalUri; |
|
232 | - $principalUri = $this->convertPrincipal($principalUri, true); |
|
233 | - $fields = array_values($this->propertyMap); |
|
234 | - $fields[] = 'id'; |
|
235 | - $fields[] = 'uri'; |
|
236 | - $fields[] = 'synctoken'; |
|
237 | - $fields[] = 'components'; |
|
238 | - $fields[] = 'principaluri'; |
|
239 | - $fields[] = 'transparent'; |
|
240 | - |
|
241 | - // Making fields a comma-delimited list |
|
242 | - $query = $this->db->getQueryBuilder(); |
|
243 | - $query->select($fields)->from('calendars') |
|
244 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
245 | - ->orderBy('calendarorder', 'ASC'); |
|
246 | - $stmt = $query->execute(); |
|
247 | - |
|
248 | - $calendars = []; |
|
249 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
250 | - |
|
251 | - $components = []; |
|
252 | - if ($row['components']) { |
|
253 | - $components = explode(',',$row['components']); |
|
254 | - } |
|
255 | - |
|
256 | - $calendar = [ |
|
257 | - 'id' => $row['id'], |
|
258 | - 'uri' => $row['uri'], |
|
259 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
260 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
261 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
262 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
263 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
264 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
265 | - ]; |
|
266 | - |
|
267 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
268 | - $calendar[$xmlName] = $row[$dbName]; |
|
269 | - } |
|
270 | - |
|
271 | - $this->addOwnerPrincipal($calendar); |
|
272 | - |
|
273 | - if (!isset($calendars[$calendar['id']])) { |
|
274 | - $calendars[$calendar['id']] = $calendar; |
|
275 | - } |
|
276 | - } |
|
277 | - |
|
278 | - $stmt->closeCursor(); |
|
279 | - |
|
280 | - // query for shared calendars |
|
281 | - $principals = $this->principalBackend->getGroupMembership($principalUriOriginal, true); |
|
282 | - $principals = array_map(function($principal) { |
|
283 | - return urldecode($principal); |
|
284 | - }, $principals); |
|
285 | - $principals[]= $principalUri; |
|
286 | - |
|
287 | - $fields = array_values($this->propertyMap); |
|
288 | - $fields[] = 'a.id'; |
|
289 | - $fields[] = 'a.uri'; |
|
290 | - $fields[] = 'a.synctoken'; |
|
291 | - $fields[] = 'a.components'; |
|
292 | - $fields[] = 'a.principaluri'; |
|
293 | - $fields[] = 'a.transparent'; |
|
294 | - $fields[] = 's.access'; |
|
295 | - $query = $this->db->getQueryBuilder(); |
|
296 | - $result = $query->select($fields) |
|
297 | - ->from('dav_shares', 's') |
|
298 | - ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
299 | - ->where($query->expr()->in('s.principaluri', $query->createParameter('principaluri'))) |
|
300 | - ->andWhere($query->expr()->eq('s.type', $query->createParameter('type'))) |
|
301 | - ->setParameter('type', 'calendar') |
|
302 | - ->setParameter('principaluri', $principals, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) |
|
303 | - ->execute(); |
|
304 | - |
|
305 | - $readOnlyPropertyName = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'; |
|
306 | - while($row = $result->fetch()) { |
|
307 | - if ($row['principaluri'] === $principalUri) { |
|
308 | - continue; |
|
309 | - } |
|
310 | - |
|
311 | - $readOnly = (int) $row['access'] === Backend::ACCESS_READ; |
|
312 | - if (isset($calendars[$row['id']])) { |
|
313 | - if ($readOnly) { |
|
314 | - // New share can not have more permissions then the old one. |
|
315 | - continue; |
|
316 | - } |
|
317 | - if (isset($calendars[$row['id']][$readOnlyPropertyName]) && |
|
318 | - $calendars[$row['id']][$readOnlyPropertyName] === 0) { |
|
319 | - // Old share is already read-write, no more permissions can be gained |
|
320 | - continue; |
|
321 | - } |
|
322 | - } |
|
323 | - |
|
324 | - list(, $name) = URLUtil::splitPath($row['principaluri']); |
|
325 | - $uri = $row['uri'] . '_shared_by_' . $name; |
|
326 | - $row['displayname'] = $row['displayname'] . ' (' . $this->getUserDisplayName($name) . ')'; |
|
327 | - $components = []; |
|
328 | - if ($row['components']) { |
|
329 | - $components = explode(',',$row['components']); |
|
330 | - } |
|
331 | - $calendar = [ |
|
332 | - 'id' => $row['id'], |
|
333 | - 'uri' => $uri, |
|
334 | - 'principaluri' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
335 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
336 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
337 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
338 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
339 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
340 | - $readOnlyPropertyName => $readOnly, |
|
341 | - ]; |
|
342 | - |
|
343 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
344 | - $calendar[$xmlName] = $row[$dbName]; |
|
345 | - } |
|
346 | - |
|
347 | - $this->addOwnerPrincipal($calendar); |
|
348 | - |
|
349 | - $calendars[$calendar['id']] = $calendar; |
|
350 | - } |
|
351 | - $result->closeCursor(); |
|
352 | - |
|
353 | - return array_values($calendars); |
|
354 | - } |
|
355 | - |
|
356 | - public function getUsersOwnCalendars($principalUri) { |
|
357 | - $principalUri = $this->convertPrincipal($principalUri, true); |
|
358 | - $fields = array_values($this->propertyMap); |
|
359 | - $fields[] = 'id'; |
|
360 | - $fields[] = 'uri'; |
|
361 | - $fields[] = 'synctoken'; |
|
362 | - $fields[] = 'components'; |
|
363 | - $fields[] = 'principaluri'; |
|
364 | - $fields[] = 'transparent'; |
|
365 | - // Making fields a comma-delimited list |
|
366 | - $query = $this->db->getQueryBuilder(); |
|
367 | - $query->select($fields)->from('calendars') |
|
368 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
369 | - ->orderBy('calendarorder', 'ASC'); |
|
370 | - $stmt = $query->execute(); |
|
371 | - $calendars = []; |
|
372 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
373 | - $components = []; |
|
374 | - if ($row['components']) { |
|
375 | - $components = explode(',',$row['components']); |
|
376 | - } |
|
377 | - $calendar = [ |
|
378 | - 'id' => $row['id'], |
|
379 | - 'uri' => $row['uri'], |
|
380 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
381 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
382 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
383 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
384 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
385 | - ]; |
|
386 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
387 | - $calendar[$xmlName] = $row[$dbName]; |
|
388 | - } |
|
389 | - |
|
390 | - $this->addOwnerPrincipal($calendar); |
|
391 | - |
|
392 | - if (!isset($calendars[$calendar['id']])) { |
|
393 | - $calendars[$calendar['id']] = $calendar; |
|
394 | - } |
|
395 | - } |
|
396 | - $stmt->closeCursor(); |
|
397 | - return array_values($calendars); |
|
398 | - } |
|
399 | - |
|
400 | - |
|
401 | - private function getUserDisplayName($uid) { |
|
402 | - if (!isset($this->userDisplayNames[$uid])) { |
|
403 | - $user = $this->userManager->get($uid); |
|
404 | - |
|
405 | - if ($user instanceof IUser) { |
|
406 | - $this->userDisplayNames[$uid] = $user->getDisplayName(); |
|
407 | - } else { |
|
408 | - $this->userDisplayNames[$uid] = $uid; |
|
409 | - } |
|
410 | - } |
|
411 | - |
|
412 | - return $this->userDisplayNames[$uid]; |
|
413 | - } |
|
66 | + const PERSONAL_CALENDAR_URI = 'personal'; |
|
67 | + const PERSONAL_CALENDAR_NAME = 'Personal'; |
|
68 | + |
|
69 | + /** |
|
70 | + * We need to specify a max date, because we need to stop *somewhere* |
|
71 | + * |
|
72 | + * On 32 bit system the maximum for a signed integer is 2147483647, so |
|
73 | + * MAX_DATE cannot be higher than date('Y-m-d', 2147483647) which results |
|
74 | + * in 2038-01-19 to avoid problems when the date is converted |
|
75 | + * to a unix timestamp. |
|
76 | + */ |
|
77 | + const MAX_DATE = '2038-01-01'; |
|
78 | + |
|
79 | + const ACCESS_PUBLIC = 4; |
|
80 | + const CLASSIFICATION_PUBLIC = 0; |
|
81 | + const CLASSIFICATION_PRIVATE = 1; |
|
82 | + const CLASSIFICATION_CONFIDENTIAL = 2; |
|
83 | + |
|
84 | + /** |
|
85 | + * List of CalDAV properties, and how they map to database field names |
|
86 | + * Add your own properties by simply adding on to this array. |
|
87 | + * |
|
88 | + * Note that only string-based properties are supported here. |
|
89 | + * |
|
90 | + * @var array |
|
91 | + */ |
|
92 | + public $propertyMap = [ |
|
93 | + '{DAV:}displayname' => 'displayname', |
|
94 | + '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'description', |
|
95 | + '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => 'timezone', |
|
96 | + '{http://apple.com/ns/ical/}calendar-order' => 'calendarorder', |
|
97 | + '{http://apple.com/ns/ical/}calendar-color' => 'calendarcolor', |
|
98 | + ]; |
|
99 | + |
|
100 | + /** |
|
101 | + * List of subscription properties, and how they map to database field names. |
|
102 | + * |
|
103 | + * @var array |
|
104 | + */ |
|
105 | + public $subscriptionPropertyMap = [ |
|
106 | + '{DAV:}displayname' => 'displayname', |
|
107 | + '{http://apple.com/ns/ical/}refreshrate' => 'refreshrate', |
|
108 | + '{http://apple.com/ns/ical/}calendar-order' => 'calendarorder', |
|
109 | + '{http://apple.com/ns/ical/}calendar-color' => 'calendarcolor', |
|
110 | + '{http://calendarserver.org/ns/}subscribed-strip-todos' => 'striptodos', |
|
111 | + '{http://calendarserver.org/ns/}subscribed-strip-alarms' => 'stripalarms', |
|
112 | + '{http://calendarserver.org/ns/}subscribed-strip-attachments' => 'stripattachments', |
|
113 | + ]; |
|
114 | + |
|
115 | + /** @var array properties to index */ |
|
116 | + public static $indexProperties = ['CATEGORIES', 'COMMENT', 'DESCRIPTION', |
|
117 | + 'LOCATION', 'RESOURCES', 'STATUS', 'SUMMARY', 'ATTENDEE', 'CONTACT', |
|
118 | + 'ORGANIZER']; |
|
119 | + |
|
120 | + /** @var array parameters to index */ |
|
121 | + public static $indexParameters = [ |
|
122 | + 'ATTENDEE' => ['CN'], |
|
123 | + 'ORGANIZER' => ['CN'], |
|
124 | + ]; |
|
125 | + |
|
126 | + /** |
|
127 | + * @var string[] Map of uid => display name |
|
128 | + */ |
|
129 | + protected $userDisplayNames; |
|
130 | + |
|
131 | + /** @var IDBConnection */ |
|
132 | + private $db; |
|
133 | + |
|
134 | + /** @var Backend */ |
|
135 | + private $sharingBackend; |
|
136 | + |
|
137 | + /** @var Principal */ |
|
138 | + private $principalBackend; |
|
139 | + |
|
140 | + /** @var IUserManager */ |
|
141 | + private $userManager; |
|
142 | + |
|
143 | + /** @var ISecureRandom */ |
|
144 | + private $random; |
|
145 | + |
|
146 | + /** @var EventDispatcherInterface */ |
|
147 | + private $dispatcher; |
|
148 | + |
|
149 | + /** @var bool */ |
|
150 | + private $legacyEndpoint; |
|
151 | + |
|
152 | + /** @var string */ |
|
153 | + private $dbObjectPropertiesTable = 'calendarobjects_props'; |
|
154 | + |
|
155 | + /** |
|
156 | + * CalDavBackend constructor. |
|
157 | + * |
|
158 | + * @param IDBConnection $db |
|
159 | + * @param Principal $principalBackend |
|
160 | + * @param IUserManager $userManager |
|
161 | + * @param IConfig $config |
|
162 | + * @param ISecureRandom $random |
|
163 | + * @param EventDispatcherInterface $dispatcher |
|
164 | + * @param bool $legacyEndpoint |
|
165 | + */ |
|
166 | + public function __construct(IDBConnection $db, |
|
167 | + Principal $principalBackend, |
|
168 | + IUserManager $userManager, |
|
169 | + IConfig $config, |
|
170 | + ISecureRandom $random, |
|
171 | + EventDispatcherInterface $dispatcher, |
|
172 | + $legacyEndpoint = false) { |
|
173 | + $this->db = $db; |
|
174 | + $this->principalBackend = $principalBackend; |
|
175 | + $this->userManager = $userManager; |
|
176 | + $this->sharingBackend = new Backend($this->db, $principalBackend, 'calendar'); |
|
177 | + $this->random = $random; |
|
178 | + $this->dispatcher = $dispatcher; |
|
179 | + $this->legacyEndpoint = $legacyEndpoint; |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * Return the number of calendars for a principal |
|
184 | + * |
|
185 | + * By default this excludes the automatically generated birthday calendar |
|
186 | + * |
|
187 | + * @param $principalUri |
|
188 | + * @param bool $excludeBirthday |
|
189 | + * @return int |
|
190 | + */ |
|
191 | + public function getCalendarsForUserCount($principalUri, $excludeBirthday = true) { |
|
192 | + $principalUri = $this->convertPrincipal($principalUri, true); |
|
193 | + $query = $this->db->getQueryBuilder(); |
|
194 | + $query->select($query->createFunction('COUNT(*)')) |
|
195 | + ->from('calendars') |
|
196 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))); |
|
197 | + |
|
198 | + if ($excludeBirthday) { |
|
199 | + $query->andWhere($query->expr()->neq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))); |
|
200 | + } |
|
201 | + |
|
202 | + return (int)$query->execute()->fetchColumn(); |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * Returns a list of calendars for a principal. |
|
207 | + * |
|
208 | + * Every project is an array with the following keys: |
|
209 | + * * id, a unique id that will be used by other functions to modify the |
|
210 | + * calendar. This can be the same as the uri or a database key. |
|
211 | + * * uri, which the basename of the uri with which the calendar is |
|
212 | + * accessed. |
|
213 | + * * principaluri. The owner of the calendar. Almost always the same as |
|
214 | + * principalUri passed to this method. |
|
215 | + * |
|
216 | + * Furthermore it can contain webdav properties in clark notation. A very |
|
217 | + * common one is '{DAV:}displayname'. |
|
218 | + * |
|
219 | + * Many clients also require: |
|
220 | + * {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set |
|
221 | + * For this property, you can just return an instance of |
|
222 | + * Sabre\CalDAV\Property\SupportedCalendarComponentSet. |
|
223 | + * |
|
224 | + * If you return {http://sabredav.org/ns}read-only and set the value to 1, |
|
225 | + * ACL will automatically be put in read-only mode. |
|
226 | + * |
|
227 | + * @param string $principalUri |
|
228 | + * @return array |
|
229 | + */ |
|
230 | + function getCalendarsForUser($principalUri) { |
|
231 | + $principalUriOriginal = $principalUri; |
|
232 | + $principalUri = $this->convertPrincipal($principalUri, true); |
|
233 | + $fields = array_values($this->propertyMap); |
|
234 | + $fields[] = 'id'; |
|
235 | + $fields[] = 'uri'; |
|
236 | + $fields[] = 'synctoken'; |
|
237 | + $fields[] = 'components'; |
|
238 | + $fields[] = 'principaluri'; |
|
239 | + $fields[] = 'transparent'; |
|
240 | + |
|
241 | + // Making fields a comma-delimited list |
|
242 | + $query = $this->db->getQueryBuilder(); |
|
243 | + $query->select($fields)->from('calendars') |
|
244 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
245 | + ->orderBy('calendarorder', 'ASC'); |
|
246 | + $stmt = $query->execute(); |
|
247 | + |
|
248 | + $calendars = []; |
|
249 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
250 | + |
|
251 | + $components = []; |
|
252 | + if ($row['components']) { |
|
253 | + $components = explode(',',$row['components']); |
|
254 | + } |
|
255 | + |
|
256 | + $calendar = [ |
|
257 | + 'id' => $row['id'], |
|
258 | + 'uri' => $row['uri'], |
|
259 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
260 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
261 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
262 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
263 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
264 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
265 | + ]; |
|
266 | + |
|
267 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
268 | + $calendar[$xmlName] = $row[$dbName]; |
|
269 | + } |
|
270 | + |
|
271 | + $this->addOwnerPrincipal($calendar); |
|
272 | + |
|
273 | + if (!isset($calendars[$calendar['id']])) { |
|
274 | + $calendars[$calendar['id']] = $calendar; |
|
275 | + } |
|
276 | + } |
|
277 | + |
|
278 | + $stmt->closeCursor(); |
|
279 | + |
|
280 | + // query for shared calendars |
|
281 | + $principals = $this->principalBackend->getGroupMembership($principalUriOriginal, true); |
|
282 | + $principals = array_map(function($principal) { |
|
283 | + return urldecode($principal); |
|
284 | + }, $principals); |
|
285 | + $principals[]= $principalUri; |
|
286 | + |
|
287 | + $fields = array_values($this->propertyMap); |
|
288 | + $fields[] = 'a.id'; |
|
289 | + $fields[] = 'a.uri'; |
|
290 | + $fields[] = 'a.synctoken'; |
|
291 | + $fields[] = 'a.components'; |
|
292 | + $fields[] = 'a.principaluri'; |
|
293 | + $fields[] = 'a.transparent'; |
|
294 | + $fields[] = 's.access'; |
|
295 | + $query = $this->db->getQueryBuilder(); |
|
296 | + $result = $query->select($fields) |
|
297 | + ->from('dav_shares', 's') |
|
298 | + ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
299 | + ->where($query->expr()->in('s.principaluri', $query->createParameter('principaluri'))) |
|
300 | + ->andWhere($query->expr()->eq('s.type', $query->createParameter('type'))) |
|
301 | + ->setParameter('type', 'calendar') |
|
302 | + ->setParameter('principaluri', $principals, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) |
|
303 | + ->execute(); |
|
304 | + |
|
305 | + $readOnlyPropertyName = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'; |
|
306 | + while($row = $result->fetch()) { |
|
307 | + if ($row['principaluri'] === $principalUri) { |
|
308 | + continue; |
|
309 | + } |
|
310 | + |
|
311 | + $readOnly = (int) $row['access'] === Backend::ACCESS_READ; |
|
312 | + if (isset($calendars[$row['id']])) { |
|
313 | + if ($readOnly) { |
|
314 | + // New share can not have more permissions then the old one. |
|
315 | + continue; |
|
316 | + } |
|
317 | + if (isset($calendars[$row['id']][$readOnlyPropertyName]) && |
|
318 | + $calendars[$row['id']][$readOnlyPropertyName] === 0) { |
|
319 | + // Old share is already read-write, no more permissions can be gained |
|
320 | + continue; |
|
321 | + } |
|
322 | + } |
|
323 | + |
|
324 | + list(, $name) = URLUtil::splitPath($row['principaluri']); |
|
325 | + $uri = $row['uri'] . '_shared_by_' . $name; |
|
326 | + $row['displayname'] = $row['displayname'] . ' (' . $this->getUserDisplayName($name) . ')'; |
|
327 | + $components = []; |
|
328 | + if ($row['components']) { |
|
329 | + $components = explode(',',$row['components']); |
|
330 | + } |
|
331 | + $calendar = [ |
|
332 | + 'id' => $row['id'], |
|
333 | + 'uri' => $uri, |
|
334 | + 'principaluri' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
335 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
336 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
337 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
338 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
339 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
340 | + $readOnlyPropertyName => $readOnly, |
|
341 | + ]; |
|
342 | + |
|
343 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
344 | + $calendar[$xmlName] = $row[$dbName]; |
|
345 | + } |
|
346 | + |
|
347 | + $this->addOwnerPrincipal($calendar); |
|
348 | + |
|
349 | + $calendars[$calendar['id']] = $calendar; |
|
350 | + } |
|
351 | + $result->closeCursor(); |
|
352 | + |
|
353 | + return array_values($calendars); |
|
354 | + } |
|
355 | + |
|
356 | + public function getUsersOwnCalendars($principalUri) { |
|
357 | + $principalUri = $this->convertPrincipal($principalUri, true); |
|
358 | + $fields = array_values($this->propertyMap); |
|
359 | + $fields[] = 'id'; |
|
360 | + $fields[] = 'uri'; |
|
361 | + $fields[] = 'synctoken'; |
|
362 | + $fields[] = 'components'; |
|
363 | + $fields[] = 'principaluri'; |
|
364 | + $fields[] = 'transparent'; |
|
365 | + // Making fields a comma-delimited list |
|
366 | + $query = $this->db->getQueryBuilder(); |
|
367 | + $query->select($fields)->from('calendars') |
|
368 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
369 | + ->orderBy('calendarorder', 'ASC'); |
|
370 | + $stmt = $query->execute(); |
|
371 | + $calendars = []; |
|
372 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
373 | + $components = []; |
|
374 | + if ($row['components']) { |
|
375 | + $components = explode(',',$row['components']); |
|
376 | + } |
|
377 | + $calendar = [ |
|
378 | + 'id' => $row['id'], |
|
379 | + 'uri' => $row['uri'], |
|
380 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
381 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
382 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
383 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
384 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
385 | + ]; |
|
386 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
387 | + $calendar[$xmlName] = $row[$dbName]; |
|
388 | + } |
|
389 | + |
|
390 | + $this->addOwnerPrincipal($calendar); |
|
391 | + |
|
392 | + if (!isset($calendars[$calendar['id']])) { |
|
393 | + $calendars[$calendar['id']] = $calendar; |
|
394 | + } |
|
395 | + } |
|
396 | + $stmt->closeCursor(); |
|
397 | + return array_values($calendars); |
|
398 | + } |
|
399 | + |
|
400 | + |
|
401 | + private function getUserDisplayName($uid) { |
|
402 | + if (!isset($this->userDisplayNames[$uid])) { |
|
403 | + $user = $this->userManager->get($uid); |
|
404 | + |
|
405 | + if ($user instanceof IUser) { |
|
406 | + $this->userDisplayNames[$uid] = $user->getDisplayName(); |
|
407 | + } else { |
|
408 | + $this->userDisplayNames[$uid] = $uid; |
|
409 | + } |
|
410 | + } |
|
411 | + |
|
412 | + return $this->userDisplayNames[$uid]; |
|
413 | + } |
|
414 | 414 | |
415 | - /** |
|
416 | - * @return array |
|
417 | - */ |
|
418 | - public function getPublicCalendars() { |
|
419 | - $fields = array_values($this->propertyMap); |
|
420 | - $fields[] = 'a.id'; |
|
421 | - $fields[] = 'a.uri'; |
|
422 | - $fields[] = 'a.synctoken'; |
|
423 | - $fields[] = 'a.components'; |
|
424 | - $fields[] = 'a.principaluri'; |
|
425 | - $fields[] = 'a.transparent'; |
|
426 | - $fields[] = 's.access'; |
|
427 | - $fields[] = 's.publicuri'; |
|
428 | - $calendars = []; |
|
429 | - $query = $this->db->getQueryBuilder(); |
|
430 | - $result = $query->select($fields) |
|
431 | - ->from('dav_shares', 's') |
|
432 | - ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
433 | - ->where($query->expr()->in('s.access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
434 | - ->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar'))) |
|
435 | - ->execute(); |
|
436 | - |
|
437 | - while($row = $result->fetch()) { |
|
438 | - list(, $name) = URLUtil::splitPath($row['principaluri']); |
|
439 | - $row['displayname'] = $row['displayname'] . "($name)"; |
|
440 | - $components = []; |
|
441 | - if ($row['components']) { |
|
442 | - $components = explode(',',$row['components']); |
|
443 | - } |
|
444 | - $calendar = [ |
|
445 | - 'id' => $row['id'], |
|
446 | - 'uri' => $row['publicuri'], |
|
447 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
448 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
449 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
450 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
451 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
452 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], $this->legacyEndpoint), |
|
453 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
454 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
455 | - ]; |
|
456 | - |
|
457 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
458 | - $calendar[$xmlName] = $row[$dbName]; |
|
459 | - } |
|
460 | - |
|
461 | - $this->addOwnerPrincipal($calendar); |
|
462 | - |
|
463 | - if (!isset($calendars[$calendar['id']])) { |
|
464 | - $calendars[$calendar['id']] = $calendar; |
|
465 | - } |
|
466 | - } |
|
467 | - $result->closeCursor(); |
|
468 | - |
|
469 | - return array_values($calendars); |
|
470 | - } |
|
471 | - |
|
472 | - /** |
|
473 | - * @param string $uri |
|
474 | - * @return array |
|
475 | - * @throws NotFound |
|
476 | - */ |
|
477 | - public function getPublicCalendar($uri) { |
|
478 | - $fields = array_values($this->propertyMap); |
|
479 | - $fields[] = 'a.id'; |
|
480 | - $fields[] = 'a.uri'; |
|
481 | - $fields[] = 'a.synctoken'; |
|
482 | - $fields[] = 'a.components'; |
|
483 | - $fields[] = 'a.principaluri'; |
|
484 | - $fields[] = 'a.transparent'; |
|
485 | - $fields[] = 's.access'; |
|
486 | - $fields[] = 's.publicuri'; |
|
487 | - $query = $this->db->getQueryBuilder(); |
|
488 | - $result = $query->select($fields) |
|
489 | - ->from('dav_shares', 's') |
|
490 | - ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
491 | - ->where($query->expr()->in('s.access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
492 | - ->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar'))) |
|
493 | - ->andWhere($query->expr()->eq('s.publicuri', $query->createNamedParameter($uri))) |
|
494 | - ->execute(); |
|
495 | - |
|
496 | - $row = $result->fetch(\PDO::FETCH_ASSOC); |
|
497 | - |
|
498 | - $result->closeCursor(); |
|
499 | - |
|
500 | - if ($row === false) { |
|
501 | - throw new NotFound('Node with name \'' . $uri . '\' could not be found'); |
|
502 | - } |
|
503 | - |
|
504 | - list(, $name) = URLUtil::splitPath($row['principaluri']); |
|
505 | - $row['displayname'] = $row['displayname'] . ' ' . "($name)"; |
|
506 | - $components = []; |
|
507 | - if ($row['components']) { |
|
508 | - $components = explode(',',$row['components']); |
|
509 | - } |
|
510 | - $calendar = [ |
|
511 | - 'id' => $row['id'], |
|
512 | - 'uri' => $row['publicuri'], |
|
513 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
514 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
515 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
516 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
517 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
518 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
519 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
520 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
521 | - ]; |
|
522 | - |
|
523 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
524 | - $calendar[$xmlName] = $row[$dbName]; |
|
525 | - } |
|
526 | - |
|
527 | - $this->addOwnerPrincipal($calendar); |
|
528 | - |
|
529 | - return $calendar; |
|
530 | - |
|
531 | - } |
|
532 | - |
|
533 | - /** |
|
534 | - * @param string $principal |
|
535 | - * @param string $uri |
|
536 | - * @return array|null |
|
537 | - */ |
|
538 | - public function getCalendarByUri($principal, $uri) { |
|
539 | - $fields = array_values($this->propertyMap); |
|
540 | - $fields[] = 'id'; |
|
541 | - $fields[] = 'uri'; |
|
542 | - $fields[] = 'synctoken'; |
|
543 | - $fields[] = 'components'; |
|
544 | - $fields[] = 'principaluri'; |
|
545 | - $fields[] = 'transparent'; |
|
546 | - |
|
547 | - // Making fields a comma-delimited list |
|
548 | - $query = $this->db->getQueryBuilder(); |
|
549 | - $query->select($fields)->from('calendars') |
|
550 | - ->where($query->expr()->eq('uri', $query->createNamedParameter($uri))) |
|
551 | - ->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($principal))) |
|
552 | - ->setMaxResults(1); |
|
553 | - $stmt = $query->execute(); |
|
554 | - |
|
555 | - $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
556 | - $stmt->closeCursor(); |
|
557 | - if ($row === false) { |
|
558 | - return null; |
|
559 | - } |
|
560 | - |
|
561 | - $components = []; |
|
562 | - if ($row['components']) { |
|
563 | - $components = explode(',',$row['components']); |
|
564 | - } |
|
565 | - |
|
566 | - $calendar = [ |
|
567 | - 'id' => $row['id'], |
|
568 | - 'uri' => $row['uri'], |
|
569 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
570 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
571 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
572 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
573 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
574 | - ]; |
|
575 | - |
|
576 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
577 | - $calendar[$xmlName] = $row[$dbName]; |
|
578 | - } |
|
579 | - |
|
580 | - $this->addOwnerPrincipal($calendar); |
|
581 | - |
|
582 | - return $calendar; |
|
583 | - } |
|
584 | - |
|
585 | - public function getCalendarById($calendarId) { |
|
586 | - $fields = array_values($this->propertyMap); |
|
587 | - $fields[] = 'id'; |
|
588 | - $fields[] = 'uri'; |
|
589 | - $fields[] = 'synctoken'; |
|
590 | - $fields[] = 'components'; |
|
591 | - $fields[] = 'principaluri'; |
|
592 | - $fields[] = 'transparent'; |
|
593 | - |
|
594 | - // Making fields a comma-delimited list |
|
595 | - $query = $this->db->getQueryBuilder(); |
|
596 | - $query->select($fields)->from('calendars') |
|
597 | - ->where($query->expr()->eq('id', $query->createNamedParameter($calendarId))) |
|
598 | - ->setMaxResults(1); |
|
599 | - $stmt = $query->execute(); |
|
600 | - |
|
601 | - $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
602 | - $stmt->closeCursor(); |
|
603 | - if ($row === false) { |
|
604 | - return null; |
|
605 | - } |
|
606 | - |
|
607 | - $components = []; |
|
608 | - if ($row['components']) { |
|
609 | - $components = explode(',',$row['components']); |
|
610 | - } |
|
611 | - |
|
612 | - $calendar = [ |
|
613 | - 'id' => $row['id'], |
|
614 | - 'uri' => $row['uri'], |
|
615 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
616 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
617 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
618 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
619 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
620 | - ]; |
|
621 | - |
|
622 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
623 | - $calendar[$xmlName] = $row[$dbName]; |
|
624 | - } |
|
625 | - |
|
626 | - $this->addOwnerPrincipal($calendar); |
|
627 | - |
|
628 | - return $calendar; |
|
629 | - } |
|
630 | - |
|
631 | - /** |
|
632 | - * Creates a new calendar for a principal. |
|
633 | - * |
|
634 | - * If the creation was a success, an id must be returned that can be used to reference |
|
635 | - * this calendar in other methods, such as updateCalendar. |
|
636 | - * |
|
637 | - * @param string $principalUri |
|
638 | - * @param string $calendarUri |
|
639 | - * @param array $properties |
|
640 | - * @return int |
|
641 | - */ |
|
642 | - function createCalendar($principalUri, $calendarUri, array $properties) { |
|
643 | - $values = [ |
|
644 | - 'principaluri' => $this->convertPrincipal($principalUri, true), |
|
645 | - 'uri' => $calendarUri, |
|
646 | - 'synctoken' => 1, |
|
647 | - 'transparent' => 0, |
|
648 | - 'components' => 'VEVENT,VTODO', |
|
649 | - 'displayname' => $calendarUri |
|
650 | - ]; |
|
651 | - |
|
652 | - // Default value |
|
653 | - $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set'; |
|
654 | - if (isset($properties[$sccs])) { |
|
655 | - if (!($properties[$sccs] instanceof SupportedCalendarComponentSet)) { |
|
656 | - throw new DAV\Exception('The ' . $sccs . ' property must be of type: \Sabre\CalDAV\Property\SupportedCalendarComponentSet'); |
|
657 | - } |
|
658 | - $values['components'] = implode(',',$properties[$sccs]->getValue()); |
|
659 | - } |
|
660 | - $transp = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
661 | - if (isset($properties[$transp])) { |
|
662 | - $values['transparent'] = (int) ($properties[$transp]->getValue() === 'transparent'); |
|
663 | - } |
|
664 | - |
|
665 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
666 | - if (isset($properties[$xmlName])) { |
|
667 | - $values[$dbName] = $properties[$xmlName]; |
|
668 | - } |
|
669 | - } |
|
670 | - |
|
671 | - $query = $this->db->getQueryBuilder(); |
|
672 | - $query->insert('calendars'); |
|
673 | - foreach($values as $column => $value) { |
|
674 | - $query->setValue($column, $query->createNamedParameter($value)); |
|
675 | - } |
|
676 | - $query->execute(); |
|
677 | - $calendarId = $query->getLastInsertId(); |
|
678 | - |
|
679 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', new GenericEvent( |
|
680 | - '\OCA\DAV\CalDAV\CalDavBackend::createCalendar', |
|
681 | - [ |
|
682 | - 'calendarId' => $calendarId, |
|
683 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
684 | - ])); |
|
685 | - |
|
686 | - return $calendarId; |
|
687 | - } |
|
688 | - |
|
689 | - /** |
|
690 | - * Updates properties for a calendar. |
|
691 | - * |
|
692 | - * The list of mutations is stored in a Sabre\DAV\PropPatch object. |
|
693 | - * To do the actual updates, you must tell this object which properties |
|
694 | - * you're going to process with the handle() method. |
|
695 | - * |
|
696 | - * Calling the handle method is like telling the PropPatch object "I |
|
697 | - * promise I can handle updating this property". |
|
698 | - * |
|
699 | - * Read the PropPatch documentation for more info and examples. |
|
700 | - * |
|
701 | - * @param PropPatch $propPatch |
|
702 | - * @return void |
|
703 | - */ |
|
704 | - function updateCalendar($calendarId, PropPatch $propPatch) { |
|
705 | - $supportedProperties = array_keys($this->propertyMap); |
|
706 | - $supportedProperties[] = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
707 | - |
|
708 | - $propPatch->handle($supportedProperties, function($mutations) use ($calendarId) { |
|
709 | - $newValues = []; |
|
710 | - foreach ($mutations as $propertyName => $propertyValue) { |
|
711 | - |
|
712 | - switch ($propertyName) { |
|
713 | - case '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' : |
|
714 | - $fieldName = 'transparent'; |
|
715 | - $newValues[$fieldName] = (int) ($propertyValue->getValue() === 'transparent'); |
|
716 | - break; |
|
717 | - default : |
|
718 | - $fieldName = $this->propertyMap[$propertyName]; |
|
719 | - $newValues[$fieldName] = $propertyValue; |
|
720 | - break; |
|
721 | - } |
|
722 | - |
|
723 | - } |
|
724 | - $query = $this->db->getQueryBuilder(); |
|
725 | - $query->update('calendars'); |
|
726 | - foreach ($newValues as $fieldName => $value) { |
|
727 | - $query->set($fieldName, $query->createNamedParameter($value)); |
|
728 | - } |
|
729 | - $query->where($query->expr()->eq('id', $query->createNamedParameter($calendarId))); |
|
730 | - $query->execute(); |
|
731 | - |
|
732 | - $this->addChange($calendarId, "", 2); |
|
733 | - |
|
734 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', new GenericEvent( |
|
735 | - '\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', |
|
736 | - [ |
|
737 | - 'calendarId' => $calendarId, |
|
738 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
739 | - 'shares' => $this->getShares($calendarId), |
|
740 | - 'propertyMutations' => $mutations, |
|
741 | - ])); |
|
742 | - |
|
743 | - return true; |
|
744 | - }); |
|
745 | - } |
|
746 | - |
|
747 | - /** |
|
748 | - * Delete a calendar and all it's objects |
|
749 | - * |
|
750 | - * @param mixed $calendarId |
|
751 | - * @return void |
|
752 | - */ |
|
753 | - function deleteCalendar($calendarId) { |
|
754 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', new GenericEvent( |
|
755 | - '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', |
|
756 | - [ |
|
757 | - 'calendarId' => $calendarId, |
|
758 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
759 | - 'shares' => $this->getShares($calendarId), |
|
760 | - ])); |
|
761 | - |
|
762 | - $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ?'); |
|
763 | - $stmt->execute([$calendarId]); |
|
764 | - |
|
765 | - $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
766 | - $stmt->execute([$calendarId]); |
|
767 | - |
|
768 | - $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarchanges` WHERE `calendarid` = ?'); |
|
769 | - $stmt->execute([$calendarId]); |
|
770 | - |
|
771 | - $this->sharingBackend->deleteAllShares($calendarId); |
|
772 | - |
|
773 | - $query = $this->db->getQueryBuilder(); |
|
774 | - $query->delete($this->dbObjectPropertiesTable) |
|
775 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
776 | - ->execute(); |
|
777 | - } |
|
778 | - |
|
779 | - /** |
|
780 | - * Delete all of an user's shares |
|
781 | - * |
|
782 | - * @param string $principaluri |
|
783 | - * @return void |
|
784 | - */ |
|
785 | - function deleteAllSharesByUser($principaluri) { |
|
786 | - $this->sharingBackend->deleteAllSharesByUser($principaluri); |
|
787 | - } |
|
788 | - |
|
789 | - /** |
|
790 | - * Returns all calendar objects within a calendar. |
|
791 | - * |
|
792 | - * Every item contains an array with the following keys: |
|
793 | - * * calendardata - The iCalendar-compatible calendar data |
|
794 | - * * uri - a unique key which will be used to construct the uri. This can |
|
795 | - * be any arbitrary string, but making sure it ends with '.ics' is a |
|
796 | - * good idea. This is only the basename, or filename, not the full |
|
797 | - * path. |
|
798 | - * * lastmodified - a timestamp of the last modification time |
|
799 | - * * etag - An arbitrary string, surrounded by double-quotes. (e.g.: |
|
800 | - * '"abcdef"') |
|
801 | - * * size - The size of the calendar objects, in bytes. |
|
802 | - * * component - optional, a string containing the type of object, such |
|
803 | - * as 'vevent' or 'vtodo'. If specified, this will be used to populate |
|
804 | - * the Content-Type header. |
|
805 | - * |
|
806 | - * Note that the etag is optional, but it's highly encouraged to return for |
|
807 | - * speed reasons. |
|
808 | - * |
|
809 | - * The calendardata is also optional. If it's not returned |
|
810 | - * 'getCalendarObject' will be called later, which *is* expected to return |
|
811 | - * calendardata. |
|
812 | - * |
|
813 | - * If neither etag or size are specified, the calendardata will be |
|
814 | - * used/fetched to determine these numbers. If both are specified the |
|
815 | - * amount of times this is needed is reduced by a great degree. |
|
816 | - * |
|
817 | - * @param mixed $calendarId |
|
818 | - * @return array |
|
819 | - */ |
|
820 | - function getCalendarObjects($calendarId) { |
|
821 | - $query = $this->db->getQueryBuilder(); |
|
822 | - $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'componenttype', 'classification']) |
|
823 | - ->from('calendarobjects') |
|
824 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
825 | - $stmt = $query->execute(); |
|
826 | - |
|
827 | - $result = []; |
|
828 | - foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
829 | - $result[] = [ |
|
830 | - 'id' => $row['id'], |
|
831 | - 'uri' => $row['uri'], |
|
832 | - 'lastmodified' => $row['lastmodified'], |
|
833 | - 'etag' => '"' . $row['etag'] . '"', |
|
834 | - 'calendarid' => $row['calendarid'], |
|
835 | - 'size' => (int)$row['size'], |
|
836 | - 'component' => strtolower($row['componenttype']), |
|
837 | - 'classification'=> (int)$row['classification'] |
|
838 | - ]; |
|
839 | - } |
|
840 | - |
|
841 | - return $result; |
|
842 | - } |
|
843 | - |
|
844 | - /** |
|
845 | - * Returns information from a single calendar object, based on it's object |
|
846 | - * uri. |
|
847 | - * |
|
848 | - * The object uri is only the basename, or filename and not a full path. |
|
849 | - * |
|
850 | - * The returned array must have the same keys as getCalendarObjects. The |
|
851 | - * 'calendardata' object is required here though, while it's not required |
|
852 | - * for getCalendarObjects. |
|
853 | - * |
|
854 | - * This method must return null if the object did not exist. |
|
855 | - * |
|
856 | - * @param mixed $calendarId |
|
857 | - * @param string $objectUri |
|
858 | - * @return array|null |
|
859 | - */ |
|
860 | - function getCalendarObject($calendarId, $objectUri) { |
|
861 | - |
|
862 | - $query = $this->db->getQueryBuilder(); |
|
863 | - $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification']) |
|
864 | - ->from('calendarobjects') |
|
865 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
866 | - ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))); |
|
867 | - $stmt = $query->execute(); |
|
868 | - $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
869 | - |
|
870 | - if(!$row) return null; |
|
871 | - |
|
872 | - return [ |
|
873 | - 'id' => $row['id'], |
|
874 | - 'uri' => $row['uri'], |
|
875 | - 'lastmodified' => $row['lastmodified'], |
|
876 | - 'etag' => '"' . $row['etag'] . '"', |
|
877 | - 'calendarid' => $row['calendarid'], |
|
878 | - 'size' => (int)$row['size'], |
|
879 | - 'calendardata' => $this->readBlob($row['calendardata']), |
|
880 | - 'component' => strtolower($row['componenttype']), |
|
881 | - 'classification'=> (int)$row['classification'] |
|
882 | - ]; |
|
883 | - } |
|
884 | - |
|
885 | - /** |
|
886 | - * Returns a list of calendar objects. |
|
887 | - * |
|
888 | - * This method should work identical to getCalendarObject, but instead |
|
889 | - * return all the calendar objects in the list as an array. |
|
890 | - * |
|
891 | - * If the backend supports this, it may allow for some speed-ups. |
|
892 | - * |
|
893 | - * @param mixed $calendarId |
|
894 | - * @param string[] $uris |
|
895 | - * @return array |
|
896 | - */ |
|
897 | - function getMultipleCalendarObjects($calendarId, array $uris) { |
|
898 | - if (empty($uris)) { |
|
899 | - return []; |
|
900 | - } |
|
901 | - |
|
902 | - $chunks = array_chunk($uris, 100); |
|
903 | - $objects = []; |
|
904 | - |
|
905 | - $query = $this->db->getQueryBuilder(); |
|
906 | - $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification']) |
|
907 | - ->from('calendarobjects') |
|
908 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
909 | - ->andWhere($query->expr()->in('uri', $query->createParameter('uri'))); |
|
910 | - |
|
911 | - foreach ($chunks as $uris) { |
|
912 | - $query->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY); |
|
913 | - $result = $query->execute(); |
|
914 | - |
|
915 | - while ($row = $result->fetch()) { |
|
916 | - $objects[] = [ |
|
917 | - 'id' => $row['id'], |
|
918 | - 'uri' => $row['uri'], |
|
919 | - 'lastmodified' => $row['lastmodified'], |
|
920 | - 'etag' => '"' . $row['etag'] . '"', |
|
921 | - 'calendarid' => $row['calendarid'], |
|
922 | - 'size' => (int)$row['size'], |
|
923 | - 'calendardata' => $this->readBlob($row['calendardata']), |
|
924 | - 'component' => strtolower($row['componenttype']), |
|
925 | - 'classification' => (int)$row['classification'] |
|
926 | - ]; |
|
927 | - } |
|
928 | - $result->closeCursor(); |
|
929 | - } |
|
930 | - return $objects; |
|
931 | - } |
|
932 | - |
|
933 | - /** |
|
934 | - * Creates a new calendar object. |
|
935 | - * |
|
936 | - * The object uri is only the basename, or filename and not a full path. |
|
937 | - * |
|
938 | - * It is possible return an etag from this function, which will be used in |
|
939 | - * the response to this PUT request. Note that the ETag must be surrounded |
|
940 | - * by double-quotes. |
|
941 | - * |
|
942 | - * However, you should only really return this ETag if you don't mangle the |
|
943 | - * calendar-data. If the result of a subsequent GET to this object is not |
|
944 | - * the exact same as this request body, you should omit the ETag. |
|
945 | - * |
|
946 | - * @param mixed $calendarId |
|
947 | - * @param string $objectUri |
|
948 | - * @param string $calendarData |
|
949 | - * @return string |
|
950 | - */ |
|
951 | - function createCalendarObject($calendarId, $objectUri, $calendarData) { |
|
952 | - $extraData = $this->getDenormalizedData($calendarData); |
|
953 | - |
|
954 | - $query = $this->db->getQueryBuilder(); |
|
955 | - $query->insert('calendarobjects') |
|
956 | - ->values([ |
|
957 | - 'calendarid' => $query->createNamedParameter($calendarId), |
|
958 | - 'uri' => $query->createNamedParameter($objectUri), |
|
959 | - 'calendardata' => $query->createNamedParameter($calendarData, IQueryBuilder::PARAM_LOB), |
|
960 | - 'lastmodified' => $query->createNamedParameter(time()), |
|
961 | - 'etag' => $query->createNamedParameter($extraData['etag']), |
|
962 | - 'size' => $query->createNamedParameter($extraData['size']), |
|
963 | - 'componenttype' => $query->createNamedParameter($extraData['componentType']), |
|
964 | - 'firstoccurence' => $query->createNamedParameter($extraData['firstOccurence']), |
|
965 | - 'lastoccurence' => $query->createNamedParameter($extraData['lastOccurence']), |
|
966 | - 'classification' => $query->createNamedParameter($extraData['classification']), |
|
967 | - 'uid' => $query->createNamedParameter($extraData['uid']), |
|
968 | - ]) |
|
969 | - ->execute(); |
|
970 | - |
|
971 | - $this->updateProperties($calendarId, $objectUri, $calendarData); |
|
972 | - |
|
973 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', new GenericEvent( |
|
974 | - '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', |
|
975 | - [ |
|
976 | - 'calendarId' => $calendarId, |
|
977 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
978 | - 'shares' => $this->getShares($calendarId), |
|
979 | - 'objectData' => $this->getCalendarObject($calendarId, $objectUri), |
|
980 | - ] |
|
981 | - )); |
|
982 | - $this->addChange($calendarId, $objectUri, 1); |
|
983 | - |
|
984 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDAVBackend::createCalendarObject', |
|
985 | - new GenericEvent(null, [ |
|
986 | - 'calendarId' => $calendarId, |
|
987 | - 'objectUri' => $objectUri, |
|
988 | - 'calendarData' => $calendarData])); |
|
989 | - |
|
990 | - return '"' . $extraData['etag'] . '"'; |
|
991 | - } |
|
992 | - |
|
993 | - /** |
|
994 | - * Updates an existing calendarobject, based on it's uri. |
|
995 | - * |
|
996 | - * The object uri is only the basename, or filename and not a full path. |
|
997 | - * |
|
998 | - * It is possible return an etag from this function, which will be used in |
|
999 | - * the response to this PUT request. Note that the ETag must be surrounded |
|
1000 | - * by double-quotes. |
|
1001 | - * |
|
1002 | - * However, you should only really return this ETag if you don't mangle the |
|
1003 | - * calendar-data. If the result of a subsequent GET to this object is not |
|
1004 | - * the exact same as this request body, you should omit the ETag. |
|
1005 | - * |
|
1006 | - * @param mixed $calendarId |
|
1007 | - * @param string $objectUri |
|
1008 | - * @param string $calendarData |
|
1009 | - * @return string |
|
1010 | - */ |
|
1011 | - function updateCalendarObject($calendarId, $objectUri, $calendarData) { |
|
1012 | - $extraData = $this->getDenormalizedData($calendarData); |
|
1013 | - $query = $this->db->getQueryBuilder(); |
|
1014 | - $query->update('calendarobjects') |
|
1015 | - ->set('calendardata', $query->createNamedParameter($calendarData, IQueryBuilder::PARAM_LOB)) |
|
1016 | - ->set('lastmodified', $query->createNamedParameter(time())) |
|
1017 | - ->set('etag', $query->createNamedParameter($extraData['etag'])) |
|
1018 | - ->set('size', $query->createNamedParameter($extraData['size'])) |
|
1019 | - ->set('componenttype', $query->createNamedParameter($extraData['componentType'])) |
|
1020 | - ->set('firstoccurence', $query->createNamedParameter($extraData['firstOccurence'])) |
|
1021 | - ->set('lastoccurence', $query->createNamedParameter($extraData['lastOccurence'])) |
|
1022 | - ->set('classification', $query->createNamedParameter($extraData['classification'])) |
|
1023 | - ->set('uid', $query->createNamedParameter($extraData['uid'])) |
|
1024 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
1025 | - ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
1026 | - ->execute(); |
|
1027 | - |
|
1028 | - $this->updateProperties($calendarId, $objectUri, $calendarData); |
|
1029 | - |
|
1030 | - $data = $this->getCalendarObject($calendarId, $objectUri); |
|
1031 | - if (is_array($data)) { |
|
1032 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', new GenericEvent( |
|
1033 | - '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', |
|
1034 | - [ |
|
1035 | - 'calendarId' => $calendarId, |
|
1036 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
1037 | - 'shares' => $this->getShares($calendarId), |
|
1038 | - 'objectData' => $data, |
|
1039 | - ] |
|
1040 | - )); |
|
1041 | - } |
|
1042 | - $this->addChange($calendarId, $objectUri, 2); |
|
1043 | - |
|
1044 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDAVBackend::updateCalendarObject', |
|
1045 | - new GenericEvent(null, [ |
|
1046 | - 'calendarId' => $calendarId, |
|
1047 | - 'objectUri' => $objectUri, |
|
1048 | - 'calendarData' => $calendarData])); |
|
1049 | - |
|
1050 | - return '"' . $extraData['etag'] . '"'; |
|
1051 | - } |
|
1052 | - |
|
1053 | - /** |
|
1054 | - * @param int $calendarObjectId |
|
1055 | - * @param int $classification |
|
1056 | - */ |
|
1057 | - public function setClassification($calendarObjectId, $classification) { |
|
1058 | - if (!in_array($classification, [ |
|
1059 | - self::CLASSIFICATION_PUBLIC, self::CLASSIFICATION_PRIVATE, self::CLASSIFICATION_CONFIDENTIAL |
|
1060 | - ])) { |
|
1061 | - throw new \InvalidArgumentException(); |
|
1062 | - } |
|
1063 | - $query = $this->db->getQueryBuilder(); |
|
1064 | - $query->update('calendarobjects') |
|
1065 | - ->set('classification', $query->createNamedParameter($classification)) |
|
1066 | - ->where($query->expr()->eq('id', $query->createNamedParameter($calendarObjectId))) |
|
1067 | - ->execute(); |
|
1068 | - } |
|
1069 | - |
|
1070 | - /** |
|
1071 | - * Deletes an existing calendar object. |
|
1072 | - * |
|
1073 | - * The object uri is only the basename, or filename and not a full path. |
|
1074 | - * |
|
1075 | - * @param mixed $calendarId |
|
1076 | - * @param string $objectUri |
|
1077 | - * @return void |
|
1078 | - */ |
|
1079 | - function deleteCalendarObject($calendarId, $objectUri) { |
|
1080 | - $data = $this->getCalendarObject($calendarId, $objectUri); |
|
1081 | - if (is_array($data)) { |
|
1082 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', new GenericEvent( |
|
1083 | - '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', |
|
1084 | - [ |
|
1085 | - 'calendarId' => $calendarId, |
|
1086 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
1087 | - 'shares' => $this->getShares($calendarId), |
|
1088 | - 'objectData' => $data, |
|
1089 | - ] |
|
1090 | - )); |
|
1091 | - } |
|
1092 | - |
|
1093 | - $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ? AND `uri` = ?'); |
|
1094 | - $stmt->execute([$calendarId, $objectUri]); |
|
1095 | - |
|
1096 | - $this->purgeProperties($calendarId, $data['id']); |
|
1097 | - |
|
1098 | - $this->addChange($calendarId, $objectUri, 3); |
|
1099 | - |
|
1100 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDAVBackend::deleteCalendarObject', |
|
1101 | - new GenericEvent(null, [ |
|
1102 | - 'calendarId' => $calendarId, |
|
1103 | - 'objectUri' => $objectUri])); |
|
1104 | - } |
|
1105 | - |
|
1106 | - /** |
|
1107 | - * Performs a calendar-query on the contents of this calendar. |
|
1108 | - * |
|
1109 | - * The calendar-query is defined in RFC4791 : CalDAV. Using the |
|
1110 | - * calendar-query it is possible for a client to request a specific set of |
|
1111 | - * object, based on contents of iCalendar properties, date-ranges and |
|
1112 | - * iCalendar component types (VTODO, VEVENT). |
|
1113 | - * |
|
1114 | - * This method should just return a list of (relative) urls that match this |
|
1115 | - * query. |
|
1116 | - * |
|
1117 | - * The list of filters are specified as an array. The exact array is |
|
1118 | - * documented by Sabre\CalDAV\CalendarQueryParser. |
|
1119 | - * |
|
1120 | - * Note that it is extremely likely that getCalendarObject for every path |
|
1121 | - * returned from this method will be called almost immediately after. You |
|
1122 | - * may want to anticipate this to speed up these requests. |
|
1123 | - * |
|
1124 | - * This method provides a default implementation, which parses *all* the |
|
1125 | - * iCalendar objects in the specified calendar. |
|
1126 | - * |
|
1127 | - * This default may well be good enough for personal use, and calendars |
|
1128 | - * that aren't very large. But if you anticipate high usage, big calendars |
|
1129 | - * or high loads, you are strongly advised to optimize certain paths. |
|
1130 | - * |
|
1131 | - * The best way to do so is override this method and to optimize |
|
1132 | - * specifically for 'common filters'. |
|
1133 | - * |
|
1134 | - * Requests that are extremely common are: |
|
1135 | - * * requests for just VEVENTS |
|
1136 | - * * requests for just VTODO |
|
1137 | - * * requests with a time-range-filter on either VEVENT or VTODO. |
|
1138 | - * |
|
1139 | - * ..and combinations of these requests. It may not be worth it to try to |
|
1140 | - * handle every possible situation and just rely on the (relatively |
|
1141 | - * easy to use) CalendarQueryValidator to handle the rest. |
|
1142 | - * |
|
1143 | - * Note that especially time-range-filters may be difficult to parse. A |
|
1144 | - * time-range filter specified on a VEVENT must for instance also handle |
|
1145 | - * recurrence rules correctly. |
|
1146 | - * A good example of how to interprete all these filters can also simply |
|
1147 | - * be found in Sabre\CalDAV\CalendarQueryFilter. This class is as correct |
|
1148 | - * as possible, so it gives you a good idea on what type of stuff you need |
|
1149 | - * to think of. |
|
1150 | - * |
|
1151 | - * @param mixed $calendarId |
|
1152 | - * @param array $filters |
|
1153 | - * @return array |
|
1154 | - */ |
|
1155 | - function calendarQuery($calendarId, array $filters) { |
|
1156 | - $componentType = null; |
|
1157 | - $requirePostFilter = true; |
|
1158 | - $timeRange = null; |
|
1159 | - |
|
1160 | - // if no filters were specified, we don't need to filter after a query |
|
1161 | - if (!$filters['prop-filters'] && !$filters['comp-filters']) { |
|
1162 | - $requirePostFilter = false; |
|
1163 | - } |
|
1164 | - |
|
1165 | - // Figuring out if there's a component filter |
|
1166 | - if (count($filters['comp-filters']) > 0 && !$filters['comp-filters'][0]['is-not-defined']) { |
|
1167 | - $componentType = $filters['comp-filters'][0]['name']; |
|
1168 | - |
|
1169 | - // Checking if we need post-filters |
|
1170 | - if (!$filters['prop-filters'] && !$filters['comp-filters'][0]['comp-filters'] && !$filters['comp-filters'][0]['time-range'] && !$filters['comp-filters'][0]['prop-filters']) { |
|
1171 | - $requirePostFilter = false; |
|
1172 | - } |
|
1173 | - // There was a time-range filter |
|
1174 | - if ($componentType == 'VEVENT' && isset($filters['comp-filters'][0]['time-range'])) { |
|
1175 | - $timeRange = $filters['comp-filters'][0]['time-range']; |
|
1176 | - |
|
1177 | - // If start time OR the end time is not specified, we can do a |
|
1178 | - // 100% accurate mysql query. |
|
1179 | - if (!$filters['prop-filters'] && !$filters['comp-filters'][0]['comp-filters'] && !$filters['comp-filters'][0]['prop-filters'] && (!$timeRange['start'] || !$timeRange['end'])) { |
|
1180 | - $requirePostFilter = false; |
|
1181 | - } |
|
1182 | - } |
|
1183 | - |
|
1184 | - } |
|
1185 | - $columns = ['uri']; |
|
1186 | - if ($requirePostFilter) { |
|
1187 | - $columns = ['uri', 'calendardata']; |
|
1188 | - } |
|
1189 | - $query = $this->db->getQueryBuilder(); |
|
1190 | - $query->select($columns) |
|
1191 | - ->from('calendarobjects') |
|
1192 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
1193 | - |
|
1194 | - if ($componentType) { |
|
1195 | - $query->andWhere($query->expr()->eq('componenttype', $query->createNamedParameter($componentType))); |
|
1196 | - } |
|
1197 | - |
|
1198 | - if ($timeRange && $timeRange['start']) { |
|
1199 | - $query->andWhere($query->expr()->gt('lastoccurence', $query->createNamedParameter($timeRange['start']->getTimeStamp()))); |
|
1200 | - } |
|
1201 | - if ($timeRange && $timeRange['end']) { |
|
1202 | - $query->andWhere($query->expr()->lt('firstoccurence', $query->createNamedParameter($timeRange['end']->getTimeStamp()))); |
|
1203 | - } |
|
1204 | - |
|
1205 | - $stmt = $query->execute(); |
|
1206 | - |
|
1207 | - $result = []; |
|
1208 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1209 | - if ($requirePostFilter) { |
|
1210 | - if (!$this->validateFilterForObject($row, $filters)) { |
|
1211 | - continue; |
|
1212 | - } |
|
1213 | - } |
|
1214 | - $result[] = $row['uri']; |
|
1215 | - } |
|
1216 | - |
|
1217 | - return $result; |
|
1218 | - } |
|
1219 | - |
|
1220 | - /** |
|
1221 | - * custom Nextcloud search extension for CalDAV |
|
1222 | - * |
|
1223 | - * @param string $principalUri |
|
1224 | - * @param array $filters |
|
1225 | - * @param integer|null $limit |
|
1226 | - * @param integer|null $offset |
|
1227 | - * @return array |
|
1228 | - */ |
|
1229 | - public function calendarSearch($principalUri, array $filters, $limit=null, $offset=null) { |
|
1230 | - $calendars = $this->getCalendarsForUser($principalUri); |
|
1231 | - $ownCalendars = []; |
|
1232 | - $sharedCalendars = []; |
|
1233 | - |
|
1234 | - $uriMapper = []; |
|
1235 | - |
|
1236 | - foreach($calendars as $calendar) { |
|
1237 | - if ($calendar['{http://owncloud.org/ns}owner-principal'] === $principalUri) { |
|
1238 | - $ownCalendars[] = $calendar['id']; |
|
1239 | - } else { |
|
1240 | - $sharedCalendars[] = $calendar['id']; |
|
1241 | - } |
|
1242 | - $uriMapper[$calendar['id']] = $calendar['uri']; |
|
1243 | - } |
|
1244 | - if (count($ownCalendars) === 0 && count($sharedCalendars) === 0) { |
|
1245 | - return []; |
|
1246 | - } |
|
1247 | - |
|
1248 | - $query = $this->db->getQueryBuilder(); |
|
1249 | - // Calendar id expressions |
|
1250 | - $calendarExpressions = []; |
|
1251 | - foreach($ownCalendars as $id) { |
|
1252 | - $calendarExpressions[] = $query->expr() |
|
1253 | - ->eq('c.calendarid', $query->createNamedParameter($id)); |
|
1254 | - } |
|
1255 | - foreach($sharedCalendars as $id) { |
|
1256 | - $calendarExpressions[] = $query->expr()->andX( |
|
1257 | - $query->expr()->eq('c.calendarid', |
|
1258 | - $query->createNamedParameter($id)), |
|
1259 | - $query->expr()->eq('c.classification', |
|
1260 | - $query->createNamedParameter(self::CLASSIFICATION_PUBLIC)) |
|
1261 | - ); |
|
1262 | - } |
|
1263 | - |
|
1264 | - if (count($calendarExpressions) === 1) { |
|
1265 | - $calExpr = $calendarExpressions[0]; |
|
1266 | - } else { |
|
1267 | - $calExpr = call_user_func_array([$query->expr(), 'orX'], $calendarExpressions); |
|
1268 | - } |
|
1269 | - |
|
1270 | - // Component expressions |
|
1271 | - $compExpressions = []; |
|
1272 | - foreach($filters['comps'] as $comp) { |
|
1273 | - $compExpressions[] = $query->expr() |
|
1274 | - ->eq('c.componenttype', $query->createNamedParameter($comp)); |
|
1275 | - } |
|
1276 | - |
|
1277 | - if (count($compExpressions) === 1) { |
|
1278 | - $compExpr = $compExpressions[0]; |
|
1279 | - } else { |
|
1280 | - $compExpr = call_user_func_array([$query->expr(), 'orX'], $compExpressions); |
|
1281 | - } |
|
1282 | - |
|
1283 | - if (!isset($filters['props'])) { |
|
1284 | - $filters['props'] = []; |
|
1285 | - } |
|
1286 | - if (!isset($filters['params'])) { |
|
1287 | - $filters['params'] = []; |
|
1288 | - } |
|
1289 | - |
|
1290 | - $propParamExpressions = []; |
|
1291 | - foreach($filters['props'] as $prop) { |
|
1292 | - $propParamExpressions[] = $query->expr()->andX( |
|
1293 | - $query->expr()->eq('i.name', $query->createNamedParameter($prop)), |
|
1294 | - $query->expr()->isNull('i.parameter') |
|
1295 | - ); |
|
1296 | - } |
|
1297 | - foreach($filters['params'] as $param) { |
|
1298 | - $propParamExpressions[] = $query->expr()->andX( |
|
1299 | - $query->expr()->eq('i.name', $query->createNamedParameter($param['property'])), |
|
1300 | - $query->expr()->eq('i.parameter', $query->createNamedParameter($param['parameter'])) |
|
1301 | - ); |
|
1302 | - } |
|
1303 | - |
|
1304 | - if (count($propParamExpressions) === 1) { |
|
1305 | - $propParamExpr = $propParamExpressions[0]; |
|
1306 | - } else { |
|
1307 | - $propParamExpr = call_user_func_array([$query->expr(), 'orX'], $propParamExpressions); |
|
1308 | - } |
|
1309 | - |
|
1310 | - $query->select(['c.calendarid', 'c.uri']) |
|
1311 | - ->from($this->dbObjectPropertiesTable, 'i') |
|
1312 | - ->join('i', 'calendarobjects', 'c', $query->expr()->eq('i.objectid', 'c.id')) |
|
1313 | - ->where($calExpr) |
|
1314 | - ->andWhere($compExpr) |
|
1315 | - ->andWhere($propParamExpr) |
|
1316 | - ->andWhere($query->expr()->iLike('i.value', |
|
1317 | - $query->createNamedParameter('%'.$this->db->escapeLikeParameter($filters['search-term']).'%'))); |
|
1318 | - |
|
1319 | - if ($offset) { |
|
1320 | - $query->setFirstResult($offset); |
|
1321 | - } |
|
1322 | - if ($limit) { |
|
1323 | - $query->setMaxResults($limit); |
|
1324 | - } |
|
1325 | - |
|
1326 | - $stmt = $query->execute(); |
|
1327 | - |
|
1328 | - $result = []; |
|
1329 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1330 | - $path = $uriMapper[$row['calendarid']] . '/' . $row['uri']; |
|
1331 | - if (!in_array($path, $result)) { |
|
1332 | - $result[] = $path; |
|
1333 | - } |
|
1334 | - } |
|
1335 | - |
|
1336 | - return $result; |
|
1337 | - } |
|
1338 | - |
|
1339 | - /** |
|
1340 | - * Searches through all of a users calendars and calendar objects to find |
|
1341 | - * an object with a specific UID. |
|
1342 | - * |
|
1343 | - * This method should return the path to this object, relative to the |
|
1344 | - * calendar home, so this path usually only contains two parts: |
|
1345 | - * |
|
1346 | - * calendarpath/objectpath.ics |
|
1347 | - * |
|
1348 | - * If the uid is not found, return null. |
|
1349 | - * |
|
1350 | - * This method should only consider * objects that the principal owns, so |
|
1351 | - * any calendars owned by other principals that also appear in this |
|
1352 | - * collection should be ignored. |
|
1353 | - * |
|
1354 | - * @param string $principalUri |
|
1355 | - * @param string $uid |
|
1356 | - * @return string|null |
|
1357 | - */ |
|
1358 | - function getCalendarObjectByUID($principalUri, $uid) { |
|
1359 | - |
|
1360 | - $query = $this->db->getQueryBuilder(); |
|
1361 | - $query->selectAlias('c.uri', 'calendaruri')->selectAlias('co.uri', 'objecturi') |
|
1362 | - ->from('calendarobjects', 'co') |
|
1363 | - ->leftJoin('co', 'calendars', 'c', $query->expr()->eq('co.calendarid', 'c.id')) |
|
1364 | - ->where($query->expr()->eq('c.principaluri', $query->createNamedParameter($principalUri))) |
|
1365 | - ->andWhere($query->expr()->eq('co.uid', $query->createNamedParameter($uid))); |
|
1366 | - |
|
1367 | - $stmt = $query->execute(); |
|
1368 | - |
|
1369 | - if ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1370 | - return $row['calendaruri'] . '/' . $row['objecturi']; |
|
1371 | - } |
|
1372 | - |
|
1373 | - return null; |
|
1374 | - } |
|
1375 | - |
|
1376 | - /** |
|
1377 | - * The getChanges method returns all the changes that have happened, since |
|
1378 | - * the specified syncToken in the specified calendar. |
|
1379 | - * |
|
1380 | - * This function should return an array, such as the following: |
|
1381 | - * |
|
1382 | - * [ |
|
1383 | - * 'syncToken' => 'The current synctoken', |
|
1384 | - * 'added' => [ |
|
1385 | - * 'new.txt', |
|
1386 | - * ], |
|
1387 | - * 'modified' => [ |
|
1388 | - * 'modified.txt', |
|
1389 | - * ], |
|
1390 | - * 'deleted' => [ |
|
1391 | - * 'foo.php.bak', |
|
1392 | - * 'old.txt' |
|
1393 | - * ] |
|
1394 | - * ); |
|
1395 | - * |
|
1396 | - * The returned syncToken property should reflect the *current* syncToken |
|
1397 | - * of the calendar, as reported in the {http://sabredav.org/ns}sync-token |
|
1398 | - * property This is * needed here too, to ensure the operation is atomic. |
|
1399 | - * |
|
1400 | - * If the $syncToken argument is specified as null, this is an initial |
|
1401 | - * sync, and all members should be reported. |
|
1402 | - * |
|
1403 | - * The modified property is an array of nodenames that have changed since |
|
1404 | - * the last token. |
|
1405 | - * |
|
1406 | - * The deleted property is an array with nodenames, that have been deleted |
|
1407 | - * from collection. |
|
1408 | - * |
|
1409 | - * The $syncLevel argument is basically the 'depth' of the report. If it's |
|
1410 | - * 1, you only have to report changes that happened only directly in |
|
1411 | - * immediate descendants. If it's 2, it should also include changes from |
|
1412 | - * the nodes below the child collections. (grandchildren) |
|
1413 | - * |
|
1414 | - * The $limit argument allows a client to specify how many results should |
|
1415 | - * be returned at most. If the limit is not specified, it should be treated |
|
1416 | - * as infinite. |
|
1417 | - * |
|
1418 | - * If the limit (infinite or not) is higher than you're willing to return, |
|
1419 | - * you should throw a Sabre\DAV\Exception\TooMuchMatches() exception. |
|
1420 | - * |
|
1421 | - * If the syncToken is expired (due to data cleanup) or unknown, you must |
|
1422 | - * return null. |
|
1423 | - * |
|
1424 | - * The limit is 'suggestive'. You are free to ignore it. |
|
1425 | - * |
|
1426 | - * @param string $calendarId |
|
1427 | - * @param string $syncToken |
|
1428 | - * @param int $syncLevel |
|
1429 | - * @param int $limit |
|
1430 | - * @return array |
|
1431 | - */ |
|
1432 | - function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limit = null) { |
|
1433 | - // Current synctoken |
|
1434 | - $stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
1435 | - $stmt->execute([ $calendarId ]); |
|
1436 | - $currentToken = $stmt->fetchColumn(0); |
|
1437 | - |
|
1438 | - if (is_null($currentToken)) { |
|
1439 | - return null; |
|
1440 | - } |
|
1441 | - |
|
1442 | - $result = [ |
|
1443 | - 'syncToken' => $currentToken, |
|
1444 | - 'added' => [], |
|
1445 | - 'modified' => [], |
|
1446 | - 'deleted' => [], |
|
1447 | - ]; |
|
1448 | - |
|
1449 | - if ($syncToken) { |
|
1450 | - |
|
1451 | - $query = "SELECT `uri`, `operation` FROM `*PREFIX*calendarchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `calendarid` = ? ORDER BY `synctoken`"; |
|
1452 | - if ($limit>0) { |
|
1453 | - $query.= " `LIMIT` " . (int)$limit; |
|
1454 | - } |
|
1455 | - |
|
1456 | - // Fetching all changes |
|
1457 | - $stmt = $this->db->prepare($query); |
|
1458 | - $stmt->execute([$syncToken, $currentToken, $calendarId]); |
|
1459 | - |
|
1460 | - $changes = []; |
|
1461 | - |
|
1462 | - // This loop ensures that any duplicates are overwritten, only the |
|
1463 | - // last change on a node is relevant. |
|
1464 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1465 | - |
|
1466 | - $changes[$row['uri']] = $row['operation']; |
|
1467 | - |
|
1468 | - } |
|
1469 | - |
|
1470 | - foreach($changes as $uri => $operation) { |
|
1471 | - |
|
1472 | - switch($operation) { |
|
1473 | - case 1 : |
|
1474 | - $result['added'][] = $uri; |
|
1475 | - break; |
|
1476 | - case 2 : |
|
1477 | - $result['modified'][] = $uri; |
|
1478 | - break; |
|
1479 | - case 3 : |
|
1480 | - $result['deleted'][] = $uri; |
|
1481 | - break; |
|
1482 | - } |
|
1483 | - |
|
1484 | - } |
|
1485 | - } else { |
|
1486 | - // No synctoken supplied, this is the initial sync. |
|
1487 | - $query = "SELECT `uri` FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ?"; |
|
1488 | - $stmt = $this->db->prepare($query); |
|
1489 | - $stmt->execute([$calendarId]); |
|
1490 | - |
|
1491 | - $result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN); |
|
1492 | - } |
|
1493 | - return $result; |
|
1494 | - |
|
1495 | - } |
|
1496 | - |
|
1497 | - /** |
|
1498 | - * Returns a list of subscriptions for a principal. |
|
1499 | - * |
|
1500 | - * Every subscription is an array with the following keys: |
|
1501 | - * * id, a unique id that will be used by other functions to modify the |
|
1502 | - * subscription. This can be the same as the uri or a database key. |
|
1503 | - * * uri. This is just the 'base uri' or 'filename' of the subscription. |
|
1504 | - * * principaluri. The owner of the subscription. Almost always the same as |
|
1505 | - * principalUri passed to this method. |
|
1506 | - * |
|
1507 | - * Furthermore, all the subscription info must be returned too: |
|
1508 | - * |
|
1509 | - * 1. {DAV:}displayname |
|
1510 | - * 2. {http://apple.com/ns/ical/}refreshrate |
|
1511 | - * 3. {http://calendarserver.org/ns/}subscribed-strip-todos (omit if todos |
|
1512 | - * should not be stripped). |
|
1513 | - * 4. {http://calendarserver.org/ns/}subscribed-strip-alarms (omit if alarms |
|
1514 | - * should not be stripped). |
|
1515 | - * 5. {http://calendarserver.org/ns/}subscribed-strip-attachments (omit if |
|
1516 | - * attachments should not be stripped). |
|
1517 | - * 6. {http://calendarserver.org/ns/}source (Must be a |
|
1518 | - * Sabre\DAV\Property\Href). |
|
1519 | - * 7. {http://apple.com/ns/ical/}calendar-color |
|
1520 | - * 8. {http://apple.com/ns/ical/}calendar-order |
|
1521 | - * 9. {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set |
|
1522 | - * (should just be an instance of |
|
1523 | - * Sabre\CalDAV\Property\SupportedCalendarComponentSet, with a bunch of |
|
1524 | - * default components). |
|
1525 | - * |
|
1526 | - * @param string $principalUri |
|
1527 | - * @return array |
|
1528 | - */ |
|
1529 | - function getSubscriptionsForUser($principalUri) { |
|
1530 | - $fields = array_values($this->subscriptionPropertyMap); |
|
1531 | - $fields[] = 'id'; |
|
1532 | - $fields[] = 'uri'; |
|
1533 | - $fields[] = 'source'; |
|
1534 | - $fields[] = 'principaluri'; |
|
1535 | - $fields[] = 'lastmodified'; |
|
1536 | - |
|
1537 | - $query = $this->db->getQueryBuilder(); |
|
1538 | - $query->select($fields) |
|
1539 | - ->from('calendarsubscriptions') |
|
1540 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1541 | - ->orderBy('calendarorder', 'asc'); |
|
1542 | - $stmt =$query->execute(); |
|
1543 | - |
|
1544 | - $subscriptions = []; |
|
1545 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1546 | - |
|
1547 | - $subscription = [ |
|
1548 | - 'id' => $row['id'], |
|
1549 | - 'uri' => $row['uri'], |
|
1550 | - 'principaluri' => $row['principaluri'], |
|
1551 | - 'source' => $row['source'], |
|
1552 | - 'lastmodified' => $row['lastmodified'], |
|
1553 | - |
|
1554 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO', 'VEVENT']), |
|
1555 | - ]; |
|
1556 | - |
|
1557 | - foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1558 | - if (!is_null($row[$dbName])) { |
|
1559 | - $subscription[$xmlName] = $row[$dbName]; |
|
1560 | - } |
|
1561 | - } |
|
1562 | - |
|
1563 | - $subscriptions[] = $subscription; |
|
1564 | - |
|
1565 | - } |
|
1566 | - |
|
1567 | - return $subscriptions; |
|
1568 | - } |
|
1569 | - |
|
1570 | - /** |
|
1571 | - * Creates a new subscription for a principal. |
|
1572 | - * |
|
1573 | - * If the creation was a success, an id must be returned that can be used to reference |
|
1574 | - * this subscription in other methods, such as updateSubscription. |
|
1575 | - * |
|
1576 | - * @param string $principalUri |
|
1577 | - * @param string $uri |
|
1578 | - * @param array $properties |
|
1579 | - * @return mixed |
|
1580 | - */ |
|
1581 | - function createSubscription($principalUri, $uri, array $properties) { |
|
1582 | - |
|
1583 | - if (!isset($properties['{http://calendarserver.org/ns/}source'])) { |
|
1584 | - throw new Forbidden('The {http://calendarserver.org/ns/}source property is required when creating subscriptions'); |
|
1585 | - } |
|
1586 | - |
|
1587 | - $values = [ |
|
1588 | - 'principaluri' => $principalUri, |
|
1589 | - 'uri' => $uri, |
|
1590 | - 'source' => $properties['{http://calendarserver.org/ns/}source']->getHref(), |
|
1591 | - 'lastmodified' => time(), |
|
1592 | - ]; |
|
1593 | - |
|
1594 | - $propertiesBoolean = ['striptodos', 'stripalarms', 'stripattachments']; |
|
1595 | - |
|
1596 | - foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1597 | - if (array_key_exists($xmlName, $properties)) { |
|
1598 | - $values[$dbName] = $properties[$xmlName]; |
|
1599 | - if (in_array($dbName, $propertiesBoolean)) { |
|
1600 | - $values[$dbName] = true; |
|
1601 | - } |
|
1602 | - } |
|
1603 | - } |
|
1604 | - |
|
1605 | - $valuesToInsert = array(); |
|
1606 | - |
|
1607 | - $query = $this->db->getQueryBuilder(); |
|
1608 | - |
|
1609 | - foreach (array_keys($values) as $name) { |
|
1610 | - $valuesToInsert[$name] = $query->createNamedParameter($values[$name]); |
|
1611 | - } |
|
1612 | - |
|
1613 | - $query->insert('calendarsubscriptions') |
|
1614 | - ->values($valuesToInsert) |
|
1615 | - ->execute(); |
|
1616 | - |
|
1617 | - return $this->db->lastInsertId('*PREFIX*calendarsubscriptions'); |
|
1618 | - } |
|
1619 | - |
|
1620 | - /** |
|
1621 | - * Updates a subscription |
|
1622 | - * |
|
1623 | - * The list of mutations is stored in a Sabre\DAV\PropPatch object. |
|
1624 | - * To do the actual updates, you must tell this object which properties |
|
1625 | - * you're going to process with the handle() method. |
|
1626 | - * |
|
1627 | - * Calling the handle method is like telling the PropPatch object "I |
|
1628 | - * promise I can handle updating this property". |
|
1629 | - * |
|
1630 | - * Read the PropPatch documentation for more info and examples. |
|
1631 | - * |
|
1632 | - * @param mixed $subscriptionId |
|
1633 | - * @param PropPatch $propPatch |
|
1634 | - * @return void |
|
1635 | - */ |
|
1636 | - function updateSubscription($subscriptionId, PropPatch $propPatch) { |
|
1637 | - $supportedProperties = array_keys($this->subscriptionPropertyMap); |
|
1638 | - $supportedProperties[] = '{http://calendarserver.org/ns/}source'; |
|
1639 | - |
|
1640 | - $propPatch->handle($supportedProperties, function($mutations) use ($subscriptionId) { |
|
1641 | - |
|
1642 | - $newValues = []; |
|
1643 | - |
|
1644 | - foreach($mutations as $propertyName=>$propertyValue) { |
|
1645 | - if ($propertyName === '{http://calendarserver.org/ns/}source') { |
|
1646 | - $newValues['source'] = $propertyValue->getHref(); |
|
1647 | - } else { |
|
1648 | - $fieldName = $this->subscriptionPropertyMap[$propertyName]; |
|
1649 | - $newValues[$fieldName] = $propertyValue; |
|
1650 | - } |
|
1651 | - } |
|
1652 | - |
|
1653 | - $query = $this->db->getQueryBuilder(); |
|
1654 | - $query->update('calendarsubscriptions') |
|
1655 | - ->set('lastmodified', $query->createNamedParameter(time())); |
|
1656 | - foreach($newValues as $fieldName=>$value) { |
|
1657 | - $query->set($fieldName, $query->createNamedParameter($value)); |
|
1658 | - } |
|
1659 | - $query->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) |
|
1660 | - ->execute(); |
|
1661 | - |
|
1662 | - return true; |
|
1663 | - |
|
1664 | - }); |
|
1665 | - } |
|
1666 | - |
|
1667 | - /** |
|
1668 | - * Deletes a subscription. |
|
1669 | - * |
|
1670 | - * @param mixed $subscriptionId |
|
1671 | - * @return void |
|
1672 | - */ |
|
1673 | - function deleteSubscription($subscriptionId) { |
|
1674 | - $query = $this->db->getQueryBuilder(); |
|
1675 | - $query->delete('calendarsubscriptions') |
|
1676 | - ->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) |
|
1677 | - ->execute(); |
|
1678 | - } |
|
1679 | - |
|
1680 | - /** |
|
1681 | - * Returns a single scheduling object for the inbox collection. |
|
1682 | - * |
|
1683 | - * The returned array should contain the following elements: |
|
1684 | - * * uri - A unique basename for the object. This will be used to |
|
1685 | - * construct a full uri. |
|
1686 | - * * calendardata - The iCalendar object |
|
1687 | - * * lastmodified - The last modification date. Can be an int for a unix |
|
1688 | - * timestamp, or a PHP DateTime object. |
|
1689 | - * * etag - A unique token that must change if the object changed. |
|
1690 | - * * size - The size of the object, in bytes. |
|
1691 | - * |
|
1692 | - * @param string $principalUri |
|
1693 | - * @param string $objectUri |
|
1694 | - * @return array |
|
1695 | - */ |
|
1696 | - function getSchedulingObject($principalUri, $objectUri) { |
|
1697 | - $query = $this->db->getQueryBuilder(); |
|
1698 | - $stmt = $query->select(['uri', 'calendardata', 'lastmodified', 'etag', 'size']) |
|
1699 | - ->from('schedulingobjects') |
|
1700 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1701 | - ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
1702 | - ->execute(); |
|
1703 | - |
|
1704 | - $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
1705 | - |
|
1706 | - if(!$row) { |
|
1707 | - return null; |
|
1708 | - } |
|
1709 | - |
|
1710 | - return [ |
|
1711 | - 'uri' => $row['uri'], |
|
1712 | - 'calendardata' => $row['calendardata'], |
|
1713 | - 'lastmodified' => $row['lastmodified'], |
|
1714 | - 'etag' => '"' . $row['etag'] . '"', |
|
1715 | - 'size' => (int)$row['size'], |
|
1716 | - ]; |
|
1717 | - } |
|
1718 | - |
|
1719 | - /** |
|
1720 | - * Returns all scheduling objects for the inbox collection. |
|
1721 | - * |
|
1722 | - * These objects should be returned as an array. Every item in the array |
|
1723 | - * should follow the same structure as returned from getSchedulingObject. |
|
1724 | - * |
|
1725 | - * The main difference is that 'calendardata' is optional. |
|
1726 | - * |
|
1727 | - * @param string $principalUri |
|
1728 | - * @return array |
|
1729 | - */ |
|
1730 | - function getSchedulingObjects($principalUri) { |
|
1731 | - $query = $this->db->getQueryBuilder(); |
|
1732 | - $stmt = $query->select(['uri', 'calendardata', 'lastmodified', 'etag', 'size']) |
|
1733 | - ->from('schedulingobjects') |
|
1734 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1735 | - ->execute(); |
|
1736 | - |
|
1737 | - $result = []; |
|
1738 | - foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
1739 | - $result[] = [ |
|
1740 | - 'calendardata' => $row['calendardata'], |
|
1741 | - 'uri' => $row['uri'], |
|
1742 | - 'lastmodified' => $row['lastmodified'], |
|
1743 | - 'etag' => '"' . $row['etag'] . '"', |
|
1744 | - 'size' => (int)$row['size'], |
|
1745 | - ]; |
|
1746 | - } |
|
1747 | - |
|
1748 | - return $result; |
|
1749 | - } |
|
1750 | - |
|
1751 | - /** |
|
1752 | - * Deletes a scheduling object from the inbox collection. |
|
1753 | - * |
|
1754 | - * @param string $principalUri |
|
1755 | - * @param string $objectUri |
|
1756 | - * @return void |
|
1757 | - */ |
|
1758 | - function deleteSchedulingObject($principalUri, $objectUri) { |
|
1759 | - $query = $this->db->getQueryBuilder(); |
|
1760 | - $query->delete('schedulingobjects') |
|
1761 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1762 | - ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
1763 | - ->execute(); |
|
1764 | - } |
|
1765 | - |
|
1766 | - /** |
|
1767 | - * Creates a new scheduling object. This should land in a users' inbox. |
|
1768 | - * |
|
1769 | - * @param string $principalUri |
|
1770 | - * @param string $objectUri |
|
1771 | - * @param string $objectData |
|
1772 | - * @return void |
|
1773 | - */ |
|
1774 | - function createSchedulingObject($principalUri, $objectUri, $objectData) { |
|
1775 | - $query = $this->db->getQueryBuilder(); |
|
1776 | - $query->insert('schedulingobjects') |
|
1777 | - ->values([ |
|
1778 | - 'principaluri' => $query->createNamedParameter($principalUri), |
|
1779 | - 'calendardata' => $query->createNamedParameter($objectData), |
|
1780 | - 'uri' => $query->createNamedParameter($objectUri), |
|
1781 | - 'lastmodified' => $query->createNamedParameter(time()), |
|
1782 | - 'etag' => $query->createNamedParameter(md5($objectData)), |
|
1783 | - 'size' => $query->createNamedParameter(strlen($objectData)) |
|
1784 | - ]) |
|
1785 | - ->execute(); |
|
1786 | - } |
|
1787 | - |
|
1788 | - /** |
|
1789 | - * Adds a change record to the calendarchanges table. |
|
1790 | - * |
|
1791 | - * @param mixed $calendarId |
|
1792 | - * @param string $objectUri |
|
1793 | - * @param int $operation 1 = add, 2 = modify, 3 = delete. |
|
1794 | - * @return void |
|
1795 | - */ |
|
1796 | - protected function addChange($calendarId, $objectUri, $operation) { |
|
1797 | - |
|
1798 | - $stmt = $this->db->prepare('INSERT INTO `*PREFIX*calendarchanges` (`uri`, `synctoken`, `calendarid`, `operation`) SELECT ?, `synctoken`, ?, ? FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
1799 | - $stmt->execute([ |
|
1800 | - $objectUri, |
|
1801 | - $calendarId, |
|
1802 | - $operation, |
|
1803 | - $calendarId |
|
1804 | - ]); |
|
1805 | - $stmt = $this->db->prepare('UPDATE `*PREFIX*calendars` SET `synctoken` = `synctoken` + 1 WHERE `id` = ?'); |
|
1806 | - $stmt->execute([ |
|
1807 | - $calendarId |
|
1808 | - ]); |
|
1809 | - |
|
1810 | - } |
|
1811 | - |
|
1812 | - /** |
|
1813 | - * Parses some information from calendar objects, used for optimized |
|
1814 | - * calendar-queries. |
|
1815 | - * |
|
1816 | - * Returns an array with the following keys: |
|
1817 | - * * etag - An md5 checksum of the object without the quotes. |
|
1818 | - * * size - Size of the object in bytes |
|
1819 | - * * componentType - VEVENT, VTODO or VJOURNAL |
|
1820 | - * * firstOccurence |
|
1821 | - * * lastOccurence |
|
1822 | - * * uid - value of the UID property |
|
1823 | - * |
|
1824 | - * @param string $calendarData |
|
1825 | - * @return array |
|
1826 | - */ |
|
1827 | - public function getDenormalizedData($calendarData) { |
|
1828 | - |
|
1829 | - $vObject = Reader::read($calendarData); |
|
1830 | - $componentType = null; |
|
1831 | - $component = null; |
|
1832 | - $firstOccurrence = null; |
|
1833 | - $lastOccurrence = null; |
|
1834 | - $uid = null; |
|
1835 | - $classification = self::CLASSIFICATION_PUBLIC; |
|
1836 | - foreach($vObject->getComponents() as $component) { |
|
1837 | - if ($component->name!=='VTIMEZONE') { |
|
1838 | - $componentType = $component->name; |
|
1839 | - $uid = (string)$component->UID; |
|
1840 | - break; |
|
1841 | - } |
|
1842 | - } |
|
1843 | - if (!$componentType) { |
|
1844 | - throw new \Sabre\DAV\Exception\BadRequest('Calendar objects must have a VJOURNAL, VEVENT or VTODO component'); |
|
1845 | - } |
|
1846 | - if ($componentType === 'VEVENT' && $component->DTSTART) { |
|
1847 | - $firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp(); |
|
1848 | - // Finding the last occurrence is a bit harder |
|
1849 | - if (!isset($component->RRULE)) { |
|
1850 | - if (isset($component->DTEND)) { |
|
1851 | - $lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp(); |
|
1852 | - } elseif (isset($component->DURATION)) { |
|
1853 | - $endDate = clone $component->DTSTART->getDateTime(); |
|
1854 | - $endDate->add(DateTimeParser::parse($component->DURATION->getValue())); |
|
1855 | - $lastOccurrence = $endDate->getTimeStamp(); |
|
1856 | - } elseif (!$component->DTSTART->hasTime()) { |
|
1857 | - $endDate = clone $component->DTSTART->getDateTime(); |
|
1858 | - $endDate->modify('+1 day'); |
|
1859 | - $lastOccurrence = $endDate->getTimeStamp(); |
|
1860 | - } else { |
|
1861 | - $lastOccurrence = $firstOccurrence; |
|
1862 | - } |
|
1863 | - } else { |
|
1864 | - $it = new EventIterator($vObject, (string)$component->UID); |
|
1865 | - $maxDate = new \DateTime(self::MAX_DATE); |
|
1866 | - if ($it->isInfinite()) { |
|
1867 | - $lastOccurrence = $maxDate->getTimestamp(); |
|
1868 | - } else { |
|
1869 | - $end = $it->getDtEnd(); |
|
1870 | - while($it->valid() && $end < $maxDate) { |
|
1871 | - $end = $it->getDtEnd(); |
|
1872 | - $it->next(); |
|
1873 | - |
|
1874 | - } |
|
1875 | - $lastOccurrence = $end->getTimestamp(); |
|
1876 | - } |
|
1877 | - |
|
1878 | - } |
|
1879 | - } |
|
1880 | - |
|
1881 | - if ($component->CLASS) { |
|
1882 | - $classification = CalDavBackend::CLASSIFICATION_PRIVATE; |
|
1883 | - switch ($component->CLASS->getValue()) { |
|
1884 | - case 'PUBLIC': |
|
1885 | - $classification = CalDavBackend::CLASSIFICATION_PUBLIC; |
|
1886 | - break; |
|
1887 | - case 'CONFIDENTIAL': |
|
1888 | - $classification = CalDavBackend::CLASSIFICATION_CONFIDENTIAL; |
|
1889 | - break; |
|
1890 | - } |
|
1891 | - } |
|
1892 | - return [ |
|
1893 | - 'etag' => md5($calendarData), |
|
1894 | - 'size' => strlen($calendarData), |
|
1895 | - 'componentType' => $componentType, |
|
1896 | - 'firstOccurence' => is_null($firstOccurrence) ? null : max(0, $firstOccurrence), |
|
1897 | - 'lastOccurence' => $lastOccurrence, |
|
1898 | - 'uid' => $uid, |
|
1899 | - 'classification' => $classification |
|
1900 | - ]; |
|
1901 | - |
|
1902 | - } |
|
1903 | - |
|
1904 | - private function readBlob($cardData) { |
|
1905 | - if (is_resource($cardData)) { |
|
1906 | - return stream_get_contents($cardData); |
|
1907 | - } |
|
1908 | - |
|
1909 | - return $cardData; |
|
1910 | - } |
|
1911 | - |
|
1912 | - /** |
|
1913 | - * @param IShareable $shareable |
|
1914 | - * @param array $add |
|
1915 | - * @param array $remove |
|
1916 | - */ |
|
1917 | - public function updateShares($shareable, $add, $remove) { |
|
1918 | - $calendarId = $shareable->getResourceId(); |
|
1919 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateShares', new GenericEvent( |
|
1920 | - '\OCA\DAV\CalDAV\CalDavBackend::updateShares', |
|
1921 | - [ |
|
1922 | - 'calendarId' => $calendarId, |
|
1923 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
1924 | - 'shares' => $this->getShares($calendarId), |
|
1925 | - 'add' => $add, |
|
1926 | - 'remove' => $remove, |
|
1927 | - ])); |
|
1928 | - $this->sharingBackend->updateShares($shareable, $add, $remove); |
|
1929 | - } |
|
1930 | - |
|
1931 | - /** |
|
1932 | - * @param int $resourceId |
|
1933 | - * @return array |
|
1934 | - */ |
|
1935 | - public function getShares($resourceId) { |
|
1936 | - return $this->sharingBackend->getShares($resourceId); |
|
1937 | - } |
|
1938 | - |
|
1939 | - /** |
|
1940 | - * @param boolean $value |
|
1941 | - * @param \OCA\DAV\CalDAV\Calendar $calendar |
|
1942 | - * @return string|null |
|
1943 | - */ |
|
1944 | - public function setPublishStatus($value, $calendar) { |
|
1945 | - $query = $this->db->getQueryBuilder(); |
|
1946 | - if ($value) { |
|
1947 | - $publicUri = $this->random->generate(16, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS); |
|
1948 | - $query->insert('dav_shares') |
|
1949 | - ->values([ |
|
1950 | - 'principaluri' => $query->createNamedParameter($calendar->getPrincipalURI()), |
|
1951 | - 'type' => $query->createNamedParameter('calendar'), |
|
1952 | - 'access' => $query->createNamedParameter(self::ACCESS_PUBLIC), |
|
1953 | - 'resourceid' => $query->createNamedParameter($calendar->getResourceId()), |
|
1954 | - 'publicuri' => $query->createNamedParameter($publicUri) |
|
1955 | - ]); |
|
1956 | - $query->execute(); |
|
1957 | - return $publicUri; |
|
1958 | - } |
|
1959 | - $query->delete('dav_shares') |
|
1960 | - ->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) |
|
1961 | - ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))); |
|
1962 | - $query->execute(); |
|
1963 | - return null; |
|
1964 | - } |
|
1965 | - |
|
1966 | - /** |
|
1967 | - * @param \OCA\DAV\CalDAV\Calendar $calendar |
|
1968 | - * @return mixed |
|
1969 | - */ |
|
1970 | - public function getPublishStatus($calendar) { |
|
1971 | - $query = $this->db->getQueryBuilder(); |
|
1972 | - $result = $query->select('publicuri') |
|
1973 | - ->from('dav_shares') |
|
1974 | - ->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) |
|
1975 | - ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
1976 | - ->execute(); |
|
1977 | - |
|
1978 | - $row = $result->fetch(); |
|
1979 | - $result->closeCursor(); |
|
1980 | - return $row ? reset($row) : false; |
|
1981 | - } |
|
1982 | - |
|
1983 | - /** |
|
1984 | - * @param int $resourceId |
|
1985 | - * @param array $acl |
|
1986 | - * @return array |
|
1987 | - */ |
|
1988 | - public function applyShareAcl($resourceId, $acl) { |
|
1989 | - return $this->sharingBackend->applyShareAcl($resourceId, $acl); |
|
1990 | - } |
|
1991 | - |
|
1992 | - |
|
1993 | - |
|
1994 | - /** |
|
1995 | - * update properties table |
|
1996 | - * |
|
1997 | - * @param int $calendarId |
|
1998 | - * @param string $objectUri |
|
1999 | - * @param string $calendarData |
|
2000 | - */ |
|
2001 | - public function updateProperties($calendarId, $objectUri, $calendarData) { |
|
2002 | - $objectId = $this->getCalendarObjectId($calendarId, $objectUri); |
|
2003 | - |
|
2004 | - try { |
|
2005 | - $vCalendar = $this->readCalendarData($calendarData); |
|
2006 | - } catch (\Exception $ex) { |
|
2007 | - return; |
|
2008 | - } |
|
2009 | - |
|
2010 | - $this->purgeProperties($calendarId, $objectId); |
|
2011 | - |
|
2012 | - $query = $this->db->getQueryBuilder(); |
|
2013 | - $query->insert($this->dbObjectPropertiesTable) |
|
2014 | - ->values( |
|
2015 | - [ |
|
2016 | - 'calendarid' => $query->createNamedParameter($calendarId), |
|
2017 | - 'objectid' => $query->createNamedParameter($objectId), |
|
2018 | - 'name' => $query->createParameter('name'), |
|
2019 | - 'parameter' => $query->createParameter('parameter'), |
|
2020 | - 'value' => $query->createParameter('value'), |
|
2021 | - ] |
|
2022 | - ); |
|
2023 | - |
|
2024 | - $indexComponents = ['VEVENT', 'VJOURNAL', 'VTODO']; |
|
2025 | - foreach ($vCalendar->getComponents() as $component) { |
|
2026 | - if (!in_array($component->name, $indexComponents)) { |
|
2027 | - continue; |
|
2028 | - } |
|
2029 | - |
|
2030 | - foreach ($component->children() as $property) { |
|
2031 | - if (in_array($property->name, self::$indexProperties)) { |
|
2032 | - $value = $property->getValue(); |
|
2033 | - // is this a shitty db? |
|
2034 | - if (!$this->db->supports4ByteText()) { |
|
2035 | - $value = preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $value); |
|
2036 | - } |
|
2037 | - $value = substr($value, 0, 254); |
|
2038 | - |
|
2039 | - $query->setParameter('name', $property->name); |
|
2040 | - $query->setParameter('parameter', null); |
|
2041 | - $query->setParameter('value', $value); |
|
2042 | - $query->execute(); |
|
2043 | - } |
|
2044 | - |
|
2045 | - if (in_array($property->name, array_keys(self::$indexParameters))) { |
|
2046 | - $parameters = $property->parameters(); |
|
2047 | - $indexedParametersForProperty = self::$indexParameters[$property->name]; |
|
2048 | - |
|
2049 | - foreach ($parameters as $key => $value) { |
|
2050 | - if (in_array($key, $indexedParametersForProperty)) { |
|
2051 | - // is this a shitty db? |
|
2052 | - if ($this->db->supports4ByteText()) { |
|
2053 | - $value = preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $value); |
|
2054 | - } |
|
2055 | - $value = substr($value, 0, 254); |
|
2056 | - |
|
2057 | - $query->setParameter('name', $property->name); |
|
2058 | - $query->setParameter('parameter', substr($key, 0, 254)); |
|
2059 | - $query->setParameter('value', substr($value, 0, 254)); |
|
2060 | - $query->execute(); |
|
2061 | - } |
|
2062 | - } |
|
2063 | - } |
|
2064 | - } |
|
2065 | - } |
|
2066 | - } |
|
2067 | - |
|
2068 | - /** |
|
2069 | - * read VCalendar data into a VCalendar object |
|
2070 | - * |
|
2071 | - * @param string $objectData |
|
2072 | - * @return VCalendar |
|
2073 | - */ |
|
2074 | - protected function readCalendarData($objectData) { |
|
2075 | - return Reader::read($objectData); |
|
2076 | - } |
|
2077 | - |
|
2078 | - /** |
|
2079 | - * delete all properties from a given calendar object |
|
2080 | - * |
|
2081 | - * @param int $calendarId |
|
2082 | - * @param int $objectId |
|
2083 | - */ |
|
2084 | - protected function purgeProperties($calendarId, $objectId) { |
|
2085 | - $query = $this->db->getQueryBuilder(); |
|
2086 | - $query->delete($this->dbObjectPropertiesTable) |
|
2087 | - ->where($query->expr()->eq('objectid', $query->createNamedParameter($objectId))) |
|
2088 | - ->andWhere($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
2089 | - $query->execute(); |
|
2090 | - } |
|
2091 | - |
|
2092 | - /** |
|
2093 | - * get ID from a given calendar object |
|
2094 | - * |
|
2095 | - * @param int $calendarId |
|
2096 | - * @param string $uri |
|
2097 | - * @return int |
|
2098 | - */ |
|
2099 | - protected function getCalendarObjectId($calendarId, $uri) { |
|
2100 | - $query = $this->db->getQueryBuilder(); |
|
2101 | - $query->select('id')->from('calendarobjects') |
|
2102 | - ->where($query->expr()->eq('uri', $query->createNamedParameter($uri))) |
|
2103 | - ->andWhere($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
2104 | - |
|
2105 | - $result = $query->execute(); |
|
2106 | - $objectIds = $result->fetch(); |
|
2107 | - $result->closeCursor(); |
|
2108 | - |
|
2109 | - if (!isset($objectIds['id'])) { |
|
2110 | - throw new \InvalidArgumentException('Calendarobject does not exists: ' . $uri); |
|
2111 | - } |
|
2112 | - |
|
2113 | - return (int)$objectIds['id']; |
|
2114 | - } |
|
2115 | - |
|
2116 | - private function convertPrincipal($principalUri, $toV2) { |
|
2117 | - if ($this->principalBackend->getPrincipalPrefix() === 'principals') { |
|
2118 | - list(, $name) = URLUtil::splitPath($principalUri); |
|
2119 | - if ($toV2 === true) { |
|
2120 | - return "principals/users/$name"; |
|
2121 | - } |
|
2122 | - return "principals/$name"; |
|
2123 | - } |
|
2124 | - return $principalUri; |
|
2125 | - } |
|
2126 | - |
|
2127 | - private function addOwnerPrincipal(&$calendarInfo) { |
|
2128 | - $ownerPrincipalKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'; |
|
2129 | - $displaynameKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname'; |
|
2130 | - if (isset($calendarInfo[$ownerPrincipalKey])) { |
|
2131 | - $uri = $calendarInfo[$ownerPrincipalKey]; |
|
2132 | - } else { |
|
2133 | - $uri = $calendarInfo['principaluri']; |
|
2134 | - } |
|
2135 | - |
|
2136 | - $principalInformation = $this->principalBackend->getPrincipalByPath($uri); |
|
2137 | - if (isset($principalInformation['{DAV:}displayname'])) { |
|
2138 | - $calendarInfo[$displaynameKey] = $principalInformation['{DAV:}displayname']; |
|
2139 | - } |
|
2140 | - } |
|
2141 | - |
|
2142 | - /** |
|
2143 | - * Add a reminder for an event |
|
2144 | - * |
|
2145 | - * @param string $calendarId |
|
2146 | - * @param string $objectUri |
|
2147 | - * @param string $type |
|
2148 | - * @param \DateTime $time |
|
2149 | - */ |
|
2150 | - public function addReminderForEvent($calendarId, $objectUri, $type, \DateTime $time) { |
|
2151 | - $query = $this->db->getQueryBuilder(); |
|
2152 | - $query->insert('calendar_reminders') |
|
2153 | - ->values([ |
|
2154 | - 'calendarid' => $query->createNamedParameter($calendarId), |
|
2155 | - 'objecturi' => $query->createNamedParameter($objectUri), |
|
2156 | - 'type' => $query->createNamedParameter($type), |
|
2157 | - 'notificationDate' => $query->createNamedParameter($time->getTimestamp()), |
|
2158 | - ]); |
|
2159 | - $query->execute(); |
|
2160 | - } |
|
2161 | - |
|
2162 | - /** |
|
2163 | - * Cleans reminders in database |
|
2164 | - * |
|
2165 | - * @param string $calendarId |
|
2166 | - * @param string $objectUri |
|
2167 | - */ |
|
2168 | - public function cleanRemindersForEvent($calendarId, $objectUri) { |
|
2169 | - $query = $this->db->getQueryBuilder(); |
|
2170 | - |
|
2171 | - $query->delete('calendar_reminders') |
|
2172 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
2173 | - ->andWhere($query->expr()->eq('objecturi', $query->createNamedParameter($objectUri))) |
|
2174 | - ->execute(); |
|
2175 | - } |
|
2176 | - |
|
2177 | - public function removeReminder($reminderId) { |
|
2178 | - $query = $this->db->getQueryBuilder(); |
|
2179 | - |
|
2180 | - $query->delete('calendar_reminders') |
|
2181 | - ->where($query->expr()->eq('id', $query->createNamedParameter($reminderId))) |
|
2182 | - ->execute(); |
|
2183 | - } |
|
2184 | - |
|
2185 | - /** |
|
2186 | - * Get reminders |
|
2187 | - * |
|
2188 | - * @return array |
|
2189 | - */ |
|
2190 | - public function getReminders() { |
|
2191 | - $query = $this->db->getQueryBuilder(); |
|
2192 | - $fields = ['id', 'calendarId', 'objecturi', 'type', 'notificationDate']; |
|
2193 | - $result = $query->select($fields) |
|
2194 | - ->from('calendar_reminders') |
|
2195 | - ->execute(); |
|
2196 | - |
|
2197 | - $reminders = []; |
|
2198 | - while($row = $result->fetch(\PDO::FETCH_ASSOC)) { |
|
2199 | - $reminder = [ |
|
2200 | - 'id' => $row['id'], |
|
2201 | - 'calendarId' => $row['calendarId'], |
|
2202 | - 'objecturi' => $row['objecturi'], |
|
2203 | - 'type' => $row['type'], |
|
2204 | - 'notificationDate' => $row['notificationDate'] |
|
2205 | - ]; |
|
2206 | - |
|
2207 | - if ($calendarData = $this->getCalendarObject($row['calendarId'], $row['objecturi'])) { |
|
2208 | - $reminder['data'] = $calendarData['calendardata']; |
|
2209 | - } |
|
2210 | - |
|
2211 | - if ($calendar = $this->getCalendarById($row['calendarId'])) { |
|
2212 | - $reminder['owner'] = substr($calendar['principaluri'], 10); |
|
2213 | - } |
|
2214 | - |
|
2215 | - if ($shares = $this->getShares($row['calendarId'])) { |
|
2216 | - $key = 'href'; |
|
2217 | - $reminder['sharees'] = array_map(function ($item) use ($key) { |
|
2218 | - return substr($item[$key], 10); |
|
2219 | - }, $shares); |
|
2220 | - } |
|
2221 | - |
|
2222 | - $reminders[$reminder['id']] = $reminder; |
|
2223 | - } |
|
2224 | - return $reminders; |
|
2225 | - } |
|
415 | + /** |
|
416 | + * @return array |
|
417 | + */ |
|
418 | + public function getPublicCalendars() { |
|
419 | + $fields = array_values($this->propertyMap); |
|
420 | + $fields[] = 'a.id'; |
|
421 | + $fields[] = 'a.uri'; |
|
422 | + $fields[] = 'a.synctoken'; |
|
423 | + $fields[] = 'a.components'; |
|
424 | + $fields[] = 'a.principaluri'; |
|
425 | + $fields[] = 'a.transparent'; |
|
426 | + $fields[] = 's.access'; |
|
427 | + $fields[] = 's.publicuri'; |
|
428 | + $calendars = []; |
|
429 | + $query = $this->db->getQueryBuilder(); |
|
430 | + $result = $query->select($fields) |
|
431 | + ->from('dav_shares', 's') |
|
432 | + ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
433 | + ->where($query->expr()->in('s.access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
434 | + ->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar'))) |
|
435 | + ->execute(); |
|
436 | + |
|
437 | + while($row = $result->fetch()) { |
|
438 | + list(, $name) = URLUtil::splitPath($row['principaluri']); |
|
439 | + $row['displayname'] = $row['displayname'] . "($name)"; |
|
440 | + $components = []; |
|
441 | + if ($row['components']) { |
|
442 | + $components = explode(',',$row['components']); |
|
443 | + } |
|
444 | + $calendar = [ |
|
445 | + 'id' => $row['id'], |
|
446 | + 'uri' => $row['publicuri'], |
|
447 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
448 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
449 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
450 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
451 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
452 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], $this->legacyEndpoint), |
|
453 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
454 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
455 | + ]; |
|
456 | + |
|
457 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
458 | + $calendar[$xmlName] = $row[$dbName]; |
|
459 | + } |
|
460 | + |
|
461 | + $this->addOwnerPrincipal($calendar); |
|
462 | + |
|
463 | + if (!isset($calendars[$calendar['id']])) { |
|
464 | + $calendars[$calendar['id']] = $calendar; |
|
465 | + } |
|
466 | + } |
|
467 | + $result->closeCursor(); |
|
468 | + |
|
469 | + return array_values($calendars); |
|
470 | + } |
|
471 | + |
|
472 | + /** |
|
473 | + * @param string $uri |
|
474 | + * @return array |
|
475 | + * @throws NotFound |
|
476 | + */ |
|
477 | + public function getPublicCalendar($uri) { |
|
478 | + $fields = array_values($this->propertyMap); |
|
479 | + $fields[] = 'a.id'; |
|
480 | + $fields[] = 'a.uri'; |
|
481 | + $fields[] = 'a.synctoken'; |
|
482 | + $fields[] = 'a.components'; |
|
483 | + $fields[] = 'a.principaluri'; |
|
484 | + $fields[] = 'a.transparent'; |
|
485 | + $fields[] = 's.access'; |
|
486 | + $fields[] = 's.publicuri'; |
|
487 | + $query = $this->db->getQueryBuilder(); |
|
488 | + $result = $query->select($fields) |
|
489 | + ->from('dav_shares', 's') |
|
490 | + ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
491 | + ->where($query->expr()->in('s.access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
492 | + ->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar'))) |
|
493 | + ->andWhere($query->expr()->eq('s.publicuri', $query->createNamedParameter($uri))) |
|
494 | + ->execute(); |
|
495 | + |
|
496 | + $row = $result->fetch(\PDO::FETCH_ASSOC); |
|
497 | + |
|
498 | + $result->closeCursor(); |
|
499 | + |
|
500 | + if ($row === false) { |
|
501 | + throw new NotFound('Node with name \'' . $uri . '\' could not be found'); |
|
502 | + } |
|
503 | + |
|
504 | + list(, $name) = URLUtil::splitPath($row['principaluri']); |
|
505 | + $row['displayname'] = $row['displayname'] . ' ' . "($name)"; |
|
506 | + $components = []; |
|
507 | + if ($row['components']) { |
|
508 | + $components = explode(',',$row['components']); |
|
509 | + } |
|
510 | + $calendar = [ |
|
511 | + 'id' => $row['id'], |
|
512 | + 'uri' => $row['publicuri'], |
|
513 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
514 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
515 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
516 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
517 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
518 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
519 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
520 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
521 | + ]; |
|
522 | + |
|
523 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
524 | + $calendar[$xmlName] = $row[$dbName]; |
|
525 | + } |
|
526 | + |
|
527 | + $this->addOwnerPrincipal($calendar); |
|
528 | + |
|
529 | + return $calendar; |
|
530 | + |
|
531 | + } |
|
532 | + |
|
533 | + /** |
|
534 | + * @param string $principal |
|
535 | + * @param string $uri |
|
536 | + * @return array|null |
|
537 | + */ |
|
538 | + public function getCalendarByUri($principal, $uri) { |
|
539 | + $fields = array_values($this->propertyMap); |
|
540 | + $fields[] = 'id'; |
|
541 | + $fields[] = 'uri'; |
|
542 | + $fields[] = 'synctoken'; |
|
543 | + $fields[] = 'components'; |
|
544 | + $fields[] = 'principaluri'; |
|
545 | + $fields[] = 'transparent'; |
|
546 | + |
|
547 | + // Making fields a comma-delimited list |
|
548 | + $query = $this->db->getQueryBuilder(); |
|
549 | + $query->select($fields)->from('calendars') |
|
550 | + ->where($query->expr()->eq('uri', $query->createNamedParameter($uri))) |
|
551 | + ->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($principal))) |
|
552 | + ->setMaxResults(1); |
|
553 | + $stmt = $query->execute(); |
|
554 | + |
|
555 | + $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
556 | + $stmt->closeCursor(); |
|
557 | + if ($row === false) { |
|
558 | + return null; |
|
559 | + } |
|
560 | + |
|
561 | + $components = []; |
|
562 | + if ($row['components']) { |
|
563 | + $components = explode(',',$row['components']); |
|
564 | + } |
|
565 | + |
|
566 | + $calendar = [ |
|
567 | + 'id' => $row['id'], |
|
568 | + 'uri' => $row['uri'], |
|
569 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
570 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
571 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
572 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
573 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
574 | + ]; |
|
575 | + |
|
576 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
577 | + $calendar[$xmlName] = $row[$dbName]; |
|
578 | + } |
|
579 | + |
|
580 | + $this->addOwnerPrincipal($calendar); |
|
581 | + |
|
582 | + return $calendar; |
|
583 | + } |
|
584 | + |
|
585 | + public function getCalendarById($calendarId) { |
|
586 | + $fields = array_values($this->propertyMap); |
|
587 | + $fields[] = 'id'; |
|
588 | + $fields[] = 'uri'; |
|
589 | + $fields[] = 'synctoken'; |
|
590 | + $fields[] = 'components'; |
|
591 | + $fields[] = 'principaluri'; |
|
592 | + $fields[] = 'transparent'; |
|
593 | + |
|
594 | + // Making fields a comma-delimited list |
|
595 | + $query = $this->db->getQueryBuilder(); |
|
596 | + $query->select($fields)->from('calendars') |
|
597 | + ->where($query->expr()->eq('id', $query->createNamedParameter($calendarId))) |
|
598 | + ->setMaxResults(1); |
|
599 | + $stmt = $query->execute(); |
|
600 | + |
|
601 | + $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
602 | + $stmt->closeCursor(); |
|
603 | + if ($row === false) { |
|
604 | + return null; |
|
605 | + } |
|
606 | + |
|
607 | + $components = []; |
|
608 | + if ($row['components']) { |
|
609 | + $components = explode(',',$row['components']); |
|
610 | + } |
|
611 | + |
|
612 | + $calendar = [ |
|
613 | + 'id' => $row['id'], |
|
614 | + 'uri' => $row['uri'], |
|
615 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
616 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
617 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
618 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
619 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
620 | + ]; |
|
621 | + |
|
622 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
623 | + $calendar[$xmlName] = $row[$dbName]; |
|
624 | + } |
|
625 | + |
|
626 | + $this->addOwnerPrincipal($calendar); |
|
627 | + |
|
628 | + return $calendar; |
|
629 | + } |
|
630 | + |
|
631 | + /** |
|
632 | + * Creates a new calendar for a principal. |
|
633 | + * |
|
634 | + * If the creation was a success, an id must be returned that can be used to reference |
|
635 | + * this calendar in other methods, such as updateCalendar. |
|
636 | + * |
|
637 | + * @param string $principalUri |
|
638 | + * @param string $calendarUri |
|
639 | + * @param array $properties |
|
640 | + * @return int |
|
641 | + */ |
|
642 | + function createCalendar($principalUri, $calendarUri, array $properties) { |
|
643 | + $values = [ |
|
644 | + 'principaluri' => $this->convertPrincipal($principalUri, true), |
|
645 | + 'uri' => $calendarUri, |
|
646 | + 'synctoken' => 1, |
|
647 | + 'transparent' => 0, |
|
648 | + 'components' => 'VEVENT,VTODO', |
|
649 | + 'displayname' => $calendarUri |
|
650 | + ]; |
|
651 | + |
|
652 | + // Default value |
|
653 | + $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set'; |
|
654 | + if (isset($properties[$sccs])) { |
|
655 | + if (!($properties[$sccs] instanceof SupportedCalendarComponentSet)) { |
|
656 | + throw new DAV\Exception('The ' . $sccs . ' property must be of type: \Sabre\CalDAV\Property\SupportedCalendarComponentSet'); |
|
657 | + } |
|
658 | + $values['components'] = implode(',',$properties[$sccs]->getValue()); |
|
659 | + } |
|
660 | + $transp = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
661 | + if (isset($properties[$transp])) { |
|
662 | + $values['transparent'] = (int) ($properties[$transp]->getValue() === 'transparent'); |
|
663 | + } |
|
664 | + |
|
665 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
666 | + if (isset($properties[$xmlName])) { |
|
667 | + $values[$dbName] = $properties[$xmlName]; |
|
668 | + } |
|
669 | + } |
|
670 | + |
|
671 | + $query = $this->db->getQueryBuilder(); |
|
672 | + $query->insert('calendars'); |
|
673 | + foreach($values as $column => $value) { |
|
674 | + $query->setValue($column, $query->createNamedParameter($value)); |
|
675 | + } |
|
676 | + $query->execute(); |
|
677 | + $calendarId = $query->getLastInsertId(); |
|
678 | + |
|
679 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', new GenericEvent( |
|
680 | + '\OCA\DAV\CalDAV\CalDavBackend::createCalendar', |
|
681 | + [ |
|
682 | + 'calendarId' => $calendarId, |
|
683 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
684 | + ])); |
|
685 | + |
|
686 | + return $calendarId; |
|
687 | + } |
|
688 | + |
|
689 | + /** |
|
690 | + * Updates properties for a calendar. |
|
691 | + * |
|
692 | + * The list of mutations is stored in a Sabre\DAV\PropPatch object. |
|
693 | + * To do the actual updates, you must tell this object which properties |
|
694 | + * you're going to process with the handle() method. |
|
695 | + * |
|
696 | + * Calling the handle method is like telling the PropPatch object "I |
|
697 | + * promise I can handle updating this property". |
|
698 | + * |
|
699 | + * Read the PropPatch documentation for more info and examples. |
|
700 | + * |
|
701 | + * @param PropPatch $propPatch |
|
702 | + * @return void |
|
703 | + */ |
|
704 | + function updateCalendar($calendarId, PropPatch $propPatch) { |
|
705 | + $supportedProperties = array_keys($this->propertyMap); |
|
706 | + $supportedProperties[] = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
707 | + |
|
708 | + $propPatch->handle($supportedProperties, function($mutations) use ($calendarId) { |
|
709 | + $newValues = []; |
|
710 | + foreach ($mutations as $propertyName => $propertyValue) { |
|
711 | + |
|
712 | + switch ($propertyName) { |
|
713 | + case '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' : |
|
714 | + $fieldName = 'transparent'; |
|
715 | + $newValues[$fieldName] = (int) ($propertyValue->getValue() === 'transparent'); |
|
716 | + break; |
|
717 | + default : |
|
718 | + $fieldName = $this->propertyMap[$propertyName]; |
|
719 | + $newValues[$fieldName] = $propertyValue; |
|
720 | + break; |
|
721 | + } |
|
722 | + |
|
723 | + } |
|
724 | + $query = $this->db->getQueryBuilder(); |
|
725 | + $query->update('calendars'); |
|
726 | + foreach ($newValues as $fieldName => $value) { |
|
727 | + $query->set($fieldName, $query->createNamedParameter($value)); |
|
728 | + } |
|
729 | + $query->where($query->expr()->eq('id', $query->createNamedParameter($calendarId))); |
|
730 | + $query->execute(); |
|
731 | + |
|
732 | + $this->addChange($calendarId, "", 2); |
|
733 | + |
|
734 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', new GenericEvent( |
|
735 | + '\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', |
|
736 | + [ |
|
737 | + 'calendarId' => $calendarId, |
|
738 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
739 | + 'shares' => $this->getShares($calendarId), |
|
740 | + 'propertyMutations' => $mutations, |
|
741 | + ])); |
|
742 | + |
|
743 | + return true; |
|
744 | + }); |
|
745 | + } |
|
746 | + |
|
747 | + /** |
|
748 | + * Delete a calendar and all it's objects |
|
749 | + * |
|
750 | + * @param mixed $calendarId |
|
751 | + * @return void |
|
752 | + */ |
|
753 | + function deleteCalendar($calendarId) { |
|
754 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', new GenericEvent( |
|
755 | + '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', |
|
756 | + [ |
|
757 | + 'calendarId' => $calendarId, |
|
758 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
759 | + 'shares' => $this->getShares($calendarId), |
|
760 | + ])); |
|
761 | + |
|
762 | + $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ?'); |
|
763 | + $stmt->execute([$calendarId]); |
|
764 | + |
|
765 | + $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
766 | + $stmt->execute([$calendarId]); |
|
767 | + |
|
768 | + $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarchanges` WHERE `calendarid` = ?'); |
|
769 | + $stmt->execute([$calendarId]); |
|
770 | + |
|
771 | + $this->sharingBackend->deleteAllShares($calendarId); |
|
772 | + |
|
773 | + $query = $this->db->getQueryBuilder(); |
|
774 | + $query->delete($this->dbObjectPropertiesTable) |
|
775 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
776 | + ->execute(); |
|
777 | + } |
|
778 | + |
|
779 | + /** |
|
780 | + * Delete all of an user's shares |
|
781 | + * |
|
782 | + * @param string $principaluri |
|
783 | + * @return void |
|
784 | + */ |
|
785 | + function deleteAllSharesByUser($principaluri) { |
|
786 | + $this->sharingBackend->deleteAllSharesByUser($principaluri); |
|
787 | + } |
|
788 | + |
|
789 | + /** |
|
790 | + * Returns all calendar objects within a calendar. |
|
791 | + * |
|
792 | + * Every item contains an array with the following keys: |
|
793 | + * * calendardata - The iCalendar-compatible calendar data |
|
794 | + * * uri - a unique key which will be used to construct the uri. This can |
|
795 | + * be any arbitrary string, but making sure it ends with '.ics' is a |
|
796 | + * good idea. This is only the basename, or filename, not the full |
|
797 | + * path. |
|
798 | + * * lastmodified - a timestamp of the last modification time |
|
799 | + * * etag - An arbitrary string, surrounded by double-quotes. (e.g.: |
|
800 | + * '"abcdef"') |
|
801 | + * * size - The size of the calendar objects, in bytes. |
|
802 | + * * component - optional, a string containing the type of object, such |
|
803 | + * as 'vevent' or 'vtodo'. If specified, this will be used to populate |
|
804 | + * the Content-Type header. |
|
805 | + * |
|
806 | + * Note that the etag is optional, but it's highly encouraged to return for |
|
807 | + * speed reasons. |
|
808 | + * |
|
809 | + * The calendardata is also optional. If it's not returned |
|
810 | + * 'getCalendarObject' will be called later, which *is* expected to return |
|
811 | + * calendardata. |
|
812 | + * |
|
813 | + * If neither etag or size are specified, the calendardata will be |
|
814 | + * used/fetched to determine these numbers. If both are specified the |
|
815 | + * amount of times this is needed is reduced by a great degree. |
|
816 | + * |
|
817 | + * @param mixed $calendarId |
|
818 | + * @return array |
|
819 | + */ |
|
820 | + function getCalendarObjects($calendarId) { |
|
821 | + $query = $this->db->getQueryBuilder(); |
|
822 | + $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'componenttype', 'classification']) |
|
823 | + ->from('calendarobjects') |
|
824 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
825 | + $stmt = $query->execute(); |
|
826 | + |
|
827 | + $result = []; |
|
828 | + foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
829 | + $result[] = [ |
|
830 | + 'id' => $row['id'], |
|
831 | + 'uri' => $row['uri'], |
|
832 | + 'lastmodified' => $row['lastmodified'], |
|
833 | + 'etag' => '"' . $row['etag'] . '"', |
|
834 | + 'calendarid' => $row['calendarid'], |
|
835 | + 'size' => (int)$row['size'], |
|
836 | + 'component' => strtolower($row['componenttype']), |
|
837 | + 'classification'=> (int)$row['classification'] |
|
838 | + ]; |
|
839 | + } |
|
840 | + |
|
841 | + return $result; |
|
842 | + } |
|
843 | + |
|
844 | + /** |
|
845 | + * Returns information from a single calendar object, based on it's object |
|
846 | + * uri. |
|
847 | + * |
|
848 | + * The object uri is only the basename, or filename and not a full path. |
|
849 | + * |
|
850 | + * The returned array must have the same keys as getCalendarObjects. The |
|
851 | + * 'calendardata' object is required here though, while it's not required |
|
852 | + * for getCalendarObjects. |
|
853 | + * |
|
854 | + * This method must return null if the object did not exist. |
|
855 | + * |
|
856 | + * @param mixed $calendarId |
|
857 | + * @param string $objectUri |
|
858 | + * @return array|null |
|
859 | + */ |
|
860 | + function getCalendarObject($calendarId, $objectUri) { |
|
861 | + |
|
862 | + $query = $this->db->getQueryBuilder(); |
|
863 | + $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification']) |
|
864 | + ->from('calendarobjects') |
|
865 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
866 | + ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))); |
|
867 | + $stmt = $query->execute(); |
|
868 | + $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
869 | + |
|
870 | + if(!$row) return null; |
|
871 | + |
|
872 | + return [ |
|
873 | + 'id' => $row['id'], |
|
874 | + 'uri' => $row['uri'], |
|
875 | + 'lastmodified' => $row['lastmodified'], |
|
876 | + 'etag' => '"' . $row['etag'] . '"', |
|
877 | + 'calendarid' => $row['calendarid'], |
|
878 | + 'size' => (int)$row['size'], |
|
879 | + 'calendardata' => $this->readBlob($row['calendardata']), |
|
880 | + 'component' => strtolower($row['componenttype']), |
|
881 | + 'classification'=> (int)$row['classification'] |
|
882 | + ]; |
|
883 | + } |
|
884 | + |
|
885 | + /** |
|
886 | + * Returns a list of calendar objects. |
|
887 | + * |
|
888 | + * This method should work identical to getCalendarObject, but instead |
|
889 | + * return all the calendar objects in the list as an array. |
|
890 | + * |
|
891 | + * If the backend supports this, it may allow for some speed-ups. |
|
892 | + * |
|
893 | + * @param mixed $calendarId |
|
894 | + * @param string[] $uris |
|
895 | + * @return array |
|
896 | + */ |
|
897 | + function getMultipleCalendarObjects($calendarId, array $uris) { |
|
898 | + if (empty($uris)) { |
|
899 | + return []; |
|
900 | + } |
|
901 | + |
|
902 | + $chunks = array_chunk($uris, 100); |
|
903 | + $objects = []; |
|
904 | + |
|
905 | + $query = $this->db->getQueryBuilder(); |
|
906 | + $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification']) |
|
907 | + ->from('calendarobjects') |
|
908 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
909 | + ->andWhere($query->expr()->in('uri', $query->createParameter('uri'))); |
|
910 | + |
|
911 | + foreach ($chunks as $uris) { |
|
912 | + $query->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY); |
|
913 | + $result = $query->execute(); |
|
914 | + |
|
915 | + while ($row = $result->fetch()) { |
|
916 | + $objects[] = [ |
|
917 | + 'id' => $row['id'], |
|
918 | + 'uri' => $row['uri'], |
|
919 | + 'lastmodified' => $row['lastmodified'], |
|
920 | + 'etag' => '"' . $row['etag'] . '"', |
|
921 | + 'calendarid' => $row['calendarid'], |
|
922 | + 'size' => (int)$row['size'], |
|
923 | + 'calendardata' => $this->readBlob($row['calendardata']), |
|
924 | + 'component' => strtolower($row['componenttype']), |
|
925 | + 'classification' => (int)$row['classification'] |
|
926 | + ]; |
|
927 | + } |
|
928 | + $result->closeCursor(); |
|
929 | + } |
|
930 | + return $objects; |
|
931 | + } |
|
932 | + |
|
933 | + /** |
|
934 | + * Creates a new calendar object. |
|
935 | + * |
|
936 | + * The object uri is only the basename, or filename and not a full path. |
|
937 | + * |
|
938 | + * It is possible return an etag from this function, which will be used in |
|
939 | + * the response to this PUT request. Note that the ETag must be surrounded |
|
940 | + * by double-quotes. |
|
941 | + * |
|
942 | + * However, you should only really return this ETag if you don't mangle the |
|
943 | + * calendar-data. If the result of a subsequent GET to this object is not |
|
944 | + * the exact same as this request body, you should omit the ETag. |
|
945 | + * |
|
946 | + * @param mixed $calendarId |
|
947 | + * @param string $objectUri |
|
948 | + * @param string $calendarData |
|
949 | + * @return string |
|
950 | + */ |
|
951 | + function createCalendarObject($calendarId, $objectUri, $calendarData) { |
|
952 | + $extraData = $this->getDenormalizedData($calendarData); |
|
953 | + |
|
954 | + $query = $this->db->getQueryBuilder(); |
|
955 | + $query->insert('calendarobjects') |
|
956 | + ->values([ |
|
957 | + 'calendarid' => $query->createNamedParameter($calendarId), |
|
958 | + 'uri' => $query->createNamedParameter($objectUri), |
|
959 | + 'calendardata' => $query->createNamedParameter($calendarData, IQueryBuilder::PARAM_LOB), |
|
960 | + 'lastmodified' => $query->createNamedParameter(time()), |
|
961 | + 'etag' => $query->createNamedParameter($extraData['etag']), |
|
962 | + 'size' => $query->createNamedParameter($extraData['size']), |
|
963 | + 'componenttype' => $query->createNamedParameter($extraData['componentType']), |
|
964 | + 'firstoccurence' => $query->createNamedParameter($extraData['firstOccurence']), |
|
965 | + 'lastoccurence' => $query->createNamedParameter($extraData['lastOccurence']), |
|
966 | + 'classification' => $query->createNamedParameter($extraData['classification']), |
|
967 | + 'uid' => $query->createNamedParameter($extraData['uid']), |
|
968 | + ]) |
|
969 | + ->execute(); |
|
970 | + |
|
971 | + $this->updateProperties($calendarId, $objectUri, $calendarData); |
|
972 | + |
|
973 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', new GenericEvent( |
|
974 | + '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', |
|
975 | + [ |
|
976 | + 'calendarId' => $calendarId, |
|
977 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
978 | + 'shares' => $this->getShares($calendarId), |
|
979 | + 'objectData' => $this->getCalendarObject($calendarId, $objectUri), |
|
980 | + ] |
|
981 | + )); |
|
982 | + $this->addChange($calendarId, $objectUri, 1); |
|
983 | + |
|
984 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDAVBackend::createCalendarObject', |
|
985 | + new GenericEvent(null, [ |
|
986 | + 'calendarId' => $calendarId, |
|
987 | + 'objectUri' => $objectUri, |
|
988 | + 'calendarData' => $calendarData])); |
|
989 | + |
|
990 | + return '"' . $extraData['etag'] . '"'; |
|
991 | + } |
|
992 | + |
|
993 | + /** |
|
994 | + * Updates an existing calendarobject, based on it's uri. |
|
995 | + * |
|
996 | + * The object uri is only the basename, or filename and not a full path. |
|
997 | + * |
|
998 | + * It is possible return an etag from this function, which will be used in |
|
999 | + * the response to this PUT request. Note that the ETag must be surrounded |
|
1000 | + * by double-quotes. |
|
1001 | + * |
|
1002 | + * However, you should only really return this ETag if you don't mangle the |
|
1003 | + * calendar-data. If the result of a subsequent GET to this object is not |
|
1004 | + * the exact same as this request body, you should omit the ETag. |
|
1005 | + * |
|
1006 | + * @param mixed $calendarId |
|
1007 | + * @param string $objectUri |
|
1008 | + * @param string $calendarData |
|
1009 | + * @return string |
|
1010 | + */ |
|
1011 | + function updateCalendarObject($calendarId, $objectUri, $calendarData) { |
|
1012 | + $extraData = $this->getDenormalizedData($calendarData); |
|
1013 | + $query = $this->db->getQueryBuilder(); |
|
1014 | + $query->update('calendarobjects') |
|
1015 | + ->set('calendardata', $query->createNamedParameter($calendarData, IQueryBuilder::PARAM_LOB)) |
|
1016 | + ->set('lastmodified', $query->createNamedParameter(time())) |
|
1017 | + ->set('etag', $query->createNamedParameter($extraData['etag'])) |
|
1018 | + ->set('size', $query->createNamedParameter($extraData['size'])) |
|
1019 | + ->set('componenttype', $query->createNamedParameter($extraData['componentType'])) |
|
1020 | + ->set('firstoccurence', $query->createNamedParameter($extraData['firstOccurence'])) |
|
1021 | + ->set('lastoccurence', $query->createNamedParameter($extraData['lastOccurence'])) |
|
1022 | + ->set('classification', $query->createNamedParameter($extraData['classification'])) |
|
1023 | + ->set('uid', $query->createNamedParameter($extraData['uid'])) |
|
1024 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
1025 | + ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
1026 | + ->execute(); |
|
1027 | + |
|
1028 | + $this->updateProperties($calendarId, $objectUri, $calendarData); |
|
1029 | + |
|
1030 | + $data = $this->getCalendarObject($calendarId, $objectUri); |
|
1031 | + if (is_array($data)) { |
|
1032 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', new GenericEvent( |
|
1033 | + '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', |
|
1034 | + [ |
|
1035 | + 'calendarId' => $calendarId, |
|
1036 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
1037 | + 'shares' => $this->getShares($calendarId), |
|
1038 | + 'objectData' => $data, |
|
1039 | + ] |
|
1040 | + )); |
|
1041 | + } |
|
1042 | + $this->addChange($calendarId, $objectUri, 2); |
|
1043 | + |
|
1044 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDAVBackend::updateCalendarObject', |
|
1045 | + new GenericEvent(null, [ |
|
1046 | + 'calendarId' => $calendarId, |
|
1047 | + 'objectUri' => $objectUri, |
|
1048 | + 'calendarData' => $calendarData])); |
|
1049 | + |
|
1050 | + return '"' . $extraData['etag'] . '"'; |
|
1051 | + } |
|
1052 | + |
|
1053 | + /** |
|
1054 | + * @param int $calendarObjectId |
|
1055 | + * @param int $classification |
|
1056 | + */ |
|
1057 | + public function setClassification($calendarObjectId, $classification) { |
|
1058 | + if (!in_array($classification, [ |
|
1059 | + self::CLASSIFICATION_PUBLIC, self::CLASSIFICATION_PRIVATE, self::CLASSIFICATION_CONFIDENTIAL |
|
1060 | + ])) { |
|
1061 | + throw new \InvalidArgumentException(); |
|
1062 | + } |
|
1063 | + $query = $this->db->getQueryBuilder(); |
|
1064 | + $query->update('calendarobjects') |
|
1065 | + ->set('classification', $query->createNamedParameter($classification)) |
|
1066 | + ->where($query->expr()->eq('id', $query->createNamedParameter($calendarObjectId))) |
|
1067 | + ->execute(); |
|
1068 | + } |
|
1069 | + |
|
1070 | + /** |
|
1071 | + * Deletes an existing calendar object. |
|
1072 | + * |
|
1073 | + * The object uri is only the basename, or filename and not a full path. |
|
1074 | + * |
|
1075 | + * @param mixed $calendarId |
|
1076 | + * @param string $objectUri |
|
1077 | + * @return void |
|
1078 | + */ |
|
1079 | + function deleteCalendarObject($calendarId, $objectUri) { |
|
1080 | + $data = $this->getCalendarObject($calendarId, $objectUri); |
|
1081 | + if (is_array($data)) { |
|
1082 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', new GenericEvent( |
|
1083 | + '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', |
|
1084 | + [ |
|
1085 | + 'calendarId' => $calendarId, |
|
1086 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
1087 | + 'shares' => $this->getShares($calendarId), |
|
1088 | + 'objectData' => $data, |
|
1089 | + ] |
|
1090 | + )); |
|
1091 | + } |
|
1092 | + |
|
1093 | + $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ? AND `uri` = ?'); |
|
1094 | + $stmt->execute([$calendarId, $objectUri]); |
|
1095 | + |
|
1096 | + $this->purgeProperties($calendarId, $data['id']); |
|
1097 | + |
|
1098 | + $this->addChange($calendarId, $objectUri, 3); |
|
1099 | + |
|
1100 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDAVBackend::deleteCalendarObject', |
|
1101 | + new GenericEvent(null, [ |
|
1102 | + 'calendarId' => $calendarId, |
|
1103 | + 'objectUri' => $objectUri])); |
|
1104 | + } |
|
1105 | + |
|
1106 | + /** |
|
1107 | + * Performs a calendar-query on the contents of this calendar. |
|
1108 | + * |
|
1109 | + * The calendar-query is defined in RFC4791 : CalDAV. Using the |
|
1110 | + * calendar-query it is possible for a client to request a specific set of |
|
1111 | + * object, based on contents of iCalendar properties, date-ranges and |
|
1112 | + * iCalendar component types (VTODO, VEVENT). |
|
1113 | + * |
|
1114 | + * This method should just return a list of (relative) urls that match this |
|
1115 | + * query. |
|
1116 | + * |
|
1117 | + * The list of filters are specified as an array. The exact array is |
|
1118 | + * documented by Sabre\CalDAV\CalendarQueryParser. |
|
1119 | + * |
|
1120 | + * Note that it is extremely likely that getCalendarObject for every path |
|
1121 | + * returned from this method will be called almost immediately after. You |
|
1122 | + * may want to anticipate this to speed up these requests. |
|
1123 | + * |
|
1124 | + * This method provides a default implementation, which parses *all* the |
|
1125 | + * iCalendar objects in the specified calendar. |
|
1126 | + * |
|
1127 | + * This default may well be good enough for personal use, and calendars |
|
1128 | + * that aren't very large. But if you anticipate high usage, big calendars |
|
1129 | + * or high loads, you are strongly advised to optimize certain paths. |
|
1130 | + * |
|
1131 | + * The best way to do so is override this method and to optimize |
|
1132 | + * specifically for 'common filters'. |
|
1133 | + * |
|
1134 | + * Requests that are extremely common are: |
|
1135 | + * * requests for just VEVENTS |
|
1136 | + * * requests for just VTODO |
|
1137 | + * * requests with a time-range-filter on either VEVENT or VTODO. |
|
1138 | + * |
|
1139 | + * ..and combinations of these requests. It may not be worth it to try to |
|
1140 | + * handle every possible situation and just rely on the (relatively |
|
1141 | + * easy to use) CalendarQueryValidator to handle the rest. |
|
1142 | + * |
|
1143 | + * Note that especially time-range-filters may be difficult to parse. A |
|
1144 | + * time-range filter specified on a VEVENT must for instance also handle |
|
1145 | + * recurrence rules correctly. |
|
1146 | + * A good example of how to interprete all these filters can also simply |
|
1147 | + * be found in Sabre\CalDAV\CalendarQueryFilter. This class is as correct |
|
1148 | + * as possible, so it gives you a good idea on what type of stuff you need |
|
1149 | + * to think of. |
|
1150 | + * |
|
1151 | + * @param mixed $calendarId |
|
1152 | + * @param array $filters |
|
1153 | + * @return array |
|
1154 | + */ |
|
1155 | + function calendarQuery($calendarId, array $filters) { |
|
1156 | + $componentType = null; |
|
1157 | + $requirePostFilter = true; |
|
1158 | + $timeRange = null; |
|
1159 | + |
|
1160 | + // if no filters were specified, we don't need to filter after a query |
|
1161 | + if (!$filters['prop-filters'] && !$filters['comp-filters']) { |
|
1162 | + $requirePostFilter = false; |
|
1163 | + } |
|
1164 | + |
|
1165 | + // Figuring out if there's a component filter |
|
1166 | + if (count($filters['comp-filters']) > 0 && !$filters['comp-filters'][0]['is-not-defined']) { |
|
1167 | + $componentType = $filters['comp-filters'][0]['name']; |
|
1168 | + |
|
1169 | + // Checking if we need post-filters |
|
1170 | + if (!$filters['prop-filters'] && !$filters['comp-filters'][0]['comp-filters'] && !$filters['comp-filters'][0]['time-range'] && !$filters['comp-filters'][0]['prop-filters']) { |
|
1171 | + $requirePostFilter = false; |
|
1172 | + } |
|
1173 | + // There was a time-range filter |
|
1174 | + if ($componentType == 'VEVENT' && isset($filters['comp-filters'][0]['time-range'])) { |
|
1175 | + $timeRange = $filters['comp-filters'][0]['time-range']; |
|
1176 | + |
|
1177 | + // If start time OR the end time is not specified, we can do a |
|
1178 | + // 100% accurate mysql query. |
|
1179 | + if (!$filters['prop-filters'] && !$filters['comp-filters'][0]['comp-filters'] && !$filters['comp-filters'][0]['prop-filters'] && (!$timeRange['start'] || !$timeRange['end'])) { |
|
1180 | + $requirePostFilter = false; |
|
1181 | + } |
|
1182 | + } |
|
1183 | + |
|
1184 | + } |
|
1185 | + $columns = ['uri']; |
|
1186 | + if ($requirePostFilter) { |
|
1187 | + $columns = ['uri', 'calendardata']; |
|
1188 | + } |
|
1189 | + $query = $this->db->getQueryBuilder(); |
|
1190 | + $query->select($columns) |
|
1191 | + ->from('calendarobjects') |
|
1192 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
1193 | + |
|
1194 | + if ($componentType) { |
|
1195 | + $query->andWhere($query->expr()->eq('componenttype', $query->createNamedParameter($componentType))); |
|
1196 | + } |
|
1197 | + |
|
1198 | + if ($timeRange && $timeRange['start']) { |
|
1199 | + $query->andWhere($query->expr()->gt('lastoccurence', $query->createNamedParameter($timeRange['start']->getTimeStamp()))); |
|
1200 | + } |
|
1201 | + if ($timeRange && $timeRange['end']) { |
|
1202 | + $query->andWhere($query->expr()->lt('firstoccurence', $query->createNamedParameter($timeRange['end']->getTimeStamp()))); |
|
1203 | + } |
|
1204 | + |
|
1205 | + $stmt = $query->execute(); |
|
1206 | + |
|
1207 | + $result = []; |
|
1208 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1209 | + if ($requirePostFilter) { |
|
1210 | + if (!$this->validateFilterForObject($row, $filters)) { |
|
1211 | + continue; |
|
1212 | + } |
|
1213 | + } |
|
1214 | + $result[] = $row['uri']; |
|
1215 | + } |
|
1216 | + |
|
1217 | + return $result; |
|
1218 | + } |
|
1219 | + |
|
1220 | + /** |
|
1221 | + * custom Nextcloud search extension for CalDAV |
|
1222 | + * |
|
1223 | + * @param string $principalUri |
|
1224 | + * @param array $filters |
|
1225 | + * @param integer|null $limit |
|
1226 | + * @param integer|null $offset |
|
1227 | + * @return array |
|
1228 | + */ |
|
1229 | + public function calendarSearch($principalUri, array $filters, $limit=null, $offset=null) { |
|
1230 | + $calendars = $this->getCalendarsForUser($principalUri); |
|
1231 | + $ownCalendars = []; |
|
1232 | + $sharedCalendars = []; |
|
1233 | + |
|
1234 | + $uriMapper = []; |
|
1235 | + |
|
1236 | + foreach($calendars as $calendar) { |
|
1237 | + if ($calendar['{http://owncloud.org/ns}owner-principal'] === $principalUri) { |
|
1238 | + $ownCalendars[] = $calendar['id']; |
|
1239 | + } else { |
|
1240 | + $sharedCalendars[] = $calendar['id']; |
|
1241 | + } |
|
1242 | + $uriMapper[$calendar['id']] = $calendar['uri']; |
|
1243 | + } |
|
1244 | + if (count($ownCalendars) === 0 && count($sharedCalendars) === 0) { |
|
1245 | + return []; |
|
1246 | + } |
|
1247 | + |
|
1248 | + $query = $this->db->getQueryBuilder(); |
|
1249 | + // Calendar id expressions |
|
1250 | + $calendarExpressions = []; |
|
1251 | + foreach($ownCalendars as $id) { |
|
1252 | + $calendarExpressions[] = $query->expr() |
|
1253 | + ->eq('c.calendarid', $query->createNamedParameter($id)); |
|
1254 | + } |
|
1255 | + foreach($sharedCalendars as $id) { |
|
1256 | + $calendarExpressions[] = $query->expr()->andX( |
|
1257 | + $query->expr()->eq('c.calendarid', |
|
1258 | + $query->createNamedParameter($id)), |
|
1259 | + $query->expr()->eq('c.classification', |
|
1260 | + $query->createNamedParameter(self::CLASSIFICATION_PUBLIC)) |
|
1261 | + ); |
|
1262 | + } |
|
1263 | + |
|
1264 | + if (count($calendarExpressions) === 1) { |
|
1265 | + $calExpr = $calendarExpressions[0]; |
|
1266 | + } else { |
|
1267 | + $calExpr = call_user_func_array([$query->expr(), 'orX'], $calendarExpressions); |
|
1268 | + } |
|
1269 | + |
|
1270 | + // Component expressions |
|
1271 | + $compExpressions = []; |
|
1272 | + foreach($filters['comps'] as $comp) { |
|
1273 | + $compExpressions[] = $query->expr() |
|
1274 | + ->eq('c.componenttype', $query->createNamedParameter($comp)); |
|
1275 | + } |
|
1276 | + |
|
1277 | + if (count($compExpressions) === 1) { |
|
1278 | + $compExpr = $compExpressions[0]; |
|
1279 | + } else { |
|
1280 | + $compExpr = call_user_func_array([$query->expr(), 'orX'], $compExpressions); |
|
1281 | + } |
|
1282 | + |
|
1283 | + if (!isset($filters['props'])) { |
|
1284 | + $filters['props'] = []; |
|
1285 | + } |
|
1286 | + if (!isset($filters['params'])) { |
|
1287 | + $filters['params'] = []; |
|
1288 | + } |
|
1289 | + |
|
1290 | + $propParamExpressions = []; |
|
1291 | + foreach($filters['props'] as $prop) { |
|
1292 | + $propParamExpressions[] = $query->expr()->andX( |
|
1293 | + $query->expr()->eq('i.name', $query->createNamedParameter($prop)), |
|
1294 | + $query->expr()->isNull('i.parameter') |
|
1295 | + ); |
|
1296 | + } |
|
1297 | + foreach($filters['params'] as $param) { |
|
1298 | + $propParamExpressions[] = $query->expr()->andX( |
|
1299 | + $query->expr()->eq('i.name', $query->createNamedParameter($param['property'])), |
|
1300 | + $query->expr()->eq('i.parameter', $query->createNamedParameter($param['parameter'])) |
|
1301 | + ); |
|
1302 | + } |
|
1303 | + |
|
1304 | + if (count($propParamExpressions) === 1) { |
|
1305 | + $propParamExpr = $propParamExpressions[0]; |
|
1306 | + } else { |
|
1307 | + $propParamExpr = call_user_func_array([$query->expr(), 'orX'], $propParamExpressions); |
|
1308 | + } |
|
1309 | + |
|
1310 | + $query->select(['c.calendarid', 'c.uri']) |
|
1311 | + ->from($this->dbObjectPropertiesTable, 'i') |
|
1312 | + ->join('i', 'calendarobjects', 'c', $query->expr()->eq('i.objectid', 'c.id')) |
|
1313 | + ->where($calExpr) |
|
1314 | + ->andWhere($compExpr) |
|
1315 | + ->andWhere($propParamExpr) |
|
1316 | + ->andWhere($query->expr()->iLike('i.value', |
|
1317 | + $query->createNamedParameter('%'.$this->db->escapeLikeParameter($filters['search-term']).'%'))); |
|
1318 | + |
|
1319 | + if ($offset) { |
|
1320 | + $query->setFirstResult($offset); |
|
1321 | + } |
|
1322 | + if ($limit) { |
|
1323 | + $query->setMaxResults($limit); |
|
1324 | + } |
|
1325 | + |
|
1326 | + $stmt = $query->execute(); |
|
1327 | + |
|
1328 | + $result = []; |
|
1329 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1330 | + $path = $uriMapper[$row['calendarid']] . '/' . $row['uri']; |
|
1331 | + if (!in_array($path, $result)) { |
|
1332 | + $result[] = $path; |
|
1333 | + } |
|
1334 | + } |
|
1335 | + |
|
1336 | + return $result; |
|
1337 | + } |
|
1338 | + |
|
1339 | + /** |
|
1340 | + * Searches through all of a users calendars and calendar objects to find |
|
1341 | + * an object with a specific UID. |
|
1342 | + * |
|
1343 | + * This method should return the path to this object, relative to the |
|
1344 | + * calendar home, so this path usually only contains two parts: |
|
1345 | + * |
|
1346 | + * calendarpath/objectpath.ics |
|
1347 | + * |
|
1348 | + * If the uid is not found, return null. |
|
1349 | + * |
|
1350 | + * This method should only consider * objects that the principal owns, so |
|
1351 | + * any calendars owned by other principals that also appear in this |
|
1352 | + * collection should be ignored. |
|
1353 | + * |
|
1354 | + * @param string $principalUri |
|
1355 | + * @param string $uid |
|
1356 | + * @return string|null |
|
1357 | + */ |
|
1358 | + function getCalendarObjectByUID($principalUri, $uid) { |
|
1359 | + |
|
1360 | + $query = $this->db->getQueryBuilder(); |
|
1361 | + $query->selectAlias('c.uri', 'calendaruri')->selectAlias('co.uri', 'objecturi') |
|
1362 | + ->from('calendarobjects', 'co') |
|
1363 | + ->leftJoin('co', 'calendars', 'c', $query->expr()->eq('co.calendarid', 'c.id')) |
|
1364 | + ->where($query->expr()->eq('c.principaluri', $query->createNamedParameter($principalUri))) |
|
1365 | + ->andWhere($query->expr()->eq('co.uid', $query->createNamedParameter($uid))); |
|
1366 | + |
|
1367 | + $stmt = $query->execute(); |
|
1368 | + |
|
1369 | + if ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1370 | + return $row['calendaruri'] . '/' . $row['objecturi']; |
|
1371 | + } |
|
1372 | + |
|
1373 | + return null; |
|
1374 | + } |
|
1375 | + |
|
1376 | + /** |
|
1377 | + * The getChanges method returns all the changes that have happened, since |
|
1378 | + * the specified syncToken in the specified calendar. |
|
1379 | + * |
|
1380 | + * This function should return an array, such as the following: |
|
1381 | + * |
|
1382 | + * [ |
|
1383 | + * 'syncToken' => 'The current synctoken', |
|
1384 | + * 'added' => [ |
|
1385 | + * 'new.txt', |
|
1386 | + * ], |
|
1387 | + * 'modified' => [ |
|
1388 | + * 'modified.txt', |
|
1389 | + * ], |
|
1390 | + * 'deleted' => [ |
|
1391 | + * 'foo.php.bak', |
|
1392 | + * 'old.txt' |
|
1393 | + * ] |
|
1394 | + * ); |
|
1395 | + * |
|
1396 | + * The returned syncToken property should reflect the *current* syncToken |
|
1397 | + * of the calendar, as reported in the {http://sabredav.org/ns}sync-token |
|
1398 | + * property This is * needed here too, to ensure the operation is atomic. |
|
1399 | + * |
|
1400 | + * If the $syncToken argument is specified as null, this is an initial |
|
1401 | + * sync, and all members should be reported. |
|
1402 | + * |
|
1403 | + * The modified property is an array of nodenames that have changed since |
|
1404 | + * the last token. |
|
1405 | + * |
|
1406 | + * The deleted property is an array with nodenames, that have been deleted |
|
1407 | + * from collection. |
|
1408 | + * |
|
1409 | + * The $syncLevel argument is basically the 'depth' of the report. If it's |
|
1410 | + * 1, you only have to report changes that happened only directly in |
|
1411 | + * immediate descendants. If it's 2, it should also include changes from |
|
1412 | + * the nodes below the child collections. (grandchildren) |
|
1413 | + * |
|
1414 | + * The $limit argument allows a client to specify how many results should |
|
1415 | + * be returned at most. If the limit is not specified, it should be treated |
|
1416 | + * as infinite. |
|
1417 | + * |
|
1418 | + * If the limit (infinite or not) is higher than you're willing to return, |
|
1419 | + * you should throw a Sabre\DAV\Exception\TooMuchMatches() exception. |
|
1420 | + * |
|
1421 | + * If the syncToken is expired (due to data cleanup) or unknown, you must |
|
1422 | + * return null. |
|
1423 | + * |
|
1424 | + * The limit is 'suggestive'. You are free to ignore it. |
|
1425 | + * |
|
1426 | + * @param string $calendarId |
|
1427 | + * @param string $syncToken |
|
1428 | + * @param int $syncLevel |
|
1429 | + * @param int $limit |
|
1430 | + * @return array |
|
1431 | + */ |
|
1432 | + function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limit = null) { |
|
1433 | + // Current synctoken |
|
1434 | + $stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
1435 | + $stmt->execute([ $calendarId ]); |
|
1436 | + $currentToken = $stmt->fetchColumn(0); |
|
1437 | + |
|
1438 | + if (is_null($currentToken)) { |
|
1439 | + return null; |
|
1440 | + } |
|
1441 | + |
|
1442 | + $result = [ |
|
1443 | + 'syncToken' => $currentToken, |
|
1444 | + 'added' => [], |
|
1445 | + 'modified' => [], |
|
1446 | + 'deleted' => [], |
|
1447 | + ]; |
|
1448 | + |
|
1449 | + if ($syncToken) { |
|
1450 | + |
|
1451 | + $query = "SELECT `uri`, `operation` FROM `*PREFIX*calendarchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `calendarid` = ? ORDER BY `synctoken`"; |
|
1452 | + if ($limit>0) { |
|
1453 | + $query.= " `LIMIT` " . (int)$limit; |
|
1454 | + } |
|
1455 | + |
|
1456 | + // Fetching all changes |
|
1457 | + $stmt = $this->db->prepare($query); |
|
1458 | + $stmt->execute([$syncToken, $currentToken, $calendarId]); |
|
1459 | + |
|
1460 | + $changes = []; |
|
1461 | + |
|
1462 | + // This loop ensures that any duplicates are overwritten, only the |
|
1463 | + // last change on a node is relevant. |
|
1464 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1465 | + |
|
1466 | + $changes[$row['uri']] = $row['operation']; |
|
1467 | + |
|
1468 | + } |
|
1469 | + |
|
1470 | + foreach($changes as $uri => $operation) { |
|
1471 | + |
|
1472 | + switch($operation) { |
|
1473 | + case 1 : |
|
1474 | + $result['added'][] = $uri; |
|
1475 | + break; |
|
1476 | + case 2 : |
|
1477 | + $result['modified'][] = $uri; |
|
1478 | + break; |
|
1479 | + case 3 : |
|
1480 | + $result['deleted'][] = $uri; |
|
1481 | + break; |
|
1482 | + } |
|
1483 | + |
|
1484 | + } |
|
1485 | + } else { |
|
1486 | + // No synctoken supplied, this is the initial sync. |
|
1487 | + $query = "SELECT `uri` FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ?"; |
|
1488 | + $stmt = $this->db->prepare($query); |
|
1489 | + $stmt->execute([$calendarId]); |
|
1490 | + |
|
1491 | + $result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN); |
|
1492 | + } |
|
1493 | + return $result; |
|
1494 | + |
|
1495 | + } |
|
1496 | + |
|
1497 | + /** |
|
1498 | + * Returns a list of subscriptions for a principal. |
|
1499 | + * |
|
1500 | + * Every subscription is an array with the following keys: |
|
1501 | + * * id, a unique id that will be used by other functions to modify the |
|
1502 | + * subscription. This can be the same as the uri or a database key. |
|
1503 | + * * uri. This is just the 'base uri' or 'filename' of the subscription. |
|
1504 | + * * principaluri. The owner of the subscription. Almost always the same as |
|
1505 | + * principalUri passed to this method. |
|
1506 | + * |
|
1507 | + * Furthermore, all the subscription info must be returned too: |
|
1508 | + * |
|
1509 | + * 1. {DAV:}displayname |
|
1510 | + * 2. {http://apple.com/ns/ical/}refreshrate |
|
1511 | + * 3. {http://calendarserver.org/ns/}subscribed-strip-todos (omit if todos |
|
1512 | + * should not be stripped). |
|
1513 | + * 4. {http://calendarserver.org/ns/}subscribed-strip-alarms (omit if alarms |
|
1514 | + * should not be stripped). |
|
1515 | + * 5. {http://calendarserver.org/ns/}subscribed-strip-attachments (omit if |
|
1516 | + * attachments should not be stripped). |
|
1517 | + * 6. {http://calendarserver.org/ns/}source (Must be a |
|
1518 | + * Sabre\DAV\Property\Href). |
|
1519 | + * 7. {http://apple.com/ns/ical/}calendar-color |
|
1520 | + * 8. {http://apple.com/ns/ical/}calendar-order |
|
1521 | + * 9. {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set |
|
1522 | + * (should just be an instance of |
|
1523 | + * Sabre\CalDAV\Property\SupportedCalendarComponentSet, with a bunch of |
|
1524 | + * default components). |
|
1525 | + * |
|
1526 | + * @param string $principalUri |
|
1527 | + * @return array |
|
1528 | + */ |
|
1529 | + function getSubscriptionsForUser($principalUri) { |
|
1530 | + $fields = array_values($this->subscriptionPropertyMap); |
|
1531 | + $fields[] = 'id'; |
|
1532 | + $fields[] = 'uri'; |
|
1533 | + $fields[] = 'source'; |
|
1534 | + $fields[] = 'principaluri'; |
|
1535 | + $fields[] = 'lastmodified'; |
|
1536 | + |
|
1537 | + $query = $this->db->getQueryBuilder(); |
|
1538 | + $query->select($fields) |
|
1539 | + ->from('calendarsubscriptions') |
|
1540 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1541 | + ->orderBy('calendarorder', 'asc'); |
|
1542 | + $stmt =$query->execute(); |
|
1543 | + |
|
1544 | + $subscriptions = []; |
|
1545 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1546 | + |
|
1547 | + $subscription = [ |
|
1548 | + 'id' => $row['id'], |
|
1549 | + 'uri' => $row['uri'], |
|
1550 | + 'principaluri' => $row['principaluri'], |
|
1551 | + 'source' => $row['source'], |
|
1552 | + 'lastmodified' => $row['lastmodified'], |
|
1553 | + |
|
1554 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO', 'VEVENT']), |
|
1555 | + ]; |
|
1556 | + |
|
1557 | + foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1558 | + if (!is_null($row[$dbName])) { |
|
1559 | + $subscription[$xmlName] = $row[$dbName]; |
|
1560 | + } |
|
1561 | + } |
|
1562 | + |
|
1563 | + $subscriptions[] = $subscription; |
|
1564 | + |
|
1565 | + } |
|
1566 | + |
|
1567 | + return $subscriptions; |
|
1568 | + } |
|
1569 | + |
|
1570 | + /** |
|
1571 | + * Creates a new subscription for a principal. |
|
1572 | + * |
|
1573 | + * If the creation was a success, an id must be returned that can be used to reference |
|
1574 | + * this subscription in other methods, such as updateSubscription. |
|
1575 | + * |
|
1576 | + * @param string $principalUri |
|
1577 | + * @param string $uri |
|
1578 | + * @param array $properties |
|
1579 | + * @return mixed |
|
1580 | + */ |
|
1581 | + function createSubscription($principalUri, $uri, array $properties) { |
|
1582 | + |
|
1583 | + if (!isset($properties['{http://calendarserver.org/ns/}source'])) { |
|
1584 | + throw new Forbidden('The {http://calendarserver.org/ns/}source property is required when creating subscriptions'); |
|
1585 | + } |
|
1586 | + |
|
1587 | + $values = [ |
|
1588 | + 'principaluri' => $principalUri, |
|
1589 | + 'uri' => $uri, |
|
1590 | + 'source' => $properties['{http://calendarserver.org/ns/}source']->getHref(), |
|
1591 | + 'lastmodified' => time(), |
|
1592 | + ]; |
|
1593 | + |
|
1594 | + $propertiesBoolean = ['striptodos', 'stripalarms', 'stripattachments']; |
|
1595 | + |
|
1596 | + foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1597 | + if (array_key_exists($xmlName, $properties)) { |
|
1598 | + $values[$dbName] = $properties[$xmlName]; |
|
1599 | + if (in_array($dbName, $propertiesBoolean)) { |
|
1600 | + $values[$dbName] = true; |
|
1601 | + } |
|
1602 | + } |
|
1603 | + } |
|
1604 | + |
|
1605 | + $valuesToInsert = array(); |
|
1606 | + |
|
1607 | + $query = $this->db->getQueryBuilder(); |
|
1608 | + |
|
1609 | + foreach (array_keys($values) as $name) { |
|
1610 | + $valuesToInsert[$name] = $query->createNamedParameter($values[$name]); |
|
1611 | + } |
|
1612 | + |
|
1613 | + $query->insert('calendarsubscriptions') |
|
1614 | + ->values($valuesToInsert) |
|
1615 | + ->execute(); |
|
1616 | + |
|
1617 | + return $this->db->lastInsertId('*PREFIX*calendarsubscriptions'); |
|
1618 | + } |
|
1619 | + |
|
1620 | + /** |
|
1621 | + * Updates a subscription |
|
1622 | + * |
|
1623 | + * The list of mutations is stored in a Sabre\DAV\PropPatch object. |
|
1624 | + * To do the actual updates, you must tell this object which properties |
|
1625 | + * you're going to process with the handle() method. |
|
1626 | + * |
|
1627 | + * Calling the handle method is like telling the PropPatch object "I |
|
1628 | + * promise I can handle updating this property". |
|
1629 | + * |
|
1630 | + * Read the PropPatch documentation for more info and examples. |
|
1631 | + * |
|
1632 | + * @param mixed $subscriptionId |
|
1633 | + * @param PropPatch $propPatch |
|
1634 | + * @return void |
|
1635 | + */ |
|
1636 | + function updateSubscription($subscriptionId, PropPatch $propPatch) { |
|
1637 | + $supportedProperties = array_keys($this->subscriptionPropertyMap); |
|
1638 | + $supportedProperties[] = '{http://calendarserver.org/ns/}source'; |
|
1639 | + |
|
1640 | + $propPatch->handle($supportedProperties, function($mutations) use ($subscriptionId) { |
|
1641 | + |
|
1642 | + $newValues = []; |
|
1643 | + |
|
1644 | + foreach($mutations as $propertyName=>$propertyValue) { |
|
1645 | + if ($propertyName === '{http://calendarserver.org/ns/}source') { |
|
1646 | + $newValues['source'] = $propertyValue->getHref(); |
|
1647 | + } else { |
|
1648 | + $fieldName = $this->subscriptionPropertyMap[$propertyName]; |
|
1649 | + $newValues[$fieldName] = $propertyValue; |
|
1650 | + } |
|
1651 | + } |
|
1652 | + |
|
1653 | + $query = $this->db->getQueryBuilder(); |
|
1654 | + $query->update('calendarsubscriptions') |
|
1655 | + ->set('lastmodified', $query->createNamedParameter(time())); |
|
1656 | + foreach($newValues as $fieldName=>$value) { |
|
1657 | + $query->set($fieldName, $query->createNamedParameter($value)); |
|
1658 | + } |
|
1659 | + $query->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) |
|
1660 | + ->execute(); |
|
1661 | + |
|
1662 | + return true; |
|
1663 | + |
|
1664 | + }); |
|
1665 | + } |
|
1666 | + |
|
1667 | + /** |
|
1668 | + * Deletes a subscription. |
|
1669 | + * |
|
1670 | + * @param mixed $subscriptionId |
|
1671 | + * @return void |
|
1672 | + */ |
|
1673 | + function deleteSubscription($subscriptionId) { |
|
1674 | + $query = $this->db->getQueryBuilder(); |
|
1675 | + $query->delete('calendarsubscriptions') |
|
1676 | + ->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) |
|
1677 | + ->execute(); |
|
1678 | + } |
|
1679 | + |
|
1680 | + /** |
|
1681 | + * Returns a single scheduling object for the inbox collection. |
|
1682 | + * |
|
1683 | + * The returned array should contain the following elements: |
|
1684 | + * * uri - A unique basename for the object. This will be used to |
|
1685 | + * construct a full uri. |
|
1686 | + * * calendardata - The iCalendar object |
|
1687 | + * * lastmodified - The last modification date. Can be an int for a unix |
|
1688 | + * timestamp, or a PHP DateTime object. |
|
1689 | + * * etag - A unique token that must change if the object changed. |
|
1690 | + * * size - The size of the object, in bytes. |
|
1691 | + * |
|
1692 | + * @param string $principalUri |
|
1693 | + * @param string $objectUri |
|
1694 | + * @return array |
|
1695 | + */ |
|
1696 | + function getSchedulingObject($principalUri, $objectUri) { |
|
1697 | + $query = $this->db->getQueryBuilder(); |
|
1698 | + $stmt = $query->select(['uri', 'calendardata', 'lastmodified', 'etag', 'size']) |
|
1699 | + ->from('schedulingobjects') |
|
1700 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1701 | + ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
1702 | + ->execute(); |
|
1703 | + |
|
1704 | + $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
1705 | + |
|
1706 | + if(!$row) { |
|
1707 | + return null; |
|
1708 | + } |
|
1709 | + |
|
1710 | + return [ |
|
1711 | + 'uri' => $row['uri'], |
|
1712 | + 'calendardata' => $row['calendardata'], |
|
1713 | + 'lastmodified' => $row['lastmodified'], |
|
1714 | + 'etag' => '"' . $row['etag'] . '"', |
|
1715 | + 'size' => (int)$row['size'], |
|
1716 | + ]; |
|
1717 | + } |
|
1718 | + |
|
1719 | + /** |
|
1720 | + * Returns all scheduling objects for the inbox collection. |
|
1721 | + * |
|
1722 | + * These objects should be returned as an array. Every item in the array |
|
1723 | + * should follow the same structure as returned from getSchedulingObject. |
|
1724 | + * |
|
1725 | + * The main difference is that 'calendardata' is optional. |
|
1726 | + * |
|
1727 | + * @param string $principalUri |
|
1728 | + * @return array |
|
1729 | + */ |
|
1730 | + function getSchedulingObjects($principalUri) { |
|
1731 | + $query = $this->db->getQueryBuilder(); |
|
1732 | + $stmt = $query->select(['uri', 'calendardata', 'lastmodified', 'etag', 'size']) |
|
1733 | + ->from('schedulingobjects') |
|
1734 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1735 | + ->execute(); |
|
1736 | + |
|
1737 | + $result = []; |
|
1738 | + foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
1739 | + $result[] = [ |
|
1740 | + 'calendardata' => $row['calendardata'], |
|
1741 | + 'uri' => $row['uri'], |
|
1742 | + 'lastmodified' => $row['lastmodified'], |
|
1743 | + 'etag' => '"' . $row['etag'] . '"', |
|
1744 | + 'size' => (int)$row['size'], |
|
1745 | + ]; |
|
1746 | + } |
|
1747 | + |
|
1748 | + return $result; |
|
1749 | + } |
|
1750 | + |
|
1751 | + /** |
|
1752 | + * Deletes a scheduling object from the inbox collection. |
|
1753 | + * |
|
1754 | + * @param string $principalUri |
|
1755 | + * @param string $objectUri |
|
1756 | + * @return void |
|
1757 | + */ |
|
1758 | + function deleteSchedulingObject($principalUri, $objectUri) { |
|
1759 | + $query = $this->db->getQueryBuilder(); |
|
1760 | + $query->delete('schedulingobjects') |
|
1761 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1762 | + ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
1763 | + ->execute(); |
|
1764 | + } |
|
1765 | + |
|
1766 | + /** |
|
1767 | + * Creates a new scheduling object. This should land in a users' inbox. |
|
1768 | + * |
|
1769 | + * @param string $principalUri |
|
1770 | + * @param string $objectUri |
|
1771 | + * @param string $objectData |
|
1772 | + * @return void |
|
1773 | + */ |
|
1774 | + function createSchedulingObject($principalUri, $objectUri, $objectData) { |
|
1775 | + $query = $this->db->getQueryBuilder(); |
|
1776 | + $query->insert('schedulingobjects') |
|
1777 | + ->values([ |
|
1778 | + 'principaluri' => $query->createNamedParameter($principalUri), |
|
1779 | + 'calendardata' => $query->createNamedParameter($objectData), |
|
1780 | + 'uri' => $query->createNamedParameter($objectUri), |
|
1781 | + 'lastmodified' => $query->createNamedParameter(time()), |
|
1782 | + 'etag' => $query->createNamedParameter(md5($objectData)), |
|
1783 | + 'size' => $query->createNamedParameter(strlen($objectData)) |
|
1784 | + ]) |
|
1785 | + ->execute(); |
|
1786 | + } |
|
1787 | + |
|
1788 | + /** |
|
1789 | + * Adds a change record to the calendarchanges table. |
|
1790 | + * |
|
1791 | + * @param mixed $calendarId |
|
1792 | + * @param string $objectUri |
|
1793 | + * @param int $operation 1 = add, 2 = modify, 3 = delete. |
|
1794 | + * @return void |
|
1795 | + */ |
|
1796 | + protected function addChange($calendarId, $objectUri, $operation) { |
|
1797 | + |
|
1798 | + $stmt = $this->db->prepare('INSERT INTO `*PREFIX*calendarchanges` (`uri`, `synctoken`, `calendarid`, `operation`) SELECT ?, `synctoken`, ?, ? FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
1799 | + $stmt->execute([ |
|
1800 | + $objectUri, |
|
1801 | + $calendarId, |
|
1802 | + $operation, |
|
1803 | + $calendarId |
|
1804 | + ]); |
|
1805 | + $stmt = $this->db->prepare('UPDATE `*PREFIX*calendars` SET `synctoken` = `synctoken` + 1 WHERE `id` = ?'); |
|
1806 | + $stmt->execute([ |
|
1807 | + $calendarId |
|
1808 | + ]); |
|
1809 | + |
|
1810 | + } |
|
1811 | + |
|
1812 | + /** |
|
1813 | + * Parses some information from calendar objects, used for optimized |
|
1814 | + * calendar-queries. |
|
1815 | + * |
|
1816 | + * Returns an array with the following keys: |
|
1817 | + * * etag - An md5 checksum of the object without the quotes. |
|
1818 | + * * size - Size of the object in bytes |
|
1819 | + * * componentType - VEVENT, VTODO or VJOURNAL |
|
1820 | + * * firstOccurence |
|
1821 | + * * lastOccurence |
|
1822 | + * * uid - value of the UID property |
|
1823 | + * |
|
1824 | + * @param string $calendarData |
|
1825 | + * @return array |
|
1826 | + */ |
|
1827 | + public function getDenormalizedData($calendarData) { |
|
1828 | + |
|
1829 | + $vObject = Reader::read($calendarData); |
|
1830 | + $componentType = null; |
|
1831 | + $component = null; |
|
1832 | + $firstOccurrence = null; |
|
1833 | + $lastOccurrence = null; |
|
1834 | + $uid = null; |
|
1835 | + $classification = self::CLASSIFICATION_PUBLIC; |
|
1836 | + foreach($vObject->getComponents() as $component) { |
|
1837 | + if ($component->name!=='VTIMEZONE') { |
|
1838 | + $componentType = $component->name; |
|
1839 | + $uid = (string)$component->UID; |
|
1840 | + break; |
|
1841 | + } |
|
1842 | + } |
|
1843 | + if (!$componentType) { |
|
1844 | + throw new \Sabre\DAV\Exception\BadRequest('Calendar objects must have a VJOURNAL, VEVENT or VTODO component'); |
|
1845 | + } |
|
1846 | + if ($componentType === 'VEVENT' && $component->DTSTART) { |
|
1847 | + $firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp(); |
|
1848 | + // Finding the last occurrence is a bit harder |
|
1849 | + if (!isset($component->RRULE)) { |
|
1850 | + if (isset($component->DTEND)) { |
|
1851 | + $lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp(); |
|
1852 | + } elseif (isset($component->DURATION)) { |
|
1853 | + $endDate = clone $component->DTSTART->getDateTime(); |
|
1854 | + $endDate->add(DateTimeParser::parse($component->DURATION->getValue())); |
|
1855 | + $lastOccurrence = $endDate->getTimeStamp(); |
|
1856 | + } elseif (!$component->DTSTART->hasTime()) { |
|
1857 | + $endDate = clone $component->DTSTART->getDateTime(); |
|
1858 | + $endDate->modify('+1 day'); |
|
1859 | + $lastOccurrence = $endDate->getTimeStamp(); |
|
1860 | + } else { |
|
1861 | + $lastOccurrence = $firstOccurrence; |
|
1862 | + } |
|
1863 | + } else { |
|
1864 | + $it = new EventIterator($vObject, (string)$component->UID); |
|
1865 | + $maxDate = new \DateTime(self::MAX_DATE); |
|
1866 | + if ($it->isInfinite()) { |
|
1867 | + $lastOccurrence = $maxDate->getTimestamp(); |
|
1868 | + } else { |
|
1869 | + $end = $it->getDtEnd(); |
|
1870 | + while($it->valid() && $end < $maxDate) { |
|
1871 | + $end = $it->getDtEnd(); |
|
1872 | + $it->next(); |
|
1873 | + |
|
1874 | + } |
|
1875 | + $lastOccurrence = $end->getTimestamp(); |
|
1876 | + } |
|
1877 | + |
|
1878 | + } |
|
1879 | + } |
|
1880 | + |
|
1881 | + if ($component->CLASS) { |
|
1882 | + $classification = CalDavBackend::CLASSIFICATION_PRIVATE; |
|
1883 | + switch ($component->CLASS->getValue()) { |
|
1884 | + case 'PUBLIC': |
|
1885 | + $classification = CalDavBackend::CLASSIFICATION_PUBLIC; |
|
1886 | + break; |
|
1887 | + case 'CONFIDENTIAL': |
|
1888 | + $classification = CalDavBackend::CLASSIFICATION_CONFIDENTIAL; |
|
1889 | + break; |
|
1890 | + } |
|
1891 | + } |
|
1892 | + return [ |
|
1893 | + 'etag' => md5($calendarData), |
|
1894 | + 'size' => strlen($calendarData), |
|
1895 | + 'componentType' => $componentType, |
|
1896 | + 'firstOccurence' => is_null($firstOccurrence) ? null : max(0, $firstOccurrence), |
|
1897 | + 'lastOccurence' => $lastOccurrence, |
|
1898 | + 'uid' => $uid, |
|
1899 | + 'classification' => $classification |
|
1900 | + ]; |
|
1901 | + |
|
1902 | + } |
|
1903 | + |
|
1904 | + private function readBlob($cardData) { |
|
1905 | + if (is_resource($cardData)) { |
|
1906 | + return stream_get_contents($cardData); |
|
1907 | + } |
|
1908 | + |
|
1909 | + return $cardData; |
|
1910 | + } |
|
1911 | + |
|
1912 | + /** |
|
1913 | + * @param IShareable $shareable |
|
1914 | + * @param array $add |
|
1915 | + * @param array $remove |
|
1916 | + */ |
|
1917 | + public function updateShares($shareable, $add, $remove) { |
|
1918 | + $calendarId = $shareable->getResourceId(); |
|
1919 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateShares', new GenericEvent( |
|
1920 | + '\OCA\DAV\CalDAV\CalDavBackend::updateShares', |
|
1921 | + [ |
|
1922 | + 'calendarId' => $calendarId, |
|
1923 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
1924 | + 'shares' => $this->getShares($calendarId), |
|
1925 | + 'add' => $add, |
|
1926 | + 'remove' => $remove, |
|
1927 | + ])); |
|
1928 | + $this->sharingBackend->updateShares($shareable, $add, $remove); |
|
1929 | + } |
|
1930 | + |
|
1931 | + /** |
|
1932 | + * @param int $resourceId |
|
1933 | + * @return array |
|
1934 | + */ |
|
1935 | + public function getShares($resourceId) { |
|
1936 | + return $this->sharingBackend->getShares($resourceId); |
|
1937 | + } |
|
1938 | + |
|
1939 | + /** |
|
1940 | + * @param boolean $value |
|
1941 | + * @param \OCA\DAV\CalDAV\Calendar $calendar |
|
1942 | + * @return string|null |
|
1943 | + */ |
|
1944 | + public function setPublishStatus($value, $calendar) { |
|
1945 | + $query = $this->db->getQueryBuilder(); |
|
1946 | + if ($value) { |
|
1947 | + $publicUri = $this->random->generate(16, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS); |
|
1948 | + $query->insert('dav_shares') |
|
1949 | + ->values([ |
|
1950 | + 'principaluri' => $query->createNamedParameter($calendar->getPrincipalURI()), |
|
1951 | + 'type' => $query->createNamedParameter('calendar'), |
|
1952 | + 'access' => $query->createNamedParameter(self::ACCESS_PUBLIC), |
|
1953 | + 'resourceid' => $query->createNamedParameter($calendar->getResourceId()), |
|
1954 | + 'publicuri' => $query->createNamedParameter($publicUri) |
|
1955 | + ]); |
|
1956 | + $query->execute(); |
|
1957 | + return $publicUri; |
|
1958 | + } |
|
1959 | + $query->delete('dav_shares') |
|
1960 | + ->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) |
|
1961 | + ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))); |
|
1962 | + $query->execute(); |
|
1963 | + return null; |
|
1964 | + } |
|
1965 | + |
|
1966 | + /** |
|
1967 | + * @param \OCA\DAV\CalDAV\Calendar $calendar |
|
1968 | + * @return mixed |
|
1969 | + */ |
|
1970 | + public function getPublishStatus($calendar) { |
|
1971 | + $query = $this->db->getQueryBuilder(); |
|
1972 | + $result = $query->select('publicuri') |
|
1973 | + ->from('dav_shares') |
|
1974 | + ->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) |
|
1975 | + ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
1976 | + ->execute(); |
|
1977 | + |
|
1978 | + $row = $result->fetch(); |
|
1979 | + $result->closeCursor(); |
|
1980 | + return $row ? reset($row) : false; |
|
1981 | + } |
|
1982 | + |
|
1983 | + /** |
|
1984 | + * @param int $resourceId |
|
1985 | + * @param array $acl |
|
1986 | + * @return array |
|
1987 | + */ |
|
1988 | + public function applyShareAcl($resourceId, $acl) { |
|
1989 | + return $this->sharingBackend->applyShareAcl($resourceId, $acl); |
|
1990 | + } |
|
1991 | + |
|
1992 | + |
|
1993 | + |
|
1994 | + /** |
|
1995 | + * update properties table |
|
1996 | + * |
|
1997 | + * @param int $calendarId |
|
1998 | + * @param string $objectUri |
|
1999 | + * @param string $calendarData |
|
2000 | + */ |
|
2001 | + public function updateProperties($calendarId, $objectUri, $calendarData) { |
|
2002 | + $objectId = $this->getCalendarObjectId($calendarId, $objectUri); |
|
2003 | + |
|
2004 | + try { |
|
2005 | + $vCalendar = $this->readCalendarData($calendarData); |
|
2006 | + } catch (\Exception $ex) { |
|
2007 | + return; |
|
2008 | + } |
|
2009 | + |
|
2010 | + $this->purgeProperties($calendarId, $objectId); |
|
2011 | + |
|
2012 | + $query = $this->db->getQueryBuilder(); |
|
2013 | + $query->insert($this->dbObjectPropertiesTable) |
|
2014 | + ->values( |
|
2015 | + [ |
|
2016 | + 'calendarid' => $query->createNamedParameter($calendarId), |
|
2017 | + 'objectid' => $query->createNamedParameter($objectId), |
|
2018 | + 'name' => $query->createParameter('name'), |
|
2019 | + 'parameter' => $query->createParameter('parameter'), |
|
2020 | + 'value' => $query->createParameter('value'), |
|
2021 | + ] |
|
2022 | + ); |
|
2023 | + |
|
2024 | + $indexComponents = ['VEVENT', 'VJOURNAL', 'VTODO']; |
|
2025 | + foreach ($vCalendar->getComponents() as $component) { |
|
2026 | + if (!in_array($component->name, $indexComponents)) { |
|
2027 | + continue; |
|
2028 | + } |
|
2029 | + |
|
2030 | + foreach ($component->children() as $property) { |
|
2031 | + if (in_array($property->name, self::$indexProperties)) { |
|
2032 | + $value = $property->getValue(); |
|
2033 | + // is this a shitty db? |
|
2034 | + if (!$this->db->supports4ByteText()) { |
|
2035 | + $value = preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $value); |
|
2036 | + } |
|
2037 | + $value = substr($value, 0, 254); |
|
2038 | + |
|
2039 | + $query->setParameter('name', $property->name); |
|
2040 | + $query->setParameter('parameter', null); |
|
2041 | + $query->setParameter('value', $value); |
|
2042 | + $query->execute(); |
|
2043 | + } |
|
2044 | + |
|
2045 | + if (in_array($property->name, array_keys(self::$indexParameters))) { |
|
2046 | + $parameters = $property->parameters(); |
|
2047 | + $indexedParametersForProperty = self::$indexParameters[$property->name]; |
|
2048 | + |
|
2049 | + foreach ($parameters as $key => $value) { |
|
2050 | + if (in_array($key, $indexedParametersForProperty)) { |
|
2051 | + // is this a shitty db? |
|
2052 | + if ($this->db->supports4ByteText()) { |
|
2053 | + $value = preg_replace('/[\x{10000}-\x{10FFFF}]/u', "\xEF\xBF\xBD", $value); |
|
2054 | + } |
|
2055 | + $value = substr($value, 0, 254); |
|
2056 | + |
|
2057 | + $query->setParameter('name', $property->name); |
|
2058 | + $query->setParameter('parameter', substr($key, 0, 254)); |
|
2059 | + $query->setParameter('value', substr($value, 0, 254)); |
|
2060 | + $query->execute(); |
|
2061 | + } |
|
2062 | + } |
|
2063 | + } |
|
2064 | + } |
|
2065 | + } |
|
2066 | + } |
|
2067 | + |
|
2068 | + /** |
|
2069 | + * read VCalendar data into a VCalendar object |
|
2070 | + * |
|
2071 | + * @param string $objectData |
|
2072 | + * @return VCalendar |
|
2073 | + */ |
|
2074 | + protected function readCalendarData($objectData) { |
|
2075 | + return Reader::read($objectData); |
|
2076 | + } |
|
2077 | + |
|
2078 | + /** |
|
2079 | + * delete all properties from a given calendar object |
|
2080 | + * |
|
2081 | + * @param int $calendarId |
|
2082 | + * @param int $objectId |
|
2083 | + */ |
|
2084 | + protected function purgeProperties($calendarId, $objectId) { |
|
2085 | + $query = $this->db->getQueryBuilder(); |
|
2086 | + $query->delete($this->dbObjectPropertiesTable) |
|
2087 | + ->where($query->expr()->eq('objectid', $query->createNamedParameter($objectId))) |
|
2088 | + ->andWhere($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
2089 | + $query->execute(); |
|
2090 | + } |
|
2091 | + |
|
2092 | + /** |
|
2093 | + * get ID from a given calendar object |
|
2094 | + * |
|
2095 | + * @param int $calendarId |
|
2096 | + * @param string $uri |
|
2097 | + * @return int |
|
2098 | + */ |
|
2099 | + protected function getCalendarObjectId($calendarId, $uri) { |
|
2100 | + $query = $this->db->getQueryBuilder(); |
|
2101 | + $query->select('id')->from('calendarobjects') |
|
2102 | + ->where($query->expr()->eq('uri', $query->createNamedParameter($uri))) |
|
2103 | + ->andWhere($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
2104 | + |
|
2105 | + $result = $query->execute(); |
|
2106 | + $objectIds = $result->fetch(); |
|
2107 | + $result->closeCursor(); |
|
2108 | + |
|
2109 | + if (!isset($objectIds['id'])) { |
|
2110 | + throw new \InvalidArgumentException('Calendarobject does not exists: ' . $uri); |
|
2111 | + } |
|
2112 | + |
|
2113 | + return (int)$objectIds['id']; |
|
2114 | + } |
|
2115 | + |
|
2116 | + private function convertPrincipal($principalUri, $toV2) { |
|
2117 | + if ($this->principalBackend->getPrincipalPrefix() === 'principals') { |
|
2118 | + list(, $name) = URLUtil::splitPath($principalUri); |
|
2119 | + if ($toV2 === true) { |
|
2120 | + return "principals/users/$name"; |
|
2121 | + } |
|
2122 | + return "principals/$name"; |
|
2123 | + } |
|
2124 | + return $principalUri; |
|
2125 | + } |
|
2126 | + |
|
2127 | + private function addOwnerPrincipal(&$calendarInfo) { |
|
2128 | + $ownerPrincipalKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'; |
|
2129 | + $displaynameKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname'; |
|
2130 | + if (isset($calendarInfo[$ownerPrincipalKey])) { |
|
2131 | + $uri = $calendarInfo[$ownerPrincipalKey]; |
|
2132 | + } else { |
|
2133 | + $uri = $calendarInfo['principaluri']; |
|
2134 | + } |
|
2135 | + |
|
2136 | + $principalInformation = $this->principalBackend->getPrincipalByPath($uri); |
|
2137 | + if (isset($principalInformation['{DAV:}displayname'])) { |
|
2138 | + $calendarInfo[$displaynameKey] = $principalInformation['{DAV:}displayname']; |
|
2139 | + } |
|
2140 | + } |
|
2141 | + |
|
2142 | + /** |
|
2143 | + * Add a reminder for an event |
|
2144 | + * |
|
2145 | + * @param string $calendarId |
|
2146 | + * @param string $objectUri |
|
2147 | + * @param string $type |
|
2148 | + * @param \DateTime $time |
|
2149 | + */ |
|
2150 | + public function addReminderForEvent($calendarId, $objectUri, $type, \DateTime $time) { |
|
2151 | + $query = $this->db->getQueryBuilder(); |
|
2152 | + $query->insert('calendar_reminders') |
|
2153 | + ->values([ |
|
2154 | + 'calendarid' => $query->createNamedParameter($calendarId), |
|
2155 | + 'objecturi' => $query->createNamedParameter($objectUri), |
|
2156 | + 'type' => $query->createNamedParameter($type), |
|
2157 | + 'notificationDate' => $query->createNamedParameter($time->getTimestamp()), |
|
2158 | + ]); |
|
2159 | + $query->execute(); |
|
2160 | + } |
|
2161 | + |
|
2162 | + /** |
|
2163 | + * Cleans reminders in database |
|
2164 | + * |
|
2165 | + * @param string $calendarId |
|
2166 | + * @param string $objectUri |
|
2167 | + */ |
|
2168 | + public function cleanRemindersForEvent($calendarId, $objectUri) { |
|
2169 | + $query = $this->db->getQueryBuilder(); |
|
2170 | + |
|
2171 | + $query->delete('calendar_reminders') |
|
2172 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
2173 | + ->andWhere($query->expr()->eq('objecturi', $query->createNamedParameter($objectUri))) |
|
2174 | + ->execute(); |
|
2175 | + } |
|
2176 | + |
|
2177 | + public function removeReminder($reminderId) { |
|
2178 | + $query = $this->db->getQueryBuilder(); |
|
2179 | + |
|
2180 | + $query->delete('calendar_reminders') |
|
2181 | + ->where($query->expr()->eq('id', $query->createNamedParameter($reminderId))) |
|
2182 | + ->execute(); |
|
2183 | + } |
|
2184 | + |
|
2185 | + /** |
|
2186 | + * Get reminders |
|
2187 | + * |
|
2188 | + * @return array |
|
2189 | + */ |
|
2190 | + public function getReminders() { |
|
2191 | + $query = $this->db->getQueryBuilder(); |
|
2192 | + $fields = ['id', 'calendarId', 'objecturi', 'type', 'notificationDate']; |
|
2193 | + $result = $query->select($fields) |
|
2194 | + ->from('calendar_reminders') |
|
2195 | + ->execute(); |
|
2196 | + |
|
2197 | + $reminders = []; |
|
2198 | + while($row = $result->fetch(\PDO::FETCH_ASSOC)) { |
|
2199 | + $reminder = [ |
|
2200 | + 'id' => $row['id'], |
|
2201 | + 'calendarId' => $row['calendarId'], |
|
2202 | + 'objecturi' => $row['objecturi'], |
|
2203 | + 'type' => $row['type'], |
|
2204 | + 'notificationDate' => $row['notificationDate'] |
|
2205 | + ]; |
|
2206 | + |
|
2207 | + if ($calendarData = $this->getCalendarObject($row['calendarId'], $row['objecturi'])) { |
|
2208 | + $reminder['data'] = $calendarData['calendardata']; |
|
2209 | + } |
|
2210 | + |
|
2211 | + if ($calendar = $this->getCalendarById($row['calendarId'])) { |
|
2212 | + $reminder['owner'] = substr($calendar['principaluri'], 10); |
|
2213 | + } |
|
2214 | + |
|
2215 | + if ($shares = $this->getShares($row['calendarId'])) { |
|
2216 | + $key = 'href'; |
|
2217 | + $reminder['sharees'] = array_map(function ($item) use ($key) { |
|
2218 | + return substr($item[$key], 10); |
|
2219 | + }, $shares); |
|
2220 | + } |
|
2221 | + |
|
2222 | + $reminders[$reminder['id']] = $reminder; |
|
2223 | + } |
|
2224 | + return $reminders; |
|
2225 | + } |
|
2226 | 2226 | } |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | $query->andWhere($query->expr()->neq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))); |
200 | 200 | } |
201 | 201 | |
202 | - return (int)$query->execute()->fetchColumn(); |
|
202 | + return (int) $query->execute()->fetchColumn(); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
@@ -246,25 +246,25 @@ discard block |
||
246 | 246 | $stmt = $query->execute(); |
247 | 247 | |
248 | 248 | $calendars = []; |
249 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
249 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
250 | 250 | |
251 | 251 | $components = []; |
252 | 252 | if ($row['components']) { |
253 | - $components = explode(',',$row['components']); |
|
253 | + $components = explode(',', $row['components']); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | $calendar = [ |
257 | 257 | 'id' => $row['id'], |
258 | 258 | 'uri' => $row['uri'], |
259 | 259 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
260 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
261 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
262 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
263 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
264 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
260 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
261 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
262 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
263 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
264 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}owner-principal' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
265 | 265 | ]; |
266 | 266 | |
267 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
267 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
268 | 268 | $calendar[$xmlName] = $row[$dbName]; |
269 | 269 | } |
270 | 270 | |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | $principals = array_map(function($principal) { |
283 | 283 | return urldecode($principal); |
284 | 284 | }, $principals); |
285 | - $principals[]= $principalUri; |
|
285 | + $principals[] = $principalUri; |
|
286 | 286 | |
287 | 287 | $fields = array_values($this->propertyMap); |
288 | 288 | $fields[] = 'a.id'; |
@@ -302,8 +302,8 @@ discard block |
||
302 | 302 | ->setParameter('principaluri', $principals, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) |
303 | 303 | ->execute(); |
304 | 304 | |
305 | - $readOnlyPropertyName = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'; |
|
306 | - while($row = $result->fetch()) { |
|
305 | + $readOnlyPropertyName = '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}read-only'; |
|
306 | + while ($row = $result->fetch()) { |
|
307 | 307 | if ($row['principaluri'] === $principalUri) { |
308 | 308 | continue; |
309 | 309 | } |
@@ -322,25 +322,25 @@ discard block |
||
322 | 322 | } |
323 | 323 | |
324 | 324 | list(, $name) = URLUtil::splitPath($row['principaluri']); |
325 | - $uri = $row['uri'] . '_shared_by_' . $name; |
|
326 | - $row['displayname'] = $row['displayname'] . ' (' . $this->getUserDisplayName($name) . ')'; |
|
325 | + $uri = $row['uri'].'_shared_by_'.$name; |
|
326 | + $row['displayname'] = $row['displayname'].' ('.$this->getUserDisplayName($name).')'; |
|
327 | 327 | $components = []; |
328 | 328 | if ($row['components']) { |
329 | - $components = explode(',',$row['components']); |
|
329 | + $components = explode(',', $row['components']); |
|
330 | 330 | } |
331 | 331 | $calendar = [ |
332 | 332 | 'id' => $row['id'], |
333 | 333 | 'uri' => $uri, |
334 | 334 | 'principaluri' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
335 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
336 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
337 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
338 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
339 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
335 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
336 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
337 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
338 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
339 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
340 | 340 | $readOnlyPropertyName => $readOnly, |
341 | 341 | ]; |
342 | 342 | |
343 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
343 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
344 | 344 | $calendar[$xmlName] = $row[$dbName]; |
345 | 345 | } |
346 | 346 | |
@@ -369,21 +369,21 @@ discard block |
||
369 | 369 | ->orderBy('calendarorder', 'ASC'); |
370 | 370 | $stmt = $query->execute(); |
371 | 371 | $calendars = []; |
372 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
372 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
373 | 373 | $components = []; |
374 | 374 | if ($row['components']) { |
375 | - $components = explode(',',$row['components']); |
|
375 | + $components = explode(',', $row['components']); |
|
376 | 376 | } |
377 | 377 | $calendar = [ |
378 | 378 | 'id' => $row['id'], |
379 | 379 | 'uri' => $row['uri'], |
380 | 380 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
381 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
382 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
383 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
384 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
381 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
382 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
383 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
384 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
385 | 385 | ]; |
386 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
386 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
387 | 387 | $calendar[$xmlName] = $row[$dbName]; |
388 | 388 | } |
389 | 389 | |
@@ -434,27 +434,27 @@ discard block |
||
434 | 434 | ->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar'))) |
435 | 435 | ->execute(); |
436 | 436 | |
437 | - while($row = $result->fetch()) { |
|
437 | + while ($row = $result->fetch()) { |
|
438 | 438 | list(, $name) = URLUtil::splitPath($row['principaluri']); |
439 | - $row['displayname'] = $row['displayname'] . "($name)"; |
|
439 | + $row['displayname'] = $row['displayname']."($name)"; |
|
440 | 440 | $components = []; |
441 | 441 | if ($row['components']) { |
442 | - $components = explode(',',$row['components']); |
|
442 | + $components = explode(',', $row['components']); |
|
443 | 443 | } |
444 | 444 | $calendar = [ |
445 | 445 | 'id' => $row['id'], |
446 | 446 | 'uri' => $row['publicuri'], |
447 | 447 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
448 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
449 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
450 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
451 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
452 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], $this->legacyEndpoint), |
|
453 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
454 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
448 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
449 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
450 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
451 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
452 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}owner-principal' => $this->convertPrincipal($row['principaluri'], $this->legacyEndpoint), |
|
453 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}read-only' => (int) $row['access'] === Backend::ACCESS_READ, |
|
454 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}public' => (int) $row['access'] === self::ACCESS_PUBLIC, |
|
455 | 455 | ]; |
456 | 456 | |
457 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
457 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
458 | 458 | $calendar[$xmlName] = $row[$dbName]; |
459 | 459 | } |
460 | 460 | |
@@ -498,29 +498,29 @@ discard block |
||
498 | 498 | $result->closeCursor(); |
499 | 499 | |
500 | 500 | if ($row === false) { |
501 | - throw new NotFound('Node with name \'' . $uri . '\' could not be found'); |
|
501 | + throw new NotFound('Node with name \''.$uri.'\' could not be found'); |
|
502 | 502 | } |
503 | 503 | |
504 | 504 | list(, $name) = URLUtil::splitPath($row['principaluri']); |
505 | - $row['displayname'] = $row['displayname'] . ' ' . "($name)"; |
|
505 | + $row['displayname'] = $row['displayname'].' '."($name)"; |
|
506 | 506 | $components = []; |
507 | 507 | if ($row['components']) { |
508 | - $components = explode(',',$row['components']); |
|
508 | + $components = explode(',', $row['components']); |
|
509 | 509 | } |
510 | 510 | $calendar = [ |
511 | 511 | 'id' => $row['id'], |
512 | 512 | 'uri' => $row['publicuri'], |
513 | 513 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
514 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
515 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
516 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
517 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
518 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
519 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
520 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
514 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
515 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
516 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
517 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
518 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
519 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}read-only' => (int) $row['access'] === Backend::ACCESS_READ, |
|
520 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}public' => (int) $row['access'] === self::ACCESS_PUBLIC, |
|
521 | 521 | ]; |
522 | 522 | |
523 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
523 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
524 | 524 | $calendar[$xmlName] = $row[$dbName]; |
525 | 525 | } |
526 | 526 | |
@@ -560,20 +560,20 @@ discard block |
||
560 | 560 | |
561 | 561 | $components = []; |
562 | 562 | if ($row['components']) { |
563 | - $components = explode(',',$row['components']); |
|
563 | + $components = explode(',', $row['components']); |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | $calendar = [ |
567 | 567 | 'id' => $row['id'], |
568 | 568 | 'uri' => $row['uri'], |
569 | 569 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
570 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
571 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
572 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
573 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
570 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
571 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
572 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
573 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
574 | 574 | ]; |
575 | 575 | |
576 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
576 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
577 | 577 | $calendar[$xmlName] = $row[$dbName]; |
578 | 578 | } |
579 | 579 | |
@@ -606,20 +606,20 @@ discard block |
||
606 | 606 | |
607 | 607 | $components = []; |
608 | 608 | if ($row['components']) { |
609 | - $components = explode(',',$row['components']); |
|
609 | + $components = explode(',', $row['components']); |
|
610 | 610 | } |
611 | 611 | |
612 | 612 | $calendar = [ |
613 | 613 | 'id' => $row['id'], |
614 | 614 | 'uri' => $row['uri'], |
615 | 615 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
616 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
617 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
618 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
619 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
616 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
617 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
618 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
619 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
620 | 620 | ]; |
621 | 621 | |
622 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
622 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
623 | 623 | $calendar[$xmlName] = $row[$dbName]; |
624 | 624 | } |
625 | 625 | |
@@ -653,16 +653,16 @@ discard block |
||
653 | 653 | $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set'; |
654 | 654 | if (isset($properties[$sccs])) { |
655 | 655 | if (!($properties[$sccs] instanceof SupportedCalendarComponentSet)) { |
656 | - throw new DAV\Exception('The ' . $sccs . ' property must be of type: \Sabre\CalDAV\Property\SupportedCalendarComponentSet'); |
|
656 | + throw new DAV\Exception('The '.$sccs.' property must be of type: \Sabre\CalDAV\Property\SupportedCalendarComponentSet'); |
|
657 | 657 | } |
658 | - $values['components'] = implode(',',$properties[$sccs]->getValue()); |
|
658 | + $values['components'] = implode(',', $properties[$sccs]->getValue()); |
|
659 | 659 | } |
660 | - $transp = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
660 | + $transp = '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp'; |
|
661 | 661 | if (isset($properties[$transp])) { |
662 | 662 | $values['transparent'] = (int) ($properties[$transp]->getValue() === 'transparent'); |
663 | 663 | } |
664 | 664 | |
665 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
665 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
666 | 666 | if (isset($properties[$xmlName])) { |
667 | 667 | $values[$dbName] = $properties[$xmlName]; |
668 | 668 | } |
@@ -670,7 +670,7 @@ discard block |
||
670 | 670 | |
671 | 671 | $query = $this->db->getQueryBuilder(); |
672 | 672 | $query->insert('calendars'); |
673 | - foreach($values as $column => $value) { |
|
673 | + foreach ($values as $column => $value) { |
|
674 | 674 | $query->setValue($column, $query->createNamedParameter($value)); |
675 | 675 | } |
676 | 676 | $query->execute(); |
@@ -703,14 +703,14 @@ discard block |
||
703 | 703 | */ |
704 | 704 | function updateCalendar($calendarId, PropPatch $propPatch) { |
705 | 705 | $supportedProperties = array_keys($this->propertyMap); |
706 | - $supportedProperties[] = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
706 | + $supportedProperties[] = '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp'; |
|
707 | 707 | |
708 | 708 | $propPatch->handle($supportedProperties, function($mutations) use ($calendarId) { |
709 | 709 | $newValues = []; |
710 | 710 | foreach ($mutations as $propertyName => $propertyValue) { |
711 | 711 | |
712 | 712 | switch ($propertyName) { |
713 | - case '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' : |
|
713 | + case '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' : |
|
714 | 714 | $fieldName = 'transparent'; |
715 | 715 | $newValues[$fieldName] = (int) ($propertyValue->getValue() === 'transparent'); |
716 | 716 | break; |
@@ -825,16 +825,16 @@ discard block |
||
825 | 825 | $stmt = $query->execute(); |
826 | 826 | |
827 | 827 | $result = []; |
828 | - foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
828 | + foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
829 | 829 | $result[] = [ |
830 | 830 | 'id' => $row['id'], |
831 | 831 | 'uri' => $row['uri'], |
832 | 832 | 'lastmodified' => $row['lastmodified'], |
833 | - 'etag' => '"' . $row['etag'] . '"', |
|
833 | + 'etag' => '"'.$row['etag'].'"', |
|
834 | 834 | 'calendarid' => $row['calendarid'], |
835 | - 'size' => (int)$row['size'], |
|
835 | + 'size' => (int) $row['size'], |
|
836 | 836 | 'component' => strtolower($row['componenttype']), |
837 | - 'classification'=> (int)$row['classification'] |
|
837 | + 'classification'=> (int) $row['classification'] |
|
838 | 838 | ]; |
839 | 839 | } |
840 | 840 | |
@@ -867,18 +867,18 @@ discard block |
||
867 | 867 | $stmt = $query->execute(); |
868 | 868 | $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
869 | 869 | |
870 | - if(!$row) return null; |
|
870 | + if (!$row) return null; |
|
871 | 871 | |
872 | 872 | return [ |
873 | 873 | 'id' => $row['id'], |
874 | 874 | 'uri' => $row['uri'], |
875 | 875 | 'lastmodified' => $row['lastmodified'], |
876 | - 'etag' => '"' . $row['etag'] . '"', |
|
876 | + 'etag' => '"'.$row['etag'].'"', |
|
877 | 877 | 'calendarid' => $row['calendarid'], |
878 | - 'size' => (int)$row['size'], |
|
878 | + 'size' => (int) $row['size'], |
|
879 | 879 | 'calendardata' => $this->readBlob($row['calendardata']), |
880 | 880 | 'component' => strtolower($row['componenttype']), |
881 | - 'classification'=> (int)$row['classification'] |
|
881 | + 'classification'=> (int) $row['classification'] |
|
882 | 882 | ]; |
883 | 883 | } |
884 | 884 | |
@@ -917,12 +917,12 @@ discard block |
||
917 | 917 | 'id' => $row['id'], |
918 | 918 | 'uri' => $row['uri'], |
919 | 919 | 'lastmodified' => $row['lastmodified'], |
920 | - 'etag' => '"' . $row['etag'] . '"', |
|
920 | + 'etag' => '"'.$row['etag'].'"', |
|
921 | 921 | 'calendarid' => $row['calendarid'], |
922 | - 'size' => (int)$row['size'], |
|
922 | + 'size' => (int) $row['size'], |
|
923 | 923 | 'calendardata' => $this->readBlob($row['calendardata']), |
924 | 924 | 'component' => strtolower($row['componenttype']), |
925 | - 'classification' => (int)$row['classification'] |
|
925 | + 'classification' => (int) $row['classification'] |
|
926 | 926 | ]; |
927 | 927 | } |
928 | 928 | $result->closeCursor(); |
@@ -987,7 +987,7 @@ discard block |
||
987 | 987 | 'objectUri' => $objectUri, |
988 | 988 | 'calendarData' => $calendarData])); |
989 | 989 | |
990 | - return '"' . $extraData['etag'] . '"'; |
|
990 | + return '"'.$extraData['etag'].'"'; |
|
991 | 991 | } |
992 | 992 | |
993 | 993 | /** |
@@ -1047,7 +1047,7 @@ discard block |
||
1047 | 1047 | 'objectUri' => $objectUri, |
1048 | 1048 | 'calendarData' => $calendarData])); |
1049 | 1049 | |
1050 | - return '"' . $extraData['etag'] . '"'; |
|
1050 | + return '"'.$extraData['etag'].'"'; |
|
1051 | 1051 | } |
1052 | 1052 | |
1053 | 1053 | /** |
@@ -1205,7 +1205,7 @@ discard block |
||
1205 | 1205 | $stmt = $query->execute(); |
1206 | 1206 | |
1207 | 1207 | $result = []; |
1208 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1208 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1209 | 1209 | if ($requirePostFilter) { |
1210 | 1210 | if (!$this->validateFilterForObject($row, $filters)) { |
1211 | 1211 | continue; |
@@ -1226,14 +1226,14 @@ discard block |
||
1226 | 1226 | * @param integer|null $offset |
1227 | 1227 | * @return array |
1228 | 1228 | */ |
1229 | - public function calendarSearch($principalUri, array $filters, $limit=null, $offset=null) { |
|
1229 | + public function calendarSearch($principalUri, array $filters, $limit = null, $offset = null) { |
|
1230 | 1230 | $calendars = $this->getCalendarsForUser($principalUri); |
1231 | 1231 | $ownCalendars = []; |
1232 | 1232 | $sharedCalendars = []; |
1233 | 1233 | |
1234 | 1234 | $uriMapper = []; |
1235 | 1235 | |
1236 | - foreach($calendars as $calendar) { |
|
1236 | + foreach ($calendars as $calendar) { |
|
1237 | 1237 | if ($calendar['{http://owncloud.org/ns}owner-principal'] === $principalUri) { |
1238 | 1238 | $ownCalendars[] = $calendar['id']; |
1239 | 1239 | } else { |
@@ -1248,11 +1248,11 @@ discard block |
||
1248 | 1248 | $query = $this->db->getQueryBuilder(); |
1249 | 1249 | // Calendar id expressions |
1250 | 1250 | $calendarExpressions = []; |
1251 | - foreach($ownCalendars as $id) { |
|
1251 | + foreach ($ownCalendars as $id) { |
|
1252 | 1252 | $calendarExpressions[] = $query->expr() |
1253 | 1253 | ->eq('c.calendarid', $query->createNamedParameter($id)); |
1254 | 1254 | } |
1255 | - foreach($sharedCalendars as $id) { |
|
1255 | + foreach ($sharedCalendars as $id) { |
|
1256 | 1256 | $calendarExpressions[] = $query->expr()->andX( |
1257 | 1257 | $query->expr()->eq('c.calendarid', |
1258 | 1258 | $query->createNamedParameter($id)), |
@@ -1269,7 +1269,7 @@ discard block |
||
1269 | 1269 | |
1270 | 1270 | // Component expressions |
1271 | 1271 | $compExpressions = []; |
1272 | - foreach($filters['comps'] as $comp) { |
|
1272 | + foreach ($filters['comps'] as $comp) { |
|
1273 | 1273 | $compExpressions[] = $query->expr() |
1274 | 1274 | ->eq('c.componenttype', $query->createNamedParameter($comp)); |
1275 | 1275 | } |
@@ -1288,13 +1288,13 @@ discard block |
||
1288 | 1288 | } |
1289 | 1289 | |
1290 | 1290 | $propParamExpressions = []; |
1291 | - foreach($filters['props'] as $prop) { |
|
1291 | + foreach ($filters['props'] as $prop) { |
|
1292 | 1292 | $propParamExpressions[] = $query->expr()->andX( |
1293 | 1293 | $query->expr()->eq('i.name', $query->createNamedParameter($prop)), |
1294 | 1294 | $query->expr()->isNull('i.parameter') |
1295 | 1295 | ); |
1296 | 1296 | } |
1297 | - foreach($filters['params'] as $param) { |
|
1297 | + foreach ($filters['params'] as $param) { |
|
1298 | 1298 | $propParamExpressions[] = $query->expr()->andX( |
1299 | 1299 | $query->expr()->eq('i.name', $query->createNamedParameter($param['property'])), |
1300 | 1300 | $query->expr()->eq('i.parameter', $query->createNamedParameter($param['parameter'])) |
@@ -1326,8 +1326,8 @@ discard block |
||
1326 | 1326 | $stmt = $query->execute(); |
1327 | 1327 | |
1328 | 1328 | $result = []; |
1329 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1330 | - $path = $uriMapper[$row['calendarid']] . '/' . $row['uri']; |
|
1329 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1330 | + $path = $uriMapper[$row['calendarid']].'/'.$row['uri']; |
|
1331 | 1331 | if (!in_array($path, $result)) { |
1332 | 1332 | $result[] = $path; |
1333 | 1333 | } |
@@ -1367,7 +1367,7 @@ discard block |
||
1367 | 1367 | $stmt = $query->execute(); |
1368 | 1368 | |
1369 | 1369 | if ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
1370 | - return $row['calendaruri'] . '/' . $row['objecturi']; |
|
1370 | + return $row['calendaruri'].'/'.$row['objecturi']; |
|
1371 | 1371 | } |
1372 | 1372 | |
1373 | 1373 | return null; |
@@ -1432,7 +1432,7 @@ discard block |
||
1432 | 1432 | function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limit = null) { |
1433 | 1433 | // Current synctoken |
1434 | 1434 | $stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*calendars` WHERE `id` = ?'); |
1435 | - $stmt->execute([ $calendarId ]); |
|
1435 | + $stmt->execute([$calendarId]); |
|
1436 | 1436 | $currentToken = $stmt->fetchColumn(0); |
1437 | 1437 | |
1438 | 1438 | if (is_null($currentToken)) { |
@@ -1449,8 +1449,8 @@ discard block |
||
1449 | 1449 | if ($syncToken) { |
1450 | 1450 | |
1451 | 1451 | $query = "SELECT `uri`, `operation` FROM `*PREFIX*calendarchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `calendarid` = ? ORDER BY `synctoken`"; |
1452 | - if ($limit>0) { |
|
1453 | - $query.= " `LIMIT` " . (int)$limit; |
|
1452 | + if ($limit > 0) { |
|
1453 | + $query .= " `LIMIT` ".(int) $limit; |
|
1454 | 1454 | } |
1455 | 1455 | |
1456 | 1456 | // Fetching all changes |
@@ -1461,15 +1461,15 @@ discard block |
||
1461 | 1461 | |
1462 | 1462 | // This loop ensures that any duplicates are overwritten, only the |
1463 | 1463 | // last change on a node is relevant. |
1464 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1464 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1465 | 1465 | |
1466 | 1466 | $changes[$row['uri']] = $row['operation']; |
1467 | 1467 | |
1468 | 1468 | } |
1469 | 1469 | |
1470 | - foreach($changes as $uri => $operation) { |
|
1470 | + foreach ($changes as $uri => $operation) { |
|
1471 | 1471 | |
1472 | - switch($operation) { |
|
1472 | + switch ($operation) { |
|
1473 | 1473 | case 1 : |
1474 | 1474 | $result['added'][] = $uri; |
1475 | 1475 | break; |
@@ -1539,10 +1539,10 @@ discard block |
||
1539 | 1539 | ->from('calendarsubscriptions') |
1540 | 1540 | ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
1541 | 1541 | ->orderBy('calendarorder', 'asc'); |
1542 | - $stmt =$query->execute(); |
|
1542 | + $stmt = $query->execute(); |
|
1543 | 1543 | |
1544 | 1544 | $subscriptions = []; |
1545 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1545 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1546 | 1546 | |
1547 | 1547 | $subscription = [ |
1548 | 1548 | 'id' => $row['id'], |
@@ -1551,10 +1551,10 @@ discard block |
||
1551 | 1551 | 'source' => $row['source'], |
1552 | 1552 | 'lastmodified' => $row['lastmodified'], |
1553 | 1553 | |
1554 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO', 'VEVENT']), |
|
1554 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO', 'VEVENT']), |
|
1555 | 1555 | ]; |
1556 | 1556 | |
1557 | - foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1557 | + foreach ($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1558 | 1558 | if (!is_null($row[$dbName])) { |
1559 | 1559 | $subscription[$xmlName] = $row[$dbName]; |
1560 | 1560 | } |
@@ -1593,7 +1593,7 @@ discard block |
||
1593 | 1593 | |
1594 | 1594 | $propertiesBoolean = ['striptodos', 'stripalarms', 'stripattachments']; |
1595 | 1595 | |
1596 | - foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1596 | + foreach ($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1597 | 1597 | if (array_key_exists($xmlName, $properties)) { |
1598 | 1598 | $values[$dbName] = $properties[$xmlName]; |
1599 | 1599 | if (in_array($dbName, $propertiesBoolean)) { |
@@ -1641,7 +1641,7 @@ discard block |
||
1641 | 1641 | |
1642 | 1642 | $newValues = []; |
1643 | 1643 | |
1644 | - foreach($mutations as $propertyName=>$propertyValue) { |
|
1644 | + foreach ($mutations as $propertyName=>$propertyValue) { |
|
1645 | 1645 | if ($propertyName === '{http://calendarserver.org/ns/}source') { |
1646 | 1646 | $newValues['source'] = $propertyValue->getHref(); |
1647 | 1647 | } else { |
@@ -1653,7 +1653,7 @@ discard block |
||
1653 | 1653 | $query = $this->db->getQueryBuilder(); |
1654 | 1654 | $query->update('calendarsubscriptions') |
1655 | 1655 | ->set('lastmodified', $query->createNamedParameter(time())); |
1656 | - foreach($newValues as $fieldName=>$value) { |
|
1656 | + foreach ($newValues as $fieldName=>$value) { |
|
1657 | 1657 | $query->set($fieldName, $query->createNamedParameter($value)); |
1658 | 1658 | } |
1659 | 1659 | $query->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) |
@@ -1703,7 +1703,7 @@ discard block |
||
1703 | 1703 | |
1704 | 1704 | $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
1705 | 1705 | |
1706 | - if(!$row) { |
|
1706 | + if (!$row) { |
|
1707 | 1707 | return null; |
1708 | 1708 | } |
1709 | 1709 | |
@@ -1711,8 +1711,8 @@ discard block |
||
1711 | 1711 | 'uri' => $row['uri'], |
1712 | 1712 | 'calendardata' => $row['calendardata'], |
1713 | 1713 | 'lastmodified' => $row['lastmodified'], |
1714 | - 'etag' => '"' . $row['etag'] . '"', |
|
1715 | - 'size' => (int)$row['size'], |
|
1714 | + 'etag' => '"'.$row['etag'].'"', |
|
1715 | + 'size' => (int) $row['size'], |
|
1716 | 1716 | ]; |
1717 | 1717 | } |
1718 | 1718 | |
@@ -1735,13 +1735,13 @@ discard block |
||
1735 | 1735 | ->execute(); |
1736 | 1736 | |
1737 | 1737 | $result = []; |
1738 | - foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
1738 | + foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
1739 | 1739 | $result[] = [ |
1740 | 1740 | 'calendardata' => $row['calendardata'], |
1741 | 1741 | 'uri' => $row['uri'], |
1742 | 1742 | 'lastmodified' => $row['lastmodified'], |
1743 | - 'etag' => '"' . $row['etag'] . '"', |
|
1744 | - 'size' => (int)$row['size'], |
|
1743 | + 'etag' => '"'.$row['etag'].'"', |
|
1744 | + 'size' => (int) $row['size'], |
|
1745 | 1745 | ]; |
1746 | 1746 | } |
1747 | 1747 | |
@@ -1833,10 +1833,10 @@ discard block |
||
1833 | 1833 | $lastOccurrence = null; |
1834 | 1834 | $uid = null; |
1835 | 1835 | $classification = self::CLASSIFICATION_PUBLIC; |
1836 | - foreach($vObject->getComponents() as $component) { |
|
1837 | - if ($component->name!=='VTIMEZONE') { |
|
1836 | + foreach ($vObject->getComponents() as $component) { |
|
1837 | + if ($component->name !== 'VTIMEZONE') { |
|
1838 | 1838 | $componentType = $component->name; |
1839 | - $uid = (string)$component->UID; |
|
1839 | + $uid = (string) $component->UID; |
|
1840 | 1840 | break; |
1841 | 1841 | } |
1842 | 1842 | } |
@@ -1861,13 +1861,13 @@ discard block |
||
1861 | 1861 | $lastOccurrence = $firstOccurrence; |
1862 | 1862 | } |
1863 | 1863 | } else { |
1864 | - $it = new EventIterator($vObject, (string)$component->UID); |
|
1864 | + $it = new EventIterator($vObject, (string) $component->UID); |
|
1865 | 1865 | $maxDate = new \DateTime(self::MAX_DATE); |
1866 | 1866 | if ($it->isInfinite()) { |
1867 | 1867 | $lastOccurrence = $maxDate->getTimestamp(); |
1868 | 1868 | } else { |
1869 | 1869 | $end = $it->getDtEnd(); |
1870 | - while($it->valid() && $end < $maxDate) { |
|
1870 | + while ($it->valid() && $end < $maxDate) { |
|
1871 | 1871 | $end = $it->getDtEnd(); |
1872 | 1872 | $it->next(); |
1873 | 1873 | |
@@ -2107,10 +2107,10 @@ discard block |
||
2107 | 2107 | $result->closeCursor(); |
2108 | 2108 | |
2109 | 2109 | if (!isset($objectIds['id'])) { |
2110 | - throw new \InvalidArgumentException('Calendarobject does not exists: ' . $uri); |
|
2110 | + throw new \InvalidArgumentException('Calendarobject does not exists: '.$uri); |
|
2111 | 2111 | } |
2112 | 2112 | |
2113 | - return (int)$objectIds['id']; |
|
2113 | + return (int) $objectIds['id']; |
|
2114 | 2114 | } |
2115 | 2115 | |
2116 | 2116 | private function convertPrincipal($principalUri, $toV2) { |
@@ -2125,8 +2125,8 @@ discard block |
||
2125 | 2125 | } |
2126 | 2126 | |
2127 | 2127 | private function addOwnerPrincipal(&$calendarInfo) { |
2128 | - $ownerPrincipalKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal'; |
|
2129 | - $displaynameKey = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD . '}owner-displayname'; |
|
2128 | + $ownerPrincipalKey = '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}owner-principal'; |
|
2129 | + $displaynameKey = '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_NEXTCLOUD.'}owner-displayname'; |
|
2130 | 2130 | if (isset($calendarInfo[$ownerPrincipalKey])) { |
2131 | 2131 | $uri = $calendarInfo[$ownerPrincipalKey]; |
2132 | 2132 | } else { |
@@ -2195,7 +2195,7 @@ discard block |
||
2195 | 2195 | ->execute(); |
2196 | 2196 | |
2197 | 2197 | $reminders = []; |
2198 | - while($row = $result->fetch(\PDO::FETCH_ASSOC)) { |
|
2198 | + while ($row = $result->fetch(\PDO::FETCH_ASSOC)) { |
|
2199 | 2199 | $reminder = [ |
2200 | 2200 | 'id' => $row['id'], |
2201 | 2201 | 'calendarId' => $row['calendarId'], |
@@ -2214,7 +2214,7 @@ discard block |
||
2214 | 2214 | |
2215 | 2215 | if ($shares = $this->getShares($row['calendarId'])) { |
2216 | 2216 | $key = 'href'; |
2217 | - $reminder['sharees'] = array_map(function ($item) use ($key) { |
|
2217 | + $reminder['sharees'] = array_map(function($item) use ($key) { |
|
2218 | 2218 | return substr($item[$key], 10); |
2219 | 2219 | }, $shares); |
2220 | 2220 | } |
@@ -33,83 +33,83 @@ |
||
33 | 33 | |
34 | 34 | class ReminderJob extends TimedJob { |
35 | 35 | |
36 | - /** @var IConfig */ |
|
37 | - private $config; |
|
38 | - |
|
39 | - /** @var Defaults */ |
|
40 | - private $defaults; |
|
41 | - |
|
42 | - /** @var IMailer */ |
|
43 | - private $mailer; |
|
44 | - |
|
45 | - /** @var IL10N */ |
|
46 | - private $l10n; |
|
47 | - |
|
48 | - /** @var IManager */ |
|
49 | - private $notifications; |
|
50 | - |
|
51 | - /** @var CalDavBackend */ |
|
52 | - private $backend; |
|
53 | - |
|
54 | - /** @var IUserManager */ |
|
55 | - private $usermanager; |
|
56 | - |
|
57 | - public function __construct(IConfig $config, Defaults $defaults, IMailer $mailer, IL10N $l10n, IManager $notifications, CalDavBackend $backend, IUserManager $usermanager) { |
|
58 | - $this->config = $config; |
|
59 | - $this->defaults = $defaults; |
|
60 | - $this->mailer = $mailer; |
|
61 | - $this->l10n = $l10n; |
|
62 | - $this->notifications = $notifications; |
|
63 | - $this->backend = $backend; |
|
64 | - $this->usermanager = $usermanager; |
|
65 | - |
|
66 | - /** Run every 15 minutes */ |
|
67 | - $this->setInterval(10); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @param $arg |
|
72 | - */ |
|
73 | - public function run($arg) { |
|
74 | - $reminders = $this->backend->getReminders(); |
|
75 | - |
|
76 | - foreach ($reminders as $reminder) { |
|
77 | - if ($reminder['notificationDate'] > (new \DateTime())->getTimestamp()) { |
|
78 | - $calendar = $this->backend->getCalendarById($reminder['calendarId']); |
|
79 | - switch ($reminder['type']) { |
|
80 | - case 'EMAIL': |
|
81 | - $this->sendMail($this->usermanager->get($reminder['userid']), $calendar); |
|
82 | - break; |
|
83 | - case 'DISPLAY': |
|
84 | - $this->sendNotification($this->usermanager->get($reminder['userid']), $reminder['notificationDate'], $calendar); |
|
85 | - break; |
|
86 | - } |
|
87 | - $this->backend->removeReminder($reminder['id']); |
|
88 | - } |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - private function sendMail(IUser $user, array $calendar) { |
|
93 | - $message = $this->mailer->createMessage(); |
|
94 | - $message->setSubject($this->l10n->t('Your Subject')); |
|
95 | - |
|
96 | - $from = Util::getDefaultEmailAddress('register'); |
|
97 | - |
|
98 | - $message->setFrom([$from => $this->defaults->getName()]); |
|
99 | - $message->setTo([$user->getEMailAddress() => 'Recipient']); |
|
100 | - $message->setBody($calendar['calendardata'], 'text/calendar; charset=UTF-8'); |
|
101 | - $this->mailer->send($message); |
|
102 | - } |
|
103 | - |
|
104 | - private function sendNotification(IUser $user, \DateTime $time, $calendar) { |
|
105 | - /** @var INotification $notification */ |
|
106 | - $notification = $this->notifications->createNotification(); |
|
107 | - $notification->setApp('dav') |
|
108 | - ->setUser($user->getUID()) |
|
109 | - ->setDateTime($time) |
|
110 | - ->setObject('calendar_reminder', $calendar['id']) // $type and $id |
|
111 | - ->setSubject('calendar_reminder', [$calendar]) // $subject and $parameters |
|
112 | - ; |
|
113 | - $this->notifications->notify($notification); |
|
114 | - } |
|
36 | + /** @var IConfig */ |
|
37 | + private $config; |
|
38 | + |
|
39 | + /** @var Defaults */ |
|
40 | + private $defaults; |
|
41 | + |
|
42 | + /** @var IMailer */ |
|
43 | + private $mailer; |
|
44 | + |
|
45 | + /** @var IL10N */ |
|
46 | + private $l10n; |
|
47 | + |
|
48 | + /** @var IManager */ |
|
49 | + private $notifications; |
|
50 | + |
|
51 | + /** @var CalDavBackend */ |
|
52 | + private $backend; |
|
53 | + |
|
54 | + /** @var IUserManager */ |
|
55 | + private $usermanager; |
|
56 | + |
|
57 | + public function __construct(IConfig $config, Defaults $defaults, IMailer $mailer, IL10N $l10n, IManager $notifications, CalDavBackend $backend, IUserManager $usermanager) { |
|
58 | + $this->config = $config; |
|
59 | + $this->defaults = $defaults; |
|
60 | + $this->mailer = $mailer; |
|
61 | + $this->l10n = $l10n; |
|
62 | + $this->notifications = $notifications; |
|
63 | + $this->backend = $backend; |
|
64 | + $this->usermanager = $usermanager; |
|
65 | + |
|
66 | + /** Run every 15 minutes */ |
|
67 | + $this->setInterval(10); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @param $arg |
|
72 | + */ |
|
73 | + public function run($arg) { |
|
74 | + $reminders = $this->backend->getReminders(); |
|
75 | + |
|
76 | + foreach ($reminders as $reminder) { |
|
77 | + if ($reminder['notificationDate'] > (new \DateTime())->getTimestamp()) { |
|
78 | + $calendar = $this->backend->getCalendarById($reminder['calendarId']); |
|
79 | + switch ($reminder['type']) { |
|
80 | + case 'EMAIL': |
|
81 | + $this->sendMail($this->usermanager->get($reminder['userid']), $calendar); |
|
82 | + break; |
|
83 | + case 'DISPLAY': |
|
84 | + $this->sendNotification($this->usermanager->get($reminder['userid']), $reminder['notificationDate'], $calendar); |
|
85 | + break; |
|
86 | + } |
|
87 | + $this->backend->removeReminder($reminder['id']); |
|
88 | + } |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + private function sendMail(IUser $user, array $calendar) { |
|
93 | + $message = $this->mailer->createMessage(); |
|
94 | + $message->setSubject($this->l10n->t('Your Subject')); |
|
95 | + |
|
96 | + $from = Util::getDefaultEmailAddress('register'); |
|
97 | + |
|
98 | + $message->setFrom([$from => $this->defaults->getName()]); |
|
99 | + $message->setTo([$user->getEMailAddress() => 'Recipient']); |
|
100 | + $message->setBody($calendar['calendardata'], 'text/calendar; charset=UTF-8'); |
|
101 | + $this->mailer->send($message); |
|
102 | + } |
|
103 | + |
|
104 | + private function sendNotification(IUser $user, \DateTime $time, $calendar) { |
|
105 | + /** @var INotification $notification */ |
|
106 | + $notification = $this->notifications->createNotification(); |
|
107 | + $notification->setApp('dav') |
|
108 | + ->setUser($user->getUID()) |
|
109 | + ->setDateTime($time) |
|
110 | + ->setObject('calendar_reminder', $calendar['id']) // $type and $id |
|
111 | + ->setSubject('calendar_reminder', [$calendar]) // $subject and $parameters |
|
112 | + ; |
|
113 | + $this->notifications->notify($notification); |
|
114 | + } |
|
115 | 115 | } |
116 | 116 | \ No newline at end of file |
@@ -26,38 +26,38 @@ |
||
26 | 26 | use OCP\Notification\INotifier; |
27 | 27 | |
28 | 28 | class Notifier implements INotifier { |
29 | - protected $factory; |
|
30 | - |
|
31 | - public function __construct(IFactory $factory) { |
|
32 | - $this->factory = $factory; |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * @param INotification $notification |
|
37 | - * @param string $languageCode The code of the language that should be used to prepare the notification |
|
38 | - * @return INotification |
|
39 | - */ |
|
40 | - public function prepare(INotification $notification, $languageCode) { |
|
41 | - if ($notification->getApp() !== 'dav') { |
|
42 | - throw new \InvalidArgumentException(); |
|
43 | - } |
|
44 | - |
|
45 | - // Read the language from the notification |
|
46 | - $l = $this->factory->get('dav', $languageCode); |
|
47 | - |
|
48 | - switch ($notification->getSubject()) { |
|
49 | - // Deal with known subjects |
|
50 | - case 'calendar_reminder': |
|
51 | - $notification->setParsedSubject( |
|
52 | - (string)$l->t('Your event "%s" is in %s', $notification->getSubjectParameters()) |
|
53 | - ); |
|
54 | - |
|
55 | - return $notification; |
|
56 | - break; |
|
57 | - |
|
58 | - default: |
|
59 | - // Unknown subject => Unknown notification => throw |
|
60 | - throw new \InvalidArgumentException(); |
|
61 | - } |
|
62 | - } |
|
29 | + protected $factory; |
|
30 | + |
|
31 | + public function __construct(IFactory $factory) { |
|
32 | + $this->factory = $factory; |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * @param INotification $notification |
|
37 | + * @param string $languageCode The code of the language that should be used to prepare the notification |
|
38 | + * @return INotification |
|
39 | + */ |
|
40 | + public function prepare(INotification $notification, $languageCode) { |
|
41 | + if ($notification->getApp() !== 'dav') { |
|
42 | + throw new \InvalidArgumentException(); |
|
43 | + } |
|
44 | + |
|
45 | + // Read the language from the notification |
|
46 | + $l = $this->factory->get('dav', $languageCode); |
|
47 | + |
|
48 | + switch ($notification->getSubject()) { |
|
49 | + // Deal with known subjects |
|
50 | + case 'calendar_reminder': |
|
51 | + $notification->setParsedSubject( |
|
52 | + (string)$l->t('Your event "%s" is in %s', $notification->getSubjectParameters()) |
|
53 | + ); |
|
54 | + |
|
55 | + return $notification; |
|
56 | + break; |
|
57 | + |
|
58 | + default: |
|
59 | + // Unknown subject => Unknown notification => throw |
|
60 | + throw new \InvalidArgumentException(); |
|
61 | + } |
|
62 | + } |
|
63 | 63 | } |
64 | 64 | \ No newline at end of file |
@@ -49,7 +49,7 @@ |
||
49 | 49 | // Deal with known subjects |
50 | 50 | case 'calendar_reminder': |
51 | 51 | $notification->setParsedSubject( |
52 | - (string)$l->t('Your event "%s" is in %s', $notification->getSubjectParameters()) |
|
52 | + (string) $l->t('Your event "%s" is in %s', $notification->getSubjectParameters()) |
|
53 | 53 | ); |
54 | 54 | |
55 | 55 | return $notification; |
@@ -26,45 +26,45 @@ |
||
26 | 26 | |
27 | 27 | class ReminderService { |
28 | 28 | |
29 | - /** @var CalDavBackend */ |
|
30 | - private $calDavBackEnd; |
|
29 | + /** @var CalDavBackend */ |
|
30 | + private $calDavBackEnd; |
|
31 | 31 | |
32 | - private $types = ['AUDIO', 'EMAIL', 'DISPLAY']; |
|
32 | + private $types = ['AUDIO', 'EMAIL', 'DISPLAY']; |
|
33 | 33 | |
34 | - /** |
|
35 | - * BirthdayService constructor. |
|
36 | - * |
|
37 | - * @param CalDavBackend $calDavBackEnd |
|
38 | - */ |
|
39 | - public function __construct(CalDavBackend $calDavBackEnd) { |
|
40 | - $this->calDavBackEnd = $calDavBackEnd; |
|
41 | - } |
|
34 | + /** |
|
35 | + * BirthdayService constructor. |
|
36 | + * |
|
37 | + * @param CalDavBackend $calDavBackEnd |
|
38 | + */ |
|
39 | + public function __construct(CalDavBackend $calDavBackEnd) { |
|
40 | + $this->calDavBackEnd = $calDavBackEnd; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param $calendarId |
|
45 | - * @param $objectUri |
|
46 | - * @param $calendarData |
|
47 | - */ |
|
48 | - function onCalendarObjectChanged($calendarId, $objectUri, $calendarData) { |
|
49 | - $vobject = VObject\Reader::read($calendarData); |
|
43 | + /** |
|
44 | + * @param $calendarId |
|
45 | + * @param $objectUri |
|
46 | + * @param $calendarData |
|
47 | + */ |
|
48 | + function onCalendarObjectChanged($calendarId, $objectUri, $calendarData) { |
|
49 | + $vobject = VObject\Reader::read($calendarData); |
|
50 | 50 | |
51 | - /** Remove all other reminders for this event */ |
|
52 | - $this->calDavBackEnd->cleanRemindersForEvent($calendarId, $objectUri); |
|
51 | + /** Remove all other reminders for this event */ |
|
52 | + $this->calDavBackEnd->cleanRemindersForEvent($calendarId, $objectUri); |
|
53 | 53 | |
54 | - foreach ($vobject->VEVENT->VALARM as $alarm) { |
|
55 | - if ($alarm instanceof VAlarm) { |
|
56 | - $type = strtoupper($alarm->ACTION->getValue()); |
|
57 | - if (in_array($type, $this->types)) { |
|
58 | - /** @var \DateTime $time */ |
|
59 | - $time = $alarm->getEffectiveTriggerTime(); |
|
60 | - $this->calDavBackEnd->addReminderForEvent($calendarId, $objectUri, $type, $time); |
|
61 | - } |
|
62 | - } |
|
63 | - } |
|
64 | - } |
|
54 | + foreach ($vobject->VEVENT->VALARM as $alarm) { |
|
55 | + if ($alarm instanceof VAlarm) { |
|
56 | + $type = strtoupper($alarm->ACTION->getValue()); |
|
57 | + if (in_array($type, $this->types)) { |
|
58 | + /** @var \DateTime $time */ |
|
59 | + $time = $alarm->getEffectiveTriggerTime(); |
|
60 | + $this->calDavBackEnd->addReminderForEvent($calendarId, $objectUri, $type, $time); |
|
61 | + } |
|
62 | + } |
|
63 | + } |
|
64 | + } |
|
65 | 65 | |
66 | - function onCalendarObjectDeleted($calendarId, $objectUri) { |
|
67 | - $this->calDavBackEnd->cleanRemindersForEvent($calendarId, $objectUri); |
|
68 | - } |
|
66 | + function onCalendarObjectDeleted($calendarId, $objectUri) { |
|
67 | + $this->calDavBackEnd->cleanRemindersForEvent($calendarId, $objectUri); |
|
68 | + } |
|
69 | 69 | |
70 | 70 | } |
71 | 71 | \ No newline at end of file |
@@ -31,50 +31,50 @@ |
||
31 | 31 | $app->registerHooks(); |
32 | 32 | |
33 | 33 | \OC::$server->registerService('CardDAVSyncService', function() use ($app) { |
34 | - return $app->getSyncService(); |
|
34 | + return $app->getSyncService(); |
|
35 | 35 | }); |
36 | 36 | |
37 | 37 | $eventDispatcher = \OC::$server->getEventDispatcher(); |
38 | 38 | |
39 | 39 | $eventDispatcher->addListener('OCP\Federation\TrustedServerEvent::remove', |
40 | - function(GenericEvent $event) use ($app) { |
|
41 | - /** @var CardDavBackend $cardDavBackend */ |
|
42 | - $cardDavBackend = $app->getContainer()->query(CardDavBackend::class); |
|
43 | - $addressBookUri = $event->getSubject(); |
|
44 | - $addressBook = $cardDavBackend->getAddressBooksByUri('principals/system/system', $addressBookUri); |
|
45 | - if (!is_null($addressBook)) { |
|
46 | - $cardDavBackend->deleteAddressBook($addressBook['id']); |
|
47 | - } |
|
48 | - } |
|
40 | + function(GenericEvent $event) use ($app) { |
|
41 | + /** @var CardDavBackend $cardDavBackend */ |
|
42 | + $cardDavBackend = $app->getContainer()->query(CardDavBackend::class); |
|
43 | + $addressBookUri = $event->getSubject(); |
|
44 | + $addressBook = $cardDavBackend->getAddressBooksByUri('principals/system/system', $addressBookUri); |
|
45 | + if (!is_null($addressBook)) { |
|
46 | + $cardDavBackend->deleteAddressBook($addressBook['id']); |
|
47 | + } |
|
48 | + } |
|
49 | 49 | ); |
50 | 50 | |
51 | 51 | $cm = \OC::$server->getContactsManager(); |
52 | 52 | $cm->register(function() use ($cm, $app) { |
53 | - $user = \OC::$server->getUserSession()->getUser(); |
|
54 | - if (is_null($user)) { |
|
55 | - return; |
|
56 | - } |
|
57 | - if (\OC::$server->getConfig()->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') !== 'yes') { |
|
58 | - // Don't include system users |
|
59 | - // This prevents user enumeration in the contacts menu and the mail app |
|
60 | - return; |
|
61 | - } |
|
62 | - $app->setupContactsProvider($cm, $user->getUID()); |
|
53 | + $user = \OC::$server->getUserSession()->getUser(); |
|
54 | + if (is_null($user)) { |
|
55 | + return; |
|
56 | + } |
|
57 | + if (\OC::$server->getConfig()->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') !== 'yes') { |
|
58 | + // Don't include system users |
|
59 | + // This prevents user enumeration in the contacts menu and the mail app |
|
60 | + return; |
|
61 | + } |
|
62 | + $app->setupContactsProvider($cm, $user->getUID()); |
|
63 | 63 | }); |
64 | 64 | |
65 | 65 | $manager = \OC::$server->getNotificationManager(); |
66 | 66 | $manager->registerNotifier(function() { |
67 | - return new Notifier( |
|
68 | - \OC::$server->getL10NFactory() |
|
69 | - ); |
|
67 | + return new Notifier( |
|
68 | + \OC::$server->getL10NFactory() |
|
69 | + ); |
|
70 | 70 | }, function() { |
71 | - return [ |
|
72 | - 'id' => 'dav_reminders', |
|
73 | - 'name' => 'dav' |
|
74 | - ]; |
|
71 | + return [ |
|
72 | + 'id' => 'dav_reminders', |
|
73 | + 'name' => 'dav' |
|
74 | + ]; |
|
75 | 75 | }); |
76 | 76 | |
77 | 77 | $joblist = \OC::$server->getJobList(); |
78 | 78 | if (!$joblist->has('OCA\DAV\CalDAV\Reminder\ReminderJob', null)) { |
79 | - $joblist->add('OCA\DAV\CalDAV\Reminder\ReminderJob'); |
|
79 | + $joblist->add('OCA\DAV\CalDAV\Reminder\ReminderJob'); |
|
80 | 80 | } |