Completed
Push — master ( b93938...e5c086 )
by Morris
15:45
created
lib/private/Files/Cache/Wrapper/CacheJail.php 1 patch
Indentation   +304 added lines, -304 removed lines patch added patch discarded remove patch
@@ -37,308 +37,308 @@
 block discarded – undo
37 37
  * Jail to a subdirectory of the wrapped cache
38 38
  */
39 39
 class CacheJail extends CacheWrapper {
40
-	/**
41
-	 * @var string
42
-	 */
43
-	protected $root;
44
-
45
-	/**
46
-	 * @param \OCP\Files\Cache\ICache $cache
47
-	 * @param string $root
48
-	 */
49
-	public function __construct($cache, $root) {
50
-		parent::__construct($cache);
51
-		$this->root = $root;
52
-	}
53
-
54
-	protected function getRoot() {
55
-		return $this->root;
56
-	}
57
-
58
-	protected function getSourcePath($path) {
59
-		if ($path === '') {
60
-			return $this->getRoot();
61
-		} else {
62
-			return $this->getRoot() . '/' . ltrim($path, '/');
63
-		}
64
-	}
65
-
66
-	/**
67
-	 * @param string $path
68
-	 * @return null|string the jailed path or null if the path is outside the jail
69
-	 */
70
-	protected function getJailedPath($path) {
71
-		if ($this->getRoot() === '') {
72
-			return $path;
73
-		}
74
-		$rootLength = strlen($this->getRoot()) + 1;
75
-		if ($path === $this->getRoot()) {
76
-			return '';
77
-		} else if (substr($path, 0, $rootLength) === $this->getRoot() . '/') {
78
-			return substr($path, $rootLength);
79
-		} else {
80
-			return null;
81
-		}
82
-	}
83
-
84
-	/**
85
-	 * @param ICacheEntry|array $entry
86
-	 * @return array
87
-	 */
88
-	protected function formatCacheEntry($entry) {
89
-		if (isset($entry['path'])) {
90
-			$entry['path'] = $this->getJailedPath($entry['path']);
91
-		}
92
-		return $entry;
93
-	}
94
-
95
-	protected function filterCacheEntry($entry) {
96
-		$rootLength = strlen($this->getRoot()) + 1;
97
-		return ($entry['path'] === $this->getRoot()) or (substr($entry['path'], 0, $rootLength) === $this->getRoot() . '/');
98
-	}
99
-
100
-	/**
101
-	 * get the stored metadata of a file or folder
102
-	 *
103
-	 * @param string /int $file
104
-	 * @return ICacheEntry|false
105
-	 */
106
-	public function get($file) {
107
-		if (is_string($file) or $file == '') {
108
-			$file = $this->getSourcePath($file);
109
-		}
110
-		return parent::get($file);
111
-	}
112
-
113
-	/**
114
-	 * insert meta data for a new file or folder
115
-	 *
116
-	 * @param string $file
117
-	 * @param array $data
118
-	 *
119
-	 * @return int file id
120
-	 * @throws \RuntimeException
121
-	 */
122
-	public function insert($file, array $data) {
123
-		return $this->getCache()->insert($this->getSourcePath($file), $data);
124
-	}
125
-
126
-	/**
127
-	 * update the metadata in the cache
128
-	 *
129
-	 * @param int $id
130
-	 * @param array $data
131
-	 */
132
-	public function update($id, array $data) {
133
-		$this->getCache()->update($id, $data);
134
-	}
135
-
136
-	/**
137
-	 * get the file id for a file
138
-	 *
139
-	 * @param string $file
140
-	 * @return int
141
-	 */
142
-	public function getId($file) {
143
-		return $this->getCache()->getId($this->getSourcePath($file));
144
-	}
145
-
146
-	/**
147
-	 * get the id of the parent folder of a file
148
-	 *
149
-	 * @param string $file
150
-	 * @return int
151
-	 */
152
-	public function getParentId($file) {
153
-		return $this->getCache()->getParentId($this->getSourcePath($file));
154
-	}
155
-
156
-	/**
157
-	 * check if a file is available in the cache
158
-	 *
159
-	 * @param string $file
160
-	 * @return bool
161
-	 */
162
-	public function inCache($file) {
163
-		return $this->getCache()->inCache($this->getSourcePath($file));
164
-	}
165
-
166
-	/**
167
-	 * remove a file or folder from the cache
168
-	 *
169
-	 * @param string $file
170
-	 */
171
-	public function remove($file) {
172
-		$this->getCache()->remove($this->getSourcePath($file));
173
-	}
174
-
175
-	/**
176
-	 * Move a file or folder in the cache
177
-	 *
178
-	 * @param string $source
179
-	 * @param string $target
180
-	 */
181
-	public function move($source, $target) {
182
-		$this->getCache()->move($this->getSourcePath($source), $this->getSourcePath($target));
183
-	}
184
-
185
-	/**
186
-	 * Get the storage id and path needed for a move
187
-	 *
188
-	 * @param string $path
189
-	 * @return array [$storageId, $internalPath]
190
-	 */
191
-	protected function getMoveInfo($path) {
192
-		return [$this->getNumericStorageId(), $this->getSourcePath($path)];
193
-	}
194
-
195
-	/**
196
-	 * remove all entries for files that are stored on the storage from the cache
197
-	 */
198
-	public function clear() {
199
-		$this->getCache()->remove($this->getRoot());
200
-	}
201
-
202
-	/**
203
-	 * @param string $file
204
-	 *
205
-	 * @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE
206
-	 */
207
-	public function getStatus($file) {
208
-		return $this->getCache()->getStatus($this->getSourcePath($file));
209
-	}
210
-
211
-	private function formatSearchResults($results) {
212
-		$results = array_filter($results, array($this, 'filterCacheEntry'));
213
-		$results = array_values($results);
214
-		return array_map(array($this, 'formatCacheEntry'), $results);
215
-	}
216
-
217
-	/**
218
-	 * search for files matching $pattern
219
-	 *
220
-	 * @param string $pattern
221
-	 * @return array an array of file data
222
-	 */
223
-	public function search($pattern) {
224
-		$results = $this->getCache()->search($pattern);
225
-		return $this->formatSearchResults($results);
226
-	}
227
-
228
-	/**
229
-	 * search for files by mimetype
230
-	 *
231
-	 * @param string $mimetype
232
-	 * @return array
233
-	 */
234
-	public function searchByMime($mimetype) {
235
-		$results = $this->getCache()->searchByMime($mimetype);
236
-		return $this->formatSearchResults($results);
237
-	}
238
-
239
-	public function searchQuery(ISearchQuery $query) {
240
-		$simpleQuery = new SearchQuery($query->getSearchOperation(), 0, 0, $query->getOrder(), $query->getUser());
241
-		$results = $this->getCache()->searchQuery($simpleQuery);
242
-		$results = $this->formatSearchResults($results);
243
-
244
-		$limit = $query->getLimit() === 0 ? NULL : $query->getLimit();
245
-		$results = array_slice($results, $query->getOffset(), $limit);
246
-
247
-		return $results;
248
-	}
249
-
250
-	/**
251
-	 * search for files by mimetype
252
-	 *
253
-	 * @param string|int $tag name or tag id
254
-	 * @param string $userId owner of the tags
255
-	 * @return array
256
-	 */
257
-	public function searchByTag($tag, $userId) {
258
-		$results = $this->getCache()->searchByTag($tag, $userId);
259
-		return $this->formatSearchResults($results);
260
-	}
261
-
262
-	/**
263
-	 * update the folder size and the size of all parent folders
264
-	 *
265
-	 * @param string|boolean $path
266
-	 * @param array $data (optional) meta data of the folder
267
-	 */
268
-	public function correctFolderSize($path, $data = null) {
269
-		if ($this->getCache() instanceof Cache) {
270
-			$this->getCache()->correctFolderSize($this->getSourcePath($path), $data);
271
-		}
272
-	}
273
-
274
-	/**
275
-	 * get the size of a folder and set it in the cache
276
-	 *
277
-	 * @param string $path
278
-	 * @param array $entry (optional) meta data of the folder
279
-	 * @return int
280
-	 */
281
-	public function calculateFolderSize($path, $entry = null) {
282
-		if ($this->getCache() instanceof Cache) {
283
-			return $this->getCache()->calculateFolderSize($this->getSourcePath($path), $entry);
284
-		} else {
285
-			return 0;
286
-		}
287
-
288
-	}
289
-
290
-	/**
291
-	 * get all file ids on the files on the storage
292
-	 *
293
-	 * @return int[]
294
-	 */
295
-	public function getAll() {
296
-		// not supported
297
-		return array();
298
-	}
299
-
300
-	/**
301
-	 * find a folder in the cache which has not been fully scanned
302
-	 *
303
-	 * If multiply incomplete folders are in the cache, the one with the highest id will be returned,
304
-	 * use the one with the highest id gives the best result with the background scanner, since that is most
305
-	 * likely the folder where we stopped scanning previously
306
-	 *
307
-	 * @return string|bool the path of the folder or false when no folder matched
308
-	 */
309
-	public function getIncomplete() {
310
-		// not supported
311
-		return false;
312
-	}
313
-
314
-	/**
315
-	 * get the path of a file on this storage by it's id
316
-	 *
317
-	 * @param int $id
318
-	 * @return string|null
319
-	 */
320
-	public function getPathById($id) {
321
-		$path = $this->getCache()->getPathById($id);
322
-		if ($path === null) {
323
-			return null;
324
-		}
325
-
326
-		return $this->getJailedPath($path);
327
-	}
328
-
329
-	/**
330
-	 * Move a file or folder in the cache
331
-	 *
332
-	 * Note that this should make sure the entries are removed from the source cache
333
-	 *
334
-	 * @param \OCP\Files\Cache\ICache $sourceCache
335
-	 * @param string $sourcePath
336
-	 * @param string $targetPath
337
-	 */
338
-	public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) {
339
-		if ($sourceCache === $this) {
340
-			return $this->move($sourcePath, $targetPath);
341
-		}
342
-		return $this->getCache()->moveFromCache($sourceCache, $sourcePath, $this->getSourcePath($targetPath));
343
-	}
40
+    /**
41
+     * @var string
42
+     */
43
+    protected $root;
44
+
45
+    /**
46
+     * @param \OCP\Files\Cache\ICache $cache
47
+     * @param string $root
48
+     */
49
+    public function __construct($cache, $root) {
50
+        parent::__construct($cache);
51
+        $this->root = $root;
52
+    }
53
+
54
+    protected function getRoot() {
55
+        return $this->root;
56
+    }
57
+
58
+    protected function getSourcePath($path) {
59
+        if ($path === '') {
60
+            return $this->getRoot();
61
+        } else {
62
+            return $this->getRoot() . '/' . ltrim($path, '/');
63
+        }
64
+    }
65
+
66
+    /**
67
+     * @param string $path
68
+     * @return null|string the jailed path or null if the path is outside the jail
69
+     */
70
+    protected function getJailedPath($path) {
71
+        if ($this->getRoot() === '') {
72
+            return $path;
73
+        }
74
+        $rootLength = strlen($this->getRoot()) + 1;
75
+        if ($path === $this->getRoot()) {
76
+            return '';
77
+        } else if (substr($path, 0, $rootLength) === $this->getRoot() . '/') {
78
+            return substr($path, $rootLength);
79
+        } else {
80
+            return null;
81
+        }
82
+    }
83
+
84
+    /**
85
+     * @param ICacheEntry|array $entry
86
+     * @return array
87
+     */
88
+    protected function formatCacheEntry($entry) {
89
+        if (isset($entry['path'])) {
90
+            $entry['path'] = $this->getJailedPath($entry['path']);
91
+        }
92
+        return $entry;
93
+    }
94
+
95
+    protected function filterCacheEntry($entry) {
96
+        $rootLength = strlen($this->getRoot()) + 1;
97
+        return ($entry['path'] === $this->getRoot()) or (substr($entry['path'], 0, $rootLength) === $this->getRoot() . '/');
98
+    }
99
+
100
+    /**
101
+     * get the stored metadata of a file or folder
102
+     *
103
+     * @param string /int $file
104
+     * @return ICacheEntry|false
105
+     */
106
+    public function get($file) {
107
+        if (is_string($file) or $file == '') {
108
+            $file = $this->getSourcePath($file);
109
+        }
110
+        return parent::get($file);
111
+    }
112
+
113
+    /**
114
+     * insert meta data for a new file or folder
115
+     *
116
+     * @param string $file
117
+     * @param array $data
118
+     *
119
+     * @return int file id
120
+     * @throws \RuntimeException
121
+     */
122
+    public function insert($file, array $data) {
123
+        return $this->getCache()->insert($this->getSourcePath($file), $data);
124
+    }
125
+
126
+    /**
127
+     * update the metadata in the cache
128
+     *
129
+     * @param int $id
130
+     * @param array $data
131
+     */
132
+    public function update($id, array $data) {
133
+        $this->getCache()->update($id, $data);
134
+    }
135
+
136
+    /**
137
+     * get the file id for a file
138
+     *
139
+     * @param string $file
140
+     * @return int
141
+     */
142
+    public function getId($file) {
143
+        return $this->getCache()->getId($this->getSourcePath($file));
144
+    }
145
+
146
+    /**
147
+     * get the id of the parent folder of a file
148
+     *
149
+     * @param string $file
150
+     * @return int
151
+     */
152
+    public function getParentId($file) {
153
+        return $this->getCache()->getParentId($this->getSourcePath($file));
154
+    }
155
+
156
+    /**
157
+     * check if a file is available in the cache
158
+     *
159
+     * @param string $file
160
+     * @return bool
161
+     */
162
+    public function inCache($file) {
163
+        return $this->getCache()->inCache($this->getSourcePath($file));
164
+    }
165
+
166
+    /**
167
+     * remove a file or folder from the cache
168
+     *
169
+     * @param string $file
170
+     */
171
+    public function remove($file) {
172
+        $this->getCache()->remove($this->getSourcePath($file));
173
+    }
174
+
175
+    /**
176
+     * Move a file or folder in the cache
177
+     *
178
+     * @param string $source
179
+     * @param string $target
180
+     */
181
+    public function move($source, $target) {
182
+        $this->getCache()->move($this->getSourcePath($source), $this->getSourcePath($target));
183
+    }
184
+
185
+    /**
186
+     * Get the storage id and path needed for a move
187
+     *
188
+     * @param string $path
189
+     * @return array [$storageId, $internalPath]
190
+     */
191
+    protected function getMoveInfo($path) {
192
+        return [$this->getNumericStorageId(), $this->getSourcePath($path)];
193
+    }
194
+
195
+    /**
196
+     * remove all entries for files that are stored on the storage from the cache
197
+     */
198
+    public function clear() {
199
+        $this->getCache()->remove($this->getRoot());
200
+    }
201
+
202
+    /**
203
+     * @param string $file
204
+     *
205
+     * @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE
206
+     */
207
+    public function getStatus($file) {
208
+        return $this->getCache()->getStatus($this->getSourcePath($file));
209
+    }
210
+
211
+    private function formatSearchResults($results) {
212
+        $results = array_filter($results, array($this, 'filterCacheEntry'));
213
+        $results = array_values($results);
214
+        return array_map(array($this, 'formatCacheEntry'), $results);
215
+    }
216
+
217
+    /**
218
+     * search for files matching $pattern
219
+     *
220
+     * @param string $pattern
221
+     * @return array an array of file data
222
+     */
223
+    public function search($pattern) {
224
+        $results = $this->getCache()->search($pattern);
225
+        return $this->formatSearchResults($results);
226
+    }
227
+
228
+    /**
229
+     * search for files by mimetype
230
+     *
231
+     * @param string $mimetype
232
+     * @return array
233
+     */
234
+    public function searchByMime($mimetype) {
235
+        $results = $this->getCache()->searchByMime($mimetype);
236
+        return $this->formatSearchResults($results);
237
+    }
238
+
239
+    public function searchQuery(ISearchQuery $query) {
240
+        $simpleQuery = new SearchQuery($query->getSearchOperation(), 0, 0, $query->getOrder(), $query->getUser());
241
+        $results = $this->getCache()->searchQuery($simpleQuery);
242
+        $results = $this->formatSearchResults($results);
243
+
244
+        $limit = $query->getLimit() === 0 ? NULL : $query->getLimit();
245
+        $results = array_slice($results, $query->getOffset(), $limit);
246
+
247
+        return $results;
248
+    }
249
+
250
+    /**
251
+     * search for files by mimetype
252
+     *
253
+     * @param string|int $tag name or tag id
254
+     * @param string $userId owner of the tags
255
+     * @return array
256
+     */
257
+    public function searchByTag($tag, $userId) {
258
+        $results = $this->getCache()->searchByTag($tag, $userId);
259
+        return $this->formatSearchResults($results);
260
+    }
261
+
262
+    /**
263
+     * update the folder size and the size of all parent folders
264
+     *
265
+     * @param string|boolean $path
266
+     * @param array $data (optional) meta data of the folder
267
+     */
268
+    public function correctFolderSize($path, $data = null) {
269
+        if ($this->getCache() instanceof Cache) {
270
+            $this->getCache()->correctFolderSize($this->getSourcePath($path), $data);
271
+        }
272
+    }
273
+
274
+    /**
275
+     * get the size of a folder and set it in the cache
276
+     *
277
+     * @param string $path
278
+     * @param array $entry (optional) meta data of the folder
279
+     * @return int
280
+     */
281
+    public function calculateFolderSize($path, $entry = null) {
282
+        if ($this->getCache() instanceof Cache) {
283
+            return $this->getCache()->calculateFolderSize($this->getSourcePath($path), $entry);
284
+        } else {
285
+            return 0;
286
+        }
287
+
288
+    }
289
+
290
+    /**
291
+     * get all file ids on the files on the storage
292
+     *
293
+     * @return int[]
294
+     */
295
+    public function getAll() {
296
+        // not supported
297
+        return array();
298
+    }
299
+
300
+    /**
301
+     * find a folder in the cache which has not been fully scanned
302
+     *
303
+     * If multiply incomplete folders are in the cache, the one with the highest id will be returned,
304
+     * use the one with the highest id gives the best result with the background scanner, since that is most
305
+     * likely the folder where we stopped scanning previously
306
+     *
307
+     * @return string|bool the path of the folder or false when no folder matched
308
+     */
309
+    public function getIncomplete() {
310
+        // not supported
311
+        return false;
312
+    }
313
+
314
+    /**
315
+     * get the path of a file on this storage by it's id
316
+     *
317
+     * @param int $id
318
+     * @return string|null
319
+     */
320
+    public function getPathById($id) {
321
+        $path = $this->getCache()->getPathById($id);
322
+        if ($path === null) {
323
+            return null;
324
+        }
325
+
326
+        return $this->getJailedPath($path);
327
+    }
328
+
329
+    /**
330
+     * Move a file or folder in the cache
331
+     *
332
+     * Note that this should make sure the entries are removed from the source cache
333
+     *
334
+     * @param \OCP\Files\Cache\ICache $sourceCache
335
+     * @param string $sourcePath
336
+     * @param string $targetPath
337
+     */
338
+    public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) {
339
+        if ($sourceCache === $this) {
340
+            return $this->move($sourcePath, $targetPath);
341
+        }
342
+        return $this->getCache()->moveFromCache($sourceCache, $sourcePath, $this->getSourcePath($targetPath));
343
+    }
344 344
 }
Please login to merge, or discard this patch.
apps/dav/lib/Files/FileSearchBackend.php 2 patches
Indentation   +309 added lines, -309 removed lines patch added patch discarded remove patch
@@ -51,313 +51,313 @@
 block discarded – undo
51 51
 use SearchDAV\Query\Order;
52 52
 
53 53
 class FileSearchBackend implements ISearchBackend {
54
-	/** @var CachingTree */
55
-	private $tree;
56
-
57
-	/** @var IUser */
58
-	private $user;
59
-
60
-	/** @var IRootFolder */
61
-	private $rootFolder;
62
-
63
-	/** @var IManager */
64
-	private $shareManager;
65
-
66
-	/** @var View */
67
-	private $view;
68
-
69
-	/**
70
-	 * FileSearchBackend constructor.
71
-	 *
72
-	 * @param CachingTree $tree
73
-	 * @param IUser $user
74
-	 * @param IRootFolder $rootFolder
75
-	 * @param IManager $shareManager
76
-	 * @param View $view
77
-	 * @internal param IRootFolder $rootFolder
78
-	 */
79
-	public function __construct(CachingTree $tree, IUser $user, IRootFolder $rootFolder, IManager $shareManager, View $view) {
80
-		$this->tree = $tree;
81
-		$this->user = $user;
82
-		$this->rootFolder = $rootFolder;
83
-		$this->shareManager = $shareManager;
84
-		$this->view = $view;
85
-	}
86
-
87
-	/**
88
-	 * Search endpoint will be remote.php/dav
89
-	 *
90
-	 * @return string
91
-	 */
92
-	public function getArbiterPath() {
93
-		return '';
94
-	}
95
-
96
-	public function isValidScope($href, $depth, $path) {
97
-		// only allow scopes inside the dav server
98
-		if (is_null($path)) {
99
-			return false;
100
-		}
101
-
102
-		try {
103
-			$node = $this->tree->getNodeForPath($path);
104
-			return $node instanceof Directory;
105
-		} catch (NotFound $e) {
106
-			return false;
107
-		}
108
-	}
109
-
110
-	public function getPropertyDefinitionsForScope($href, $path) {
111
-		// all valid scopes support the same schema
112
-
113
-		//todo dynamically load all propfind properties that are supported
114
-		return [
115
-			// queryable properties
116
-			new SearchPropertyDefinition('{DAV:}displayname', true, false, true),
117
-			new SearchPropertyDefinition('{DAV:}getcontenttype', true, true, true),
118
-			new SearchPropertyDefinition('{DAV:}getlastmodified', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME),
119
-			new SearchPropertyDefinition(FilesPlugin::SIZE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
120
-			new SearchPropertyDefinition(TagsPlugin::FAVORITE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_BOOLEAN),
121
-			new SearchPropertyDefinition(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, true, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
122
-
123
-			// select only properties
124
-			new SearchPropertyDefinition('{DAV:}resourcetype', false, true, false),
125
-			new SearchPropertyDefinition('{DAV:}getcontentlength', false, true, false),
126
-			new SearchPropertyDefinition(FilesPlugin::CHECKSUMS_PROPERTYNAME, false, true, false),
127
-			new SearchPropertyDefinition(FilesPlugin::PERMISSIONS_PROPERTYNAME, false, true, false),
128
-			new SearchPropertyDefinition(FilesPlugin::GETETAG_PROPERTYNAME, false, true, false),
129
-			new SearchPropertyDefinition(FilesPlugin::OWNER_ID_PROPERTYNAME, false, true, false),
130
-			new SearchPropertyDefinition(FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME, false, true, false),
131
-			new SearchPropertyDefinition(FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME, false, true, false),
132
-			new SearchPropertyDefinition(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_BOOLEAN),
133
-			new SearchPropertyDefinition(FilesPlugin::FILEID_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
134
-		];
135
-	}
136
-
137
-	/**
138
-	 * @param Query $search
139
-	 * @return SearchResult[]
140
-	 */
141
-	public function search(Query $search) {
142
-		if (count($search->from) !== 1) {
143
-			throw new \InvalidArgumentException('Searching more than one folder is not supported');
144
-		}
145
-		$query = $this->transformQuery($search);
146
-		$scope = $search->from[0];
147
-		if ($scope->path === null) {
148
-			throw new \InvalidArgumentException('Using uri\'s as scope is not supported, please use a path relative to the search arbiter instead');
149
-		}
150
-		$node = $this->tree->getNodeForPath($scope->path);
151
-		if (!$node instanceof Directory) {
152
-			throw new \InvalidArgumentException('Search is only supported on directories');
153
-		}
154
-
155
-		$fileInfo = $node->getFileInfo();
156
-		$folder = $this->rootFolder->get($fileInfo->getPath());
157
-		/** @var Folder $folder $results */
158
-		$results = $folder->search($query);
159
-
160
-		/** @var SearchResult[] $nodes */
161
-		$nodes = array_map(function (Node $node) {
162
-			if ($node instanceof Folder) {
163
-				$davNode = new \OCA\DAV\Connector\Sabre\Directory($this->view, $node, $this->tree, $this->shareManager);
164
-			} else {
165
-				$davNode = new \OCA\DAV\Connector\Sabre\File($this->view, $node, $this->shareManager);
166
-			}
167
-			$path = $this->getHrefForNode($node);
168
-			$this->tree->cacheNode($davNode, $path);
169
-			return new SearchResult($davNode, $path);
170
-		}, $results);
171
-
172
-		// Sort again, since the result from multiple storages is appended and not sorted
173
-		usort($nodes, function (SearchResult $a, SearchResult $b) use ($search) {
174
-			return $this->sort($a, $b, $search->orderBy);
175
-		});
176
-
177
-		// If a limit is provided use only return that number of files
178
-		if ($search->limit->maxResults !== 0) {
179
-			$nodes = \array_slice($nodes, 0, $search->limit->maxResults);
180
-		}
181
-
182
-		return $nodes;
183
-	}
184
-
185
-	private function sort(SearchResult $a, SearchResult $b, array $orders) {
186
-		/** @var Order $order */
187
-		foreach ($orders as $order) {
188
-			$v1 = $this->getSearchResultProperty($a, $order->property);
189
-			$v2 = $this->getSearchResultProperty($b, $order->property);
190
-
191
-
192
-			if ($v1 === null && $v2 === null) {
193
-				continue;
194
-			}
195
-			if ($v1 === null) {
196
-				return $order->order === Order::ASC ? 1 : -1;
197
-			}
198
-			if ($v2 === null) {
199
-				return $order->order === Order::ASC ? -1 : 1;
200
-			}
201
-
202
-			$s = $this->compareProperties($v1, $v2, $order);
203
-			if ($s === 0) {
204
-				continue;
205
-			}
206
-
207
-			if ($order->order === Order::DESC) {
208
-				$s = -$s;
209
-			}
210
-			return $s;
211
-		}
212
-
213
-		return 0;
214
-	}
215
-
216
-	private function compareProperties($a, $b, Order $order) {
217
-		switch ($order->property->dataType) {
218
-			case SearchPropertyDefinition::DATATYPE_STRING:
219
-				return strcmp($a, $b);
220
-			case SearchPropertyDefinition::DATATYPE_BOOLEAN:
221
-				if ($a === $b) {
222
-					return 0;
223
-				}
224
-				if ($a === false) {
225
-					return -1;
226
-				}
227
-				return 1;
228
-			default:
229
-				if ($a === $b) {
230
-					return 0;
231
-				}
232
-				if ($a < $b) {
233
-					return -1;
234
-				}
235
-				return 1;
236
-		}
237
-	}
238
-
239
-	private function getSearchResultProperty(SearchResult $result, SearchPropertyDefinition $property) {
240
-		/** @var \OCA\DAV\Connector\Sabre\Node $node */
241
-		$node = $result->node;
242
-
243
-		switch ($property->name) {
244
-			case '{DAV:}displayname':
245
-				return $node->getName();
246
-			case '{DAV:}getlastmodified':
247
-				return $node->getLastModified();
248
-			case FilesPlugin::SIZE_PROPERTYNAME:
249
-				return $node->getSize();
250
-			case FilesPlugin::INTERNAL_FILEID_PROPERTYNAME:
251
-				return $node->getInternalFileId();
252
-			default:
253
-				return null;
254
-		}
255
-	}
256
-
257
-	/**
258
-	 * @param Node $node
259
-	 * @return string
260
-	 */
261
-	private function getHrefForNode(Node $node) {
262
-		$base = '/files/' . $this->user->getUID();
263
-		return $base . $this->view->getRelativePath($node->getPath());
264
-	}
265
-
266
-	/**
267
-	 * @param Query $query
268
-	 * @return ISearchQuery
269
-	 */
270
-	private function transformQuery(Query $query) {
271
-		// TODO offset
272
-		$limit = $query->limit;
273
-		$orders = array_map([$this, 'mapSearchOrder'], $query->orderBy);
274
-		return new SearchQuery($this->transformSearchOperation($query->where), (int)$limit->maxResults, 0, $orders, $this->user);
275
-	}
276
-
277
-	/**
278
-	 * @param Order $order
279
-	 * @return ISearchOrder
280
-	 */
281
-	private function mapSearchOrder(Order $order) {
282
-		return new SearchOrder($order->order === Order::ASC ? ISearchOrder::DIRECTION_ASCENDING : ISearchOrder::DIRECTION_DESCENDING, $this->mapPropertyNameToColumn($order->property));
283
-	}
284
-
285
-	/**
286
-	 * @param Operator $operator
287
-	 * @return ISearchOperator
288
-	 */
289
-	private function transformSearchOperation(Operator $operator) {
290
-		list(, $trimmedType) = explode('}', $operator->type);
291
-		switch ($operator->type) {
292
-			case Operator::OPERATION_AND:
293
-			case Operator::OPERATION_OR:
294
-			case Operator::OPERATION_NOT:
295
-				$arguments = array_map([$this, 'transformSearchOperation'], $operator->arguments);
296
-				return new SearchBinaryOperator($trimmedType, $arguments);
297
-			case Operator::OPERATION_EQUAL:
298
-			case Operator::OPERATION_GREATER_OR_EQUAL_THAN:
299
-			case Operator::OPERATION_GREATER_THAN:
300
-			case Operator::OPERATION_LESS_OR_EQUAL_THAN:
301
-			case Operator::OPERATION_LESS_THAN:
302
-			case Operator::OPERATION_IS_LIKE:
303
-				if (count($operator->arguments) !== 2) {
304
-					throw new \InvalidArgumentException('Invalid number of arguments for ' . $trimmedType . ' operation');
305
-				}
306
-				if (!($operator->arguments[0] instanceof SearchPropertyDefinition)) {
307
-					throw new \InvalidArgumentException('Invalid argument 1 for ' . $trimmedType . ' operation, expected property');
308
-				}
309
-				if (!($operator->arguments[1] instanceof Literal)) {
310
-					throw new \InvalidArgumentException('Invalid argument 2 for ' . $trimmedType . ' operation, expected literal');
311
-				}
312
-				return new SearchComparison($trimmedType, $this->mapPropertyNameToColumn($operator->arguments[0]), $this->castValue($operator->arguments[0], $operator->arguments[1]->value));
313
-			case Operator::OPERATION_IS_COLLECTION:
314
-				return new SearchComparison('eq', 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE);
315
-			default:
316
-				throw new \InvalidArgumentException('Unsupported operation ' . $trimmedType . ' (' . $operator->type . ')');
317
-		}
318
-	}
319
-
320
-	/**
321
-	 * @param SearchPropertyDefinition $property
322
-	 * @return string
323
-	 */
324
-	private function mapPropertyNameToColumn(SearchPropertyDefinition $property) {
325
-		switch ($property->name) {
326
-			case '{DAV:}displayname':
327
-				return 'name';
328
-			case '{DAV:}getcontenttype':
329
-				return 'mimetype';
330
-			case '{DAV:}getlastmodified':
331
-				return 'mtime';
332
-			case FilesPlugin::SIZE_PROPERTYNAME:
333
-				return 'size';
334
-			case TagsPlugin::FAVORITE_PROPERTYNAME:
335
-				return 'favorite';
336
-			case TagsPlugin::TAGS_PROPERTYNAME:
337
-				return 'tagname';
338
-			case FilesPlugin::INTERNAL_FILEID_PROPERTYNAME:
339
-				return 'fileid';
340
-			default:
341
-				throw new \InvalidArgumentException('Unsupported property for search or order: ' . $property->name);
342
-		}
343
-	}
344
-
345
-	private function castValue(SearchPropertyDefinition $property, $value) {
346
-		switch ($property->dataType) {
347
-			case SearchPropertyDefinition::DATATYPE_BOOLEAN:
348
-				return $value === 'yes';
349
-			case SearchPropertyDefinition::DATATYPE_DECIMAL:
350
-			case SearchPropertyDefinition::DATATYPE_INTEGER:
351
-			case SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER:
352
-				return 0 + $value;
353
-			case SearchPropertyDefinition::DATATYPE_DATETIME:
354
-				if (is_numeric($value)) {
355
-					return 0 + $value;
356
-				}
357
-				$date = \DateTime::createFromFormat(\DateTime::ATOM, $value);
358
-				return ($date instanceof \DateTime) ? $date->getTimestamp() : 0;
359
-			default:
360
-				return $value;
361
-		}
362
-	}
54
+    /** @var CachingTree */
55
+    private $tree;
56
+
57
+    /** @var IUser */
58
+    private $user;
59
+
60
+    /** @var IRootFolder */
61
+    private $rootFolder;
62
+
63
+    /** @var IManager */
64
+    private $shareManager;
65
+
66
+    /** @var View */
67
+    private $view;
68
+
69
+    /**
70
+     * FileSearchBackend constructor.
71
+     *
72
+     * @param CachingTree $tree
73
+     * @param IUser $user
74
+     * @param IRootFolder $rootFolder
75
+     * @param IManager $shareManager
76
+     * @param View $view
77
+     * @internal param IRootFolder $rootFolder
78
+     */
79
+    public function __construct(CachingTree $tree, IUser $user, IRootFolder $rootFolder, IManager $shareManager, View $view) {
80
+        $this->tree = $tree;
81
+        $this->user = $user;
82
+        $this->rootFolder = $rootFolder;
83
+        $this->shareManager = $shareManager;
84
+        $this->view = $view;
85
+    }
86
+
87
+    /**
88
+     * Search endpoint will be remote.php/dav
89
+     *
90
+     * @return string
91
+     */
92
+    public function getArbiterPath() {
93
+        return '';
94
+    }
95
+
96
+    public function isValidScope($href, $depth, $path) {
97
+        // only allow scopes inside the dav server
98
+        if (is_null($path)) {
99
+            return false;
100
+        }
101
+
102
+        try {
103
+            $node = $this->tree->getNodeForPath($path);
104
+            return $node instanceof Directory;
105
+        } catch (NotFound $e) {
106
+            return false;
107
+        }
108
+    }
109
+
110
+    public function getPropertyDefinitionsForScope($href, $path) {
111
+        // all valid scopes support the same schema
112
+
113
+        //todo dynamically load all propfind properties that are supported
114
+        return [
115
+            // queryable properties
116
+            new SearchPropertyDefinition('{DAV:}displayname', true, false, true),
117
+            new SearchPropertyDefinition('{DAV:}getcontenttype', true, true, true),
118
+            new SearchPropertyDefinition('{DAV:}getlastmodified', true, true, true, SearchPropertyDefinition::DATATYPE_DATETIME),
119
+            new SearchPropertyDefinition(FilesPlugin::SIZE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
120
+            new SearchPropertyDefinition(TagsPlugin::FAVORITE_PROPERTYNAME, true, true, true, SearchPropertyDefinition::DATATYPE_BOOLEAN),
121
+            new SearchPropertyDefinition(FilesPlugin::INTERNAL_FILEID_PROPERTYNAME, true, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
122
+
123
+            // select only properties
124
+            new SearchPropertyDefinition('{DAV:}resourcetype', false, true, false),
125
+            new SearchPropertyDefinition('{DAV:}getcontentlength', false, true, false),
126
+            new SearchPropertyDefinition(FilesPlugin::CHECKSUMS_PROPERTYNAME, false, true, false),
127
+            new SearchPropertyDefinition(FilesPlugin::PERMISSIONS_PROPERTYNAME, false, true, false),
128
+            new SearchPropertyDefinition(FilesPlugin::GETETAG_PROPERTYNAME, false, true, false),
129
+            new SearchPropertyDefinition(FilesPlugin::OWNER_ID_PROPERTYNAME, false, true, false),
130
+            new SearchPropertyDefinition(FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME, false, true, false),
131
+            new SearchPropertyDefinition(FilesPlugin::DATA_FINGERPRINT_PROPERTYNAME, false, true, false),
132
+            new SearchPropertyDefinition(FilesPlugin::HAS_PREVIEW_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_BOOLEAN),
133
+            new SearchPropertyDefinition(FilesPlugin::FILEID_PROPERTYNAME, false, true, false, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
134
+        ];
135
+    }
136
+
137
+    /**
138
+     * @param Query $search
139
+     * @return SearchResult[]
140
+     */
141
+    public function search(Query $search) {
142
+        if (count($search->from) !== 1) {
143
+            throw new \InvalidArgumentException('Searching more than one folder is not supported');
144
+        }
145
+        $query = $this->transformQuery($search);
146
+        $scope = $search->from[0];
147
+        if ($scope->path === null) {
148
+            throw new \InvalidArgumentException('Using uri\'s as scope is not supported, please use a path relative to the search arbiter instead');
149
+        }
150
+        $node = $this->tree->getNodeForPath($scope->path);
151
+        if (!$node instanceof Directory) {
152
+            throw new \InvalidArgumentException('Search is only supported on directories');
153
+        }
154
+
155
+        $fileInfo = $node->getFileInfo();
156
+        $folder = $this->rootFolder->get($fileInfo->getPath());
157
+        /** @var Folder $folder $results */
158
+        $results = $folder->search($query);
159
+
160
+        /** @var SearchResult[] $nodes */
161
+        $nodes = array_map(function (Node $node) {
162
+            if ($node instanceof Folder) {
163
+                $davNode = new \OCA\DAV\Connector\Sabre\Directory($this->view, $node, $this->tree, $this->shareManager);
164
+            } else {
165
+                $davNode = new \OCA\DAV\Connector\Sabre\File($this->view, $node, $this->shareManager);
166
+            }
167
+            $path = $this->getHrefForNode($node);
168
+            $this->tree->cacheNode($davNode, $path);
169
+            return new SearchResult($davNode, $path);
170
+        }, $results);
171
+
172
+        // Sort again, since the result from multiple storages is appended and not sorted
173
+        usort($nodes, function (SearchResult $a, SearchResult $b) use ($search) {
174
+            return $this->sort($a, $b, $search->orderBy);
175
+        });
176
+
177
+        // If a limit is provided use only return that number of files
178
+        if ($search->limit->maxResults !== 0) {
179
+            $nodes = \array_slice($nodes, 0, $search->limit->maxResults);
180
+        }
181
+
182
+        return $nodes;
183
+    }
184
+
185
+    private function sort(SearchResult $a, SearchResult $b, array $orders) {
186
+        /** @var Order $order */
187
+        foreach ($orders as $order) {
188
+            $v1 = $this->getSearchResultProperty($a, $order->property);
189
+            $v2 = $this->getSearchResultProperty($b, $order->property);
190
+
191
+
192
+            if ($v1 === null && $v2 === null) {
193
+                continue;
194
+            }
195
+            if ($v1 === null) {
196
+                return $order->order === Order::ASC ? 1 : -1;
197
+            }
198
+            if ($v2 === null) {
199
+                return $order->order === Order::ASC ? -1 : 1;
200
+            }
201
+
202
+            $s = $this->compareProperties($v1, $v2, $order);
203
+            if ($s === 0) {
204
+                continue;
205
+            }
206
+
207
+            if ($order->order === Order::DESC) {
208
+                $s = -$s;
209
+            }
210
+            return $s;
211
+        }
212
+
213
+        return 0;
214
+    }
215
+
216
+    private function compareProperties($a, $b, Order $order) {
217
+        switch ($order->property->dataType) {
218
+            case SearchPropertyDefinition::DATATYPE_STRING:
219
+                return strcmp($a, $b);
220
+            case SearchPropertyDefinition::DATATYPE_BOOLEAN:
221
+                if ($a === $b) {
222
+                    return 0;
223
+                }
224
+                if ($a === false) {
225
+                    return -1;
226
+                }
227
+                return 1;
228
+            default:
229
+                if ($a === $b) {
230
+                    return 0;
231
+                }
232
+                if ($a < $b) {
233
+                    return -1;
234
+                }
235
+                return 1;
236
+        }
237
+    }
238
+
239
+    private function getSearchResultProperty(SearchResult $result, SearchPropertyDefinition $property) {
240
+        /** @var \OCA\DAV\Connector\Sabre\Node $node */
241
+        $node = $result->node;
242
+
243
+        switch ($property->name) {
244
+            case '{DAV:}displayname':
245
+                return $node->getName();
246
+            case '{DAV:}getlastmodified':
247
+                return $node->getLastModified();
248
+            case FilesPlugin::SIZE_PROPERTYNAME:
249
+                return $node->getSize();
250
+            case FilesPlugin::INTERNAL_FILEID_PROPERTYNAME:
251
+                return $node->getInternalFileId();
252
+            default:
253
+                return null;
254
+        }
255
+    }
256
+
257
+    /**
258
+     * @param Node $node
259
+     * @return string
260
+     */
261
+    private function getHrefForNode(Node $node) {
262
+        $base = '/files/' . $this->user->getUID();
263
+        return $base . $this->view->getRelativePath($node->getPath());
264
+    }
265
+
266
+    /**
267
+     * @param Query $query
268
+     * @return ISearchQuery
269
+     */
270
+    private function transformQuery(Query $query) {
271
+        // TODO offset
272
+        $limit = $query->limit;
273
+        $orders = array_map([$this, 'mapSearchOrder'], $query->orderBy);
274
+        return new SearchQuery($this->transformSearchOperation($query->where), (int)$limit->maxResults, 0, $orders, $this->user);
275
+    }
276
+
277
+    /**
278
+     * @param Order $order
279
+     * @return ISearchOrder
280
+     */
281
+    private function mapSearchOrder(Order $order) {
282
+        return new SearchOrder($order->order === Order::ASC ? ISearchOrder::DIRECTION_ASCENDING : ISearchOrder::DIRECTION_DESCENDING, $this->mapPropertyNameToColumn($order->property));
283
+    }
284
+
285
+    /**
286
+     * @param Operator $operator
287
+     * @return ISearchOperator
288
+     */
289
+    private function transformSearchOperation(Operator $operator) {
290
+        list(, $trimmedType) = explode('}', $operator->type);
291
+        switch ($operator->type) {
292
+            case Operator::OPERATION_AND:
293
+            case Operator::OPERATION_OR:
294
+            case Operator::OPERATION_NOT:
295
+                $arguments = array_map([$this, 'transformSearchOperation'], $operator->arguments);
296
+                return new SearchBinaryOperator($trimmedType, $arguments);
297
+            case Operator::OPERATION_EQUAL:
298
+            case Operator::OPERATION_GREATER_OR_EQUAL_THAN:
299
+            case Operator::OPERATION_GREATER_THAN:
300
+            case Operator::OPERATION_LESS_OR_EQUAL_THAN:
301
+            case Operator::OPERATION_LESS_THAN:
302
+            case Operator::OPERATION_IS_LIKE:
303
+                if (count($operator->arguments) !== 2) {
304
+                    throw new \InvalidArgumentException('Invalid number of arguments for ' . $trimmedType . ' operation');
305
+                }
306
+                if (!($operator->arguments[0] instanceof SearchPropertyDefinition)) {
307
+                    throw new \InvalidArgumentException('Invalid argument 1 for ' . $trimmedType . ' operation, expected property');
308
+                }
309
+                if (!($operator->arguments[1] instanceof Literal)) {
310
+                    throw new \InvalidArgumentException('Invalid argument 2 for ' . $trimmedType . ' operation, expected literal');
311
+                }
312
+                return new SearchComparison($trimmedType, $this->mapPropertyNameToColumn($operator->arguments[0]), $this->castValue($operator->arguments[0], $operator->arguments[1]->value));
313
+            case Operator::OPERATION_IS_COLLECTION:
314
+                return new SearchComparison('eq', 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE);
315
+            default:
316
+                throw new \InvalidArgumentException('Unsupported operation ' . $trimmedType . ' (' . $operator->type . ')');
317
+        }
318
+    }
319
+
320
+    /**
321
+     * @param SearchPropertyDefinition $property
322
+     * @return string
323
+     */
324
+    private function mapPropertyNameToColumn(SearchPropertyDefinition $property) {
325
+        switch ($property->name) {
326
+            case '{DAV:}displayname':
327
+                return 'name';
328
+            case '{DAV:}getcontenttype':
329
+                return 'mimetype';
330
+            case '{DAV:}getlastmodified':
331
+                return 'mtime';
332
+            case FilesPlugin::SIZE_PROPERTYNAME:
333
+                return 'size';
334
+            case TagsPlugin::FAVORITE_PROPERTYNAME:
335
+                return 'favorite';
336
+            case TagsPlugin::TAGS_PROPERTYNAME:
337
+                return 'tagname';
338
+            case FilesPlugin::INTERNAL_FILEID_PROPERTYNAME:
339
+                return 'fileid';
340
+            default:
341
+                throw new \InvalidArgumentException('Unsupported property for search or order: ' . $property->name);
342
+        }
343
+    }
344
+
345
+    private function castValue(SearchPropertyDefinition $property, $value) {
346
+        switch ($property->dataType) {
347
+            case SearchPropertyDefinition::DATATYPE_BOOLEAN:
348
+                return $value === 'yes';
349
+            case SearchPropertyDefinition::DATATYPE_DECIMAL:
350
+            case SearchPropertyDefinition::DATATYPE_INTEGER:
351
+            case SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER:
352
+                return 0 + $value;
353
+            case SearchPropertyDefinition::DATATYPE_DATETIME:
354
+                if (is_numeric($value)) {
355
+                    return 0 + $value;
356
+                }
357
+                $date = \DateTime::createFromFormat(\DateTime::ATOM, $value);
358
+                return ($date instanceof \DateTime) ? $date->getTimestamp() : 0;
359
+            default:
360
+                return $value;
361
+        }
362
+    }
363 363
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 		$results = $folder->search($query);
159 159
 
160 160
 		/** @var SearchResult[] $nodes */
161
-		$nodes = array_map(function (Node $node) {
161
+		$nodes = array_map(function(Node $node) {
162 162
 			if ($node instanceof Folder) {
163 163
 				$davNode = new \OCA\DAV\Connector\Sabre\Directory($this->view, $node, $this->tree, $this->shareManager);
164 164
 			} else {
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 		}, $results);
171 171
 
172 172
 		// Sort again, since the result from multiple storages is appended and not sorted
173
-		usort($nodes, function (SearchResult $a, SearchResult $b) use ($search) {
173
+		usort($nodes, function(SearchResult $a, SearchResult $b) use ($search) {
174 174
 			return $this->sort($a, $b, $search->orderBy);
175 175
 		});
176 176
 
@@ -259,8 +259,8 @@  discard block
 block discarded – undo
259 259
 	 * @return string
260 260
 	 */
261 261
 	private function getHrefForNode(Node $node) {
262
-		$base = '/files/' . $this->user->getUID();
263
-		return $base . $this->view->getRelativePath($node->getPath());
262
+		$base = '/files/'.$this->user->getUID();
263
+		return $base.$this->view->getRelativePath($node->getPath());
264 264
 	}
265 265
 
266 266
 	/**
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 		// TODO offset
272 272
 		$limit = $query->limit;
273 273
 		$orders = array_map([$this, 'mapSearchOrder'], $query->orderBy);
274
-		return new SearchQuery($this->transformSearchOperation($query->where), (int)$limit->maxResults, 0, $orders, $this->user);
274
+		return new SearchQuery($this->transformSearchOperation($query->where), (int) $limit->maxResults, 0, $orders, $this->user);
275 275
 	}
276 276
 
277 277
 	/**
@@ -301,19 +301,19 @@  discard block
 block discarded – undo
301 301
 			case Operator::OPERATION_LESS_THAN:
302 302
 			case Operator::OPERATION_IS_LIKE:
303 303
 				if (count($operator->arguments) !== 2) {
304
-					throw new \InvalidArgumentException('Invalid number of arguments for ' . $trimmedType . ' operation');
304
+					throw new \InvalidArgumentException('Invalid number of arguments for '.$trimmedType.' operation');
305 305
 				}
306 306
 				if (!($operator->arguments[0] instanceof SearchPropertyDefinition)) {
307
-					throw new \InvalidArgumentException('Invalid argument 1 for ' . $trimmedType . ' operation, expected property');
307
+					throw new \InvalidArgumentException('Invalid argument 1 for '.$trimmedType.' operation, expected property');
308 308
 				}
309 309
 				if (!($operator->arguments[1] instanceof Literal)) {
310
-					throw new \InvalidArgumentException('Invalid argument 2 for ' . $trimmedType . ' operation, expected literal');
310
+					throw new \InvalidArgumentException('Invalid argument 2 for '.$trimmedType.' operation, expected literal');
311 311
 				}
312 312
 				return new SearchComparison($trimmedType, $this->mapPropertyNameToColumn($operator->arguments[0]), $this->castValue($operator->arguments[0], $operator->arguments[1]->value));
313 313
 			case Operator::OPERATION_IS_COLLECTION:
314 314
 				return new SearchComparison('eq', 'mimetype', ICacheEntry::DIRECTORY_MIMETYPE);
315 315
 			default:
316
-				throw new \InvalidArgumentException('Unsupported operation ' . $trimmedType . ' (' . $operator->type . ')');
316
+				throw new \InvalidArgumentException('Unsupported operation '.$trimmedType.' ('.$operator->type.')');
317 317
 		}
318 318
 	}
319 319
 
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
 			case FilesPlugin::INTERNAL_FILEID_PROPERTYNAME:
339 339
 				return 'fileid';
340 340
 			default:
341
-				throw new \InvalidArgumentException('Unsupported property for search or order: ' . $property->name);
341
+				throw new \InvalidArgumentException('Unsupported property for search or order: '.$property->name);
342 342
 		}
343 343
 	}
344 344
 
Please login to merge, or discard this patch.