@@ -245,7 +245,9 @@ |
||
245 | 245 | function httpGet(RequestInterface $request, ResponseInterface $response) { |
246 | 246 | // Only handle valid files |
247 | 247 | $node = $this->tree->getNodeForPath($request->getPath()); |
248 | - if (!($node instanceof IFile)) return; |
|
248 | + if (!($node instanceof IFile)) { |
|
249 | + return; |
|
250 | + } |
|
249 | 251 | |
250 | 252 | // adds a 'Content-Disposition: attachment' header in case no disposition |
251 | 253 | // header has been set before |
@@ -448,7 +448,7 @@ |
||
448 | 448 | * |
449 | 449 | * @param string $path source path |
450 | 450 | * @param string $destination destination path |
451 | - * @return bool|void false to stop handling, void to skip this handler |
|
451 | + * @return null|false false to stop handling, void to skip this handler |
|
452 | 452 | */ |
453 | 453 | public function beforeMoveFutureFile($path, $destination) { |
454 | 454 | $sourceNode = $this->tree->getNodeForPath($path); |
@@ -49,441 +49,441 @@ |
||
49 | 49 | |
50 | 50 | class FilesPlugin extends ServerPlugin { |
51 | 51 | |
52 | - // namespace |
|
53 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
54 | - const NS_NEXTCLOUD = 'http://nextcloud.org/ns'; |
|
55 | - const FILEID_PROPERTYNAME = '{http://owncloud.org/ns}id'; |
|
56 | - const INTERNAL_FILEID_PROPERTYNAME = '{http://owncloud.org/ns}fileid'; |
|
57 | - const PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}permissions'; |
|
58 | - const SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-collaboration-services.org/ns}share-permissions'; |
|
59 | - const DOWNLOADURL_PROPERTYNAME = '{http://owncloud.org/ns}downloadURL'; |
|
60 | - const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size'; |
|
61 | - const GETETAG_PROPERTYNAME = '{DAV:}getetag'; |
|
62 | - const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified'; |
|
63 | - const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id'; |
|
64 | - const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name'; |
|
65 | - const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums'; |
|
66 | - const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint'; |
|
67 | - const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview'; |
|
68 | - const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type'; |
|
69 | - |
|
70 | - /** |
|
71 | - * Reference to main server object |
|
72 | - * |
|
73 | - * @var \Sabre\DAV\Server |
|
74 | - */ |
|
75 | - private $server; |
|
76 | - |
|
77 | - /** |
|
78 | - * @var Tree |
|
79 | - */ |
|
80 | - private $tree; |
|
81 | - |
|
82 | - /** |
|
83 | - * Whether this is public webdav. |
|
84 | - * If true, some returned information will be stripped off. |
|
85 | - * |
|
86 | - * @var bool |
|
87 | - */ |
|
88 | - private $isPublic; |
|
89 | - |
|
90 | - /** |
|
91 | - * @var View |
|
92 | - */ |
|
93 | - private $fileView; |
|
94 | - |
|
95 | - /** |
|
96 | - * @var bool |
|
97 | - */ |
|
98 | - private $downloadAttachment; |
|
99 | - |
|
100 | - /** |
|
101 | - * @var IConfig |
|
102 | - */ |
|
103 | - private $config; |
|
104 | - |
|
105 | - /** |
|
106 | - * @var IRequest |
|
107 | - */ |
|
108 | - private $request; |
|
109 | - |
|
110 | - /** |
|
111 | - * @var IPreview |
|
112 | - */ |
|
113 | - private $previewManager; |
|
114 | - |
|
115 | - /** |
|
116 | - * @param Tree $tree |
|
117 | - * @param IConfig $config |
|
118 | - * @param IRequest $request |
|
119 | - * @param IPreview $previewManager |
|
120 | - * @param bool $isPublic |
|
121 | - * @param bool $downloadAttachment |
|
122 | - */ |
|
123 | - public function __construct(Tree $tree, |
|
124 | - IConfig $config, |
|
125 | - IRequest $request, |
|
126 | - IPreview $previewManager, |
|
127 | - $isPublic = false, |
|
128 | - $downloadAttachment = true) { |
|
129 | - $this->tree = $tree; |
|
130 | - $this->config = $config; |
|
131 | - $this->request = $request; |
|
132 | - $this->isPublic = $isPublic; |
|
133 | - $this->downloadAttachment = $downloadAttachment; |
|
134 | - $this->previewManager = $previewManager; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * This initializes the plugin. |
|
139 | - * |
|
140 | - * This function is called by \Sabre\DAV\Server, after |
|
141 | - * addPlugin is called. |
|
142 | - * |
|
143 | - * This method should set up the required event subscriptions. |
|
144 | - * |
|
145 | - * @param \Sabre\DAV\Server $server |
|
146 | - * @return void |
|
147 | - */ |
|
148 | - public function initialize(\Sabre\DAV\Server $server) { |
|
149 | - |
|
150 | - $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
151 | - $server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc'; |
|
152 | - $server->protectedProperties[] = self::FILEID_PROPERTYNAME; |
|
153 | - $server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME; |
|
154 | - $server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME; |
|
155 | - $server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME; |
|
156 | - $server->protectedProperties[] = self::SIZE_PROPERTYNAME; |
|
157 | - $server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME; |
|
158 | - $server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME; |
|
159 | - $server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME; |
|
160 | - $server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME; |
|
161 | - $server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME; |
|
162 | - $server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME; |
|
163 | - $server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME; |
|
164 | - |
|
165 | - // normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH |
|
166 | - $allowedProperties = ['{DAV:}getetag']; |
|
167 | - $server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties); |
|
168 | - |
|
169 | - $this->server = $server; |
|
170 | - $this->server->on('propFind', array($this, 'handleGetProperties')); |
|
171 | - $this->server->on('propPatch', array($this, 'handleUpdateProperties')); |
|
172 | - $this->server->on('afterBind', array($this, 'sendFileIdHeader')); |
|
173 | - $this->server->on('afterWriteContent', array($this, 'sendFileIdHeader')); |
|
174 | - $this->server->on('afterMethod:GET', [$this,'httpGet']); |
|
175 | - $this->server->on('afterMethod:GET', array($this, 'handleDownloadToken')); |
|
176 | - $this->server->on('afterResponse', function($request, ResponseInterface $response) { |
|
177 | - $body = $response->getBody(); |
|
178 | - if (is_resource($body)) { |
|
179 | - fclose($body); |
|
180 | - } |
|
181 | - }); |
|
182 | - $this->server->on('beforeMove', [$this, 'checkMove']); |
|
183 | - $this->server->on('beforeMove', [$this, 'beforeMoveFutureFile']); |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Plugin that checks if a move can actually be performed. |
|
188 | - * |
|
189 | - * @param string $source source path |
|
190 | - * @param string $destination destination path |
|
191 | - * @throws Forbidden |
|
192 | - * @throws NotFound |
|
193 | - */ |
|
194 | - function checkMove($source, $destination) { |
|
195 | - $sourceNode = $this->tree->getNodeForPath($source); |
|
196 | - if (!$sourceNode instanceof Node) { |
|
197 | - return; |
|
198 | - } |
|
199 | - list($sourceDir,) = \Sabre\HTTP\URLUtil::splitPath($source); |
|
200 | - list($destinationDir,) = \Sabre\HTTP\URLUtil::splitPath($destination); |
|
201 | - |
|
202 | - if ($sourceDir !== $destinationDir) { |
|
203 | - $sourceNodeFileInfo = $sourceNode->getFileInfo(); |
|
204 | - if (is_null($sourceNodeFileInfo)) { |
|
205 | - throw new NotFound($source . ' does not exist'); |
|
206 | - } |
|
207 | - |
|
208 | - if (!$sourceNodeFileInfo->isDeletable()) { |
|
209 | - throw new Forbidden($source . " cannot be deleted"); |
|
210 | - } |
|
211 | - } |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * This sets a cookie to be able to recognize the start of the download |
|
216 | - * the content must not be longer than 32 characters and must only contain |
|
217 | - * alphanumeric characters |
|
218 | - * |
|
219 | - * @param RequestInterface $request |
|
220 | - * @param ResponseInterface $response |
|
221 | - */ |
|
222 | - function handleDownloadToken(RequestInterface $request, ResponseInterface $response) { |
|
223 | - $queryParams = $request->getQueryParameters(); |
|
224 | - |
|
225 | - /** |
|
226 | - * this sets a cookie to be able to recognize the start of the download |
|
227 | - * the content must not be longer than 32 characters and must only contain |
|
228 | - * alphanumeric characters |
|
229 | - */ |
|
230 | - if (isset($queryParams['downloadStartSecret'])) { |
|
231 | - $token = $queryParams['downloadStartSecret']; |
|
232 | - if (!isset($token[32]) |
|
233 | - && preg_match('!^[a-zA-Z0-9]+$!', $token) === 1) { |
|
234 | - // FIXME: use $response->setHeader() instead |
|
235 | - setcookie('ocDownloadStarted', $token, time() + 20, '/'); |
|
236 | - } |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * Add headers to file download |
|
242 | - * |
|
243 | - * @param RequestInterface $request |
|
244 | - * @param ResponseInterface $response |
|
245 | - */ |
|
246 | - function httpGet(RequestInterface $request, ResponseInterface $response) { |
|
247 | - // Only handle valid files |
|
248 | - $node = $this->tree->getNodeForPath($request->getPath()); |
|
249 | - if (!($node instanceof IFile)) return; |
|
250 | - |
|
251 | - // adds a 'Content-Disposition: attachment' header in case no disposition |
|
252 | - // header has been set before |
|
253 | - if ($this->downloadAttachment && |
|
254 | - $response->getHeader('Content-Disposition') === null) { |
|
255 | - $filename = $node->getName(); |
|
256 | - if ($this->request->isUserAgent( |
|
257 | - [ |
|
258 | - \OC\AppFramework\Http\Request::USER_AGENT_IE, |
|
259 | - \OC\AppFramework\Http\Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
|
260 | - \OC\AppFramework\Http\Request::USER_AGENT_FREEBOX, |
|
261 | - ])) { |
|
262 | - $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"'); |
|
263 | - } else { |
|
264 | - $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename) |
|
265 | - . '; filename="' . rawurlencode($filename) . '"'); |
|
266 | - } |
|
267 | - } |
|
268 | - |
|
269 | - if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
|
270 | - //Add OC-Checksum header |
|
271 | - /** @var $node File */ |
|
272 | - $checksum = $node->getChecksum(); |
|
273 | - if ($checksum !== null && $checksum !== '') { |
|
274 | - $response->addHeader('OC-Checksum', $checksum); |
|
275 | - } |
|
276 | - } |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Adds all ownCloud-specific properties |
|
281 | - * |
|
282 | - * @param PropFind $propFind |
|
283 | - * @param \Sabre\DAV\INode $node |
|
284 | - * @return void |
|
285 | - */ |
|
286 | - public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) { |
|
287 | - |
|
288 | - $httpRequest = $this->server->httpRequest; |
|
289 | - |
|
290 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
291 | - if (!$node->getFileInfo()->isReadable()) { |
|
292 | - // avoid detecting files through this means |
|
293 | - throw new NotFound(); |
|
294 | - } |
|
295 | - |
|
296 | - $propFind->handle(self::FILEID_PROPERTYNAME, function() use ($node) { |
|
297 | - return $node->getFileId(); |
|
298 | - }); |
|
299 | - |
|
300 | - $propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function() use ($node) { |
|
301 | - return $node->getInternalFileId(); |
|
302 | - }); |
|
303 | - |
|
304 | - $propFind->handle(self::PERMISSIONS_PROPERTYNAME, function() use ($node) { |
|
305 | - $perms = $node->getDavPermissions(); |
|
306 | - if ($this->isPublic) { |
|
307 | - // remove mount information |
|
308 | - $perms = str_replace(['S', 'M'], '', $perms); |
|
309 | - } |
|
310 | - return $perms; |
|
311 | - }); |
|
312 | - |
|
313 | - $propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) { |
|
314 | - return $node->getSharePermissions( |
|
315 | - $httpRequest->getRawServerValue('PHP_AUTH_USER') |
|
316 | - ); |
|
317 | - }); |
|
318 | - |
|
319 | - $propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) { |
|
320 | - return $node->getETag(); |
|
321 | - }); |
|
322 | - |
|
323 | - $propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) { |
|
324 | - $owner = $node->getOwner(); |
|
325 | - if (!$owner) { |
|
326 | - return null; |
|
327 | - } else { |
|
328 | - return $owner->getUID(); |
|
329 | - } |
|
330 | - }); |
|
331 | - $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) { |
|
332 | - $owner = $node->getOwner(); |
|
333 | - if (!$owner) { |
|
334 | - return null; |
|
335 | - } else { |
|
336 | - return $owner->getDisplayName(); |
|
337 | - } |
|
338 | - }); |
|
339 | - |
|
340 | - $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) { |
|
341 | - return json_encode($this->previewManager->isAvailable($node->getFileInfo())); |
|
342 | - }); |
|
343 | - $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
|
344 | - return $node->getSize(); |
|
345 | - }); |
|
346 | - $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) { |
|
347 | - return $node->getFileInfo()->getMountPoint()->getMountType(); |
|
348 | - }); |
|
349 | - } |
|
350 | - |
|
351 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
352 | - $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) { |
|
353 | - return $this->config->getSystemValue('data-fingerprint', ''); |
|
354 | - }); |
|
355 | - } |
|
356 | - |
|
357 | - if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
|
358 | - $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) { |
|
359 | - /** @var $node \OCA\DAV\Connector\Sabre\File */ |
|
360 | - try { |
|
361 | - $directDownloadUrl = $node->getDirectDownload(); |
|
362 | - if (isset($directDownloadUrl['url'])) { |
|
363 | - return $directDownloadUrl['url']; |
|
364 | - } |
|
365 | - } catch (StorageNotAvailableException $e) { |
|
366 | - return false; |
|
367 | - } catch (ForbiddenException $e) { |
|
368 | - return false; |
|
369 | - } |
|
370 | - return false; |
|
371 | - }); |
|
372 | - |
|
373 | - $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) { |
|
374 | - $checksum = $node->getChecksum(); |
|
375 | - if ($checksum === NULL || $checksum === '') { |
|
376 | - return null; |
|
377 | - } |
|
378 | - |
|
379 | - return new ChecksumList($checksum); |
|
380 | - }); |
|
381 | - |
|
382 | - } |
|
383 | - |
|
384 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) { |
|
385 | - $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
|
386 | - return $node->getSize(); |
|
387 | - }); |
|
388 | - } |
|
389 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * Update ownCloud-specific properties |
|
393 | - * |
|
394 | - * @param string $path |
|
395 | - * @param PropPatch $propPatch |
|
396 | - * |
|
397 | - * @return void |
|
398 | - */ |
|
399 | - public function handleUpdateProperties($path, PropPatch $propPatch) { |
|
400 | - $node = $this->tree->getNodeForPath($path); |
|
401 | - if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
402 | - return; |
|
403 | - } |
|
404 | - |
|
405 | - $propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function($time) use ($node) { |
|
406 | - if (empty($time)) { |
|
407 | - return false; |
|
408 | - } |
|
409 | - $node->touch($time); |
|
410 | - return true; |
|
411 | - }); |
|
412 | - $propPatch->handle(self::GETETAG_PROPERTYNAME, function($etag) use ($node) { |
|
413 | - if (empty($etag)) { |
|
414 | - return false; |
|
415 | - } |
|
416 | - if ($node->setEtag($etag) !== -1) { |
|
417 | - return true; |
|
418 | - } |
|
419 | - return false; |
|
420 | - }); |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * @param string $filePath |
|
425 | - * @param \Sabre\DAV\INode $node |
|
426 | - * @throws \Sabre\DAV\Exception\BadRequest |
|
427 | - */ |
|
428 | - public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) { |
|
429 | - // chunked upload handling |
|
430 | - if (isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
431 | - list($path, $name) = \Sabre\HTTP\URLUtil::splitPath($filePath); |
|
432 | - $info = \OC_FileChunking::decodeName($name); |
|
433 | - if (!empty($info)) { |
|
434 | - $filePath = $path . '/' . $info['name']; |
|
435 | - } |
|
436 | - } |
|
437 | - |
|
438 | - // we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder |
|
439 | - if (!$this->server->tree->nodeExists($filePath)) { |
|
440 | - return; |
|
441 | - } |
|
442 | - $node = $this->server->tree->getNodeForPath($filePath); |
|
443 | - if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
444 | - $fileId = $node->getFileId(); |
|
445 | - if (!is_null($fileId)) { |
|
446 | - $this->server->httpResponse->setHeader('OC-FileId', $fileId); |
|
447 | - } |
|
448 | - } |
|
449 | - } |
|
450 | - |
|
451 | - /** |
|
452 | - * Move handler for future file. |
|
453 | - * |
|
454 | - * This overrides the default move behavior to prevent Sabre |
|
455 | - * to delete the target file before moving. Because deleting would |
|
456 | - * lose the file id and metadata. |
|
457 | - * |
|
458 | - * @param string $path source path |
|
459 | - * @param string $destination destination path |
|
460 | - * @return bool|void false to stop handling, void to skip this handler |
|
461 | - */ |
|
462 | - public function beforeMoveFutureFile($path, $destination) { |
|
463 | - $sourceNode = $this->tree->getNodeForPath($path); |
|
464 | - if (!$sourceNode instanceof FutureFile) { |
|
465 | - // skip handling as the source is not a chunked FutureFile |
|
466 | - return; |
|
467 | - } |
|
468 | - |
|
469 | - if (!$this->tree->nodeExists($destination)) { |
|
470 | - // skip and let the default handler do its work |
|
471 | - return; |
|
472 | - } |
|
473 | - |
|
474 | - // do a move manually, skipping Sabre's default "delete" for existing nodes |
|
475 | - $this->tree->move($path, $destination); |
|
476 | - |
|
477 | - // trigger all default events (copied from CorePlugin::move) |
|
478 | - $this->server->emit('afterMove', [$path, $destination]); |
|
479 | - $this->server->emit('afterUnbind', [$path]); |
|
480 | - $this->server->emit('afterBind', [$destination]); |
|
481 | - |
|
482 | - $response = $this->server->httpResponse; |
|
483 | - $response->setHeader('Content-Length', '0'); |
|
484 | - $response->setStatus(204); |
|
485 | - |
|
486 | - return false; |
|
487 | - } |
|
52 | + // namespace |
|
53 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
54 | + const NS_NEXTCLOUD = 'http://nextcloud.org/ns'; |
|
55 | + const FILEID_PROPERTYNAME = '{http://owncloud.org/ns}id'; |
|
56 | + const INTERNAL_FILEID_PROPERTYNAME = '{http://owncloud.org/ns}fileid'; |
|
57 | + const PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}permissions'; |
|
58 | + const SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-collaboration-services.org/ns}share-permissions'; |
|
59 | + const DOWNLOADURL_PROPERTYNAME = '{http://owncloud.org/ns}downloadURL'; |
|
60 | + const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size'; |
|
61 | + const GETETAG_PROPERTYNAME = '{DAV:}getetag'; |
|
62 | + const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified'; |
|
63 | + const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id'; |
|
64 | + const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name'; |
|
65 | + const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums'; |
|
66 | + const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint'; |
|
67 | + const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview'; |
|
68 | + const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type'; |
|
69 | + |
|
70 | + /** |
|
71 | + * Reference to main server object |
|
72 | + * |
|
73 | + * @var \Sabre\DAV\Server |
|
74 | + */ |
|
75 | + private $server; |
|
76 | + |
|
77 | + /** |
|
78 | + * @var Tree |
|
79 | + */ |
|
80 | + private $tree; |
|
81 | + |
|
82 | + /** |
|
83 | + * Whether this is public webdav. |
|
84 | + * If true, some returned information will be stripped off. |
|
85 | + * |
|
86 | + * @var bool |
|
87 | + */ |
|
88 | + private $isPublic; |
|
89 | + |
|
90 | + /** |
|
91 | + * @var View |
|
92 | + */ |
|
93 | + private $fileView; |
|
94 | + |
|
95 | + /** |
|
96 | + * @var bool |
|
97 | + */ |
|
98 | + private $downloadAttachment; |
|
99 | + |
|
100 | + /** |
|
101 | + * @var IConfig |
|
102 | + */ |
|
103 | + private $config; |
|
104 | + |
|
105 | + /** |
|
106 | + * @var IRequest |
|
107 | + */ |
|
108 | + private $request; |
|
109 | + |
|
110 | + /** |
|
111 | + * @var IPreview |
|
112 | + */ |
|
113 | + private $previewManager; |
|
114 | + |
|
115 | + /** |
|
116 | + * @param Tree $tree |
|
117 | + * @param IConfig $config |
|
118 | + * @param IRequest $request |
|
119 | + * @param IPreview $previewManager |
|
120 | + * @param bool $isPublic |
|
121 | + * @param bool $downloadAttachment |
|
122 | + */ |
|
123 | + public function __construct(Tree $tree, |
|
124 | + IConfig $config, |
|
125 | + IRequest $request, |
|
126 | + IPreview $previewManager, |
|
127 | + $isPublic = false, |
|
128 | + $downloadAttachment = true) { |
|
129 | + $this->tree = $tree; |
|
130 | + $this->config = $config; |
|
131 | + $this->request = $request; |
|
132 | + $this->isPublic = $isPublic; |
|
133 | + $this->downloadAttachment = $downloadAttachment; |
|
134 | + $this->previewManager = $previewManager; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * This initializes the plugin. |
|
139 | + * |
|
140 | + * This function is called by \Sabre\DAV\Server, after |
|
141 | + * addPlugin is called. |
|
142 | + * |
|
143 | + * This method should set up the required event subscriptions. |
|
144 | + * |
|
145 | + * @param \Sabre\DAV\Server $server |
|
146 | + * @return void |
|
147 | + */ |
|
148 | + public function initialize(\Sabre\DAV\Server $server) { |
|
149 | + |
|
150 | + $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc'; |
|
151 | + $server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc'; |
|
152 | + $server->protectedProperties[] = self::FILEID_PROPERTYNAME; |
|
153 | + $server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME; |
|
154 | + $server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME; |
|
155 | + $server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME; |
|
156 | + $server->protectedProperties[] = self::SIZE_PROPERTYNAME; |
|
157 | + $server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME; |
|
158 | + $server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME; |
|
159 | + $server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME; |
|
160 | + $server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME; |
|
161 | + $server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME; |
|
162 | + $server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME; |
|
163 | + $server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME; |
|
164 | + |
|
165 | + // normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH |
|
166 | + $allowedProperties = ['{DAV:}getetag']; |
|
167 | + $server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties); |
|
168 | + |
|
169 | + $this->server = $server; |
|
170 | + $this->server->on('propFind', array($this, 'handleGetProperties')); |
|
171 | + $this->server->on('propPatch', array($this, 'handleUpdateProperties')); |
|
172 | + $this->server->on('afterBind', array($this, 'sendFileIdHeader')); |
|
173 | + $this->server->on('afterWriteContent', array($this, 'sendFileIdHeader')); |
|
174 | + $this->server->on('afterMethod:GET', [$this,'httpGet']); |
|
175 | + $this->server->on('afterMethod:GET', array($this, 'handleDownloadToken')); |
|
176 | + $this->server->on('afterResponse', function($request, ResponseInterface $response) { |
|
177 | + $body = $response->getBody(); |
|
178 | + if (is_resource($body)) { |
|
179 | + fclose($body); |
|
180 | + } |
|
181 | + }); |
|
182 | + $this->server->on('beforeMove', [$this, 'checkMove']); |
|
183 | + $this->server->on('beforeMove', [$this, 'beforeMoveFutureFile']); |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Plugin that checks if a move can actually be performed. |
|
188 | + * |
|
189 | + * @param string $source source path |
|
190 | + * @param string $destination destination path |
|
191 | + * @throws Forbidden |
|
192 | + * @throws NotFound |
|
193 | + */ |
|
194 | + function checkMove($source, $destination) { |
|
195 | + $sourceNode = $this->tree->getNodeForPath($source); |
|
196 | + if (!$sourceNode instanceof Node) { |
|
197 | + return; |
|
198 | + } |
|
199 | + list($sourceDir,) = \Sabre\HTTP\URLUtil::splitPath($source); |
|
200 | + list($destinationDir,) = \Sabre\HTTP\URLUtil::splitPath($destination); |
|
201 | + |
|
202 | + if ($sourceDir !== $destinationDir) { |
|
203 | + $sourceNodeFileInfo = $sourceNode->getFileInfo(); |
|
204 | + if (is_null($sourceNodeFileInfo)) { |
|
205 | + throw new NotFound($source . ' does not exist'); |
|
206 | + } |
|
207 | + |
|
208 | + if (!$sourceNodeFileInfo->isDeletable()) { |
|
209 | + throw new Forbidden($source . " cannot be deleted"); |
|
210 | + } |
|
211 | + } |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * This sets a cookie to be able to recognize the start of the download |
|
216 | + * the content must not be longer than 32 characters and must only contain |
|
217 | + * alphanumeric characters |
|
218 | + * |
|
219 | + * @param RequestInterface $request |
|
220 | + * @param ResponseInterface $response |
|
221 | + */ |
|
222 | + function handleDownloadToken(RequestInterface $request, ResponseInterface $response) { |
|
223 | + $queryParams = $request->getQueryParameters(); |
|
224 | + |
|
225 | + /** |
|
226 | + * this sets a cookie to be able to recognize the start of the download |
|
227 | + * the content must not be longer than 32 characters and must only contain |
|
228 | + * alphanumeric characters |
|
229 | + */ |
|
230 | + if (isset($queryParams['downloadStartSecret'])) { |
|
231 | + $token = $queryParams['downloadStartSecret']; |
|
232 | + if (!isset($token[32]) |
|
233 | + && preg_match('!^[a-zA-Z0-9]+$!', $token) === 1) { |
|
234 | + // FIXME: use $response->setHeader() instead |
|
235 | + setcookie('ocDownloadStarted', $token, time() + 20, '/'); |
|
236 | + } |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * Add headers to file download |
|
242 | + * |
|
243 | + * @param RequestInterface $request |
|
244 | + * @param ResponseInterface $response |
|
245 | + */ |
|
246 | + function httpGet(RequestInterface $request, ResponseInterface $response) { |
|
247 | + // Only handle valid files |
|
248 | + $node = $this->tree->getNodeForPath($request->getPath()); |
|
249 | + if (!($node instanceof IFile)) return; |
|
250 | + |
|
251 | + // adds a 'Content-Disposition: attachment' header in case no disposition |
|
252 | + // header has been set before |
|
253 | + if ($this->downloadAttachment && |
|
254 | + $response->getHeader('Content-Disposition') === null) { |
|
255 | + $filename = $node->getName(); |
|
256 | + if ($this->request->isUserAgent( |
|
257 | + [ |
|
258 | + \OC\AppFramework\Http\Request::USER_AGENT_IE, |
|
259 | + \OC\AppFramework\Http\Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
|
260 | + \OC\AppFramework\Http\Request::USER_AGENT_FREEBOX, |
|
261 | + ])) { |
|
262 | + $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"'); |
|
263 | + } else { |
|
264 | + $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename) |
|
265 | + . '; filename="' . rawurlencode($filename) . '"'); |
|
266 | + } |
|
267 | + } |
|
268 | + |
|
269 | + if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
|
270 | + //Add OC-Checksum header |
|
271 | + /** @var $node File */ |
|
272 | + $checksum = $node->getChecksum(); |
|
273 | + if ($checksum !== null && $checksum !== '') { |
|
274 | + $response->addHeader('OC-Checksum', $checksum); |
|
275 | + } |
|
276 | + } |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * Adds all ownCloud-specific properties |
|
281 | + * |
|
282 | + * @param PropFind $propFind |
|
283 | + * @param \Sabre\DAV\INode $node |
|
284 | + * @return void |
|
285 | + */ |
|
286 | + public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) { |
|
287 | + |
|
288 | + $httpRequest = $this->server->httpRequest; |
|
289 | + |
|
290 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
291 | + if (!$node->getFileInfo()->isReadable()) { |
|
292 | + // avoid detecting files through this means |
|
293 | + throw new NotFound(); |
|
294 | + } |
|
295 | + |
|
296 | + $propFind->handle(self::FILEID_PROPERTYNAME, function() use ($node) { |
|
297 | + return $node->getFileId(); |
|
298 | + }); |
|
299 | + |
|
300 | + $propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function() use ($node) { |
|
301 | + return $node->getInternalFileId(); |
|
302 | + }); |
|
303 | + |
|
304 | + $propFind->handle(self::PERMISSIONS_PROPERTYNAME, function() use ($node) { |
|
305 | + $perms = $node->getDavPermissions(); |
|
306 | + if ($this->isPublic) { |
|
307 | + // remove mount information |
|
308 | + $perms = str_replace(['S', 'M'], '', $perms); |
|
309 | + } |
|
310 | + return $perms; |
|
311 | + }); |
|
312 | + |
|
313 | + $propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) { |
|
314 | + return $node->getSharePermissions( |
|
315 | + $httpRequest->getRawServerValue('PHP_AUTH_USER') |
|
316 | + ); |
|
317 | + }); |
|
318 | + |
|
319 | + $propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) { |
|
320 | + return $node->getETag(); |
|
321 | + }); |
|
322 | + |
|
323 | + $propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) { |
|
324 | + $owner = $node->getOwner(); |
|
325 | + if (!$owner) { |
|
326 | + return null; |
|
327 | + } else { |
|
328 | + return $owner->getUID(); |
|
329 | + } |
|
330 | + }); |
|
331 | + $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) { |
|
332 | + $owner = $node->getOwner(); |
|
333 | + if (!$owner) { |
|
334 | + return null; |
|
335 | + } else { |
|
336 | + return $owner->getDisplayName(); |
|
337 | + } |
|
338 | + }); |
|
339 | + |
|
340 | + $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) { |
|
341 | + return json_encode($this->previewManager->isAvailable($node->getFileInfo())); |
|
342 | + }); |
|
343 | + $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
|
344 | + return $node->getSize(); |
|
345 | + }); |
|
346 | + $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) { |
|
347 | + return $node->getFileInfo()->getMountPoint()->getMountType(); |
|
348 | + }); |
|
349 | + } |
|
350 | + |
|
351 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
352 | + $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) { |
|
353 | + return $this->config->getSystemValue('data-fingerprint', ''); |
|
354 | + }); |
|
355 | + } |
|
356 | + |
|
357 | + if ($node instanceof \OCA\DAV\Connector\Sabre\File) { |
|
358 | + $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) { |
|
359 | + /** @var $node \OCA\DAV\Connector\Sabre\File */ |
|
360 | + try { |
|
361 | + $directDownloadUrl = $node->getDirectDownload(); |
|
362 | + if (isset($directDownloadUrl['url'])) { |
|
363 | + return $directDownloadUrl['url']; |
|
364 | + } |
|
365 | + } catch (StorageNotAvailableException $e) { |
|
366 | + return false; |
|
367 | + } catch (ForbiddenException $e) { |
|
368 | + return false; |
|
369 | + } |
|
370 | + return false; |
|
371 | + }); |
|
372 | + |
|
373 | + $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) { |
|
374 | + $checksum = $node->getChecksum(); |
|
375 | + if ($checksum === NULL || $checksum === '') { |
|
376 | + return null; |
|
377 | + } |
|
378 | + |
|
379 | + return new ChecksumList($checksum); |
|
380 | + }); |
|
381 | + |
|
382 | + } |
|
383 | + |
|
384 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) { |
|
385 | + $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
|
386 | + return $node->getSize(); |
|
387 | + }); |
|
388 | + } |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * Update ownCloud-specific properties |
|
393 | + * |
|
394 | + * @param string $path |
|
395 | + * @param PropPatch $propPatch |
|
396 | + * |
|
397 | + * @return void |
|
398 | + */ |
|
399 | + public function handleUpdateProperties($path, PropPatch $propPatch) { |
|
400 | + $node = $this->tree->getNodeForPath($path); |
|
401 | + if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) { |
|
402 | + return; |
|
403 | + } |
|
404 | + |
|
405 | + $propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function($time) use ($node) { |
|
406 | + if (empty($time)) { |
|
407 | + return false; |
|
408 | + } |
|
409 | + $node->touch($time); |
|
410 | + return true; |
|
411 | + }); |
|
412 | + $propPatch->handle(self::GETETAG_PROPERTYNAME, function($etag) use ($node) { |
|
413 | + if (empty($etag)) { |
|
414 | + return false; |
|
415 | + } |
|
416 | + if ($node->setEtag($etag) !== -1) { |
|
417 | + return true; |
|
418 | + } |
|
419 | + return false; |
|
420 | + }); |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * @param string $filePath |
|
425 | + * @param \Sabre\DAV\INode $node |
|
426 | + * @throws \Sabre\DAV\Exception\BadRequest |
|
427 | + */ |
|
428 | + public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) { |
|
429 | + // chunked upload handling |
|
430 | + if (isset($_SERVER['HTTP_OC_CHUNKED'])) { |
|
431 | + list($path, $name) = \Sabre\HTTP\URLUtil::splitPath($filePath); |
|
432 | + $info = \OC_FileChunking::decodeName($name); |
|
433 | + if (!empty($info)) { |
|
434 | + $filePath = $path . '/' . $info['name']; |
|
435 | + } |
|
436 | + } |
|
437 | + |
|
438 | + // we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder |
|
439 | + if (!$this->server->tree->nodeExists($filePath)) { |
|
440 | + return; |
|
441 | + } |
|
442 | + $node = $this->server->tree->getNodeForPath($filePath); |
|
443 | + if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { |
|
444 | + $fileId = $node->getFileId(); |
|
445 | + if (!is_null($fileId)) { |
|
446 | + $this->server->httpResponse->setHeader('OC-FileId', $fileId); |
|
447 | + } |
|
448 | + } |
|
449 | + } |
|
450 | + |
|
451 | + /** |
|
452 | + * Move handler for future file. |
|
453 | + * |
|
454 | + * This overrides the default move behavior to prevent Sabre |
|
455 | + * to delete the target file before moving. Because deleting would |
|
456 | + * lose the file id and metadata. |
|
457 | + * |
|
458 | + * @param string $path source path |
|
459 | + * @param string $destination destination path |
|
460 | + * @return bool|void false to stop handling, void to skip this handler |
|
461 | + */ |
|
462 | + public function beforeMoveFutureFile($path, $destination) { |
|
463 | + $sourceNode = $this->tree->getNodeForPath($path); |
|
464 | + if (!$sourceNode instanceof FutureFile) { |
|
465 | + // skip handling as the source is not a chunked FutureFile |
|
466 | + return; |
|
467 | + } |
|
468 | + |
|
469 | + if (!$this->tree->nodeExists($destination)) { |
|
470 | + // skip and let the default handler do its work |
|
471 | + return; |
|
472 | + } |
|
473 | + |
|
474 | + // do a move manually, skipping Sabre's default "delete" for existing nodes |
|
475 | + $this->tree->move($path, $destination); |
|
476 | + |
|
477 | + // trigger all default events (copied from CorePlugin::move) |
|
478 | + $this->server->emit('afterMove', [$path, $destination]); |
|
479 | + $this->server->emit('afterUnbind', [$path]); |
|
480 | + $this->server->emit('afterBind', [$destination]); |
|
481 | + |
|
482 | + $response = $this->server->httpResponse; |
|
483 | + $response->setHeader('Content-Length', '0'); |
|
484 | + $response->setStatus(204); |
|
485 | + |
|
486 | + return false; |
|
487 | + } |
|
488 | 488 | |
489 | 489 | } |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | $this->server->on('propPatch', array($this, 'handleUpdateProperties')); |
172 | 172 | $this->server->on('afterBind', array($this, 'sendFileIdHeader')); |
173 | 173 | $this->server->on('afterWriteContent', array($this, 'sendFileIdHeader')); |
174 | - $this->server->on('afterMethod:GET', [$this,'httpGet']); |
|
174 | + $this->server->on('afterMethod:GET', [$this, 'httpGet']); |
|
175 | 175 | $this->server->on('afterMethod:GET', array($this, 'handleDownloadToken')); |
176 | 176 | $this->server->on('afterResponse', function($request, ResponseInterface $response) { |
177 | 177 | $body = $response->getBody(); |
@@ -202,11 +202,11 @@ discard block |
||
202 | 202 | if ($sourceDir !== $destinationDir) { |
203 | 203 | $sourceNodeFileInfo = $sourceNode->getFileInfo(); |
204 | 204 | if (is_null($sourceNodeFileInfo)) { |
205 | - throw new NotFound($source . ' does not exist'); |
|
205 | + throw new NotFound($source.' does not exist'); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | if (!$sourceNodeFileInfo->isDeletable()) { |
209 | - throw new Forbidden($source . " cannot be deleted"); |
|
209 | + throw new Forbidden($source." cannot be deleted"); |
|
210 | 210 | } |
211 | 211 | } |
212 | 212 | } |
@@ -259,10 +259,10 @@ discard block |
||
259 | 259 | \OC\AppFramework\Http\Request::USER_AGENT_ANDROID_MOBILE_CHROME, |
260 | 260 | \OC\AppFramework\Http\Request::USER_AGENT_FREEBOX, |
261 | 261 | ])) { |
262 | - $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"'); |
|
262 | + $response->addHeader('Content-Disposition', 'attachment; filename="'.rawurlencode($filename).'"'); |
|
263 | 263 | } else { |
264 | - $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename) |
|
265 | - . '; filename="' . rawurlencode($filename) . '"'); |
|
264 | + $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\''.rawurlencode($filename) |
|
265 | + . '; filename="'.rawurlencode($filename).'"'); |
|
266 | 266 | } |
267 | 267 | } |
268 | 268 | |
@@ -337,13 +337,13 @@ discard block |
||
337 | 337 | } |
338 | 338 | }); |
339 | 339 | |
340 | - $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) { |
|
340 | + $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function() use ($node) { |
|
341 | 341 | return json_encode($this->previewManager->isAvailable($node->getFileInfo())); |
342 | 342 | }); |
343 | 343 | $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) { |
344 | 344 | return $node->getSize(); |
345 | 345 | }); |
346 | - $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) { |
|
346 | + $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function() use ($node) { |
|
347 | 347 | return $node->getFileInfo()->getMountPoint()->getMountType(); |
348 | 348 | }); |
349 | 349 | } |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | list($path, $name) = \Sabre\HTTP\URLUtil::splitPath($filePath); |
432 | 432 | $info = \OC_FileChunking::decodeName($name); |
433 | 433 | if (!empty($info)) { |
434 | - $filePath = $path . '/' . $info['name']; |
|
434 | + $filePath = $path.'/'.$info['name']; |
|
435 | 435 | } |
436 | 436 | } |
437 | 437 |
@@ -32,42 +32,42 @@ |
||
32 | 32 | |
33 | 33 | class LegacyDAVACL extends DavAclPlugin { |
34 | 34 | |
35 | - /** |
|
36 | - * @inheritdoc |
|
37 | - */ |
|
38 | - public function getCurrentUserPrincipals() { |
|
39 | - $principalV2 = $this->getCurrentUserPrincipal(); |
|
35 | + /** |
|
36 | + * @inheritdoc |
|
37 | + */ |
|
38 | + public function getCurrentUserPrincipals() { |
|
39 | + $principalV2 = $this->getCurrentUserPrincipal(); |
|
40 | 40 | |
41 | - if (is_null($principalV2)) return []; |
|
41 | + if (is_null($principalV2)) return []; |
|
42 | 42 | |
43 | - $principalV1 = $this->convertPrincipal($principalV2, false); |
|
44 | - return array_merge( |
|
45 | - [ |
|
46 | - $principalV2, |
|
47 | - $principalV1 |
|
48 | - ], |
|
49 | - $this->getPrincipalMembership($principalV1) |
|
50 | - ); |
|
51 | - } |
|
43 | + $principalV1 = $this->convertPrincipal($principalV2, false); |
|
44 | + return array_merge( |
|
45 | + [ |
|
46 | + $principalV2, |
|
47 | + $principalV1 |
|
48 | + ], |
|
49 | + $this->getPrincipalMembership($principalV1) |
|
50 | + ); |
|
51 | + } |
|
52 | 52 | |
53 | - private function convertPrincipal($principal, $toV2) { |
|
54 | - list(, $name) = URLUtil::splitPath($principal); |
|
55 | - if ($toV2) { |
|
56 | - return "principals/users/$name"; |
|
57 | - } |
|
58 | - return "principals/$name"; |
|
59 | - } |
|
53 | + private function convertPrincipal($principal, $toV2) { |
|
54 | + list(, $name) = URLUtil::splitPath($principal); |
|
55 | + if ($toV2) { |
|
56 | + return "principals/users/$name"; |
|
57 | + } |
|
58 | + return "principals/$name"; |
|
59 | + } |
|
60 | 60 | |
61 | - public function propFind(PropFind $propFind, INode $node) { |
|
62 | - /* Overload current-user-principal */ |
|
63 | - $propFind->handle('{DAV:}current-user-principal', function () { |
|
64 | - if ($url = parent::getCurrentUserPrincipal()) { |
|
65 | - return new Principal(Principal::HREF, $url . '/'); |
|
66 | - } else { |
|
67 | - return new Principal(Principal::UNAUTHENTICATED); |
|
68 | - } |
|
69 | - }); |
|
61 | + public function propFind(PropFind $propFind, INode $node) { |
|
62 | + /* Overload current-user-principal */ |
|
63 | + $propFind->handle('{DAV:}current-user-principal', function () { |
|
64 | + if ($url = parent::getCurrentUserPrincipal()) { |
|
65 | + return new Principal(Principal::HREF, $url . '/'); |
|
66 | + } else { |
|
67 | + return new Principal(Principal::UNAUTHENTICATED); |
|
68 | + } |
|
69 | + }); |
|
70 | 70 | |
71 | - return parent::propFind($propFind, $node); |
|
72 | - } |
|
71 | + return parent::propFind($propFind, $node); |
|
72 | + } |
|
73 | 73 | } |
@@ -60,9 +60,9 @@ |
||
60 | 60 | |
61 | 61 | public function propFind(PropFind $propFind, INode $node) { |
62 | 62 | /* Overload current-user-principal */ |
63 | - $propFind->handle('{DAV:}current-user-principal', function () { |
|
63 | + $propFind->handle('{DAV:}current-user-principal', function() { |
|
64 | 64 | if ($url = parent::getCurrentUserPrincipal()) { |
65 | - return new Principal(Principal::HREF, $url . '/'); |
|
65 | + return new Principal(Principal::HREF, $url.'/'); |
|
66 | 66 | } else { |
67 | 67 | return new Principal(Principal::UNAUTHENTICATED); |
68 | 68 | } |
@@ -38,7 +38,9 @@ |
||
38 | 38 | public function getCurrentUserPrincipals() { |
39 | 39 | $principalV2 = $this->getCurrentUserPrincipal(); |
40 | 40 | |
41 | - if (is_null($principalV2)) return []; |
|
41 | + if (is_null($principalV2)) { |
|
42 | + return []; |
|
43 | + } |
|
42 | 44 | |
43 | 45 | $principalV1 = $this->convertPrincipal($principalV2, false); |
44 | 46 | return array_merge( |
@@ -70,7 +70,7 @@ |
||
70 | 70 | $dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
71 | 71 | |
72 | 72 | // first time login event setup |
73 | - $dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) { |
|
73 | + $dispatcher->addListener(IUser::class.'::firstLogin', function($event) use ($hm) { |
|
74 | 74 | if ($event instanceof GenericEvent) { |
75 | 75 | $hm->firstLogin($event->getSubject()); |
76 | 76 | } |
@@ -40,156 +40,156 @@ |
||
40 | 40 | |
41 | 41 | class Application extends App { |
42 | 42 | |
43 | - /** |
|
44 | - * Application constructor. |
|
45 | - */ |
|
46 | - public function __construct() { |
|
47 | - parent::__construct('dav'); |
|
48 | - |
|
49 | - $container = $this->getContainer(); |
|
50 | - $server = $container->getServer(); |
|
51 | - |
|
52 | - $container->registerService(PhotoCache::class, function(SimpleContainer $s) use ($server) { |
|
53 | - return new PhotoCache( |
|
54 | - $server->getAppDataDir('dav-photocache') |
|
55 | - ); |
|
56 | - }); |
|
57 | - |
|
58 | - /* |
|
43 | + /** |
|
44 | + * Application constructor. |
|
45 | + */ |
|
46 | + public function __construct() { |
|
47 | + parent::__construct('dav'); |
|
48 | + |
|
49 | + $container = $this->getContainer(); |
|
50 | + $server = $container->getServer(); |
|
51 | + |
|
52 | + $container->registerService(PhotoCache::class, function(SimpleContainer $s) use ($server) { |
|
53 | + return new PhotoCache( |
|
54 | + $server->getAppDataDir('dav-photocache') |
|
55 | + ); |
|
56 | + }); |
|
57 | + |
|
58 | + /* |
|
59 | 59 | * Register capabilities |
60 | 60 | */ |
61 | - $container->registerCapability(Capabilities::class); |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * @param IManager $contactsManager |
|
66 | - * @param string $userID |
|
67 | - */ |
|
68 | - public function setupContactsProvider(IManager $contactsManager, $userID) { |
|
69 | - /** @var ContactsManager $cm */ |
|
70 | - $cm = $this->getContainer()->query(ContactsManager::class); |
|
71 | - $urlGenerator = $this->getContainer()->getServer()->getURLGenerator(); |
|
72 | - $cm->setupContactsProvider($contactsManager, $userID, $urlGenerator); |
|
73 | - } |
|
74 | - |
|
75 | - public function registerHooks() { |
|
76 | - /** @var HookManager $hm */ |
|
77 | - $hm = $this->getContainer()->query(HookManager::class); |
|
78 | - $hm->setup(); |
|
79 | - |
|
80 | - $dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
|
81 | - |
|
82 | - // first time login event setup |
|
83 | - $dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) { |
|
84 | - if ($event instanceof GenericEvent) { |
|
85 | - $hm->firstLogin($event->getSubject()); |
|
86 | - } |
|
87 | - }); |
|
88 | - |
|
89 | - // carddav/caldav sync event setup |
|
90 | - $listener = function($event) { |
|
91 | - if ($event instanceof GenericEvent) { |
|
92 | - /** @var BirthdayService $b */ |
|
93 | - $b = $this->getContainer()->query(BirthdayService::class); |
|
94 | - $b->onCardChanged( |
|
95 | - $event->getArgument('addressBookId'), |
|
96 | - $event->getArgument('cardUri'), |
|
97 | - $event->getArgument('cardData') |
|
98 | - ); |
|
99 | - } |
|
100 | - }; |
|
101 | - |
|
102 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $listener); |
|
103 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $listener); |
|
104 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) { |
|
105 | - if ($event instanceof GenericEvent) { |
|
106 | - /** @var BirthdayService $b */ |
|
107 | - $b = $this->getContainer()->query(BirthdayService::class); |
|
108 | - $b->onCardDeleted( |
|
109 | - $event->getArgument('addressBookId'), |
|
110 | - $event->getArgument('cardUri') |
|
111 | - ); |
|
112 | - } |
|
113 | - }); |
|
114 | - |
|
115 | - $clearPhotoCache = function($event) { |
|
116 | - if ($event instanceof GenericEvent) { |
|
117 | - /** @var PhotoCache $p */ |
|
118 | - $p = $this->getContainer()->query(PhotoCache::class); |
|
119 | - $p->delete( |
|
120 | - $event->getArgument('addressBookId'), |
|
121 | - $event->getArgument('cardUri') |
|
122 | - ); |
|
123 | - } |
|
124 | - }; |
|
125 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache); |
|
126 | - $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache); |
|
127 | - |
|
128 | - $dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) { |
|
129 | - $user = $event->getSubject(); |
|
130 | - $syncService = $this->getContainer()->query(SyncService::class); |
|
131 | - $syncService->updateUser($user); |
|
132 | - }); |
|
133 | - |
|
134 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function(GenericEvent $event) { |
|
135 | - /** @var Backend $backend */ |
|
136 | - $backend = $this->getContainer()->query(Backend::class); |
|
137 | - $backend->onCalendarAdd( |
|
138 | - $event->getArgument('calendarData') |
|
139 | - ); |
|
140 | - }); |
|
141 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function(GenericEvent $event) { |
|
142 | - /** @var Backend $backend */ |
|
143 | - $backend = $this->getContainer()->query(Backend::class); |
|
144 | - $backend->onCalendarUpdate( |
|
145 | - $event->getArgument('calendarData'), |
|
146 | - $event->getArgument('shares'), |
|
147 | - $event->getArgument('propertyMutations') |
|
148 | - ); |
|
149 | - }); |
|
150 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function(GenericEvent $event) { |
|
151 | - /** @var Backend $backend */ |
|
152 | - $backend = $this->getContainer()->query(Backend::class); |
|
153 | - $backend->onCalendarDelete( |
|
154 | - $event->getArgument('calendarData'), |
|
155 | - $event->getArgument('shares') |
|
156 | - ); |
|
157 | - }); |
|
158 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function(GenericEvent $event) { |
|
159 | - /** @var Backend $backend */ |
|
160 | - $backend = $this->getContainer()->query(Backend::class); |
|
161 | - $backend->onCalendarUpdateShares( |
|
162 | - $event->getArgument('calendarData'), |
|
163 | - $event->getArgument('shares'), |
|
164 | - $event->getArgument('add'), |
|
165 | - $event->getArgument('remove') |
|
166 | - ); |
|
167 | - }); |
|
168 | - |
|
169 | - $listener = function(GenericEvent $event, $eventName) { |
|
170 | - /** @var Backend $backend */ |
|
171 | - $backend = $this->getContainer()->query(Backend::class); |
|
172 | - |
|
173 | - $subject = Event::SUBJECT_OBJECT_ADD; |
|
174 | - if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') { |
|
175 | - $subject = Event::SUBJECT_OBJECT_UPDATE; |
|
176 | - } else if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') { |
|
177 | - $subject = Event::SUBJECT_OBJECT_DELETE; |
|
178 | - } |
|
179 | - $backend->onTouchCalendarObject( |
|
180 | - $subject, |
|
181 | - $event->getArgument('calendarData'), |
|
182 | - $event->getArgument('shares'), |
|
183 | - $event->getArgument('objectData') |
|
184 | - ); |
|
185 | - }; |
|
186 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener); |
|
187 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener); |
|
188 | - $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener); |
|
189 | - } |
|
190 | - |
|
191 | - public function getSyncService() { |
|
192 | - return $this->getContainer()->query(SyncService::class); |
|
193 | - } |
|
61 | + $container->registerCapability(Capabilities::class); |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * @param IManager $contactsManager |
|
66 | + * @param string $userID |
|
67 | + */ |
|
68 | + public function setupContactsProvider(IManager $contactsManager, $userID) { |
|
69 | + /** @var ContactsManager $cm */ |
|
70 | + $cm = $this->getContainer()->query(ContactsManager::class); |
|
71 | + $urlGenerator = $this->getContainer()->getServer()->getURLGenerator(); |
|
72 | + $cm->setupContactsProvider($contactsManager, $userID, $urlGenerator); |
|
73 | + } |
|
74 | + |
|
75 | + public function registerHooks() { |
|
76 | + /** @var HookManager $hm */ |
|
77 | + $hm = $this->getContainer()->query(HookManager::class); |
|
78 | + $hm->setup(); |
|
79 | + |
|
80 | + $dispatcher = $this->getContainer()->getServer()->getEventDispatcher(); |
|
81 | + |
|
82 | + // first time login event setup |
|
83 | + $dispatcher->addListener(IUser::class . '::firstLogin', function ($event) use ($hm) { |
|
84 | + if ($event instanceof GenericEvent) { |
|
85 | + $hm->firstLogin($event->getSubject()); |
|
86 | + } |
|
87 | + }); |
|
88 | + |
|
89 | + // carddav/caldav sync event setup |
|
90 | + $listener = function($event) { |
|
91 | + if ($event instanceof GenericEvent) { |
|
92 | + /** @var BirthdayService $b */ |
|
93 | + $b = $this->getContainer()->query(BirthdayService::class); |
|
94 | + $b->onCardChanged( |
|
95 | + $event->getArgument('addressBookId'), |
|
96 | + $event->getArgument('cardUri'), |
|
97 | + $event->getArgument('cardData') |
|
98 | + ); |
|
99 | + } |
|
100 | + }; |
|
101 | + |
|
102 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::createCard', $listener); |
|
103 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $listener); |
|
104 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', function($event) { |
|
105 | + if ($event instanceof GenericEvent) { |
|
106 | + /** @var BirthdayService $b */ |
|
107 | + $b = $this->getContainer()->query(BirthdayService::class); |
|
108 | + $b->onCardDeleted( |
|
109 | + $event->getArgument('addressBookId'), |
|
110 | + $event->getArgument('cardUri') |
|
111 | + ); |
|
112 | + } |
|
113 | + }); |
|
114 | + |
|
115 | + $clearPhotoCache = function($event) { |
|
116 | + if ($event instanceof GenericEvent) { |
|
117 | + /** @var PhotoCache $p */ |
|
118 | + $p = $this->getContainer()->query(PhotoCache::class); |
|
119 | + $p->delete( |
|
120 | + $event->getArgument('addressBookId'), |
|
121 | + $event->getArgument('cardUri') |
|
122 | + ); |
|
123 | + } |
|
124 | + }; |
|
125 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $clearPhotoCache); |
|
126 | + $dispatcher->addListener('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $clearPhotoCache); |
|
127 | + |
|
128 | + $dispatcher->addListener('OC\AccountManager::userUpdated', function(GenericEvent $event) { |
|
129 | + $user = $event->getSubject(); |
|
130 | + $syncService = $this->getContainer()->query(SyncService::class); |
|
131 | + $syncService->updateUser($user); |
|
132 | + }); |
|
133 | + |
|
134 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendar', function(GenericEvent $event) { |
|
135 | + /** @var Backend $backend */ |
|
136 | + $backend = $this->getContainer()->query(Backend::class); |
|
137 | + $backend->onCalendarAdd( |
|
138 | + $event->getArgument('calendarData') |
|
139 | + ); |
|
140 | + }); |
|
141 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendar', function(GenericEvent $event) { |
|
142 | + /** @var Backend $backend */ |
|
143 | + $backend = $this->getContainer()->query(Backend::class); |
|
144 | + $backend->onCalendarUpdate( |
|
145 | + $event->getArgument('calendarData'), |
|
146 | + $event->getArgument('shares'), |
|
147 | + $event->getArgument('propertyMutations') |
|
148 | + ); |
|
149 | + }); |
|
150 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendar', function(GenericEvent $event) { |
|
151 | + /** @var Backend $backend */ |
|
152 | + $backend = $this->getContainer()->query(Backend::class); |
|
153 | + $backend->onCalendarDelete( |
|
154 | + $event->getArgument('calendarData'), |
|
155 | + $event->getArgument('shares') |
|
156 | + ); |
|
157 | + }); |
|
158 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateShares', function(GenericEvent $event) { |
|
159 | + /** @var Backend $backend */ |
|
160 | + $backend = $this->getContainer()->query(Backend::class); |
|
161 | + $backend->onCalendarUpdateShares( |
|
162 | + $event->getArgument('calendarData'), |
|
163 | + $event->getArgument('shares'), |
|
164 | + $event->getArgument('add'), |
|
165 | + $event->getArgument('remove') |
|
166 | + ); |
|
167 | + }); |
|
168 | + |
|
169 | + $listener = function(GenericEvent $event, $eventName) { |
|
170 | + /** @var Backend $backend */ |
|
171 | + $backend = $this->getContainer()->query(Backend::class); |
|
172 | + |
|
173 | + $subject = Event::SUBJECT_OBJECT_ADD; |
|
174 | + if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject') { |
|
175 | + $subject = Event::SUBJECT_OBJECT_UPDATE; |
|
176 | + } else if ($eventName === '\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject') { |
|
177 | + $subject = Event::SUBJECT_OBJECT_DELETE; |
|
178 | + } |
|
179 | + $backend->onTouchCalendarObject( |
|
180 | + $subject, |
|
181 | + $event->getArgument('calendarData'), |
|
182 | + $event->getArgument('shares'), |
|
183 | + $event->getArgument('objectData') |
|
184 | + ); |
|
185 | + }; |
|
186 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::createCalendarObject', $listener); |
|
187 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::updateCalendarObject', $listener); |
|
188 | + $dispatcher->addListener('\OCA\DAV\CalDAV\CalDavBackend::deleteCalendarObject', $listener); |
|
189 | + } |
|
190 | + |
|
191 | + public function getSyncService() { |
|
192 | + return $this->getContainer()->query(SyncService::class); |
|
193 | + } |
|
194 | 194 | |
195 | 195 | } |
@@ -28,35 +28,35 @@ |
||
28 | 28 | |
29 | 29 | class FixBirthdayCalendarComponent implements IRepairStep { |
30 | 30 | |
31 | - /** @var IDBConnection */ |
|
32 | - private $connection; |
|
33 | - |
|
34 | - /** |
|
35 | - * FixBirthdayCalendarComponent constructor. |
|
36 | - * |
|
37 | - * @param IDBConnection $connection |
|
38 | - */ |
|
39 | - public function __construct(IDBConnection $connection) { |
|
40 | - $this->connection = $connection; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * @inheritdoc |
|
45 | - */ |
|
46 | - public function getName() { |
|
47 | - return 'Fix component of birthday calendars'; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * @inheritdoc |
|
52 | - */ |
|
53 | - public function run(IOutput $output) { |
|
54 | - $query = $this->connection->getQueryBuilder(); |
|
55 | - $updated = $query->update('calendars') |
|
56 | - ->set('components', $query->createNamedParameter('VEVENT')) |
|
57 | - ->where($query->expr()->eq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))) |
|
58 | - ->execute(); |
|
59 | - |
|
60 | - $output->info("$updated birthday calendars updated."); |
|
61 | - } |
|
31 | + /** @var IDBConnection */ |
|
32 | + private $connection; |
|
33 | + |
|
34 | + /** |
|
35 | + * FixBirthdayCalendarComponent constructor. |
|
36 | + * |
|
37 | + * @param IDBConnection $connection |
|
38 | + */ |
|
39 | + public function __construct(IDBConnection $connection) { |
|
40 | + $this->connection = $connection; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * @inheritdoc |
|
45 | + */ |
|
46 | + public function getName() { |
|
47 | + return 'Fix component of birthday calendars'; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * @inheritdoc |
|
52 | + */ |
|
53 | + public function run(IOutput $output) { |
|
54 | + $query = $this->connection->getQueryBuilder(); |
|
55 | + $updated = $query->update('calendars') |
|
56 | + ->set('components', $query->createNamedParameter('VEVENT')) |
|
57 | + ->where($query->expr()->eq('uri', $query->createNamedParameter(BirthdayService::BIRTHDAY_CALENDAR_URI))) |
|
58 | + ->execute(); |
|
59 | + |
|
60 | + $output->info("$updated birthday calendars updated."); |
|
61 | + } |
|
62 | 62 | } |
@@ -33,55 +33,55 @@ |
||
33 | 33 | |
34 | 34 | class SyncBirthdayCalendar extends Command { |
35 | 35 | |
36 | - /** @var BirthdayService */ |
|
37 | - private $birthdayService; |
|
36 | + /** @var BirthdayService */ |
|
37 | + private $birthdayService; |
|
38 | 38 | |
39 | - /** @var IUserManager */ |
|
40 | - private $userManager; |
|
39 | + /** @var IUserManager */ |
|
40 | + private $userManager; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param IUserManager $userManager |
|
44 | - * @param BirthdayService $birthdayService |
|
45 | - */ |
|
46 | - function __construct(IUserManager $userManager, BirthdayService $birthdayService) { |
|
47 | - parent::__construct(); |
|
48 | - $this->birthdayService = $birthdayService; |
|
49 | - $this->userManager = $userManager; |
|
50 | - } |
|
42 | + /** |
|
43 | + * @param IUserManager $userManager |
|
44 | + * @param BirthdayService $birthdayService |
|
45 | + */ |
|
46 | + function __construct(IUserManager $userManager, BirthdayService $birthdayService) { |
|
47 | + parent::__construct(); |
|
48 | + $this->birthdayService = $birthdayService; |
|
49 | + $this->userManager = $userManager; |
|
50 | + } |
|
51 | 51 | |
52 | - protected function configure() { |
|
53 | - $this |
|
54 | - ->setName('dav:sync-birthday-calendar') |
|
55 | - ->setDescription('Synchronizes the birthday calendar') |
|
56 | - ->addArgument('user', |
|
57 | - InputArgument::OPTIONAL, |
|
58 | - 'User for whom the birthday calendar will be synchronized'); |
|
59 | - } |
|
52 | + protected function configure() { |
|
53 | + $this |
|
54 | + ->setName('dav:sync-birthday-calendar') |
|
55 | + ->setDescription('Synchronizes the birthday calendar') |
|
56 | + ->addArgument('user', |
|
57 | + InputArgument::OPTIONAL, |
|
58 | + 'User for whom the birthday calendar will be synchronized'); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param InputInterface $input |
|
63 | - * @param OutputInterface $output |
|
64 | - */ |
|
65 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
66 | - $user = $input->getArgument('user'); |
|
67 | - if (!is_null($user)) { |
|
68 | - if (!$this->userManager->userExists($user)) { |
|
69 | - throw new \InvalidArgumentException("User <$user> in unknown."); |
|
70 | - } |
|
71 | - $output->writeln("Start birthday calendar sync for $user"); |
|
72 | - $this->birthdayService->syncUser($user); |
|
73 | - return; |
|
74 | - } |
|
75 | - $output->writeln("Start birthday calendar sync for all users ..."); |
|
76 | - $p = new ProgressBar($output); |
|
77 | - $p->start(); |
|
78 | - $this->userManager->callForAllUsers(function($user) use ($p) { |
|
79 | - $p->advance(); |
|
80 | - /** @var IUser $user */ |
|
81 | - $this->birthdayService->syncUser($user->getUID()); |
|
82 | - }); |
|
61 | + /** |
|
62 | + * @param InputInterface $input |
|
63 | + * @param OutputInterface $output |
|
64 | + */ |
|
65 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
66 | + $user = $input->getArgument('user'); |
|
67 | + if (!is_null($user)) { |
|
68 | + if (!$this->userManager->userExists($user)) { |
|
69 | + throw new \InvalidArgumentException("User <$user> in unknown."); |
|
70 | + } |
|
71 | + $output->writeln("Start birthday calendar sync for $user"); |
|
72 | + $this->birthdayService->syncUser($user); |
|
73 | + return; |
|
74 | + } |
|
75 | + $output->writeln("Start birthday calendar sync for all users ..."); |
|
76 | + $p = new ProgressBar($output); |
|
77 | + $p->start(); |
|
78 | + $this->userManager->callForAllUsers(function($user) use ($p) { |
|
79 | + $p->advance(); |
|
80 | + /** @var IUser $user */ |
|
81 | + $this->birthdayService->syncUser($user->getUID()); |
|
82 | + }); |
|
83 | 83 | |
84 | - $p->finish(); |
|
85 | - $output->writeln(''); |
|
86 | - } |
|
84 | + $p->finish(); |
|
85 | + $output->writeln(''); |
|
86 | + } |
|
87 | 87 | } |
@@ -31,36 +31,36 @@ |
||
31 | 31 | |
32 | 32 | class SyncSystemAddressBook extends Command { |
33 | 33 | |
34 | - /** @var SyncService */ |
|
35 | - private $syncService; |
|
34 | + /** @var SyncService */ |
|
35 | + private $syncService; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param SyncService $syncService |
|
39 | - */ |
|
40 | - function __construct(SyncService $syncService) { |
|
41 | - parent::__construct(); |
|
42 | - $this->syncService = $syncService; |
|
43 | - } |
|
37 | + /** |
|
38 | + * @param SyncService $syncService |
|
39 | + */ |
|
40 | + function __construct(SyncService $syncService) { |
|
41 | + parent::__construct(); |
|
42 | + $this->syncService = $syncService; |
|
43 | + } |
|
44 | 44 | |
45 | - protected function configure() { |
|
46 | - $this |
|
47 | - ->setName('dav:sync-system-addressbook') |
|
48 | - ->setDescription('Synchronizes users to the system addressbook'); |
|
49 | - } |
|
45 | + protected function configure() { |
|
46 | + $this |
|
47 | + ->setName('dav:sync-system-addressbook') |
|
48 | + ->setDescription('Synchronizes users to the system addressbook'); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param InputInterface $input |
|
53 | - * @param OutputInterface $output |
|
54 | - */ |
|
55 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
56 | - $output->writeln('Syncing users ...'); |
|
57 | - $progress = new ProgressBar($output); |
|
58 | - $progress->start(); |
|
59 | - $this->syncService->syncInstance(function() use ($progress) { |
|
60 | - $progress->advance(); |
|
61 | - }); |
|
51 | + /** |
|
52 | + * @param InputInterface $input |
|
53 | + * @param OutputInterface $output |
|
54 | + */ |
|
55 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
56 | + $output->writeln('Syncing users ...'); |
|
57 | + $progress = new ProgressBar($output); |
|
58 | + $progress->start(); |
|
59 | + $this->syncService->syncInstance(function() use ($progress) { |
|
60 | + $progress->advance(); |
|
61 | + }); |
|
62 | 62 | |
63 | - $progress->finish(); |
|
64 | - $output->writeln(''); |
|
65 | - } |
|
63 | + $progress->finish(); |
|
64 | + $output->writeln(''); |
|
65 | + } |
|
66 | 66 | } |
@@ -33,53 +33,53 @@ |
||
33 | 33 | |
34 | 34 | class CreateCalendar extends Command { |
35 | 35 | |
36 | - /** @var IUserManager */ |
|
37 | - protected $userManager; |
|
36 | + /** @var IUserManager */ |
|
37 | + protected $userManager; |
|
38 | 38 | |
39 | - /** @var IGroupManager $groupManager */ |
|
40 | - private $groupManager; |
|
39 | + /** @var IGroupManager $groupManager */ |
|
40 | + private $groupManager; |
|
41 | 41 | |
42 | - /** @var \OCP\IDBConnection */ |
|
43 | - protected $dbConnection; |
|
42 | + /** @var \OCP\IDBConnection */ |
|
43 | + protected $dbConnection; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param IUserManager $userManager |
|
47 | - * @param IGroupManager $groupManager |
|
48 | - * @param IDBConnection $dbConnection |
|
49 | - */ |
|
50 | - function __construct(IUserManager $userManager, IGroupManager $groupManager, IDBConnection $dbConnection) { |
|
51 | - parent::__construct(); |
|
52 | - $this->userManager = $userManager; |
|
53 | - $this->groupManager = $groupManager; |
|
54 | - $this->dbConnection = $dbConnection; |
|
55 | - } |
|
45 | + /** |
|
46 | + * @param IUserManager $userManager |
|
47 | + * @param IGroupManager $groupManager |
|
48 | + * @param IDBConnection $dbConnection |
|
49 | + */ |
|
50 | + function __construct(IUserManager $userManager, IGroupManager $groupManager, IDBConnection $dbConnection) { |
|
51 | + parent::__construct(); |
|
52 | + $this->userManager = $userManager; |
|
53 | + $this->groupManager = $groupManager; |
|
54 | + $this->dbConnection = $dbConnection; |
|
55 | + } |
|
56 | 56 | |
57 | - protected function configure() { |
|
58 | - $this |
|
59 | - ->setName('dav:create-calendar') |
|
60 | - ->setDescription('Create a dav calendar') |
|
61 | - ->addArgument('user', |
|
62 | - InputArgument::REQUIRED, |
|
63 | - 'User for whom the calendar will be created') |
|
64 | - ->addArgument('name', |
|
65 | - InputArgument::REQUIRED, |
|
66 | - 'Name of the calendar'); |
|
67 | - } |
|
57 | + protected function configure() { |
|
58 | + $this |
|
59 | + ->setName('dav:create-calendar') |
|
60 | + ->setDescription('Create a dav calendar') |
|
61 | + ->addArgument('user', |
|
62 | + InputArgument::REQUIRED, |
|
63 | + 'User for whom the calendar will be created') |
|
64 | + ->addArgument('name', |
|
65 | + InputArgument::REQUIRED, |
|
66 | + 'Name of the calendar'); |
|
67 | + } |
|
68 | 68 | |
69 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
70 | - $user = $input->getArgument('user'); |
|
71 | - if (!$this->userManager->userExists($user)) { |
|
72 | - throw new \InvalidArgumentException("User <$user> in unknown."); |
|
73 | - } |
|
74 | - $principalBackend = new Principal( |
|
75 | - $this->userManager, |
|
76 | - $this->groupManager |
|
77 | - ); |
|
78 | - $random = \OC::$server->getSecureRandom(); |
|
79 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
69 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
70 | + $user = $input->getArgument('user'); |
|
71 | + if (!$this->userManager->userExists($user)) { |
|
72 | + throw new \InvalidArgumentException("User <$user> in unknown."); |
|
73 | + } |
|
74 | + $principalBackend = new Principal( |
|
75 | + $this->userManager, |
|
76 | + $this->groupManager |
|
77 | + ); |
|
78 | + $random = \OC::$server->getSecureRandom(); |
|
79 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
80 | 80 | |
81 | - $name = $input->getArgument('name'); |
|
82 | - $caldav = new CalDavBackend($this->dbConnection, $principalBackend, $this->userManager, $random, $dispatcher); |
|
83 | - $caldav->createCalendar("principals/users/$user", $name, []); |
|
84 | - } |
|
81 | + $name = $input->getArgument('name'); |
|
82 | + $caldav = new CalDavBackend($this->dbConnection, $principalBackend, $this->userManager, $random, $dispatcher); |
|
83 | + $caldav->createCalendar("principals/users/$user", $name, []); |
|
84 | + } |
|
85 | 85 | } |
@@ -36,43 +36,43 @@ |
||
36 | 36 | |
37 | 37 | class CreateAddressBook extends Command { |
38 | 38 | |
39 | - /** @var IUserManager */ |
|
40 | - private $userManager; |
|
39 | + /** @var IUserManager */ |
|
40 | + private $userManager; |
|
41 | 41 | |
42 | - /** @var CardDavBackend */ |
|
43 | - private $cardDavBackend; |
|
42 | + /** @var CardDavBackend */ |
|
43 | + private $cardDavBackend; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param IUserManager $userManager |
|
47 | - * @param CardDavBackend $cardDavBackend |
|
48 | - */ |
|
49 | - function __construct(IUserManager $userManager, |
|
50 | - CardDavBackend $cardDavBackend |
|
51 | - ) { |
|
52 | - parent::__construct(); |
|
53 | - $this->userManager = $userManager; |
|
54 | - $this->cardDavBackend = $cardDavBackend; |
|
55 | - } |
|
45 | + /** |
|
46 | + * @param IUserManager $userManager |
|
47 | + * @param CardDavBackend $cardDavBackend |
|
48 | + */ |
|
49 | + function __construct(IUserManager $userManager, |
|
50 | + CardDavBackend $cardDavBackend |
|
51 | + ) { |
|
52 | + parent::__construct(); |
|
53 | + $this->userManager = $userManager; |
|
54 | + $this->cardDavBackend = $cardDavBackend; |
|
55 | + } |
|
56 | 56 | |
57 | - protected function configure() { |
|
58 | - $this |
|
59 | - ->setName('dav:create-addressbook') |
|
60 | - ->setDescription('Create a dav addressbook') |
|
61 | - ->addArgument('user', |
|
62 | - InputArgument::REQUIRED, |
|
63 | - 'User for whom the addressbook will be created') |
|
64 | - ->addArgument('name', |
|
65 | - InputArgument::REQUIRED, |
|
66 | - 'Name of the addressbook'); |
|
67 | - } |
|
57 | + protected function configure() { |
|
58 | + $this |
|
59 | + ->setName('dav:create-addressbook') |
|
60 | + ->setDescription('Create a dav addressbook') |
|
61 | + ->addArgument('user', |
|
62 | + InputArgument::REQUIRED, |
|
63 | + 'User for whom the addressbook will be created') |
|
64 | + ->addArgument('name', |
|
65 | + InputArgument::REQUIRED, |
|
66 | + 'Name of the addressbook'); |
|
67 | + } |
|
68 | 68 | |
69 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
70 | - $user = $input->getArgument('user'); |
|
71 | - if (!$this->userManager->userExists($user)) { |
|
72 | - throw new \InvalidArgumentException("User <$user> in unknown."); |
|
73 | - } |
|
69 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
70 | + $user = $input->getArgument('user'); |
|
71 | + if (!$this->userManager->userExists($user)) { |
|
72 | + throw new \InvalidArgumentException("User <$user> in unknown."); |
|
73 | + } |
|
74 | 74 | |
75 | - $name = $input->getArgument('name'); |
|
76 | - $this->cardDavBackend->createAddressBook("principals/users/$user", $name, []); |
|
77 | - } |
|
75 | + $name = $input->getArgument('name'); |
|
76 | + $this->cardDavBackend->createAddressBook("principals/users/$user", $name, []); |
|
77 | + } |
|
78 | 78 | } |
@@ -26,11 +26,11 @@ |
||
26 | 26 | |
27 | 27 | class Capabilities implements ICapability { |
28 | 28 | |
29 | - public function getCapabilities() { |
|
30 | - return [ |
|
31 | - 'dav' => [ |
|
32 | - 'chunking' => '1.0', |
|
33 | - ] |
|
34 | - ]; |
|
35 | - } |
|
29 | + public function getCapabilities() { |
|
30 | + return [ |
|
31 | + 'dav' => [ |
|
32 | + 'chunking' => '1.0', |
|
33 | + ] |
|
34 | + ]; |
|
35 | + } |
|
36 | 36 | } |