Passed
Push — master ( 7ac6ee...bf39ad )
by Roeland
13:54 queued 15s
created

File::searchPaged()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 4
c 1
b 0
f 1
nc 2
nop 3
dl 0
loc 5
rs 10
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Andrew Brown <[email protected]>
6
 * @author Bart Visscher <[email protected]>
7
 * @author Christoph Wurst <[email protected]>
8
 * @author Jakob Sack <[email protected]>
9
 * @author John Molakvoæ (skjnldsv) <[email protected]>
10
 * @author Jörn Friedrich Dreyer <[email protected]>
11
 * @author Morris Jobke <[email protected]>
12
 * @author Roeland Jago Douma <[email protected]>
13
 *
14
 * @license AGPL-3.0
15
 *
16
 * This code is free software: you can redistribute it and/or modify
17
 * it under the terms of the GNU Affero General Public License, version 3,
18
 * as published by the Free Software Foundation.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
 * GNU Affero General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU Affero General Public License, version 3,
26
 * along with this program. If not, see <http://www.gnu.org/licenses/>
27
 *
28
 */
29
30
namespace OC\Search\Provider;
31
32
use OC\Files\Filesystem;
33
use OCP\Search\PagedProvider;
34
35
/**
36
 * Provide search results from the 'files' app
37
 * @deprecated 20.0.0
38
 */
39
class File extends PagedProvider {
0 ignored issues
show
Deprecated Code introduced by
The class OCP\Search\PagedProvider has been deprecated: 20.0.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

39
class File extends /** @scrutinizer ignore-deprecated */ PagedProvider {
Loading history...
40
41
	/**
42
	 * Search for files and folders matching the given query
43
	 *
44
	 * @param string $query
45
	 * @param int|null $limit
46
	 * @param int|null $offset
47
	 * @return \OCP\Search\Result[]
48
	 * @deprecated 20.0.0
49
	 */
50
	public function search($query, int $limit = null, int $offset = null) {
51
		if ($offset === null) {
52
			$offset = 0;
53
		}
54
		\OC_Util::setupFS();
55
		$files = Filesystem::search($query);
56
		$results = [];
57
		if ($limit !== null) {
58
			$files = array_slice($files, $offset, $offset + $limit);
59
		}
60
		// edit results
61
		foreach ($files as $fileData) {
62
			// skip versions
63
			if (strpos($fileData['path'], '_versions') === 0) {
64
				continue;
65
			}
66
			// skip top-level folder
67
			if ($fileData['name'] === 'files' && $fileData['parent'] === -1) {
68
				continue;
69
			}
70
			// create audio result
71
			if ($fileData['mimepart'] === 'audio') {
72
				$result = new \OC\Search\Result\Audio($fileData);
0 ignored issues
show
Deprecated Code introduced by
The class OC\Search\Result\Audio has been deprecated: 20.0.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

72
				$result = /** @scrutinizer ignore-deprecated */ new \OC\Search\Result\Audio($fileData);
Loading history...
73
			}
74
			// create image result
75
			elseif ($fileData['mimepart'] === 'image') {
76
				$result = new \OC\Search\Result\Image($fileData);
0 ignored issues
show
Deprecated Code introduced by
The class OC\Search\Result\Image has been deprecated: 20.0.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

76
				$result = /** @scrutinizer ignore-deprecated */ new \OC\Search\Result\Image($fileData);
Loading history...
77
			}
78
			// create folder result
79
			elseif ($fileData['mimetype'] === 'httpd/unix-directory') {
80
				$result = new \OC\Search\Result\Folder($fileData);
0 ignored issues
show
Deprecated Code introduced by
The class OC\Search\Result\Folder has been deprecated: 20.0.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

80
				$result = /** @scrutinizer ignore-deprecated */ new \OC\Search\Result\Folder($fileData);
Loading history...
81
			}
82
			// or create file result
83
			else {
84
				$result = new \OC\Search\Result\File($fileData);
0 ignored issues
show
Deprecated Code introduced by
The class OC\Search\Result\File has been deprecated: 20.0.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

84
				$result = /** @scrutinizer ignore-deprecated */ new \OC\Search\Result\File($fileData);
Loading history...
85
			}
86
			// add to results
87
			$results[] = $result;
88
		}
89
		// return
90
		return $results;
91
	}
92
93
	public function searchPaged($query, $page, $size) {
94
		if ($size === 0) {
95
			return $this->search($query);
96
		} else {
97
			return $this->search($query, $size, ($page - 1) * $size);
98
		}
99
	}
100
}
101