@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | */ |
87 | 87 | public function setId($id) { |
88 | 88 | if (is_int($id)) { |
89 | - $id = (string)$id; |
|
89 | + $id = (string) $id; |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | if (!is_string($id)) { |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | if ($this->providerId === null || $this->id === null) { |
116 | 116 | throw new \UnexpectedValueException; |
117 | 117 | } |
118 | - return $this->providerId . ':' . $this->id; |
|
118 | + return $this->providerId.':'.$this->id; |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | |
164 | 164 | $nodes = $userFolder->getById($this->fileId); |
165 | 165 | if (empty($nodes)) { |
166 | - throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId); |
|
166 | + throw new NotFoundException('Node for share not found, fileid: '.$this->fileId); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | $this->node = $nodes[0]; |
@@ -40,538 +40,538 @@ |
||
40 | 40 | |
41 | 41 | class Share implements \OCP\Share\IShare { |
42 | 42 | |
43 | - /** @var string */ |
|
44 | - private $id; |
|
45 | - /** @var string */ |
|
46 | - private $providerId; |
|
47 | - /** @var Node */ |
|
48 | - private $node; |
|
49 | - /** @var int */ |
|
50 | - private $fileId; |
|
51 | - /** @var string */ |
|
52 | - private $nodeType; |
|
53 | - /** @var int */ |
|
54 | - private $shareType; |
|
55 | - /** @var string */ |
|
56 | - private $sharedWith; |
|
57 | - /** @var string */ |
|
58 | - private $sharedWithDisplayName; |
|
59 | - /** @var string */ |
|
60 | - private $sharedWithAvatar; |
|
61 | - /** @var string */ |
|
62 | - private $sharedBy; |
|
63 | - /** @var string */ |
|
64 | - private $shareOwner; |
|
65 | - /** @var int */ |
|
66 | - private $permissions; |
|
67 | - /** @var int */ |
|
68 | - private $status; |
|
69 | - /** @var string */ |
|
70 | - private $note = ''; |
|
71 | - /** @var \DateTime */ |
|
72 | - private $expireDate; |
|
73 | - /** @var string */ |
|
74 | - private $password; |
|
75 | - /** @var bool */ |
|
76 | - private $sendPasswordByTalk = false; |
|
77 | - /** @var string */ |
|
78 | - private $token; |
|
79 | - /** @var int */ |
|
80 | - private $parent; |
|
81 | - /** @var string */ |
|
82 | - private $target; |
|
83 | - /** @var \DateTime */ |
|
84 | - private $shareTime; |
|
85 | - /** @var bool */ |
|
86 | - private $mailSend; |
|
87 | - /** @var string */ |
|
88 | - private $label = ''; |
|
89 | - |
|
90 | - /** @var IRootFolder */ |
|
91 | - private $rootFolder; |
|
92 | - |
|
93 | - /** @var IUserManager */ |
|
94 | - private $userManager; |
|
95 | - |
|
96 | - /** @var ICacheEntry|null */ |
|
97 | - private $nodeCacheEntry; |
|
98 | - |
|
99 | - /** @var bool */ |
|
100 | - private $hideDownload = false; |
|
101 | - |
|
102 | - public function __construct(IRootFolder $rootFolder, IUserManager $userManager) { |
|
103 | - $this->rootFolder = $rootFolder; |
|
104 | - $this->userManager = $userManager; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @inheritdoc |
|
109 | - */ |
|
110 | - public function setId($id) { |
|
111 | - if (is_int($id)) { |
|
112 | - $id = (string)$id; |
|
113 | - } |
|
114 | - |
|
115 | - if (!is_string($id)) { |
|
116 | - throw new \InvalidArgumentException('String expected.'); |
|
117 | - } |
|
118 | - |
|
119 | - if ($this->id !== null) { |
|
120 | - throw new IllegalIDChangeException('Not allowed to assign a new internal id to a share'); |
|
121 | - } |
|
122 | - |
|
123 | - $this->id = trim($id); |
|
124 | - return $this; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * @inheritdoc |
|
129 | - */ |
|
130 | - public function getId() { |
|
131 | - return $this->id; |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * @inheritdoc |
|
136 | - */ |
|
137 | - public function getFullId() { |
|
138 | - if ($this->providerId === null || $this->id === null) { |
|
139 | - throw new \UnexpectedValueException; |
|
140 | - } |
|
141 | - return $this->providerId . ':' . $this->id; |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * @inheritdoc |
|
146 | - */ |
|
147 | - public function setProviderId($id) { |
|
148 | - if (!is_string($id)) { |
|
149 | - throw new \InvalidArgumentException('String expected.'); |
|
150 | - } |
|
151 | - |
|
152 | - if ($this->providerId !== null) { |
|
153 | - throw new IllegalIDChangeException('Not allowed to assign a new provider id to a share'); |
|
154 | - } |
|
155 | - |
|
156 | - $this->providerId = trim($id); |
|
157 | - return $this; |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * @inheritdoc |
|
162 | - */ |
|
163 | - public function setNode(Node $node) { |
|
164 | - $this->fileId = null; |
|
165 | - $this->nodeType = null; |
|
166 | - $this->node = $node; |
|
167 | - return $this; |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * @inheritdoc |
|
172 | - */ |
|
173 | - public function getNode() { |
|
174 | - if ($this->node === null) { |
|
175 | - if ($this->shareOwner === null || $this->fileId === null) { |
|
176 | - throw new NotFoundException(); |
|
177 | - } |
|
178 | - |
|
179 | - // for federated shares the owner can be a remote user, in this |
|
180 | - // case we use the initiator |
|
181 | - if ($this->userManager->userExists($this->shareOwner)) { |
|
182 | - $userFolder = $this->rootFolder->getUserFolder($this->shareOwner); |
|
183 | - } else { |
|
184 | - $userFolder = $this->rootFolder->getUserFolder($this->sharedBy); |
|
185 | - } |
|
186 | - |
|
187 | - $nodes = $userFolder->getById($this->fileId); |
|
188 | - if (empty($nodes)) { |
|
189 | - throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId); |
|
190 | - } |
|
191 | - |
|
192 | - $this->node = $nodes[0]; |
|
193 | - } |
|
194 | - |
|
195 | - return $this->node; |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * @inheritdoc |
|
200 | - */ |
|
201 | - public function setNodeId($fileId) { |
|
202 | - $this->node = null; |
|
203 | - $this->fileId = $fileId; |
|
204 | - return $this; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * @inheritdoc |
|
209 | - */ |
|
210 | - public function getNodeId() { |
|
211 | - if ($this->fileId === null) { |
|
212 | - $this->fileId = $this->getNode()->getId(); |
|
213 | - } |
|
214 | - |
|
215 | - return $this->fileId; |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * @inheritdoc |
|
220 | - */ |
|
221 | - public function setNodeType($type) { |
|
222 | - if ($type !== 'file' && $type !== 'folder') { |
|
223 | - throw new \InvalidArgumentException(); |
|
224 | - } |
|
225 | - |
|
226 | - $this->nodeType = $type; |
|
227 | - return $this; |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * @inheritdoc |
|
232 | - */ |
|
233 | - public function getNodeType() { |
|
234 | - if ($this->nodeType === null) { |
|
235 | - $node = $this->getNode(); |
|
236 | - $this->nodeType = $node instanceof File ? 'file' : 'folder'; |
|
237 | - } |
|
238 | - |
|
239 | - return $this->nodeType; |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * @inheritdoc |
|
244 | - */ |
|
245 | - public function setShareType($shareType) { |
|
246 | - $this->shareType = $shareType; |
|
247 | - return $this; |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * @inheritdoc |
|
252 | - */ |
|
253 | - public function getShareType() { |
|
254 | - return $this->shareType; |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * @inheritdoc |
|
259 | - */ |
|
260 | - public function setSharedWith($sharedWith) { |
|
261 | - if (!is_string($sharedWith)) { |
|
262 | - throw new \InvalidArgumentException(); |
|
263 | - } |
|
264 | - $this->sharedWith = $sharedWith; |
|
265 | - return $this; |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * @inheritdoc |
|
270 | - */ |
|
271 | - public function getSharedWith() { |
|
272 | - return $this->sharedWith; |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * @inheritdoc |
|
277 | - */ |
|
278 | - public function setSharedWithDisplayName($displayName) { |
|
279 | - if (!is_string($displayName)) { |
|
280 | - throw new \InvalidArgumentException(); |
|
281 | - } |
|
282 | - $this->sharedWithDisplayName = $displayName; |
|
283 | - return $this; |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * @inheritdoc |
|
288 | - */ |
|
289 | - public function getSharedWithDisplayName() { |
|
290 | - return $this->sharedWithDisplayName; |
|
291 | - } |
|
292 | - |
|
293 | - /** |
|
294 | - * @inheritdoc |
|
295 | - */ |
|
296 | - public function setSharedWithAvatar($src) { |
|
297 | - if (!is_string($src)) { |
|
298 | - throw new \InvalidArgumentException(); |
|
299 | - } |
|
300 | - $this->sharedWithAvatar = $src; |
|
301 | - return $this; |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * @inheritdoc |
|
306 | - */ |
|
307 | - public function getSharedWithAvatar() { |
|
308 | - return $this->sharedWithAvatar; |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * @inheritdoc |
|
313 | - */ |
|
314 | - public function setPermissions($permissions) { |
|
315 | - //TODO checkes |
|
316 | - |
|
317 | - $this->permissions = $permissions; |
|
318 | - return $this; |
|
319 | - } |
|
320 | - |
|
321 | - /** |
|
322 | - * @inheritdoc |
|
323 | - */ |
|
324 | - public function getPermissions() { |
|
325 | - return $this->permissions; |
|
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * @inheritdoc |
|
330 | - */ |
|
331 | - public function setStatus(int $status): IShare { |
|
332 | - $this->status = $status; |
|
333 | - return $this; |
|
334 | - } |
|
335 | - |
|
336 | - /** |
|
337 | - * @inheritdoc |
|
338 | - */ |
|
339 | - public function getStatus(): int { |
|
340 | - return $this->status; |
|
341 | - } |
|
342 | - |
|
343 | - /** |
|
344 | - * @inheritdoc |
|
345 | - */ |
|
346 | - public function setNote($note) { |
|
347 | - $this->note = $note; |
|
348 | - return $this; |
|
349 | - } |
|
350 | - |
|
351 | - /** |
|
352 | - * @inheritdoc |
|
353 | - */ |
|
354 | - public function getNote() { |
|
355 | - if (is_string($this->note)) { |
|
356 | - return $this->note; |
|
357 | - } |
|
358 | - return ''; |
|
359 | - } |
|
360 | - |
|
361 | - /** |
|
362 | - * @inheritdoc |
|
363 | - */ |
|
364 | - public function setLabel($label) { |
|
365 | - $this->label = $label; |
|
366 | - return $this; |
|
367 | - } |
|
368 | - |
|
369 | - /** |
|
370 | - * @inheritdoc |
|
371 | - */ |
|
372 | - public function getLabel() { |
|
373 | - return $this->label; |
|
374 | - } |
|
375 | - |
|
376 | - /** |
|
377 | - * @inheritdoc |
|
378 | - */ |
|
379 | - public function setExpirationDate($expireDate) { |
|
380 | - //TODO checks |
|
381 | - |
|
382 | - $this->expireDate = $expireDate; |
|
383 | - return $this; |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * @inheritdoc |
|
388 | - */ |
|
389 | - public function getExpirationDate() { |
|
390 | - return $this->expireDate; |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * @inheritdoc |
|
395 | - */ |
|
396 | - public function isExpired() { |
|
397 | - return $this->getExpirationDate() !== null && |
|
398 | - $this->getExpirationDate() <= new \DateTime(); |
|
399 | - } |
|
400 | - |
|
401 | - /** |
|
402 | - * @inheritdoc |
|
403 | - */ |
|
404 | - public function setSharedBy($sharedBy) { |
|
405 | - if (!is_string($sharedBy)) { |
|
406 | - throw new \InvalidArgumentException(); |
|
407 | - } |
|
408 | - //TODO checks |
|
409 | - $this->sharedBy = $sharedBy; |
|
410 | - |
|
411 | - return $this; |
|
412 | - } |
|
413 | - |
|
414 | - /** |
|
415 | - * @inheritdoc |
|
416 | - */ |
|
417 | - public function getSharedBy() { |
|
418 | - //TODO check if set |
|
419 | - return $this->sharedBy; |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * @inheritdoc |
|
424 | - */ |
|
425 | - public function setShareOwner($shareOwner) { |
|
426 | - if (!is_string($shareOwner)) { |
|
427 | - throw new \InvalidArgumentException(); |
|
428 | - } |
|
429 | - //TODO checks |
|
430 | - |
|
431 | - $this->shareOwner = $shareOwner; |
|
432 | - return $this; |
|
433 | - } |
|
434 | - |
|
435 | - /** |
|
436 | - * @inheritdoc |
|
437 | - */ |
|
438 | - public function getShareOwner() { |
|
439 | - //TODO check if set |
|
440 | - return $this->shareOwner; |
|
441 | - } |
|
442 | - |
|
443 | - /** |
|
444 | - * @inheritdoc |
|
445 | - */ |
|
446 | - public function setPassword($password) { |
|
447 | - $this->password = $password; |
|
448 | - return $this; |
|
449 | - } |
|
450 | - |
|
451 | - /** |
|
452 | - * @inheritdoc |
|
453 | - */ |
|
454 | - public function getPassword() { |
|
455 | - return $this->password; |
|
456 | - } |
|
457 | - |
|
458 | - /** |
|
459 | - * @inheritdoc |
|
460 | - */ |
|
461 | - public function setSendPasswordByTalk(bool $sendPasswordByTalk) { |
|
462 | - $this->sendPasswordByTalk = $sendPasswordByTalk; |
|
463 | - return $this; |
|
464 | - } |
|
465 | - |
|
466 | - /** |
|
467 | - * @inheritdoc |
|
468 | - */ |
|
469 | - public function getSendPasswordByTalk(): bool { |
|
470 | - return $this->sendPasswordByTalk; |
|
471 | - } |
|
472 | - |
|
473 | - /** |
|
474 | - * @inheritdoc |
|
475 | - */ |
|
476 | - public function setToken($token) { |
|
477 | - $this->token = $token; |
|
478 | - return $this; |
|
479 | - } |
|
480 | - |
|
481 | - /** |
|
482 | - * @inheritdoc |
|
483 | - */ |
|
484 | - public function getToken() { |
|
485 | - return $this->token; |
|
486 | - } |
|
487 | - |
|
488 | - /** |
|
489 | - * Set the parent of this share |
|
490 | - * |
|
491 | - * @param int parent |
|
492 | - * @return \OCP\Share\IShare |
|
493 | - * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
|
494 | - */ |
|
495 | - public function setParent($parent) { |
|
496 | - $this->parent = $parent; |
|
497 | - return $this; |
|
498 | - } |
|
499 | - |
|
500 | - /** |
|
501 | - * Get the parent of this share. |
|
502 | - * |
|
503 | - * @return int |
|
504 | - * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
|
505 | - */ |
|
506 | - public function getParent() { |
|
507 | - return $this->parent; |
|
508 | - } |
|
509 | - |
|
510 | - /** |
|
511 | - * @inheritdoc |
|
512 | - */ |
|
513 | - public function setTarget($target) { |
|
514 | - $this->target = $target; |
|
515 | - return $this; |
|
516 | - } |
|
517 | - |
|
518 | - /** |
|
519 | - * @inheritdoc |
|
520 | - */ |
|
521 | - public function getTarget() { |
|
522 | - return $this->target; |
|
523 | - } |
|
524 | - |
|
525 | - /** |
|
526 | - * @inheritdoc |
|
527 | - */ |
|
528 | - public function setShareTime(\DateTime $shareTime) { |
|
529 | - $this->shareTime = $shareTime; |
|
530 | - return $this; |
|
531 | - } |
|
532 | - |
|
533 | - /** |
|
534 | - * @inheritdoc |
|
535 | - */ |
|
536 | - public function getShareTime() { |
|
537 | - return $this->shareTime; |
|
538 | - } |
|
539 | - |
|
540 | - /** |
|
541 | - * @inheritdoc |
|
542 | - */ |
|
543 | - public function setMailSend($mailSend) { |
|
544 | - $this->mailSend = $mailSend; |
|
545 | - return $this; |
|
546 | - } |
|
547 | - |
|
548 | - /** |
|
549 | - * @inheritdoc |
|
550 | - */ |
|
551 | - public function getMailSend() { |
|
552 | - return $this->mailSend; |
|
553 | - } |
|
554 | - |
|
555 | - /** |
|
556 | - * @inheritdoc |
|
557 | - */ |
|
558 | - public function setNodeCacheEntry(ICacheEntry $entry) { |
|
559 | - $this->nodeCacheEntry = $entry; |
|
560 | - } |
|
561 | - |
|
562 | - /** |
|
563 | - * @inheritdoc |
|
564 | - */ |
|
565 | - public function getNodeCacheEntry() { |
|
566 | - return $this->nodeCacheEntry; |
|
567 | - } |
|
568 | - |
|
569 | - public function setHideDownload(bool $hide): IShare { |
|
570 | - $this->hideDownload = $hide; |
|
571 | - return $this; |
|
572 | - } |
|
573 | - |
|
574 | - public function getHideDownload(): bool { |
|
575 | - return $this->hideDownload; |
|
576 | - } |
|
43 | + /** @var string */ |
|
44 | + private $id; |
|
45 | + /** @var string */ |
|
46 | + private $providerId; |
|
47 | + /** @var Node */ |
|
48 | + private $node; |
|
49 | + /** @var int */ |
|
50 | + private $fileId; |
|
51 | + /** @var string */ |
|
52 | + private $nodeType; |
|
53 | + /** @var int */ |
|
54 | + private $shareType; |
|
55 | + /** @var string */ |
|
56 | + private $sharedWith; |
|
57 | + /** @var string */ |
|
58 | + private $sharedWithDisplayName; |
|
59 | + /** @var string */ |
|
60 | + private $sharedWithAvatar; |
|
61 | + /** @var string */ |
|
62 | + private $sharedBy; |
|
63 | + /** @var string */ |
|
64 | + private $shareOwner; |
|
65 | + /** @var int */ |
|
66 | + private $permissions; |
|
67 | + /** @var int */ |
|
68 | + private $status; |
|
69 | + /** @var string */ |
|
70 | + private $note = ''; |
|
71 | + /** @var \DateTime */ |
|
72 | + private $expireDate; |
|
73 | + /** @var string */ |
|
74 | + private $password; |
|
75 | + /** @var bool */ |
|
76 | + private $sendPasswordByTalk = false; |
|
77 | + /** @var string */ |
|
78 | + private $token; |
|
79 | + /** @var int */ |
|
80 | + private $parent; |
|
81 | + /** @var string */ |
|
82 | + private $target; |
|
83 | + /** @var \DateTime */ |
|
84 | + private $shareTime; |
|
85 | + /** @var bool */ |
|
86 | + private $mailSend; |
|
87 | + /** @var string */ |
|
88 | + private $label = ''; |
|
89 | + |
|
90 | + /** @var IRootFolder */ |
|
91 | + private $rootFolder; |
|
92 | + |
|
93 | + /** @var IUserManager */ |
|
94 | + private $userManager; |
|
95 | + |
|
96 | + /** @var ICacheEntry|null */ |
|
97 | + private $nodeCacheEntry; |
|
98 | + |
|
99 | + /** @var bool */ |
|
100 | + private $hideDownload = false; |
|
101 | + |
|
102 | + public function __construct(IRootFolder $rootFolder, IUserManager $userManager) { |
|
103 | + $this->rootFolder = $rootFolder; |
|
104 | + $this->userManager = $userManager; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @inheritdoc |
|
109 | + */ |
|
110 | + public function setId($id) { |
|
111 | + if (is_int($id)) { |
|
112 | + $id = (string)$id; |
|
113 | + } |
|
114 | + |
|
115 | + if (!is_string($id)) { |
|
116 | + throw new \InvalidArgumentException('String expected.'); |
|
117 | + } |
|
118 | + |
|
119 | + if ($this->id !== null) { |
|
120 | + throw new IllegalIDChangeException('Not allowed to assign a new internal id to a share'); |
|
121 | + } |
|
122 | + |
|
123 | + $this->id = trim($id); |
|
124 | + return $this; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * @inheritdoc |
|
129 | + */ |
|
130 | + public function getId() { |
|
131 | + return $this->id; |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * @inheritdoc |
|
136 | + */ |
|
137 | + public function getFullId() { |
|
138 | + if ($this->providerId === null || $this->id === null) { |
|
139 | + throw new \UnexpectedValueException; |
|
140 | + } |
|
141 | + return $this->providerId . ':' . $this->id; |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * @inheritdoc |
|
146 | + */ |
|
147 | + public function setProviderId($id) { |
|
148 | + if (!is_string($id)) { |
|
149 | + throw new \InvalidArgumentException('String expected.'); |
|
150 | + } |
|
151 | + |
|
152 | + if ($this->providerId !== null) { |
|
153 | + throw new IllegalIDChangeException('Not allowed to assign a new provider id to a share'); |
|
154 | + } |
|
155 | + |
|
156 | + $this->providerId = trim($id); |
|
157 | + return $this; |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * @inheritdoc |
|
162 | + */ |
|
163 | + public function setNode(Node $node) { |
|
164 | + $this->fileId = null; |
|
165 | + $this->nodeType = null; |
|
166 | + $this->node = $node; |
|
167 | + return $this; |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * @inheritdoc |
|
172 | + */ |
|
173 | + public function getNode() { |
|
174 | + if ($this->node === null) { |
|
175 | + if ($this->shareOwner === null || $this->fileId === null) { |
|
176 | + throw new NotFoundException(); |
|
177 | + } |
|
178 | + |
|
179 | + // for federated shares the owner can be a remote user, in this |
|
180 | + // case we use the initiator |
|
181 | + if ($this->userManager->userExists($this->shareOwner)) { |
|
182 | + $userFolder = $this->rootFolder->getUserFolder($this->shareOwner); |
|
183 | + } else { |
|
184 | + $userFolder = $this->rootFolder->getUserFolder($this->sharedBy); |
|
185 | + } |
|
186 | + |
|
187 | + $nodes = $userFolder->getById($this->fileId); |
|
188 | + if (empty($nodes)) { |
|
189 | + throw new NotFoundException('Node for share not found, fileid: ' . $this->fileId); |
|
190 | + } |
|
191 | + |
|
192 | + $this->node = $nodes[0]; |
|
193 | + } |
|
194 | + |
|
195 | + return $this->node; |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * @inheritdoc |
|
200 | + */ |
|
201 | + public function setNodeId($fileId) { |
|
202 | + $this->node = null; |
|
203 | + $this->fileId = $fileId; |
|
204 | + return $this; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * @inheritdoc |
|
209 | + */ |
|
210 | + public function getNodeId() { |
|
211 | + if ($this->fileId === null) { |
|
212 | + $this->fileId = $this->getNode()->getId(); |
|
213 | + } |
|
214 | + |
|
215 | + return $this->fileId; |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * @inheritdoc |
|
220 | + */ |
|
221 | + public function setNodeType($type) { |
|
222 | + if ($type !== 'file' && $type !== 'folder') { |
|
223 | + throw new \InvalidArgumentException(); |
|
224 | + } |
|
225 | + |
|
226 | + $this->nodeType = $type; |
|
227 | + return $this; |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * @inheritdoc |
|
232 | + */ |
|
233 | + public function getNodeType() { |
|
234 | + if ($this->nodeType === null) { |
|
235 | + $node = $this->getNode(); |
|
236 | + $this->nodeType = $node instanceof File ? 'file' : 'folder'; |
|
237 | + } |
|
238 | + |
|
239 | + return $this->nodeType; |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * @inheritdoc |
|
244 | + */ |
|
245 | + public function setShareType($shareType) { |
|
246 | + $this->shareType = $shareType; |
|
247 | + return $this; |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * @inheritdoc |
|
252 | + */ |
|
253 | + public function getShareType() { |
|
254 | + return $this->shareType; |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * @inheritdoc |
|
259 | + */ |
|
260 | + public function setSharedWith($sharedWith) { |
|
261 | + if (!is_string($sharedWith)) { |
|
262 | + throw new \InvalidArgumentException(); |
|
263 | + } |
|
264 | + $this->sharedWith = $sharedWith; |
|
265 | + return $this; |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * @inheritdoc |
|
270 | + */ |
|
271 | + public function getSharedWith() { |
|
272 | + return $this->sharedWith; |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * @inheritdoc |
|
277 | + */ |
|
278 | + public function setSharedWithDisplayName($displayName) { |
|
279 | + if (!is_string($displayName)) { |
|
280 | + throw new \InvalidArgumentException(); |
|
281 | + } |
|
282 | + $this->sharedWithDisplayName = $displayName; |
|
283 | + return $this; |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * @inheritdoc |
|
288 | + */ |
|
289 | + public function getSharedWithDisplayName() { |
|
290 | + return $this->sharedWithDisplayName; |
|
291 | + } |
|
292 | + |
|
293 | + /** |
|
294 | + * @inheritdoc |
|
295 | + */ |
|
296 | + public function setSharedWithAvatar($src) { |
|
297 | + if (!is_string($src)) { |
|
298 | + throw new \InvalidArgumentException(); |
|
299 | + } |
|
300 | + $this->sharedWithAvatar = $src; |
|
301 | + return $this; |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * @inheritdoc |
|
306 | + */ |
|
307 | + public function getSharedWithAvatar() { |
|
308 | + return $this->sharedWithAvatar; |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * @inheritdoc |
|
313 | + */ |
|
314 | + public function setPermissions($permissions) { |
|
315 | + //TODO checkes |
|
316 | + |
|
317 | + $this->permissions = $permissions; |
|
318 | + return $this; |
|
319 | + } |
|
320 | + |
|
321 | + /** |
|
322 | + * @inheritdoc |
|
323 | + */ |
|
324 | + public function getPermissions() { |
|
325 | + return $this->permissions; |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * @inheritdoc |
|
330 | + */ |
|
331 | + public function setStatus(int $status): IShare { |
|
332 | + $this->status = $status; |
|
333 | + return $this; |
|
334 | + } |
|
335 | + |
|
336 | + /** |
|
337 | + * @inheritdoc |
|
338 | + */ |
|
339 | + public function getStatus(): int { |
|
340 | + return $this->status; |
|
341 | + } |
|
342 | + |
|
343 | + /** |
|
344 | + * @inheritdoc |
|
345 | + */ |
|
346 | + public function setNote($note) { |
|
347 | + $this->note = $note; |
|
348 | + return $this; |
|
349 | + } |
|
350 | + |
|
351 | + /** |
|
352 | + * @inheritdoc |
|
353 | + */ |
|
354 | + public function getNote() { |
|
355 | + if (is_string($this->note)) { |
|
356 | + return $this->note; |
|
357 | + } |
|
358 | + return ''; |
|
359 | + } |
|
360 | + |
|
361 | + /** |
|
362 | + * @inheritdoc |
|
363 | + */ |
|
364 | + public function setLabel($label) { |
|
365 | + $this->label = $label; |
|
366 | + return $this; |
|
367 | + } |
|
368 | + |
|
369 | + /** |
|
370 | + * @inheritdoc |
|
371 | + */ |
|
372 | + public function getLabel() { |
|
373 | + return $this->label; |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * @inheritdoc |
|
378 | + */ |
|
379 | + public function setExpirationDate($expireDate) { |
|
380 | + //TODO checks |
|
381 | + |
|
382 | + $this->expireDate = $expireDate; |
|
383 | + return $this; |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * @inheritdoc |
|
388 | + */ |
|
389 | + public function getExpirationDate() { |
|
390 | + return $this->expireDate; |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * @inheritdoc |
|
395 | + */ |
|
396 | + public function isExpired() { |
|
397 | + return $this->getExpirationDate() !== null && |
|
398 | + $this->getExpirationDate() <= new \DateTime(); |
|
399 | + } |
|
400 | + |
|
401 | + /** |
|
402 | + * @inheritdoc |
|
403 | + */ |
|
404 | + public function setSharedBy($sharedBy) { |
|
405 | + if (!is_string($sharedBy)) { |
|
406 | + throw new \InvalidArgumentException(); |
|
407 | + } |
|
408 | + //TODO checks |
|
409 | + $this->sharedBy = $sharedBy; |
|
410 | + |
|
411 | + return $this; |
|
412 | + } |
|
413 | + |
|
414 | + /** |
|
415 | + * @inheritdoc |
|
416 | + */ |
|
417 | + public function getSharedBy() { |
|
418 | + //TODO check if set |
|
419 | + return $this->sharedBy; |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * @inheritdoc |
|
424 | + */ |
|
425 | + public function setShareOwner($shareOwner) { |
|
426 | + if (!is_string($shareOwner)) { |
|
427 | + throw new \InvalidArgumentException(); |
|
428 | + } |
|
429 | + //TODO checks |
|
430 | + |
|
431 | + $this->shareOwner = $shareOwner; |
|
432 | + return $this; |
|
433 | + } |
|
434 | + |
|
435 | + /** |
|
436 | + * @inheritdoc |
|
437 | + */ |
|
438 | + public function getShareOwner() { |
|
439 | + //TODO check if set |
|
440 | + return $this->shareOwner; |
|
441 | + } |
|
442 | + |
|
443 | + /** |
|
444 | + * @inheritdoc |
|
445 | + */ |
|
446 | + public function setPassword($password) { |
|
447 | + $this->password = $password; |
|
448 | + return $this; |
|
449 | + } |
|
450 | + |
|
451 | + /** |
|
452 | + * @inheritdoc |
|
453 | + */ |
|
454 | + public function getPassword() { |
|
455 | + return $this->password; |
|
456 | + } |
|
457 | + |
|
458 | + /** |
|
459 | + * @inheritdoc |
|
460 | + */ |
|
461 | + public function setSendPasswordByTalk(bool $sendPasswordByTalk) { |
|
462 | + $this->sendPasswordByTalk = $sendPasswordByTalk; |
|
463 | + return $this; |
|
464 | + } |
|
465 | + |
|
466 | + /** |
|
467 | + * @inheritdoc |
|
468 | + */ |
|
469 | + public function getSendPasswordByTalk(): bool { |
|
470 | + return $this->sendPasswordByTalk; |
|
471 | + } |
|
472 | + |
|
473 | + /** |
|
474 | + * @inheritdoc |
|
475 | + */ |
|
476 | + public function setToken($token) { |
|
477 | + $this->token = $token; |
|
478 | + return $this; |
|
479 | + } |
|
480 | + |
|
481 | + /** |
|
482 | + * @inheritdoc |
|
483 | + */ |
|
484 | + public function getToken() { |
|
485 | + return $this->token; |
|
486 | + } |
|
487 | + |
|
488 | + /** |
|
489 | + * Set the parent of this share |
|
490 | + * |
|
491 | + * @param int parent |
|
492 | + * @return \OCP\Share\IShare |
|
493 | + * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
|
494 | + */ |
|
495 | + public function setParent($parent) { |
|
496 | + $this->parent = $parent; |
|
497 | + return $this; |
|
498 | + } |
|
499 | + |
|
500 | + /** |
|
501 | + * Get the parent of this share. |
|
502 | + * |
|
503 | + * @return int |
|
504 | + * @deprecated The new shares do not have parents. This is just here for legacy reasons. |
|
505 | + */ |
|
506 | + public function getParent() { |
|
507 | + return $this->parent; |
|
508 | + } |
|
509 | + |
|
510 | + /** |
|
511 | + * @inheritdoc |
|
512 | + */ |
|
513 | + public function setTarget($target) { |
|
514 | + $this->target = $target; |
|
515 | + return $this; |
|
516 | + } |
|
517 | + |
|
518 | + /** |
|
519 | + * @inheritdoc |
|
520 | + */ |
|
521 | + public function getTarget() { |
|
522 | + return $this->target; |
|
523 | + } |
|
524 | + |
|
525 | + /** |
|
526 | + * @inheritdoc |
|
527 | + */ |
|
528 | + public function setShareTime(\DateTime $shareTime) { |
|
529 | + $this->shareTime = $shareTime; |
|
530 | + return $this; |
|
531 | + } |
|
532 | + |
|
533 | + /** |
|
534 | + * @inheritdoc |
|
535 | + */ |
|
536 | + public function getShareTime() { |
|
537 | + return $this->shareTime; |
|
538 | + } |
|
539 | + |
|
540 | + /** |
|
541 | + * @inheritdoc |
|
542 | + */ |
|
543 | + public function setMailSend($mailSend) { |
|
544 | + $this->mailSend = $mailSend; |
|
545 | + return $this; |
|
546 | + } |
|
547 | + |
|
548 | + /** |
|
549 | + * @inheritdoc |
|
550 | + */ |
|
551 | + public function getMailSend() { |
|
552 | + return $this->mailSend; |
|
553 | + } |
|
554 | + |
|
555 | + /** |
|
556 | + * @inheritdoc |
|
557 | + */ |
|
558 | + public function setNodeCacheEntry(ICacheEntry $entry) { |
|
559 | + $this->nodeCacheEntry = $entry; |
|
560 | + } |
|
561 | + |
|
562 | + /** |
|
563 | + * @inheritdoc |
|
564 | + */ |
|
565 | + public function getNodeCacheEntry() { |
|
566 | + return $this->nodeCacheEntry; |
|
567 | + } |
|
568 | + |
|
569 | + public function setHideDownload(bool $hide): IShare { |
|
570 | + $this->hideDownload = $hide; |
|
571 | + return $this; |
|
572 | + } |
|
573 | + |
|
574 | + public function getHideDownload(): bool { |
|
575 | + return $this->hideDownload; |
|
576 | + } |
|
577 | 577 | } |
@@ -275,7 +275,7 @@ |
||
275 | 275 | return $this->getAppValues($app); |
276 | 276 | } else { |
277 | 277 | $appIds = $this->getApps(); |
278 | - $values = array_map(function ($appId) use ($key) { |
|
278 | + $values = array_map(function($appId) use ($key) { |
|
279 | 279 | return isset($this->cache[$appId][$key]) ? $this->cache[$appId][$key] : null; |
280 | 280 | }, $appIds); |
281 | 281 | $result = array_combine($appIds, $values); |
@@ -42,304 +42,304 @@ |
||
42 | 42 | */ |
43 | 43 | class AppConfig implements IAppConfig { |
44 | 44 | |
45 | - /** @var array[] */ |
|
46 | - protected $sensitiveValues = [ |
|
47 | - 'external' => [ |
|
48 | - '/^sites$/', |
|
49 | - ], |
|
50 | - 'spreed' => [ |
|
51 | - '/^signaling_ticket_secret$/', |
|
52 | - '/^turn_server_secret$/', |
|
53 | - '/^stun_servers$/', |
|
54 | - '/^turn_servers$/', |
|
55 | - '/^signaling_servers$/', |
|
56 | - ], |
|
57 | - 'theming' => [ |
|
58 | - '/^imprintUrl$/', |
|
59 | - '/^privacyUrl$/', |
|
60 | - '/^slogan$/', |
|
61 | - '/^url$/', |
|
62 | - ], |
|
63 | - 'user_ldap' => [ |
|
64 | - '/^(s..)?ldap_agent_password$/', |
|
65 | - ], |
|
66 | - ]; |
|
67 | - |
|
68 | - /** @var \OCP\IDBConnection */ |
|
69 | - protected $conn; |
|
70 | - |
|
71 | - /** @var array[] */ |
|
72 | - private $cache = []; |
|
73 | - |
|
74 | - /** @var bool */ |
|
75 | - private $configLoaded = false; |
|
76 | - |
|
77 | - /** |
|
78 | - * @param IDBConnection $conn |
|
79 | - */ |
|
80 | - public function __construct(IDBConnection $conn) { |
|
81 | - $this->conn = $conn; |
|
82 | - $this->configLoaded = false; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * @param string $app |
|
87 | - * @return array |
|
88 | - */ |
|
89 | - private function getAppValues($app) { |
|
90 | - $this->loadConfigValues(); |
|
91 | - |
|
92 | - if (isset($this->cache[$app])) { |
|
93 | - return $this->cache[$app]; |
|
94 | - } |
|
95 | - |
|
96 | - return []; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Get all apps using the config |
|
101 | - * |
|
102 | - * @return array an array of app ids |
|
103 | - * |
|
104 | - * This function returns a list of all apps that have at least one |
|
105 | - * entry in the appconfig table. |
|
106 | - */ |
|
107 | - public function getApps() { |
|
108 | - $this->loadConfigValues(); |
|
109 | - |
|
110 | - return $this->getSortedKeys($this->cache); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Get the available keys for an app |
|
115 | - * |
|
116 | - * @param string $app the app we are looking for |
|
117 | - * @return array an array of key names |
|
118 | - * |
|
119 | - * This function gets all keys of an app. Please note that the values are |
|
120 | - * not returned. |
|
121 | - */ |
|
122 | - public function getKeys($app) { |
|
123 | - $this->loadConfigValues(); |
|
124 | - |
|
125 | - if (isset($this->cache[$app])) { |
|
126 | - return $this->getSortedKeys($this->cache[$app]); |
|
127 | - } |
|
128 | - |
|
129 | - return []; |
|
130 | - } |
|
131 | - |
|
132 | - public function getSortedKeys($data) { |
|
133 | - $keys = array_keys($data); |
|
134 | - sort($keys); |
|
135 | - return $keys; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Gets the config value |
|
140 | - * |
|
141 | - * @param string $app app |
|
142 | - * @param string $key key |
|
143 | - * @param string $default = null, default value if the key does not exist |
|
144 | - * @return string the value or $default |
|
145 | - * |
|
146 | - * This function gets a value from the appconfig table. If the key does |
|
147 | - * not exist the default value will be returned |
|
148 | - */ |
|
149 | - public function getValue($app, $key, $default = null) { |
|
150 | - $this->loadConfigValues(); |
|
151 | - |
|
152 | - if ($this->hasKey($app, $key)) { |
|
153 | - return $this->cache[$app][$key]; |
|
154 | - } |
|
155 | - |
|
156 | - return $default; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * check if a key is set in the appconfig |
|
161 | - * |
|
162 | - * @param string $app |
|
163 | - * @param string $key |
|
164 | - * @return bool |
|
165 | - */ |
|
166 | - public function hasKey($app, $key) { |
|
167 | - $this->loadConfigValues(); |
|
168 | - |
|
169 | - return isset($this->cache[$app][$key]); |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Sets a value. If the key did not exist before it will be created. |
|
174 | - * |
|
175 | - * @param string $app app |
|
176 | - * @param string $key key |
|
177 | - * @param string|float|int $value value |
|
178 | - * @return bool True if the value was inserted or updated, false if the value was the same |
|
179 | - */ |
|
180 | - public function setValue($app, $key, $value) { |
|
181 | - if (!$this->hasKey($app, $key)) { |
|
182 | - $inserted = (bool) $this->conn->insertIfNotExist('*PREFIX*appconfig', [ |
|
183 | - 'appid' => $app, |
|
184 | - 'configkey' => $key, |
|
185 | - 'configvalue' => $value, |
|
186 | - ], [ |
|
187 | - 'appid', |
|
188 | - 'configkey', |
|
189 | - ]); |
|
190 | - |
|
191 | - if ($inserted) { |
|
192 | - if (!isset($this->cache[$app])) { |
|
193 | - $this->cache[$app] = []; |
|
194 | - } |
|
195 | - |
|
196 | - $this->cache[$app][$key] = $value; |
|
197 | - return true; |
|
198 | - } |
|
199 | - } |
|
200 | - |
|
201 | - $sql = $this->conn->getQueryBuilder(); |
|
202 | - $sql->update('appconfig') |
|
203 | - ->set('configvalue', $sql->createParameter('configvalue')) |
|
204 | - ->where($sql->expr()->eq('appid', $sql->createParameter('app'))) |
|
205 | - ->andWhere($sql->expr()->eq('configkey', $sql->createParameter('configkey'))) |
|
206 | - ->setParameter('configvalue', $value) |
|
207 | - ->setParameter('app', $app) |
|
208 | - ->setParameter('configkey', $key); |
|
209 | - |
|
210 | - /* |
|
45 | + /** @var array[] */ |
|
46 | + protected $sensitiveValues = [ |
|
47 | + 'external' => [ |
|
48 | + '/^sites$/', |
|
49 | + ], |
|
50 | + 'spreed' => [ |
|
51 | + '/^signaling_ticket_secret$/', |
|
52 | + '/^turn_server_secret$/', |
|
53 | + '/^stun_servers$/', |
|
54 | + '/^turn_servers$/', |
|
55 | + '/^signaling_servers$/', |
|
56 | + ], |
|
57 | + 'theming' => [ |
|
58 | + '/^imprintUrl$/', |
|
59 | + '/^privacyUrl$/', |
|
60 | + '/^slogan$/', |
|
61 | + '/^url$/', |
|
62 | + ], |
|
63 | + 'user_ldap' => [ |
|
64 | + '/^(s..)?ldap_agent_password$/', |
|
65 | + ], |
|
66 | + ]; |
|
67 | + |
|
68 | + /** @var \OCP\IDBConnection */ |
|
69 | + protected $conn; |
|
70 | + |
|
71 | + /** @var array[] */ |
|
72 | + private $cache = []; |
|
73 | + |
|
74 | + /** @var bool */ |
|
75 | + private $configLoaded = false; |
|
76 | + |
|
77 | + /** |
|
78 | + * @param IDBConnection $conn |
|
79 | + */ |
|
80 | + public function __construct(IDBConnection $conn) { |
|
81 | + $this->conn = $conn; |
|
82 | + $this->configLoaded = false; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * @param string $app |
|
87 | + * @return array |
|
88 | + */ |
|
89 | + private function getAppValues($app) { |
|
90 | + $this->loadConfigValues(); |
|
91 | + |
|
92 | + if (isset($this->cache[$app])) { |
|
93 | + return $this->cache[$app]; |
|
94 | + } |
|
95 | + |
|
96 | + return []; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Get all apps using the config |
|
101 | + * |
|
102 | + * @return array an array of app ids |
|
103 | + * |
|
104 | + * This function returns a list of all apps that have at least one |
|
105 | + * entry in the appconfig table. |
|
106 | + */ |
|
107 | + public function getApps() { |
|
108 | + $this->loadConfigValues(); |
|
109 | + |
|
110 | + return $this->getSortedKeys($this->cache); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Get the available keys for an app |
|
115 | + * |
|
116 | + * @param string $app the app we are looking for |
|
117 | + * @return array an array of key names |
|
118 | + * |
|
119 | + * This function gets all keys of an app. Please note that the values are |
|
120 | + * not returned. |
|
121 | + */ |
|
122 | + public function getKeys($app) { |
|
123 | + $this->loadConfigValues(); |
|
124 | + |
|
125 | + if (isset($this->cache[$app])) { |
|
126 | + return $this->getSortedKeys($this->cache[$app]); |
|
127 | + } |
|
128 | + |
|
129 | + return []; |
|
130 | + } |
|
131 | + |
|
132 | + public function getSortedKeys($data) { |
|
133 | + $keys = array_keys($data); |
|
134 | + sort($keys); |
|
135 | + return $keys; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Gets the config value |
|
140 | + * |
|
141 | + * @param string $app app |
|
142 | + * @param string $key key |
|
143 | + * @param string $default = null, default value if the key does not exist |
|
144 | + * @return string the value or $default |
|
145 | + * |
|
146 | + * This function gets a value from the appconfig table. If the key does |
|
147 | + * not exist the default value will be returned |
|
148 | + */ |
|
149 | + public function getValue($app, $key, $default = null) { |
|
150 | + $this->loadConfigValues(); |
|
151 | + |
|
152 | + if ($this->hasKey($app, $key)) { |
|
153 | + return $this->cache[$app][$key]; |
|
154 | + } |
|
155 | + |
|
156 | + return $default; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * check if a key is set in the appconfig |
|
161 | + * |
|
162 | + * @param string $app |
|
163 | + * @param string $key |
|
164 | + * @return bool |
|
165 | + */ |
|
166 | + public function hasKey($app, $key) { |
|
167 | + $this->loadConfigValues(); |
|
168 | + |
|
169 | + return isset($this->cache[$app][$key]); |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Sets a value. If the key did not exist before it will be created. |
|
174 | + * |
|
175 | + * @param string $app app |
|
176 | + * @param string $key key |
|
177 | + * @param string|float|int $value value |
|
178 | + * @return bool True if the value was inserted or updated, false if the value was the same |
|
179 | + */ |
|
180 | + public function setValue($app, $key, $value) { |
|
181 | + if (!$this->hasKey($app, $key)) { |
|
182 | + $inserted = (bool) $this->conn->insertIfNotExist('*PREFIX*appconfig', [ |
|
183 | + 'appid' => $app, |
|
184 | + 'configkey' => $key, |
|
185 | + 'configvalue' => $value, |
|
186 | + ], [ |
|
187 | + 'appid', |
|
188 | + 'configkey', |
|
189 | + ]); |
|
190 | + |
|
191 | + if ($inserted) { |
|
192 | + if (!isset($this->cache[$app])) { |
|
193 | + $this->cache[$app] = []; |
|
194 | + } |
|
195 | + |
|
196 | + $this->cache[$app][$key] = $value; |
|
197 | + return true; |
|
198 | + } |
|
199 | + } |
|
200 | + |
|
201 | + $sql = $this->conn->getQueryBuilder(); |
|
202 | + $sql->update('appconfig') |
|
203 | + ->set('configvalue', $sql->createParameter('configvalue')) |
|
204 | + ->where($sql->expr()->eq('appid', $sql->createParameter('app'))) |
|
205 | + ->andWhere($sql->expr()->eq('configkey', $sql->createParameter('configkey'))) |
|
206 | + ->setParameter('configvalue', $value) |
|
207 | + ->setParameter('app', $app) |
|
208 | + ->setParameter('configkey', $key); |
|
209 | + |
|
210 | + /* |
|
211 | 211 | * Only limit to the existing value for non-Oracle DBs: |
212 | 212 | * http://docs.oracle.com/cd/E11882_01/server.112/e26088/conditions002.htm#i1033286 |
213 | 213 | * > Large objects (LOBs) are not supported in comparison conditions. |
214 | 214 | */ |
215 | - if (!($this->conn instanceof OracleConnection)) { |
|
216 | - // Only update the value when it is not the same |
|
217 | - $sql->andWhere($sql->expr()->neq('configvalue', $sql->createParameter('configvalue'))) |
|
218 | - ->setParameter('configvalue', $value); |
|
219 | - } |
|
220 | - |
|
221 | - $changedRow = (bool) $sql->execute(); |
|
222 | - |
|
223 | - $this->cache[$app][$key] = $value; |
|
224 | - |
|
225 | - return $changedRow; |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * Deletes a key |
|
230 | - * |
|
231 | - * @param string $app app |
|
232 | - * @param string $key key |
|
233 | - * @return boolean |
|
234 | - */ |
|
235 | - public function deleteKey($app, $key) { |
|
236 | - $this->loadConfigValues(); |
|
237 | - |
|
238 | - $sql = $this->conn->getQueryBuilder(); |
|
239 | - $sql->delete('appconfig') |
|
240 | - ->where($sql->expr()->eq('appid', $sql->createParameter('app'))) |
|
241 | - ->andWhere($sql->expr()->eq('configkey', $sql->createParameter('configkey'))) |
|
242 | - ->setParameter('app', $app) |
|
243 | - ->setParameter('configkey', $key); |
|
244 | - $sql->execute(); |
|
245 | - |
|
246 | - unset($this->cache[$app][$key]); |
|
247 | - return false; |
|
248 | - } |
|
249 | - |
|
250 | - /** |
|
251 | - * Remove app from appconfig |
|
252 | - * |
|
253 | - * @param string $app app |
|
254 | - * @return boolean |
|
255 | - * |
|
256 | - * Removes all keys in appconfig belonging to the app. |
|
257 | - */ |
|
258 | - public function deleteApp($app) { |
|
259 | - $this->loadConfigValues(); |
|
260 | - |
|
261 | - $sql = $this->conn->getQueryBuilder(); |
|
262 | - $sql->delete('appconfig') |
|
263 | - ->where($sql->expr()->eq('appid', $sql->createParameter('app'))) |
|
264 | - ->setParameter('app', $app); |
|
265 | - $sql->execute(); |
|
266 | - |
|
267 | - unset($this->cache[$app]); |
|
268 | - return false; |
|
269 | - } |
|
270 | - |
|
271 | - /** |
|
272 | - * get multiple values, either the app or key can be used as wildcard by setting it to false |
|
273 | - * |
|
274 | - * @param string|false $app |
|
275 | - * @param string|false $key |
|
276 | - * @return array|false |
|
277 | - */ |
|
278 | - public function getValues($app, $key) { |
|
279 | - if (($app !== false) === ($key !== false)) { |
|
280 | - return false; |
|
281 | - } |
|
282 | - |
|
283 | - if ($key === false) { |
|
284 | - return $this->getAppValues($app); |
|
285 | - } else { |
|
286 | - $appIds = $this->getApps(); |
|
287 | - $values = array_map(function ($appId) use ($key) { |
|
288 | - return isset($this->cache[$appId][$key]) ? $this->cache[$appId][$key] : null; |
|
289 | - }, $appIds); |
|
290 | - $result = array_combine($appIds, $values); |
|
291 | - |
|
292 | - return array_filter($result); |
|
293 | - } |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * get all values of the app or and filters out sensitive data |
|
298 | - * |
|
299 | - * @param string $app |
|
300 | - * @return array |
|
301 | - */ |
|
302 | - public function getFilteredValues($app) { |
|
303 | - $values = $this->getValues($app, false); |
|
304 | - |
|
305 | - if (isset($this->sensitiveValues[$app])) { |
|
306 | - foreach ($this->sensitiveValues[$app] as $sensitiveKeyExp) { |
|
307 | - $sensitiveKeys = preg_grep($sensitiveKeyExp, array_keys($values)); |
|
308 | - foreach ($sensitiveKeys as $sensitiveKey) { |
|
309 | - $values[$sensitiveKey] = IConfig::SENSITIVE_VALUE; |
|
310 | - } |
|
311 | - } |
|
312 | - } |
|
313 | - |
|
314 | - return $values; |
|
315 | - } |
|
316 | - |
|
317 | - /** |
|
318 | - * Load all the app config values |
|
319 | - */ |
|
320 | - protected function loadConfigValues() { |
|
321 | - if ($this->configLoaded) { |
|
322 | - return; |
|
323 | - } |
|
324 | - |
|
325 | - $this->cache = []; |
|
326 | - |
|
327 | - $sql = $this->conn->getQueryBuilder(); |
|
328 | - $sql->select('*') |
|
329 | - ->from('appconfig'); |
|
330 | - $result = $sql->execute(); |
|
331 | - |
|
332 | - // we are going to store the result in memory anyway |
|
333 | - $rows = $result->fetchAll(); |
|
334 | - foreach ($rows as $row) { |
|
335 | - if (!isset($this->cache[$row['appid']])) { |
|
336 | - $this->cache[$row['appid']] = []; |
|
337 | - } |
|
338 | - |
|
339 | - $this->cache[$row['appid']][$row['configkey']] = $row['configvalue']; |
|
340 | - } |
|
341 | - $result->closeCursor(); |
|
342 | - |
|
343 | - $this->configLoaded = true; |
|
344 | - } |
|
215 | + if (!($this->conn instanceof OracleConnection)) { |
|
216 | + // Only update the value when it is not the same |
|
217 | + $sql->andWhere($sql->expr()->neq('configvalue', $sql->createParameter('configvalue'))) |
|
218 | + ->setParameter('configvalue', $value); |
|
219 | + } |
|
220 | + |
|
221 | + $changedRow = (bool) $sql->execute(); |
|
222 | + |
|
223 | + $this->cache[$app][$key] = $value; |
|
224 | + |
|
225 | + return $changedRow; |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * Deletes a key |
|
230 | + * |
|
231 | + * @param string $app app |
|
232 | + * @param string $key key |
|
233 | + * @return boolean |
|
234 | + */ |
|
235 | + public function deleteKey($app, $key) { |
|
236 | + $this->loadConfigValues(); |
|
237 | + |
|
238 | + $sql = $this->conn->getQueryBuilder(); |
|
239 | + $sql->delete('appconfig') |
|
240 | + ->where($sql->expr()->eq('appid', $sql->createParameter('app'))) |
|
241 | + ->andWhere($sql->expr()->eq('configkey', $sql->createParameter('configkey'))) |
|
242 | + ->setParameter('app', $app) |
|
243 | + ->setParameter('configkey', $key); |
|
244 | + $sql->execute(); |
|
245 | + |
|
246 | + unset($this->cache[$app][$key]); |
|
247 | + return false; |
|
248 | + } |
|
249 | + |
|
250 | + /** |
|
251 | + * Remove app from appconfig |
|
252 | + * |
|
253 | + * @param string $app app |
|
254 | + * @return boolean |
|
255 | + * |
|
256 | + * Removes all keys in appconfig belonging to the app. |
|
257 | + */ |
|
258 | + public function deleteApp($app) { |
|
259 | + $this->loadConfigValues(); |
|
260 | + |
|
261 | + $sql = $this->conn->getQueryBuilder(); |
|
262 | + $sql->delete('appconfig') |
|
263 | + ->where($sql->expr()->eq('appid', $sql->createParameter('app'))) |
|
264 | + ->setParameter('app', $app); |
|
265 | + $sql->execute(); |
|
266 | + |
|
267 | + unset($this->cache[$app]); |
|
268 | + return false; |
|
269 | + } |
|
270 | + |
|
271 | + /** |
|
272 | + * get multiple values, either the app or key can be used as wildcard by setting it to false |
|
273 | + * |
|
274 | + * @param string|false $app |
|
275 | + * @param string|false $key |
|
276 | + * @return array|false |
|
277 | + */ |
|
278 | + public function getValues($app, $key) { |
|
279 | + if (($app !== false) === ($key !== false)) { |
|
280 | + return false; |
|
281 | + } |
|
282 | + |
|
283 | + if ($key === false) { |
|
284 | + return $this->getAppValues($app); |
|
285 | + } else { |
|
286 | + $appIds = $this->getApps(); |
|
287 | + $values = array_map(function ($appId) use ($key) { |
|
288 | + return isset($this->cache[$appId][$key]) ? $this->cache[$appId][$key] : null; |
|
289 | + }, $appIds); |
|
290 | + $result = array_combine($appIds, $values); |
|
291 | + |
|
292 | + return array_filter($result); |
|
293 | + } |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * get all values of the app or and filters out sensitive data |
|
298 | + * |
|
299 | + * @param string $app |
|
300 | + * @return array |
|
301 | + */ |
|
302 | + public function getFilteredValues($app) { |
|
303 | + $values = $this->getValues($app, false); |
|
304 | + |
|
305 | + if (isset($this->sensitiveValues[$app])) { |
|
306 | + foreach ($this->sensitiveValues[$app] as $sensitiveKeyExp) { |
|
307 | + $sensitiveKeys = preg_grep($sensitiveKeyExp, array_keys($values)); |
|
308 | + foreach ($sensitiveKeys as $sensitiveKey) { |
|
309 | + $values[$sensitiveKey] = IConfig::SENSITIVE_VALUE; |
|
310 | + } |
|
311 | + } |
|
312 | + } |
|
313 | + |
|
314 | + return $values; |
|
315 | + } |
|
316 | + |
|
317 | + /** |
|
318 | + * Load all the app config values |
|
319 | + */ |
|
320 | + protected function loadConfigValues() { |
|
321 | + if ($this->configLoaded) { |
|
322 | + return; |
|
323 | + } |
|
324 | + |
|
325 | + $this->cache = []; |
|
326 | + |
|
327 | + $sql = $this->conn->getQueryBuilder(); |
|
328 | + $sql->select('*') |
|
329 | + ->from('appconfig'); |
|
330 | + $result = $sql->execute(); |
|
331 | + |
|
332 | + // we are going to store the result in memory anyway |
|
333 | + $rows = $result->fetchAll(); |
|
334 | + foreach ($rows as $row) { |
|
335 | + if (!isset($this->cache[$row['appid']])) { |
|
336 | + $this->cache[$row['appid']] = []; |
|
337 | + } |
|
338 | + |
|
339 | + $this->cache[$row['appid']][$row['configkey']] = $row['configvalue']; |
|
340 | + } |
|
341 | + $result->closeCursor(); |
|
342 | + |
|
343 | + $this->configLoaded = true; |
|
344 | + } |
|
345 | 345 | } |
@@ -28,51 +28,51 @@ |
||
28 | 28 | |
29 | 29 | class MoveUpdaterStepFile implements IRepairStep { |
30 | 30 | |
31 | - /** @var \OCP\IConfig */ |
|
32 | - protected $config; |
|
31 | + /** @var \OCP\IConfig */ |
|
32 | + protected $config; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param \OCP\IConfig $config |
|
36 | - */ |
|
37 | - public function __construct($config) { |
|
38 | - $this->config = $config; |
|
39 | - } |
|
34 | + /** |
|
35 | + * @param \OCP\IConfig $config |
|
36 | + */ |
|
37 | + public function __construct($config) { |
|
38 | + $this->config = $config; |
|
39 | + } |
|
40 | 40 | |
41 | - public function getName() { |
|
42 | - return 'Move .step file of updater to backup location'; |
|
43 | - } |
|
41 | + public function getName() { |
|
42 | + return 'Move .step file of updater to backup location'; |
|
43 | + } |
|
44 | 44 | |
45 | - public function run(IOutput $output) { |
|
46 | - $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
47 | - $instanceId = $this->config->getSystemValue('instanceid', null); |
|
45 | + public function run(IOutput $output) { |
|
46 | + $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
47 | + $instanceId = $this->config->getSystemValue('instanceid', null); |
|
48 | 48 | |
49 | - if (!is_string($instanceId) || empty($instanceId)) { |
|
50 | - return; |
|
51 | - } |
|
49 | + if (!is_string($instanceId) || empty($instanceId)) { |
|
50 | + return; |
|
51 | + } |
|
52 | 52 | |
53 | - $updaterFolderPath = $dataDir . '/updater-' . $instanceId; |
|
54 | - $stepFile = $updaterFolderPath . '/.step'; |
|
55 | - if (file_exists($stepFile)) { |
|
56 | - $output->info('.step file exists'); |
|
53 | + $updaterFolderPath = $dataDir . '/updater-' . $instanceId; |
|
54 | + $stepFile = $updaterFolderPath . '/.step'; |
|
55 | + if (file_exists($stepFile)) { |
|
56 | + $output->info('.step file exists'); |
|
57 | 57 | |
58 | - $previousStepFile = $updaterFolderPath . '/.step-previous-update'; |
|
58 | + $previousStepFile = $updaterFolderPath . '/.step-previous-update'; |
|
59 | 59 | |
60 | - // cleanup |
|
61 | - if (file_exists($previousStepFile)) { |
|
62 | - if (\OC_Helper::rmdirr($previousStepFile)) { |
|
63 | - $output->info('.step-previous-update removed'); |
|
64 | - } else { |
|
65 | - $output->info('.step-previous-update can\'t be removed - abort move of .step file'); |
|
66 | - return; |
|
67 | - } |
|
68 | - } |
|
60 | + // cleanup |
|
61 | + if (file_exists($previousStepFile)) { |
|
62 | + if (\OC_Helper::rmdirr($previousStepFile)) { |
|
63 | + $output->info('.step-previous-update removed'); |
|
64 | + } else { |
|
65 | + $output->info('.step-previous-update can\'t be removed - abort move of .step file'); |
|
66 | + return; |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - // move step file |
|
71 | - if (rename($stepFile, $previousStepFile)) { |
|
72 | - $output->info('.step file moved to .step-previous-update'); |
|
73 | - } else { |
|
74 | - $output->warning('.step file can\'t be moved'); |
|
75 | - } |
|
76 | - } |
|
77 | - } |
|
70 | + // move step file |
|
71 | + if (rename($stepFile, $previousStepFile)) { |
|
72 | + $output->info('.step file moved to .step-previous-update'); |
|
73 | + } else { |
|
74 | + $output->warning('.step file can\'t be moved'); |
|
75 | + } |
|
76 | + } |
|
77 | + } |
|
78 | 78 | } |
@@ -43,19 +43,19 @@ |
||
43 | 43 | } |
44 | 44 | |
45 | 45 | public function run(IOutput $output) { |
46 | - $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
46 | + $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data'); |
|
47 | 47 | $instanceId = $this->config->getSystemValue('instanceid', null); |
48 | 48 | |
49 | 49 | if (!is_string($instanceId) || empty($instanceId)) { |
50 | 50 | return; |
51 | 51 | } |
52 | 52 | |
53 | - $updaterFolderPath = $dataDir . '/updater-' . $instanceId; |
|
54 | - $stepFile = $updaterFolderPath . '/.step'; |
|
53 | + $updaterFolderPath = $dataDir.'/updater-'.$instanceId; |
|
54 | + $stepFile = $updaterFolderPath.'/.step'; |
|
55 | 55 | if (file_exists($stepFile)) { |
56 | 56 | $output->info('.step file exists'); |
57 | 57 | |
58 | - $previousStepFile = $updaterFolderPath . '/.step-previous-update'; |
|
58 | + $previousStepFile = $updaterFolderPath.'/.step-previous-update'; |
|
59 | 59 | |
60 | 60 | // cleanup |
61 | 61 | if (file_exists($previousStepFile)) { |
@@ -53,7 +53,7 @@ |
||
53 | 53 | public function sort($a, $b) { |
54 | 54 | if (!isset($a[$this->key]) || !isset($b[$this->key])) { |
55 | 55 | if (!is_null($this->log)) { |
56 | - $this->log->error('Sharing dialogue: cannot sort due to ' . |
|
56 | + $this->log->error('Sharing dialogue: cannot sort due to '. |
|
57 | 57 | 'missing array key', ['app' => 'core']); |
58 | 58 | } |
59 | 59 | return 0; |
@@ -29,50 +29,50 @@ |
||
29 | 29 | use OCP\ILogger; |
30 | 30 | |
31 | 31 | class SearchResultSorter { |
32 | - private $search; |
|
33 | - private $encoding; |
|
34 | - private $key; |
|
35 | - private $log; |
|
32 | + private $search; |
|
33 | + private $encoding; |
|
34 | + private $key; |
|
35 | + private $log; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param string $search the search term as was given by the user |
|
39 | - * @param string $key the array key containing the value that should be compared |
|
40 | - * against |
|
41 | - * @param string $encoding optional, encoding to use, defaults to UTF-8 |
|
42 | - * @param ILogger $log optional |
|
43 | - */ |
|
44 | - public function __construct($search, $key, ILogger $log = null, $encoding = 'UTF-8') { |
|
45 | - $this->encoding = $encoding; |
|
46 | - $this->key = $key; |
|
47 | - $this->log = $log; |
|
48 | - $this->search = mb_strtolower($search, $this->encoding); |
|
49 | - } |
|
37 | + /** |
|
38 | + * @param string $search the search term as was given by the user |
|
39 | + * @param string $key the array key containing the value that should be compared |
|
40 | + * against |
|
41 | + * @param string $encoding optional, encoding to use, defaults to UTF-8 |
|
42 | + * @param ILogger $log optional |
|
43 | + */ |
|
44 | + public function __construct($search, $key, ILogger $log = null, $encoding = 'UTF-8') { |
|
45 | + $this->encoding = $encoding; |
|
46 | + $this->key = $key; |
|
47 | + $this->log = $log; |
|
48 | + $this->search = mb_strtolower($search, $this->encoding); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * User and Group names matching the search term at the beginning shall appear |
|
53 | - * on top of the share dialog. Following entries in alphabetical order. |
|
54 | - * Callback function for usort. http://php.net/usort |
|
55 | - */ |
|
56 | - public function sort($a, $b) { |
|
57 | - if (!isset($a[$this->key]) || !isset($b[$this->key])) { |
|
58 | - if (!is_null($this->log)) { |
|
59 | - $this->log->error('Sharing dialogue: cannot sort due to ' . |
|
60 | - 'missing array key', ['app' => 'core']); |
|
61 | - } |
|
62 | - return 0; |
|
63 | - } |
|
64 | - $nameA = mb_strtolower($a[$this->key], $this->encoding); |
|
65 | - $nameB = mb_strtolower($b[$this->key], $this->encoding); |
|
66 | - $i = mb_strpos($nameA, $this->search, 0, $this->encoding); |
|
67 | - $j = mb_strpos($nameB, $this->search, 0, $this->encoding); |
|
51 | + /** |
|
52 | + * User and Group names matching the search term at the beginning shall appear |
|
53 | + * on top of the share dialog. Following entries in alphabetical order. |
|
54 | + * Callback function for usort. http://php.net/usort |
|
55 | + */ |
|
56 | + public function sort($a, $b) { |
|
57 | + if (!isset($a[$this->key]) || !isset($b[$this->key])) { |
|
58 | + if (!is_null($this->log)) { |
|
59 | + $this->log->error('Sharing dialogue: cannot sort due to ' . |
|
60 | + 'missing array key', ['app' => 'core']); |
|
61 | + } |
|
62 | + return 0; |
|
63 | + } |
|
64 | + $nameA = mb_strtolower($a[$this->key], $this->encoding); |
|
65 | + $nameB = mb_strtolower($b[$this->key], $this->encoding); |
|
66 | + $i = mb_strpos($nameA, $this->search, 0, $this->encoding); |
|
67 | + $j = mb_strpos($nameB, $this->search, 0, $this->encoding); |
|
68 | 68 | |
69 | - if ($i === $j || $i > 0 && $j > 0) { |
|
70 | - return strcmp(mb_strtolower($nameA, $this->encoding), |
|
71 | - mb_strtolower($nameB, $this->encoding)); |
|
72 | - } elseif ($i === 0) { |
|
73 | - return -1; |
|
74 | - } else { |
|
75 | - return 1; |
|
76 | - } |
|
77 | - } |
|
69 | + if ($i === $j || $i > 0 && $j > 0) { |
|
70 | + return strcmp(mb_strtolower($nameA, $this->encoding), |
|
71 | + mb_strtolower($nameB, $this->encoding)); |
|
72 | + } elseif ($i === 0) { |
|
73 | + return -1; |
|
74 | + } else { |
|
75 | + return 1; |
|
76 | + } |
|
77 | + } |
|
78 | 78 | } |
@@ -60,7 +60,7 @@ |
||
60 | 60 | $capabilities = array_replace_recursive($capabilities, $c->getCapabilities()); |
61 | 61 | } |
62 | 62 | } else { |
63 | - throw new \InvalidArgumentException('The given Capability (' . get_class($c) . ') does not implement the ICapability interface'); |
|
63 | + throw new \InvalidArgumentException('The given Capability ('.get_class($c).') does not implement the ICapability interface'); |
|
64 | 64 | } |
65 | 65 | } |
66 | 66 |
@@ -36,58 +36,58 @@ |
||
36 | 36 | |
37 | 37 | class CapabilitiesManager { |
38 | 38 | |
39 | - /** @var \Closure[] */ |
|
40 | - private $capabilities = []; |
|
39 | + /** @var \Closure[] */ |
|
40 | + private $capabilities = []; |
|
41 | 41 | |
42 | - /** @var ILogger */ |
|
43 | - private $logger; |
|
42 | + /** @var ILogger */ |
|
43 | + private $logger; |
|
44 | 44 | |
45 | - public function __construct(ILogger $logger) { |
|
46 | - $this->logger = $logger; |
|
47 | - } |
|
45 | + public function __construct(ILogger $logger) { |
|
46 | + $this->logger = $logger; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Get an array of al the capabilities that are registered at this manager |
|
51 | - * |
|
52 | - * @param bool $public get public capabilities only |
|
53 | - * @throws \InvalidArgumentException |
|
54 | - * @return array |
|
55 | - */ |
|
56 | - public function getCapabilities(bool $public = false) : array { |
|
57 | - $capabilities = []; |
|
58 | - foreach ($this->capabilities as $capability) { |
|
59 | - try { |
|
60 | - $c = $capability(); |
|
61 | - } catch (QueryException $e) { |
|
62 | - $this->logger->logException($e, [ |
|
63 | - 'message' => 'CapabilitiesManager', |
|
64 | - 'level' => ILogger::ERROR, |
|
65 | - 'app' => 'core', |
|
66 | - ]); |
|
67 | - continue; |
|
68 | - } |
|
49 | + /** |
|
50 | + * Get an array of al the capabilities that are registered at this manager |
|
51 | + * |
|
52 | + * @param bool $public get public capabilities only |
|
53 | + * @throws \InvalidArgumentException |
|
54 | + * @return array |
|
55 | + */ |
|
56 | + public function getCapabilities(bool $public = false) : array { |
|
57 | + $capabilities = []; |
|
58 | + foreach ($this->capabilities as $capability) { |
|
59 | + try { |
|
60 | + $c = $capability(); |
|
61 | + } catch (QueryException $e) { |
|
62 | + $this->logger->logException($e, [ |
|
63 | + 'message' => 'CapabilitiesManager', |
|
64 | + 'level' => ILogger::ERROR, |
|
65 | + 'app' => 'core', |
|
66 | + ]); |
|
67 | + continue; |
|
68 | + } |
|
69 | 69 | |
70 | - if ($c instanceof ICapability) { |
|
71 | - if (!$public || $c instanceof IPublicCapability) { |
|
72 | - $capabilities = array_replace_recursive($capabilities, $c->getCapabilities()); |
|
73 | - } |
|
74 | - } else { |
|
75 | - throw new \InvalidArgumentException('The given Capability (' . get_class($c) . ') does not implement the ICapability interface'); |
|
76 | - } |
|
77 | - } |
|
70 | + if ($c instanceof ICapability) { |
|
71 | + if (!$public || $c instanceof IPublicCapability) { |
|
72 | + $capabilities = array_replace_recursive($capabilities, $c->getCapabilities()); |
|
73 | + } |
|
74 | + } else { |
|
75 | + throw new \InvalidArgumentException('The given Capability (' . get_class($c) . ') does not implement the ICapability interface'); |
|
76 | + } |
|
77 | + } |
|
78 | 78 | |
79 | - return $capabilities; |
|
80 | - } |
|
79 | + return $capabilities; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
84 | - * capabilities are actually requested |
|
85 | - * |
|
86 | - * $callable has to return an instance of OCP\Capabilities\ICapability |
|
87 | - * |
|
88 | - * @param \Closure $callable |
|
89 | - */ |
|
90 | - public function registerCapability(\Closure $callable) { |
|
91 | - $this->capabilities[] = $callable; |
|
92 | - } |
|
82 | + /** |
|
83 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
84 | + * capabilities are actually requested |
|
85 | + * |
|
86 | + * $callable has to return an instance of OCP\Capabilities\ICapability |
|
87 | + * |
|
88 | + * @param \Closure $callable |
|
89 | + */ |
|
90 | + public function registerCapability(\Closure $callable) { |
|
91 | + $this->capabilities[] = $callable; |
|
92 | + } |
|
93 | 93 | } |
@@ -32,127 +32,127 @@ |
||
32 | 32 | |
33 | 33 | class Result { |
34 | 34 | |
35 | - /** @var array */ |
|
36 | - protected $data; |
|
37 | - |
|
38 | - /** @var null|string */ |
|
39 | - protected $message; |
|
40 | - |
|
41 | - /** @var int */ |
|
42 | - protected $statusCode; |
|
43 | - |
|
44 | - /** @var integer */ |
|
45 | - protected $items; |
|
46 | - |
|
47 | - /** @var integer */ |
|
48 | - protected $perPage; |
|
49 | - |
|
50 | - /** @var array */ |
|
51 | - private $headers = []; |
|
52 | - |
|
53 | - /** |
|
54 | - * create the OCS_Result object |
|
55 | - * @param mixed $data the data to return |
|
56 | - * @param int $code |
|
57 | - * @param null|string $message |
|
58 | - * @param array $headers |
|
59 | - */ |
|
60 | - public function __construct($data = null, $code = 100, $message = null, $headers = []) { |
|
61 | - if ($data === null) { |
|
62 | - $this->data = []; |
|
63 | - } elseif (!is_array($data)) { |
|
64 | - $this->data = [$this->data]; |
|
65 | - } else { |
|
66 | - $this->data = $data; |
|
67 | - } |
|
68 | - $this->statusCode = $code; |
|
69 | - $this->message = $message; |
|
70 | - $this->headers = $headers; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * optionally set the total number of items available |
|
75 | - * @param int $items |
|
76 | - */ |
|
77 | - public function setTotalItems($items) { |
|
78 | - $this->items = $items; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * optionally set the the number of items per page |
|
83 | - * @param int $items |
|
84 | - */ |
|
85 | - public function setItemsPerPage($items) { |
|
86 | - $this->perPage = $items; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * get the status code |
|
91 | - * @return int |
|
92 | - */ |
|
93 | - public function getStatusCode() { |
|
94 | - return $this->statusCode; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * get the meta data for the result |
|
99 | - * @return array |
|
100 | - */ |
|
101 | - public function getMeta() { |
|
102 | - $meta = []; |
|
103 | - $meta['status'] = $this->succeeded() ? 'ok' : 'failure'; |
|
104 | - $meta['statuscode'] = $this->statusCode; |
|
105 | - $meta['message'] = $this->message; |
|
106 | - if (isset($this->items)) { |
|
107 | - $meta['totalitems'] = $this->items; |
|
108 | - } |
|
109 | - if (isset($this->perPage)) { |
|
110 | - $meta['itemsperpage'] = $this->perPage; |
|
111 | - } |
|
112 | - return $meta; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * get the result data |
|
117 | - * @return array |
|
118 | - */ |
|
119 | - public function getData() { |
|
120 | - return $this->data; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * return bool Whether the method succeeded |
|
125 | - * @return bool |
|
126 | - */ |
|
127 | - public function succeeded() { |
|
128 | - return ($this->statusCode == 100); |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Adds a new header to the response |
|
133 | - * @param string $name The name of the HTTP header |
|
134 | - * @param string $value The value, null will delete it |
|
135 | - * @return $this |
|
136 | - */ |
|
137 | - public function addHeader($name, $value) { |
|
138 | - $name = trim($name); // always remove leading and trailing whitespace |
|
139 | - // to be able to reliably check for security |
|
140 | - // headers |
|
141 | - |
|
142 | - if (is_null($value)) { |
|
143 | - unset($this->headers[$name]); |
|
144 | - } else { |
|
145 | - $this->headers[$name] = $value; |
|
146 | - } |
|
147 | - |
|
148 | - return $this; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Returns the set headers |
|
153 | - * @return array the headers |
|
154 | - */ |
|
155 | - public function getHeaders() { |
|
156 | - return $this->headers; |
|
157 | - } |
|
35 | + /** @var array */ |
|
36 | + protected $data; |
|
37 | + |
|
38 | + /** @var null|string */ |
|
39 | + protected $message; |
|
40 | + |
|
41 | + /** @var int */ |
|
42 | + protected $statusCode; |
|
43 | + |
|
44 | + /** @var integer */ |
|
45 | + protected $items; |
|
46 | + |
|
47 | + /** @var integer */ |
|
48 | + protected $perPage; |
|
49 | + |
|
50 | + /** @var array */ |
|
51 | + private $headers = []; |
|
52 | + |
|
53 | + /** |
|
54 | + * create the OCS_Result object |
|
55 | + * @param mixed $data the data to return |
|
56 | + * @param int $code |
|
57 | + * @param null|string $message |
|
58 | + * @param array $headers |
|
59 | + */ |
|
60 | + public function __construct($data = null, $code = 100, $message = null, $headers = []) { |
|
61 | + if ($data === null) { |
|
62 | + $this->data = []; |
|
63 | + } elseif (!is_array($data)) { |
|
64 | + $this->data = [$this->data]; |
|
65 | + } else { |
|
66 | + $this->data = $data; |
|
67 | + } |
|
68 | + $this->statusCode = $code; |
|
69 | + $this->message = $message; |
|
70 | + $this->headers = $headers; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * optionally set the total number of items available |
|
75 | + * @param int $items |
|
76 | + */ |
|
77 | + public function setTotalItems($items) { |
|
78 | + $this->items = $items; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * optionally set the the number of items per page |
|
83 | + * @param int $items |
|
84 | + */ |
|
85 | + public function setItemsPerPage($items) { |
|
86 | + $this->perPage = $items; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * get the status code |
|
91 | + * @return int |
|
92 | + */ |
|
93 | + public function getStatusCode() { |
|
94 | + return $this->statusCode; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * get the meta data for the result |
|
99 | + * @return array |
|
100 | + */ |
|
101 | + public function getMeta() { |
|
102 | + $meta = []; |
|
103 | + $meta['status'] = $this->succeeded() ? 'ok' : 'failure'; |
|
104 | + $meta['statuscode'] = $this->statusCode; |
|
105 | + $meta['message'] = $this->message; |
|
106 | + if (isset($this->items)) { |
|
107 | + $meta['totalitems'] = $this->items; |
|
108 | + } |
|
109 | + if (isset($this->perPage)) { |
|
110 | + $meta['itemsperpage'] = $this->perPage; |
|
111 | + } |
|
112 | + return $meta; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * get the result data |
|
117 | + * @return array |
|
118 | + */ |
|
119 | + public function getData() { |
|
120 | + return $this->data; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * return bool Whether the method succeeded |
|
125 | + * @return bool |
|
126 | + */ |
|
127 | + public function succeeded() { |
|
128 | + return ($this->statusCode == 100); |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Adds a new header to the response |
|
133 | + * @param string $name The name of the HTTP header |
|
134 | + * @param string $value The value, null will delete it |
|
135 | + * @return $this |
|
136 | + */ |
|
137 | + public function addHeader($name, $value) { |
|
138 | + $name = trim($name); // always remove leading and trailing whitespace |
|
139 | + // to be able to reliably check for security |
|
140 | + // headers |
|
141 | + |
|
142 | + if (is_null($value)) { |
|
143 | + unset($this->headers[$name]); |
|
144 | + } else { |
|
145 | + $this->headers[$name] = $value; |
|
146 | + } |
|
147 | + |
|
148 | + return $this; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Returns the set headers |
|
153 | + * @return array the headers |
|
154 | + */ |
|
155 | + public function getHeaders() { |
|
156 | + return $this->headers; |
|
157 | + } |
|
158 | 158 | } |
@@ -135,7 +135,7 @@ |
||
135 | 135 | * @return $this |
136 | 136 | */ |
137 | 137 | public function addHeader($name, $value) { |
138 | - $name = trim($name); // always remove leading and trailing whitespace |
|
138 | + $name = trim($name); // always remove leading and trailing whitespace |
|
139 | 139 | // to be able to reliably check for security |
140 | 140 | // headers |
141 | 141 |
@@ -29,20 +29,20 @@ |
||
29 | 29 | * local storage backend in temporary folder for testing purpose |
30 | 30 | */ |
31 | 31 | class Temporary extends Local { |
32 | - public function __construct($arguments = null) { |
|
33 | - parent::__construct(['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]); |
|
34 | - } |
|
32 | + public function __construct($arguments = null) { |
|
33 | + parent::__construct(['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]); |
|
34 | + } |
|
35 | 35 | |
36 | - public function cleanUp() { |
|
37 | - \OC_Helper::rmdirr($this->datadir); |
|
38 | - } |
|
36 | + public function cleanUp() { |
|
37 | + \OC_Helper::rmdirr($this->datadir); |
|
38 | + } |
|
39 | 39 | |
40 | - public function __destruct() { |
|
41 | - parent::__destruct(); |
|
42 | - $this->cleanUp(); |
|
43 | - } |
|
40 | + public function __destruct() { |
|
41 | + parent::__destruct(); |
|
42 | + $this->cleanUp(); |
|
43 | + } |
|
44 | 44 | |
45 | - public function getDataDir() { |
|
46 | - return $this->datadir; |
|
47 | - } |
|
45 | + public function getDataDir() { |
|
46 | + return $this->datadir; |
|
47 | + } |
|
48 | 48 | } |
@@ -50,7 +50,7 @@ |
||
50 | 50 | public function __construct($arguments) { |
51 | 51 | $this->user = $arguments['user']; |
52 | 52 | $datadir = $this->user->getHome(); |
53 | - $this->id = 'home::' . $this->user->getUID(); |
|
53 | + $this->id = 'home::'.$this->user->getUID(); |
|
54 | 54 | |
55 | 55 | parent::__construct(['datadir' => $datadir]); |
56 | 56 | } |
@@ -33,80 +33,80 @@ |
||
33 | 33 | * Specialized version of Local storage for home directory usage |
34 | 34 | */ |
35 | 35 | class Home extends Local implements \OCP\Files\IHomeStorage { |
36 | - /** |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - protected $id; |
|
36 | + /** |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + protected $id; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @var \OC\User\User $user |
|
43 | - */ |
|
44 | - protected $user; |
|
41 | + /** |
|
42 | + * @var \OC\User\User $user |
|
43 | + */ |
|
44 | + protected $user; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Construct a Home storage instance |
|
48 | - * |
|
49 | - * @param array $arguments array with "user" containing the |
|
50 | - * storage owner |
|
51 | - */ |
|
52 | - public function __construct($arguments) { |
|
53 | - $this->user = $arguments['user']; |
|
54 | - $datadir = $this->user->getHome(); |
|
55 | - $this->id = 'home::' . $this->user->getUID(); |
|
46 | + /** |
|
47 | + * Construct a Home storage instance |
|
48 | + * |
|
49 | + * @param array $arguments array with "user" containing the |
|
50 | + * storage owner |
|
51 | + */ |
|
52 | + public function __construct($arguments) { |
|
53 | + $this->user = $arguments['user']; |
|
54 | + $datadir = $this->user->getHome(); |
|
55 | + $this->id = 'home::' . $this->user->getUID(); |
|
56 | 56 | |
57 | - parent::__construct(['datadir' => $datadir]); |
|
58 | - } |
|
57 | + parent::__construct(['datadir' => $datadir]); |
|
58 | + } |
|
59 | 59 | |
60 | - public function getId() { |
|
61 | - return $this->id; |
|
62 | - } |
|
60 | + public function getId() { |
|
61 | + return $this->id; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return \OC\Files\Cache\HomeCache |
|
66 | - */ |
|
67 | - public function getCache($path = '', $storage = null) { |
|
68 | - if (!$storage) { |
|
69 | - $storage = $this; |
|
70 | - } |
|
71 | - if (!isset($this->cache)) { |
|
72 | - $this->cache = new \OC\Files\Cache\HomeCache($storage); |
|
73 | - } |
|
74 | - return $this->cache; |
|
75 | - } |
|
64 | + /** |
|
65 | + * @return \OC\Files\Cache\HomeCache |
|
66 | + */ |
|
67 | + public function getCache($path = '', $storage = null) { |
|
68 | + if (!$storage) { |
|
69 | + $storage = $this; |
|
70 | + } |
|
71 | + if (!isset($this->cache)) { |
|
72 | + $this->cache = new \OC\Files\Cache\HomeCache($storage); |
|
73 | + } |
|
74 | + return $this->cache; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * get a propagator instance for the cache |
|
79 | - * |
|
80 | - * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher |
|
81 | - * @return \OC\Files\Cache\Propagator |
|
82 | - */ |
|
83 | - public function getPropagator($storage = null) { |
|
84 | - if (!$storage) { |
|
85 | - $storage = $this; |
|
86 | - } |
|
87 | - if (!isset($this->propagator)) { |
|
88 | - $this->propagator = new HomePropagator($storage, \OC::$server->getDatabaseConnection()); |
|
89 | - } |
|
90 | - return $this->propagator; |
|
91 | - } |
|
77 | + /** |
|
78 | + * get a propagator instance for the cache |
|
79 | + * |
|
80 | + * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher |
|
81 | + * @return \OC\Files\Cache\Propagator |
|
82 | + */ |
|
83 | + public function getPropagator($storage = null) { |
|
84 | + if (!$storage) { |
|
85 | + $storage = $this; |
|
86 | + } |
|
87 | + if (!isset($this->propagator)) { |
|
88 | + $this->propagator = new HomePropagator($storage, \OC::$server->getDatabaseConnection()); |
|
89 | + } |
|
90 | + return $this->propagator; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | |
94 | - /** |
|
95 | - * Returns the owner of this home storage |
|
96 | - * |
|
97 | - * @return \OC\User\User owner of this home storage |
|
98 | - */ |
|
99 | - public function getUser() { |
|
100 | - return $this->user; |
|
101 | - } |
|
94 | + /** |
|
95 | + * Returns the owner of this home storage |
|
96 | + * |
|
97 | + * @return \OC\User\User owner of this home storage |
|
98 | + */ |
|
99 | + public function getUser() { |
|
100 | + return $this->user; |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * get the owner of a path |
|
105 | - * |
|
106 | - * @param string $path The path to get the owner |
|
107 | - * @return string uid or false |
|
108 | - */ |
|
109 | - public function getOwner($path) { |
|
110 | - return $this->user->getUID(); |
|
111 | - } |
|
103 | + /** |
|
104 | + * get the owner of a path |
|
105 | + * |
|
106 | + * @param string $path The path to get the owner |
|
107 | + * @return string uid or false |
|
108 | + */ |
|
109 | + public function getOwner($path) { |
|
110 | + return $this->user->getUID(); |
|
111 | + } |
|
112 | 112 | } |
@@ -49,7 +49,7 @@ |
||
49 | 49 | public function getDirectoryListing() { |
50 | 50 | $listing = $this->folder->getDirectoryListing(); |
51 | 51 | |
52 | - $fileListing = array_map(function (Node $file) { |
|
52 | + $fileListing = array_map(function(Node $file) { |
|
53 | 53 | if ($file instanceof File) { |
54 | 54 | return new SimpleFile($file); |
55 | 55 | } |
@@ -32,62 +32,62 @@ |
||
32 | 32 | |
33 | 33 | class SimpleFolder implements ISimpleFolder { |
34 | 34 | |
35 | - /** @var Folder */ |
|
36 | - private $folder; |
|
37 | - |
|
38 | - /** |
|
39 | - * Folder constructor. |
|
40 | - * |
|
41 | - * @param Folder $folder |
|
42 | - */ |
|
43 | - public function __construct(Folder $folder) { |
|
44 | - $this->folder = $folder; |
|
45 | - } |
|
46 | - |
|
47 | - public function getName() { |
|
48 | - return $this->folder->getName(); |
|
49 | - } |
|
50 | - |
|
51 | - public function getDirectoryListing() { |
|
52 | - $listing = $this->folder->getDirectoryListing(); |
|
53 | - |
|
54 | - $fileListing = array_map(function (Node $file) { |
|
55 | - if ($file instanceof File) { |
|
56 | - return new SimpleFile($file); |
|
57 | - } |
|
58 | - return null; |
|
59 | - }, $listing); |
|
60 | - |
|
61 | - $fileListing = array_filter($fileListing); |
|
62 | - |
|
63 | - return array_values($fileListing); |
|
64 | - } |
|
65 | - |
|
66 | - public function delete() { |
|
67 | - $this->folder->delete(); |
|
68 | - } |
|
69 | - |
|
70 | - public function fileExists($name) { |
|
71 | - return $this->folder->nodeExists($name); |
|
72 | - } |
|
73 | - |
|
74 | - public function getFile($name) { |
|
75 | - $file = $this->folder->get($name); |
|
76 | - |
|
77 | - if (!($file instanceof File)) { |
|
78 | - throw new NotFoundException(); |
|
79 | - } |
|
80 | - |
|
81 | - return new SimpleFile($file); |
|
82 | - } |
|
83 | - |
|
84 | - public function newFile($name, $content = null) { |
|
85 | - if ($content === null) { |
|
86 | - // delay creating the file until it's written to |
|
87 | - return new NewSimpleFile($this->folder, $name); |
|
88 | - } else { |
|
89 | - $file = $this->folder->newFile($name, $content); |
|
90 | - return new SimpleFile($file); |
|
91 | - } |
|
92 | - } |
|
35 | + /** @var Folder */ |
|
36 | + private $folder; |
|
37 | + |
|
38 | + /** |
|
39 | + * Folder constructor. |
|
40 | + * |
|
41 | + * @param Folder $folder |
|
42 | + */ |
|
43 | + public function __construct(Folder $folder) { |
|
44 | + $this->folder = $folder; |
|
45 | + } |
|
46 | + |
|
47 | + public function getName() { |
|
48 | + return $this->folder->getName(); |
|
49 | + } |
|
50 | + |
|
51 | + public function getDirectoryListing() { |
|
52 | + $listing = $this->folder->getDirectoryListing(); |
|
53 | + |
|
54 | + $fileListing = array_map(function (Node $file) { |
|
55 | + if ($file instanceof File) { |
|
56 | + return new SimpleFile($file); |
|
57 | + } |
|
58 | + return null; |
|
59 | + }, $listing); |
|
60 | + |
|
61 | + $fileListing = array_filter($fileListing); |
|
62 | + |
|
63 | + return array_values($fileListing); |
|
64 | + } |
|
65 | + |
|
66 | + public function delete() { |
|
67 | + $this->folder->delete(); |
|
68 | + } |
|
69 | + |
|
70 | + public function fileExists($name) { |
|
71 | + return $this->folder->nodeExists($name); |
|
72 | + } |
|
73 | + |
|
74 | + public function getFile($name) { |
|
75 | + $file = $this->folder->get($name); |
|
76 | + |
|
77 | + if (!($file instanceof File)) { |
|
78 | + throw new NotFoundException(); |
|
79 | + } |
|
80 | + |
|
81 | + return new SimpleFile($file); |
|
82 | + } |
|
83 | + |
|
84 | + public function newFile($name, $content = null) { |
|
85 | + if ($content === null) { |
|
86 | + // delay creating the file until it's written to |
|
87 | + return new NewSimpleFile($this->folder, $name); |
|
88 | + } else { |
|
89 | + $file = $this->folder->newFile($name, $content); |
|
90 | + return new SimpleFile($file); |
|
91 | + } |
|
92 | + } |
|
93 | 93 | } |