@@ -59,1868 +59,1868 @@ |
||
59 | 59 | */ |
60 | 60 | class CalDavBackend extends AbstractBackend implements SyncSupport, SubscriptionSupport, SchedulingSupport { |
61 | 61 | |
62 | - const PERSONAL_CALENDAR_URI = 'personal'; |
|
63 | - const PERSONAL_CALENDAR_NAME = 'Personal'; |
|
64 | - |
|
65 | - /** |
|
66 | - * We need to specify a max date, because we need to stop *somewhere* |
|
67 | - * |
|
68 | - * On 32 bit system the maximum for a signed integer is 2147483647, so |
|
69 | - * MAX_DATE cannot be higher than date('Y-m-d', 2147483647) which results |
|
70 | - * in 2038-01-19 to avoid problems when the date is converted |
|
71 | - * to a unix timestamp. |
|
72 | - */ |
|
73 | - const MAX_DATE = '2038-01-01'; |
|
74 | - |
|
75 | - const ACCESS_PUBLIC = 4; |
|
76 | - const CLASSIFICATION_PUBLIC = 0; |
|
77 | - const CLASSIFICATION_PRIVATE = 1; |
|
78 | - const CLASSIFICATION_CONFIDENTIAL = 2; |
|
79 | - |
|
80 | - /** |
|
81 | - * List of CalDAV properties, and how they map to database field names |
|
82 | - * Add your own properties by simply adding on to this array. |
|
83 | - * |
|
84 | - * Note that only string-based properties are supported here. |
|
85 | - * |
|
86 | - * @var array |
|
87 | - */ |
|
88 | - public $propertyMap = [ |
|
89 | - '{DAV:}displayname' => 'displayname', |
|
90 | - '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'description', |
|
91 | - '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => 'timezone', |
|
92 | - '{http://apple.com/ns/ical/}calendar-order' => 'calendarorder', |
|
93 | - '{http://apple.com/ns/ical/}calendar-color' => 'calendarcolor', |
|
94 | - ]; |
|
95 | - |
|
96 | - /** |
|
97 | - * List of subscription properties, and how they map to database field names. |
|
98 | - * |
|
99 | - * @var array |
|
100 | - */ |
|
101 | - public $subscriptionPropertyMap = [ |
|
102 | - '{DAV:}displayname' => 'displayname', |
|
103 | - '{http://apple.com/ns/ical/}refreshrate' => 'refreshrate', |
|
104 | - '{http://apple.com/ns/ical/}calendar-order' => 'calendarorder', |
|
105 | - '{http://apple.com/ns/ical/}calendar-color' => 'calendarcolor', |
|
106 | - '{http://calendarserver.org/ns/}subscribed-strip-todos' => 'striptodos', |
|
107 | - '{http://calendarserver.org/ns/}subscribed-strip-alarms' => 'stripalarms', |
|
108 | - '{http://calendarserver.org/ns/}subscribed-strip-attachments' => 'stripattachments', |
|
109 | - ]; |
|
110 | - |
|
111 | - /** |
|
112 | - * @var string[] Map of uid => display name |
|
113 | - */ |
|
114 | - protected $userDisplayNames; |
|
115 | - |
|
116 | - /** @var IDBConnection */ |
|
117 | - private $db; |
|
118 | - |
|
119 | - /** @var Backend */ |
|
120 | - private $sharingBackend; |
|
121 | - |
|
122 | - /** @var Principal */ |
|
123 | - private $principalBackend; |
|
124 | - |
|
125 | - /** @var IUserManager */ |
|
126 | - private $userManager; |
|
127 | - |
|
128 | - /** @var ISecureRandom */ |
|
129 | - private $random; |
|
130 | - |
|
131 | - /** @var EventDispatcherInterface */ |
|
132 | - private $dispatcher; |
|
133 | - |
|
134 | - /** @var bool */ |
|
135 | - private $legacyEndpoint; |
|
136 | - |
|
137 | - /** |
|
138 | - * CalDavBackend constructor. |
|
139 | - * |
|
140 | - * @param IDBConnection $db |
|
141 | - * @param Principal $principalBackend |
|
142 | - * @param IUserManager $userManager |
|
143 | - * @param ISecureRandom $random |
|
144 | - * @param EventDispatcherInterface $dispatcher |
|
145 | - * @param bool $legacyEndpoint |
|
146 | - */ |
|
147 | - public function __construct(IDBConnection $db, |
|
148 | - Principal $principalBackend, |
|
149 | - IUserManager $userManager, |
|
150 | - ISecureRandom $random, |
|
151 | - EventDispatcherInterface $dispatcher, |
|
152 | - $legacyEndpoint = false) { |
|
153 | - $this->db = $db; |
|
154 | - $this->principalBackend = $principalBackend; |
|
155 | - $this->userManager = $userManager; |
|
156 | - $this->sharingBackend = new Backend($this->db, $principalBackend, 'calendar'); |
|
157 | - $this->random = $random; |
|
158 | - $this->dispatcher = $dispatcher; |
|
159 | - $this->legacyEndpoint = $legacyEndpoint; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Return the number of calendars for a principal |
|
164 | - * |
|
165 | - * By default this excludes the automatically generated birthday calendar |
|
166 | - * |
|
167 | - * @param $principalUri |
|
168 | - * @param bool $excludeBirthday |
|
169 | - * @return int |
|
170 | - */ |
|
171 | - public function getCalendarsForUserCount($principalUri, $excludeBirthday = true) { |
|
172 | - $principalUri = $this->convertPrincipal($principalUri, true); |
|
173 | - $query = $this->db->getQueryBuilder(); |
|
174 | - $query->select($query->createFunction('COUNT(*)')) |
|
175 | - ->from('calendars') |
|
176 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))); |
|
177 | - |
|
178 | - if ($excludeBirthday) { |
|
179 | - $query->andWhere($query->expr()->neq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))); |
|
180 | - } |
|
181 | - |
|
182 | - return (int)$query->execute()->fetchColumn(); |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Returns a list of calendars for a principal. |
|
187 | - * |
|
188 | - * Every project is an array with the following keys: |
|
189 | - * * id, a unique id that will be used by other functions to modify the |
|
190 | - * calendar. This can be the same as the uri or a database key. |
|
191 | - * * uri, which the basename of the uri with which the calendar is |
|
192 | - * accessed. |
|
193 | - * * principaluri. The owner of the calendar. Almost always the same as |
|
194 | - * principalUri passed to this method. |
|
195 | - * |
|
196 | - * Furthermore it can contain webdav properties in clark notation. A very |
|
197 | - * common one is '{DAV:}displayname'. |
|
198 | - * |
|
199 | - * Many clients also require: |
|
200 | - * {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set |
|
201 | - * For this property, you can just return an instance of |
|
202 | - * Sabre\CalDAV\Property\SupportedCalendarComponentSet. |
|
203 | - * |
|
204 | - * If you return {http://sabredav.org/ns}read-only and set the value to 1, |
|
205 | - * ACL will automatically be put in read-only mode. |
|
206 | - * |
|
207 | - * @param string $principalUri |
|
208 | - * @return array |
|
209 | - */ |
|
210 | - function getCalendarsForUser($principalUri) { |
|
211 | - $principalUriOriginal = $principalUri; |
|
212 | - $principalUri = $this->convertPrincipal($principalUri, true); |
|
213 | - $fields = array_values($this->propertyMap); |
|
214 | - $fields[] = 'id'; |
|
215 | - $fields[] = 'uri'; |
|
216 | - $fields[] = 'synctoken'; |
|
217 | - $fields[] = 'components'; |
|
218 | - $fields[] = 'principaluri'; |
|
219 | - $fields[] = 'transparent'; |
|
220 | - |
|
221 | - // Making fields a comma-delimited list |
|
222 | - $query = $this->db->getQueryBuilder(); |
|
223 | - $query->select($fields)->from('calendars') |
|
224 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
225 | - ->orderBy('calendarorder', 'ASC'); |
|
226 | - $stmt = $query->execute(); |
|
227 | - |
|
228 | - $calendars = []; |
|
229 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
230 | - |
|
231 | - $components = []; |
|
232 | - if ($row['components']) { |
|
233 | - $components = explode(',',$row['components']); |
|
234 | - } |
|
235 | - |
|
236 | - $calendar = [ |
|
237 | - 'id' => $row['id'], |
|
238 | - 'uri' => $row['uri'], |
|
239 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
240 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
241 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
242 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
243 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
244 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
245 | - ]; |
|
246 | - |
|
247 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
248 | - $calendar[$xmlName] = $row[$dbName]; |
|
249 | - } |
|
250 | - |
|
251 | - if (!isset($calendars[$calendar['id']])) { |
|
252 | - $calendars[$calendar['id']] = $calendar; |
|
253 | - } |
|
254 | - } |
|
255 | - |
|
256 | - $stmt->closeCursor(); |
|
257 | - |
|
258 | - // query for shared calendars |
|
259 | - $principals = $this->principalBackend->getGroupMembership($principalUriOriginal, true); |
|
260 | - $principals[]= $principalUri; |
|
261 | - |
|
262 | - $fields = array_values($this->propertyMap); |
|
263 | - $fields[] = 'a.id'; |
|
264 | - $fields[] = 'a.uri'; |
|
265 | - $fields[] = 'a.synctoken'; |
|
266 | - $fields[] = 'a.components'; |
|
267 | - $fields[] = 'a.principaluri'; |
|
268 | - $fields[] = 'a.transparent'; |
|
269 | - $fields[] = 's.access'; |
|
270 | - $query = $this->db->getQueryBuilder(); |
|
271 | - $result = $query->select($fields) |
|
272 | - ->from('dav_shares', 's') |
|
273 | - ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
274 | - ->where($query->expr()->in('s.principaluri', $query->createParameter('principaluri'))) |
|
275 | - ->andWhere($query->expr()->eq('s.type', $query->createParameter('type'))) |
|
276 | - ->setParameter('type', 'calendar') |
|
277 | - ->setParameter('principaluri', $principals, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) |
|
278 | - ->execute(); |
|
279 | - |
|
280 | - $readOnlyPropertyName = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'; |
|
281 | - while($row = $result->fetch()) { |
|
282 | - if ($row['principaluri'] === $principalUri) { |
|
283 | - continue; |
|
284 | - } |
|
285 | - |
|
286 | - $readOnly = (int) $row['access'] === Backend::ACCESS_READ; |
|
287 | - if (isset($calendars[$row['id']])) { |
|
288 | - if ($readOnly) { |
|
289 | - // New share can not have more permissions then the old one. |
|
290 | - continue; |
|
291 | - } |
|
292 | - if (isset($calendars[$row['id']][$readOnlyPropertyName]) && |
|
293 | - $calendars[$row['id']][$readOnlyPropertyName] === 0) { |
|
294 | - // Old share is already read-write, no more permissions can be gained |
|
295 | - continue; |
|
296 | - } |
|
297 | - } |
|
298 | - |
|
299 | - list(, $name) = URLUtil::splitPath($row['principaluri']); |
|
300 | - $uri = $row['uri'] . '_shared_by_' . $name; |
|
301 | - $row['displayname'] = $row['displayname'] . ' (' . $this->getUserDisplayName($name) . ')'; |
|
302 | - $components = []; |
|
303 | - if ($row['components']) { |
|
304 | - $components = explode(',',$row['components']); |
|
305 | - } |
|
306 | - $calendar = [ |
|
307 | - 'id' => $row['id'], |
|
308 | - 'uri' => $uri, |
|
309 | - 'principaluri' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
310 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
311 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
312 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
313 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
314 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
315 | - $readOnlyPropertyName => $readOnly, |
|
316 | - ]; |
|
317 | - |
|
318 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
319 | - $calendar[$xmlName] = $row[$dbName]; |
|
320 | - } |
|
321 | - |
|
322 | - $calendars[$calendar['id']] = $calendar; |
|
323 | - } |
|
324 | - $result->closeCursor(); |
|
325 | - |
|
326 | - return array_values($calendars); |
|
327 | - } |
|
328 | - |
|
329 | - public function getUsersOwnCalendars($principalUri) { |
|
330 | - $principalUri = $this->convertPrincipal($principalUri, true); |
|
331 | - $fields = array_values($this->propertyMap); |
|
332 | - $fields[] = 'id'; |
|
333 | - $fields[] = 'uri'; |
|
334 | - $fields[] = 'synctoken'; |
|
335 | - $fields[] = 'components'; |
|
336 | - $fields[] = 'principaluri'; |
|
337 | - $fields[] = 'transparent'; |
|
338 | - // Making fields a comma-delimited list |
|
339 | - $query = $this->db->getQueryBuilder(); |
|
340 | - $query->select($fields)->from('calendars') |
|
341 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
342 | - ->orderBy('calendarorder', 'ASC'); |
|
343 | - $stmt = $query->execute(); |
|
344 | - $calendars = []; |
|
345 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
346 | - $components = []; |
|
347 | - if ($row['components']) { |
|
348 | - $components = explode(',',$row['components']); |
|
349 | - } |
|
350 | - $calendar = [ |
|
351 | - 'id' => $row['id'], |
|
352 | - 'uri' => $row['uri'], |
|
353 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
354 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
355 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
356 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
357 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
358 | - ]; |
|
359 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
360 | - $calendar[$xmlName] = $row[$dbName]; |
|
361 | - } |
|
362 | - if (!isset($calendars[$calendar['id']])) { |
|
363 | - $calendars[$calendar['id']] = $calendar; |
|
364 | - } |
|
365 | - } |
|
366 | - $stmt->closeCursor(); |
|
367 | - return array_values($calendars); |
|
368 | - } |
|
369 | - |
|
370 | - |
|
371 | - private function getUserDisplayName($uid) { |
|
372 | - if (!isset($this->userDisplayNames[$uid])) { |
|
373 | - $user = $this->userManager->get($uid); |
|
374 | - |
|
375 | - if ($user instanceof IUser) { |
|
376 | - $this->userDisplayNames[$uid] = $user->getDisplayName(); |
|
377 | - } else { |
|
378 | - $this->userDisplayNames[$uid] = $uid; |
|
379 | - } |
|
380 | - } |
|
381 | - |
|
382 | - return $this->userDisplayNames[$uid]; |
|
383 | - } |
|
62 | + const PERSONAL_CALENDAR_URI = 'personal'; |
|
63 | + const PERSONAL_CALENDAR_NAME = 'Personal'; |
|
64 | + |
|
65 | + /** |
|
66 | + * We need to specify a max date, because we need to stop *somewhere* |
|
67 | + * |
|
68 | + * On 32 bit system the maximum for a signed integer is 2147483647, so |
|
69 | + * MAX_DATE cannot be higher than date('Y-m-d', 2147483647) which results |
|
70 | + * in 2038-01-19 to avoid problems when the date is converted |
|
71 | + * to a unix timestamp. |
|
72 | + */ |
|
73 | + const MAX_DATE = '2038-01-01'; |
|
74 | + |
|
75 | + const ACCESS_PUBLIC = 4; |
|
76 | + const CLASSIFICATION_PUBLIC = 0; |
|
77 | + const CLASSIFICATION_PRIVATE = 1; |
|
78 | + const CLASSIFICATION_CONFIDENTIAL = 2; |
|
79 | + |
|
80 | + /** |
|
81 | + * List of CalDAV properties, and how they map to database field names |
|
82 | + * Add your own properties by simply adding on to this array. |
|
83 | + * |
|
84 | + * Note that only string-based properties are supported here. |
|
85 | + * |
|
86 | + * @var array |
|
87 | + */ |
|
88 | + public $propertyMap = [ |
|
89 | + '{DAV:}displayname' => 'displayname', |
|
90 | + '{urn:ietf:params:xml:ns:caldav}calendar-description' => 'description', |
|
91 | + '{urn:ietf:params:xml:ns:caldav}calendar-timezone' => 'timezone', |
|
92 | + '{http://apple.com/ns/ical/}calendar-order' => 'calendarorder', |
|
93 | + '{http://apple.com/ns/ical/}calendar-color' => 'calendarcolor', |
|
94 | + ]; |
|
95 | + |
|
96 | + /** |
|
97 | + * List of subscription properties, and how they map to database field names. |
|
98 | + * |
|
99 | + * @var array |
|
100 | + */ |
|
101 | + public $subscriptionPropertyMap = [ |
|
102 | + '{DAV:}displayname' => 'displayname', |
|
103 | + '{http://apple.com/ns/ical/}refreshrate' => 'refreshrate', |
|
104 | + '{http://apple.com/ns/ical/}calendar-order' => 'calendarorder', |
|
105 | + '{http://apple.com/ns/ical/}calendar-color' => 'calendarcolor', |
|
106 | + '{http://calendarserver.org/ns/}subscribed-strip-todos' => 'striptodos', |
|
107 | + '{http://calendarserver.org/ns/}subscribed-strip-alarms' => 'stripalarms', |
|
108 | + '{http://calendarserver.org/ns/}subscribed-strip-attachments' => 'stripattachments', |
|
109 | + ]; |
|
110 | + |
|
111 | + /** |
|
112 | + * @var string[] Map of uid => display name |
|
113 | + */ |
|
114 | + protected $userDisplayNames; |
|
115 | + |
|
116 | + /** @var IDBConnection */ |
|
117 | + private $db; |
|
118 | + |
|
119 | + /** @var Backend */ |
|
120 | + private $sharingBackend; |
|
121 | + |
|
122 | + /** @var Principal */ |
|
123 | + private $principalBackend; |
|
124 | + |
|
125 | + /** @var IUserManager */ |
|
126 | + private $userManager; |
|
127 | + |
|
128 | + /** @var ISecureRandom */ |
|
129 | + private $random; |
|
130 | + |
|
131 | + /** @var EventDispatcherInterface */ |
|
132 | + private $dispatcher; |
|
133 | + |
|
134 | + /** @var bool */ |
|
135 | + private $legacyEndpoint; |
|
136 | + |
|
137 | + /** |
|
138 | + * CalDavBackend constructor. |
|
139 | + * |
|
140 | + * @param IDBConnection $db |
|
141 | + * @param Principal $principalBackend |
|
142 | + * @param IUserManager $userManager |
|
143 | + * @param ISecureRandom $random |
|
144 | + * @param EventDispatcherInterface $dispatcher |
|
145 | + * @param bool $legacyEndpoint |
|
146 | + */ |
|
147 | + public function __construct(IDBConnection $db, |
|
148 | + Principal $principalBackend, |
|
149 | + IUserManager $userManager, |
|
150 | + ISecureRandom $random, |
|
151 | + EventDispatcherInterface $dispatcher, |
|
152 | + $legacyEndpoint = false) { |
|
153 | + $this->db = $db; |
|
154 | + $this->principalBackend = $principalBackend; |
|
155 | + $this->userManager = $userManager; |
|
156 | + $this->sharingBackend = new Backend($this->db, $principalBackend, 'calendar'); |
|
157 | + $this->random = $random; |
|
158 | + $this->dispatcher = $dispatcher; |
|
159 | + $this->legacyEndpoint = $legacyEndpoint; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Return the number of calendars for a principal |
|
164 | + * |
|
165 | + * By default this excludes the automatically generated birthday calendar |
|
166 | + * |
|
167 | + * @param $principalUri |
|
168 | + * @param bool $excludeBirthday |
|
169 | + * @return int |
|
170 | + */ |
|
171 | + public function getCalendarsForUserCount($principalUri, $excludeBirthday = true) { |
|
172 | + $principalUri = $this->convertPrincipal($principalUri, true); |
|
173 | + $query = $this->db->getQueryBuilder(); |
|
174 | + $query->select($query->createFunction('COUNT(*)')) |
|
175 | + ->from('calendars') |
|
176 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))); |
|
177 | + |
|
178 | + if ($excludeBirthday) { |
|
179 | + $query->andWhere($query->expr()->neq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))); |
|
180 | + } |
|
181 | + |
|
182 | + return (int)$query->execute()->fetchColumn(); |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Returns a list of calendars for a principal. |
|
187 | + * |
|
188 | + * Every project is an array with the following keys: |
|
189 | + * * id, a unique id that will be used by other functions to modify the |
|
190 | + * calendar. This can be the same as the uri or a database key. |
|
191 | + * * uri, which the basename of the uri with which the calendar is |
|
192 | + * accessed. |
|
193 | + * * principaluri. The owner of the calendar. Almost always the same as |
|
194 | + * principalUri passed to this method. |
|
195 | + * |
|
196 | + * Furthermore it can contain webdav properties in clark notation. A very |
|
197 | + * common one is '{DAV:}displayname'. |
|
198 | + * |
|
199 | + * Many clients also require: |
|
200 | + * {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set |
|
201 | + * For this property, you can just return an instance of |
|
202 | + * Sabre\CalDAV\Property\SupportedCalendarComponentSet. |
|
203 | + * |
|
204 | + * If you return {http://sabredav.org/ns}read-only and set the value to 1, |
|
205 | + * ACL will automatically be put in read-only mode. |
|
206 | + * |
|
207 | + * @param string $principalUri |
|
208 | + * @return array |
|
209 | + */ |
|
210 | + function getCalendarsForUser($principalUri) { |
|
211 | + $principalUriOriginal = $principalUri; |
|
212 | + $principalUri = $this->convertPrincipal($principalUri, true); |
|
213 | + $fields = array_values($this->propertyMap); |
|
214 | + $fields[] = 'id'; |
|
215 | + $fields[] = 'uri'; |
|
216 | + $fields[] = 'synctoken'; |
|
217 | + $fields[] = 'components'; |
|
218 | + $fields[] = 'principaluri'; |
|
219 | + $fields[] = 'transparent'; |
|
220 | + |
|
221 | + // Making fields a comma-delimited list |
|
222 | + $query = $this->db->getQueryBuilder(); |
|
223 | + $query->select($fields)->from('calendars') |
|
224 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
225 | + ->orderBy('calendarorder', 'ASC'); |
|
226 | + $stmt = $query->execute(); |
|
227 | + |
|
228 | + $calendars = []; |
|
229 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
230 | + |
|
231 | + $components = []; |
|
232 | + if ($row['components']) { |
|
233 | + $components = explode(',',$row['components']); |
|
234 | + } |
|
235 | + |
|
236 | + $calendar = [ |
|
237 | + 'id' => $row['id'], |
|
238 | + 'uri' => $row['uri'], |
|
239 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
240 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
241 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
242 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
243 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
244 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
245 | + ]; |
|
246 | + |
|
247 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
248 | + $calendar[$xmlName] = $row[$dbName]; |
|
249 | + } |
|
250 | + |
|
251 | + if (!isset($calendars[$calendar['id']])) { |
|
252 | + $calendars[$calendar['id']] = $calendar; |
|
253 | + } |
|
254 | + } |
|
255 | + |
|
256 | + $stmt->closeCursor(); |
|
257 | + |
|
258 | + // query for shared calendars |
|
259 | + $principals = $this->principalBackend->getGroupMembership($principalUriOriginal, true); |
|
260 | + $principals[]= $principalUri; |
|
261 | + |
|
262 | + $fields = array_values($this->propertyMap); |
|
263 | + $fields[] = 'a.id'; |
|
264 | + $fields[] = 'a.uri'; |
|
265 | + $fields[] = 'a.synctoken'; |
|
266 | + $fields[] = 'a.components'; |
|
267 | + $fields[] = 'a.principaluri'; |
|
268 | + $fields[] = 'a.transparent'; |
|
269 | + $fields[] = 's.access'; |
|
270 | + $query = $this->db->getQueryBuilder(); |
|
271 | + $result = $query->select($fields) |
|
272 | + ->from('dav_shares', 's') |
|
273 | + ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
274 | + ->where($query->expr()->in('s.principaluri', $query->createParameter('principaluri'))) |
|
275 | + ->andWhere($query->expr()->eq('s.type', $query->createParameter('type'))) |
|
276 | + ->setParameter('type', 'calendar') |
|
277 | + ->setParameter('principaluri', $principals, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) |
|
278 | + ->execute(); |
|
279 | + |
|
280 | + $readOnlyPropertyName = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'; |
|
281 | + while($row = $result->fetch()) { |
|
282 | + if ($row['principaluri'] === $principalUri) { |
|
283 | + continue; |
|
284 | + } |
|
285 | + |
|
286 | + $readOnly = (int) $row['access'] === Backend::ACCESS_READ; |
|
287 | + if (isset($calendars[$row['id']])) { |
|
288 | + if ($readOnly) { |
|
289 | + // New share can not have more permissions then the old one. |
|
290 | + continue; |
|
291 | + } |
|
292 | + if (isset($calendars[$row['id']][$readOnlyPropertyName]) && |
|
293 | + $calendars[$row['id']][$readOnlyPropertyName] === 0) { |
|
294 | + // Old share is already read-write, no more permissions can be gained |
|
295 | + continue; |
|
296 | + } |
|
297 | + } |
|
298 | + |
|
299 | + list(, $name) = URLUtil::splitPath($row['principaluri']); |
|
300 | + $uri = $row['uri'] . '_shared_by_' . $name; |
|
301 | + $row['displayname'] = $row['displayname'] . ' (' . $this->getUserDisplayName($name) . ')'; |
|
302 | + $components = []; |
|
303 | + if ($row['components']) { |
|
304 | + $components = explode(',',$row['components']); |
|
305 | + } |
|
306 | + $calendar = [ |
|
307 | + 'id' => $row['id'], |
|
308 | + 'uri' => $uri, |
|
309 | + 'principaluri' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
310 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
311 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
312 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
313 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
314 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
315 | + $readOnlyPropertyName => $readOnly, |
|
316 | + ]; |
|
317 | + |
|
318 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
319 | + $calendar[$xmlName] = $row[$dbName]; |
|
320 | + } |
|
321 | + |
|
322 | + $calendars[$calendar['id']] = $calendar; |
|
323 | + } |
|
324 | + $result->closeCursor(); |
|
325 | + |
|
326 | + return array_values($calendars); |
|
327 | + } |
|
328 | + |
|
329 | + public function getUsersOwnCalendars($principalUri) { |
|
330 | + $principalUri = $this->convertPrincipal($principalUri, true); |
|
331 | + $fields = array_values($this->propertyMap); |
|
332 | + $fields[] = 'id'; |
|
333 | + $fields[] = 'uri'; |
|
334 | + $fields[] = 'synctoken'; |
|
335 | + $fields[] = 'components'; |
|
336 | + $fields[] = 'principaluri'; |
|
337 | + $fields[] = 'transparent'; |
|
338 | + // Making fields a comma-delimited list |
|
339 | + $query = $this->db->getQueryBuilder(); |
|
340 | + $query->select($fields)->from('calendars') |
|
341 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
342 | + ->orderBy('calendarorder', 'ASC'); |
|
343 | + $stmt = $query->execute(); |
|
344 | + $calendars = []; |
|
345 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
346 | + $components = []; |
|
347 | + if ($row['components']) { |
|
348 | + $components = explode(',',$row['components']); |
|
349 | + } |
|
350 | + $calendar = [ |
|
351 | + 'id' => $row['id'], |
|
352 | + 'uri' => $row['uri'], |
|
353 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
354 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
355 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
356 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
357 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
358 | + ]; |
|
359 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
360 | + $calendar[$xmlName] = $row[$dbName]; |
|
361 | + } |
|
362 | + if (!isset($calendars[$calendar['id']])) { |
|
363 | + $calendars[$calendar['id']] = $calendar; |
|
364 | + } |
|
365 | + } |
|
366 | + $stmt->closeCursor(); |
|
367 | + return array_values($calendars); |
|
368 | + } |
|
369 | + |
|
370 | + |
|
371 | + private function getUserDisplayName($uid) { |
|
372 | + if (!isset($this->userDisplayNames[$uid])) { |
|
373 | + $user = $this->userManager->get($uid); |
|
374 | + |
|
375 | + if ($user instanceof IUser) { |
|
376 | + $this->userDisplayNames[$uid] = $user->getDisplayName(); |
|
377 | + } else { |
|
378 | + $this->userDisplayNames[$uid] = $uid; |
|
379 | + } |
|
380 | + } |
|
381 | + |
|
382 | + return $this->userDisplayNames[$uid]; |
|
383 | + } |
|
384 | 384 | |
385 | - /** |
|
386 | - * @return array |
|
387 | - */ |
|
388 | - public function getPublicCalendars() { |
|
389 | - $fields = array_values($this->propertyMap); |
|
390 | - $fields[] = 'a.id'; |
|
391 | - $fields[] = 'a.uri'; |
|
392 | - $fields[] = 'a.synctoken'; |
|
393 | - $fields[] = 'a.components'; |
|
394 | - $fields[] = 'a.principaluri'; |
|
395 | - $fields[] = 'a.transparent'; |
|
396 | - $fields[] = 's.access'; |
|
397 | - $fields[] = 's.publicuri'; |
|
398 | - $calendars = []; |
|
399 | - $query = $this->db->getQueryBuilder(); |
|
400 | - $result = $query->select($fields) |
|
401 | - ->from('dav_shares', 's') |
|
402 | - ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
403 | - ->where($query->expr()->in('s.access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
404 | - ->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar'))) |
|
405 | - ->execute(); |
|
406 | - |
|
407 | - while($row = $result->fetch()) { |
|
408 | - list(, $name) = URLUtil::splitPath($row['principaluri']); |
|
409 | - $row['displayname'] = $row['displayname'] . "($name)"; |
|
410 | - $components = []; |
|
411 | - if ($row['components']) { |
|
412 | - $components = explode(',',$row['components']); |
|
413 | - } |
|
414 | - $calendar = [ |
|
415 | - 'id' => $row['id'], |
|
416 | - 'uri' => $row['publicuri'], |
|
417 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
418 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
419 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
420 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
421 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
422 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], $this->legacyEndpoint), |
|
423 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
424 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
425 | - ]; |
|
426 | - |
|
427 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
428 | - $calendar[$xmlName] = $row[$dbName]; |
|
429 | - } |
|
430 | - |
|
431 | - if (!isset($calendars[$calendar['id']])) { |
|
432 | - $calendars[$calendar['id']] = $calendar; |
|
433 | - } |
|
434 | - } |
|
435 | - $result->closeCursor(); |
|
436 | - |
|
437 | - return array_values($calendars); |
|
438 | - } |
|
439 | - |
|
440 | - /** |
|
441 | - * @param string $uri |
|
442 | - * @return array |
|
443 | - * @throws NotFound |
|
444 | - */ |
|
445 | - public function getPublicCalendar($uri) { |
|
446 | - $fields = array_values($this->propertyMap); |
|
447 | - $fields[] = 'a.id'; |
|
448 | - $fields[] = 'a.uri'; |
|
449 | - $fields[] = 'a.synctoken'; |
|
450 | - $fields[] = 'a.components'; |
|
451 | - $fields[] = 'a.principaluri'; |
|
452 | - $fields[] = 'a.transparent'; |
|
453 | - $fields[] = 's.access'; |
|
454 | - $fields[] = 's.publicuri'; |
|
455 | - $query = $this->db->getQueryBuilder(); |
|
456 | - $result = $query->select($fields) |
|
457 | - ->from('dav_shares', 's') |
|
458 | - ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
459 | - ->where($query->expr()->in('s.access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
460 | - ->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar'))) |
|
461 | - ->andWhere($query->expr()->eq('s.publicuri', $query->createNamedParameter($uri))) |
|
462 | - ->execute(); |
|
463 | - |
|
464 | - $row = $result->fetch(\PDO::FETCH_ASSOC); |
|
465 | - |
|
466 | - $result->closeCursor(); |
|
467 | - |
|
468 | - if ($row === false) { |
|
469 | - throw new NotFound('Node with name \'' . $uri . '\' could not be found'); |
|
470 | - } |
|
471 | - |
|
472 | - list(, $name) = URLUtil::splitPath($row['principaluri']); |
|
473 | - $row['displayname'] = $row['displayname'] . ' ' . "($name)"; |
|
474 | - $components = []; |
|
475 | - if ($row['components']) { |
|
476 | - $components = explode(',',$row['components']); |
|
477 | - } |
|
478 | - $calendar = [ |
|
479 | - 'id' => $row['id'], |
|
480 | - 'uri' => $row['publicuri'], |
|
481 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
482 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
483 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
484 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
485 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
486 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
487 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
488 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
489 | - ]; |
|
490 | - |
|
491 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
492 | - $calendar[$xmlName] = $row[$dbName]; |
|
493 | - } |
|
494 | - |
|
495 | - return $calendar; |
|
496 | - |
|
497 | - } |
|
498 | - |
|
499 | - /** |
|
500 | - * @param string $principal |
|
501 | - * @param string $uri |
|
502 | - * @return array|null |
|
503 | - */ |
|
504 | - public function getCalendarByUri($principal, $uri) { |
|
505 | - $fields = array_values($this->propertyMap); |
|
506 | - $fields[] = 'id'; |
|
507 | - $fields[] = 'uri'; |
|
508 | - $fields[] = 'synctoken'; |
|
509 | - $fields[] = 'components'; |
|
510 | - $fields[] = 'principaluri'; |
|
511 | - $fields[] = 'transparent'; |
|
512 | - |
|
513 | - // Making fields a comma-delimited list |
|
514 | - $query = $this->db->getQueryBuilder(); |
|
515 | - $query->select($fields)->from('calendars') |
|
516 | - ->where($query->expr()->eq('uri', $query->createNamedParameter($uri))) |
|
517 | - ->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($principal))) |
|
518 | - ->setMaxResults(1); |
|
519 | - $stmt = $query->execute(); |
|
520 | - |
|
521 | - $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
522 | - $stmt->closeCursor(); |
|
523 | - if ($row === false) { |
|
524 | - return null; |
|
525 | - } |
|
526 | - |
|
527 | - $components = []; |
|
528 | - if ($row['components']) { |
|
529 | - $components = explode(',',$row['components']); |
|
530 | - } |
|
531 | - |
|
532 | - $calendar = [ |
|
533 | - 'id' => $row['id'], |
|
534 | - 'uri' => $row['uri'], |
|
535 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
536 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
537 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
538 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
539 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
540 | - ]; |
|
541 | - |
|
542 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
543 | - $calendar[$xmlName] = $row[$dbName]; |
|
544 | - } |
|
545 | - |
|
546 | - return $calendar; |
|
547 | - } |
|
548 | - |
|
549 | - public function getCalendarById($calendarId) { |
|
550 | - $fields = array_values($this->propertyMap); |
|
551 | - $fields[] = 'id'; |
|
552 | - $fields[] = 'uri'; |
|
553 | - $fields[] = 'synctoken'; |
|
554 | - $fields[] = 'components'; |
|
555 | - $fields[] = 'principaluri'; |
|
556 | - $fields[] = 'transparent'; |
|
557 | - |
|
558 | - // Making fields a comma-delimited list |
|
559 | - $query = $this->db->getQueryBuilder(); |
|
560 | - $query->select($fields)->from('calendars') |
|
561 | - ->where($query->expr()->eq('id', $query->createNamedParameter($calendarId))) |
|
562 | - ->setMaxResults(1); |
|
563 | - $stmt = $query->execute(); |
|
564 | - |
|
565 | - $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
566 | - $stmt->closeCursor(); |
|
567 | - if ($row === false) { |
|
568 | - return null; |
|
569 | - } |
|
570 | - |
|
571 | - $components = []; |
|
572 | - if ($row['components']) { |
|
573 | - $components = explode(',',$row['components']); |
|
574 | - } |
|
575 | - |
|
576 | - $calendar = [ |
|
577 | - 'id' => $row['id'], |
|
578 | - 'uri' => $row['uri'], |
|
579 | - 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
580 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
581 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
582 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
583 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
584 | - ]; |
|
585 | - |
|
586 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
587 | - $calendar[$xmlName] = $row[$dbName]; |
|
588 | - } |
|
589 | - |
|
590 | - return $calendar; |
|
591 | - } |
|
592 | - |
|
593 | - /** |
|
594 | - * Creates a new calendar for a principal. |
|
595 | - * |
|
596 | - * If the creation was a success, an id must be returned that can be used to reference |
|
597 | - * this calendar in other methods, such as updateCalendar. |
|
598 | - * |
|
599 | - * @param string $principalUri |
|
600 | - * @param string $calendarUri |
|
601 | - * @param array $properties |
|
602 | - * @return int |
|
603 | - */ |
|
604 | - function createCalendar($principalUri, $calendarUri, array $properties) { |
|
605 | - $values = [ |
|
606 | - 'principaluri' => $this->convertPrincipal($principalUri, true), |
|
607 | - 'uri' => $calendarUri, |
|
608 | - 'synctoken' => 1, |
|
609 | - 'transparent' => 0, |
|
610 | - 'components' => 'VEVENT,VTODO', |
|
611 | - 'displayname' => $calendarUri |
|
612 | - ]; |
|
613 | - |
|
614 | - // Default value |
|
615 | - $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set'; |
|
616 | - if (isset($properties[$sccs])) { |
|
617 | - if (!($properties[$sccs] instanceof SupportedCalendarComponentSet)) { |
|
618 | - throw new DAV\Exception('The ' . $sccs . ' property must be of type: \Sabre\CalDAV\Property\SupportedCalendarComponentSet'); |
|
619 | - } |
|
620 | - $values['components'] = implode(',',$properties[$sccs]->getValue()); |
|
621 | - } |
|
622 | - $transp = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
623 | - if (isset($properties[$transp])) { |
|
624 | - $values['transparent'] = (int) ($properties[$transp]->getValue() === 'transparent'); |
|
625 | - } |
|
626 | - |
|
627 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
628 | - if (isset($properties[$xmlName])) { |
|
629 | - $values[$dbName] = $properties[$xmlName]; |
|
630 | - } |
|
631 | - } |
|
632 | - |
|
633 | - $query = $this->db->getQueryBuilder(); |
|
634 | - $query->insert('calendars'); |
|
635 | - foreach($values as $column => $value) { |
|
636 | - $query->setValue($column, $query->createNamedParameter($value)); |
|
637 | - } |
|
638 | - $query->execute(); |
|
639 | - $calendarId = $query->getLastInsertId(); |
|
640 | - |
|
641 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', new GenericEvent( |
|
642 | - '\OCA\DAV\CalDAV\CalDavBackend::createCalendar', |
|
643 | - [ |
|
644 | - 'calendarId' => $calendarId, |
|
645 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
646 | - ])); |
|
647 | - |
|
648 | - return $calendarId; |
|
649 | - } |
|
650 | - |
|
651 | - /** |
|
652 | - * Updates properties for a calendar. |
|
653 | - * |
|
654 | - * The list of mutations is stored in a Sabre\DAV\PropPatch object. |
|
655 | - * To do the actual updates, you must tell this object which properties |
|
656 | - * you're going to process with the handle() method. |
|
657 | - * |
|
658 | - * Calling the handle method is like telling the PropPatch object "I |
|
659 | - * promise I can handle updating this property". |
|
660 | - * |
|
661 | - * Read the PropPatch documentation for more info and examples. |
|
662 | - * |
|
663 | - * @param PropPatch $propPatch |
|
664 | - * @return void |
|
665 | - */ |
|
666 | - function updateCalendar($calendarId, PropPatch $propPatch) { |
|
667 | - $supportedProperties = array_keys($this->propertyMap); |
|
668 | - $supportedProperties[] = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
669 | - |
|
670 | - $propPatch->handle($supportedProperties, function($mutations) use ($calendarId) { |
|
671 | - $newValues = []; |
|
672 | - foreach ($mutations as $propertyName => $propertyValue) { |
|
673 | - |
|
674 | - switch ($propertyName) { |
|
675 | - case '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' : |
|
676 | - $fieldName = 'transparent'; |
|
677 | - $newValues[$fieldName] = (int) ($propertyValue->getValue() === 'transparent'); |
|
678 | - break; |
|
679 | - default : |
|
680 | - $fieldName = $this->propertyMap[$propertyName]; |
|
681 | - $newValues[$fieldName] = $propertyValue; |
|
682 | - break; |
|
683 | - } |
|
684 | - |
|
685 | - } |
|
686 | - $query = $this->db->getQueryBuilder(); |
|
687 | - $query->update('calendars'); |
|
688 | - foreach ($newValues as $fieldName => $value) { |
|
689 | - $query->set($fieldName, $query->createNamedParameter($value)); |
|
690 | - } |
|
691 | - $query->where($query->expr()->eq('id', $query->createNamedParameter($calendarId))); |
|
692 | - $query->execute(); |
|
693 | - |
|
694 | - $this->addChange($calendarId, "", 2); |
|
695 | - |
|
696 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', new GenericEvent( |
|
697 | - '\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', |
|
698 | - [ |
|
699 | - 'calendarId' => $calendarId, |
|
700 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
701 | - 'shares' => $this->getShares($calendarId), |
|
702 | - 'propertyMutations' => $mutations, |
|
703 | - ])); |
|
704 | - |
|
705 | - return true; |
|
706 | - }); |
|
707 | - } |
|
708 | - |
|
709 | - /** |
|
710 | - * Delete a calendar and all it's objects |
|
711 | - * |
|
712 | - * @param mixed $calendarId |
|
713 | - * @return void |
|
714 | - */ |
|
715 | - function deleteCalendar($calendarId) { |
|
716 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', new GenericEvent( |
|
717 | - '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', |
|
718 | - [ |
|
719 | - 'calendarId' => $calendarId, |
|
720 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
721 | - 'shares' => $this->getShares($calendarId), |
|
722 | - ])); |
|
723 | - |
|
724 | - $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ?'); |
|
725 | - $stmt->execute([$calendarId]); |
|
726 | - |
|
727 | - $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
728 | - $stmt->execute([$calendarId]); |
|
729 | - |
|
730 | - $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarchanges` WHERE `calendarid` = ?'); |
|
731 | - $stmt->execute([$calendarId]); |
|
732 | - |
|
733 | - $this->sharingBackend->deleteAllShares($calendarId); |
|
734 | - } |
|
735 | - |
|
736 | - /** |
|
737 | - * Delete all of an user's shares |
|
738 | - * |
|
739 | - * @param string $principaluri |
|
740 | - * @return void |
|
741 | - */ |
|
742 | - function deleteAllSharesByUser($principaluri) { |
|
743 | - $this->sharingBackend->deleteAllSharesByUser($principaluri); |
|
744 | - } |
|
745 | - |
|
746 | - /** |
|
747 | - * Returns all calendar objects within a calendar. |
|
748 | - * |
|
749 | - * Every item contains an array with the following keys: |
|
750 | - * * calendardata - The iCalendar-compatible calendar data |
|
751 | - * * uri - a unique key which will be used to construct the uri. This can |
|
752 | - * be any arbitrary string, but making sure it ends with '.ics' is a |
|
753 | - * good idea. This is only the basename, or filename, not the full |
|
754 | - * path. |
|
755 | - * * lastmodified - a timestamp of the last modification time |
|
756 | - * * etag - An arbitrary string, surrounded by double-quotes. (e.g.: |
|
757 | - * '"abcdef"') |
|
758 | - * * size - The size of the calendar objects, in bytes. |
|
759 | - * * component - optional, a string containing the type of object, such |
|
760 | - * as 'vevent' or 'vtodo'. If specified, this will be used to populate |
|
761 | - * the Content-Type header. |
|
762 | - * |
|
763 | - * Note that the etag is optional, but it's highly encouraged to return for |
|
764 | - * speed reasons. |
|
765 | - * |
|
766 | - * The calendardata is also optional. If it's not returned |
|
767 | - * 'getCalendarObject' will be called later, which *is* expected to return |
|
768 | - * calendardata. |
|
769 | - * |
|
770 | - * If neither etag or size are specified, the calendardata will be |
|
771 | - * used/fetched to determine these numbers. If both are specified the |
|
772 | - * amount of times this is needed is reduced by a great degree. |
|
773 | - * |
|
774 | - * @param mixed $calendarId |
|
775 | - * @return array |
|
776 | - */ |
|
777 | - function getCalendarObjects($calendarId) { |
|
778 | - $query = $this->db->getQueryBuilder(); |
|
779 | - $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'componenttype', 'classification']) |
|
780 | - ->from('calendarobjects') |
|
781 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
782 | - $stmt = $query->execute(); |
|
783 | - |
|
784 | - $result = []; |
|
785 | - foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
786 | - $result[] = [ |
|
787 | - 'id' => $row['id'], |
|
788 | - 'uri' => $row['uri'], |
|
789 | - 'lastmodified' => $row['lastmodified'], |
|
790 | - 'etag' => '"' . $row['etag'] . '"', |
|
791 | - 'calendarid' => $row['calendarid'], |
|
792 | - 'size' => (int)$row['size'], |
|
793 | - 'component' => strtolower($row['componenttype']), |
|
794 | - 'classification'=> (int)$row['classification'] |
|
795 | - ]; |
|
796 | - } |
|
797 | - |
|
798 | - return $result; |
|
799 | - } |
|
800 | - |
|
801 | - /** |
|
802 | - * Returns information from a single calendar object, based on it's object |
|
803 | - * uri. |
|
804 | - * |
|
805 | - * The object uri is only the basename, or filename and not a full path. |
|
806 | - * |
|
807 | - * The returned array must have the same keys as getCalendarObjects. The |
|
808 | - * 'calendardata' object is required here though, while it's not required |
|
809 | - * for getCalendarObjects. |
|
810 | - * |
|
811 | - * This method must return null if the object did not exist. |
|
812 | - * |
|
813 | - * @param mixed $calendarId |
|
814 | - * @param string $objectUri |
|
815 | - * @return array|null |
|
816 | - */ |
|
817 | - function getCalendarObject($calendarId, $objectUri) { |
|
818 | - |
|
819 | - $query = $this->db->getQueryBuilder(); |
|
820 | - $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification']) |
|
821 | - ->from('calendarobjects') |
|
822 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
823 | - ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))); |
|
824 | - $stmt = $query->execute(); |
|
825 | - $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
826 | - |
|
827 | - if(!$row) return null; |
|
828 | - |
|
829 | - return [ |
|
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 | - 'calendardata' => $this->readBlob($row['calendardata']), |
|
837 | - 'component' => strtolower($row['componenttype']), |
|
838 | - 'classification'=> (int)$row['classification'] |
|
839 | - ]; |
|
840 | - } |
|
841 | - |
|
842 | - /** |
|
843 | - * Returns a list of calendar objects. |
|
844 | - * |
|
845 | - * This method should work identical to getCalendarObject, but instead |
|
846 | - * return all the calendar objects in the list as an array. |
|
847 | - * |
|
848 | - * If the backend supports this, it may allow for some speed-ups. |
|
849 | - * |
|
850 | - * @param mixed $calendarId |
|
851 | - * @param string[] $uris |
|
852 | - * @return array |
|
853 | - */ |
|
854 | - function getMultipleCalendarObjects($calendarId, array $uris) { |
|
855 | - if (empty($uris)) { |
|
856 | - return []; |
|
857 | - } |
|
858 | - |
|
859 | - $chunks = array_chunk($uris, 100); |
|
860 | - $objects = []; |
|
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()->in('uri', $query->createParameter('uri'))); |
|
867 | - |
|
868 | - foreach ($chunks as $uris) { |
|
869 | - $query->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY); |
|
870 | - $result = $query->execute(); |
|
871 | - |
|
872 | - while ($row = $result->fetch()) { |
|
873 | - $objects[] = [ |
|
874 | - 'id' => $row['id'], |
|
875 | - 'uri' => $row['uri'], |
|
876 | - 'lastmodified' => $row['lastmodified'], |
|
877 | - 'etag' => '"' . $row['etag'] . '"', |
|
878 | - 'calendarid' => $row['calendarid'], |
|
879 | - 'size' => (int)$row['size'], |
|
880 | - 'calendardata' => $this->readBlob($row['calendardata']), |
|
881 | - 'component' => strtolower($row['componenttype']), |
|
882 | - 'classification' => (int)$row['classification'] |
|
883 | - ]; |
|
884 | - } |
|
885 | - $result->closeCursor(); |
|
886 | - } |
|
887 | - return $objects; |
|
888 | - } |
|
889 | - |
|
890 | - /** |
|
891 | - * Creates a new calendar object. |
|
892 | - * |
|
893 | - * The object uri is only the basename, or filename and not a full path. |
|
894 | - * |
|
895 | - * It is possible return an etag from this function, which will be used in |
|
896 | - * the response to this PUT request. Note that the ETag must be surrounded |
|
897 | - * by double-quotes. |
|
898 | - * |
|
899 | - * However, you should only really return this ETag if you don't mangle the |
|
900 | - * calendar-data. If the result of a subsequent GET to this object is not |
|
901 | - * the exact same as this request body, you should omit the ETag. |
|
902 | - * |
|
903 | - * @param mixed $calendarId |
|
904 | - * @param string $objectUri |
|
905 | - * @param string $calendarData |
|
906 | - * @return string |
|
907 | - */ |
|
908 | - function createCalendarObject($calendarId, $objectUri, $calendarData) { |
|
909 | - $extraData = $this->getDenormalizedData($calendarData); |
|
910 | - |
|
911 | - $query = $this->db->getQueryBuilder(); |
|
912 | - $query->insert('calendarobjects') |
|
913 | - ->values([ |
|
914 | - 'calendarid' => $query->createNamedParameter($calendarId), |
|
915 | - 'uri' => $query->createNamedParameter($objectUri), |
|
916 | - 'calendardata' => $query->createNamedParameter($calendarData, IQueryBuilder::PARAM_LOB), |
|
917 | - 'lastmodified' => $query->createNamedParameter(time()), |
|
918 | - 'etag' => $query->createNamedParameter($extraData['etag']), |
|
919 | - 'size' => $query->createNamedParameter($extraData['size']), |
|
920 | - 'componenttype' => $query->createNamedParameter($extraData['componentType']), |
|
921 | - 'firstoccurence' => $query->createNamedParameter($extraData['firstOccurence']), |
|
922 | - 'lastoccurence' => $query->createNamedParameter($extraData['lastOccurence']), |
|
923 | - 'classification' => $query->createNamedParameter($extraData['classification']), |
|
924 | - 'uid' => $query->createNamedParameter($extraData['uid']), |
|
925 | - ]) |
|
926 | - ->execute(); |
|
927 | - |
|
928 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', new GenericEvent( |
|
929 | - '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', |
|
930 | - [ |
|
931 | - 'calendarId' => $calendarId, |
|
932 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
933 | - 'shares' => $this->getShares($calendarId), |
|
934 | - 'objectData' => $this->getCalendarObject($calendarId, $objectUri), |
|
935 | - ] |
|
936 | - )); |
|
937 | - $this->addChange($calendarId, $objectUri, 1); |
|
938 | - |
|
939 | - return '"' . $extraData['etag'] . '"'; |
|
940 | - } |
|
941 | - |
|
942 | - /** |
|
943 | - * Updates an existing calendarobject, based on it's uri. |
|
944 | - * |
|
945 | - * The object uri is only the basename, or filename and not a full path. |
|
946 | - * |
|
947 | - * It is possible return an etag from this function, which will be used in |
|
948 | - * the response to this PUT request. Note that the ETag must be surrounded |
|
949 | - * by double-quotes. |
|
950 | - * |
|
951 | - * However, you should only really return this ETag if you don't mangle the |
|
952 | - * calendar-data. If the result of a subsequent GET to this object is not |
|
953 | - * the exact same as this request body, you should omit the ETag. |
|
954 | - * |
|
955 | - * @param mixed $calendarId |
|
956 | - * @param string $objectUri |
|
957 | - * @param string $calendarData |
|
958 | - * @return string |
|
959 | - */ |
|
960 | - function updateCalendarObject($calendarId, $objectUri, $calendarData) { |
|
961 | - $extraData = $this->getDenormalizedData($calendarData); |
|
962 | - |
|
963 | - $query = $this->db->getQueryBuilder(); |
|
964 | - $query->update('calendarobjects') |
|
965 | - ->set('calendardata', $query->createNamedParameter($calendarData, IQueryBuilder::PARAM_LOB)) |
|
966 | - ->set('lastmodified', $query->createNamedParameter(time())) |
|
967 | - ->set('etag', $query->createNamedParameter($extraData['etag'])) |
|
968 | - ->set('size', $query->createNamedParameter($extraData['size'])) |
|
969 | - ->set('componenttype', $query->createNamedParameter($extraData['componentType'])) |
|
970 | - ->set('firstoccurence', $query->createNamedParameter($extraData['firstOccurence'])) |
|
971 | - ->set('lastoccurence', $query->createNamedParameter($extraData['lastOccurence'])) |
|
972 | - ->set('classification', $query->createNamedParameter($extraData['classification'])) |
|
973 | - ->set('uid', $query->createNamedParameter($extraData['uid'])) |
|
974 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
975 | - ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
976 | - ->execute(); |
|
977 | - |
|
978 | - $data = $this->getCalendarObject($calendarId, $objectUri); |
|
979 | - if (is_array($data)) { |
|
980 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', new GenericEvent( |
|
981 | - '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', |
|
982 | - [ |
|
983 | - 'calendarId' => $calendarId, |
|
984 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
985 | - 'shares' => $this->getShares($calendarId), |
|
986 | - 'objectData' => $data, |
|
987 | - ] |
|
988 | - )); |
|
989 | - } |
|
990 | - $this->addChange($calendarId, $objectUri, 2); |
|
991 | - |
|
992 | - return '"' . $extraData['etag'] . '"'; |
|
993 | - } |
|
994 | - |
|
995 | - /** |
|
996 | - * @param int $calendarObjectId |
|
997 | - * @param int $classification |
|
998 | - */ |
|
999 | - public function setClassification($calendarObjectId, $classification) { |
|
1000 | - if (!in_array($classification, [ |
|
1001 | - self::CLASSIFICATION_PUBLIC, self::CLASSIFICATION_PRIVATE, self::CLASSIFICATION_CONFIDENTIAL |
|
1002 | - ])) { |
|
1003 | - throw new \InvalidArgumentException(); |
|
1004 | - } |
|
1005 | - $query = $this->db->getQueryBuilder(); |
|
1006 | - $query->update('calendarobjects') |
|
1007 | - ->set('classification', $query->createNamedParameter($classification)) |
|
1008 | - ->where($query->expr()->eq('id', $query->createNamedParameter($calendarObjectId))) |
|
1009 | - ->execute(); |
|
1010 | - } |
|
1011 | - |
|
1012 | - /** |
|
1013 | - * Deletes an existing calendar object. |
|
1014 | - * |
|
1015 | - * The object uri is only the basename, or filename and not a full path. |
|
1016 | - * |
|
1017 | - * @param mixed $calendarId |
|
1018 | - * @param string $objectUri |
|
1019 | - * @return void |
|
1020 | - */ |
|
1021 | - function deleteCalendarObject($calendarId, $objectUri) { |
|
1022 | - $data = $this->getCalendarObject($calendarId, $objectUri); |
|
1023 | - if (is_array($data)) { |
|
1024 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', new GenericEvent( |
|
1025 | - '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', |
|
1026 | - [ |
|
1027 | - 'calendarId' => $calendarId, |
|
1028 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
1029 | - 'shares' => $this->getShares($calendarId), |
|
1030 | - 'objectData' => $data, |
|
1031 | - ] |
|
1032 | - )); |
|
1033 | - } |
|
1034 | - |
|
1035 | - $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ? AND `uri` = ?'); |
|
1036 | - $stmt->execute([$calendarId, $objectUri]); |
|
1037 | - |
|
1038 | - $this->addChange($calendarId, $objectUri, 3); |
|
1039 | - } |
|
1040 | - |
|
1041 | - /** |
|
1042 | - * Performs a calendar-query on the contents of this calendar. |
|
1043 | - * |
|
1044 | - * The calendar-query is defined in RFC4791 : CalDAV. Using the |
|
1045 | - * calendar-query it is possible for a client to request a specific set of |
|
1046 | - * object, based on contents of iCalendar properties, date-ranges and |
|
1047 | - * iCalendar component types (VTODO, VEVENT). |
|
1048 | - * |
|
1049 | - * This method should just return a list of (relative) urls that match this |
|
1050 | - * query. |
|
1051 | - * |
|
1052 | - * The list of filters are specified as an array. The exact array is |
|
1053 | - * documented by Sabre\CalDAV\CalendarQueryParser. |
|
1054 | - * |
|
1055 | - * Note that it is extremely likely that getCalendarObject for every path |
|
1056 | - * returned from this method will be called almost immediately after. You |
|
1057 | - * may want to anticipate this to speed up these requests. |
|
1058 | - * |
|
1059 | - * This method provides a default implementation, which parses *all* the |
|
1060 | - * iCalendar objects in the specified calendar. |
|
1061 | - * |
|
1062 | - * This default may well be good enough for personal use, and calendars |
|
1063 | - * that aren't very large. But if you anticipate high usage, big calendars |
|
1064 | - * or high loads, you are strongly advised to optimize certain paths. |
|
1065 | - * |
|
1066 | - * The best way to do so is override this method and to optimize |
|
1067 | - * specifically for 'common filters'. |
|
1068 | - * |
|
1069 | - * Requests that are extremely common are: |
|
1070 | - * * requests for just VEVENTS |
|
1071 | - * * requests for just VTODO |
|
1072 | - * * requests with a time-range-filter on either VEVENT or VTODO. |
|
1073 | - * |
|
1074 | - * ..and combinations of these requests. It may not be worth it to try to |
|
1075 | - * handle every possible situation and just rely on the (relatively |
|
1076 | - * easy to use) CalendarQueryValidator to handle the rest. |
|
1077 | - * |
|
1078 | - * Note that especially time-range-filters may be difficult to parse. A |
|
1079 | - * time-range filter specified on a VEVENT must for instance also handle |
|
1080 | - * recurrence rules correctly. |
|
1081 | - * A good example of how to interprete all these filters can also simply |
|
1082 | - * be found in Sabre\CalDAV\CalendarQueryFilter. This class is as correct |
|
1083 | - * as possible, so it gives you a good idea on what type of stuff you need |
|
1084 | - * to think of. |
|
1085 | - * |
|
1086 | - * @param mixed $calendarId |
|
1087 | - * @param array $filters |
|
1088 | - * @return array |
|
1089 | - */ |
|
1090 | - function calendarQuery($calendarId, array $filters) { |
|
1091 | - $componentType = null; |
|
1092 | - $requirePostFilter = true; |
|
1093 | - $timeRange = null; |
|
1094 | - |
|
1095 | - // if no filters were specified, we don't need to filter after a query |
|
1096 | - if (!$filters['prop-filters'] && !$filters['comp-filters']) { |
|
1097 | - $requirePostFilter = false; |
|
1098 | - } |
|
1099 | - |
|
1100 | - // Figuring out if there's a component filter |
|
1101 | - if (count($filters['comp-filters']) > 0 && !$filters['comp-filters'][0]['is-not-defined']) { |
|
1102 | - $componentType = $filters['comp-filters'][0]['name']; |
|
1103 | - |
|
1104 | - // Checking if we need post-filters |
|
1105 | - if (!$filters['prop-filters'] && !$filters['comp-filters'][0]['comp-filters'] && !$filters['comp-filters'][0]['time-range'] && !$filters['comp-filters'][0]['prop-filters']) { |
|
1106 | - $requirePostFilter = false; |
|
1107 | - } |
|
1108 | - // There was a time-range filter |
|
1109 | - if ($componentType == 'VEVENT' && isset($filters['comp-filters'][0]['time-range'])) { |
|
1110 | - $timeRange = $filters['comp-filters'][0]['time-range']; |
|
1111 | - |
|
1112 | - // If start time OR the end time is not specified, we can do a |
|
1113 | - // 100% accurate mysql query. |
|
1114 | - if (!$filters['prop-filters'] && !$filters['comp-filters'][0]['comp-filters'] && !$filters['comp-filters'][0]['prop-filters'] && (!$timeRange['start'] || !$timeRange['end'])) { |
|
1115 | - $requirePostFilter = false; |
|
1116 | - } |
|
1117 | - } |
|
1118 | - |
|
1119 | - } |
|
1120 | - $columns = ['uri']; |
|
1121 | - if ($requirePostFilter) { |
|
1122 | - $columns = ['uri', 'calendardata']; |
|
1123 | - } |
|
1124 | - $query = $this->db->getQueryBuilder(); |
|
1125 | - $query->select($columns) |
|
1126 | - ->from('calendarobjects') |
|
1127 | - ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
1128 | - |
|
1129 | - if ($componentType) { |
|
1130 | - $query->andWhere($query->expr()->eq('componenttype', $query->createNamedParameter($componentType))); |
|
1131 | - } |
|
1132 | - |
|
1133 | - if ($timeRange && $timeRange['start']) { |
|
1134 | - $query->andWhere($query->expr()->gt('lastoccurence', $query->createNamedParameter($timeRange['start']->getTimeStamp()))); |
|
1135 | - } |
|
1136 | - if ($timeRange && $timeRange['end']) { |
|
1137 | - $query->andWhere($query->expr()->lt('firstoccurence', $query->createNamedParameter($timeRange['end']->getTimeStamp()))); |
|
1138 | - } |
|
1139 | - |
|
1140 | - $stmt = $query->execute(); |
|
1141 | - |
|
1142 | - $result = []; |
|
1143 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1144 | - if ($requirePostFilter) { |
|
1145 | - if (!$this->validateFilterForObject($row, $filters)) { |
|
1146 | - continue; |
|
1147 | - } |
|
1148 | - } |
|
1149 | - $result[] = $row['uri']; |
|
1150 | - } |
|
1151 | - |
|
1152 | - return $result; |
|
1153 | - } |
|
1154 | - |
|
1155 | - /** |
|
1156 | - * custom Nextcloud search extension for CalDAV |
|
1157 | - * |
|
1158 | - * @param string $principalUri |
|
1159 | - * @param array $filters |
|
1160 | - * @param integer|null $limit |
|
1161 | - * @param integer|null $offset |
|
1162 | - * @return array |
|
1163 | - */ |
|
1164 | - public function calendarSearch($principalUri, array $filters, $limit=null, $offset=null) { |
|
1165 | - $calendars = $this->getCalendarsForUser($principalUri); |
|
1166 | - $ownCalendars = []; |
|
1167 | - $sharedCalendars = []; |
|
1168 | - |
|
1169 | - $uriMapper = []; |
|
1170 | - |
|
1171 | - foreach($calendars as $calendar) { |
|
1172 | - if ($calendar['{http://owncloud.org/ns}owner-principal'] === $principalUri) { |
|
1173 | - $ownCalendars[] = $calendar['id']; |
|
1174 | - } else { |
|
1175 | - $sharedCalendars[] = $calendar['id']; |
|
1176 | - } |
|
1177 | - $uriMapper[$calendar['id']] = $calendar['uri']; |
|
1178 | - } |
|
1179 | - if (count($ownCalendars) === 0 && count($sharedCalendars) === 0) { |
|
1180 | - return []; |
|
1181 | - } |
|
1182 | - |
|
1183 | - $query = $this->db->getQueryBuilder(); |
|
1184 | - |
|
1185 | - // Calendar id expressions |
|
1186 | - $calendarExpressions = []; |
|
1187 | - foreach($ownCalendars as $id) { |
|
1188 | - $calendarExpressions[] = $query->expr() |
|
1189 | - ->eq('calendarid', $query->createNamedParameter($id)); |
|
1190 | - } |
|
1191 | - foreach($sharedCalendars as $id) { |
|
1192 | - $calendarExpressions[] = $query->expr()->andX( |
|
1193 | - $query->expr()->eq('calendarid', |
|
1194 | - $query->createNamedParameter($id)), |
|
1195 | - $query->expr()->eq('classification', |
|
1196 | - $query->createNamedParameter(0)) |
|
1197 | - ); |
|
1198 | - } |
|
1199 | - |
|
1200 | - if (count($calendarExpressions) === 1) { |
|
1201 | - $calExpr = $calendarExpressions[0]; |
|
1202 | - } else { |
|
1203 | - $calExpr = call_user_func_array([$query->expr(), 'orX'], $calendarExpressions); |
|
1204 | - } |
|
1205 | - |
|
1206 | - // Component expressions |
|
1207 | - $compExpressions = []; |
|
1208 | - foreach($filters['comps'] as $comp) { |
|
1209 | - $compExpressions[] = $query->expr() |
|
1210 | - ->eq('componenttype', $query->createNamedParameter($comp)); |
|
1211 | - } |
|
1212 | - |
|
1213 | - if (count($compExpressions) === 1) { |
|
1214 | - $compExpr = $compExpressions[0]; |
|
1215 | - } else { |
|
1216 | - $compExpr = call_user_func_array([$query->expr(), 'orX'], $compExpressions); |
|
1217 | - } |
|
1218 | - |
|
1219 | - // property and filter expression |
|
1220 | - $searchTermFilter = $query->expr()->like('calendardata', |
|
1221 | - $query->createNamedParameter('%' . $this->db->escapeLikeParameter($filters['search-term']) . '%')); |
|
1222 | - |
|
1223 | - $query->select(['calendarid', 'uri', 'calendardata']) |
|
1224 | - ->from('calendarobjects') |
|
1225 | - ->where($calExpr) |
|
1226 | - ->andWhere($compExpr) |
|
1227 | - ->andWhere($searchTermFilter); |
|
1228 | - |
|
1229 | - $stmt = $query->execute(); |
|
1230 | - |
|
1231 | - $result = []; |
|
1232 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1233 | - if (!$this->validateFilterForCalendarSearch($row, $filters)) { |
|
1234 | - continue; |
|
1235 | - } |
|
1236 | - |
|
1237 | - $result[] = $uriMapper[$row['calendarid']] . '/' . $row['uri']; |
|
1238 | - } |
|
1239 | - |
|
1240 | - return $result; |
|
1241 | - } |
|
1242 | - |
|
1243 | - /** |
|
1244 | - * This method validates if a filter (as passed to calendarSearch) matches |
|
1245 | - * the given object. |
|
1246 | - * |
|
1247 | - * @param array $object |
|
1248 | - * @param array $filters |
|
1249 | - * @return bool |
|
1250 | - */ |
|
1251 | - protected function validateFilterForCalendarSearch(array $object, array $filters) { |
|
1252 | - $vObject = Reader::read($object['calendardata']); |
|
1253 | - |
|
1254 | - $validator = new Search\CalendarSearchValidator(); |
|
1255 | - $result = $validator->validate($vObject, $filters); |
|
1256 | - |
|
1257 | - // Destroy circular references so PHP will GC the object. |
|
1258 | - $vObject->destroy(); |
|
1259 | - |
|
1260 | - return $result; |
|
1261 | - } |
|
1262 | - |
|
1263 | - /** |
|
1264 | - * Searches through all of a users calendars and calendar objects to find |
|
1265 | - * an object with a specific UID. |
|
1266 | - * |
|
1267 | - * This method should return the path to this object, relative to the |
|
1268 | - * calendar home, so this path usually only contains two parts: |
|
1269 | - * |
|
1270 | - * calendarpath/objectpath.ics |
|
1271 | - * |
|
1272 | - * If the uid is not found, return null. |
|
1273 | - * |
|
1274 | - * This method should only consider * objects that the principal owns, so |
|
1275 | - * any calendars owned by other principals that also appear in this |
|
1276 | - * collection should be ignored. |
|
1277 | - * |
|
1278 | - * @param string $principalUri |
|
1279 | - * @param string $uid |
|
1280 | - * @return string|null |
|
1281 | - */ |
|
1282 | - function getCalendarObjectByUID($principalUri, $uid) { |
|
1283 | - |
|
1284 | - $query = $this->db->getQueryBuilder(); |
|
1285 | - $query->selectAlias('c.uri', 'calendaruri')->selectAlias('co.uri', 'objecturi') |
|
1286 | - ->from('calendarobjects', 'co') |
|
1287 | - ->leftJoin('co', 'calendars', 'c', $query->expr()->eq('co.calendarid', 'c.id')) |
|
1288 | - ->where($query->expr()->eq('c.principaluri', $query->createNamedParameter($principalUri))) |
|
1289 | - ->andWhere($query->expr()->eq('co.uid', $query->createNamedParameter($uid))); |
|
1290 | - |
|
1291 | - $stmt = $query->execute(); |
|
1292 | - |
|
1293 | - if ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1294 | - return $row['calendaruri'] . '/' . $row['objecturi']; |
|
1295 | - } |
|
1296 | - |
|
1297 | - return null; |
|
1298 | - } |
|
1299 | - |
|
1300 | - /** |
|
1301 | - * The getChanges method returns all the changes that have happened, since |
|
1302 | - * the specified syncToken in the specified calendar. |
|
1303 | - * |
|
1304 | - * This function should return an array, such as the following: |
|
1305 | - * |
|
1306 | - * [ |
|
1307 | - * 'syncToken' => 'The current synctoken', |
|
1308 | - * 'added' => [ |
|
1309 | - * 'new.txt', |
|
1310 | - * ], |
|
1311 | - * 'modified' => [ |
|
1312 | - * 'modified.txt', |
|
1313 | - * ], |
|
1314 | - * 'deleted' => [ |
|
1315 | - * 'foo.php.bak', |
|
1316 | - * 'old.txt' |
|
1317 | - * ] |
|
1318 | - * ); |
|
1319 | - * |
|
1320 | - * The returned syncToken property should reflect the *current* syncToken |
|
1321 | - * of the calendar, as reported in the {http://sabredav.org/ns}sync-token |
|
1322 | - * property This is * needed here too, to ensure the operation is atomic. |
|
1323 | - * |
|
1324 | - * If the $syncToken argument is specified as null, this is an initial |
|
1325 | - * sync, and all members should be reported. |
|
1326 | - * |
|
1327 | - * The modified property is an array of nodenames that have changed since |
|
1328 | - * the last token. |
|
1329 | - * |
|
1330 | - * The deleted property is an array with nodenames, that have been deleted |
|
1331 | - * from collection. |
|
1332 | - * |
|
1333 | - * The $syncLevel argument is basically the 'depth' of the report. If it's |
|
1334 | - * 1, you only have to report changes that happened only directly in |
|
1335 | - * immediate descendants. If it's 2, it should also include changes from |
|
1336 | - * the nodes below the child collections. (grandchildren) |
|
1337 | - * |
|
1338 | - * The $limit argument allows a client to specify how many results should |
|
1339 | - * be returned at most. If the limit is not specified, it should be treated |
|
1340 | - * as infinite. |
|
1341 | - * |
|
1342 | - * If the limit (infinite or not) is higher than you're willing to return, |
|
1343 | - * you should throw a Sabre\DAV\Exception\TooMuchMatches() exception. |
|
1344 | - * |
|
1345 | - * If the syncToken is expired (due to data cleanup) or unknown, you must |
|
1346 | - * return null. |
|
1347 | - * |
|
1348 | - * The limit is 'suggestive'. You are free to ignore it. |
|
1349 | - * |
|
1350 | - * @param string $calendarId |
|
1351 | - * @param string $syncToken |
|
1352 | - * @param int $syncLevel |
|
1353 | - * @param int $limit |
|
1354 | - * @return array |
|
1355 | - */ |
|
1356 | - function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limit = null) { |
|
1357 | - // Current synctoken |
|
1358 | - $stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
1359 | - $stmt->execute([ $calendarId ]); |
|
1360 | - $currentToken = $stmt->fetchColumn(0); |
|
1361 | - |
|
1362 | - if (is_null($currentToken)) { |
|
1363 | - return null; |
|
1364 | - } |
|
1365 | - |
|
1366 | - $result = [ |
|
1367 | - 'syncToken' => $currentToken, |
|
1368 | - 'added' => [], |
|
1369 | - 'modified' => [], |
|
1370 | - 'deleted' => [], |
|
1371 | - ]; |
|
1372 | - |
|
1373 | - if ($syncToken) { |
|
1374 | - |
|
1375 | - $query = "SELECT `uri`, `operation` FROM `*PREFIX*calendarchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `calendarid` = ? ORDER BY `synctoken`"; |
|
1376 | - if ($limit>0) { |
|
1377 | - $query.= " `LIMIT` " . (int)$limit; |
|
1378 | - } |
|
1379 | - |
|
1380 | - // Fetching all changes |
|
1381 | - $stmt = $this->db->prepare($query); |
|
1382 | - $stmt->execute([$syncToken, $currentToken, $calendarId]); |
|
1383 | - |
|
1384 | - $changes = []; |
|
1385 | - |
|
1386 | - // This loop ensures that any duplicates are overwritten, only the |
|
1387 | - // last change on a node is relevant. |
|
1388 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1389 | - |
|
1390 | - $changes[$row['uri']] = $row['operation']; |
|
1391 | - |
|
1392 | - } |
|
1393 | - |
|
1394 | - foreach($changes as $uri => $operation) { |
|
1395 | - |
|
1396 | - switch($operation) { |
|
1397 | - case 1 : |
|
1398 | - $result['added'][] = $uri; |
|
1399 | - break; |
|
1400 | - case 2 : |
|
1401 | - $result['modified'][] = $uri; |
|
1402 | - break; |
|
1403 | - case 3 : |
|
1404 | - $result['deleted'][] = $uri; |
|
1405 | - break; |
|
1406 | - } |
|
1407 | - |
|
1408 | - } |
|
1409 | - } else { |
|
1410 | - // No synctoken supplied, this is the initial sync. |
|
1411 | - $query = "SELECT `uri` FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ?"; |
|
1412 | - $stmt = $this->db->prepare($query); |
|
1413 | - $stmt->execute([$calendarId]); |
|
1414 | - |
|
1415 | - $result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN); |
|
1416 | - } |
|
1417 | - return $result; |
|
1418 | - |
|
1419 | - } |
|
1420 | - |
|
1421 | - /** |
|
1422 | - * Returns a list of subscriptions for a principal. |
|
1423 | - * |
|
1424 | - * Every subscription is an array with the following keys: |
|
1425 | - * * id, a unique id that will be used by other functions to modify the |
|
1426 | - * subscription. This can be the same as the uri or a database key. |
|
1427 | - * * uri. This is just the 'base uri' or 'filename' of the subscription. |
|
1428 | - * * principaluri. The owner of the subscription. Almost always the same as |
|
1429 | - * principalUri passed to this method. |
|
1430 | - * |
|
1431 | - * Furthermore, all the subscription info must be returned too: |
|
1432 | - * |
|
1433 | - * 1. {DAV:}displayname |
|
1434 | - * 2. {http://apple.com/ns/ical/}refreshrate |
|
1435 | - * 3. {http://calendarserver.org/ns/}subscribed-strip-todos (omit if todos |
|
1436 | - * should not be stripped). |
|
1437 | - * 4. {http://calendarserver.org/ns/}subscribed-strip-alarms (omit if alarms |
|
1438 | - * should not be stripped). |
|
1439 | - * 5. {http://calendarserver.org/ns/}subscribed-strip-attachments (omit if |
|
1440 | - * attachments should not be stripped). |
|
1441 | - * 6. {http://calendarserver.org/ns/}source (Must be a |
|
1442 | - * Sabre\DAV\Property\Href). |
|
1443 | - * 7. {http://apple.com/ns/ical/}calendar-color |
|
1444 | - * 8. {http://apple.com/ns/ical/}calendar-order |
|
1445 | - * 9. {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set |
|
1446 | - * (should just be an instance of |
|
1447 | - * Sabre\CalDAV\Property\SupportedCalendarComponentSet, with a bunch of |
|
1448 | - * default components). |
|
1449 | - * |
|
1450 | - * @param string $principalUri |
|
1451 | - * @return array |
|
1452 | - */ |
|
1453 | - function getSubscriptionsForUser($principalUri) { |
|
1454 | - $fields = array_values($this->subscriptionPropertyMap); |
|
1455 | - $fields[] = 'id'; |
|
1456 | - $fields[] = 'uri'; |
|
1457 | - $fields[] = 'source'; |
|
1458 | - $fields[] = 'principaluri'; |
|
1459 | - $fields[] = 'lastmodified'; |
|
1460 | - |
|
1461 | - $query = $this->db->getQueryBuilder(); |
|
1462 | - $query->select($fields) |
|
1463 | - ->from('calendarsubscriptions') |
|
1464 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1465 | - ->orderBy('calendarorder', 'asc'); |
|
1466 | - $stmt =$query->execute(); |
|
1467 | - |
|
1468 | - $subscriptions = []; |
|
1469 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1470 | - |
|
1471 | - $subscription = [ |
|
1472 | - 'id' => $row['id'], |
|
1473 | - 'uri' => $row['uri'], |
|
1474 | - 'principaluri' => $row['principaluri'], |
|
1475 | - 'source' => $row['source'], |
|
1476 | - 'lastmodified' => $row['lastmodified'], |
|
1477 | - |
|
1478 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO', 'VEVENT']), |
|
1479 | - ]; |
|
1480 | - |
|
1481 | - foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1482 | - if (!is_null($row[$dbName])) { |
|
1483 | - $subscription[$xmlName] = $row[$dbName]; |
|
1484 | - } |
|
1485 | - } |
|
1486 | - |
|
1487 | - $subscriptions[] = $subscription; |
|
1488 | - |
|
1489 | - } |
|
1490 | - |
|
1491 | - return $subscriptions; |
|
1492 | - } |
|
1493 | - |
|
1494 | - /** |
|
1495 | - * Creates a new subscription for a principal. |
|
1496 | - * |
|
1497 | - * If the creation was a success, an id must be returned that can be used to reference |
|
1498 | - * this subscription in other methods, such as updateSubscription. |
|
1499 | - * |
|
1500 | - * @param string $principalUri |
|
1501 | - * @param string $uri |
|
1502 | - * @param array $properties |
|
1503 | - * @return mixed |
|
1504 | - */ |
|
1505 | - function createSubscription($principalUri, $uri, array $properties) { |
|
1506 | - |
|
1507 | - if (!isset($properties['{http://calendarserver.org/ns/}source'])) { |
|
1508 | - throw new Forbidden('The {http://calendarserver.org/ns/}source property is required when creating subscriptions'); |
|
1509 | - } |
|
1510 | - |
|
1511 | - $values = [ |
|
1512 | - 'principaluri' => $principalUri, |
|
1513 | - 'uri' => $uri, |
|
1514 | - 'source' => $properties['{http://calendarserver.org/ns/}source']->getHref(), |
|
1515 | - 'lastmodified' => time(), |
|
1516 | - ]; |
|
1517 | - |
|
1518 | - $propertiesBoolean = ['striptodos', 'stripalarms', 'stripattachments']; |
|
1519 | - |
|
1520 | - foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1521 | - if (array_key_exists($xmlName, $properties)) { |
|
1522 | - $values[$dbName] = $properties[$xmlName]; |
|
1523 | - if (in_array($dbName, $propertiesBoolean)) { |
|
1524 | - $values[$dbName] = true; |
|
1525 | - } |
|
1526 | - } |
|
1527 | - } |
|
1528 | - |
|
1529 | - $valuesToInsert = array(); |
|
1530 | - |
|
1531 | - $query = $this->db->getQueryBuilder(); |
|
1532 | - |
|
1533 | - foreach (array_keys($values) as $name) { |
|
1534 | - $valuesToInsert[$name] = $query->createNamedParameter($values[$name]); |
|
1535 | - } |
|
1536 | - |
|
1537 | - $query->insert('calendarsubscriptions') |
|
1538 | - ->values($valuesToInsert) |
|
1539 | - ->execute(); |
|
1540 | - |
|
1541 | - return $this->db->lastInsertId('*PREFIX*calendarsubscriptions'); |
|
1542 | - } |
|
1543 | - |
|
1544 | - /** |
|
1545 | - * Updates a subscription |
|
1546 | - * |
|
1547 | - * The list of mutations is stored in a Sabre\DAV\PropPatch object. |
|
1548 | - * To do the actual updates, you must tell this object which properties |
|
1549 | - * you're going to process with the handle() method. |
|
1550 | - * |
|
1551 | - * Calling the handle method is like telling the PropPatch object "I |
|
1552 | - * promise I can handle updating this property". |
|
1553 | - * |
|
1554 | - * Read the PropPatch documentation for more info and examples. |
|
1555 | - * |
|
1556 | - * @param mixed $subscriptionId |
|
1557 | - * @param PropPatch $propPatch |
|
1558 | - * @return void |
|
1559 | - */ |
|
1560 | - function updateSubscription($subscriptionId, PropPatch $propPatch) { |
|
1561 | - $supportedProperties = array_keys($this->subscriptionPropertyMap); |
|
1562 | - $supportedProperties[] = '{http://calendarserver.org/ns/}source'; |
|
1563 | - |
|
1564 | - $propPatch->handle($supportedProperties, function($mutations) use ($subscriptionId) { |
|
1565 | - |
|
1566 | - $newValues = []; |
|
1567 | - |
|
1568 | - foreach($mutations as $propertyName=>$propertyValue) { |
|
1569 | - if ($propertyName === '{http://calendarserver.org/ns/}source') { |
|
1570 | - $newValues['source'] = $propertyValue->getHref(); |
|
1571 | - } else { |
|
1572 | - $fieldName = $this->subscriptionPropertyMap[$propertyName]; |
|
1573 | - $newValues[$fieldName] = $propertyValue; |
|
1574 | - } |
|
1575 | - } |
|
1576 | - |
|
1577 | - $query = $this->db->getQueryBuilder(); |
|
1578 | - $query->update('calendarsubscriptions') |
|
1579 | - ->set('lastmodified', $query->createNamedParameter(time())); |
|
1580 | - foreach($newValues as $fieldName=>$value) { |
|
1581 | - $query->set($fieldName, $query->createNamedParameter($value)); |
|
1582 | - } |
|
1583 | - $query->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) |
|
1584 | - ->execute(); |
|
1585 | - |
|
1586 | - return true; |
|
1587 | - |
|
1588 | - }); |
|
1589 | - } |
|
1590 | - |
|
1591 | - /** |
|
1592 | - * Deletes a subscription. |
|
1593 | - * |
|
1594 | - * @param mixed $subscriptionId |
|
1595 | - * @return void |
|
1596 | - */ |
|
1597 | - function deleteSubscription($subscriptionId) { |
|
1598 | - $query = $this->db->getQueryBuilder(); |
|
1599 | - $query->delete('calendarsubscriptions') |
|
1600 | - ->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) |
|
1601 | - ->execute(); |
|
1602 | - } |
|
1603 | - |
|
1604 | - /** |
|
1605 | - * Returns a single scheduling object for the inbox collection. |
|
1606 | - * |
|
1607 | - * The returned array should contain the following elements: |
|
1608 | - * * uri - A unique basename for the object. This will be used to |
|
1609 | - * construct a full uri. |
|
1610 | - * * calendardata - The iCalendar object |
|
1611 | - * * lastmodified - The last modification date. Can be an int for a unix |
|
1612 | - * timestamp, or a PHP DateTime object. |
|
1613 | - * * etag - A unique token that must change if the object changed. |
|
1614 | - * * size - The size of the object, in bytes. |
|
1615 | - * |
|
1616 | - * @param string $principalUri |
|
1617 | - * @param string $objectUri |
|
1618 | - * @return array |
|
1619 | - */ |
|
1620 | - function getSchedulingObject($principalUri, $objectUri) { |
|
1621 | - $query = $this->db->getQueryBuilder(); |
|
1622 | - $stmt = $query->select(['uri', 'calendardata', 'lastmodified', 'etag', 'size']) |
|
1623 | - ->from('schedulingobjects') |
|
1624 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1625 | - ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
1626 | - ->execute(); |
|
1627 | - |
|
1628 | - $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
1629 | - |
|
1630 | - if(!$row) { |
|
1631 | - return null; |
|
1632 | - } |
|
1633 | - |
|
1634 | - return [ |
|
1635 | - 'uri' => $row['uri'], |
|
1636 | - 'calendardata' => $row['calendardata'], |
|
1637 | - 'lastmodified' => $row['lastmodified'], |
|
1638 | - 'etag' => '"' . $row['etag'] . '"', |
|
1639 | - 'size' => (int)$row['size'], |
|
1640 | - ]; |
|
1641 | - } |
|
1642 | - |
|
1643 | - /** |
|
1644 | - * Returns all scheduling objects for the inbox collection. |
|
1645 | - * |
|
1646 | - * These objects should be returned as an array. Every item in the array |
|
1647 | - * should follow the same structure as returned from getSchedulingObject. |
|
1648 | - * |
|
1649 | - * The main difference is that 'calendardata' is optional. |
|
1650 | - * |
|
1651 | - * @param string $principalUri |
|
1652 | - * @return array |
|
1653 | - */ |
|
1654 | - function getSchedulingObjects($principalUri) { |
|
1655 | - $query = $this->db->getQueryBuilder(); |
|
1656 | - $stmt = $query->select(['uri', 'calendardata', 'lastmodified', 'etag', 'size']) |
|
1657 | - ->from('schedulingobjects') |
|
1658 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1659 | - ->execute(); |
|
1660 | - |
|
1661 | - $result = []; |
|
1662 | - foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
1663 | - $result[] = [ |
|
1664 | - 'calendardata' => $row['calendardata'], |
|
1665 | - 'uri' => $row['uri'], |
|
1666 | - 'lastmodified' => $row['lastmodified'], |
|
1667 | - 'etag' => '"' . $row['etag'] . '"', |
|
1668 | - 'size' => (int)$row['size'], |
|
1669 | - ]; |
|
1670 | - } |
|
1671 | - |
|
1672 | - return $result; |
|
1673 | - } |
|
1674 | - |
|
1675 | - /** |
|
1676 | - * Deletes a scheduling object from the inbox collection. |
|
1677 | - * |
|
1678 | - * @param string $principalUri |
|
1679 | - * @param string $objectUri |
|
1680 | - * @return void |
|
1681 | - */ |
|
1682 | - function deleteSchedulingObject($principalUri, $objectUri) { |
|
1683 | - $query = $this->db->getQueryBuilder(); |
|
1684 | - $query->delete('schedulingobjects') |
|
1685 | - ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1686 | - ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
1687 | - ->execute(); |
|
1688 | - } |
|
1689 | - |
|
1690 | - /** |
|
1691 | - * Creates a new scheduling object. This should land in a users' inbox. |
|
1692 | - * |
|
1693 | - * @param string $principalUri |
|
1694 | - * @param string $objectUri |
|
1695 | - * @param string $objectData |
|
1696 | - * @return void |
|
1697 | - */ |
|
1698 | - function createSchedulingObject($principalUri, $objectUri, $objectData) { |
|
1699 | - $query = $this->db->getQueryBuilder(); |
|
1700 | - $query->insert('schedulingobjects') |
|
1701 | - ->values([ |
|
1702 | - 'principaluri' => $query->createNamedParameter($principalUri), |
|
1703 | - 'calendardata' => $query->createNamedParameter($objectData), |
|
1704 | - 'uri' => $query->createNamedParameter($objectUri), |
|
1705 | - 'lastmodified' => $query->createNamedParameter(time()), |
|
1706 | - 'etag' => $query->createNamedParameter(md5($objectData)), |
|
1707 | - 'size' => $query->createNamedParameter(strlen($objectData)) |
|
1708 | - ]) |
|
1709 | - ->execute(); |
|
1710 | - } |
|
1711 | - |
|
1712 | - /** |
|
1713 | - * Adds a change record to the calendarchanges table. |
|
1714 | - * |
|
1715 | - * @param mixed $calendarId |
|
1716 | - * @param string $objectUri |
|
1717 | - * @param int $operation 1 = add, 2 = modify, 3 = delete. |
|
1718 | - * @return void |
|
1719 | - */ |
|
1720 | - protected function addChange($calendarId, $objectUri, $operation) { |
|
1721 | - |
|
1722 | - $stmt = $this->db->prepare('INSERT INTO `*PREFIX*calendarchanges` (`uri`, `synctoken`, `calendarid`, `operation`) SELECT ?, `synctoken`, ?, ? FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
1723 | - $stmt->execute([ |
|
1724 | - $objectUri, |
|
1725 | - $calendarId, |
|
1726 | - $operation, |
|
1727 | - $calendarId |
|
1728 | - ]); |
|
1729 | - $stmt = $this->db->prepare('UPDATE `*PREFIX*calendars` SET `synctoken` = `synctoken` + 1 WHERE `id` = ?'); |
|
1730 | - $stmt->execute([ |
|
1731 | - $calendarId |
|
1732 | - ]); |
|
1733 | - |
|
1734 | - } |
|
1735 | - |
|
1736 | - /** |
|
1737 | - * Parses some information from calendar objects, used for optimized |
|
1738 | - * calendar-queries. |
|
1739 | - * |
|
1740 | - * Returns an array with the following keys: |
|
1741 | - * * etag - An md5 checksum of the object without the quotes. |
|
1742 | - * * size - Size of the object in bytes |
|
1743 | - * * componentType - VEVENT, VTODO or VJOURNAL |
|
1744 | - * * firstOccurence |
|
1745 | - * * lastOccurence |
|
1746 | - * * uid - value of the UID property |
|
1747 | - * |
|
1748 | - * @param string $calendarData |
|
1749 | - * @return array |
|
1750 | - */ |
|
1751 | - public function getDenormalizedData($calendarData) { |
|
1752 | - |
|
1753 | - $vObject = Reader::read($calendarData); |
|
1754 | - $componentType = null; |
|
1755 | - $component = null; |
|
1756 | - $firstOccurrence = null; |
|
1757 | - $lastOccurrence = null; |
|
1758 | - $uid = null; |
|
1759 | - $classification = self::CLASSIFICATION_PUBLIC; |
|
1760 | - foreach($vObject->getComponents() as $component) { |
|
1761 | - if ($component->name!=='VTIMEZONE') { |
|
1762 | - $componentType = $component->name; |
|
1763 | - $uid = (string)$component->UID; |
|
1764 | - break; |
|
1765 | - } |
|
1766 | - } |
|
1767 | - if (!$componentType) { |
|
1768 | - throw new \Sabre\DAV\Exception\BadRequest('Calendar objects must have a VJOURNAL, VEVENT or VTODO component'); |
|
1769 | - } |
|
1770 | - if ($componentType === 'VEVENT' && $component->DTSTART) { |
|
1771 | - $firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp(); |
|
1772 | - // Finding the last occurrence is a bit harder |
|
1773 | - if (!isset($component->RRULE)) { |
|
1774 | - if (isset($component->DTEND)) { |
|
1775 | - $lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp(); |
|
1776 | - } elseif (isset($component->DURATION)) { |
|
1777 | - $endDate = clone $component->DTSTART->getDateTime(); |
|
1778 | - $endDate->add(DateTimeParser::parse($component->DURATION->getValue())); |
|
1779 | - $lastOccurrence = $endDate->getTimeStamp(); |
|
1780 | - } elseif (!$component->DTSTART->hasTime()) { |
|
1781 | - $endDate = clone $component->DTSTART->getDateTime(); |
|
1782 | - $endDate->modify('+1 day'); |
|
1783 | - $lastOccurrence = $endDate->getTimeStamp(); |
|
1784 | - } else { |
|
1785 | - $lastOccurrence = $firstOccurrence; |
|
1786 | - } |
|
1787 | - } else { |
|
1788 | - $it = new EventIterator($vObject, (string)$component->UID); |
|
1789 | - $maxDate = new \DateTime(self::MAX_DATE); |
|
1790 | - if ($it->isInfinite()) { |
|
1791 | - $lastOccurrence = $maxDate->getTimestamp(); |
|
1792 | - } else { |
|
1793 | - $end = $it->getDtEnd(); |
|
1794 | - while($it->valid() && $end < $maxDate) { |
|
1795 | - $end = $it->getDtEnd(); |
|
1796 | - $it->next(); |
|
1797 | - |
|
1798 | - } |
|
1799 | - $lastOccurrence = $end->getTimestamp(); |
|
1800 | - } |
|
1801 | - |
|
1802 | - } |
|
1803 | - } |
|
1804 | - |
|
1805 | - if ($component->CLASS) { |
|
1806 | - $classification = CalDavBackend::CLASSIFICATION_PRIVATE; |
|
1807 | - switch ($component->CLASS->getValue()) { |
|
1808 | - case 'PUBLIC': |
|
1809 | - $classification = CalDavBackend::CLASSIFICATION_PUBLIC; |
|
1810 | - break; |
|
1811 | - case 'CONFIDENTIAL': |
|
1812 | - $classification = CalDavBackend::CLASSIFICATION_CONFIDENTIAL; |
|
1813 | - break; |
|
1814 | - } |
|
1815 | - } |
|
1816 | - return [ |
|
1817 | - 'etag' => md5($calendarData), |
|
1818 | - 'size' => strlen($calendarData), |
|
1819 | - 'componentType' => $componentType, |
|
1820 | - 'firstOccurence' => is_null($firstOccurrence) ? null : max(0, $firstOccurrence), |
|
1821 | - 'lastOccurence' => $lastOccurrence, |
|
1822 | - 'uid' => $uid, |
|
1823 | - 'classification' => $classification |
|
1824 | - ]; |
|
1825 | - |
|
1826 | - } |
|
1827 | - |
|
1828 | - private function readBlob($cardData) { |
|
1829 | - if (is_resource($cardData)) { |
|
1830 | - return stream_get_contents($cardData); |
|
1831 | - } |
|
1832 | - |
|
1833 | - return $cardData; |
|
1834 | - } |
|
1835 | - |
|
1836 | - /** |
|
1837 | - * @param IShareable $shareable |
|
1838 | - * @param array $add |
|
1839 | - * @param array $remove |
|
1840 | - */ |
|
1841 | - public function updateShares($shareable, $add, $remove) { |
|
1842 | - $calendarId = $shareable->getResourceId(); |
|
1843 | - $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateShares', new GenericEvent( |
|
1844 | - '\OCA\DAV\CalDAV\CalDavBackend::updateShares', |
|
1845 | - [ |
|
1846 | - 'calendarId' => $calendarId, |
|
1847 | - 'calendarData' => $this->getCalendarById($calendarId), |
|
1848 | - 'shares' => $this->getShares($calendarId), |
|
1849 | - 'add' => $add, |
|
1850 | - 'remove' => $remove, |
|
1851 | - ])); |
|
1852 | - $this->sharingBackend->updateShares($shareable, $add, $remove); |
|
1853 | - } |
|
1854 | - |
|
1855 | - /** |
|
1856 | - * @param int $resourceId |
|
1857 | - * @return array |
|
1858 | - */ |
|
1859 | - public function getShares($resourceId) { |
|
1860 | - return $this->sharingBackend->getShares($resourceId); |
|
1861 | - } |
|
1862 | - |
|
1863 | - /** |
|
1864 | - * @param boolean $value |
|
1865 | - * @param \OCA\DAV\CalDAV\Calendar $calendar |
|
1866 | - * @return string|null |
|
1867 | - */ |
|
1868 | - public function setPublishStatus($value, $calendar) { |
|
1869 | - $query = $this->db->getQueryBuilder(); |
|
1870 | - if ($value) { |
|
1871 | - $publicUri = $this->random->generate(16, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS); |
|
1872 | - $query->insert('dav_shares') |
|
1873 | - ->values([ |
|
1874 | - 'principaluri' => $query->createNamedParameter($calendar->getPrincipalURI()), |
|
1875 | - 'type' => $query->createNamedParameter('calendar'), |
|
1876 | - 'access' => $query->createNamedParameter(self::ACCESS_PUBLIC), |
|
1877 | - 'resourceid' => $query->createNamedParameter($calendar->getResourceId()), |
|
1878 | - 'publicuri' => $query->createNamedParameter($publicUri) |
|
1879 | - ]); |
|
1880 | - $query->execute(); |
|
1881 | - return $publicUri; |
|
1882 | - } |
|
1883 | - $query->delete('dav_shares') |
|
1884 | - ->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) |
|
1885 | - ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))); |
|
1886 | - $query->execute(); |
|
1887 | - return null; |
|
1888 | - } |
|
1889 | - |
|
1890 | - /** |
|
1891 | - * @param \OCA\DAV\CalDAV\Calendar $calendar |
|
1892 | - * @return mixed |
|
1893 | - */ |
|
1894 | - public function getPublishStatus($calendar) { |
|
1895 | - $query = $this->db->getQueryBuilder(); |
|
1896 | - $result = $query->select('publicuri') |
|
1897 | - ->from('dav_shares') |
|
1898 | - ->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) |
|
1899 | - ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
1900 | - ->execute(); |
|
1901 | - |
|
1902 | - $row = $result->fetch(); |
|
1903 | - $result->closeCursor(); |
|
1904 | - return $row ? reset($row) : false; |
|
1905 | - } |
|
1906 | - |
|
1907 | - /** |
|
1908 | - * @param int $resourceId |
|
1909 | - * @param array $acl |
|
1910 | - * @return array |
|
1911 | - */ |
|
1912 | - public function applyShareAcl($resourceId, $acl) { |
|
1913 | - return $this->sharingBackend->applyShareAcl($resourceId, $acl); |
|
1914 | - } |
|
1915 | - |
|
1916 | - private function convertPrincipal($principalUri, $toV2) { |
|
1917 | - if ($this->principalBackend->getPrincipalPrefix() === 'principals') { |
|
1918 | - list(, $name) = URLUtil::splitPath($principalUri); |
|
1919 | - if ($toV2 === true) { |
|
1920 | - return "principals/users/$name"; |
|
1921 | - } |
|
1922 | - return "principals/$name"; |
|
1923 | - } |
|
1924 | - return $principalUri; |
|
1925 | - } |
|
385 | + /** |
|
386 | + * @return array |
|
387 | + */ |
|
388 | + public function getPublicCalendars() { |
|
389 | + $fields = array_values($this->propertyMap); |
|
390 | + $fields[] = 'a.id'; |
|
391 | + $fields[] = 'a.uri'; |
|
392 | + $fields[] = 'a.synctoken'; |
|
393 | + $fields[] = 'a.components'; |
|
394 | + $fields[] = 'a.principaluri'; |
|
395 | + $fields[] = 'a.transparent'; |
|
396 | + $fields[] = 's.access'; |
|
397 | + $fields[] = 's.publicuri'; |
|
398 | + $calendars = []; |
|
399 | + $query = $this->db->getQueryBuilder(); |
|
400 | + $result = $query->select($fields) |
|
401 | + ->from('dav_shares', 's') |
|
402 | + ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
403 | + ->where($query->expr()->in('s.access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
404 | + ->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar'))) |
|
405 | + ->execute(); |
|
406 | + |
|
407 | + while($row = $result->fetch()) { |
|
408 | + list(, $name) = URLUtil::splitPath($row['principaluri']); |
|
409 | + $row['displayname'] = $row['displayname'] . "($name)"; |
|
410 | + $components = []; |
|
411 | + if ($row['components']) { |
|
412 | + $components = explode(',',$row['components']); |
|
413 | + } |
|
414 | + $calendar = [ |
|
415 | + 'id' => $row['id'], |
|
416 | + 'uri' => $row['publicuri'], |
|
417 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
418 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
419 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
420 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
421 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
422 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], $this->legacyEndpoint), |
|
423 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
424 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
425 | + ]; |
|
426 | + |
|
427 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
428 | + $calendar[$xmlName] = $row[$dbName]; |
|
429 | + } |
|
430 | + |
|
431 | + if (!isset($calendars[$calendar['id']])) { |
|
432 | + $calendars[$calendar['id']] = $calendar; |
|
433 | + } |
|
434 | + } |
|
435 | + $result->closeCursor(); |
|
436 | + |
|
437 | + return array_values($calendars); |
|
438 | + } |
|
439 | + |
|
440 | + /** |
|
441 | + * @param string $uri |
|
442 | + * @return array |
|
443 | + * @throws NotFound |
|
444 | + */ |
|
445 | + public function getPublicCalendar($uri) { |
|
446 | + $fields = array_values($this->propertyMap); |
|
447 | + $fields[] = 'a.id'; |
|
448 | + $fields[] = 'a.uri'; |
|
449 | + $fields[] = 'a.synctoken'; |
|
450 | + $fields[] = 'a.components'; |
|
451 | + $fields[] = 'a.principaluri'; |
|
452 | + $fields[] = 'a.transparent'; |
|
453 | + $fields[] = 's.access'; |
|
454 | + $fields[] = 's.publicuri'; |
|
455 | + $query = $this->db->getQueryBuilder(); |
|
456 | + $result = $query->select($fields) |
|
457 | + ->from('dav_shares', 's') |
|
458 | + ->join('s', 'calendars', 'a', $query->expr()->eq('s.resourceid', 'a.id')) |
|
459 | + ->where($query->expr()->in('s.access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
460 | + ->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar'))) |
|
461 | + ->andWhere($query->expr()->eq('s.publicuri', $query->createNamedParameter($uri))) |
|
462 | + ->execute(); |
|
463 | + |
|
464 | + $row = $result->fetch(\PDO::FETCH_ASSOC); |
|
465 | + |
|
466 | + $result->closeCursor(); |
|
467 | + |
|
468 | + if ($row === false) { |
|
469 | + throw new NotFound('Node with name \'' . $uri . '\' could not be found'); |
|
470 | + } |
|
471 | + |
|
472 | + list(, $name) = URLUtil::splitPath($row['principaluri']); |
|
473 | + $row['displayname'] = $row['displayname'] . ' ' . "($name)"; |
|
474 | + $components = []; |
|
475 | + if ($row['components']) { |
|
476 | + $components = explode(',',$row['components']); |
|
477 | + } |
|
478 | + $calendar = [ |
|
479 | + 'id' => $row['id'], |
|
480 | + 'uri' => $row['publicuri'], |
|
481 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
482 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
483 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
484 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
485 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
486 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
487 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
488 | + '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
489 | + ]; |
|
490 | + |
|
491 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
492 | + $calendar[$xmlName] = $row[$dbName]; |
|
493 | + } |
|
494 | + |
|
495 | + return $calendar; |
|
496 | + |
|
497 | + } |
|
498 | + |
|
499 | + /** |
|
500 | + * @param string $principal |
|
501 | + * @param string $uri |
|
502 | + * @return array|null |
|
503 | + */ |
|
504 | + public function getCalendarByUri($principal, $uri) { |
|
505 | + $fields = array_values($this->propertyMap); |
|
506 | + $fields[] = 'id'; |
|
507 | + $fields[] = 'uri'; |
|
508 | + $fields[] = 'synctoken'; |
|
509 | + $fields[] = 'components'; |
|
510 | + $fields[] = 'principaluri'; |
|
511 | + $fields[] = 'transparent'; |
|
512 | + |
|
513 | + // Making fields a comma-delimited list |
|
514 | + $query = $this->db->getQueryBuilder(); |
|
515 | + $query->select($fields)->from('calendars') |
|
516 | + ->where($query->expr()->eq('uri', $query->createNamedParameter($uri))) |
|
517 | + ->andWhere($query->expr()->eq('principaluri', $query->createNamedParameter($principal))) |
|
518 | + ->setMaxResults(1); |
|
519 | + $stmt = $query->execute(); |
|
520 | + |
|
521 | + $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
522 | + $stmt->closeCursor(); |
|
523 | + if ($row === false) { |
|
524 | + return null; |
|
525 | + } |
|
526 | + |
|
527 | + $components = []; |
|
528 | + if ($row['components']) { |
|
529 | + $components = explode(',',$row['components']); |
|
530 | + } |
|
531 | + |
|
532 | + $calendar = [ |
|
533 | + 'id' => $row['id'], |
|
534 | + 'uri' => $row['uri'], |
|
535 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
536 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
537 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
538 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
539 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
540 | + ]; |
|
541 | + |
|
542 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
543 | + $calendar[$xmlName] = $row[$dbName]; |
|
544 | + } |
|
545 | + |
|
546 | + return $calendar; |
|
547 | + } |
|
548 | + |
|
549 | + public function getCalendarById($calendarId) { |
|
550 | + $fields = array_values($this->propertyMap); |
|
551 | + $fields[] = 'id'; |
|
552 | + $fields[] = 'uri'; |
|
553 | + $fields[] = 'synctoken'; |
|
554 | + $fields[] = 'components'; |
|
555 | + $fields[] = 'principaluri'; |
|
556 | + $fields[] = 'transparent'; |
|
557 | + |
|
558 | + // Making fields a comma-delimited list |
|
559 | + $query = $this->db->getQueryBuilder(); |
|
560 | + $query->select($fields)->from('calendars') |
|
561 | + ->where($query->expr()->eq('id', $query->createNamedParameter($calendarId))) |
|
562 | + ->setMaxResults(1); |
|
563 | + $stmt = $query->execute(); |
|
564 | + |
|
565 | + $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
566 | + $stmt->closeCursor(); |
|
567 | + if ($row === false) { |
|
568 | + return null; |
|
569 | + } |
|
570 | + |
|
571 | + $components = []; |
|
572 | + if ($row['components']) { |
|
573 | + $components = explode(',',$row['components']); |
|
574 | + } |
|
575 | + |
|
576 | + $calendar = [ |
|
577 | + 'id' => $row['id'], |
|
578 | + 'uri' => $row['uri'], |
|
579 | + 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
580 | + '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
581 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
582 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
583 | + '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
584 | + ]; |
|
585 | + |
|
586 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
587 | + $calendar[$xmlName] = $row[$dbName]; |
|
588 | + } |
|
589 | + |
|
590 | + return $calendar; |
|
591 | + } |
|
592 | + |
|
593 | + /** |
|
594 | + * Creates a new calendar for a principal. |
|
595 | + * |
|
596 | + * If the creation was a success, an id must be returned that can be used to reference |
|
597 | + * this calendar in other methods, such as updateCalendar. |
|
598 | + * |
|
599 | + * @param string $principalUri |
|
600 | + * @param string $calendarUri |
|
601 | + * @param array $properties |
|
602 | + * @return int |
|
603 | + */ |
|
604 | + function createCalendar($principalUri, $calendarUri, array $properties) { |
|
605 | + $values = [ |
|
606 | + 'principaluri' => $this->convertPrincipal($principalUri, true), |
|
607 | + 'uri' => $calendarUri, |
|
608 | + 'synctoken' => 1, |
|
609 | + 'transparent' => 0, |
|
610 | + 'components' => 'VEVENT,VTODO', |
|
611 | + 'displayname' => $calendarUri |
|
612 | + ]; |
|
613 | + |
|
614 | + // Default value |
|
615 | + $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set'; |
|
616 | + if (isset($properties[$sccs])) { |
|
617 | + if (!($properties[$sccs] instanceof SupportedCalendarComponentSet)) { |
|
618 | + throw new DAV\Exception('The ' . $sccs . ' property must be of type: \Sabre\CalDAV\Property\SupportedCalendarComponentSet'); |
|
619 | + } |
|
620 | + $values['components'] = implode(',',$properties[$sccs]->getValue()); |
|
621 | + } |
|
622 | + $transp = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
623 | + if (isset($properties[$transp])) { |
|
624 | + $values['transparent'] = (int) ($properties[$transp]->getValue() === 'transparent'); |
|
625 | + } |
|
626 | + |
|
627 | + foreach($this->propertyMap as $xmlName=>$dbName) { |
|
628 | + if (isset($properties[$xmlName])) { |
|
629 | + $values[$dbName] = $properties[$xmlName]; |
|
630 | + } |
|
631 | + } |
|
632 | + |
|
633 | + $query = $this->db->getQueryBuilder(); |
|
634 | + $query->insert('calendars'); |
|
635 | + foreach($values as $column => $value) { |
|
636 | + $query->setValue($column, $query->createNamedParameter($value)); |
|
637 | + } |
|
638 | + $query->execute(); |
|
639 | + $calendarId = $query->getLastInsertId(); |
|
640 | + |
|
641 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', new GenericEvent( |
|
642 | + '\OCA\DAV\CalDAV\CalDavBackend::createCalendar', |
|
643 | + [ |
|
644 | + 'calendarId' => $calendarId, |
|
645 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
646 | + ])); |
|
647 | + |
|
648 | + return $calendarId; |
|
649 | + } |
|
650 | + |
|
651 | + /** |
|
652 | + * Updates properties for a calendar. |
|
653 | + * |
|
654 | + * The list of mutations is stored in a Sabre\DAV\PropPatch object. |
|
655 | + * To do the actual updates, you must tell this object which properties |
|
656 | + * you're going to process with the handle() method. |
|
657 | + * |
|
658 | + * Calling the handle method is like telling the PropPatch object "I |
|
659 | + * promise I can handle updating this property". |
|
660 | + * |
|
661 | + * Read the PropPatch documentation for more info and examples. |
|
662 | + * |
|
663 | + * @param PropPatch $propPatch |
|
664 | + * @return void |
|
665 | + */ |
|
666 | + function updateCalendar($calendarId, PropPatch $propPatch) { |
|
667 | + $supportedProperties = array_keys($this->propertyMap); |
|
668 | + $supportedProperties[] = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
669 | + |
|
670 | + $propPatch->handle($supportedProperties, function($mutations) use ($calendarId) { |
|
671 | + $newValues = []; |
|
672 | + foreach ($mutations as $propertyName => $propertyValue) { |
|
673 | + |
|
674 | + switch ($propertyName) { |
|
675 | + case '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' : |
|
676 | + $fieldName = 'transparent'; |
|
677 | + $newValues[$fieldName] = (int) ($propertyValue->getValue() === 'transparent'); |
|
678 | + break; |
|
679 | + default : |
|
680 | + $fieldName = $this->propertyMap[$propertyName]; |
|
681 | + $newValues[$fieldName] = $propertyValue; |
|
682 | + break; |
|
683 | + } |
|
684 | + |
|
685 | + } |
|
686 | + $query = $this->db->getQueryBuilder(); |
|
687 | + $query->update('calendars'); |
|
688 | + foreach ($newValues as $fieldName => $value) { |
|
689 | + $query->set($fieldName, $query->createNamedParameter($value)); |
|
690 | + } |
|
691 | + $query->where($query->expr()->eq('id', $query->createNamedParameter($calendarId))); |
|
692 | + $query->execute(); |
|
693 | + |
|
694 | + $this->addChange($calendarId, "", 2); |
|
695 | + |
|
696 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', new GenericEvent( |
|
697 | + '\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', |
|
698 | + [ |
|
699 | + 'calendarId' => $calendarId, |
|
700 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
701 | + 'shares' => $this->getShares($calendarId), |
|
702 | + 'propertyMutations' => $mutations, |
|
703 | + ])); |
|
704 | + |
|
705 | + return true; |
|
706 | + }); |
|
707 | + } |
|
708 | + |
|
709 | + /** |
|
710 | + * Delete a calendar and all it's objects |
|
711 | + * |
|
712 | + * @param mixed $calendarId |
|
713 | + * @return void |
|
714 | + */ |
|
715 | + function deleteCalendar($calendarId) { |
|
716 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', new GenericEvent( |
|
717 | + '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', |
|
718 | + [ |
|
719 | + 'calendarId' => $calendarId, |
|
720 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
721 | + 'shares' => $this->getShares($calendarId), |
|
722 | + ])); |
|
723 | + |
|
724 | + $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ?'); |
|
725 | + $stmt->execute([$calendarId]); |
|
726 | + |
|
727 | + $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
728 | + $stmt->execute([$calendarId]); |
|
729 | + |
|
730 | + $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarchanges` WHERE `calendarid` = ?'); |
|
731 | + $stmt->execute([$calendarId]); |
|
732 | + |
|
733 | + $this->sharingBackend->deleteAllShares($calendarId); |
|
734 | + } |
|
735 | + |
|
736 | + /** |
|
737 | + * Delete all of an user's shares |
|
738 | + * |
|
739 | + * @param string $principaluri |
|
740 | + * @return void |
|
741 | + */ |
|
742 | + function deleteAllSharesByUser($principaluri) { |
|
743 | + $this->sharingBackend->deleteAllSharesByUser($principaluri); |
|
744 | + } |
|
745 | + |
|
746 | + /** |
|
747 | + * Returns all calendar objects within a calendar. |
|
748 | + * |
|
749 | + * Every item contains an array with the following keys: |
|
750 | + * * calendardata - The iCalendar-compatible calendar data |
|
751 | + * * uri - a unique key which will be used to construct the uri. This can |
|
752 | + * be any arbitrary string, but making sure it ends with '.ics' is a |
|
753 | + * good idea. This is only the basename, or filename, not the full |
|
754 | + * path. |
|
755 | + * * lastmodified - a timestamp of the last modification time |
|
756 | + * * etag - An arbitrary string, surrounded by double-quotes. (e.g.: |
|
757 | + * '"abcdef"') |
|
758 | + * * size - The size of the calendar objects, in bytes. |
|
759 | + * * component - optional, a string containing the type of object, such |
|
760 | + * as 'vevent' or 'vtodo'. If specified, this will be used to populate |
|
761 | + * the Content-Type header. |
|
762 | + * |
|
763 | + * Note that the etag is optional, but it's highly encouraged to return for |
|
764 | + * speed reasons. |
|
765 | + * |
|
766 | + * The calendardata is also optional. If it's not returned |
|
767 | + * 'getCalendarObject' will be called later, which *is* expected to return |
|
768 | + * calendardata. |
|
769 | + * |
|
770 | + * If neither etag or size are specified, the calendardata will be |
|
771 | + * used/fetched to determine these numbers. If both are specified the |
|
772 | + * amount of times this is needed is reduced by a great degree. |
|
773 | + * |
|
774 | + * @param mixed $calendarId |
|
775 | + * @return array |
|
776 | + */ |
|
777 | + function getCalendarObjects($calendarId) { |
|
778 | + $query = $this->db->getQueryBuilder(); |
|
779 | + $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'componenttype', 'classification']) |
|
780 | + ->from('calendarobjects') |
|
781 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
782 | + $stmt = $query->execute(); |
|
783 | + |
|
784 | + $result = []; |
|
785 | + foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
786 | + $result[] = [ |
|
787 | + 'id' => $row['id'], |
|
788 | + 'uri' => $row['uri'], |
|
789 | + 'lastmodified' => $row['lastmodified'], |
|
790 | + 'etag' => '"' . $row['etag'] . '"', |
|
791 | + 'calendarid' => $row['calendarid'], |
|
792 | + 'size' => (int)$row['size'], |
|
793 | + 'component' => strtolower($row['componenttype']), |
|
794 | + 'classification'=> (int)$row['classification'] |
|
795 | + ]; |
|
796 | + } |
|
797 | + |
|
798 | + return $result; |
|
799 | + } |
|
800 | + |
|
801 | + /** |
|
802 | + * Returns information from a single calendar object, based on it's object |
|
803 | + * uri. |
|
804 | + * |
|
805 | + * The object uri is only the basename, or filename and not a full path. |
|
806 | + * |
|
807 | + * The returned array must have the same keys as getCalendarObjects. The |
|
808 | + * 'calendardata' object is required here though, while it's not required |
|
809 | + * for getCalendarObjects. |
|
810 | + * |
|
811 | + * This method must return null if the object did not exist. |
|
812 | + * |
|
813 | + * @param mixed $calendarId |
|
814 | + * @param string $objectUri |
|
815 | + * @return array|null |
|
816 | + */ |
|
817 | + function getCalendarObject($calendarId, $objectUri) { |
|
818 | + |
|
819 | + $query = $this->db->getQueryBuilder(); |
|
820 | + $query->select(['id', 'uri', 'lastmodified', 'etag', 'calendarid', 'size', 'calendardata', 'componenttype', 'classification']) |
|
821 | + ->from('calendarobjects') |
|
822 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
823 | + ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))); |
|
824 | + $stmt = $query->execute(); |
|
825 | + $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
826 | + |
|
827 | + if(!$row) return null; |
|
828 | + |
|
829 | + return [ |
|
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 | + 'calendardata' => $this->readBlob($row['calendardata']), |
|
837 | + 'component' => strtolower($row['componenttype']), |
|
838 | + 'classification'=> (int)$row['classification'] |
|
839 | + ]; |
|
840 | + } |
|
841 | + |
|
842 | + /** |
|
843 | + * Returns a list of calendar objects. |
|
844 | + * |
|
845 | + * This method should work identical to getCalendarObject, but instead |
|
846 | + * return all the calendar objects in the list as an array. |
|
847 | + * |
|
848 | + * If the backend supports this, it may allow for some speed-ups. |
|
849 | + * |
|
850 | + * @param mixed $calendarId |
|
851 | + * @param string[] $uris |
|
852 | + * @return array |
|
853 | + */ |
|
854 | + function getMultipleCalendarObjects($calendarId, array $uris) { |
|
855 | + if (empty($uris)) { |
|
856 | + return []; |
|
857 | + } |
|
858 | + |
|
859 | + $chunks = array_chunk($uris, 100); |
|
860 | + $objects = []; |
|
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()->in('uri', $query->createParameter('uri'))); |
|
867 | + |
|
868 | + foreach ($chunks as $uris) { |
|
869 | + $query->setParameter('uri', $uris, IQueryBuilder::PARAM_STR_ARRAY); |
|
870 | + $result = $query->execute(); |
|
871 | + |
|
872 | + while ($row = $result->fetch()) { |
|
873 | + $objects[] = [ |
|
874 | + 'id' => $row['id'], |
|
875 | + 'uri' => $row['uri'], |
|
876 | + 'lastmodified' => $row['lastmodified'], |
|
877 | + 'etag' => '"' . $row['etag'] . '"', |
|
878 | + 'calendarid' => $row['calendarid'], |
|
879 | + 'size' => (int)$row['size'], |
|
880 | + 'calendardata' => $this->readBlob($row['calendardata']), |
|
881 | + 'component' => strtolower($row['componenttype']), |
|
882 | + 'classification' => (int)$row['classification'] |
|
883 | + ]; |
|
884 | + } |
|
885 | + $result->closeCursor(); |
|
886 | + } |
|
887 | + return $objects; |
|
888 | + } |
|
889 | + |
|
890 | + /** |
|
891 | + * Creates a new calendar object. |
|
892 | + * |
|
893 | + * The object uri is only the basename, or filename and not a full path. |
|
894 | + * |
|
895 | + * It is possible return an etag from this function, which will be used in |
|
896 | + * the response to this PUT request. Note that the ETag must be surrounded |
|
897 | + * by double-quotes. |
|
898 | + * |
|
899 | + * However, you should only really return this ETag if you don't mangle the |
|
900 | + * calendar-data. If the result of a subsequent GET to this object is not |
|
901 | + * the exact same as this request body, you should omit the ETag. |
|
902 | + * |
|
903 | + * @param mixed $calendarId |
|
904 | + * @param string $objectUri |
|
905 | + * @param string $calendarData |
|
906 | + * @return string |
|
907 | + */ |
|
908 | + function createCalendarObject($calendarId, $objectUri, $calendarData) { |
|
909 | + $extraData = $this->getDenormalizedData($calendarData); |
|
910 | + |
|
911 | + $query = $this->db->getQueryBuilder(); |
|
912 | + $query->insert('calendarobjects') |
|
913 | + ->values([ |
|
914 | + 'calendarid' => $query->createNamedParameter($calendarId), |
|
915 | + 'uri' => $query->createNamedParameter($objectUri), |
|
916 | + 'calendardata' => $query->createNamedParameter($calendarData, IQueryBuilder::PARAM_LOB), |
|
917 | + 'lastmodified' => $query->createNamedParameter(time()), |
|
918 | + 'etag' => $query->createNamedParameter($extraData['etag']), |
|
919 | + 'size' => $query->createNamedParameter($extraData['size']), |
|
920 | + 'componenttype' => $query->createNamedParameter($extraData['componentType']), |
|
921 | + 'firstoccurence' => $query->createNamedParameter($extraData['firstOccurence']), |
|
922 | + 'lastoccurence' => $query->createNamedParameter($extraData['lastOccurence']), |
|
923 | + 'classification' => $query->createNamedParameter($extraData['classification']), |
|
924 | + 'uid' => $query->createNamedParameter($extraData['uid']), |
|
925 | + ]) |
|
926 | + ->execute(); |
|
927 | + |
|
928 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', new GenericEvent( |
|
929 | + '\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', |
|
930 | + [ |
|
931 | + 'calendarId' => $calendarId, |
|
932 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
933 | + 'shares' => $this->getShares($calendarId), |
|
934 | + 'objectData' => $this->getCalendarObject($calendarId, $objectUri), |
|
935 | + ] |
|
936 | + )); |
|
937 | + $this->addChange($calendarId, $objectUri, 1); |
|
938 | + |
|
939 | + return '"' . $extraData['etag'] . '"'; |
|
940 | + } |
|
941 | + |
|
942 | + /** |
|
943 | + * Updates an existing calendarobject, based on it's uri. |
|
944 | + * |
|
945 | + * The object uri is only the basename, or filename and not a full path. |
|
946 | + * |
|
947 | + * It is possible return an etag from this function, which will be used in |
|
948 | + * the response to this PUT request. Note that the ETag must be surrounded |
|
949 | + * by double-quotes. |
|
950 | + * |
|
951 | + * However, you should only really return this ETag if you don't mangle the |
|
952 | + * calendar-data. If the result of a subsequent GET to this object is not |
|
953 | + * the exact same as this request body, you should omit the ETag. |
|
954 | + * |
|
955 | + * @param mixed $calendarId |
|
956 | + * @param string $objectUri |
|
957 | + * @param string $calendarData |
|
958 | + * @return string |
|
959 | + */ |
|
960 | + function updateCalendarObject($calendarId, $objectUri, $calendarData) { |
|
961 | + $extraData = $this->getDenormalizedData($calendarData); |
|
962 | + |
|
963 | + $query = $this->db->getQueryBuilder(); |
|
964 | + $query->update('calendarobjects') |
|
965 | + ->set('calendardata', $query->createNamedParameter($calendarData, IQueryBuilder::PARAM_LOB)) |
|
966 | + ->set('lastmodified', $query->createNamedParameter(time())) |
|
967 | + ->set('etag', $query->createNamedParameter($extraData['etag'])) |
|
968 | + ->set('size', $query->createNamedParameter($extraData['size'])) |
|
969 | + ->set('componenttype', $query->createNamedParameter($extraData['componentType'])) |
|
970 | + ->set('firstoccurence', $query->createNamedParameter($extraData['firstOccurence'])) |
|
971 | + ->set('lastoccurence', $query->createNamedParameter($extraData['lastOccurence'])) |
|
972 | + ->set('classification', $query->createNamedParameter($extraData['classification'])) |
|
973 | + ->set('uid', $query->createNamedParameter($extraData['uid'])) |
|
974 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))) |
|
975 | + ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
976 | + ->execute(); |
|
977 | + |
|
978 | + $data = $this->getCalendarObject($calendarId, $objectUri); |
|
979 | + if (is_array($data)) { |
|
980 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', new GenericEvent( |
|
981 | + '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', |
|
982 | + [ |
|
983 | + 'calendarId' => $calendarId, |
|
984 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
985 | + 'shares' => $this->getShares($calendarId), |
|
986 | + 'objectData' => $data, |
|
987 | + ] |
|
988 | + )); |
|
989 | + } |
|
990 | + $this->addChange($calendarId, $objectUri, 2); |
|
991 | + |
|
992 | + return '"' . $extraData['etag'] . '"'; |
|
993 | + } |
|
994 | + |
|
995 | + /** |
|
996 | + * @param int $calendarObjectId |
|
997 | + * @param int $classification |
|
998 | + */ |
|
999 | + public function setClassification($calendarObjectId, $classification) { |
|
1000 | + if (!in_array($classification, [ |
|
1001 | + self::CLASSIFICATION_PUBLIC, self::CLASSIFICATION_PRIVATE, self::CLASSIFICATION_CONFIDENTIAL |
|
1002 | + ])) { |
|
1003 | + throw new \InvalidArgumentException(); |
|
1004 | + } |
|
1005 | + $query = $this->db->getQueryBuilder(); |
|
1006 | + $query->update('calendarobjects') |
|
1007 | + ->set('classification', $query->createNamedParameter($classification)) |
|
1008 | + ->where($query->expr()->eq('id', $query->createNamedParameter($calendarObjectId))) |
|
1009 | + ->execute(); |
|
1010 | + } |
|
1011 | + |
|
1012 | + /** |
|
1013 | + * Deletes an existing calendar object. |
|
1014 | + * |
|
1015 | + * The object uri is only the basename, or filename and not a full path. |
|
1016 | + * |
|
1017 | + * @param mixed $calendarId |
|
1018 | + * @param string $objectUri |
|
1019 | + * @return void |
|
1020 | + */ |
|
1021 | + function deleteCalendarObject($calendarId, $objectUri) { |
|
1022 | + $data = $this->getCalendarObject($calendarId, $objectUri); |
|
1023 | + if (is_array($data)) { |
|
1024 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', new GenericEvent( |
|
1025 | + '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', |
|
1026 | + [ |
|
1027 | + 'calendarId' => $calendarId, |
|
1028 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
1029 | + 'shares' => $this->getShares($calendarId), |
|
1030 | + 'objectData' => $data, |
|
1031 | + ] |
|
1032 | + )); |
|
1033 | + } |
|
1034 | + |
|
1035 | + $stmt = $this->db->prepare('DELETE FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ? AND `uri` = ?'); |
|
1036 | + $stmt->execute([$calendarId, $objectUri]); |
|
1037 | + |
|
1038 | + $this->addChange($calendarId, $objectUri, 3); |
|
1039 | + } |
|
1040 | + |
|
1041 | + /** |
|
1042 | + * Performs a calendar-query on the contents of this calendar. |
|
1043 | + * |
|
1044 | + * The calendar-query is defined in RFC4791 : CalDAV. Using the |
|
1045 | + * calendar-query it is possible for a client to request a specific set of |
|
1046 | + * object, based on contents of iCalendar properties, date-ranges and |
|
1047 | + * iCalendar component types (VTODO, VEVENT). |
|
1048 | + * |
|
1049 | + * This method should just return a list of (relative) urls that match this |
|
1050 | + * query. |
|
1051 | + * |
|
1052 | + * The list of filters are specified as an array. The exact array is |
|
1053 | + * documented by Sabre\CalDAV\CalendarQueryParser. |
|
1054 | + * |
|
1055 | + * Note that it is extremely likely that getCalendarObject for every path |
|
1056 | + * returned from this method will be called almost immediately after. You |
|
1057 | + * may want to anticipate this to speed up these requests. |
|
1058 | + * |
|
1059 | + * This method provides a default implementation, which parses *all* the |
|
1060 | + * iCalendar objects in the specified calendar. |
|
1061 | + * |
|
1062 | + * This default may well be good enough for personal use, and calendars |
|
1063 | + * that aren't very large. But if you anticipate high usage, big calendars |
|
1064 | + * or high loads, you are strongly advised to optimize certain paths. |
|
1065 | + * |
|
1066 | + * The best way to do so is override this method and to optimize |
|
1067 | + * specifically for 'common filters'. |
|
1068 | + * |
|
1069 | + * Requests that are extremely common are: |
|
1070 | + * * requests for just VEVENTS |
|
1071 | + * * requests for just VTODO |
|
1072 | + * * requests with a time-range-filter on either VEVENT or VTODO. |
|
1073 | + * |
|
1074 | + * ..and combinations of these requests. It may not be worth it to try to |
|
1075 | + * handle every possible situation and just rely on the (relatively |
|
1076 | + * easy to use) CalendarQueryValidator to handle the rest. |
|
1077 | + * |
|
1078 | + * Note that especially time-range-filters may be difficult to parse. A |
|
1079 | + * time-range filter specified on a VEVENT must for instance also handle |
|
1080 | + * recurrence rules correctly. |
|
1081 | + * A good example of how to interprete all these filters can also simply |
|
1082 | + * be found in Sabre\CalDAV\CalendarQueryFilter. This class is as correct |
|
1083 | + * as possible, so it gives you a good idea on what type of stuff you need |
|
1084 | + * to think of. |
|
1085 | + * |
|
1086 | + * @param mixed $calendarId |
|
1087 | + * @param array $filters |
|
1088 | + * @return array |
|
1089 | + */ |
|
1090 | + function calendarQuery($calendarId, array $filters) { |
|
1091 | + $componentType = null; |
|
1092 | + $requirePostFilter = true; |
|
1093 | + $timeRange = null; |
|
1094 | + |
|
1095 | + // if no filters were specified, we don't need to filter after a query |
|
1096 | + if (!$filters['prop-filters'] && !$filters['comp-filters']) { |
|
1097 | + $requirePostFilter = false; |
|
1098 | + } |
|
1099 | + |
|
1100 | + // Figuring out if there's a component filter |
|
1101 | + if (count($filters['comp-filters']) > 0 && !$filters['comp-filters'][0]['is-not-defined']) { |
|
1102 | + $componentType = $filters['comp-filters'][0]['name']; |
|
1103 | + |
|
1104 | + // Checking if we need post-filters |
|
1105 | + if (!$filters['prop-filters'] && !$filters['comp-filters'][0]['comp-filters'] && !$filters['comp-filters'][0]['time-range'] && !$filters['comp-filters'][0]['prop-filters']) { |
|
1106 | + $requirePostFilter = false; |
|
1107 | + } |
|
1108 | + // There was a time-range filter |
|
1109 | + if ($componentType == 'VEVENT' && isset($filters['comp-filters'][0]['time-range'])) { |
|
1110 | + $timeRange = $filters['comp-filters'][0]['time-range']; |
|
1111 | + |
|
1112 | + // If start time OR the end time is not specified, we can do a |
|
1113 | + // 100% accurate mysql query. |
|
1114 | + if (!$filters['prop-filters'] && !$filters['comp-filters'][0]['comp-filters'] && !$filters['comp-filters'][0]['prop-filters'] && (!$timeRange['start'] || !$timeRange['end'])) { |
|
1115 | + $requirePostFilter = false; |
|
1116 | + } |
|
1117 | + } |
|
1118 | + |
|
1119 | + } |
|
1120 | + $columns = ['uri']; |
|
1121 | + if ($requirePostFilter) { |
|
1122 | + $columns = ['uri', 'calendardata']; |
|
1123 | + } |
|
1124 | + $query = $this->db->getQueryBuilder(); |
|
1125 | + $query->select($columns) |
|
1126 | + ->from('calendarobjects') |
|
1127 | + ->where($query->expr()->eq('calendarid', $query->createNamedParameter($calendarId))); |
|
1128 | + |
|
1129 | + if ($componentType) { |
|
1130 | + $query->andWhere($query->expr()->eq('componenttype', $query->createNamedParameter($componentType))); |
|
1131 | + } |
|
1132 | + |
|
1133 | + if ($timeRange && $timeRange['start']) { |
|
1134 | + $query->andWhere($query->expr()->gt('lastoccurence', $query->createNamedParameter($timeRange['start']->getTimeStamp()))); |
|
1135 | + } |
|
1136 | + if ($timeRange && $timeRange['end']) { |
|
1137 | + $query->andWhere($query->expr()->lt('firstoccurence', $query->createNamedParameter($timeRange['end']->getTimeStamp()))); |
|
1138 | + } |
|
1139 | + |
|
1140 | + $stmt = $query->execute(); |
|
1141 | + |
|
1142 | + $result = []; |
|
1143 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1144 | + if ($requirePostFilter) { |
|
1145 | + if (!$this->validateFilterForObject($row, $filters)) { |
|
1146 | + continue; |
|
1147 | + } |
|
1148 | + } |
|
1149 | + $result[] = $row['uri']; |
|
1150 | + } |
|
1151 | + |
|
1152 | + return $result; |
|
1153 | + } |
|
1154 | + |
|
1155 | + /** |
|
1156 | + * custom Nextcloud search extension for CalDAV |
|
1157 | + * |
|
1158 | + * @param string $principalUri |
|
1159 | + * @param array $filters |
|
1160 | + * @param integer|null $limit |
|
1161 | + * @param integer|null $offset |
|
1162 | + * @return array |
|
1163 | + */ |
|
1164 | + public function calendarSearch($principalUri, array $filters, $limit=null, $offset=null) { |
|
1165 | + $calendars = $this->getCalendarsForUser($principalUri); |
|
1166 | + $ownCalendars = []; |
|
1167 | + $sharedCalendars = []; |
|
1168 | + |
|
1169 | + $uriMapper = []; |
|
1170 | + |
|
1171 | + foreach($calendars as $calendar) { |
|
1172 | + if ($calendar['{http://owncloud.org/ns}owner-principal'] === $principalUri) { |
|
1173 | + $ownCalendars[] = $calendar['id']; |
|
1174 | + } else { |
|
1175 | + $sharedCalendars[] = $calendar['id']; |
|
1176 | + } |
|
1177 | + $uriMapper[$calendar['id']] = $calendar['uri']; |
|
1178 | + } |
|
1179 | + if (count($ownCalendars) === 0 && count($sharedCalendars) === 0) { |
|
1180 | + return []; |
|
1181 | + } |
|
1182 | + |
|
1183 | + $query = $this->db->getQueryBuilder(); |
|
1184 | + |
|
1185 | + // Calendar id expressions |
|
1186 | + $calendarExpressions = []; |
|
1187 | + foreach($ownCalendars as $id) { |
|
1188 | + $calendarExpressions[] = $query->expr() |
|
1189 | + ->eq('calendarid', $query->createNamedParameter($id)); |
|
1190 | + } |
|
1191 | + foreach($sharedCalendars as $id) { |
|
1192 | + $calendarExpressions[] = $query->expr()->andX( |
|
1193 | + $query->expr()->eq('calendarid', |
|
1194 | + $query->createNamedParameter($id)), |
|
1195 | + $query->expr()->eq('classification', |
|
1196 | + $query->createNamedParameter(0)) |
|
1197 | + ); |
|
1198 | + } |
|
1199 | + |
|
1200 | + if (count($calendarExpressions) === 1) { |
|
1201 | + $calExpr = $calendarExpressions[0]; |
|
1202 | + } else { |
|
1203 | + $calExpr = call_user_func_array([$query->expr(), 'orX'], $calendarExpressions); |
|
1204 | + } |
|
1205 | + |
|
1206 | + // Component expressions |
|
1207 | + $compExpressions = []; |
|
1208 | + foreach($filters['comps'] as $comp) { |
|
1209 | + $compExpressions[] = $query->expr() |
|
1210 | + ->eq('componenttype', $query->createNamedParameter($comp)); |
|
1211 | + } |
|
1212 | + |
|
1213 | + if (count($compExpressions) === 1) { |
|
1214 | + $compExpr = $compExpressions[0]; |
|
1215 | + } else { |
|
1216 | + $compExpr = call_user_func_array([$query->expr(), 'orX'], $compExpressions); |
|
1217 | + } |
|
1218 | + |
|
1219 | + // property and filter expression |
|
1220 | + $searchTermFilter = $query->expr()->like('calendardata', |
|
1221 | + $query->createNamedParameter('%' . $this->db->escapeLikeParameter($filters['search-term']) . '%')); |
|
1222 | + |
|
1223 | + $query->select(['calendarid', 'uri', 'calendardata']) |
|
1224 | + ->from('calendarobjects') |
|
1225 | + ->where($calExpr) |
|
1226 | + ->andWhere($compExpr) |
|
1227 | + ->andWhere($searchTermFilter); |
|
1228 | + |
|
1229 | + $stmt = $query->execute(); |
|
1230 | + |
|
1231 | + $result = []; |
|
1232 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1233 | + if (!$this->validateFilterForCalendarSearch($row, $filters)) { |
|
1234 | + continue; |
|
1235 | + } |
|
1236 | + |
|
1237 | + $result[] = $uriMapper[$row['calendarid']] . '/' . $row['uri']; |
|
1238 | + } |
|
1239 | + |
|
1240 | + return $result; |
|
1241 | + } |
|
1242 | + |
|
1243 | + /** |
|
1244 | + * This method validates if a filter (as passed to calendarSearch) matches |
|
1245 | + * the given object. |
|
1246 | + * |
|
1247 | + * @param array $object |
|
1248 | + * @param array $filters |
|
1249 | + * @return bool |
|
1250 | + */ |
|
1251 | + protected function validateFilterForCalendarSearch(array $object, array $filters) { |
|
1252 | + $vObject = Reader::read($object['calendardata']); |
|
1253 | + |
|
1254 | + $validator = new Search\CalendarSearchValidator(); |
|
1255 | + $result = $validator->validate($vObject, $filters); |
|
1256 | + |
|
1257 | + // Destroy circular references so PHP will GC the object. |
|
1258 | + $vObject->destroy(); |
|
1259 | + |
|
1260 | + return $result; |
|
1261 | + } |
|
1262 | + |
|
1263 | + /** |
|
1264 | + * Searches through all of a users calendars and calendar objects to find |
|
1265 | + * an object with a specific UID. |
|
1266 | + * |
|
1267 | + * This method should return the path to this object, relative to the |
|
1268 | + * calendar home, so this path usually only contains two parts: |
|
1269 | + * |
|
1270 | + * calendarpath/objectpath.ics |
|
1271 | + * |
|
1272 | + * If the uid is not found, return null. |
|
1273 | + * |
|
1274 | + * This method should only consider * objects that the principal owns, so |
|
1275 | + * any calendars owned by other principals that also appear in this |
|
1276 | + * collection should be ignored. |
|
1277 | + * |
|
1278 | + * @param string $principalUri |
|
1279 | + * @param string $uid |
|
1280 | + * @return string|null |
|
1281 | + */ |
|
1282 | + function getCalendarObjectByUID($principalUri, $uid) { |
|
1283 | + |
|
1284 | + $query = $this->db->getQueryBuilder(); |
|
1285 | + $query->selectAlias('c.uri', 'calendaruri')->selectAlias('co.uri', 'objecturi') |
|
1286 | + ->from('calendarobjects', 'co') |
|
1287 | + ->leftJoin('co', 'calendars', 'c', $query->expr()->eq('co.calendarid', 'c.id')) |
|
1288 | + ->where($query->expr()->eq('c.principaluri', $query->createNamedParameter($principalUri))) |
|
1289 | + ->andWhere($query->expr()->eq('co.uid', $query->createNamedParameter($uid))); |
|
1290 | + |
|
1291 | + $stmt = $query->execute(); |
|
1292 | + |
|
1293 | + if ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1294 | + return $row['calendaruri'] . '/' . $row['objecturi']; |
|
1295 | + } |
|
1296 | + |
|
1297 | + return null; |
|
1298 | + } |
|
1299 | + |
|
1300 | + /** |
|
1301 | + * The getChanges method returns all the changes that have happened, since |
|
1302 | + * the specified syncToken in the specified calendar. |
|
1303 | + * |
|
1304 | + * This function should return an array, such as the following: |
|
1305 | + * |
|
1306 | + * [ |
|
1307 | + * 'syncToken' => 'The current synctoken', |
|
1308 | + * 'added' => [ |
|
1309 | + * 'new.txt', |
|
1310 | + * ], |
|
1311 | + * 'modified' => [ |
|
1312 | + * 'modified.txt', |
|
1313 | + * ], |
|
1314 | + * 'deleted' => [ |
|
1315 | + * 'foo.php.bak', |
|
1316 | + * 'old.txt' |
|
1317 | + * ] |
|
1318 | + * ); |
|
1319 | + * |
|
1320 | + * The returned syncToken property should reflect the *current* syncToken |
|
1321 | + * of the calendar, as reported in the {http://sabredav.org/ns}sync-token |
|
1322 | + * property This is * needed here too, to ensure the operation is atomic. |
|
1323 | + * |
|
1324 | + * If the $syncToken argument is specified as null, this is an initial |
|
1325 | + * sync, and all members should be reported. |
|
1326 | + * |
|
1327 | + * The modified property is an array of nodenames that have changed since |
|
1328 | + * the last token. |
|
1329 | + * |
|
1330 | + * The deleted property is an array with nodenames, that have been deleted |
|
1331 | + * from collection. |
|
1332 | + * |
|
1333 | + * The $syncLevel argument is basically the 'depth' of the report. If it's |
|
1334 | + * 1, you only have to report changes that happened only directly in |
|
1335 | + * immediate descendants. If it's 2, it should also include changes from |
|
1336 | + * the nodes below the child collections. (grandchildren) |
|
1337 | + * |
|
1338 | + * The $limit argument allows a client to specify how many results should |
|
1339 | + * be returned at most. If the limit is not specified, it should be treated |
|
1340 | + * as infinite. |
|
1341 | + * |
|
1342 | + * If the limit (infinite or not) is higher than you're willing to return, |
|
1343 | + * you should throw a Sabre\DAV\Exception\TooMuchMatches() exception. |
|
1344 | + * |
|
1345 | + * If the syncToken is expired (due to data cleanup) or unknown, you must |
|
1346 | + * return null. |
|
1347 | + * |
|
1348 | + * The limit is 'suggestive'. You are free to ignore it. |
|
1349 | + * |
|
1350 | + * @param string $calendarId |
|
1351 | + * @param string $syncToken |
|
1352 | + * @param int $syncLevel |
|
1353 | + * @param int $limit |
|
1354 | + * @return array |
|
1355 | + */ |
|
1356 | + function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limit = null) { |
|
1357 | + // Current synctoken |
|
1358 | + $stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
1359 | + $stmt->execute([ $calendarId ]); |
|
1360 | + $currentToken = $stmt->fetchColumn(0); |
|
1361 | + |
|
1362 | + if (is_null($currentToken)) { |
|
1363 | + return null; |
|
1364 | + } |
|
1365 | + |
|
1366 | + $result = [ |
|
1367 | + 'syncToken' => $currentToken, |
|
1368 | + 'added' => [], |
|
1369 | + 'modified' => [], |
|
1370 | + 'deleted' => [], |
|
1371 | + ]; |
|
1372 | + |
|
1373 | + if ($syncToken) { |
|
1374 | + |
|
1375 | + $query = "SELECT `uri`, `operation` FROM `*PREFIX*calendarchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `calendarid` = ? ORDER BY `synctoken`"; |
|
1376 | + if ($limit>0) { |
|
1377 | + $query.= " `LIMIT` " . (int)$limit; |
|
1378 | + } |
|
1379 | + |
|
1380 | + // Fetching all changes |
|
1381 | + $stmt = $this->db->prepare($query); |
|
1382 | + $stmt->execute([$syncToken, $currentToken, $calendarId]); |
|
1383 | + |
|
1384 | + $changes = []; |
|
1385 | + |
|
1386 | + // This loop ensures that any duplicates are overwritten, only the |
|
1387 | + // last change on a node is relevant. |
|
1388 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1389 | + |
|
1390 | + $changes[$row['uri']] = $row['operation']; |
|
1391 | + |
|
1392 | + } |
|
1393 | + |
|
1394 | + foreach($changes as $uri => $operation) { |
|
1395 | + |
|
1396 | + switch($operation) { |
|
1397 | + case 1 : |
|
1398 | + $result['added'][] = $uri; |
|
1399 | + break; |
|
1400 | + case 2 : |
|
1401 | + $result['modified'][] = $uri; |
|
1402 | + break; |
|
1403 | + case 3 : |
|
1404 | + $result['deleted'][] = $uri; |
|
1405 | + break; |
|
1406 | + } |
|
1407 | + |
|
1408 | + } |
|
1409 | + } else { |
|
1410 | + // No synctoken supplied, this is the initial sync. |
|
1411 | + $query = "SELECT `uri` FROM `*PREFIX*calendarobjects` WHERE `calendarid` = ?"; |
|
1412 | + $stmt = $this->db->prepare($query); |
|
1413 | + $stmt->execute([$calendarId]); |
|
1414 | + |
|
1415 | + $result['added'] = $stmt->fetchAll(\PDO::FETCH_COLUMN); |
|
1416 | + } |
|
1417 | + return $result; |
|
1418 | + |
|
1419 | + } |
|
1420 | + |
|
1421 | + /** |
|
1422 | + * Returns a list of subscriptions for a principal. |
|
1423 | + * |
|
1424 | + * Every subscription is an array with the following keys: |
|
1425 | + * * id, a unique id that will be used by other functions to modify the |
|
1426 | + * subscription. This can be the same as the uri or a database key. |
|
1427 | + * * uri. This is just the 'base uri' or 'filename' of the subscription. |
|
1428 | + * * principaluri. The owner of the subscription. Almost always the same as |
|
1429 | + * principalUri passed to this method. |
|
1430 | + * |
|
1431 | + * Furthermore, all the subscription info must be returned too: |
|
1432 | + * |
|
1433 | + * 1. {DAV:}displayname |
|
1434 | + * 2. {http://apple.com/ns/ical/}refreshrate |
|
1435 | + * 3. {http://calendarserver.org/ns/}subscribed-strip-todos (omit if todos |
|
1436 | + * should not be stripped). |
|
1437 | + * 4. {http://calendarserver.org/ns/}subscribed-strip-alarms (omit if alarms |
|
1438 | + * should not be stripped). |
|
1439 | + * 5. {http://calendarserver.org/ns/}subscribed-strip-attachments (omit if |
|
1440 | + * attachments should not be stripped). |
|
1441 | + * 6. {http://calendarserver.org/ns/}source (Must be a |
|
1442 | + * Sabre\DAV\Property\Href). |
|
1443 | + * 7. {http://apple.com/ns/ical/}calendar-color |
|
1444 | + * 8. {http://apple.com/ns/ical/}calendar-order |
|
1445 | + * 9. {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set |
|
1446 | + * (should just be an instance of |
|
1447 | + * Sabre\CalDAV\Property\SupportedCalendarComponentSet, with a bunch of |
|
1448 | + * default components). |
|
1449 | + * |
|
1450 | + * @param string $principalUri |
|
1451 | + * @return array |
|
1452 | + */ |
|
1453 | + function getSubscriptionsForUser($principalUri) { |
|
1454 | + $fields = array_values($this->subscriptionPropertyMap); |
|
1455 | + $fields[] = 'id'; |
|
1456 | + $fields[] = 'uri'; |
|
1457 | + $fields[] = 'source'; |
|
1458 | + $fields[] = 'principaluri'; |
|
1459 | + $fields[] = 'lastmodified'; |
|
1460 | + |
|
1461 | + $query = $this->db->getQueryBuilder(); |
|
1462 | + $query->select($fields) |
|
1463 | + ->from('calendarsubscriptions') |
|
1464 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1465 | + ->orderBy('calendarorder', 'asc'); |
|
1466 | + $stmt =$query->execute(); |
|
1467 | + |
|
1468 | + $subscriptions = []; |
|
1469 | + while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1470 | + |
|
1471 | + $subscription = [ |
|
1472 | + 'id' => $row['id'], |
|
1473 | + 'uri' => $row['uri'], |
|
1474 | + 'principaluri' => $row['principaluri'], |
|
1475 | + 'source' => $row['source'], |
|
1476 | + 'lastmodified' => $row['lastmodified'], |
|
1477 | + |
|
1478 | + '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO', 'VEVENT']), |
|
1479 | + ]; |
|
1480 | + |
|
1481 | + foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1482 | + if (!is_null($row[$dbName])) { |
|
1483 | + $subscription[$xmlName] = $row[$dbName]; |
|
1484 | + } |
|
1485 | + } |
|
1486 | + |
|
1487 | + $subscriptions[] = $subscription; |
|
1488 | + |
|
1489 | + } |
|
1490 | + |
|
1491 | + return $subscriptions; |
|
1492 | + } |
|
1493 | + |
|
1494 | + /** |
|
1495 | + * Creates a new subscription for a principal. |
|
1496 | + * |
|
1497 | + * If the creation was a success, an id must be returned that can be used to reference |
|
1498 | + * this subscription in other methods, such as updateSubscription. |
|
1499 | + * |
|
1500 | + * @param string $principalUri |
|
1501 | + * @param string $uri |
|
1502 | + * @param array $properties |
|
1503 | + * @return mixed |
|
1504 | + */ |
|
1505 | + function createSubscription($principalUri, $uri, array $properties) { |
|
1506 | + |
|
1507 | + if (!isset($properties['{http://calendarserver.org/ns/}source'])) { |
|
1508 | + throw new Forbidden('The {http://calendarserver.org/ns/}source property is required when creating subscriptions'); |
|
1509 | + } |
|
1510 | + |
|
1511 | + $values = [ |
|
1512 | + 'principaluri' => $principalUri, |
|
1513 | + 'uri' => $uri, |
|
1514 | + 'source' => $properties['{http://calendarserver.org/ns/}source']->getHref(), |
|
1515 | + 'lastmodified' => time(), |
|
1516 | + ]; |
|
1517 | + |
|
1518 | + $propertiesBoolean = ['striptodos', 'stripalarms', 'stripattachments']; |
|
1519 | + |
|
1520 | + foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1521 | + if (array_key_exists($xmlName, $properties)) { |
|
1522 | + $values[$dbName] = $properties[$xmlName]; |
|
1523 | + if (in_array($dbName, $propertiesBoolean)) { |
|
1524 | + $values[$dbName] = true; |
|
1525 | + } |
|
1526 | + } |
|
1527 | + } |
|
1528 | + |
|
1529 | + $valuesToInsert = array(); |
|
1530 | + |
|
1531 | + $query = $this->db->getQueryBuilder(); |
|
1532 | + |
|
1533 | + foreach (array_keys($values) as $name) { |
|
1534 | + $valuesToInsert[$name] = $query->createNamedParameter($values[$name]); |
|
1535 | + } |
|
1536 | + |
|
1537 | + $query->insert('calendarsubscriptions') |
|
1538 | + ->values($valuesToInsert) |
|
1539 | + ->execute(); |
|
1540 | + |
|
1541 | + return $this->db->lastInsertId('*PREFIX*calendarsubscriptions'); |
|
1542 | + } |
|
1543 | + |
|
1544 | + /** |
|
1545 | + * Updates a subscription |
|
1546 | + * |
|
1547 | + * The list of mutations is stored in a Sabre\DAV\PropPatch object. |
|
1548 | + * To do the actual updates, you must tell this object which properties |
|
1549 | + * you're going to process with the handle() method. |
|
1550 | + * |
|
1551 | + * Calling the handle method is like telling the PropPatch object "I |
|
1552 | + * promise I can handle updating this property". |
|
1553 | + * |
|
1554 | + * Read the PropPatch documentation for more info and examples. |
|
1555 | + * |
|
1556 | + * @param mixed $subscriptionId |
|
1557 | + * @param PropPatch $propPatch |
|
1558 | + * @return void |
|
1559 | + */ |
|
1560 | + function updateSubscription($subscriptionId, PropPatch $propPatch) { |
|
1561 | + $supportedProperties = array_keys($this->subscriptionPropertyMap); |
|
1562 | + $supportedProperties[] = '{http://calendarserver.org/ns/}source'; |
|
1563 | + |
|
1564 | + $propPatch->handle($supportedProperties, function($mutations) use ($subscriptionId) { |
|
1565 | + |
|
1566 | + $newValues = []; |
|
1567 | + |
|
1568 | + foreach($mutations as $propertyName=>$propertyValue) { |
|
1569 | + if ($propertyName === '{http://calendarserver.org/ns/}source') { |
|
1570 | + $newValues['source'] = $propertyValue->getHref(); |
|
1571 | + } else { |
|
1572 | + $fieldName = $this->subscriptionPropertyMap[$propertyName]; |
|
1573 | + $newValues[$fieldName] = $propertyValue; |
|
1574 | + } |
|
1575 | + } |
|
1576 | + |
|
1577 | + $query = $this->db->getQueryBuilder(); |
|
1578 | + $query->update('calendarsubscriptions') |
|
1579 | + ->set('lastmodified', $query->createNamedParameter(time())); |
|
1580 | + foreach($newValues as $fieldName=>$value) { |
|
1581 | + $query->set($fieldName, $query->createNamedParameter($value)); |
|
1582 | + } |
|
1583 | + $query->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) |
|
1584 | + ->execute(); |
|
1585 | + |
|
1586 | + return true; |
|
1587 | + |
|
1588 | + }); |
|
1589 | + } |
|
1590 | + |
|
1591 | + /** |
|
1592 | + * Deletes a subscription. |
|
1593 | + * |
|
1594 | + * @param mixed $subscriptionId |
|
1595 | + * @return void |
|
1596 | + */ |
|
1597 | + function deleteSubscription($subscriptionId) { |
|
1598 | + $query = $this->db->getQueryBuilder(); |
|
1599 | + $query->delete('calendarsubscriptions') |
|
1600 | + ->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) |
|
1601 | + ->execute(); |
|
1602 | + } |
|
1603 | + |
|
1604 | + /** |
|
1605 | + * Returns a single scheduling object for the inbox collection. |
|
1606 | + * |
|
1607 | + * The returned array should contain the following elements: |
|
1608 | + * * uri - A unique basename for the object. This will be used to |
|
1609 | + * construct a full uri. |
|
1610 | + * * calendardata - The iCalendar object |
|
1611 | + * * lastmodified - The last modification date. Can be an int for a unix |
|
1612 | + * timestamp, or a PHP DateTime object. |
|
1613 | + * * etag - A unique token that must change if the object changed. |
|
1614 | + * * size - The size of the object, in bytes. |
|
1615 | + * |
|
1616 | + * @param string $principalUri |
|
1617 | + * @param string $objectUri |
|
1618 | + * @return array |
|
1619 | + */ |
|
1620 | + function getSchedulingObject($principalUri, $objectUri) { |
|
1621 | + $query = $this->db->getQueryBuilder(); |
|
1622 | + $stmt = $query->select(['uri', 'calendardata', 'lastmodified', 'etag', 'size']) |
|
1623 | + ->from('schedulingobjects') |
|
1624 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1625 | + ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
1626 | + ->execute(); |
|
1627 | + |
|
1628 | + $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
|
1629 | + |
|
1630 | + if(!$row) { |
|
1631 | + return null; |
|
1632 | + } |
|
1633 | + |
|
1634 | + return [ |
|
1635 | + 'uri' => $row['uri'], |
|
1636 | + 'calendardata' => $row['calendardata'], |
|
1637 | + 'lastmodified' => $row['lastmodified'], |
|
1638 | + 'etag' => '"' . $row['etag'] . '"', |
|
1639 | + 'size' => (int)$row['size'], |
|
1640 | + ]; |
|
1641 | + } |
|
1642 | + |
|
1643 | + /** |
|
1644 | + * Returns all scheduling objects for the inbox collection. |
|
1645 | + * |
|
1646 | + * These objects should be returned as an array. Every item in the array |
|
1647 | + * should follow the same structure as returned from getSchedulingObject. |
|
1648 | + * |
|
1649 | + * The main difference is that 'calendardata' is optional. |
|
1650 | + * |
|
1651 | + * @param string $principalUri |
|
1652 | + * @return array |
|
1653 | + */ |
|
1654 | + function getSchedulingObjects($principalUri) { |
|
1655 | + $query = $this->db->getQueryBuilder(); |
|
1656 | + $stmt = $query->select(['uri', 'calendardata', 'lastmodified', 'etag', 'size']) |
|
1657 | + ->from('schedulingobjects') |
|
1658 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1659 | + ->execute(); |
|
1660 | + |
|
1661 | + $result = []; |
|
1662 | + foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
1663 | + $result[] = [ |
|
1664 | + 'calendardata' => $row['calendardata'], |
|
1665 | + 'uri' => $row['uri'], |
|
1666 | + 'lastmodified' => $row['lastmodified'], |
|
1667 | + 'etag' => '"' . $row['etag'] . '"', |
|
1668 | + 'size' => (int)$row['size'], |
|
1669 | + ]; |
|
1670 | + } |
|
1671 | + |
|
1672 | + return $result; |
|
1673 | + } |
|
1674 | + |
|
1675 | + /** |
|
1676 | + * Deletes a scheduling object from the inbox collection. |
|
1677 | + * |
|
1678 | + * @param string $principalUri |
|
1679 | + * @param string $objectUri |
|
1680 | + * @return void |
|
1681 | + */ |
|
1682 | + function deleteSchedulingObject($principalUri, $objectUri) { |
|
1683 | + $query = $this->db->getQueryBuilder(); |
|
1684 | + $query->delete('schedulingobjects') |
|
1685 | + ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
|
1686 | + ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($objectUri))) |
|
1687 | + ->execute(); |
|
1688 | + } |
|
1689 | + |
|
1690 | + /** |
|
1691 | + * Creates a new scheduling object. This should land in a users' inbox. |
|
1692 | + * |
|
1693 | + * @param string $principalUri |
|
1694 | + * @param string $objectUri |
|
1695 | + * @param string $objectData |
|
1696 | + * @return void |
|
1697 | + */ |
|
1698 | + function createSchedulingObject($principalUri, $objectUri, $objectData) { |
|
1699 | + $query = $this->db->getQueryBuilder(); |
|
1700 | + $query->insert('schedulingobjects') |
|
1701 | + ->values([ |
|
1702 | + 'principaluri' => $query->createNamedParameter($principalUri), |
|
1703 | + 'calendardata' => $query->createNamedParameter($objectData), |
|
1704 | + 'uri' => $query->createNamedParameter($objectUri), |
|
1705 | + 'lastmodified' => $query->createNamedParameter(time()), |
|
1706 | + 'etag' => $query->createNamedParameter(md5($objectData)), |
|
1707 | + 'size' => $query->createNamedParameter(strlen($objectData)) |
|
1708 | + ]) |
|
1709 | + ->execute(); |
|
1710 | + } |
|
1711 | + |
|
1712 | + /** |
|
1713 | + * Adds a change record to the calendarchanges table. |
|
1714 | + * |
|
1715 | + * @param mixed $calendarId |
|
1716 | + * @param string $objectUri |
|
1717 | + * @param int $operation 1 = add, 2 = modify, 3 = delete. |
|
1718 | + * @return void |
|
1719 | + */ |
|
1720 | + protected function addChange($calendarId, $objectUri, $operation) { |
|
1721 | + |
|
1722 | + $stmt = $this->db->prepare('INSERT INTO `*PREFIX*calendarchanges` (`uri`, `synctoken`, `calendarid`, `operation`) SELECT ?, `synctoken`, ?, ? FROM `*PREFIX*calendars` WHERE `id` = ?'); |
|
1723 | + $stmt->execute([ |
|
1724 | + $objectUri, |
|
1725 | + $calendarId, |
|
1726 | + $operation, |
|
1727 | + $calendarId |
|
1728 | + ]); |
|
1729 | + $stmt = $this->db->prepare('UPDATE `*PREFIX*calendars` SET `synctoken` = `synctoken` + 1 WHERE `id` = ?'); |
|
1730 | + $stmt->execute([ |
|
1731 | + $calendarId |
|
1732 | + ]); |
|
1733 | + |
|
1734 | + } |
|
1735 | + |
|
1736 | + /** |
|
1737 | + * Parses some information from calendar objects, used for optimized |
|
1738 | + * calendar-queries. |
|
1739 | + * |
|
1740 | + * Returns an array with the following keys: |
|
1741 | + * * etag - An md5 checksum of the object without the quotes. |
|
1742 | + * * size - Size of the object in bytes |
|
1743 | + * * componentType - VEVENT, VTODO or VJOURNAL |
|
1744 | + * * firstOccurence |
|
1745 | + * * lastOccurence |
|
1746 | + * * uid - value of the UID property |
|
1747 | + * |
|
1748 | + * @param string $calendarData |
|
1749 | + * @return array |
|
1750 | + */ |
|
1751 | + public function getDenormalizedData($calendarData) { |
|
1752 | + |
|
1753 | + $vObject = Reader::read($calendarData); |
|
1754 | + $componentType = null; |
|
1755 | + $component = null; |
|
1756 | + $firstOccurrence = null; |
|
1757 | + $lastOccurrence = null; |
|
1758 | + $uid = null; |
|
1759 | + $classification = self::CLASSIFICATION_PUBLIC; |
|
1760 | + foreach($vObject->getComponents() as $component) { |
|
1761 | + if ($component->name!=='VTIMEZONE') { |
|
1762 | + $componentType = $component->name; |
|
1763 | + $uid = (string)$component->UID; |
|
1764 | + break; |
|
1765 | + } |
|
1766 | + } |
|
1767 | + if (!$componentType) { |
|
1768 | + throw new \Sabre\DAV\Exception\BadRequest('Calendar objects must have a VJOURNAL, VEVENT or VTODO component'); |
|
1769 | + } |
|
1770 | + if ($componentType === 'VEVENT' && $component->DTSTART) { |
|
1771 | + $firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp(); |
|
1772 | + // Finding the last occurrence is a bit harder |
|
1773 | + if (!isset($component->RRULE)) { |
|
1774 | + if (isset($component->DTEND)) { |
|
1775 | + $lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp(); |
|
1776 | + } elseif (isset($component->DURATION)) { |
|
1777 | + $endDate = clone $component->DTSTART->getDateTime(); |
|
1778 | + $endDate->add(DateTimeParser::parse($component->DURATION->getValue())); |
|
1779 | + $lastOccurrence = $endDate->getTimeStamp(); |
|
1780 | + } elseif (!$component->DTSTART->hasTime()) { |
|
1781 | + $endDate = clone $component->DTSTART->getDateTime(); |
|
1782 | + $endDate->modify('+1 day'); |
|
1783 | + $lastOccurrence = $endDate->getTimeStamp(); |
|
1784 | + } else { |
|
1785 | + $lastOccurrence = $firstOccurrence; |
|
1786 | + } |
|
1787 | + } else { |
|
1788 | + $it = new EventIterator($vObject, (string)$component->UID); |
|
1789 | + $maxDate = new \DateTime(self::MAX_DATE); |
|
1790 | + if ($it->isInfinite()) { |
|
1791 | + $lastOccurrence = $maxDate->getTimestamp(); |
|
1792 | + } else { |
|
1793 | + $end = $it->getDtEnd(); |
|
1794 | + while($it->valid() && $end < $maxDate) { |
|
1795 | + $end = $it->getDtEnd(); |
|
1796 | + $it->next(); |
|
1797 | + |
|
1798 | + } |
|
1799 | + $lastOccurrence = $end->getTimestamp(); |
|
1800 | + } |
|
1801 | + |
|
1802 | + } |
|
1803 | + } |
|
1804 | + |
|
1805 | + if ($component->CLASS) { |
|
1806 | + $classification = CalDavBackend::CLASSIFICATION_PRIVATE; |
|
1807 | + switch ($component->CLASS->getValue()) { |
|
1808 | + case 'PUBLIC': |
|
1809 | + $classification = CalDavBackend::CLASSIFICATION_PUBLIC; |
|
1810 | + break; |
|
1811 | + case 'CONFIDENTIAL': |
|
1812 | + $classification = CalDavBackend::CLASSIFICATION_CONFIDENTIAL; |
|
1813 | + break; |
|
1814 | + } |
|
1815 | + } |
|
1816 | + return [ |
|
1817 | + 'etag' => md5($calendarData), |
|
1818 | + 'size' => strlen($calendarData), |
|
1819 | + 'componentType' => $componentType, |
|
1820 | + 'firstOccurence' => is_null($firstOccurrence) ? null : max(0, $firstOccurrence), |
|
1821 | + 'lastOccurence' => $lastOccurrence, |
|
1822 | + 'uid' => $uid, |
|
1823 | + 'classification' => $classification |
|
1824 | + ]; |
|
1825 | + |
|
1826 | + } |
|
1827 | + |
|
1828 | + private function readBlob($cardData) { |
|
1829 | + if (is_resource($cardData)) { |
|
1830 | + return stream_get_contents($cardData); |
|
1831 | + } |
|
1832 | + |
|
1833 | + return $cardData; |
|
1834 | + } |
|
1835 | + |
|
1836 | + /** |
|
1837 | + * @param IShareable $shareable |
|
1838 | + * @param array $add |
|
1839 | + * @param array $remove |
|
1840 | + */ |
|
1841 | + public function updateShares($shareable, $add, $remove) { |
|
1842 | + $calendarId = $shareable->getResourceId(); |
|
1843 | + $this->dispatcher->dispatch('\OCA\DAV\CalDAV\CalDavBackend::updateShares', new GenericEvent( |
|
1844 | + '\OCA\DAV\CalDAV\CalDavBackend::updateShares', |
|
1845 | + [ |
|
1846 | + 'calendarId' => $calendarId, |
|
1847 | + 'calendarData' => $this->getCalendarById($calendarId), |
|
1848 | + 'shares' => $this->getShares($calendarId), |
|
1849 | + 'add' => $add, |
|
1850 | + 'remove' => $remove, |
|
1851 | + ])); |
|
1852 | + $this->sharingBackend->updateShares($shareable, $add, $remove); |
|
1853 | + } |
|
1854 | + |
|
1855 | + /** |
|
1856 | + * @param int $resourceId |
|
1857 | + * @return array |
|
1858 | + */ |
|
1859 | + public function getShares($resourceId) { |
|
1860 | + return $this->sharingBackend->getShares($resourceId); |
|
1861 | + } |
|
1862 | + |
|
1863 | + /** |
|
1864 | + * @param boolean $value |
|
1865 | + * @param \OCA\DAV\CalDAV\Calendar $calendar |
|
1866 | + * @return string|null |
|
1867 | + */ |
|
1868 | + public function setPublishStatus($value, $calendar) { |
|
1869 | + $query = $this->db->getQueryBuilder(); |
|
1870 | + if ($value) { |
|
1871 | + $publicUri = $this->random->generate(16, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS); |
|
1872 | + $query->insert('dav_shares') |
|
1873 | + ->values([ |
|
1874 | + 'principaluri' => $query->createNamedParameter($calendar->getPrincipalURI()), |
|
1875 | + 'type' => $query->createNamedParameter('calendar'), |
|
1876 | + 'access' => $query->createNamedParameter(self::ACCESS_PUBLIC), |
|
1877 | + 'resourceid' => $query->createNamedParameter($calendar->getResourceId()), |
|
1878 | + 'publicuri' => $query->createNamedParameter($publicUri) |
|
1879 | + ]); |
|
1880 | + $query->execute(); |
|
1881 | + return $publicUri; |
|
1882 | + } |
|
1883 | + $query->delete('dav_shares') |
|
1884 | + ->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) |
|
1885 | + ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))); |
|
1886 | + $query->execute(); |
|
1887 | + return null; |
|
1888 | + } |
|
1889 | + |
|
1890 | + /** |
|
1891 | + * @param \OCA\DAV\CalDAV\Calendar $calendar |
|
1892 | + * @return mixed |
|
1893 | + */ |
|
1894 | + public function getPublishStatus($calendar) { |
|
1895 | + $query = $this->db->getQueryBuilder(); |
|
1896 | + $result = $query->select('publicuri') |
|
1897 | + ->from('dav_shares') |
|
1898 | + ->where($query->expr()->eq('resourceid', $query->createNamedParameter($calendar->getResourceId()))) |
|
1899 | + ->andWhere($query->expr()->eq('access', $query->createNamedParameter(self::ACCESS_PUBLIC))) |
|
1900 | + ->execute(); |
|
1901 | + |
|
1902 | + $row = $result->fetch(); |
|
1903 | + $result->closeCursor(); |
|
1904 | + return $row ? reset($row) : false; |
|
1905 | + } |
|
1906 | + |
|
1907 | + /** |
|
1908 | + * @param int $resourceId |
|
1909 | + * @param array $acl |
|
1910 | + * @return array |
|
1911 | + */ |
|
1912 | + public function applyShareAcl($resourceId, $acl) { |
|
1913 | + return $this->sharingBackend->applyShareAcl($resourceId, $acl); |
|
1914 | + } |
|
1915 | + |
|
1916 | + private function convertPrincipal($principalUri, $toV2) { |
|
1917 | + if ($this->principalBackend->getPrincipalPrefix() === 'principals') { |
|
1918 | + list(, $name) = URLUtil::splitPath($principalUri); |
|
1919 | + if ($toV2 === true) { |
|
1920 | + return "principals/users/$name"; |
|
1921 | + } |
|
1922 | + return "principals/$name"; |
|
1923 | + } |
|
1924 | + return $principalUri; |
|
1925 | + } |
|
1926 | 1926 | } |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | $query->andWhere($query->expr()->neq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))); |
180 | 180 | } |
181 | 181 | |
182 | - return (int)$query->execute()->fetchColumn(); |
|
182 | + return (int) $query->execute()->fetchColumn(); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -226,25 +226,25 @@ discard block |
||
226 | 226 | $stmt = $query->execute(); |
227 | 227 | |
228 | 228 | $calendars = []; |
229 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
229 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
230 | 230 | |
231 | 231 | $components = []; |
232 | 232 | if ($row['components']) { |
233 | - $components = explode(',',$row['components']); |
|
233 | + $components = explode(',', $row['components']); |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | $calendar = [ |
237 | 237 | 'id' => $row['id'], |
238 | 238 | 'uri' => $row['uri'], |
239 | 239 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
240 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
241 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
242 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
243 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
244 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
240 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
241 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
242 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
243 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
244 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}owner-principal' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
|
245 | 245 | ]; |
246 | 246 | |
247 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
247 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
248 | 248 | $calendar[$xmlName] = $row[$dbName]; |
249 | 249 | } |
250 | 250 | |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | |
258 | 258 | // query for shared calendars |
259 | 259 | $principals = $this->principalBackend->getGroupMembership($principalUriOriginal, true); |
260 | - $principals[]= $principalUri; |
|
260 | + $principals[] = $principalUri; |
|
261 | 261 | |
262 | 262 | $fields = array_values($this->propertyMap); |
263 | 263 | $fields[] = 'a.id'; |
@@ -277,8 +277,8 @@ discard block |
||
277 | 277 | ->setParameter('principaluri', $principals, \Doctrine\DBAL\Connection::PARAM_STR_ARRAY) |
278 | 278 | ->execute(); |
279 | 279 | |
280 | - $readOnlyPropertyName = '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only'; |
|
281 | - while($row = $result->fetch()) { |
|
280 | + $readOnlyPropertyName = '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}read-only'; |
|
281 | + while ($row = $result->fetch()) { |
|
282 | 282 | if ($row['principaluri'] === $principalUri) { |
283 | 283 | continue; |
284 | 284 | } |
@@ -297,25 +297,25 @@ discard block |
||
297 | 297 | } |
298 | 298 | |
299 | 299 | list(, $name) = URLUtil::splitPath($row['principaluri']); |
300 | - $uri = $row['uri'] . '_shared_by_' . $name; |
|
301 | - $row['displayname'] = $row['displayname'] . ' (' . $this->getUserDisplayName($name) . ')'; |
|
300 | + $uri = $row['uri'].'_shared_by_'.$name; |
|
301 | + $row['displayname'] = $row['displayname'].' ('.$this->getUserDisplayName($name).')'; |
|
302 | 302 | $components = []; |
303 | 303 | if ($row['components']) { |
304 | - $components = explode(',',$row['components']); |
|
304 | + $components = explode(',', $row['components']); |
|
305 | 305 | } |
306 | 306 | $calendar = [ |
307 | 307 | 'id' => $row['id'], |
308 | 308 | 'uri' => $uri, |
309 | 309 | 'principaluri' => $this->convertPrincipal($principalUri, !$this->legacyEndpoint), |
310 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
311 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
312 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
313 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
314 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
310 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
311 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
312 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
313 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
314 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
315 | 315 | $readOnlyPropertyName => $readOnly, |
316 | 316 | ]; |
317 | 317 | |
318 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
318 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
319 | 319 | $calendar[$xmlName] = $row[$dbName]; |
320 | 320 | } |
321 | 321 | |
@@ -342,21 +342,21 @@ discard block |
||
342 | 342 | ->orderBy('calendarorder', 'ASC'); |
343 | 343 | $stmt = $query->execute(); |
344 | 344 | $calendars = []; |
345 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
345 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
346 | 346 | $components = []; |
347 | 347 | if ($row['components']) { |
348 | - $components = explode(',',$row['components']); |
|
348 | + $components = explode(',', $row['components']); |
|
349 | 349 | } |
350 | 350 | $calendar = [ |
351 | 351 | 'id' => $row['id'], |
352 | 352 | 'uri' => $row['uri'], |
353 | 353 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
354 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
355 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
356 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
357 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
354 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
355 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
356 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
357 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
358 | 358 | ]; |
359 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
359 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
360 | 360 | $calendar[$xmlName] = $row[$dbName]; |
361 | 361 | } |
362 | 362 | if (!isset($calendars[$calendar['id']])) { |
@@ -404,27 +404,27 @@ discard block |
||
404 | 404 | ->andWhere($query->expr()->eq('s.type', $query->createNamedParameter('calendar'))) |
405 | 405 | ->execute(); |
406 | 406 | |
407 | - while($row = $result->fetch()) { |
|
407 | + while ($row = $result->fetch()) { |
|
408 | 408 | list(, $name) = URLUtil::splitPath($row['principaluri']); |
409 | - $row['displayname'] = $row['displayname'] . "($name)"; |
|
409 | + $row['displayname'] = $row['displayname']."($name)"; |
|
410 | 410 | $components = []; |
411 | 411 | if ($row['components']) { |
412 | - $components = explode(',',$row['components']); |
|
412 | + $components = explode(',', $row['components']); |
|
413 | 413 | } |
414 | 414 | $calendar = [ |
415 | 415 | 'id' => $row['id'], |
416 | 416 | 'uri' => $row['publicuri'], |
417 | 417 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
418 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
419 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
420 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
421 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
422 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], $this->legacyEndpoint), |
|
423 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
424 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
418 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
419 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
420 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
421 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
422 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}owner-principal' => $this->convertPrincipal($row['principaluri'], $this->legacyEndpoint), |
|
423 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}read-only' => (int) $row['access'] === Backend::ACCESS_READ, |
|
424 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}public' => (int) $row['access'] === self::ACCESS_PUBLIC, |
|
425 | 425 | ]; |
426 | 426 | |
427 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
427 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
428 | 428 | $calendar[$xmlName] = $row[$dbName]; |
429 | 429 | } |
430 | 430 | |
@@ -466,29 +466,29 @@ discard block |
||
466 | 466 | $result->closeCursor(); |
467 | 467 | |
468 | 468 | if ($row === false) { |
469 | - throw new NotFound('Node with name \'' . $uri . '\' could not be found'); |
|
469 | + throw new NotFound('Node with name \''.$uri.'\' could not be found'); |
|
470 | 470 | } |
471 | 471 | |
472 | 472 | list(, $name) = URLUtil::splitPath($row['principaluri']); |
473 | - $row['displayname'] = $row['displayname'] . ' ' . "($name)"; |
|
473 | + $row['displayname'] = $row['displayname'].' '."($name)"; |
|
474 | 474 | $components = []; |
475 | 475 | if ($row['components']) { |
476 | - $components = explode(',',$row['components']); |
|
476 | + $components = explode(',', $row['components']); |
|
477 | 477 | } |
478 | 478 | $calendar = [ |
479 | 479 | 'id' => $row['id'], |
480 | 480 | 'uri' => $row['publicuri'], |
481 | 481 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
482 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
483 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
484 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
485 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
486 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
487 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}read-only' => (int)$row['access'] === Backend::ACCESS_READ, |
|
488 | - '{' . \OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD . '}public' => (int)$row['access'] === self::ACCESS_PUBLIC, |
|
482 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
483 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
484 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
485 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
486 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}owner-principal' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
|
487 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}read-only' => (int) $row['access'] === Backend::ACCESS_READ, |
|
488 | + '{'.\OCA\DAV\DAV\Sharing\Plugin::NS_OWNCLOUD.'}public' => (int) $row['access'] === self::ACCESS_PUBLIC, |
|
489 | 489 | ]; |
490 | 490 | |
491 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
491 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
492 | 492 | $calendar[$xmlName] = $row[$dbName]; |
493 | 493 | } |
494 | 494 | |
@@ -526,20 +526,20 @@ discard block |
||
526 | 526 | |
527 | 527 | $components = []; |
528 | 528 | if ($row['components']) { |
529 | - $components = explode(',',$row['components']); |
|
529 | + $components = explode(',', $row['components']); |
|
530 | 530 | } |
531 | 531 | |
532 | 532 | $calendar = [ |
533 | 533 | 'id' => $row['id'], |
534 | 534 | 'uri' => $row['uri'], |
535 | 535 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
536 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
537 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
538 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
539 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
536 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
537 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
538 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
539 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
540 | 540 | ]; |
541 | 541 | |
542 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
542 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
543 | 543 | $calendar[$xmlName] = $row[$dbName]; |
544 | 544 | } |
545 | 545 | |
@@ -570,20 +570,20 @@ discard block |
||
570 | 570 | |
571 | 571 | $components = []; |
572 | 572 | if ($row['components']) { |
573 | - $components = explode(',',$row['components']); |
|
573 | + $components = explode(',', $row['components']); |
|
574 | 574 | } |
575 | 575 | |
576 | 576 | $calendar = [ |
577 | 577 | 'id' => $row['id'], |
578 | 578 | 'uri' => $row['uri'], |
579 | 579 | 'principaluri' => $this->convertPrincipal($row['principaluri'], !$this->legacyEndpoint), |
580 | - '{' . Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'), |
|
581 | - '{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0', |
|
582 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
583 | - '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'), |
|
580 | + '{'.Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($row['synctoken'] ? $row['synctoken'] : '0'), |
|
581 | + '{http://sabredav.org/ns}sync-token' => $row['synctoken'] ? $row['synctoken'] : '0', |
|
582 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet($components), |
|
583 | + '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' => new ScheduleCalendarTransp($row['transparent'] ? 'transparent' : 'opaque'), |
|
584 | 584 | ]; |
585 | 585 | |
586 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
586 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
587 | 587 | $calendar[$xmlName] = $row[$dbName]; |
588 | 588 | } |
589 | 589 | |
@@ -615,16 +615,16 @@ discard block |
||
615 | 615 | $sccs = '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set'; |
616 | 616 | if (isset($properties[$sccs])) { |
617 | 617 | if (!($properties[$sccs] instanceof SupportedCalendarComponentSet)) { |
618 | - throw new DAV\Exception('The ' . $sccs . ' property must be of type: \Sabre\CalDAV\Property\SupportedCalendarComponentSet'); |
|
618 | + throw new DAV\Exception('The '.$sccs.' property must be of type: \Sabre\CalDAV\Property\SupportedCalendarComponentSet'); |
|
619 | 619 | } |
620 | - $values['components'] = implode(',',$properties[$sccs]->getValue()); |
|
620 | + $values['components'] = implode(',', $properties[$sccs]->getValue()); |
|
621 | 621 | } |
622 | - $transp = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
622 | + $transp = '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp'; |
|
623 | 623 | if (isset($properties[$transp])) { |
624 | 624 | $values['transparent'] = (int) ($properties[$transp]->getValue() === 'transparent'); |
625 | 625 | } |
626 | 626 | |
627 | - foreach($this->propertyMap as $xmlName=>$dbName) { |
|
627 | + foreach ($this->propertyMap as $xmlName=>$dbName) { |
|
628 | 628 | if (isset($properties[$xmlName])) { |
629 | 629 | $values[$dbName] = $properties[$xmlName]; |
630 | 630 | } |
@@ -632,7 +632,7 @@ discard block |
||
632 | 632 | |
633 | 633 | $query = $this->db->getQueryBuilder(); |
634 | 634 | $query->insert('calendars'); |
635 | - foreach($values as $column => $value) { |
|
635 | + foreach ($values as $column => $value) { |
|
636 | 636 | $query->setValue($column, $query->createNamedParameter($value)); |
637 | 637 | } |
638 | 638 | $query->execute(); |
@@ -665,14 +665,14 @@ discard block |
||
665 | 665 | */ |
666 | 666 | function updateCalendar($calendarId, PropPatch $propPatch) { |
667 | 667 | $supportedProperties = array_keys($this->propertyMap); |
668 | - $supportedProperties[] = '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp'; |
|
668 | + $supportedProperties[] = '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp'; |
|
669 | 669 | |
670 | 670 | $propPatch->handle($supportedProperties, function($mutations) use ($calendarId) { |
671 | 671 | $newValues = []; |
672 | 672 | foreach ($mutations as $propertyName => $propertyValue) { |
673 | 673 | |
674 | 674 | switch ($propertyName) { |
675 | - case '{' . Plugin::NS_CALDAV . '}schedule-calendar-transp' : |
|
675 | + case '{'.Plugin::NS_CALDAV.'}schedule-calendar-transp' : |
|
676 | 676 | $fieldName = 'transparent'; |
677 | 677 | $newValues[$fieldName] = (int) ($propertyValue->getValue() === 'transparent'); |
678 | 678 | break; |
@@ -782,16 +782,16 @@ discard block |
||
782 | 782 | $stmt = $query->execute(); |
783 | 783 | |
784 | 784 | $result = []; |
785 | - foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
785 | + foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
786 | 786 | $result[] = [ |
787 | 787 | 'id' => $row['id'], |
788 | 788 | 'uri' => $row['uri'], |
789 | 789 | 'lastmodified' => $row['lastmodified'], |
790 | - 'etag' => '"' . $row['etag'] . '"', |
|
790 | + 'etag' => '"'.$row['etag'].'"', |
|
791 | 791 | 'calendarid' => $row['calendarid'], |
792 | - 'size' => (int)$row['size'], |
|
792 | + 'size' => (int) $row['size'], |
|
793 | 793 | 'component' => strtolower($row['componenttype']), |
794 | - 'classification'=> (int)$row['classification'] |
|
794 | + 'classification'=> (int) $row['classification'] |
|
795 | 795 | ]; |
796 | 796 | } |
797 | 797 | |
@@ -824,18 +824,18 @@ discard block |
||
824 | 824 | $stmt = $query->execute(); |
825 | 825 | $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
826 | 826 | |
827 | - if(!$row) return null; |
|
827 | + if (!$row) return null; |
|
828 | 828 | |
829 | 829 | return [ |
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 | 'calendardata' => $this->readBlob($row['calendardata']), |
837 | 837 | 'component' => strtolower($row['componenttype']), |
838 | - 'classification'=> (int)$row['classification'] |
|
838 | + 'classification'=> (int) $row['classification'] |
|
839 | 839 | ]; |
840 | 840 | } |
841 | 841 | |
@@ -874,12 +874,12 @@ discard block |
||
874 | 874 | 'id' => $row['id'], |
875 | 875 | 'uri' => $row['uri'], |
876 | 876 | 'lastmodified' => $row['lastmodified'], |
877 | - 'etag' => '"' . $row['etag'] . '"', |
|
877 | + 'etag' => '"'.$row['etag'].'"', |
|
878 | 878 | 'calendarid' => $row['calendarid'], |
879 | - 'size' => (int)$row['size'], |
|
879 | + 'size' => (int) $row['size'], |
|
880 | 880 | 'calendardata' => $this->readBlob($row['calendardata']), |
881 | 881 | 'component' => strtolower($row['componenttype']), |
882 | - 'classification' => (int)$row['classification'] |
|
882 | + 'classification' => (int) $row['classification'] |
|
883 | 883 | ]; |
884 | 884 | } |
885 | 885 | $result->closeCursor(); |
@@ -936,7 +936,7 @@ discard block |
||
936 | 936 | )); |
937 | 937 | $this->addChange($calendarId, $objectUri, 1); |
938 | 938 | |
939 | - return '"' . $extraData['etag'] . '"'; |
|
939 | + return '"'.$extraData['etag'].'"'; |
|
940 | 940 | } |
941 | 941 | |
942 | 942 | /** |
@@ -989,7 +989,7 @@ discard block |
||
989 | 989 | } |
990 | 990 | $this->addChange($calendarId, $objectUri, 2); |
991 | 991 | |
992 | - return '"' . $extraData['etag'] . '"'; |
|
992 | + return '"'.$extraData['etag'].'"'; |
|
993 | 993 | } |
994 | 994 | |
995 | 995 | /** |
@@ -1140,7 +1140,7 @@ discard block |
||
1140 | 1140 | $stmt = $query->execute(); |
1141 | 1141 | |
1142 | 1142 | $result = []; |
1143 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1143 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1144 | 1144 | if ($requirePostFilter) { |
1145 | 1145 | if (!$this->validateFilterForObject($row, $filters)) { |
1146 | 1146 | continue; |
@@ -1161,14 +1161,14 @@ discard block |
||
1161 | 1161 | * @param integer|null $offset |
1162 | 1162 | * @return array |
1163 | 1163 | */ |
1164 | - public function calendarSearch($principalUri, array $filters, $limit=null, $offset=null) { |
|
1164 | + public function calendarSearch($principalUri, array $filters, $limit = null, $offset = null) { |
|
1165 | 1165 | $calendars = $this->getCalendarsForUser($principalUri); |
1166 | 1166 | $ownCalendars = []; |
1167 | 1167 | $sharedCalendars = []; |
1168 | 1168 | |
1169 | 1169 | $uriMapper = []; |
1170 | 1170 | |
1171 | - foreach($calendars as $calendar) { |
|
1171 | + foreach ($calendars as $calendar) { |
|
1172 | 1172 | if ($calendar['{http://owncloud.org/ns}owner-principal'] === $principalUri) { |
1173 | 1173 | $ownCalendars[] = $calendar['id']; |
1174 | 1174 | } else { |
@@ -1184,11 +1184,11 @@ discard block |
||
1184 | 1184 | |
1185 | 1185 | // Calendar id expressions |
1186 | 1186 | $calendarExpressions = []; |
1187 | - foreach($ownCalendars as $id) { |
|
1187 | + foreach ($ownCalendars as $id) { |
|
1188 | 1188 | $calendarExpressions[] = $query->expr() |
1189 | 1189 | ->eq('calendarid', $query->createNamedParameter($id)); |
1190 | 1190 | } |
1191 | - foreach($sharedCalendars as $id) { |
|
1191 | + foreach ($sharedCalendars as $id) { |
|
1192 | 1192 | $calendarExpressions[] = $query->expr()->andX( |
1193 | 1193 | $query->expr()->eq('calendarid', |
1194 | 1194 | $query->createNamedParameter($id)), |
@@ -1205,7 +1205,7 @@ discard block |
||
1205 | 1205 | |
1206 | 1206 | // Component expressions |
1207 | 1207 | $compExpressions = []; |
1208 | - foreach($filters['comps'] as $comp) { |
|
1208 | + foreach ($filters['comps'] as $comp) { |
|
1209 | 1209 | $compExpressions[] = $query->expr() |
1210 | 1210 | ->eq('componenttype', $query->createNamedParameter($comp)); |
1211 | 1211 | } |
@@ -1218,7 +1218,7 @@ discard block |
||
1218 | 1218 | |
1219 | 1219 | // property and filter expression |
1220 | 1220 | $searchTermFilter = $query->expr()->like('calendardata', |
1221 | - $query->createNamedParameter('%' . $this->db->escapeLikeParameter($filters['search-term']) . '%')); |
|
1221 | + $query->createNamedParameter('%'.$this->db->escapeLikeParameter($filters['search-term']).'%')); |
|
1222 | 1222 | |
1223 | 1223 | $query->select(['calendarid', 'uri', 'calendardata']) |
1224 | 1224 | ->from('calendarobjects') |
@@ -1229,12 +1229,12 @@ discard block |
||
1229 | 1229 | $stmt = $query->execute(); |
1230 | 1230 | |
1231 | 1231 | $result = []; |
1232 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1232 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1233 | 1233 | if (!$this->validateFilterForCalendarSearch($row, $filters)) { |
1234 | 1234 | continue; |
1235 | 1235 | } |
1236 | 1236 | |
1237 | - $result[] = $uriMapper[$row['calendarid']] . '/' . $row['uri']; |
|
1237 | + $result[] = $uriMapper[$row['calendarid']].'/'.$row['uri']; |
|
1238 | 1238 | } |
1239 | 1239 | |
1240 | 1240 | return $result; |
@@ -1291,7 +1291,7 @@ discard block |
||
1291 | 1291 | $stmt = $query->execute(); |
1292 | 1292 | |
1293 | 1293 | if ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
1294 | - return $row['calendaruri'] . '/' . $row['objecturi']; |
|
1294 | + return $row['calendaruri'].'/'.$row['objecturi']; |
|
1295 | 1295 | } |
1296 | 1296 | |
1297 | 1297 | return null; |
@@ -1356,7 +1356,7 @@ discard block |
||
1356 | 1356 | function getChangesForCalendar($calendarId, $syncToken, $syncLevel, $limit = null) { |
1357 | 1357 | // Current synctoken |
1358 | 1358 | $stmt = $this->db->prepare('SELECT `synctoken` FROM `*PREFIX*calendars` WHERE `id` = ?'); |
1359 | - $stmt->execute([ $calendarId ]); |
|
1359 | + $stmt->execute([$calendarId]); |
|
1360 | 1360 | $currentToken = $stmt->fetchColumn(0); |
1361 | 1361 | |
1362 | 1362 | if (is_null($currentToken)) { |
@@ -1373,8 +1373,8 @@ discard block |
||
1373 | 1373 | if ($syncToken) { |
1374 | 1374 | |
1375 | 1375 | $query = "SELECT `uri`, `operation` FROM `*PREFIX*calendarchanges` WHERE `synctoken` >= ? AND `synctoken` < ? AND `calendarid` = ? ORDER BY `synctoken`"; |
1376 | - if ($limit>0) { |
|
1377 | - $query.= " `LIMIT` " . (int)$limit; |
|
1376 | + if ($limit > 0) { |
|
1377 | + $query .= " `LIMIT` ".(int) $limit; |
|
1378 | 1378 | } |
1379 | 1379 | |
1380 | 1380 | // Fetching all changes |
@@ -1385,15 +1385,15 @@ discard block |
||
1385 | 1385 | |
1386 | 1386 | // This loop ensures that any duplicates are overwritten, only the |
1387 | 1387 | // last change on a node is relevant. |
1388 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1388 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1389 | 1389 | |
1390 | 1390 | $changes[$row['uri']] = $row['operation']; |
1391 | 1391 | |
1392 | 1392 | } |
1393 | 1393 | |
1394 | - foreach($changes as $uri => $operation) { |
|
1394 | + foreach ($changes as $uri => $operation) { |
|
1395 | 1395 | |
1396 | - switch($operation) { |
|
1396 | + switch ($operation) { |
|
1397 | 1397 | case 1 : |
1398 | 1398 | $result['added'][] = $uri; |
1399 | 1399 | break; |
@@ -1463,10 +1463,10 @@ discard block |
||
1463 | 1463 | ->from('calendarsubscriptions') |
1464 | 1464 | ->where($query->expr()->eq('principaluri', $query->createNamedParameter($principalUri))) |
1465 | 1465 | ->orderBy('calendarorder', 'asc'); |
1466 | - $stmt =$query->execute(); |
|
1466 | + $stmt = $query->execute(); |
|
1467 | 1467 | |
1468 | 1468 | $subscriptions = []; |
1469 | - while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1469 | + while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) { |
|
1470 | 1470 | |
1471 | 1471 | $subscription = [ |
1472 | 1472 | 'id' => $row['id'], |
@@ -1475,10 +1475,10 @@ discard block |
||
1475 | 1475 | 'source' => $row['source'], |
1476 | 1476 | 'lastmodified' => $row['lastmodified'], |
1477 | 1477 | |
1478 | - '{' . Plugin::NS_CALDAV . '}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO', 'VEVENT']), |
|
1478 | + '{'.Plugin::NS_CALDAV.'}supported-calendar-component-set' => new SupportedCalendarComponentSet(['VTODO', 'VEVENT']), |
|
1479 | 1479 | ]; |
1480 | 1480 | |
1481 | - foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1481 | + foreach ($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1482 | 1482 | if (!is_null($row[$dbName])) { |
1483 | 1483 | $subscription[$xmlName] = $row[$dbName]; |
1484 | 1484 | } |
@@ -1517,7 +1517,7 @@ discard block |
||
1517 | 1517 | |
1518 | 1518 | $propertiesBoolean = ['striptodos', 'stripalarms', 'stripattachments']; |
1519 | 1519 | |
1520 | - foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1520 | + foreach ($this->subscriptionPropertyMap as $xmlName=>$dbName) { |
|
1521 | 1521 | if (array_key_exists($xmlName, $properties)) { |
1522 | 1522 | $values[$dbName] = $properties[$xmlName]; |
1523 | 1523 | if (in_array($dbName, $propertiesBoolean)) { |
@@ -1565,7 +1565,7 @@ discard block |
||
1565 | 1565 | |
1566 | 1566 | $newValues = []; |
1567 | 1567 | |
1568 | - foreach($mutations as $propertyName=>$propertyValue) { |
|
1568 | + foreach ($mutations as $propertyName=>$propertyValue) { |
|
1569 | 1569 | if ($propertyName === '{http://calendarserver.org/ns/}source') { |
1570 | 1570 | $newValues['source'] = $propertyValue->getHref(); |
1571 | 1571 | } else { |
@@ -1577,7 +1577,7 @@ discard block |
||
1577 | 1577 | $query = $this->db->getQueryBuilder(); |
1578 | 1578 | $query->update('calendarsubscriptions') |
1579 | 1579 | ->set('lastmodified', $query->createNamedParameter(time())); |
1580 | - foreach($newValues as $fieldName=>$value) { |
|
1580 | + foreach ($newValues as $fieldName=>$value) { |
|
1581 | 1581 | $query->set($fieldName, $query->createNamedParameter($value)); |
1582 | 1582 | } |
1583 | 1583 | $query->where($query->expr()->eq('id', $query->createNamedParameter($subscriptionId))) |
@@ -1627,7 +1627,7 @@ discard block |
||
1627 | 1627 | |
1628 | 1628 | $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
1629 | 1629 | |
1630 | - if(!$row) { |
|
1630 | + if (!$row) { |
|
1631 | 1631 | return null; |
1632 | 1632 | } |
1633 | 1633 | |
@@ -1635,8 +1635,8 @@ discard block |
||
1635 | 1635 | 'uri' => $row['uri'], |
1636 | 1636 | 'calendardata' => $row['calendardata'], |
1637 | 1637 | 'lastmodified' => $row['lastmodified'], |
1638 | - 'etag' => '"' . $row['etag'] . '"', |
|
1639 | - 'size' => (int)$row['size'], |
|
1638 | + 'etag' => '"'.$row['etag'].'"', |
|
1639 | + 'size' => (int) $row['size'], |
|
1640 | 1640 | ]; |
1641 | 1641 | } |
1642 | 1642 | |
@@ -1659,13 +1659,13 @@ discard block |
||
1659 | 1659 | ->execute(); |
1660 | 1660 | |
1661 | 1661 | $result = []; |
1662 | - foreach($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
1662 | + foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) { |
|
1663 | 1663 | $result[] = [ |
1664 | 1664 | 'calendardata' => $row['calendardata'], |
1665 | 1665 | 'uri' => $row['uri'], |
1666 | 1666 | 'lastmodified' => $row['lastmodified'], |
1667 | - 'etag' => '"' . $row['etag'] . '"', |
|
1668 | - 'size' => (int)$row['size'], |
|
1667 | + 'etag' => '"'.$row['etag'].'"', |
|
1668 | + 'size' => (int) $row['size'], |
|
1669 | 1669 | ]; |
1670 | 1670 | } |
1671 | 1671 | |
@@ -1757,10 +1757,10 @@ discard block |
||
1757 | 1757 | $lastOccurrence = null; |
1758 | 1758 | $uid = null; |
1759 | 1759 | $classification = self::CLASSIFICATION_PUBLIC; |
1760 | - foreach($vObject->getComponents() as $component) { |
|
1761 | - if ($component->name!=='VTIMEZONE') { |
|
1760 | + foreach ($vObject->getComponents() as $component) { |
|
1761 | + if ($component->name !== 'VTIMEZONE') { |
|
1762 | 1762 | $componentType = $component->name; |
1763 | - $uid = (string)$component->UID; |
|
1763 | + $uid = (string) $component->UID; |
|
1764 | 1764 | break; |
1765 | 1765 | } |
1766 | 1766 | } |
@@ -1785,13 +1785,13 @@ discard block |
||
1785 | 1785 | $lastOccurrence = $firstOccurrence; |
1786 | 1786 | } |
1787 | 1787 | } else { |
1788 | - $it = new EventIterator($vObject, (string)$component->UID); |
|
1788 | + $it = new EventIterator($vObject, (string) $component->UID); |
|
1789 | 1789 | $maxDate = new \DateTime(self::MAX_DATE); |
1790 | 1790 | if ($it->isInfinite()) { |
1791 | 1791 | $lastOccurrence = $maxDate->getTimestamp(); |
1792 | 1792 | } else { |
1793 | 1793 | $end = $it->getDtEnd(); |
1794 | - while($it->valid() && $end < $maxDate) { |
|
1794 | + while ($it->valid() && $end < $maxDate) { |
|
1795 | 1795 | $end = $it->getDtEnd(); |
1796 | 1796 | $it->next(); |
1797 | 1797 |
@@ -55,192 +55,192 @@ |
||
55 | 55 | |
56 | 56 | class Server { |
57 | 57 | |
58 | - /** @var IRequest */ |
|
59 | - private $request; |
|
60 | - |
|
61 | - /** @var string */ |
|
62 | - private $baseUri; |
|
63 | - |
|
64 | - /** @var Connector\Sabre\Server */ |
|
65 | - private $server; |
|
66 | - |
|
67 | - public function __construct(IRequest $request, $baseUri) { |
|
68 | - $this->request = $request; |
|
69 | - $this->baseUri = $baseUri; |
|
70 | - $logger = \OC::$server->getLogger(); |
|
71 | - $mailer = \OC::$server->getMailer(); |
|
72 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
73 | - |
|
74 | - $root = new RootCollection(); |
|
75 | - $this->server = new \OCA\DAV\Connector\Sabre\Server($root); |
|
76 | - |
|
77 | - // Add maintenance plugin |
|
78 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig())); |
|
79 | - |
|
80 | - // Backends |
|
81 | - $authBackend = new Auth( |
|
82 | - \OC::$server->getSession(), |
|
83 | - \OC::$server->getUserSession(), |
|
84 | - \OC::$server->getRequest(), |
|
85 | - \OC::$server->getTwoFactorAuthManager(), |
|
86 | - \OC::$server->getBruteForceThrottler() |
|
87 | - ); |
|
88 | - |
|
89 | - // Set URL explicitly due to reverse-proxy situations |
|
90 | - $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
91 | - $this->server->setBaseUri($this->baseUri); |
|
92 | - |
|
93 | - $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
94 | - $authPlugin = new Plugin(); |
|
95 | - $authPlugin->addBackend(new PublicAuth()); |
|
96 | - $this->server->addPlugin($authPlugin); |
|
97 | - |
|
98 | - // allow setup of additional auth backends |
|
99 | - $event = new SabrePluginEvent($this->server); |
|
100 | - $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
101 | - |
|
102 | - // because we are throwing exceptions this plugin has to be the last one |
|
103 | - $authPlugin->addBackend($authBackend); |
|
104 | - |
|
105 | - // debugging |
|
106 | - if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
107 | - $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
108 | - } else { |
|
109 | - $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
110 | - } |
|
111 | - |
|
112 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
113 | - $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
114 | - $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
115 | - |
|
116 | - // acl |
|
117 | - $acl = new DavAclPlugin(); |
|
118 | - $acl->principalCollectionSet = [ |
|
119 | - 'principals/users', 'principals/groups' |
|
120 | - ]; |
|
121 | - $acl->defaultUsernamePath = 'principals/users'; |
|
122 | - $this->server->addPlugin($acl); |
|
123 | - |
|
124 | - // calendar plugins |
|
125 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
126 | - $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); |
|
127 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
|
128 | - $this->server->addPlugin(new IMipPlugin($mailer, $logger)); |
|
129 | - $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
130 | - $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
131 | - $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
132 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
133 | - \OC::$server->getConfig(), |
|
134 | - \OC::$server->getURLGenerator() |
|
135 | - )); |
|
136 | - |
|
137 | - // addressbook plugins |
|
138 | - $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
139 | - $this->server->addPlugin(new VCFExportPlugin()); |
|
140 | - $this->server->addPlugin(new ImageExportPlugin(\OC::$server->getLogger())); |
|
141 | - |
|
142 | - // system tags plugins |
|
143 | - $this->server->addPlugin(new SystemTagPlugin( |
|
144 | - \OC::$server->getSystemTagManager(), |
|
145 | - \OC::$server->getGroupManager(), |
|
146 | - \OC::$server->getUserSession() |
|
147 | - )); |
|
148 | - |
|
149 | - // comments plugin |
|
150 | - $this->server->addPlugin(new CommentsPlugin( |
|
151 | - \OC::$server->getCommentsManager(), |
|
152 | - \OC::$server->getUserSession() |
|
153 | - )); |
|
154 | - |
|
155 | - $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
156 | - |
|
157 | - // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
158 | - // we do not provide locking we emulate it using a fake locking plugin. |
|
159 | - if($request->isUserAgent([ |
|
160 | - '/WebDAVFS/', |
|
161 | - '/Microsoft Office OneNote 2013/', |
|
162 | - '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
163 | - ])) { |
|
164 | - $this->server->addPlugin(new FakeLockerPlugin()); |
|
165 | - } |
|
166 | - |
|
167 | - if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
168 | - $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
169 | - } |
|
170 | - |
|
171 | - // wait with registering these until auth is handled and the filesystem is setup |
|
172 | - $this->server->on('beforeMethod', function () { |
|
173 | - // custom properties plugin must be the last one |
|
174 | - $userSession = \OC::$server->getUserSession(); |
|
175 | - $user = $userSession->getUser(); |
|
176 | - if ($user !== null) { |
|
177 | - $view = \OC\Files\Filesystem::getView(); |
|
178 | - $this->server->addPlugin( |
|
179 | - new FilesPlugin( |
|
180 | - $this->server->tree, |
|
181 | - \OC::$server->getConfig(), |
|
182 | - $this->request, |
|
183 | - \OC::$server->getPreviewManager(), |
|
184 | - false, |
|
185 | - !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
186 | - ) |
|
187 | - ); |
|
188 | - |
|
189 | - $this->server->addPlugin( |
|
190 | - new \Sabre\DAV\PropertyStorage\Plugin( |
|
191 | - new CustomPropertiesBackend( |
|
192 | - $this->server->tree, |
|
193 | - \OC::$server->getDatabaseConnection(), |
|
194 | - \OC::$server->getUserSession()->getUser() |
|
195 | - ) |
|
196 | - ) |
|
197 | - ); |
|
198 | - if ($view !== null) { |
|
199 | - $this->server->addPlugin( |
|
200 | - new QuotaPlugin($view)); |
|
201 | - } |
|
202 | - $this->server->addPlugin( |
|
203 | - new TagsPlugin( |
|
204 | - $this->server->tree, \OC::$server->getTagManager() |
|
205 | - ) |
|
206 | - ); |
|
207 | - // TODO: switch to LazyUserFolder |
|
208 | - $userFolder = \OC::$server->getUserFolder(); |
|
209 | - $this->server->addPlugin(new SharesPlugin( |
|
210 | - $this->server->tree, |
|
211 | - $userSession, |
|
212 | - $userFolder, |
|
213 | - \OC::$server->getShareManager() |
|
214 | - )); |
|
215 | - $this->server->addPlugin(new CommentPropertiesPlugin( |
|
216 | - \OC::$server->getCommentsManager(), |
|
217 | - $userSession |
|
218 | - )); |
|
219 | - $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); |
|
220 | - if ($view !== null) { |
|
221 | - $this->server->addPlugin(new FilesReportPlugin( |
|
222 | - $this->server->tree, |
|
223 | - $view, |
|
224 | - \OC::$server->getSystemTagManager(), |
|
225 | - \OC::$server->getSystemTagObjectMapper(), |
|
226 | - \OC::$server->getTagManager(), |
|
227 | - $userSession, |
|
228 | - \OC::$server->getGroupManager(), |
|
229 | - $userFolder |
|
230 | - )); |
|
231 | - $this->server->addPlugin(new SearchPlugin(new \OCA\DAV\Files\FileSearchBackend( |
|
232 | - $this->server->tree, |
|
233 | - $user, |
|
234 | - \OC::$server->getRootFolder(), |
|
235 | - \OC::$server->getShareManager(), |
|
236 | - $view |
|
237 | - ))); |
|
238 | - } |
|
239 | - } |
|
240 | - }); |
|
241 | - } |
|
242 | - |
|
243 | - public function exec() { |
|
244 | - $this->server->exec(); |
|
245 | - } |
|
58 | + /** @var IRequest */ |
|
59 | + private $request; |
|
60 | + |
|
61 | + /** @var string */ |
|
62 | + private $baseUri; |
|
63 | + |
|
64 | + /** @var Connector\Sabre\Server */ |
|
65 | + private $server; |
|
66 | + |
|
67 | + public function __construct(IRequest $request, $baseUri) { |
|
68 | + $this->request = $request; |
|
69 | + $this->baseUri = $baseUri; |
|
70 | + $logger = \OC::$server->getLogger(); |
|
71 | + $mailer = \OC::$server->getMailer(); |
|
72 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
73 | + |
|
74 | + $root = new RootCollection(); |
|
75 | + $this->server = new \OCA\DAV\Connector\Sabre\Server($root); |
|
76 | + |
|
77 | + // Add maintenance plugin |
|
78 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig())); |
|
79 | + |
|
80 | + // Backends |
|
81 | + $authBackend = new Auth( |
|
82 | + \OC::$server->getSession(), |
|
83 | + \OC::$server->getUserSession(), |
|
84 | + \OC::$server->getRequest(), |
|
85 | + \OC::$server->getTwoFactorAuthManager(), |
|
86 | + \OC::$server->getBruteForceThrottler() |
|
87 | + ); |
|
88 | + |
|
89 | + // Set URL explicitly due to reverse-proxy situations |
|
90 | + $this->server->httpRequest->setUrl($this->request->getRequestUri()); |
|
91 | + $this->server->setBaseUri($this->baseUri); |
|
92 | + |
|
93 | + $this->server->addPlugin(new BlockLegacyClientPlugin(\OC::$server->getConfig())); |
|
94 | + $authPlugin = new Plugin(); |
|
95 | + $authPlugin->addBackend(new PublicAuth()); |
|
96 | + $this->server->addPlugin($authPlugin); |
|
97 | + |
|
98 | + // allow setup of additional auth backends |
|
99 | + $event = new SabrePluginEvent($this->server); |
|
100 | + $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event); |
|
101 | + |
|
102 | + // because we are throwing exceptions this plugin has to be the last one |
|
103 | + $authPlugin->addBackend($authBackend); |
|
104 | + |
|
105 | + // debugging |
|
106 | + if(\OC::$server->getConfig()->getSystemValue('debug', false)) { |
|
107 | + $this->server->addPlugin(new \Sabre\DAV\Browser\Plugin()); |
|
108 | + } else { |
|
109 | + $this->server->addPlugin(new DummyGetResponsePlugin()); |
|
110 | + } |
|
111 | + |
|
112 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\ExceptionLoggerPlugin('webdav', $logger)); |
|
113 | + $this->server->addPlugin(new \OCA\DAV\Connector\Sabre\LockPlugin()); |
|
114 | + $this->server->addPlugin(new \Sabre\DAV\Sync\Plugin()); |
|
115 | + |
|
116 | + // acl |
|
117 | + $acl = new DavAclPlugin(); |
|
118 | + $acl->principalCollectionSet = [ |
|
119 | + 'principals/users', 'principals/groups' |
|
120 | + ]; |
|
121 | + $acl->defaultUsernamePath = 'principals/users'; |
|
122 | + $this->server->addPlugin($acl); |
|
123 | + |
|
124 | + // calendar plugins |
|
125 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Plugin()); |
|
126 | + $this->server->addPlugin(new \Sabre\CalDAV\ICSExportPlugin()); |
|
127 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Schedule\Plugin()); |
|
128 | + $this->server->addPlugin(new IMipPlugin($mailer, $logger)); |
|
129 | + $this->server->addPlugin(new \Sabre\CalDAV\Subscriptions\Plugin()); |
|
130 | + $this->server->addPlugin(new \Sabre\CalDAV\Notifications\Plugin()); |
|
131 | + $this->server->addPlugin(new DAV\Sharing\Plugin($authBackend, \OC::$server->getRequest())); |
|
132 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Publishing\PublishPlugin( |
|
133 | + \OC::$server->getConfig(), |
|
134 | + \OC::$server->getURLGenerator() |
|
135 | + )); |
|
136 | + |
|
137 | + // addressbook plugins |
|
138 | + $this->server->addPlugin(new \OCA\DAV\CardDAV\Plugin()); |
|
139 | + $this->server->addPlugin(new VCFExportPlugin()); |
|
140 | + $this->server->addPlugin(new ImageExportPlugin(\OC::$server->getLogger())); |
|
141 | + |
|
142 | + // system tags plugins |
|
143 | + $this->server->addPlugin(new SystemTagPlugin( |
|
144 | + \OC::$server->getSystemTagManager(), |
|
145 | + \OC::$server->getGroupManager(), |
|
146 | + \OC::$server->getUserSession() |
|
147 | + )); |
|
148 | + |
|
149 | + // comments plugin |
|
150 | + $this->server->addPlugin(new CommentsPlugin( |
|
151 | + \OC::$server->getCommentsManager(), |
|
152 | + \OC::$server->getUserSession() |
|
153 | + )); |
|
154 | + |
|
155 | + $this->server->addPlugin(new CopyEtagHeaderPlugin()); |
|
156 | + |
|
157 | + // Some WebDAV clients do require Class 2 WebDAV support (locking), since |
|
158 | + // we do not provide locking we emulate it using a fake locking plugin. |
|
159 | + if($request->isUserAgent([ |
|
160 | + '/WebDAVFS/', |
|
161 | + '/Microsoft Office OneNote 2013/', |
|
162 | + '/^Microsoft-WebDAV/',// Microsoft-WebDAV-MiniRedir/6.1.7601 |
|
163 | + ])) { |
|
164 | + $this->server->addPlugin(new FakeLockerPlugin()); |
|
165 | + } |
|
166 | + |
|
167 | + if (BrowserErrorPagePlugin::isBrowserRequest($request)) { |
|
168 | + $this->server->addPlugin(new BrowserErrorPagePlugin()); |
|
169 | + } |
|
170 | + |
|
171 | + // wait with registering these until auth is handled and the filesystem is setup |
|
172 | + $this->server->on('beforeMethod', function () { |
|
173 | + // custom properties plugin must be the last one |
|
174 | + $userSession = \OC::$server->getUserSession(); |
|
175 | + $user = $userSession->getUser(); |
|
176 | + if ($user !== null) { |
|
177 | + $view = \OC\Files\Filesystem::getView(); |
|
178 | + $this->server->addPlugin( |
|
179 | + new FilesPlugin( |
|
180 | + $this->server->tree, |
|
181 | + \OC::$server->getConfig(), |
|
182 | + $this->request, |
|
183 | + \OC::$server->getPreviewManager(), |
|
184 | + false, |
|
185 | + !\OC::$server->getConfig()->getSystemValue('debug', false) |
|
186 | + ) |
|
187 | + ); |
|
188 | + |
|
189 | + $this->server->addPlugin( |
|
190 | + new \Sabre\DAV\PropertyStorage\Plugin( |
|
191 | + new CustomPropertiesBackend( |
|
192 | + $this->server->tree, |
|
193 | + \OC::$server->getDatabaseConnection(), |
|
194 | + \OC::$server->getUserSession()->getUser() |
|
195 | + ) |
|
196 | + ) |
|
197 | + ); |
|
198 | + if ($view !== null) { |
|
199 | + $this->server->addPlugin( |
|
200 | + new QuotaPlugin($view)); |
|
201 | + } |
|
202 | + $this->server->addPlugin( |
|
203 | + new TagsPlugin( |
|
204 | + $this->server->tree, \OC::$server->getTagManager() |
|
205 | + ) |
|
206 | + ); |
|
207 | + // TODO: switch to LazyUserFolder |
|
208 | + $userFolder = \OC::$server->getUserFolder(); |
|
209 | + $this->server->addPlugin(new SharesPlugin( |
|
210 | + $this->server->tree, |
|
211 | + $userSession, |
|
212 | + $userFolder, |
|
213 | + \OC::$server->getShareManager() |
|
214 | + )); |
|
215 | + $this->server->addPlugin(new CommentPropertiesPlugin( |
|
216 | + \OC::$server->getCommentsManager(), |
|
217 | + $userSession |
|
218 | + )); |
|
219 | + $this->server->addPlugin(new \OCA\DAV\CalDAV\Search\SearchPlugin()); |
|
220 | + if ($view !== null) { |
|
221 | + $this->server->addPlugin(new FilesReportPlugin( |
|
222 | + $this->server->tree, |
|
223 | + $view, |
|
224 | + \OC::$server->getSystemTagManager(), |
|
225 | + \OC::$server->getSystemTagObjectMapper(), |
|
226 | + \OC::$server->getTagManager(), |
|
227 | + $userSession, |
|
228 | + \OC::$server->getGroupManager(), |
|
229 | + $userFolder |
|
230 | + )); |
|
231 | + $this->server->addPlugin(new SearchPlugin(new \OCA\DAV\Files\FileSearchBackend( |
|
232 | + $this->server->tree, |
|
233 | + $user, |
|
234 | + \OC::$server->getRootFolder(), |
|
235 | + \OC::$server->getShareManager(), |
|
236 | + $view |
|
237 | + ))); |
|
238 | + } |
|
239 | + } |
|
240 | + }); |
|
241 | + } |
|
242 | + |
|
243 | + public function exec() { |
|
244 | + $this->server->exec(); |
|
245 | + } |
|
246 | 246 | } |