Passed
Push — master ( f99642...201905 )
by Joas
13:29 queued 12s
created
core/Db/LoginFlowV2Mapper.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -30,71 +30,71 @@
 block discarded – undo
30 30
 use OCP\IDBConnection;
31 31
 
32 32
 class LoginFlowV2Mapper extends QBMapper {
33
-	private const lifetime = 1200;
33
+    private const lifetime = 1200;
34 34
 
35
-	/** @var ITimeFactory */
36
-	private $timeFactory;
35
+    /** @var ITimeFactory */
36
+    private $timeFactory;
37 37
 
38
-	public function __construct(IDBConnection $db, ITimeFactory $timeFactory) {
39
-		parent::__construct($db, 'login_flow_v2', LoginFlowV2::class);
40
-		$this->timeFactory = $timeFactory;
41
-	}
38
+    public function __construct(IDBConnection $db, ITimeFactory $timeFactory) {
39
+        parent::__construct($db, 'login_flow_v2', LoginFlowV2::class);
40
+        $this->timeFactory = $timeFactory;
41
+    }
42 42
 
43
-	/**
44
-	 * @param string $pollToken
45
-	 * @return LoginFlowV2
46
-	 * @throws DoesNotExistException
47
-	 */
48
-	public function getByPollToken(string $pollToken): LoginFlowV2 {
49
-		$qb = $this->db->getQueryBuilder();
50
-		$qb->select('*')
51
-			->from($this->getTableName())
52
-			->where(
53
-				$qb->expr()->eq('poll_token', $qb->createNamedParameter($pollToken))
54
-			);
43
+    /**
44
+     * @param string $pollToken
45
+     * @return LoginFlowV2
46
+     * @throws DoesNotExistException
47
+     */
48
+    public function getByPollToken(string $pollToken): LoginFlowV2 {
49
+        $qb = $this->db->getQueryBuilder();
50
+        $qb->select('*')
51
+            ->from($this->getTableName())
52
+            ->where(
53
+                $qb->expr()->eq('poll_token', $qb->createNamedParameter($pollToken))
54
+            );
55 55
 
56
-		$entity = $this->findEntity($qb);
57
-		return $this->validateTimestamp($entity);
58
-	}
56
+        $entity = $this->findEntity($qb);
57
+        return $this->validateTimestamp($entity);
58
+    }
59 59
 
60
-	/**
61
-	 * @param string $loginToken
62
-	 * @return LoginFlowV2
63
-	 * @throws DoesNotExistException
64
-	 */
65
-	public function getByLoginToken(string $loginToken): LoginFlowV2 {
66
-		$qb = $this->db->getQueryBuilder();
67
-		$qb->select('*')
68
-			->from($this->getTableName())
69
-			->where(
70
-				$qb->expr()->eq('login_token', $qb->createNamedParameter($loginToken))
71
-			);
60
+    /**
61
+     * @param string $loginToken
62
+     * @return LoginFlowV2
63
+     * @throws DoesNotExistException
64
+     */
65
+    public function getByLoginToken(string $loginToken): LoginFlowV2 {
66
+        $qb = $this->db->getQueryBuilder();
67
+        $qb->select('*')
68
+            ->from($this->getTableName())
69
+            ->where(
70
+                $qb->expr()->eq('login_token', $qb->createNamedParameter($loginToken))
71
+            );
72 72
 
73
-		$entity = $this->findEntity($qb);
74
-		return $this->validateTimestamp($entity);
75
-	}
73
+        $entity = $this->findEntity($qb);
74
+        return $this->validateTimestamp($entity);
75
+    }
76 76
 
77
-	public function cleanup(): void {
78
-		$qb = $this->db->getQueryBuilder();
79
-		$qb->delete($this->getTableName())
80
-			->where(
81
-				$qb->expr()->lt('timestamp', $qb->createNamedParameter($this->timeFactory->getTime() - self::lifetime))
82
-			);
77
+    public function cleanup(): void {
78
+        $qb = $this->db->getQueryBuilder();
79
+        $qb->delete($this->getTableName())
80
+            ->where(
81
+                $qb->expr()->lt('timestamp', $qb->createNamedParameter($this->timeFactory->getTime() - self::lifetime))
82
+            );
83 83
 
84
-		$qb->execute();
85
-	}
84
+        $qb->execute();
85
+    }
86 86
 
87
-	/**
88
-	 * @param LoginFlowV2 $flowV2
89
-	 * @return LoginFlowV2
90
-	 * @throws DoesNotExistException
91
-	 */
92
-	private function validateTimestamp(LoginFlowV2 $flowV2): LoginFlowV2 {
93
-		if ($flowV2->getTimestamp() < ($this->timeFactory->getTime() - self::lifetime)) {
94
-			$this->delete($flowV2);
95
-			throw new DoesNotExistException('Token expired');
96
-		}
87
+    /**
88
+     * @param LoginFlowV2 $flowV2
89
+     * @return LoginFlowV2
90
+     * @throws DoesNotExistException
91
+     */
92
+    private function validateTimestamp(LoginFlowV2 $flowV2): LoginFlowV2 {
93
+        if ($flowV2->getTimestamp() < ($this->timeFactory->getTime() - self::lifetime)) {
94
+            $this->delete($flowV2);
95
+            throw new DoesNotExistException('Token expired');
96
+        }
97 97
 
98
-		return $flowV2;
99
-	}
98
+        return $flowV2;
99
+    }
100 100
 }
Please login to merge, or discard this patch.
lib/public/Group/Backend/IHideFromCollaborationBackend.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -27,12 +27,12 @@
 block discarded – undo
27 27
  * Allow the backend to mark groups to be excluded from being shown in search dialogs
28 28
  */
29 29
 interface IHideFromCollaborationBackend {
30
-	/**
31
-	 * Check if a group should be hidden from search dialogs
32
-	 *
33
-	 * @param string $groupId
34
-	 * @return bool
35
-	 * @since 16.0.0
36
-	 */
37
-	public function hideGroup(string $groupId): bool;
30
+    /**
31
+     * Check if a group should be hidden from search dialogs
32
+     *
33
+     * @param string $groupId
34
+     * @return bool
35
+     * @since 16.0.0
36
+     */
37
+    public function hideGroup(string $groupId): bool;
38 38
 }
Please login to merge, or discard this patch.
lib/private/Files/Node/NonExistingFile.php 1 patch
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -26,119 +26,119 @@
 block discarded – undo
26 26
 use OCP\Files\NotFoundException;
27 27
 
28 28
 class NonExistingFile extends File {
29
-	/**
30
-	 * @param string $newPath
31
-	 * @throws \OCP\Files\NotFoundException
32
-	 */
33
-	public function rename($newPath) {
34
-		throw new NotFoundException();
35
-	}
36
-
37
-	public function delete() {
38
-		throw new NotFoundException();
39
-	}
40
-
41
-	public function copy($newPath) {
42
-		throw new NotFoundException();
43
-	}
44
-
45
-	public function touch($mtime = null) {
46
-		throw new NotFoundException();
47
-	}
48
-
49
-	public function getId() {
50
-		if ($this->fileInfo) {
51
-			return parent::getId();
52
-		} else {
53
-			throw new NotFoundException();
54
-		}
55
-	}
56
-
57
-	public function stat() {
58
-		throw new NotFoundException();
59
-	}
60
-
61
-	public function getMTime() {
62
-		if ($this->fileInfo) {
63
-			return parent::getMTime();
64
-		} else {
65
-			throw new NotFoundException();
66
-		}
67
-	}
68
-
69
-	public function getSize($includeMounts = true) {
70
-		if ($this->fileInfo) {
71
-			return parent::getSize($includeMounts);
72
-		} else {
73
-			throw new NotFoundException();
74
-		}
75
-	}
76
-
77
-	public function getEtag() {
78
-		if ($this->fileInfo) {
79
-			return parent::getEtag();
80
-		} else {
81
-			throw new NotFoundException();
82
-		}
83
-	}
84
-
85
-	public function getPermissions() {
86
-		if ($this->fileInfo) {
87
-			return parent::getPermissions();
88
-		} else {
89
-			throw new NotFoundException();
90
-		}
91
-	}
92
-
93
-	public function isReadable() {
94
-		if ($this->fileInfo) {
95
-			return parent::isReadable();
96
-		} else {
97
-			throw new NotFoundException();
98
-		}
99
-	}
100
-
101
-	public function isUpdateable() {
102
-		if ($this->fileInfo) {
103
-			return parent::isUpdateable();
104
-		} else {
105
-			throw new NotFoundException();
106
-		}
107
-	}
108
-
109
-	public function isDeletable() {
110
-		if ($this->fileInfo) {
111
-			return parent::isDeletable();
112
-		} else {
113
-			throw new NotFoundException();
114
-		}
115
-	}
116
-
117
-	public function isShareable() {
118
-		if ($this->fileInfo) {
119
-			return parent::isShareable();
120
-		} else {
121
-			throw new NotFoundException();
122
-		}
123
-	}
124
-
125
-	public function getContent() {
126
-		throw new NotFoundException();
127
-	}
128
-
129
-	public function putContent($data) {
130
-		throw new NotFoundException();
131
-	}
132
-
133
-	public function getMimeType() {
134
-		if ($this->fileInfo) {
135
-			return parent::getMimeType();
136
-		} else {
137
-			throw new NotFoundException();
138
-		}
139
-	}
140
-
141
-	public function fopen($mode) {
142
-		throw new NotFoundException();
143
-	}
29
+    /**
30
+     * @param string $newPath
31
+     * @throws \OCP\Files\NotFoundException
32
+     */
33
+    public function rename($newPath) {
34
+        throw new NotFoundException();
35
+    }
36
+
37
+    public function delete() {
38
+        throw new NotFoundException();
39
+    }
40
+
41
+    public function copy($newPath) {
42
+        throw new NotFoundException();
43
+    }
44
+
45
+    public function touch($mtime = null) {
46
+        throw new NotFoundException();
47
+    }
48
+
49
+    public function getId() {
50
+        if ($this->fileInfo) {
51
+            return parent::getId();
52
+        } else {
53
+            throw new NotFoundException();
54
+        }
55
+    }
56
+
57
+    public function stat() {
58
+        throw new NotFoundException();
59
+    }
60
+
61
+    public function getMTime() {
62
+        if ($this->fileInfo) {
63
+            return parent::getMTime();
64
+        } else {
65
+            throw new NotFoundException();
66
+        }
67
+    }
68
+
69
+    public function getSize($includeMounts = true) {
70
+        if ($this->fileInfo) {
71
+            return parent::getSize($includeMounts);
72
+        } else {
73
+            throw new NotFoundException();
74
+        }
75
+    }
76
+
77
+    public function getEtag() {
78
+        if ($this->fileInfo) {
79
+            return parent::getEtag();
80
+        } else {
81
+            throw new NotFoundException();
82
+        }
83
+    }
84
+
85
+    public function getPermissions() {
86
+        if ($this->fileInfo) {
87
+            return parent::getPermissions();
88
+        } else {
89
+            throw new NotFoundException();
90
+        }
91
+    }
92
+
93
+    public function isReadable() {
94
+        if ($this->fileInfo) {
95
+            return parent::isReadable();
96
+        } else {
97
+            throw new NotFoundException();
98
+        }
99
+    }
100
+
101
+    public function isUpdateable() {
102
+        if ($this->fileInfo) {
103
+            return parent::isUpdateable();
104
+        } else {
105
+            throw new NotFoundException();
106
+        }
107
+    }
108
+
109
+    public function isDeletable() {
110
+        if ($this->fileInfo) {
111
+            return parent::isDeletable();
112
+        } else {
113
+            throw new NotFoundException();
114
+        }
115
+    }
116
+
117
+    public function isShareable() {
118
+        if ($this->fileInfo) {
119
+            return parent::isShareable();
120
+        } else {
121
+            throw new NotFoundException();
122
+        }
123
+    }
124
+
125
+    public function getContent() {
126
+        throw new NotFoundException();
127
+    }
128
+
129
+    public function putContent($data) {
130
+        throw new NotFoundException();
131
+    }
132
+
133
+    public function getMimeType() {
134
+        if ($this->fileInfo) {
135
+            return parent::getMimeType();
136
+        } else {
137
+            throw new NotFoundException();
138
+        }
139
+    }
140
+
141
+    public function fopen($mode) {
142
+        throw new NotFoundException();
143
+    }
144 144
 }
Please login to merge, or discard this patch.
lib/private/FullTextSearch/Model/IndexDocument.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -389,7 +389,7 @@
 block discarded – undo
389 389
 		foreach ($ak as $source) {
390 390
 			$tags = $this->subTags[$source];
391 391
 			foreach ($tags as $tag) {
392
-				$subTags[] = $source . '_' . $tag;
392
+				$subTags[] = $source.'_'.$tag;
393 393
 			}
394 394
 		}
395 395
 
Please login to merge, or discard this patch.
Indentation   +934 added lines, -934 removed lines patch added patch discarded remove patch
@@ -47,940 +47,940 @@
 block discarded – undo
47 47
  * @package OC\FullTextSearch\Model
48 48
  */
49 49
 class IndexDocument implements IIndexDocument, JsonSerializable {
50
-	/** @var string */
51
-	protected $id = '';
50
+    /** @var string */
51
+    protected $id = '';
52 52
 
53
-	/** @var string */
54
-	protected $providerId = '';
53
+    /** @var string */
54
+    protected $providerId = '';
55 55
 
56
-	/** @var DocumentAccess */
57
-	protected $access;
58
-
59
-	/** @var IIndex */
60
-	protected $index;
61
-
62
-	/** @var int */
63
-	protected $modifiedTime = 0;
64
-
65
-	/** @var string */
66
-	protected $source = '';
67
-
68
-	/** @var array */
69
-	protected $tags = [];
70
-
71
-	/** @var array */
72
-	protected $metaTags = [];
73
-
74
-	/** @var array */
75
-	protected $subTags = [];
76
-
77
-	/** @var string */
78
-	protected $title = '';
79
-
80
-	/** @var string */
81
-	protected $content = '';
82
-
83
-	/** @var string */
84
-	protected $hash = '';
85
-
86
-	/** @var array */
87
-	protected $parts = [];
88
-
89
-	/** @var string */
90
-	protected $link = '';
91
-
92
-	/** @var array */
93
-	protected $more = [];
94
-
95
-	/** @var array */
96
-	protected $excerpts = [];
97
-
98
-	/** @var string */
99
-	protected $score = '';
100
-
101
-	/** @var array */
102
-	protected $info = [];
103
-
104
-	/** @var int */
105
-	protected $contentEncoded = 0;
106
-
107
-
108
-	/**
109
-	 * IIndexDocument constructor.
110
-	 *
111
-	 * On creation, we assure the uniqueness of the object using the providerId
112
-	 * and the Id of the original document.
113
-	 *
114
-	 * @since 15.0.0
115
-	 *
116
-	 * @param string $providerId
117
-	 * @param string $documentId
118
-	 */
119
-	public function __construct(string $providerId, string $documentId) {
120
-		$this->providerId = $providerId;
121
-		$this->id = $documentId;
122
-	}
123
-
124
-
125
-	/**
126
-	 * Returns the Id of the original document.
127
-	 *
128
-	 * @since 15.0.0
129
-	 *
130
-	 * @return string
131
-	 */
132
-	final public function getId(): string {
133
-		return $this->id;
134
-	}
135
-
136
-
137
-	/**
138
-	 * Returns the Id of the provider.
139
-	 *
140
-	 * @since 15.0.0
141
-	 *
142
-	 * @return string
143
-	 */
144
-	final public function getProviderId(): string {
145
-		return $this->providerId;
146
-	}
147
-
148
-
149
-	/**
150
-	 * Set the Index related to the IIndexDocument.
151
-	 *
152
-	 * @see IIndex
153
-	 *
154
-	 * @since 15.0.0
155
-	 *
156
-	 * @param IIndex $index
157
-	 *
158
-	 * @return IIndexDocument
159
-	 */
160
-	final public function setIndex(IIndex $index): IIndexDocument {
161
-		$this->index = $index;
162
-
163
-		return $this;
164
-	}
165
-
166
-	/**
167
-	 * Get the Index.
168
-	 *
169
-	 * @since 15.0.0
170
-	 *
171
-	 * @return IIndex
172
-	 */
173
-	final public function getIndex(): IIndex {
174
-		return $this->index;
175
-	}
176
-
177
-	/**
178
-	 * return if Index is defined.
179
-	 *
180
-	 * @since 16.0.0
181
-	 *
182
-	 * @return bool
183
-	 */
184
-	final public function hasIndex(): bool {
185
-		return ($this->index !== null);
186
-	}
187
-
188
-
189
-	/**
190
-	 * Set the modified time of the original document.
191
-	 *
192
-	 * @since 15.0.0
193
-	 *
194
-	 * @param int $modifiedTime
195
-	 *
196
-	 * @return IIndexDocument
197
-	 */
198
-	final public function setModifiedTime(int $modifiedTime): IIndexDocument {
199
-		$this->modifiedTime = $modifiedTime;
200
-
201
-		return $this;
202
-	}
203
-
204
-	/**
205
-	 * Get the modified time of the original document.
206
-	 *
207
-	 * @since 15.0.0
208
-	 *
209
-	 * @return int
210
-	 */
211
-	final public function getModifiedTime(): int {
212
-		return $this->modifiedTime;
213
-	}
214
-
215
-	/**
216
-	 * Check if the original document of the IIndexDocument is older than $time.
217
-	 *
218
-	 * @since 15.0.0
219
-	 *
220
-	 * @param int $time
221
-	 *
222
-	 * @return bool
223
-	 */
224
-	final public function isOlderThan(int $time): bool {
225
-		return ($this->modifiedTime < $time);
226
-	}
227
-
228
-
229
-	/**
230
-	 * Set the read rights of the original document using a IDocumentAccess.
231
-	 *
232
-	 * @see IDocumentAccess
233
-	 *
234
-	 * @since 15.0.0
235
-	 *
236
-	 * @param IDocumentAccess $access
237
-	 *
238
-	 * @return $this
239
-	 */
240
-	final public function setAccess(IDocumentAccess $access): IIndexDocument {
241
-		$this->access = $access;
242
-
243
-		return $this;
244
-	}
245
-
246
-	/**
247
-	 * Get the IDocumentAccess related to the original document.
248
-	 *
249
-	 * @since 15.0.0
250
-	 *
251
-	 * @return IDocumentAccess
252
-	 */
253
-	final public function getAccess(): IDocumentAccess {
254
-		return $this->access;
255
-	}
256
-
257
-
258
-	/**
259
-	 * Add a tag to the list.
260
-	 *
261
-	 * @since 15.0.0
262
-	 *
263
-	 * @param string $tag
264
-	 *
265
-	 * @return IIndexDocument
266
-	 */
267
-	final public function addTag(string $tag): IIndexDocument {
268
-		$this->tags[] = $tag;
269
-
270
-		return $this;
271
-	}
272
-
273
-	/**
274
-	 * Set the list of tags assigned to the original document.
275
-	 *
276
-	 * @since 15.0.0
277
-	 *
278
-	 * @param array $tags
279
-	 *
280
-	 * @return IIndexDocument
281
-	 */
282
-	final public function setTags(array $tags): IIndexDocument {
283
-		$this->tags = $tags;
284
-
285
-		return $this;
286
-	}
287
-
288
-	/**
289
-	 * Get the list of tags assigned to the original document.
290
-	 *
291
-	 * @since 15.0.0
292
-	 *
293
-	 * @return array
294
-	 */
295
-	final public function getTags(): array {
296
-		return $this->tags;
297
-	}
298
-
299
-
300
-	/**
301
-	 * Add a meta tag to the list.
302
-	 *
303
-	 * @since 15.0.0
304
-	 *
305
-	 * @param string $tag
306
-	 *
307
-	 * @return IIndexDocument
308
-	 */
309
-	final public function addMetaTag(string $tag): IIndexDocument {
310
-		$this->metaTags[] = $tag;
311
-
312
-		return $this;
313
-	}
314
-
315
-	/**
316
-	 * Set the list of meta tags assigned to the original document.
317
-	 *
318
-	 * @since 15.0.0
319
-	 *
320
-	 * @param array $tags
321
-	 *
322
-	 * @return IIndexDocument
323
-	 */
324
-	final public function setMetaTags(array $tags): IIndexDocument {
325
-		$this->metaTags = $tags;
326
-
327
-		return $this;
328
-	}
329
-
330
-	/**
331
-	 * Get the list of meta tags assigned to the original document.
332
-	 *
333
-	 * @since 15.0.0
334
-	 *
335
-	 * @return array
336
-	 */
337
-	final public function getMetaTags(): array {
338
-		return $this->metaTags;
339
-	}
340
-
341
-
342
-	/**
343
-	 * Add a sub tag to the list.
344
-	 *
345
-	 * @since 15.0.0
346
-	 *
347
-	 * @param string $sub
348
-	 * @param string $tag
349
-	 *
350
-	 * @return IIndexDocument
351
-	 */
352
-	final public function addSubTag(string $sub, string $tag): IIndexDocument {
353
-		if (!array_key_exists($sub, $this->subTags)) {
354
-			$this->subTags[$sub] = [];
355
-		}
356
-
357
-		$this->subTags[$sub][] = $tag;
358
-
359
-		return $this;
360
-	}
361
-
362
-
363
-	/**
364
-	 * Set the list of sub tags assigned to the original document.
365
-	 *
366
-	 * @since 15.0.0
367
-	 *
368
-	 * @param array $tags
369
-	 *
370
-	 * @return IIndexDocument
371
-	 */
372
-	final public function setSubTags(array $tags): IIndexDocument {
373
-		$this->subTags = $tags;
374
-
375
-		return $this;
376
-	}
377
-
378
-	/**
379
-	 * Get the list of sub tags assigned to the original document.
380
-	 * If $formatted is true, the result will be formatted in a one
381
-	 * dimensional array.
382
-	 *
383
-	 * @since 15.0.0
384
-	 *
385
-	 * @param bool $formatted
386
-	 *
387
-	 * @return array
388
-	 */
389
-	final public function getSubTags(bool $formatted = false): array {
390
-		if ($formatted === false) {
391
-			return $this->subTags;
392
-		}
393
-
394
-		$subTags = [];
395
-		$ak = array_keys($this->subTags);
396
-		foreach ($ak as $source) {
397
-			$tags = $this->subTags[$source];
398
-			foreach ($tags as $tag) {
399
-				$subTags[] = $source . '_' . $tag;
400
-			}
401
-		}
402
-
403
-		return $subTags;
404
-	}
405
-
406
-
407
-	/**
408
-	 * Set the source of the original document.
409
-	 *
410
-	 * @since 15.0.0
411
-	 *
412
-	 * @param string $source
413
-	 *
414
-	 * @return IIndexDocument
415
-	 */
416
-	final public function setSource(string $source): IIndexDocument {
417
-		$this->source = $source;
418
-
419
-		return $this;
420
-	}
421
-
422
-	/**
423
-	 * Get the source of the original document.
424
-	 *
425
-	 * @since 15.0.0
426
-	 *
427
-	 * @return string
428
-	 */
429
-	final public function getSource(): string {
430
-		return $this->source;
431
-	}
432
-
433
-
434
-	/**
435
-	 * Set the title of the original document.
436
-	 *
437
-	 * @since 15.0.0
438
-	 *
439
-	 * @param string $title
440
-	 *
441
-	 * @return IIndexDocument
442
-	 */
443
-	final public function setTitle(string $title): IIndexDocument {
444
-		$this->title = $title;
445
-
446
-		return $this;
447
-	}
448
-
449
-	/**
450
-	 * Get the title of the original document.
451
-	 *
452
-	 * @since 15.0.0
453
-	 *
454
-	 * @return string
455
-	 */
456
-	final public function getTitle(): string {
457
-		return $this->title;
458
-	}
459
-
460
-
461
-	/**
462
-	 * Set the content of the document.
463
-	 * $encoded can be NOT_ENCODED or ENCODED_BASE64 if the content is raw or
464
-	 * encoded in base64.
465
-	 *
466
-	 * @since 15.0.0
467
-	 *
468
-	 * @param string $content
469
-	 * @param int $encoded
470
-	 *
471
-	 * @return IIndexDocument
472
-	 */
473
-	final public function setContent(string $content, int $encoded = 0): IIndexDocument {
474
-		$this->content = $content;
475
-		$this->contentEncoded = $encoded;
476
-
477
-		return $this;
478
-	}
479
-
480
-	/**
481
-	 * Get the content of the original document.
482
-	 *
483
-	 * @since 15.0.0
484
-	 *
485
-	 * @return string
486
-	 */
487
-	final public function getContent(): string {
488
-		return $this->content;
489
-	}
490
-
491
-	/**
492
-	 * Returns the type of the encoding on the content.
493
-	 *
494
-	 * @since 15.0.0
495
-	 *
496
-	 * @return int
497
-	 */
498
-	final public function isContentEncoded(): int {
499
-		return $this->contentEncoded;
500
-	}
501
-
502
-	/**
503
-	 * Return the size of the content.
504
-	 *
505
-	 * @since 15.0.0
506
-	 *
507
-	 * @return int
508
-	 */
509
-	final public function getContentSize(): int {
510
-		return strlen($this->getContent());
511
-	}
512
-
513
-
514
-	/**
515
-	 * Generate an hash, based on the content of the original document.
516
-	 *
517
-	 * @since 15.0.0
518
-	 *
519
-	 * @return IIndexDocument
520
-	 */
521
-	final public function initHash(): IIndexDocument {
522
-		if ($this->getContent() === '' || is_null($this->getContent())) {
523
-			return $this;
524
-		}
525
-
526
-		$this->hash = hash("md5", $this->getContent());
527
-
528
-		return $this;
529
-	}
530
-
531
-	/**
532
-	 * Set the hash of the original document.
533
-	 *
534
-	 * @since 15.0.0
535
-	 *
536
-	 * @param string $hash
537
-	 *
538
-	 * @return IIndexDocument
539
-	 */
540
-	final public function setHash(string $hash): IIndexDocument {
541
-		$this->hash = $hash;
542
-
543
-		return $this;
544
-	}
545
-
546
-	/**
547
-	 * Get the hash of the original document.
548
-	 *
549
-	 * @since 15.0.0
550
-	 *
551
-	 * @return string
552
-	 */
553
-	final public function getHash(): string {
554
-		return $this->hash;
555
-	}
556
-
557
-
558
-	/**
559
-	 * Add a part, identified by a string, and its content.
560
-	 *
561
-	 * It is strongly advised to use alphanumerical chars with no space in the
562
-	 * $part string.
563
-	 *
564
-	 * @since 15.0.0
565
-	 *
566
-	 * @param string $part
567
-	 * @param string $content
568
-	 *
569
-	 * @return IIndexDocument
570
-	 */
571
-	final public function addPart(string $part, string $content): IIndexDocument {
572
-		$this->parts[$part] = $content;
573
-
574
-		return $this;
575
-	}
576
-
577
-	/**
578
-	 * Set all parts and their content.
579
-	 *
580
-	 * @since 15.0.0
581
-	 *
582
-	 * @param array $parts
583
-	 *
584
-	 * @return IIndexDocument
585
-	 */
586
-	final public function setParts(array $parts): IIndexDocument {
587
-		$this->parts = $parts;
588
-
589
-		return $this;
590
-	}
591
-
592
-	/**
593
-	 * Get all parts of the IIndexDocument.
594
-	 *
595
-	 * @since 15.0.0
596
-	 *
597
-	 * @return array
598
-	 */
599
-	final public function getParts(): array {
600
-		return $this->parts;
601
-	}
602
-
603
-
604
-	/**
605
-	 * Add a link, usable by the frontend.
606
-	 *
607
-	 * @since 15.0.0
608
-	 *
609
-	 * @param string $link
610
-	 *
611
-	 * @return IIndexDocument
612
-	 */
613
-	final public function setLink(string $link): IIndexDocument {
614
-		$this->link = $link;
615
-
616
-		return $this;
617
-	}
618
-
619
-	/**
620
-	 * Get the link.
621
-	 *
622
-	 * @since 15.0.0
623
-	 *
624
-	 * @return string
625
-	 */
626
-	final public function getLink(): string {
627
-		return $this->link;
628
-	}
629
-
630
-
631
-	/**
632
-	 * Set more information that couldn't be set using other method.
633
-	 *
634
-	 * @since 15.0.0
635
-	 *
636
-	 * @param array $more
637
-	 *
638
-	 * @return IIndexDocument
639
-	 */
640
-	final public function setMore(array $more): IIndexDocument {
641
-		$this->more = $more;
642
-
643
-		return $this;
644
-	}
645
-
646
-	/**
647
-	 * Get more information.
648
-	 *
649
-	 * @since 15.0.0
650
-	 *
651
-	 * @return array
652
-	 */
653
-	final public function getMore(): array {
654
-		return $this->more;
655
-	}
656
-
657
-
658
-	/**
659
-	 * Add some excerpt of the content of the original document, usually based
660
-	 * on the search request.
661
-	 *
662
-	 * @since 16.0.0
663
-	 *
664
-	 * @param string $source
665
-	 * @param string $excerpt
666
-	 *
667
-	 * @return IIndexDocument
668
-	 */
669
-	final public function addExcerpt(string $source, string $excerpt): IIndexDocument {
670
-		$this->excerpts[] =
671
-			[
672
-				'source' => $source,
673
-				'excerpt' => $this->cleanExcerpt($excerpt)
674
-			];
675
-
676
-		return $this;
677
-	}
678
-
679
-
680
-	/**
681
-	 * Set all excerpts of the content of the original document.
682
-	 *
683
-	 * @since 16.0.0
684
-	 *
685
-	 * @param array $excerpts
686
-	 *
687
-	 * @return IIndexDocument
688
-	 */
689
-	final public function setExcerpts(array $excerpts): IIndexDocument {
690
-		$new = [];
691
-		foreach ($excerpts as $entry) {
692
-			$new[] = [
693
-				'source' => $entry['source'],
694
-				'excerpt' => $this->cleanExcerpt($entry['excerpt'])
695
-			];
696
-		}
697
-
698
-		$this->excerpts = $new;
699
-
700
-		return $this;
701
-	}
702
-
703
-	/**
704
-	 * Get all excerpts of the content of the original document.
705
-	 *
706
-	 * @since 15.0.0
707
-	 *
708
-	 * @return array
709
-	 */
710
-	final public function getExcerpts(): array {
711
-		return $this->excerpts;
712
-	}
713
-
714
-	/**
715
-	 * Clean excerpt.
716
-	 *
717
-	 * @since 16.0.0
718
-	 *
719
-	 * @param string $excerpt
720
-	 * @return string
721
-	 */
722
-	private function cleanExcerpt(string $excerpt): string {
723
-		$excerpt = str_replace("\\n", ' ', $excerpt);
724
-		$excerpt = str_replace("\\r", ' ', $excerpt);
725
-		$excerpt = str_replace("\\t", ' ', $excerpt);
726
-		$excerpt = str_replace("\n", ' ', $excerpt);
727
-		$excerpt = str_replace("\r", ' ', $excerpt);
728
-		$excerpt = str_replace("\t", ' ', $excerpt);
729
-
730
-		return $excerpt;
731
-	}
732
-
733
-
734
-	/**
735
-	 * Set the score to the result assigned to this document during a search
736
-	 * request.
737
-	 *
738
-	 * @since 15.0.0
739
-	 *
740
-	 * @param string $score
741
-	 *
742
-	 * @return IIndexDocument
743
-	 */
744
-	final public function setScore(string $score): IIndexDocument {
745
-		$this->score = $score;
746
-
747
-		return $this;
748
-	}
749
-
750
-	/**
751
-	 * Get the score.
752
-	 *
753
-	 * @since 15.0.0
754
-	 *
755
-	 * @return string
756
-	 */
757
-	final public function getScore(): string {
758
-		return $this->score;
759
-	}
760
-
761
-
762
-	/**
763
-	 * Set some information about the original document that will be available
764
-	 * to the front-end when displaying search result. (as string)
765
-	 * Because this information will not be indexed, this method can also be
766
-	 * used to manage some data while filling the IIndexDocument before its
767
-	 * indexing.
768
-	 *
769
-	 * @since 15.0.0
770
-	 *
771
-	 * @param string $info
772
-	 * @param string $value
773
-	 *
774
-	 * @return IIndexDocument
775
-	 */
776
-	final public function setInfo(string $info, string $value): IIndexDocument {
777
-		$this->info[$info] = $value;
778
-
779
-		return $this;
780
-	}
781
-
782
-	/**
783
-	 * Get an information about a document. (string)
784
-	 *
785
-	 * @since 15.0.0
786
-	 *
787
-	 * @param string $info
788
-	 * @param string $default
789
-	 *
790
-	 * @return string
791
-	 */
792
-	final public function getInfo(string $info, string $default = ''): string {
793
-		if (!key_exists($info, $this->info)) {
794
-			return $default;
795
-		}
796
-
797
-		return $this->info[$info];
798
-	}
799
-
800
-	/**
801
-	 * Set some information about the original document that will be available
802
-	 * to the front-end when displaying search result. (as array)
803
-	 * Because this information will not be indexed, this method can also be
804
-	 * used to manage some data while filling the IIndexDocument before its
805
-	 * indexing.
806
-	 *
807
-	 * @since 15.0.0
808
-	 *
809
-	 * @param string $info
810
-	 * @param array $value
811
-	 *
812
-	 * @return IIndexDocument
813
-	 */
814
-	final public function setInfoArray(string $info, array $value): IIndexDocument {
815
-		$this->info[$info] = $value;
816
-
817
-		return $this;
818
-	}
819
-
820
-	/**
821
-	 * Get an information about a document. (array)
822
-	 *
823
-	 * @since 15.0.0
824
-	 *
825
-	 * @param string $info
826
-	 * @param array $default
827
-	 *
828
-	 * @return array
829
-	 */
830
-	final public function getInfoArray(string $info, array $default = []): array {
831
-		if (!key_exists($info, $this->info)) {
832
-			return $default;
833
-		}
834
-
835
-		return $this->info[$info];
836
-	}
837
-
838
-	/**
839
-	 * Set some information about the original document that will be available
840
-	 * to the front-end when displaying search result. (as int)
841
-	 * Because this information will not be indexed, this method can also be
842
-	 * used to manage some data while filling the IIndexDocument before its
843
-	 * indexing.
844
-	 *
845
-	 * @since 15.0.0
846
-	 *
847
-	 * @param string $info
848
-	 * @param int $value
849
-	 *
850
-	 * @return IIndexDocument
851
-	 */
852
-	final public function setInfoInt(string $info, int $value): IIndexDocument {
853
-		$this->info[$info] = $value;
854
-
855
-		return $this;
856
-	}
857
-
858
-	/**
859
-	 * Get an information about a document. (int)
860
-	 *
861
-	 * @since 15.0.0
862
-	 *
863
-	 * @param string $info
864
-	 * @param int $default
865
-	 *
866
-	 * @return int
867
-	 */
868
-	final public function getInfoInt(string $info, int $default = 0): int {
869
-		if (!key_exists($info, $this->info)) {
870
-			return $default;
871
-		}
872
-
873
-		return $this->info[$info];
874
-	}
875
-
876
-	/**
877
-	 * Set some information about the original document that will be available
878
-	 * to the front-end when displaying search result. (as bool)
879
-	 * Because this information will not be indexed, this method can also be
880
-	 * used to manage some data while filling the IIndexDocument before its
881
-	 * indexing.
882
-	 *
883
-	 * @since 15.0.0
884
-	 *
885
-	 * @param string $info
886
-	 * @param bool $value
887
-	 *
888
-	 * @return IIndexDocument
889
-	 */
890
-	final public function setInfoBool(string $info, bool $value): IIndexDocument {
891
-		$this->info[$info] = $value;
892
-
893
-		return $this;
894
-	}
895
-
896
-	/**
897
-	 * Get an information about a document. (bool)
898
-	 *
899
-	 * @since 15.0.0
900
-	 *
901
-	 * @param string $info
902
-	 * @param bool $default
903
-	 *
904
-	 * @return bool
905
-	 */
906
-	final public function getInfoBool(string $info, bool $default = false): bool {
907
-		if (!key_exists($info, $this->info)) {
908
-			return $default;
909
-		}
910
-
911
-		return $this->info[$info];
912
-	}
913
-
914
-	/**
915
-	 * Get all info.
916
-	 *
917
-	 * @since 15.0.0
918
-	 *
919
-	 * @return array
920
-	 */
921
-	final public function getInfoAll(): array {
922
-		$info = [];
923
-		foreach ($this->info as $k => $v) {
924
-			if (substr($k, 0, 1) === '_') {
925
-				continue;
926
-			}
927
-
928
-			$info[$k] = $v;
929
-		}
930
-
931
-		return $info;
932
-	}
933
-
934
-
935
-	/**
936
-	 * @since 15.0.0
937
-	 *
938
-	 * On some version of PHP, it is better to force destruct the object.
939
-	 * And during the index, the number of generated IIndexDocument can be
940
-	 * _huge_.
941
-	 */
942
-	public function __destruct() {
943
-		unset($this->id);
944
-		unset($this->providerId);
945
-		unset($this->access);
946
-		unset($this->modifiedTime);
947
-		unset($this->title);
948
-		unset($this->content);
949
-		unset($this->hash);
950
-		unset($this->link);
951
-		unset($this->source);
952
-		unset($this->tags);
953
-		unset($this->metaTags);
954
-		unset($this->subTags);
955
-		unset($this->more);
956
-		unset($this->excerpts);
957
-		unset($this->score);
958
-		unset($this->info);
959
-		unset($this->contentEncoded);
960
-	}
961
-
962
-	/**
963
-	 * @since 15.0.0
964
-	 */
965
-	public function jsonSerialize(): array {
966
-		return [
967
-			'id' => $this->getId(),
968
-			'providerId' => $this->getProviderId(),
969
-			'access' => $this->access,
970
-			'modifiedTime' => $this->getModifiedTime(),
971
-			'title' => $this->getTitle(),
972
-			'link' => $this->getLink(),
973
-			'index' => $this->index,
974
-			'source' => $this->getSource(),
975
-			'info' => $this->getInfoAll(),
976
-			'hash' => $this->getHash(),
977
-			'contentSize' => $this->getContentSize(),
978
-			'tags' => $this->getTags(),
979
-			'metatags' => $this->getMetaTags(),
980
-			'subtags' => $this->getSubTags(),
981
-			'more' => $this->getMore(),
982
-			'excerpts' => $this->getExcerpts(),
983
-			'score' => $this->getScore()
984
-		];
985
-	}
56
+    /** @var DocumentAccess */
57
+    protected $access;
58
+
59
+    /** @var IIndex */
60
+    protected $index;
61
+
62
+    /** @var int */
63
+    protected $modifiedTime = 0;
64
+
65
+    /** @var string */
66
+    protected $source = '';
67
+
68
+    /** @var array */
69
+    protected $tags = [];
70
+
71
+    /** @var array */
72
+    protected $metaTags = [];
73
+
74
+    /** @var array */
75
+    protected $subTags = [];
76
+
77
+    /** @var string */
78
+    protected $title = '';
79
+
80
+    /** @var string */
81
+    protected $content = '';
82
+
83
+    /** @var string */
84
+    protected $hash = '';
85
+
86
+    /** @var array */
87
+    protected $parts = [];
88
+
89
+    /** @var string */
90
+    protected $link = '';
91
+
92
+    /** @var array */
93
+    protected $more = [];
94
+
95
+    /** @var array */
96
+    protected $excerpts = [];
97
+
98
+    /** @var string */
99
+    protected $score = '';
100
+
101
+    /** @var array */
102
+    protected $info = [];
103
+
104
+    /** @var int */
105
+    protected $contentEncoded = 0;
106
+
107
+
108
+    /**
109
+     * IIndexDocument constructor.
110
+     *
111
+     * On creation, we assure the uniqueness of the object using the providerId
112
+     * and the Id of the original document.
113
+     *
114
+     * @since 15.0.0
115
+     *
116
+     * @param string $providerId
117
+     * @param string $documentId
118
+     */
119
+    public function __construct(string $providerId, string $documentId) {
120
+        $this->providerId = $providerId;
121
+        $this->id = $documentId;
122
+    }
123
+
124
+
125
+    /**
126
+     * Returns the Id of the original document.
127
+     *
128
+     * @since 15.0.0
129
+     *
130
+     * @return string
131
+     */
132
+    final public function getId(): string {
133
+        return $this->id;
134
+    }
135
+
136
+
137
+    /**
138
+     * Returns the Id of the provider.
139
+     *
140
+     * @since 15.0.0
141
+     *
142
+     * @return string
143
+     */
144
+    final public function getProviderId(): string {
145
+        return $this->providerId;
146
+    }
147
+
148
+
149
+    /**
150
+     * Set the Index related to the IIndexDocument.
151
+     *
152
+     * @see IIndex
153
+     *
154
+     * @since 15.0.0
155
+     *
156
+     * @param IIndex $index
157
+     *
158
+     * @return IIndexDocument
159
+     */
160
+    final public function setIndex(IIndex $index): IIndexDocument {
161
+        $this->index = $index;
162
+
163
+        return $this;
164
+    }
165
+
166
+    /**
167
+     * Get the Index.
168
+     *
169
+     * @since 15.0.0
170
+     *
171
+     * @return IIndex
172
+     */
173
+    final public function getIndex(): IIndex {
174
+        return $this->index;
175
+    }
176
+
177
+    /**
178
+     * return if Index is defined.
179
+     *
180
+     * @since 16.0.0
181
+     *
182
+     * @return bool
183
+     */
184
+    final public function hasIndex(): bool {
185
+        return ($this->index !== null);
186
+    }
187
+
188
+
189
+    /**
190
+     * Set the modified time of the original document.
191
+     *
192
+     * @since 15.0.0
193
+     *
194
+     * @param int $modifiedTime
195
+     *
196
+     * @return IIndexDocument
197
+     */
198
+    final public function setModifiedTime(int $modifiedTime): IIndexDocument {
199
+        $this->modifiedTime = $modifiedTime;
200
+
201
+        return $this;
202
+    }
203
+
204
+    /**
205
+     * Get the modified time of the original document.
206
+     *
207
+     * @since 15.0.0
208
+     *
209
+     * @return int
210
+     */
211
+    final public function getModifiedTime(): int {
212
+        return $this->modifiedTime;
213
+    }
214
+
215
+    /**
216
+     * Check if the original document of the IIndexDocument is older than $time.
217
+     *
218
+     * @since 15.0.0
219
+     *
220
+     * @param int $time
221
+     *
222
+     * @return bool
223
+     */
224
+    final public function isOlderThan(int $time): bool {
225
+        return ($this->modifiedTime < $time);
226
+    }
227
+
228
+
229
+    /**
230
+     * Set the read rights of the original document using a IDocumentAccess.
231
+     *
232
+     * @see IDocumentAccess
233
+     *
234
+     * @since 15.0.0
235
+     *
236
+     * @param IDocumentAccess $access
237
+     *
238
+     * @return $this
239
+     */
240
+    final public function setAccess(IDocumentAccess $access): IIndexDocument {
241
+        $this->access = $access;
242
+
243
+        return $this;
244
+    }
245
+
246
+    /**
247
+     * Get the IDocumentAccess related to the original document.
248
+     *
249
+     * @since 15.0.0
250
+     *
251
+     * @return IDocumentAccess
252
+     */
253
+    final public function getAccess(): IDocumentAccess {
254
+        return $this->access;
255
+    }
256
+
257
+
258
+    /**
259
+     * Add a tag to the list.
260
+     *
261
+     * @since 15.0.0
262
+     *
263
+     * @param string $tag
264
+     *
265
+     * @return IIndexDocument
266
+     */
267
+    final public function addTag(string $tag): IIndexDocument {
268
+        $this->tags[] = $tag;
269
+
270
+        return $this;
271
+    }
272
+
273
+    /**
274
+     * Set the list of tags assigned to the original document.
275
+     *
276
+     * @since 15.0.0
277
+     *
278
+     * @param array $tags
279
+     *
280
+     * @return IIndexDocument
281
+     */
282
+    final public function setTags(array $tags): IIndexDocument {
283
+        $this->tags = $tags;
284
+
285
+        return $this;
286
+    }
287
+
288
+    /**
289
+     * Get the list of tags assigned to the original document.
290
+     *
291
+     * @since 15.0.0
292
+     *
293
+     * @return array
294
+     */
295
+    final public function getTags(): array {
296
+        return $this->tags;
297
+    }
298
+
299
+
300
+    /**
301
+     * Add a meta tag to the list.
302
+     *
303
+     * @since 15.0.0
304
+     *
305
+     * @param string $tag
306
+     *
307
+     * @return IIndexDocument
308
+     */
309
+    final public function addMetaTag(string $tag): IIndexDocument {
310
+        $this->metaTags[] = $tag;
311
+
312
+        return $this;
313
+    }
314
+
315
+    /**
316
+     * Set the list of meta tags assigned to the original document.
317
+     *
318
+     * @since 15.0.0
319
+     *
320
+     * @param array $tags
321
+     *
322
+     * @return IIndexDocument
323
+     */
324
+    final public function setMetaTags(array $tags): IIndexDocument {
325
+        $this->metaTags = $tags;
326
+
327
+        return $this;
328
+    }
329
+
330
+    /**
331
+     * Get the list of meta tags assigned to the original document.
332
+     *
333
+     * @since 15.0.0
334
+     *
335
+     * @return array
336
+     */
337
+    final public function getMetaTags(): array {
338
+        return $this->metaTags;
339
+    }
340
+
341
+
342
+    /**
343
+     * Add a sub tag to the list.
344
+     *
345
+     * @since 15.0.0
346
+     *
347
+     * @param string $sub
348
+     * @param string $tag
349
+     *
350
+     * @return IIndexDocument
351
+     */
352
+    final public function addSubTag(string $sub, string $tag): IIndexDocument {
353
+        if (!array_key_exists($sub, $this->subTags)) {
354
+            $this->subTags[$sub] = [];
355
+        }
356
+
357
+        $this->subTags[$sub][] = $tag;
358
+
359
+        return $this;
360
+    }
361
+
362
+
363
+    /**
364
+     * Set the list of sub tags assigned to the original document.
365
+     *
366
+     * @since 15.0.0
367
+     *
368
+     * @param array $tags
369
+     *
370
+     * @return IIndexDocument
371
+     */
372
+    final public function setSubTags(array $tags): IIndexDocument {
373
+        $this->subTags = $tags;
374
+
375
+        return $this;
376
+    }
377
+
378
+    /**
379
+     * Get the list of sub tags assigned to the original document.
380
+     * If $formatted is true, the result will be formatted in a one
381
+     * dimensional array.
382
+     *
383
+     * @since 15.0.0
384
+     *
385
+     * @param bool $formatted
386
+     *
387
+     * @return array
388
+     */
389
+    final public function getSubTags(bool $formatted = false): array {
390
+        if ($formatted === false) {
391
+            return $this->subTags;
392
+        }
393
+
394
+        $subTags = [];
395
+        $ak = array_keys($this->subTags);
396
+        foreach ($ak as $source) {
397
+            $tags = $this->subTags[$source];
398
+            foreach ($tags as $tag) {
399
+                $subTags[] = $source . '_' . $tag;
400
+            }
401
+        }
402
+
403
+        return $subTags;
404
+    }
405
+
406
+
407
+    /**
408
+     * Set the source of the original document.
409
+     *
410
+     * @since 15.0.0
411
+     *
412
+     * @param string $source
413
+     *
414
+     * @return IIndexDocument
415
+     */
416
+    final public function setSource(string $source): IIndexDocument {
417
+        $this->source = $source;
418
+
419
+        return $this;
420
+    }
421
+
422
+    /**
423
+     * Get the source of the original document.
424
+     *
425
+     * @since 15.0.0
426
+     *
427
+     * @return string
428
+     */
429
+    final public function getSource(): string {
430
+        return $this->source;
431
+    }
432
+
433
+
434
+    /**
435
+     * Set the title of the original document.
436
+     *
437
+     * @since 15.0.0
438
+     *
439
+     * @param string $title
440
+     *
441
+     * @return IIndexDocument
442
+     */
443
+    final public function setTitle(string $title): IIndexDocument {
444
+        $this->title = $title;
445
+
446
+        return $this;
447
+    }
448
+
449
+    /**
450
+     * Get the title of the original document.
451
+     *
452
+     * @since 15.0.0
453
+     *
454
+     * @return string
455
+     */
456
+    final public function getTitle(): string {
457
+        return $this->title;
458
+    }
459
+
460
+
461
+    /**
462
+     * Set the content of the document.
463
+     * $encoded can be NOT_ENCODED or ENCODED_BASE64 if the content is raw or
464
+     * encoded in base64.
465
+     *
466
+     * @since 15.0.0
467
+     *
468
+     * @param string $content
469
+     * @param int $encoded
470
+     *
471
+     * @return IIndexDocument
472
+     */
473
+    final public function setContent(string $content, int $encoded = 0): IIndexDocument {
474
+        $this->content = $content;
475
+        $this->contentEncoded = $encoded;
476
+
477
+        return $this;
478
+    }
479
+
480
+    /**
481
+     * Get the content of the original document.
482
+     *
483
+     * @since 15.0.0
484
+     *
485
+     * @return string
486
+     */
487
+    final public function getContent(): string {
488
+        return $this->content;
489
+    }
490
+
491
+    /**
492
+     * Returns the type of the encoding on the content.
493
+     *
494
+     * @since 15.0.0
495
+     *
496
+     * @return int
497
+     */
498
+    final public function isContentEncoded(): int {
499
+        return $this->contentEncoded;
500
+    }
501
+
502
+    /**
503
+     * Return the size of the content.
504
+     *
505
+     * @since 15.0.0
506
+     *
507
+     * @return int
508
+     */
509
+    final public function getContentSize(): int {
510
+        return strlen($this->getContent());
511
+    }
512
+
513
+
514
+    /**
515
+     * Generate an hash, based on the content of the original document.
516
+     *
517
+     * @since 15.0.0
518
+     *
519
+     * @return IIndexDocument
520
+     */
521
+    final public function initHash(): IIndexDocument {
522
+        if ($this->getContent() === '' || is_null($this->getContent())) {
523
+            return $this;
524
+        }
525
+
526
+        $this->hash = hash("md5", $this->getContent());
527
+
528
+        return $this;
529
+    }
530
+
531
+    /**
532
+     * Set the hash of the original document.
533
+     *
534
+     * @since 15.0.0
535
+     *
536
+     * @param string $hash
537
+     *
538
+     * @return IIndexDocument
539
+     */
540
+    final public function setHash(string $hash): IIndexDocument {
541
+        $this->hash = $hash;
542
+
543
+        return $this;
544
+    }
545
+
546
+    /**
547
+     * Get the hash of the original document.
548
+     *
549
+     * @since 15.0.0
550
+     *
551
+     * @return string
552
+     */
553
+    final public function getHash(): string {
554
+        return $this->hash;
555
+    }
556
+
557
+
558
+    /**
559
+     * Add a part, identified by a string, and its content.
560
+     *
561
+     * It is strongly advised to use alphanumerical chars with no space in the
562
+     * $part string.
563
+     *
564
+     * @since 15.0.0
565
+     *
566
+     * @param string $part
567
+     * @param string $content
568
+     *
569
+     * @return IIndexDocument
570
+     */
571
+    final public function addPart(string $part, string $content): IIndexDocument {
572
+        $this->parts[$part] = $content;
573
+
574
+        return $this;
575
+    }
576
+
577
+    /**
578
+     * Set all parts and their content.
579
+     *
580
+     * @since 15.0.0
581
+     *
582
+     * @param array $parts
583
+     *
584
+     * @return IIndexDocument
585
+     */
586
+    final public function setParts(array $parts): IIndexDocument {
587
+        $this->parts = $parts;
588
+
589
+        return $this;
590
+    }
591
+
592
+    /**
593
+     * Get all parts of the IIndexDocument.
594
+     *
595
+     * @since 15.0.0
596
+     *
597
+     * @return array
598
+     */
599
+    final public function getParts(): array {
600
+        return $this->parts;
601
+    }
602
+
603
+
604
+    /**
605
+     * Add a link, usable by the frontend.
606
+     *
607
+     * @since 15.0.0
608
+     *
609
+     * @param string $link
610
+     *
611
+     * @return IIndexDocument
612
+     */
613
+    final public function setLink(string $link): IIndexDocument {
614
+        $this->link = $link;
615
+
616
+        return $this;
617
+    }
618
+
619
+    /**
620
+     * Get the link.
621
+     *
622
+     * @since 15.0.0
623
+     *
624
+     * @return string
625
+     */
626
+    final public function getLink(): string {
627
+        return $this->link;
628
+    }
629
+
630
+
631
+    /**
632
+     * Set more information that couldn't be set using other method.
633
+     *
634
+     * @since 15.0.0
635
+     *
636
+     * @param array $more
637
+     *
638
+     * @return IIndexDocument
639
+     */
640
+    final public function setMore(array $more): IIndexDocument {
641
+        $this->more = $more;
642
+
643
+        return $this;
644
+    }
645
+
646
+    /**
647
+     * Get more information.
648
+     *
649
+     * @since 15.0.0
650
+     *
651
+     * @return array
652
+     */
653
+    final public function getMore(): array {
654
+        return $this->more;
655
+    }
656
+
657
+
658
+    /**
659
+     * Add some excerpt of the content of the original document, usually based
660
+     * on the search request.
661
+     *
662
+     * @since 16.0.0
663
+     *
664
+     * @param string $source
665
+     * @param string $excerpt
666
+     *
667
+     * @return IIndexDocument
668
+     */
669
+    final public function addExcerpt(string $source, string $excerpt): IIndexDocument {
670
+        $this->excerpts[] =
671
+            [
672
+                'source' => $source,
673
+                'excerpt' => $this->cleanExcerpt($excerpt)
674
+            ];
675
+
676
+        return $this;
677
+    }
678
+
679
+
680
+    /**
681
+     * Set all excerpts of the content of the original document.
682
+     *
683
+     * @since 16.0.0
684
+     *
685
+     * @param array $excerpts
686
+     *
687
+     * @return IIndexDocument
688
+     */
689
+    final public function setExcerpts(array $excerpts): IIndexDocument {
690
+        $new = [];
691
+        foreach ($excerpts as $entry) {
692
+            $new[] = [
693
+                'source' => $entry['source'],
694
+                'excerpt' => $this->cleanExcerpt($entry['excerpt'])
695
+            ];
696
+        }
697
+
698
+        $this->excerpts = $new;
699
+
700
+        return $this;
701
+    }
702
+
703
+    /**
704
+     * Get all excerpts of the content of the original document.
705
+     *
706
+     * @since 15.0.0
707
+     *
708
+     * @return array
709
+     */
710
+    final public function getExcerpts(): array {
711
+        return $this->excerpts;
712
+    }
713
+
714
+    /**
715
+     * Clean excerpt.
716
+     *
717
+     * @since 16.0.0
718
+     *
719
+     * @param string $excerpt
720
+     * @return string
721
+     */
722
+    private function cleanExcerpt(string $excerpt): string {
723
+        $excerpt = str_replace("\\n", ' ', $excerpt);
724
+        $excerpt = str_replace("\\r", ' ', $excerpt);
725
+        $excerpt = str_replace("\\t", ' ', $excerpt);
726
+        $excerpt = str_replace("\n", ' ', $excerpt);
727
+        $excerpt = str_replace("\r", ' ', $excerpt);
728
+        $excerpt = str_replace("\t", ' ', $excerpt);
729
+
730
+        return $excerpt;
731
+    }
732
+
733
+
734
+    /**
735
+     * Set the score to the result assigned to this document during a search
736
+     * request.
737
+     *
738
+     * @since 15.0.0
739
+     *
740
+     * @param string $score
741
+     *
742
+     * @return IIndexDocument
743
+     */
744
+    final public function setScore(string $score): IIndexDocument {
745
+        $this->score = $score;
746
+
747
+        return $this;
748
+    }
749
+
750
+    /**
751
+     * Get the score.
752
+     *
753
+     * @since 15.0.0
754
+     *
755
+     * @return string
756
+     */
757
+    final public function getScore(): string {
758
+        return $this->score;
759
+    }
760
+
761
+
762
+    /**
763
+     * Set some information about the original document that will be available
764
+     * to the front-end when displaying search result. (as string)
765
+     * Because this information will not be indexed, this method can also be
766
+     * used to manage some data while filling the IIndexDocument before its
767
+     * indexing.
768
+     *
769
+     * @since 15.0.0
770
+     *
771
+     * @param string $info
772
+     * @param string $value
773
+     *
774
+     * @return IIndexDocument
775
+     */
776
+    final public function setInfo(string $info, string $value): IIndexDocument {
777
+        $this->info[$info] = $value;
778
+
779
+        return $this;
780
+    }
781
+
782
+    /**
783
+     * Get an information about a document. (string)
784
+     *
785
+     * @since 15.0.0
786
+     *
787
+     * @param string $info
788
+     * @param string $default
789
+     *
790
+     * @return string
791
+     */
792
+    final public function getInfo(string $info, string $default = ''): string {
793
+        if (!key_exists($info, $this->info)) {
794
+            return $default;
795
+        }
796
+
797
+        return $this->info[$info];
798
+    }
799
+
800
+    /**
801
+     * Set some information about the original document that will be available
802
+     * to the front-end when displaying search result. (as array)
803
+     * Because this information will not be indexed, this method can also be
804
+     * used to manage some data while filling the IIndexDocument before its
805
+     * indexing.
806
+     *
807
+     * @since 15.0.0
808
+     *
809
+     * @param string $info
810
+     * @param array $value
811
+     *
812
+     * @return IIndexDocument
813
+     */
814
+    final public function setInfoArray(string $info, array $value): IIndexDocument {
815
+        $this->info[$info] = $value;
816
+
817
+        return $this;
818
+    }
819
+
820
+    /**
821
+     * Get an information about a document. (array)
822
+     *
823
+     * @since 15.0.0
824
+     *
825
+     * @param string $info
826
+     * @param array $default
827
+     *
828
+     * @return array
829
+     */
830
+    final public function getInfoArray(string $info, array $default = []): array {
831
+        if (!key_exists($info, $this->info)) {
832
+            return $default;
833
+        }
834
+
835
+        return $this->info[$info];
836
+    }
837
+
838
+    /**
839
+     * Set some information about the original document that will be available
840
+     * to the front-end when displaying search result. (as int)
841
+     * Because this information will not be indexed, this method can also be
842
+     * used to manage some data while filling the IIndexDocument before its
843
+     * indexing.
844
+     *
845
+     * @since 15.0.0
846
+     *
847
+     * @param string $info
848
+     * @param int $value
849
+     *
850
+     * @return IIndexDocument
851
+     */
852
+    final public function setInfoInt(string $info, int $value): IIndexDocument {
853
+        $this->info[$info] = $value;
854
+
855
+        return $this;
856
+    }
857
+
858
+    /**
859
+     * Get an information about a document. (int)
860
+     *
861
+     * @since 15.0.0
862
+     *
863
+     * @param string $info
864
+     * @param int $default
865
+     *
866
+     * @return int
867
+     */
868
+    final public function getInfoInt(string $info, int $default = 0): int {
869
+        if (!key_exists($info, $this->info)) {
870
+            return $default;
871
+        }
872
+
873
+        return $this->info[$info];
874
+    }
875
+
876
+    /**
877
+     * Set some information about the original document that will be available
878
+     * to the front-end when displaying search result. (as bool)
879
+     * Because this information will not be indexed, this method can also be
880
+     * used to manage some data while filling the IIndexDocument before its
881
+     * indexing.
882
+     *
883
+     * @since 15.0.0
884
+     *
885
+     * @param string $info
886
+     * @param bool $value
887
+     *
888
+     * @return IIndexDocument
889
+     */
890
+    final public function setInfoBool(string $info, bool $value): IIndexDocument {
891
+        $this->info[$info] = $value;
892
+
893
+        return $this;
894
+    }
895
+
896
+    /**
897
+     * Get an information about a document. (bool)
898
+     *
899
+     * @since 15.0.0
900
+     *
901
+     * @param string $info
902
+     * @param bool $default
903
+     *
904
+     * @return bool
905
+     */
906
+    final public function getInfoBool(string $info, bool $default = false): bool {
907
+        if (!key_exists($info, $this->info)) {
908
+            return $default;
909
+        }
910
+
911
+        return $this->info[$info];
912
+    }
913
+
914
+    /**
915
+     * Get all info.
916
+     *
917
+     * @since 15.0.0
918
+     *
919
+     * @return array
920
+     */
921
+    final public function getInfoAll(): array {
922
+        $info = [];
923
+        foreach ($this->info as $k => $v) {
924
+            if (substr($k, 0, 1) === '_') {
925
+                continue;
926
+            }
927
+
928
+            $info[$k] = $v;
929
+        }
930
+
931
+        return $info;
932
+    }
933
+
934
+
935
+    /**
936
+     * @since 15.0.0
937
+     *
938
+     * On some version of PHP, it is better to force destruct the object.
939
+     * And during the index, the number of generated IIndexDocument can be
940
+     * _huge_.
941
+     */
942
+    public function __destruct() {
943
+        unset($this->id);
944
+        unset($this->providerId);
945
+        unset($this->access);
946
+        unset($this->modifiedTime);
947
+        unset($this->title);
948
+        unset($this->content);
949
+        unset($this->hash);
950
+        unset($this->link);
951
+        unset($this->source);
952
+        unset($this->tags);
953
+        unset($this->metaTags);
954
+        unset($this->subTags);
955
+        unset($this->more);
956
+        unset($this->excerpts);
957
+        unset($this->score);
958
+        unset($this->info);
959
+        unset($this->contentEncoded);
960
+    }
961
+
962
+    /**
963
+     * @since 15.0.0
964
+     */
965
+    public function jsonSerialize(): array {
966
+        return [
967
+            'id' => $this->getId(),
968
+            'providerId' => $this->getProviderId(),
969
+            'access' => $this->access,
970
+            'modifiedTime' => $this->getModifiedTime(),
971
+            'title' => $this->getTitle(),
972
+            'link' => $this->getLink(),
973
+            'index' => $this->index,
974
+            'source' => $this->getSource(),
975
+            'info' => $this->getInfoAll(),
976
+            'hash' => $this->getHash(),
977
+            'contentSize' => $this->getContentSize(),
978
+            'tags' => $this->getTags(),
979
+            'metatags' => $this->getMetaTags(),
980
+            'subtags' => $this->getSubTags(),
981
+            'more' => $this->getMore(),
982
+            'excerpts' => $this->getExcerpts(),
983
+            'score' => $this->getScore()
984
+        ];
985
+    }
986 986
 }
Please login to merge, or discard this patch.
apps/twofactor_backupcodes/lib/Listener/ProviderDisabled.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@
 block discarded – undo
53 53
 		$providers = $this->registry->getProviderStates($event->getUser());
54 54
 
55 55
 		// Loop over all providers. If all are disabled we remove the job
56
-		$state = array_reduce($providers, function (bool $carry, bool $enabled) {
56
+		$state = array_reduce($providers, function(bool $carry, bool $enabled) {
57 57
 			return $carry || $enabled;
58 58
 		}, false);
59 59
 
Please login to merge, or discard this patch.
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -35,33 +35,33 @@
 block discarded – undo
35 35
 
36 36
 class ProviderDisabled implements IEventListener {
37 37
 
38
-	/** @var IRegistry */
39
-	private $registry;
38
+    /** @var IRegistry */
39
+    private $registry;
40 40
 
41
-	/** @var IJobList */
42
-	private $jobList;
41
+    /** @var IJobList */
42
+    private $jobList;
43 43
 
44
-	public function __construct(IRegistry $registry,
45
-								IJobList $jobList) {
46
-		$this->registry = $registry;
47
-		$this->jobList = $jobList;
48
-	}
44
+    public function __construct(IRegistry $registry,
45
+                                IJobList $jobList) {
46
+        $this->registry = $registry;
47
+        $this->jobList = $jobList;
48
+    }
49 49
 
50
-	public function handle(Event $event): void {
51
-		if (!($event instanceof RegistryEvent)) {
52
-			return;
53
-		}
50
+    public function handle(Event $event): void {
51
+        if (!($event instanceof RegistryEvent)) {
52
+            return;
53
+        }
54 54
 
55
-		$providers = $this->registry->getProviderStates($event->getUser());
55
+        $providers = $this->registry->getProviderStates($event->getUser());
56 56
 
57
-		// Loop over all providers. If all are disabled we remove the job
58
-		$state = array_reduce($providers, function (bool $carry, bool $enabled) {
59
-			return $carry || $enabled;
60
-		}, false);
57
+        // Loop over all providers. If all are disabled we remove the job
58
+        $state = array_reduce($providers, function (bool $carry, bool $enabled) {
59
+            return $carry || $enabled;
60
+        }, false);
61 61
 
62
-		if ($state === false) {
63
-			$this->jobList->remove(RememberBackupCodesJob::class, ['uid' => $event->getUser()->getUID()]);
64
-		}
65
-	}
62
+        if ($state === false) {
63
+            $this->jobList->remove(RememberBackupCodesJob::class, ['uid' => $event->getUser()->getUID()]);
64
+        }
65
+    }
66 66
 
67 67
 }
Please login to merge, or discard this patch.
lib/private/Collaboration/Resources/Manager.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 			->setFirstResult($start);
145 145
 
146 146
 		if ($filter !== '') {
147
-			$query->where($query->expr()->iLike('c.name', $query->createNamedParameter('%' . $this->connection->escapeLikeParameter($filter) . '%')));
147
+			$query->where($query->expr()->iLike('c.name', $query->createNamedParameter('%'.$this->connection->escapeLikeParameter($filter).'%')));
148 148
 		}
149 149
 
150 150
 		$result = $query->execute();
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 		while ($row = $result->fetch()) {
155 155
 			$foundResults++;
156 156
 			$access = $row['access'] === null ? null : (bool) $row['access'];
157
-			$collection = new Collection($this, $this->connection, (int)$row['id'], (string)$row['name'], $user, $access);
157
+			$collection = new Collection($this, $this->connection, (int) $row['id'], (string) $row['name'], $user, $access);
158 158
 			if ($collection->canAccess($user)) {
159 159
 				$collections[] = $collection;
160 160
 			}
Please login to merge, or discard this patch.
Indentation   +481 added lines, -481 removed lines patch added patch discarded remove patch
@@ -41,485 +41,485 @@
 block discarded – undo
41 41
 use Psr\Log\LoggerInterface;
42 42
 
43 43
 class Manager implements IManager {
44
-	public const TABLE_COLLECTIONS = 'collres_collections';
45
-	public const TABLE_RESOURCES = 'collres_resources';
46
-	public const TABLE_ACCESS_CACHE = 'collres_accesscache';
47
-
48
-	/** @var IDBConnection */
49
-	protected $connection;
50
-	/** @var IProviderManager */
51
-	protected $providerManager;
52
-	/** @var LoggerInterface */
53
-	protected $logger;
54
-
55
-	/** @var string[] */
56
-	protected $providers = [];
57
-
58
-
59
-	public function __construct(IDBConnection $connection, IProviderManager $providerManager, LoggerInterface $logger) {
60
-		$this->connection = $connection;
61
-		$this->providerManager = $providerManager;
62
-		$this->logger = $logger;
63
-	}
64
-
65
-	/**
66
-	 * @param int $id
67
-	 * @return ICollection
68
-	 * @throws CollectionException when the collection could not be found
69
-	 * @since 16.0.0
70
-	 */
71
-	public function getCollection(int $id): ICollection {
72
-		$query = $this->connection->getQueryBuilder();
73
-		$query->select('*')
74
-			->from(self::TABLE_COLLECTIONS)
75
-			->where($query->expr()->eq('id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
76
-		$result = $query->execute();
77
-		$row = $result->fetch();
78
-		$result->closeCursor();
79
-
80
-		if (!$row) {
81
-			throw new CollectionException('Collection not found');
82
-		}
83
-
84
-		return new Collection($this, $this->connection, (int) $row['id'], (string) $row['name']);
85
-	}
86
-
87
-	/**
88
-	 * @param int $id
89
-	 * @param IUser|null $user
90
-	 * @return ICollection
91
-	 * @throws CollectionException when the collection could not be found
92
-	 * @since 16.0.0
93
-	 */
94
-	public function getCollectionForUser(int $id, ?IUser $user): ICollection {
95
-		$query = $this->connection->getQueryBuilder();
96
-		$userId = $user instanceof IUser ? $user->getUID() : '';
97
-
98
-		$query->select('*')
99
-			->from(self::TABLE_COLLECTIONS, 'c')
100
-			->leftJoin(
101
-				'c', self::TABLE_ACCESS_CACHE, 'a',
102
-				$query->expr()->andX(
103
-					$query->expr()->eq('c.id', 'a.collection_id'),
104
-					$query->expr()->eq('a.user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR))
105
-				)
106
-			)
107
-			->where($query->expr()->eq('c.id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
108
-		$result = $query->execute();
109
-		$row = $result->fetch();
110
-		$result->closeCursor();
111
-
112
-		if (!$row) {
113
-			throw new CollectionException('Collection not found');
114
-		}
115
-
116
-		$access = $row['access'] === null ? null : (bool) $row['access'];
117
-		if ($user instanceof IUser) {
118
-			return new Collection($this, $this->connection, (int) $row['id'], (string) $row['name'], $user, $access);
119
-		}
120
-
121
-		return new Collection($this, $this->connection, (int) $row['id'], (string) $row['name'], $user, $access);
122
-	}
123
-
124
-	/**
125
-	 * @param IUser $user
126
-	 * @param string $filter
127
-	 * @param int $limit
128
-	 * @param int $start
129
-	 * @return ICollection[]
130
-	 * @since 16.0.0
131
-	 */
132
-	public function searchCollections(IUser $user, string $filter, int $limit = 50, int $start = 0): array {
133
-		$query = $this->connection->getQueryBuilder();
134
-		$userId = $user->getUID();
135
-
136
-		$query->select('c.*', 'a.access')
137
-			->from(self::TABLE_COLLECTIONS, 'c')
138
-			->leftJoin(
139
-				'c', self::TABLE_ACCESS_CACHE, 'a',
140
-				$query->expr()->andX(
141
-					$query->expr()->eq('c.id', 'a.collection_id'),
142
-					$query->expr()->eq('a.user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR))
143
-				)
144
-			)
145
-			->where($query->expr()->eq('a.access', $query->createNamedParameter(1, IQueryBuilder::PARAM_INT)))
146
-			->orderBy('c.id')
147
-			->setMaxResults($limit)
148
-			->setFirstResult($start);
149
-
150
-		if ($filter !== '') {
151
-			$query->where($query->expr()->iLike('c.name', $query->createNamedParameter('%' . $this->connection->escapeLikeParameter($filter) . '%')));
152
-		}
153
-
154
-		$result = $query->execute();
155
-		$collections = [];
156
-
157
-		$foundResults = 0;
158
-		while ($row = $result->fetch()) {
159
-			$foundResults++;
160
-			$access = $row['access'] === null ? null : (bool) $row['access'];
161
-			$collection = new Collection($this, $this->connection, (int)$row['id'], (string)$row['name'], $user, $access);
162
-			if ($collection->canAccess($user)) {
163
-				$collections[] = $collection;
164
-			}
165
-		}
166
-		$result->closeCursor();
167
-
168
-		if (empty($collections) && $foundResults === $limit) {
169
-			return $this->searchCollections($user, $filter, $limit, $start + $limit);
170
-		}
171
-
172
-		return $collections;
173
-	}
174
-
175
-	/**
176
-	 * @param string $name
177
-	 * @return ICollection
178
-	 * @since 16.0.0
179
-	 */
180
-	public function newCollection(string $name): ICollection {
181
-		$query = $this->connection->getQueryBuilder();
182
-		$query->insert(self::TABLE_COLLECTIONS)
183
-			->values([
184
-				'name' => $query->createNamedParameter($name),
185
-			]);
186
-		$query->execute();
187
-
188
-		return new Collection($this, $this->connection, $query->getLastInsertId(), $name);
189
-	}
190
-
191
-	/**
192
-	 * @param string $type
193
-	 * @param string $id
194
-	 * @return IResource
195
-	 * @since 16.0.0
196
-	 */
197
-	public function createResource(string $type, string $id): IResource {
198
-		return new Resource($this, $this->connection, $type, $id);
199
-	}
200
-
201
-	/**
202
-	 * @param string $type
203
-	 * @param string $id
204
-	 * @param IUser|null $user
205
-	 * @return IResource
206
-	 * @throws ResourceException
207
-	 * @since 16.0.0
208
-	 */
209
-	public function getResourceForUser(string $type, string $id, ?IUser $user): IResource {
210
-		$query = $this->connection->getQueryBuilder();
211
-		$userId = $user instanceof IUser ? $user->getUID() : '';
212
-
213
-		$query->select('r.*', 'a.access')
214
-			->from(self::TABLE_RESOURCES, 'r')
215
-			->leftJoin(
216
-				'r', self::TABLE_ACCESS_CACHE, 'a',
217
-				$query->expr()->andX(
218
-					$query->expr()->eq('r.resource_id', 'a.resource_id'),
219
-					$query->expr()->eq('r.resource_type', 'a.resource_type'),
220
-					$query->expr()->eq('a.user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR))
221
-				)
222
-			)
223
-			->where($query->expr()->eq('r.resource_type', $query->createNamedParameter($type, IQueryBuilder::PARAM_STR)))
224
-			->andWhere($query->expr()->eq('r.resource_id', $query->createNamedParameter($id, IQueryBuilder::PARAM_STR)));
225
-		$result = $query->execute();
226
-		$row = $result->fetch();
227
-		$result->closeCursor();
228
-
229
-		if (!$row) {
230
-			throw new ResourceException('Resource not found');
231
-		}
232
-
233
-		$access = $row['access'] === null ? null : (bool) $row['access'];
234
-		if ($user instanceof IUser) {
235
-			return new Resource($this, $this->connection, $type, $id, $user, $access);
236
-		}
237
-
238
-		return new Resource($this, $this->connection, $type, $id, null, $access);
239
-	}
240
-
241
-	/**
242
-	 * @param ICollection $collection
243
-	 * @param IUser|null $user
244
-	 * @return IResource[]
245
-	 * @since 16.0.0
246
-	 */
247
-	public function getResourcesByCollectionForUser(ICollection $collection, ?IUser $user): array {
248
-		$query = $this->connection->getQueryBuilder();
249
-		$userId = $user instanceof IUser ? $user->getUID() : '';
250
-
251
-		$query->select('r.*', 'a.access')
252
-			->from(self::TABLE_RESOURCES, 'r')
253
-			->leftJoin(
254
-				'r', self::TABLE_ACCESS_CACHE, 'a',
255
-				$query->expr()->andX(
256
-					$query->expr()->eq('r.resource_id', 'a.resource_id'),
257
-					$query->expr()->eq('r.resource_type', 'a.resource_type'),
258
-					$query->expr()->eq('a.user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR))
259
-				)
260
-			)
261
-			->where($query->expr()->eq('r.collection_id', $query->createNamedParameter($collection->getId(), IQueryBuilder::PARAM_INT)));
262
-
263
-		$resources = [];
264
-		$result = $query->execute();
265
-		while ($row = $result->fetch()) {
266
-			$access = $row['access'] === null ? null : (bool) $row['access'];
267
-			$resources[] = new Resource($this, $this->connection, $row['resource_type'], $row['resource_id'], $user, $access);
268
-		}
269
-		$result->closeCursor();
270
-
271
-		return $resources;
272
-	}
273
-
274
-	/**
275
-	 * Get the rich object data of a resource
276
-	 *
277
-	 * @param IResource $resource
278
-	 * @return array
279
-	 * @since 16.0.0
280
-	 */
281
-	public function getResourceRichObject(IResource $resource): array {
282
-		foreach ($this->providerManager->getResourceProviders() as $provider) {
283
-			if ($provider->getType() === $resource->getType()) {
284
-				try {
285
-					return $provider->getResourceRichObject($resource);
286
-				} catch (ResourceException $e) {
287
-				}
288
-			}
289
-		}
290
-
291
-		return [];
292
-	}
293
-
294
-	/**
295
-	 * Can a user/guest access the collection
296
-	 *
297
-	 * @param IResource $resource
298
-	 * @param IUser|null $user
299
-	 * @return bool
300
-	 * @since 16.0.0
301
-	 */
302
-	public function canAccessResource(IResource $resource, ?IUser $user): bool {
303
-		$access = $this->checkAccessCacheForUserByResource($resource, $user);
304
-		if (\is_bool($access)) {
305
-			return $access;
306
-		}
307
-
308
-		$access = false;
309
-		foreach ($this->providerManager->getResourceProviders() as $provider) {
310
-			if ($provider->getType() === $resource->getType()) {
311
-				try {
312
-					if ($provider->canAccessResource($resource, $user)) {
313
-						$access = true;
314
-						break;
315
-					}
316
-				} catch (ResourceException $e) {
317
-				}
318
-			}
319
-		}
320
-
321
-		$this->cacheAccessForResource($resource, $user, $access);
322
-		return $access;
323
-	}
324
-
325
-	/**
326
-	 * Can a user/guest access the collection
327
-	 *
328
-	 * @param ICollection $collection
329
-	 * @param IUser|null $user
330
-	 * @return bool
331
-	 * @since 16.0.0
332
-	 */
333
-	public function canAccessCollection(ICollection $collection, ?IUser $user): bool {
334
-		$access = $this->checkAccessCacheForUserByCollection($collection, $user);
335
-		if (\is_bool($access)) {
336
-			return $access;
337
-		}
338
-
339
-		$access = null;
340
-		// Access is granted when a user can access all resources
341
-		foreach ($collection->getResources() as $resource) {
342
-			if (!$resource->canAccess($user)) {
343
-				$access = false;
344
-				break;
345
-			}
346
-
347
-			$access = true;
348
-		}
349
-
350
-		$this->cacheAccessForCollection($collection, $user, $access);
351
-		return $access;
352
-	}
353
-
354
-	protected function checkAccessCacheForUserByResource(IResource $resource, ?IUser $user): ?bool {
355
-		$query = $this->connection->getQueryBuilder();
356
-		$userId = $user instanceof IUser ? $user->getUID() : '';
357
-
358
-		$query->select('access')
359
-			->from(self::TABLE_ACCESS_CACHE)
360
-			->where($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId(), IQueryBuilder::PARAM_STR)))
361
-			->andWhere($query->expr()->eq('resource_type', $query->createNamedParameter($resource->getType(), IQueryBuilder::PARAM_STR)))
362
-			->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR)))
363
-			->setMaxResults(1);
364
-
365
-		$hasAccess = null;
366
-		$result = $query->execute();
367
-		if ($row = $result->fetch()) {
368
-			$hasAccess = (bool) $row['access'];
369
-		}
370
-		$result->closeCursor();
371
-
372
-		return $hasAccess;
373
-	}
374
-
375
-	protected function checkAccessCacheForUserByCollection(ICollection $collection, ?IUser $user): ?bool {
376
-		$query = $this->connection->getQueryBuilder();
377
-		$userId = $user instanceof IUser ? $user->getUID() : '';
378
-
379
-		$query->select('access')
380
-			->from(self::TABLE_ACCESS_CACHE)
381
-			->where($query->expr()->eq('collection_id', $query->createNamedParameter($collection->getId(), IQueryBuilder::PARAM_INT)))
382
-			->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR)))
383
-			->setMaxResults(1);
384
-
385
-		$hasAccess = null;
386
-		$result = $query->execute();
387
-		if ($row = $result->fetch()) {
388
-			$hasAccess = (bool) $row['access'];
389
-		}
390
-		$result->closeCursor();
391
-
392
-		return $hasAccess;
393
-	}
394
-
395
-	public function cacheAccessForResource(IResource $resource, ?IUser $user, bool $access): void {
396
-		$query = $this->connection->getQueryBuilder();
397
-		$userId = $user instanceof IUser ? $user->getUID() : '';
398
-
399
-		$query->insert(self::TABLE_ACCESS_CACHE)
400
-			->values([
401
-				'user_id' => $query->createNamedParameter($userId),
402
-				'resource_id' => $query->createNamedParameter($resource->getId()),
403
-				'resource_type' => $query->createNamedParameter($resource->getType()),
404
-				'access' => $query->createNamedParameter($access, IQueryBuilder::PARAM_BOOL),
405
-			]);
406
-		try {
407
-			$query->execute();
408
-		} catch (UniqueConstraintViolationException $e) {
409
-		}
410
-	}
411
-
412
-	public function cacheAccessForCollection(ICollection $collection, ?IUser $user, bool $access): void {
413
-		$query = $this->connection->getQueryBuilder();
414
-		$userId = $user instanceof IUser ? $user->getUID() : '';
415
-
416
-		$query->insert(self::TABLE_ACCESS_CACHE)
417
-			->values([
418
-				'user_id' => $query->createNamedParameter($userId),
419
-				'collection_id' => $query->createNamedParameter($collection->getId()),
420
-				'access' => $query->createNamedParameter($access, IQueryBuilder::PARAM_BOOL),
421
-			]);
422
-		try {
423
-			$query->execute();
424
-		} catch (UniqueConstraintViolationException $e) {
425
-		}
426
-	}
427
-
428
-	public function invalidateAccessCacheForUser(?IUser $user): void {
429
-		$query = $this->connection->getQueryBuilder();
430
-		$userId = $user instanceof IUser ? $user->getUID() : '';
431
-
432
-		$query->delete(self::TABLE_ACCESS_CACHE)
433
-			->where($query->expr()->eq('user_id', $query->createNamedParameter($userId)));
434
-		$query->execute();
435
-	}
436
-
437
-	public function invalidateAccessCacheForResource(IResource $resource): void {
438
-		$query = $this->connection->getQueryBuilder();
439
-
440
-		$query->delete(self::TABLE_ACCESS_CACHE)
441
-			->where($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId())))
442
-			->andWhere($query->expr()->eq('resource_type', $query->createNamedParameter($resource->getType(), IQueryBuilder::PARAM_STR)));
443
-		$query->execute();
444
-
445
-		foreach ($resource->getCollections() as $collection) {
446
-			$this->invalidateAccessCacheForCollection($collection);
447
-		}
448
-	}
449
-
450
-	public function invalidateAccessCacheForAllCollections(): void {
451
-		$query = $this->connection->getQueryBuilder();
452
-
453
-		$query->delete(self::TABLE_ACCESS_CACHE)
454
-			->where($query->expr()->neq('collection_id', $query->createNamedParameter(0)));
455
-		$query->execute();
456
-	}
457
-
458
-	public function invalidateAccessCacheForCollection(ICollection $collection): void {
459
-		$query = $this->connection->getQueryBuilder();
460
-
461
-		$query->delete(self::TABLE_ACCESS_CACHE)
462
-			->where($query->expr()->eq('collection_id', $query->createNamedParameter($collection->getId())));
463
-		$query->execute();
464
-	}
465
-
466
-	public function invalidateAccessCacheForProvider(IProvider $provider): void {
467
-		$query = $this->connection->getQueryBuilder();
468
-
469
-		$query->delete(self::TABLE_ACCESS_CACHE)
470
-			->where($query->expr()->eq('resource_type', $query->createNamedParameter($provider->getType(), IQueryBuilder::PARAM_STR)));
471
-		$query->execute();
472
-	}
473
-
474
-	public function invalidateAccessCacheForResourceByUser(IResource $resource, ?IUser $user): void {
475
-		$query = $this->connection->getQueryBuilder();
476
-		$userId = $user instanceof IUser ? $user->getUID() : '';
477
-
478
-		$query->delete(self::TABLE_ACCESS_CACHE)
479
-			->where($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId())))
480
-			->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId)));
481
-		$query->execute();
482
-
483
-		foreach ($resource->getCollections() as $collection) {
484
-			$this->invalidateAccessCacheForCollectionByUser($collection, $user);
485
-		}
486
-	}
487
-
488
-	protected function invalidateAccessCacheForCollectionByUser(ICollection $collection, ?IUser $user): void {
489
-		$query = $this->connection->getQueryBuilder();
490
-		$userId = $user instanceof IUser ? $user->getUID() : '';
491
-
492
-		$query->delete(self::TABLE_ACCESS_CACHE)
493
-			->where($query->expr()->eq('collection_id', $query->createNamedParameter($collection->getId())))
494
-			->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId)));
495
-		$query->execute();
496
-	}
497
-
498
-	public function invalidateAccessCacheForProviderByUser(IProvider $provider, ?IUser $user): void {
499
-		$query = $this->connection->getQueryBuilder();
500
-		$userId = $user instanceof IUser ? $user->getUID() : '';
501
-
502
-		$query->delete(self::TABLE_ACCESS_CACHE)
503
-			->where($query->expr()->eq('resource_type', $query->createNamedParameter($provider->getType(), IQueryBuilder::PARAM_STR)))
504
-			->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId)));
505
-		$query->execute();
506
-	}
507
-
508
-	/**
509
-	 * @param string $provider
510
-	 */
511
-	public function registerResourceProvider(string $provider): void {
512
-		$this->logger->debug('\OC\Collaboration\Resources\Manager::registerResourceProvider is deprecated', ['provider' => $provider]);
513
-		$this->providerManager->registerResourceProvider($provider);
514
-	}
515
-
516
-	/**
517
-	 * Get the resource type of the provider
518
-	 *
519
-	 * @return string
520
-	 * @since 16.0.0
521
-	 */
522
-	public function getType(): string {
523
-		return '';
524
-	}
44
+    public const TABLE_COLLECTIONS = 'collres_collections';
45
+    public const TABLE_RESOURCES = 'collres_resources';
46
+    public const TABLE_ACCESS_CACHE = 'collres_accesscache';
47
+
48
+    /** @var IDBConnection */
49
+    protected $connection;
50
+    /** @var IProviderManager */
51
+    protected $providerManager;
52
+    /** @var LoggerInterface */
53
+    protected $logger;
54
+
55
+    /** @var string[] */
56
+    protected $providers = [];
57
+
58
+
59
+    public function __construct(IDBConnection $connection, IProviderManager $providerManager, LoggerInterface $logger) {
60
+        $this->connection = $connection;
61
+        $this->providerManager = $providerManager;
62
+        $this->logger = $logger;
63
+    }
64
+
65
+    /**
66
+     * @param int $id
67
+     * @return ICollection
68
+     * @throws CollectionException when the collection could not be found
69
+     * @since 16.0.0
70
+     */
71
+    public function getCollection(int $id): ICollection {
72
+        $query = $this->connection->getQueryBuilder();
73
+        $query->select('*')
74
+            ->from(self::TABLE_COLLECTIONS)
75
+            ->where($query->expr()->eq('id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
76
+        $result = $query->execute();
77
+        $row = $result->fetch();
78
+        $result->closeCursor();
79
+
80
+        if (!$row) {
81
+            throw new CollectionException('Collection not found');
82
+        }
83
+
84
+        return new Collection($this, $this->connection, (int) $row['id'], (string) $row['name']);
85
+    }
86
+
87
+    /**
88
+     * @param int $id
89
+     * @param IUser|null $user
90
+     * @return ICollection
91
+     * @throws CollectionException when the collection could not be found
92
+     * @since 16.0.0
93
+     */
94
+    public function getCollectionForUser(int $id, ?IUser $user): ICollection {
95
+        $query = $this->connection->getQueryBuilder();
96
+        $userId = $user instanceof IUser ? $user->getUID() : '';
97
+
98
+        $query->select('*')
99
+            ->from(self::TABLE_COLLECTIONS, 'c')
100
+            ->leftJoin(
101
+                'c', self::TABLE_ACCESS_CACHE, 'a',
102
+                $query->expr()->andX(
103
+                    $query->expr()->eq('c.id', 'a.collection_id'),
104
+                    $query->expr()->eq('a.user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR))
105
+                )
106
+            )
107
+            ->where($query->expr()->eq('c.id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
108
+        $result = $query->execute();
109
+        $row = $result->fetch();
110
+        $result->closeCursor();
111
+
112
+        if (!$row) {
113
+            throw new CollectionException('Collection not found');
114
+        }
115
+
116
+        $access = $row['access'] === null ? null : (bool) $row['access'];
117
+        if ($user instanceof IUser) {
118
+            return new Collection($this, $this->connection, (int) $row['id'], (string) $row['name'], $user, $access);
119
+        }
120
+
121
+        return new Collection($this, $this->connection, (int) $row['id'], (string) $row['name'], $user, $access);
122
+    }
123
+
124
+    /**
125
+     * @param IUser $user
126
+     * @param string $filter
127
+     * @param int $limit
128
+     * @param int $start
129
+     * @return ICollection[]
130
+     * @since 16.0.0
131
+     */
132
+    public function searchCollections(IUser $user, string $filter, int $limit = 50, int $start = 0): array {
133
+        $query = $this->connection->getQueryBuilder();
134
+        $userId = $user->getUID();
135
+
136
+        $query->select('c.*', 'a.access')
137
+            ->from(self::TABLE_COLLECTIONS, 'c')
138
+            ->leftJoin(
139
+                'c', self::TABLE_ACCESS_CACHE, 'a',
140
+                $query->expr()->andX(
141
+                    $query->expr()->eq('c.id', 'a.collection_id'),
142
+                    $query->expr()->eq('a.user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR))
143
+                )
144
+            )
145
+            ->where($query->expr()->eq('a.access', $query->createNamedParameter(1, IQueryBuilder::PARAM_INT)))
146
+            ->orderBy('c.id')
147
+            ->setMaxResults($limit)
148
+            ->setFirstResult($start);
149
+
150
+        if ($filter !== '') {
151
+            $query->where($query->expr()->iLike('c.name', $query->createNamedParameter('%' . $this->connection->escapeLikeParameter($filter) . '%')));
152
+        }
153
+
154
+        $result = $query->execute();
155
+        $collections = [];
156
+
157
+        $foundResults = 0;
158
+        while ($row = $result->fetch()) {
159
+            $foundResults++;
160
+            $access = $row['access'] === null ? null : (bool) $row['access'];
161
+            $collection = new Collection($this, $this->connection, (int)$row['id'], (string)$row['name'], $user, $access);
162
+            if ($collection->canAccess($user)) {
163
+                $collections[] = $collection;
164
+            }
165
+        }
166
+        $result->closeCursor();
167
+
168
+        if (empty($collections) && $foundResults === $limit) {
169
+            return $this->searchCollections($user, $filter, $limit, $start + $limit);
170
+        }
171
+
172
+        return $collections;
173
+    }
174
+
175
+    /**
176
+     * @param string $name
177
+     * @return ICollection
178
+     * @since 16.0.0
179
+     */
180
+    public function newCollection(string $name): ICollection {
181
+        $query = $this->connection->getQueryBuilder();
182
+        $query->insert(self::TABLE_COLLECTIONS)
183
+            ->values([
184
+                'name' => $query->createNamedParameter($name),
185
+            ]);
186
+        $query->execute();
187
+
188
+        return new Collection($this, $this->connection, $query->getLastInsertId(), $name);
189
+    }
190
+
191
+    /**
192
+     * @param string $type
193
+     * @param string $id
194
+     * @return IResource
195
+     * @since 16.0.0
196
+     */
197
+    public function createResource(string $type, string $id): IResource {
198
+        return new Resource($this, $this->connection, $type, $id);
199
+    }
200
+
201
+    /**
202
+     * @param string $type
203
+     * @param string $id
204
+     * @param IUser|null $user
205
+     * @return IResource
206
+     * @throws ResourceException
207
+     * @since 16.0.0
208
+     */
209
+    public function getResourceForUser(string $type, string $id, ?IUser $user): IResource {
210
+        $query = $this->connection->getQueryBuilder();
211
+        $userId = $user instanceof IUser ? $user->getUID() : '';
212
+
213
+        $query->select('r.*', 'a.access')
214
+            ->from(self::TABLE_RESOURCES, 'r')
215
+            ->leftJoin(
216
+                'r', self::TABLE_ACCESS_CACHE, 'a',
217
+                $query->expr()->andX(
218
+                    $query->expr()->eq('r.resource_id', 'a.resource_id'),
219
+                    $query->expr()->eq('r.resource_type', 'a.resource_type'),
220
+                    $query->expr()->eq('a.user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR))
221
+                )
222
+            )
223
+            ->where($query->expr()->eq('r.resource_type', $query->createNamedParameter($type, IQueryBuilder::PARAM_STR)))
224
+            ->andWhere($query->expr()->eq('r.resource_id', $query->createNamedParameter($id, IQueryBuilder::PARAM_STR)));
225
+        $result = $query->execute();
226
+        $row = $result->fetch();
227
+        $result->closeCursor();
228
+
229
+        if (!$row) {
230
+            throw new ResourceException('Resource not found');
231
+        }
232
+
233
+        $access = $row['access'] === null ? null : (bool) $row['access'];
234
+        if ($user instanceof IUser) {
235
+            return new Resource($this, $this->connection, $type, $id, $user, $access);
236
+        }
237
+
238
+        return new Resource($this, $this->connection, $type, $id, null, $access);
239
+    }
240
+
241
+    /**
242
+     * @param ICollection $collection
243
+     * @param IUser|null $user
244
+     * @return IResource[]
245
+     * @since 16.0.0
246
+     */
247
+    public function getResourcesByCollectionForUser(ICollection $collection, ?IUser $user): array {
248
+        $query = $this->connection->getQueryBuilder();
249
+        $userId = $user instanceof IUser ? $user->getUID() : '';
250
+
251
+        $query->select('r.*', 'a.access')
252
+            ->from(self::TABLE_RESOURCES, 'r')
253
+            ->leftJoin(
254
+                'r', self::TABLE_ACCESS_CACHE, 'a',
255
+                $query->expr()->andX(
256
+                    $query->expr()->eq('r.resource_id', 'a.resource_id'),
257
+                    $query->expr()->eq('r.resource_type', 'a.resource_type'),
258
+                    $query->expr()->eq('a.user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR))
259
+                )
260
+            )
261
+            ->where($query->expr()->eq('r.collection_id', $query->createNamedParameter($collection->getId(), IQueryBuilder::PARAM_INT)));
262
+
263
+        $resources = [];
264
+        $result = $query->execute();
265
+        while ($row = $result->fetch()) {
266
+            $access = $row['access'] === null ? null : (bool) $row['access'];
267
+            $resources[] = new Resource($this, $this->connection, $row['resource_type'], $row['resource_id'], $user, $access);
268
+        }
269
+        $result->closeCursor();
270
+
271
+        return $resources;
272
+    }
273
+
274
+    /**
275
+     * Get the rich object data of a resource
276
+     *
277
+     * @param IResource $resource
278
+     * @return array
279
+     * @since 16.0.0
280
+     */
281
+    public function getResourceRichObject(IResource $resource): array {
282
+        foreach ($this->providerManager->getResourceProviders() as $provider) {
283
+            if ($provider->getType() === $resource->getType()) {
284
+                try {
285
+                    return $provider->getResourceRichObject($resource);
286
+                } catch (ResourceException $e) {
287
+                }
288
+            }
289
+        }
290
+
291
+        return [];
292
+    }
293
+
294
+    /**
295
+     * Can a user/guest access the collection
296
+     *
297
+     * @param IResource $resource
298
+     * @param IUser|null $user
299
+     * @return bool
300
+     * @since 16.0.0
301
+     */
302
+    public function canAccessResource(IResource $resource, ?IUser $user): bool {
303
+        $access = $this->checkAccessCacheForUserByResource($resource, $user);
304
+        if (\is_bool($access)) {
305
+            return $access;
306
+        }
307
+
308
+        $access = false;
309
+        foreach ($this->providerManager->getResourceProviders() as $provider) {
310
+            if ($provider->getType() === $resource->getType()) {
311
+                try {
312
+                    if ($provider->canAccessResource($resource, $user)) {
313
+                        $access = true;
314
+                        break;
315
+                    }
316
+                } catch (ResourceException $e) {
317
+                }
318
+            }
319
+        }
320
+
321
+        $this->cacheAccessForResource($resource, $user, $access);
322
+        return $access;
323
+    }
324
+
325
+    /**
326
+     * Can a user/guest access the collection
327
+     *
328
+     * @param ICollection $collection
329
+     * @param IUser|null $user
330
+     * @return bool
331
+     * @since 16.0.0
332
+     */
333
+    public function canAccessCollection(ICollection $collection, ?IUser $user): bool {
334
+        $access = $this->checkAccessCacheForUserByCollection($collection, $user);
335
+        if (\is_bool($access)) {
336
+            return $access;
337
+        }
338
+
339
+        $access = null;
340
+        // Access is granted when a user can access all resources
341
+        foreach ($collection->getResources() as $resource) {
342
+            if (!$resource->canAccess($user)) {
343
+                $access = false;
344
+                break;
345
+            }
346
+
347
+            $access = true;
348
+        }
349
+
350
+        $this->cacheAccessForCollection($collection, $user, $access);
351
+        return $access;
352
+    }
353
+
354
+    protected function checkAccessCacheForUserByResource(IResource $resource, ?IUser $user): ?bool {
355
+        $query = $this->connection->getQueryBuilder();
356
+        $userId = $user instanceof IUser ? $user->getUID() : '';
357
+
358
+        $query->select('access')
359
+            ->from(self::TABLE_ACCESS_CACHE)
360
+            ->where($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId(), IQueryBuilder::PARAM_STR)))
361
+            ->andWhere($query->expr()->eq('resource_type', $query->createNamedParameter($resource->getType(), IQueryBuilder::PARAM_STR)))
362
+            ->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR)))
363
+            ->setMaxResults(1);
364
+
365
+        $hasAccess = null;
366
+        $result = $query->execute();
367
+        if ($row = $result->fetch()) {
368
+            $hasAccess = (bool) $row['access'];
369
+        }
370
+        $result->closeCursor();
371
+
372
+        return $hasAccess;
373
+    }
374
+
375
+    protected function checkAccessCacheForUserByCollection(ICollection $collection, ?IUser $user): ?bool {
376
+        $query = $this->connection->getQueryBuilder();
377
+        $userId = $user instanceof IUser ? $user->getUID() : '';
378
+
379
+        $query->select('access')
380
+            ->from(self::TABLE_ACCESS_CACHE)
381
+            ->where($query->expr()->eq('collection_id', $query->createNamedParameter($collection->getId(), IQueryBuilder::PARAM_INT)))
382
+            ->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId, IQueryBuilder::PARAM_STR)))
383
+            ->setMaxResults(1);
384
+
385
+        $hasAccess = null;
386
+        $result = $query->execute();
387
+        if ($row = $result->fetch()) {
388
+            $hasAccess = (bool) $row['access'];
389
+        }
390
+        $result->closeCursor();
391
+
392
+        return $hasAccess;
393
+    }
394
+
395
+    public function cacheAccessForResource(IResource $resource, ?IUser $user, bool $access): void {
396
+        $query = $this->connection->getQueryBuilder();
397
+        $userId = $user instanceof IUser ? $user->getUID() : '';
398
+
399
+        $query->insert(self::TABLE_ACCESS_CACHE)
400
+            ->values([
401
+                'user_id' => $query->createNamedParameter($userId),
402
+                'resource_id' => $query->createNamedParameter($resource->getId()),
403
+                'resource_type' => $query->createNamedParameter($resource->getType()),
404
+                'access' => $query->createNamedParameter($access, IQueryBuilder::PARAM_BOOL),
405
+            ]);
406
+        try {
407
+            $query->execute();
408
+        } catch (UniqueConstraintViolationException $e) {
409
+        }
410
+    }
411
+
412
+    public function cacheAccessForCollection(ICollection $collection, ?IUser $user, bool $access): void {
413
+        $query = $this->connection->getQueryBuilder();
414
+        $userId = $user instanceof IUser ? $user->getUID() : '';
415
+
416
+        $query->insert(self::TABLE_ACCESS_CACHE)
417
+            ->values([
418
+                'user_id' => $query->createNamedParameter($userId),
419
+                'collection_id' => $query->createNamedParameter($collection->getId()),
420
+                'access' => $query->createNamedParameter($access, IQueryBuilder::PARAM_BOOL),
421
+            ]);
422
+        try {
423
+            $query->execute();
424
+        } catch (UniqueConstraintViolationException $e) {
425
+        }
426
+    }
427
+
428
+    public function invalidateAccessCacheForUser(?IUser $user): void {
429
+        $query = $this->connection->getQueryBuilder();
430
+        $userId = $user instanceof IUser ? $user->getUID() : '';
431
+
432
+        $query->delete(self::TABLE_ACCESS_CACHE)
433
+            ->where($query->expr()->eq('user_id', $query->createNamedParameter($userId)));
434
+        $query->execute();
435
+    }
436
+
437
+    public function invalidateAccessCacheForResource(IResource $resource): void {
438
+        $query = $this->connection->getQueryBuilder();
439
+
440
+        $query->delete(self::TABLE_ACCESS_CACHE)
441
+            ->where($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId())))
442
+            ->andWhere($query->expr()->eq('resource_type', $query->createNamedParameter($resource->getType(), IQueryBuilder::PARAM_STR)));
443
+        $query->execute();
444
+
445
+        foreach ($resource->getCollections() as $collection) {
446
+            $this->invalidateAccessCacheForCollection($collection);
447
+        }
448
+    }
449
+
450
+    public function invalidateAccessCacheForAllCollections(): void {
451
+        $query = $this->connection->getQueryBuilder();
452
+
453
+        $query->delete(self::TABLE_ACCESS_CACHE)
454
+            ->where($query->expr()->neq('collection_id', $query->createNamedParameter(0)));
455
+        $query->execute();
456
+    }
457
+
458
+    public function invalidateAccessCacheForCollection(ICollection $collection): void {
459
+        $query = $this->connection->getQueryBuilder();
460
+
461
+        $query->delete(self::TABLE_ACCESS_CACHE)
462
+            ->where($query->expr()->eq('collection_id', $query->createNamedParameter($collection->getId())));
463
+        $query->execute();
464
+    }
465
+
466
+    public function invalidateAccessCacheForProvider(IProvider $provider): void {
467
+        $query = $this->connection->getQueryBuilder();
468
+
469
+        $query->delete(self::TABLE_ACCESS_CACHE)
470
+            ->where($query->expr()->eq('resource_type', $query->createNamedParameter($provider->getType(), IQueryBuilder::PARAM_STR)));
471
+        $query->execute();
472
+    }
473
+
474
+    public function invalidateAccessCacheForResourceByUser(IResource $resource, ?IUser $user): void {
475
+        $query = $this->connection->getQueryBuilder();
476
+        $userId = $user instanceof IUser ? $user->getUID() : '';
477
+
478
+        $query->delete(self::TABLE_ACCESS_CACHE)
479
+            ->where($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId())))
480
+            ->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId)));
481
+        $query->execute();
482
+
483
+        foreach ($resource->getCollections() as $collection) {
484
+            $this->invalidateAccessCacheForCollectionByUser($collection, $user);
485
+        }
486
+    }
487
+
488
+    protected function invalidateAccessCacheForCollectionByUser(ICollection $collection, ?IUser $user): void {
489
+        $query = $this->connection->getQueryBuilder();
490
+        $userId = $user instanceof IUser ? $user->getUID() : '';
491
+
492
+        $query->delete(self::TABLE_ACCESS_CACHE)
493
+            ->where($query->expr()->eq('collection_id', $query->createNamedParameter($collection->getId())))
494
+            ->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId)));
495
+        $query->execute();
496
+    }
497
+
498
+    public function invalidateAccessCacheForProviderByUser(IProvider $provider, ?IUser $user): void {
499
+        $query = $this->connection->getQueryBuilder();
500
+        $userId = $user instanceof IUser ? $user->getUID() : '';
501
+
502
+        $query->delete(self::TABLE_ACCESS_CACHE)
503
+            ->where($query->expr()->eq('resource_type', $query->createNamedParameter($provider->getType(), IQueryBuilder::PARAM_STR)))
504
+            ->andWhere($query->expr()->eq('user_id', $query->createNamedParameter($userId)));
505
+        $query->execute();
506
+    }
507
+
508
+    /**
509
+     * @param string $provider
510
+     */
511
+    public function registerResourceProvider(string $provider): void {
512
+        $this->logger->debug('\OC\Collaboration\Resources\Manager::registerResourceProvider is deprecated', ['provider' => $provider]);
513
+        $this->providerManager->registerResourceProvider($provider);
514
+    }
515
+
516
+    /**
517
+     * Get the resource type of the provider
518
+     *
519
+     * @return string
520
+     * @since 16.0.0
521
+     */
522
+    public function getType(): string {
523
+        return '';
524
+    }
525 525
 }
Please login to merge, or discard this patch.
apps/oauth2/lib/Db/AccessToken.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -34,20 +34,20 @@
 block discarded – undo
34 34
  * @method void setHashedCode(string $token)
35 35
  */
36 36
 class AccessToken extends Entity {
37
-	/** @var int */
38
-	protected $tokenId;
39
-	/** @var int */
40
-	protected $clientId;
41
-	/** @var string */
42
-	protected $hashedCode;
43
-	/** @var string */
44
-	protected $encryptedToken;
37
+    /** @var int */
38
+    protected $tokenId;
39
+    /** @var int */
40
+    protected $clientId;
41
+    /** @var string */
42
+    protected $hashedCode;
43
+    /** @var string */
44
+    protected $encryptedToken;
45 45
 
46
-	public function __construct() {
47
-		$this->addType('id', 'int');
48
-		$this->addType('tokenId', 'int');
49
-		$this->addType('clientId', 'int');
50
-		$this->addType('hashedCode', 'string');
51
-		$this->addType('encryptedToken', 'string');
52
-	}
46
+    public function __construct() {
47
+        $this->addType('id', 'int');
48
+        $this->addType('tokenId', 'int');
49
+        $this->addType('clientId', 'int');
50
+        $this->addType('hashedCode', 'string');
51
+        $this->addType('encryptedToken', 'string');
52
+    }
53 53
 }
Please login to merge, or discard this patch.
lib/private/Authentication/Exceptions/WipeTokenException.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -26,16 +26,16 @@
 block discarded – undo
26 26
 use OC\Authentication\Token\IToken;
27 27
 
28 28
 class WipeTokenException extends InvalidTokenException {
29
-	/** @var IToken */
30
-	private $token;
29
+    /** @var IToken */
30
+    private $token;
31 31
 
32
-	public function __construct(IToken $token) {
33
-		parent::__construct();
32
+    public function __construct(IToken $token) {
33
+        parent::__construct();
34 34
 
35
-		$this->token = $token;
36
-	}
35
+        $this->token = $token;
36
+    }
37 37
 
38
-	public function getToken(): IToken {
39
-		return $this->token;
40
-	}
38
+    public function getToken(): IToken {
39
+        return $this->token;
40
+    }
41 41
 }
Please login to merge, or discard this patch.
apps/dav/lib/Migration/RegenerateBirthdayCalendars.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -30,43 +30,43 @@
 block discarded – undo
30 30
 
31 31
 class RegenerateBirthdayCalendars implements IRepairStep {
32 32
 
33
-	/** @var IJobList */
34
-	private $jobList;
33
+    /** @var IJobList */
34
+    private $jobList;
35 35
 
36
-	/** @var IConfig */
37
-	private $config;
36
+    /** @var IConfig */
37
+    private $config;
38 38
 
39
-	/**
40
-	 * @param IJobList $jobList
41
-	 * @param IConfig $config
42
-	 */
43
-	public function __construct(IJobList $jobList,
44
-								IConfig $config) {
45
-		$this->jobList = $jobList;
46
-		$this->config = $config;
47
-	}
39
+    /**
40
+     * @param IJobList $jobList
41
+     * @param IConfig $config
42
+     */
43
+    public function __construct(IJobList $jobList,
44
+                                IConfig $config) {
45
+        $this->jobList = $jobList;
46
+        $this->config = $config;
47
+    }
48 48
 
49
-	/**
50
-	 * @return string
51
-	 */
52
-	public function getName() {
53
-		return 'Regenerating birthday calendars to use new icons and fix old birthday events without year';
54
-	}
49
+    /**
50
+     * @return string
51
+     */
52
+    public function getName() {
53
+        return 'Regenerating birthday calendars to use new icons and fix old birthday events without year';
54
+    }
55 55
 
56
-	/**
57
-	 * @param IOutput $output
58
-	 */
59
-	public function run(IOutput $output) {
60
-		// only run once
61
-		if ($this->config->getAppValue('dav', 'regeneratedBirthdayCalendarsForYearFix') === 'yes') {
62
-			$output->info('Repair step already executed');
63
-			return;
64
-		}
56
+    /**
57
+     * @param IOutput $output
58
+     */
59
+    public function run(IOutput $output) {
60
+        // only run once
61
+        if ($this->config->getAppValue('dav', 'regeneratedBirthdayCalendarsForYearFix') === 'yes') {
62
+            $output->info('Repair step already executed');
63
+            return;
64
+        }
65 65
 
66
-		$output->info('Adding background jobs to regenerate birthday calendar');
67
-		$this->jobList->add(RegisterRegenerateBirthdayCalendars::class);
66
+        $output->info('Adding background jobs to regenerate birthday calendar');
67
+        $this->jobList->add(RegisterRegenerateBirthdayCalendars::class);
68 68
 
69
-		// if all were done, no need to redo the repair during next upgrade
70
-		$this->config->setAppValue('dav', 'regeneratedBirthdayCalendarsForYearFix', 'yes');
71
-	}
69
+        // if all were done, no need to redo the repair during next upgrade
70
+        $this->config->setAppValue('dav', 'regeneratedBirthdayCalendarsForYearFix', 'yes');
71
+    }
72 72
 }
Please login to merge, or discard this patch.