@@ -25,33 +25,33 @@ |
||
25 | 25 | use OCP\Files\Search\ISearchOrder; |
26 | 26 | |
27 | 27 | class SearchOrder implements ISearchOrder { |
28 | - /** @var string */ |
|
29 | - private $direction; |
|
30 | - /** @var string */ |
|
31 | - private $field; |
|
28 | + /** @var string */ |
|
29 | + private $direction; |
|
30 | + /** @var string */ |
|
31 | + private $field; |
|
32 | 32 | |
33 | - /** |
|
34 | - * SearchOrder constructor. |
|
35 | - * |
|
36 | - * @param string $direction |
|
37 | - * @param string $field |
|
38 | - */ |
|
39 | - public function __construct($direction, $field) { |
|
40 | - $this->direction = $direction; |
|
41 | - $this->field = $field; |
|
42 | - } |
|
33 | + /** |
|
34 | + * SearchOrder constructor. |
|
35 | + * |
|
36 | + * @param string $direction |
|
37 | + * @param string $field |
|
38 | + */ |
|
39 | + public function __construct($direction, $field) { |
|
40 | + $this->direction = $direction; |
|
41 | + $this->field = $field; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public function getDirection() { |
|
48 | - return $this->direction; |
|
49 | - } |
|
44 | + /** |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public function getDirection() { |
|
48 | + return $this->direction; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return string |
|
53 | - */ |
|
54 | - public function getField() { |
|
55 | - return $this->field; |
|
56 | - } |
|
51 | + /** |
|
52 | + * @return string |
|
53 | + */ |
|
54 | + public function getField() { |
|
55 | + return $this->field; |
|
56 | + } |
|
57 | 57 | } |
@@ -25,33 +25,33 @@ |
||
25 | 25 | use OCP\Files\Search\ISearchOperator; |
26 | 26 | |
27 | 27 | class SearchBinaryOperator implements ISearchBinaryOperator { |
28 | - /** @var string */ |
|
29 | - private $type; |
|
30 | - /** @var ISearchOperator[] */ |
|
31 | - private $arguments; |
|
28 | + /** @var string */ |
|
29 | + private $type; |
|
30 | + /** @var ISearchOperator[] */ |
|
31 | + private $arguments; |
|
32 | 32 | |
33 | - /** |
|
34 | - * SearchBinaryOperator constructor. |
|
35 | - * |
|
36 | - * @param string $type |
|
37 | - * @param ISearchOperator[] $arguments |
|
38 | - */ |
|
39 | - public function __construct($type, array $arguments) { |
|
40 | - $this->type = $type; |
|
41 | - $this->arguments = $arguments; |
|
42 | - } |
|
33 | + /** |
|
34 | + * SearchBinaryOperator constructor. |
|
35 | + * |
|
36 | + * @param string $type |
|
37 | + * @param ISearchOperator[] $arguments |
|
38 | + */ |
|
39 | + public function __construct($type, array $arguments) { |
|
40 | + $this->type = $type; |
|
41 | + $this->arguments = $arguments; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public function getType() { |
|
48 | - return $this->type; |
|
49 | - } |
|
44 | + /** |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public function getType() { |
|
48 | + return $this->type; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return ISearchOperator[] |
|
53 | - */ |
|
54 | - public function getArguments() { |
|
55 | - return $this->arguments; |
|
56 | - } |
|
51 | + /** |
|
52 | + * @return ISearchOperator[] |
|
53 | + */ |
|
54 | + public function getArguments() { |
|
55 | + return $this->arguments; |
|
56 | + } |
|
57 | 57 | } |
@@ -34,296 +34,296 @@ |
||
34 | 34 | use OCP\Files\Search\ISearchQuery; |
35 | 35 | |
36 | 36 | class CacheWrapper extends Cache { |
37 | - /** |
|
38 | - * @var \OCP\Files\Cache\ICache |
|
39 | - */ |
|
40 | - protected $cache; |
|
37 | + /** |
|
38 | + * @var \OCP\Files\Cache\ICache |
|
39 | + */ |
|
40 | + protected $cache; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @param \OCP\Files\Cache\ICache $cache |
|
44 | - */ |
|
45 | - public function __construct($cache) { |
|
46 | - $this->cache = $cache; |
|
47 | - } |
|
42 | + /** |
|
43 | + * @param \OCP\Files\Cache\ICache $cache |
|
44 | + */ |
|
45 | + public function __construct($cache) { |
|
46 | + $this->cache = $cache; |
|
47 | + } |
|
48 | 48 | |
49 | - protected function getCache() { |
|
50 | - return $this->cache; |
|
51 | - } |
|
49 | + protected function getCache() { |
|
50 | + return $this->cache; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Make it easy for wrappers to modify every returned cache entry |
|
55 | - * |
|
56 | - * @param ICacheEntry $entry |
|
57 | - * @return ICacheEntry |
|
58 | - */ |
|
59 | - protected function formatCacheEntry($entry) { |
|
60 | - return $entry; |
|
61 | - } |
|
53 | + /** |
|
54 | + * Make it easy for wrappers to modify every returned cache entry |
|
55 | + * |
|
56 | + * @param ICacheEntry $entry |
|
57 | + * @return ICacheEntry |
|
58 | + */ |
|
59 | + protected function formatCacheEntry($entry) { |
|
60 | + return $entry; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * get the stored metadata of a file or folder |
|
65 | - * |
|
66 | - * @param string|int $file |
|
67 | - * @return ICacheEntry|false |
|
68 | - */ |
|
69 | - public function get($file) { |
|
70 | - $result = $this->getCache()->get($file); |
|
71 | - if ($result) { |
|
72 | - $result = $this->formatCacheEntry($result); |
|
73 | - } |
|
74 | - return $result; |
|
75 | - } |
|
63 | + /** |
|
64 | + * get the stored metadata of a file or folder |
|
65 | + * |
|
66 | + * @param string|int $file |
|
67 | + * @return ICacheEntry|false |
|
68 | + */ |
|
69 | + public function get($file) { |
|
70 | + $result = $this->getCache()->get($file); |
|
71 | + if ($result) { |
|
72 | + $result = $this->formatCacheEntry($result); |
|
73 | + } |
|
74 | + return $result; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * get the metadata of all files stored in $folder |
|
79 | - * |
|
80 | - * @param string $folder |
|
81 | - * @return ICacheEntry[] |
|
82 | - */ |
|
83 | - public function getFolderContents($folder) { |
|
84 | - // can't do a simple $this->getCache()->.... call here since getFolderContentsById needs to be called on this |
|
85 | - // and not the wrapped cache |
|
86 | - $fileId = $this->getId($folder); |
|
87 | - return $this->getFolderContentsById($fileId); |
|
88 | - } |
|
77 | + /** |
|
78 | + * get the metadata of all files stored in $folder |
|
79 | + * |
|
80 | + * @param string $folder |
|
81 | + * @return ICacheEntry[] |
|
82 | + */ |
|
83 | + public function getFolderContents($folder) { |
|
84 | + // can't do a simple $this->getCache()->.... call here since getFolderContentsById needs to be called on this |
|
85 | + // and not the wrapped cache |
|
86 | + $fileId = $this->getId($folder); |
|
87 | + return $this->getFolderContentsById($fileId); |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * get the metadata of all files stored in $folder |
|
92 | - * |
|
93 | - * @param int $fileId the file id of the folder |
|
94 | - * @return array |
|
95 | - */ |
|
96 | - public function getFolderContentsById($fileId) { |
|
97 | - $results = $this->getCache()->getFolderContentsById($fileId); |
|
98 | - return array_map(array($this, 'formatCacheEntry'), $results); |
|
99 | - } |
|
90 | + /** |
|
91 | + * get the metadata of all files stored in $folder |
|
92 | + * |
|
93 | + * @param int $fileId the file id of the folder |
|
94 | + * @return array |
|
95 | + */ |
|
96 | + public function getFolderContentsById($fileId) { |
|
97 | + $results = $this->getCache()->getFolderContentsById($fileId); |
|
98 | + return array_map(array($this, 'formatCacheEntry'), $results); |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * insert or update meta data for a file or folder |
|
103 | - * |
|
104 | - * @param string $file |
|
105 | - * @param array $data |
|
106 | - * |
|
107 | - * @return int file id |
|
108 | - * @throws \RuntimeException |
|
109 | - */ |
|
110 | - public function put($file, array $data) { |
|
111 | - if (($id = $this->getId($file)) > -1) { |
|
112 | - $this->update($id, $data); |
|
113 | - return $id; |
|
114 | - } else { |
|
115 | - return $this->insert($file, $data); |
|
116 | - } |
|
117 | - } |
|
101 | + /** |
|
102 | + * insert or update meta data for a file or folder |
|
103 | + * |
|
104 | + * @param string $file |
|
105 | + * @param array $data |
|
106 | + * |
|
107 | + * @return int file id |
|
108 | + * @throws \RuntimeException |
|
109 | + */ |
|
110 | + public function put($file, array $data) { |
|
111 | + if (($id = $this->getId($file)) > -1) { |
|
112 | + $this->update($id, $data); |
|
113 | + return $id; |
|
114 | + } else { |
|
115 | + return $this->insert($file, $data); |
|
116 | + } |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * insert meta data for a new file or folder |
|
121 | - * |
|
122 | - * @param string $file |
|
123 | - * @param array $data |
|
124 | - * |
|
125 | - * @return int file id |
|
126 | - * @throws \RuntimeException |
|
127 | - */ |
|
128 | - public function insert($file, array $data) { |
|
129 | - return $this->getCache()->insert($file, $data); |
|
130 | - } |
|
119 | + /** |
|
120 | + * insert meta data for a new file or folder |
|
121 | + * |
|
122 | + * @param string $file |
|
123 | + * @param array $data |
|
124 | + * |
|
125 | + * @return int file id |
|
126 | + * @throws \RuntimeException |
|
127 | + */ |
|
128 | + public function insert($file, array $data) { |
|
129 | + return $this->getCache()->insert($file, $data); |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * update the metadata in the cache |
|
134 | - * |
|
135 | - * @param int $id |
|
136 | - * @param array $data |
|
137 | - */ |
|
138 | - public function update($id, array $data) { |
|
139 | - $this->getCache()->update($id, $data); |
|
140 | - } |
|
132 | + /** |
|
133 | + * update the metadata in the cache |
|
134 | + * |
|
135 | + * @param int $id |
|
136 | + * @param array $data |
|
137 | + */ |
|
138 | + public function update($id, array $data) { |
|
139 | + $this->getCache()->update($id, $data); |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * get the file id for a file |
|
144 | - * |
|
145 | - * @param string $file |
|
146 | - * @return int |
|
147 | - */ |
|
148 | - public function getId($file) { |
|
149 | - return $this->getCache()->getId($file); |
|
150 | - } |
|
142 | + /** |
|
143 | + * get the file id for a file |
|
144 | + * |
|
145 | + * @param string $file |
|
146 | + * @return int |
|
147 | + */ |
|
148 | + public function getId($file) { |
|
149 | + return $this->getCache()->getId($file); |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
153 | - * get the id of the parent folder of a file |
|
154 | - * |
|
155 | - * @param string $file |
|
156 | - * @return int |
|
157 | - */ |
|
158 | - public function getParentId($file) { |
|
159 | - return $this->getCache()->getParentId($file); |
|
160 | - } |
|
152 | + /** |
|
153 | + * get the id of the parent folder of a file |
|
154 | + * |
|
155 | + * @param string $file |
|
156 | + * @return int |
|
157 | + */ |
|
158 | + public function getParentId($file) { |
|
159 | + return $this->getCache()->getParentId($file); |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * check if a file is available in the cache |
|
164 | - * |
|
165 | - * @param string $file |
|
166 | - * @return bool |
|
167 | - */ |
|
168 | - public function inCache($file) { |
|
169 | - return $this->getCache()->inCache($file); |
|
170 | - } |
|
162 | + /** |
|
163 | + * check if a file is available in the cache |
|
164 | + * |
|
165 | + * @param string $file |
|
166 | + * @return bool |
|
167 | + */ |
|
168 | + public function inCache($file) { |
|
169 | + return $this->getCache()->inCache($file); |
|
170 | + } |
|
171 | 171 | |
172 | - /** |
|
173 | - * remove a file or folder from the cache |
|
174 | - * |
|
175 | - * @param string $file |
|
176 | - */ |
|
177 | - public function remove($file) { |
|
178 | - $this->getCache()->remove($file); |
|
179 | - } |
|
172 | + /** |
|
173 | + * remove a file or folder from the cache |
|
174 | + * |
|
175 | + * @param string $file |
|
176 | + */ |
|
177 | + public function remove($file) { |
|
178 | + $this->getCache()->remove($file); |
|
179 | + } |
|
180 | 180 | |
181 | - /** |
|
182 | - * Move a file or folder in the cache |
|
183 | - * |
|
184 | - * @param string $source |
|
185 | - * @param string $target |
|
186 | - */ |
|
187 | - public function move($source, $target) { |
|
188 | - $this->getCache()->move($source, $target); |
|
189 | - } |
|
181 | + /** |
|
182 | + * Move a file or folder in the cache |
|
183 | + * |
|
184 | + * @param string $source |
|
185 | + * @param string $target |
|
186 | + */ |
|
187 | + public function move($source, $target) { |
|
188 | + $this->getCache()->move($source, $target); |
|
189 | + } |
|
190 | 190 | |
191 | - public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
192 | - $this->getCache()->moveFromCache($sourceCache, $sourcePath, $targetPath); |
|
193 | - } |
|
191 | + public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
192 | + $this->getCache()->moveFromCache($sourceCache, $sourcePath, $targetPath); |
|
193 | + } |
|
194 | 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()->clear(); |
|
200 | - } |
|
195 | + /** |
|
196 | + * remove all entries for files that are stored on the storage from the cache |
|
197 | + */ |
|
198 | + public function clear() { |
|
199 | + $this->getCache()->clear(); |
|
200 | + } |
|
201 | 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($file); |
|
209 | - } |
|
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($file); |
|
209 | + } |
|
210 | 210 | |
211 | - /** |
|
212 | - * search for files matching $pattern |
|
213 | - * |
|
214 | - * @param string $pattern |
|
215 | - * @return ICacheEntry[] an array of file data |
|
216 | - */ |
|
217 | - public function search($pattern) { |
|
218 | - $results = $this->getCache()->search($pattern); |
|
219 | - return array_map(array($this, 'formatCacheEntry'), $results); |
|
220 | - } |
|
211 | + /** |
|
212 | + * search for files matching $pattern |
|
213 | + * |
|
214 | + * @param string $pattern |
|
215 | + * @return ICacheEntry[] an array of file data |
|
216 | + */ |
|
217 | + public function search($pattern) { |
|
218 | + $results = $this->getCache()->search($pattern); |
|
219 | + return array_map(array($this, 'formatCacheEntry'), $results); |
|
220 | + } |
|
221 | 221 | |
222 | - /** |
|
223 | - * search for files by mimetype |
|
224 | - * |
|
225 | - * @param string $mimetype |
|
226 | - * @return ICacheEntry[] |
|
227 | - */ |
|
228 | - public function searchByMime($mimetype) { |
|
229 | - $results = $this->getCache()->searchByMime($mimetype); |
|
230 | - return array_map(array($this, 'formatCacheEntry'), $results); |
|
231 | - } |
|
222 | + /** |
|
223 | + * search for files by mimetype |
|
224 | + * |
|
225 | + * @param string $mimetype |
|
226 | + * @return ICacheEntry[] |
|
227 | + */ |
|
228 | + public function searchByMime($mimetype) { |
|
229 | + $results = $this->getCache()->searchByMime($mimetype); |
|
230 | + return array_map(array($this, 'formatCacheEntry'), $results); |
|
231 | + } |
|
232 | 232 | |
233 | - public function searchQuery(ISearchQuery $query) { |
|
234 | - $results = $this->getCache()->searchQuery($query); |
|
235 | - return array_map(array($this, 'formatCacheEntry'), $results); |
|
236 | - } |
|
233 | + public function searchQuery(ISearchQuery $query) { |
|
234 | + $results = $this->getCache()->searchQuery($query); |
|
235 | + return array_map(array($this, 'formatCacheEntry'), $results); |
|
236 | + } |
|
237 | 237 | |
238 | - /** |
|
239 | - * search for files by tag |
|
240 | - * |
|
241 | - * @param string|int $tag name or tag id |
|
242 | - * @param string $userId owner of the tags |
|
243 | - * @return ICacheEntry[] file data |
|
244 | - */ |
|
245 | - public function searchByTag($tag, $userId) { |
|
246 | - $results = $this->getCache()->searchByTag($tag, $userId); |
|
247 | - return array_map(array($this, 'formatCacheEntry'), $results); |
|
248 | - } |
|
238 | + /** |
|
239 | + * search for files by tag |
|
240 | + * |
|
241 | + * @param string|int $tag name or tag id |
|
242 | + * @param string $userId owner of the tags |
|
243 | + * @return ICacheEntry[] file data |
|
244 | + */ |
|
245 | + public function searchByTag($tag, $userId) { |
|
246 | + $results = $this->getCache()->searchByTag($tag, $userId); |
|
247 | + return array_map(array($this, 'formatCacheEntry'), $results); |
|
248 | + } |
|
249 | 249 | |
250 | - /** |
|
251 | - * update the folder size and the size of all parent folders |
|
252 | - * |
|
253 | - * @param string|boolean $path |
|
254 | - * @param array $data (optional) meta data of the folder |
|
255 | - */ |
|
256 | - public function correctFolderSize($path, $data = null) { |
|
257 | - if ($this->getCache() instanceof Cache) { |
|
258 | - $this->getCache()->correctFolderSize($path, $data); |
|
259 | - } |
|
260 | - } |
|
250 | + /** |
|
251 | + * update the folder size and the size of all parent folders |
|
252 | + * |
|
253 | + * @param string|boolean $path |
|
254 | + * @param array $data (optional) meta data of the folder |
|
255 | + */ |
|
256 | + public function correctFolderSize($path, $data = null) { |
|
257 | + if ($this->getCache() instanceof Cache) { |
|
258 | + $this->getCache()->correctFolderSize($path, $data); |
|
259 | + } |
|
260 | + } |
|
261 | 261 | |
262 | - /** |
|
263 | - * get the size of a folder and set it in the cache |
|
264 | - * |
|
265 | - * @param string $path |
|
266 | - * @param array $entry (optional) meta data of the folder |
|
267 | - * @return int |
|
268 | - */ |
|
269 | - public function calculateFolderSize($path, $entry = null) { |
|
270 | - if ($this->getCache() instanceof Cache) { |
|
271 | - return $this->getCache()->calculateFolderSize($path, $entry); |
|
272 | - } else { |
|
273 | - return 0; |
|
274 | - } |
|
275 | - } |
|
262 | + /** |
|
263 | + * get the size of a folder and set it in the cache |
|
264 | + * |
|
265 | + * @param string $path |
|
266 | + * @param array $entry (optional) meta data of the folder |
|
267 | + * @return int |
|
268 | + */ |
|
269 | + public function calculateFolderSize($path, $entry = null) { |
|
270 | + if ($this->getCache() instanceof Cache) { |
|
271 | + return $this->getCache()->calculateFolderSize($path, $entry); |
|
272 | + } else { |
|
273 | + return 0; |
|
274 | + } |
|
275 | + } |
|
276 | 276 | |
277 | - /** |
|
278 | - * get all file ids on the files on the storage |
|
279 | - * |
|
280 | - * @return int[] |
|
281 | - */ |
|
282 | - public function getAll() { |
|
283 | - return $this->getCache()->getAll(); |
|
284 | - } |
|
277 | + /** |
|
278 | + * get all file ids on the files on the storage |
|
279 | + * |
|
280 | + * @return int[] |
|
281 | + */ |
|
282 | + public function getAll() { |
|
283 | + return $this->getCache()->getAll(); |
|
284 | + } |
|
285 | 285 | |
286 | - /** |
|
287 | - * find a folder in the cache which has not been fully scanned |
|
288 | - * |
|
289 | - * If multiple incomplete folders are in the cache, the one with the highest id will be returned, |
|
290 | - * use the one with the highest id gives the best result with the background scanner, since that is most |
|
291 | - * likely the folder where we stopped scanning previously |
|
292 | - * |
|
293 | - * @return string|bool the path of the folder or false when no folder matched |
|
294 | - */ |
|
295 | - public function getIncomplete() { |
|
296 | - return $this->getCache()->getIncomplete(); |
|
297 | - } |
|
286 | + /** |
|
287 | + * find a folder in the cache which has not been fully scanned |
|
288 | + * |
|
289 | + * If multiple incomplete folders are in the cache, the one with the highest id will be returned, |
|
290 | + * use the one with the highest id gives the best result with the background scanner, since that is most |
|
291 | + * likely the folder where we stopped scanning previously |
|
292 | + * |
|
293 | + * @return string|bool the path of the folder or false when no folder matched |
|
294 | + */ |
|
295 | + public function getIncomplete() { |
|
296 | + return $this->getCache()->getIncomplete(); |
|
297 | + } |
|
298 | 298 | |
299 | - /** |
|
300 | - * get the path of a file on this storage by it's id |
|
301 | - * |
|
302 | - * @param int $id |
|
303 | - * @return string|null |
|
304 | - */ |
|
305 | - public function getPathById($id) { |
|
306 | - return $this->getCache()->getPathById($id); |
|
307 | - } |
|
299 | + /** |
|
300 | + * get the path of a file on this storage by it's id |
|
301 | + * |
|
302 | + * @param int $id |
|
303 | + * @return string|null |
|
304 | + */ |
|
305 | + public function getPathById($id) { |
|
306 | + return $this->getCache()->getPathById($id); |
|
307 | + } |
|
308 | 308 | |
309 | - /** |
|
310 | - * Returns the numeric storage id |
|
311 | - * |
|
312 | - * @return int |
|
313 | - */ |
|
314 | - public function getNumericStorageId() { |
|
315 | - return $this->getCache()->getNumericStorageId(); |
|
316 | - } |
|
309 | + /** |
|
310 | + * Returns the numeric storage id |
|
311 | + * |
|
312 | + * @return int |
|
313 | + */ |
|
314 | + public function getNumericStorageId() { |
|
315 | + return $this->getCache()->getNumericStorageId(); |
|
316 | + } |
|
317 | 317 | |
318 | - /** |
|
319 | - * get the storage id of the storage for a file and the internal path of the file |
|
320 | - * unlike getPathById this does not limit the search to files on this storage and |
|
321 | - * instead does a global search in the cache table |
|
322 | - * |
|
323 | - * @param int $id |
|
324 | - * @return array first element holding the storage id, second the path |
|
325 | - */ |
|
326 | - static public function getById($id) { |
|
327 | - return parent::getById($id); |
|
328 | - } |
|
318 | + /** |
|
319 | + * get the storage id of the storage for a file and the internal path of the file |
|
320 | + * unlike getPathById this does not limit the search to files on this storage and |
|
321 | + * instead does a global search in the cache table |
|
322 | + * |
|
323 | + * @param int $id |
|
324 | + * @return array first element holding the storage id, second the path |
|
325 | + */ |
|
326 | + static public function getById($id) { |
|
327 | + return parent::getById($id); |
|
328 | + } |
|
329 | 329 | } |
@@ -27,101 +27,101 @@ |
||
27 | 27 | use OCP\Files\Search\ISearchQuery; |
28 | 28 | |
29 | 29 | class NullCache implements ICache { |
30 | - public function getNumericStorageId() { |
|
31 | - return -1; |
|
32 | - } |
|
33 | - |
|
34 | - public function get($file) { |
|
35 | - return $file !== '' ? null : |
|
36 | - new CacheEntry([ |
|
37 | - 'fileid' => -1, |
|
38 | - 'parent' => -1, |
|
39 | - 'name' => '', |
|
40 | - 'path' => '', |
|
41 | - 'size' => '0', |
|
42 | - 'mtime' => time(), |
|
43 | - 'storage_mtime' => time(), |
|
44 | - 'etag' => '', |
|
45 | - 'mimetype' => FileInfo::MIMETYPE_FOLDER, |
|
46 | - 'mimepart' => 'httpd', |
|
47 | - 'permissions' => Constants::PERMISSION_READ |
|
48 | - ]); |
|
49 | - } |
|
50 | - |
|
51 | - public function getFolderContents($folder) { |
|
52 | - return []; |
|
53 | - } |
|
54 | - |
|
55 | - public function getFolderContentsById($fileId) { |
|
56 | - return []; |
|
57 | - } |
|
58 | - |
|
59 | - public function put($file, array $data) { |
|
60 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
61 | - } |
|
62 | - |
|
63 | - public function insert($file, array $data) { |
|
64 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
65 | - } |
|
66 | - |
|
67 | - public function update($id, array $data) { |
|
68 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
69 | - } |
|
70 | - |
|
71 | - public function getId($file) { |
|
72 | - return -1; |
|
73 | - } |
|
74 | - |
|
75 | - public function getParentId($file) { |
|
76 | - return -1; |
|
77 | - } |
|
78 | - |
|
79 | - public function inCache($file) { |
|
80 | - return $file === ''; |
|
81 | - } |
|
82 | - |
|
83 | - public function remove($file) { |
|
84 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
85 | - } |
|
86 | - |
|
87 | - public function move($source, $target) { |
|
88 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
89 | - } |
|
90 | - |
|
91 | - public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
92 | - throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
93 | - } |
|
94 | - |
|
95 | - public function getStatus($file) { |
|
96 | - return ICache::COMPLETE; |
|
97 | - } |
|
98 | - |
|
99 | - public function search($pattern) { |
|
100 | - return []; |
|
101 | - } |
|
102 | - |
|
103 | - public function searchByMime($mimetype) { |
|
104 | - return []; |
|
105 | - } |
|
106 | - |
|
107 | - public function searchQuery(ISearchQuery $query) { |
|
108 | - return []; |
|
109 | - } |
|
110 | - |
|
111 | - public function searchByTag($tag, $userId) { |
|
112 | - return []; |
|
113 | - } |
|
114 | - |
|
115 | - public function getIncomplete() { |
|
116 | - return []; |
|
117 | - } |
|
118 | - |
|
119 | - public function getPathById($id) { |
|
120 | - return ''; |
|
121 | - } |
|
122 | - |
|
123 | - public function normalize($path) { |
|
124 | - return $path; |
|
125 | - } |
|
30 | + public function getNumericStorageId() { |
|
31 | + return -1; |
|
32 | + } |
|
33 | + |
|
34 | + public function get($file) { |
|
35 | + return $file !== '' ? null : |
|
36 | + new CacheEntry([ |
|
37 | + 'fileid' => -1, |
|
38 | + 'parent' => -1, |
|
39 | + 'name' => '', |
|
40 | + 'path' => '', |
|
41 | + 'size' => '0', |
|
42 | + 'mtime' => time(), |
|
43 | + 'storage_mtime' => time(), |
|
44 | + 'etag' => '', |
|
45 | + 'mimetype' => FileInfo::MIMETYPE_FOLDER, |
|
46 | + 'mimepart' => 'httpd', |
|
47 | + 'permissions' => Constants::PERMISSION_READ |
|
48 | + ]); |
|
49 | + } |
|
50 | + |
|
51 | + public function getFolderContents($folder) { |
|
52 | + return []; |
|
53 | + } |
|
54 | + |
|
55 | + public function getFolderContentsById($fileId) { |
|
56 | + return []; |
|
57 | + } |
|
58 | + |
|
59 | + public function put($file, array $data) { |
|
60 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
61 | + } |
|
62 | + |
|
63 | + public function insert($file, array $data) { |
|
64 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
65 | + } |
|
66 | + |
|
67 | + public function update($id, array $data) { |
|
68 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
69 | + } |
|
70 | + |
|
71 | + public function getId($file) { |
|
72 | + return -1; |
|
73 | + } |
|
74 | + |
|
75 | + public function getParentId($file) { |
|
76 | + return -1; |
|
77 | + } |
|
78 | + |
|
79 | + public function inCache($file) { |
|
80 | + return $file === ''; |
|
81 | + } |
|
82 | + |
|
83 | + public function remove($file) { |
|
84 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
85 | + } |
|
86 | + |
|
87 | + public function move($source, $target) { |
|
88 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
89 | + } |
|
90 | + |
|
91 | + public function moveFromCache(ICache $sourceCache, $sourcePath, $targetPath) { |
|
92 | + throw new \OC\ForbiddenException('This request is not allowed to access the filesystem'); |
|
93 | + } |
|
94 | + |
|
95 | + public function getStatus($file) { |
|
96 | + return ICache::COMPLETE; |
|
97 | + } |
|
98 | + |
|
99 | + public function search($pattern) { |
|
100 | + return []; |
|
101 | + } |
|
102 | + |
|
103 | + public function searchByMime($mimetype) { |
|
104 | + return []; |
|
105 | + } |
|
106 | + |
|
107 | + public function searchQuery(ISearchQuery $query) { |
|
108 | + return []; |
|
109 | + } |
|
110 | + |
|
111 | + public function searchByTag($tag, $userId) { |
|
112 | + return []; |
|
113 | + } |
|
114 | + |
|
115 | + public function getIncomplete() { |
|
116 | + return []; |
|
117 | + } |
|
118 | + |
|
119 | + public function getPathById($id) { |
|
120 | + return ''; |
|
121 | + } |
|
122 | + |
|
123 | + public function normalize($path) { |
|
124 | + return $path; |
|
125 | + } |
|
126 | 126 | |
127 | 127 | } |
@@ -1,10 +1,10 @@ |
||
1 | 1 | <?php /** @var $l OC_L10N */ ?> |
2 | 2 | <?php |
3 | 3 | script('core', [ |
4 | - 'jquery-showpassword', |
|
4 | + 'jquery-showpassword', |
|
5 | 5 | ]); |
6 | 6 | script('user_ldap', [ |
7 | - 'renewPassword', |
|
7 | + 'renewPassword', |
|
8 | 8 | ]); |
9 | 9 | style('user_ldap', 'renewPassword'); |
10 | 10 | \OC_Util::addVendorScript('strengthify/jquery.strengthify'); |
@@ -38,139 +38,139 @@ |
||
38 | 38 | |
39 | 39 | class DecryptAll extends Command { |
40 | 40 | |
41 | - /** @var IManager */ |
|
42 | - protected $encryptionManager; |
|
43 | - |
|
44 | - /** @var IAppManager */ |
|
45 | - protected $appManager; |
|
46 | - |
|
47 | - /** @var IConfig */ |
|
48 | - protected $config; |
|
49 | - |
|
50 | - /** @var QuestionHelper */ |
|
51 | - protected $questionHelper; |
|
52 | - |
|
53 | - /** @var bool */ |
|
54 | - protected $wasTrashbinEnabled; |
|
55 | - |
|
56 | - /** @var bool */ |
|
57 | - protected $wasMaintenanceModeEnabled; |
|
58 | - |
|
59 | - /** @var \OC\Encryption\DecryptAll */ |
|
60 | - protected $decryptAll; |
|
61 | - |
|
62 | - /** |
|
63 | - * @param IManager $encryptionManager |
|
64 | - * @param IAppManager $appManager |
|
65 | - * @param IConfig $config |
|
66 | - * @param \OC\Encryption\DecryptAll $decryptAll |
|
67 | - * @param QuestionHelper $questionHelper |
|
68 | - */ |
|
69 | - public function __construct( |
|
70 | - IManager $encryptionManager, |
|
71 | - IAppManager $appManager, |
|
72 | - IConfig $config, |
|
73 | - \OC\Encryption\DecryptAll $decryptAll, |
|
74 | - QuestionHelper $questionHelper |
|
75 | - ) { |
|
76 | - parent::__construct(); |
|
77 | - |
|
78 | - $this->appManager = $appManager; |
|
79 | - $this->encryptionManager = $encryptionManager; |
|
80 | - $this->config = $config; |
|
81 | - $this->decryptAll = $decryptAll; |
|
82 | - $this->questionHelper = $questionHelper; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Set maintenance mode and disable the trashbin app |
|
87 | - */ |
|
88 | - protected function forceMaintenanceAndTrashbin() { |
|
89 | - $this->wasTrashbinEnabled = $this->appManager->isEnabledForUser('files_trashbin'); |
|
90 | - $this->wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
91 | - $this->config->setSystemValue('maintenance', true); |
|
92 | - $this->appManager->disableApp('files_trashbin'); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Reset the maintenance mode and re-enable the trashbin app |
|
97 | - */ |
|
98 | - protected function resetMaintenanceAndTrashbin() { |
|
99 | - $this->config->setSystemValue('maintenance', $this->wasMaintenanceModeEnabled); |
|
100 | - if ($this->wasTrashbinEnabled) { |
|
101 | - $this->appManager->enableApp('files_trashbin'); |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - protected function configure() { |
|
106 | - parent::configure(); |
|
107 | - |
|
108 | - $this->setName('encryption:decrypt-all'); |
|
109 | - $this->setDescription('Disable server-side encryption and decrypt all files'); |
|
110 | - $this->setHelp( |
|
111 | - 'This will disable server-side encryption and decrypt all files for ' |
|
112 | - . 'all users if it is supported by your encryption module. ' |
|
113 | - . 'Please make sure that no user access his files during this process!' |
|
114 | - ); |
|
115 | - $this->addArgument( |
|
116 | - 'user', |
|
117 | - InputArgument::OPTIONAL, |
|
118 | - 'user for which you want to decrypt all files (optional)', |
|
119 | - '' |
|
120 | - ); |
|
121 | - } |
|
122 | - |
|
123 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
124 | - |
|
125 | - try { |
|
126 | - if ($this->encryptionManager->isEnabled() === true) { |
|
127 | - $output->write('Disable server side encryption... '); |
|
128 | - $this->config->setAppValue('core', 'encryption_enabled', 'no'); |
|
129 | - $output->writeln('done.'); |
|
130 | - } else { |
|
131 | - $output->writeln('Server side encryption not enabled. Nothing to do.'); |
|
132 | - return; |
|
133 | - } |
|
134 | - |
|
135 | - $uid = $input->getArgument('user'); |
|
136 | - if ($uid === '') { |
|
137 | - $message = 'your Nextcloud'; |
|
138 | - } else { |
|
139 | - $message = "$uid's account"; |
|
140 | - } |
|
141 | - |
|
142 | - $output->writeln("\n"); |
|
143 | - $output->writeln("You are about to start to decrypt all files stored in $message."); |
|
144 | - $output->writeln('It will depend on the encryption module and your setup if this is possible.'); |
|
145 | - $output->writeln('Depending on the number and size of your files this can take some time'); |
|
146 | - $output->writeln('Please make sure that no user access his files during this process!'); |
|
147 | - $output->writeln(''); |
|
148 | - $question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false); |
|
149 | - if ($this->questionHelper->ask($input, $output, $question)) { |
|
150 | - $this->forceMaintenanceAndTrashbin(); |
|
151 | - $user = $input->getArgument('user'); |
|
152 | - $result = $this->decryptAll->decryptAll($input, $output, $user); |
|
153 | - if ($result === false) { |
|
154 | - $output->writeln(' aborted.'); |
|
155 | - $output->writeln('Server side encryption remains enabled'); |
|
156 | - $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
157 | - } else if ($uid !== '') { |
|
158 | - $output->writeln('Server side encryption remains enabled'); |
|
159 | - $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
160 | - } |
|
161 | - $this->resetMaintenanceAndTrashbin(); |
|
162 | - } else { |
|
163 | - $output->write('Enable server side encryption... '); |
|
164 | - $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
165 | - $output->writeln('done.'); |
|
166 | - $output->writeln('aborted'); |
|
167 | - } |
|
168 | - } catch (\Exception $e) { |
|
169 | - // enable server side encryption again if something went wrong |
|
170 | - $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
171 | - $this->resetMaintenanceAndTrashbin(); |
|
172 | - throw $e; |
|
173 | - } |
|
174 | - |
|
175 | - } |
|
41 | + /** @var IManager */ |
|
42 | + protected $encryptionManager; |
|
43 | + |
|
44 | + /** @var IAppManager */ |
|
45 | + protected $appManager; |
|
46 | + |
|
47 | + /** @var IConfig */ |
|
48 | + protected $config; |
|
49 | + |
|
50 | + /** @var QuestionHelper */ |
|
51 | + protected $questionHelper; |
|
52 | + |
|
53 | + /** @var bool */ |
|
54 | + protected $wasTrashbinEnabled; |
|
55 | + |
|
56 | + /** @var bool */ |
|
57 | + protected $wasMaintenanceModeEnabled; |
|
58 | + |
|
59 | + /** @var \OC\Encryption\DecryptAll */ |
|
60 | + protected $decryptAll; |
|
61 | + |
|
62 | + /** |
|
63 | + * @param IManager $encryptionManager |
|
64 | + * @param IAppManager $appManager |
|
65 | + * @param IConfig $config |
|
66 | + * @param \OC\Encryption\DecryptAll $decryptAll |
|
67 | + * @param QuestionHelper $questionHelper |
|
68 | + */ |
|
69 | + public function __construct( |
|
70 | + IManager $encryptionManager, |
|
71 | + IAppManager $appManager, |
|
72 | + IConfig $config, |
|
73 | + \OC\Encryption\DecryptAll $decryptAll, |
|
74 | + QuestionHelper $questionHelper |
|
75 | + ) { |
|
76 | + parent::__construct(); |
|
77 | + |
|
78 | + $this->appManager = $appManager; |
|
79 | + $this->encryptionManager = $encryptionManager; |
|
80 | + $this->config = $config; |
|
81 | + $this->decryptAll = $decryptAll; |
|
82 | + $this->questionHelper = $questionHelper; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Set maintenance mode and disable the trashbin app |
|
87 | + */ |
|
88 | + protected function forceMaintenanceAndTrashbin() { |
|
89 | + $this->wasTrashbinEnabled = $this->appManager->isEnabledForUser('files_trashbin'); |
|
90 | + $this->wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
91 | + $this->config->setSystemValue('maintenance', true); |
|
92 | + $this->appManager->disableApp('files_trashbin'); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Reset the maintenance mode and re-enable the trashbin app |
|
97 | + */ |
|
98 | + protected function resetMaintenanceAndTrashbin() { |
|
99 | + $this->config->setSystemValue('maintenance', $this->wasMaintenanceModeEnabled); |
|
100 | + if ($this->wasTrashbinEnabled) { |
|
101 | + $this->appManager->enableApp('files_trashbin'); |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + protected function configure() { |
|
106 | + parent::configure(); |
|
107 | + |
|
108 | + $this->setName('encryption:decrypt-all'); |
|
109 | + $this->setDescription('Disable server-side encryption and decrypt all files'); |
|
110 | + $this->setHelp( |
|
111 | + 'This will disable server-side encryption and decrypt all files for ' |
|
112 | + . 'all users if it is supported by your encryption module. ' |
|
113 | + . 'Please make sure that no user access his files during this process!' |
|
114 | + ); |
|
115 | + $this->addArgument( |
|
116 | + 'user', |
|
117 | + InputArgument::OPTIONAL, |
|
118 | + 'user for which you want to decrypt all files (optional)', |
|
119 | + '' |
|
120 | + ); |
|
121 | + } |
|
122 | + |
|
123 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
124 | + |
|
125 | + try { |
|
126 | + if ($this->encryptionManager->isEnabled() === true) { |
|
127 | + $output->write('Disable server side encryption... '); |
|
128 | + $this->config->setAppValue('core', 'encryption_enabled', 'no'); |
|
129 | + $output->writeln('done.'); |
|
130 | + } else { |
|
131 | + $output->writeln('Server side encryption not enabled. Nothing to do.'); |
|
132 | + return; |
|
133 | + } |
|
134 | + |
|
135 | + $uid = $input->getArgument('user'); |
|
136 | + if ($uid === '') { |
|
137 | + $message = 'your Nextcloud'; |
|
138 | + } else { |
|
139 | + $message = "$uid's account"; |
|
140 | + } |
|
141 | + |
|
142 | + $output->writeln("\n"); |
|
143 | + $output->writeln("You are about to start to decrypt all files stored in $message."); |
|
144 | + $output->writeln('It will depend on the encryption module and your setup if this is possible.'); |
|
145 | + $output->writeln('Depending on the number and size of your files this can take some time'); |
|
146 | + $output->writeln('Please make sure that no user access his files during this process!'); |
|
147 | + $output->writeln(''); |
|
148 | + $question = new ConfirmationQuestion('Do you really want to continue? (y/n) ', false); |
|
149 | + if ($this->questionHelper->ask($input, $output, $question)) { |
|
150 | + $this->forceMaintenanceAndTrashbin(); |
|
151 | + $user = $input->getArgument('user'); |
|
152 | + $result = $this->decryptAll->decryptAll($input, $output, $user); |
|
153 | + if ($result === false) { |
|
154 | + $output->writeln(' aborted.'); |
|
155 | + $output->writeln('Server side encryption remains enabled'); |
|
156 | + $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
157 | + } else if ($uid !== '') { |
|
158 | + $output->writeln('Server side encryption remains enabled'); |
|
159 | + $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
160 | + } |
|
161 | + $this->resetMaintenanceAndTrashbin(); |
|
162 | + } else { |
|
163 | + $output->write('Enable server side encryption... '); |
|
164 | + $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
165 | + $output->writeln('done.'); |
|
166 | + $output->writeln('aborted'); |
|
167 | + } |
|
168 | + } catch (\Exception $e) { |
|
169 | + // enable server side encryption again if something went wrong |
|
170 | + $this->config->setAppValue('core', 'encryption_enabled', 'yes'); |
|
171 | + $this->resetMaintenanceAndTrashbin(); |
|
172 | + throw $e; |
|
173 | + } |
|
174 | + |
|
175 | + } |
|
176 | 176 | } |
@@ -30,172 +30,172 @@ |
||
30 | 30 | |
31 | 31 | class GroupPrincipalBackend implements BackendInterface { |
32 | 32 | |
33 | - const PRINCIPAL_PREFIX = 'principals/groups'; |
|
34 | - |
|
35 | - /** @var IGroupManager */ |
|
36 | - private $groupManager; |
|
37 | - |
|
38 | - /** |
|
39 | - * @param IGroupManager $IGroupManager |
|
40 | - */ |
|
41 | - public function __construct(IGroupManager $IGroupManager) { |
|
42 | - $this->groupManager = $IGroupManager; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * Returns a list of principals based on a prefix. |
|
47 | - * |
|
48 | - * This prefix will often contain something like 'principals'. You are only |
|
49 | - * expected to return principals that are in this base path. |
|
50 | - * |
|
51 | - * You are expected to return at least a 'uri' for every user, you can |
|
52 | - * return any additional properties if you wish so. Common properties are: |
|
53 | - * {DAV:}displayname |
|
54 | - * |
|
55 | - * @param string $prefixPath |
|
56 | - * @return string[] |
|
57 | - */ |
|
58 | - public function getPrincipalsByPrefix($prefixPath) { |
|
59 | - $principals = []; |
|
60 | - |
|
61 | - if ($prefixPath === self::PRINCIPAL_PREFIX) { |
|
62 | - foreach($this->groupManager->search('') as $user) { |
|
63 | - $principals[] = $this->groupToPrincipal($user); |
|
64 | - } |
|
65 | - } |
|
66 | - |
|
67 | - return $principals; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Returns a specific principal, specified by it's path. |
|
72 | - * The returned structure should be the exact same as from |
|
73 | - * getPrincipalsByPrefix. |
|
74 | - * |
|
75 | - * @param string $path |
|
76 | - * @return array |
|
77 | - */ |
|
78 | - public function getPrincipalByPath($path) { |
|
79 | - $elements = explode('/', $path, 3); |
|
80 | - if ($elements[0] !== 'principals') { |
|
81 | - return null; |
|
82 | - } |
|
83 | - if ($elements[1] !== 'groups') { |
|
84 | - return null; |
|
85 | - } |
|
86 | - $name = urldecode($elements[2]); |
|
87 | - $group = $this->groupManager->get($name); |
|
88 | - |
|
89 | - if (!is_null($group)) { |
|
90 | - return $this->groupToPrincipal($group); |
|
91 | - } |
|
92 | - |
|
93 | - return null; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Returns the list of members for a group-principal |
|
98 | - * |
|
99 | - * @param string $principal |
|
100 | - * @return string[] |
|
101 | - * @throws Exception |
|
102 | - */ |
|
103 | - public function getGroupMemberSet($principal) { |
|
104 | - $elements = explode('/', $principal); |
|
105 | - if ($elements[0] !== 'principals') { |
|
106 | - return []; |
|
107 | - } |
|
108 | - if ($elements[1] !== 'groups') { |
|
109 | - return []; |
|
110 | - } |
|
111 | - $name = $elements[2]; |
|
112 | - $group = $this->groupManager->get($name); |
|
113 | - |
|
114 | - if (is_null($group)) { |
|
115 | - return []; |
|
116 | - } |
|
117 | - |
|
118 | - return array_map(function($user) { |
|
119 | - return $this->userToPrincipal($user); |
|
120 | - }, $group->getUsers()); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Returns the list of groups a principal is a member of |
|
125 | - * |
|
126 | - * @param string $principal |
|
127 | - * @return array |
|
128 | - * @throws Exception |
|
129 | - */ |
|
130 | - public function getGroupMembership($principal) { |
|
131 | - return []; |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Updates the list of group members for a group principal. |
|
136 | - * |
|
137 | - * The principals should be passed as a list of uri's. |
|
138 | - * |
|
139 | - * @param string $principal |
|
140 | - * @param string[] $members |
|
141 | - * @throws Exception |
|
142 | - */ |
|
143 | - public function setGroupMemberSet($principal, array $members) { |
|
144 | - throw new Exception('Setting members of the group is not supported yet'); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @param string $path |
|
149 | - * @param PropPatch $propPatch |
|
150 | - * @return int |
|
151 | - */ |
|
152 | - function updatePrincipal($path, PropPatch $propPatch) { |
|
153 | - return 0; |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * @param string $prefixPath |
|
158 | - * @param array $searchProperties |
|
159 | - * @param string $test |
|
160 | - * @return array |
|
161 | - */ |
|
162 | - function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') { |
|
163 | - return []; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * @param string $uri |
|
168 | - * @param string $principalPrefix |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - function findByUri($uri, $principalPrefix) { |
|
172 | - return ''; |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * @param IGroup $group |
|
177 | - * @return array |
|
178 | - */ |
|
179 | - protected function groupToPrincipal($group) { |
|
180 | - $groupId = $group->getGID(); |
|
181 | - $principal = [ |
|
182 | - 'uri' => 'principals/groups/' . urlencode($groupId), |
|
183 | - '{DAV:}displayname' => $groupId, |
|
184 | - ]; |
|
185 | - |
|
186 | - return $principal; |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * @param IUser $user |
|
191 | - * @return array |
|
192 | - */ |
|
193 | - protected function userToPrincipal($user) { |
|
194 | - $principal = [ |
|
195 | - 'uri' => 'principals/users/' . $user->getUID(), |
|
196 | - '{DAV:}displayname' => $user->getDisplayName(), |
|
197 | - ]; |
|
198 | - |
|
199 | - return $principal; |
|
200 | - } |
|
33 | + const PRINCIPAL_PREFIX = 'principals/groups'; |
|
34 | + |
|
35 | + /** @var IGroupManager */ |
|
36 | + private $groupManager; |
|
37 | + |
|
38 | + /** |
|
39 | + * @param IGroupManager $IGroupManager |
|
40 | + */ |
|
41 | + public function __construct(IGroupManager $IGroupManager) { |
|
42 | + $this->groupManager = $IGroupManager; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * Returns a list of principals based on a prefix. |
|
47 | + * |
|
48 | + * This prefix will often contain something like 'principals'. You are only |
|
49 | + * expected to return principals that are in this base path. |
|
50 | + * |
|
51 | + * You are expected to return at least a 'uri' for every user, you can |
|
52 | + * return any additional properties if you wish so. Common properties are: |
|
53 | + * {DAV:}displayname |
|
54 | + * |
|
55 | + * @param string $prefixPath |
|
56 | + * @return string[] |
|
57 | + */ |
|
58 | + public function getPrincipalsByPrefix($prefixPath) { |
|
59 | + $principals = []; |
|
60 | + |
|
61 | + if ($prefixPath === self::PRINCIPAL_PREFIX) { |
|
62 | + foreach($this->groupManager->search('') as $user) { |
|
63 | + $principals[] = $this->groupToPrincipal($user); |
|
64 | + } |
|
65 | + } |
|
66 | + |
|
67 | + return $principals; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Returns a specific principal, specified by it's path. |
|
72 | + * The returned structure should be the exact same as from |
|
73 | + * getPrincipalsByPrefix. |
|
74 | + * |
|
75 | + * @param string $path |
|
76 | + * @return array |
|
77 | + */ |
|
78 | + public function getPrincipalByPath($path) { |
|
79 | + $elements = explode('/', $path, 3); |
|
80 | + if ($elements[0] !== 'principals') { |
|
81 | + return null; |
|
82 | + } |
|
83 | + if ($elements[1] !== 'groups') { |
|
84 | + return null; |
|
85 | + } |
|
86 | + $name = urldecode($elements[2]); |
|
87 | + $group = $this->groupManager->get($name); |
|
88 | + |
|
89 | + if (!is_null($group)) { |
|
90 | + return $this->groupToPrincipal($group); |
|
91 | + } |
|
92 | + |
|
93 | + return null; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Returns the list of members for a group-principal |
|
98 | + * |
|
99 | + * @param string $principal |
|
100 | + * @return string[] |
|
101 | + * @throws Exception |
|
102 | + */ |
|
103 | + public function getGroupMemberSet($principal) { |
|
104 | + $elements = explode('/', $principal); |
|
105 | + if ($elements[0] !== 'principals') { |
|
106 | + return []; |
|
107 | + } |
|
108 | + if ($elements[1] !== 'groups') { |
|
109 | + return []; |
|
110 | + } |
|
111 | + $name = $elements[2]; |
|
112 | + $group = $this->groupManager->get($name); |
|
113 | + |
|
114 | + if (is_null($group)) { |
|
115 | + return []; |
|
116 | + } |
|
117 | + |
|
118 | + return array_map(function($user) { |
|
119 | + return $this->userToPrincipal($user); |
|
120 | + }, $group->getUsers()); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Returns the list of groups a principal is a member of |
|
125 | + * |
|
126 | + * @param string $principal |
|
127 | + * @return array |
|
128 | + * @throws Exception |
|
129 | + */ |
|
130 | + public function getGroupMembership($principal) { |
|
131 | + return []; |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Updates the list of group members for a group principal. |
|
136 | + * |
|
137 | + * The principals should be passed as a list of uri's. |
|
138 | + * |
|
139 | + * @param string $principal |
|
140 | + * @param string[] $members |
|
141 | + * @throws Exception |
|
142 | + */ |
|
143 | + public function setGroupMemberSet($principal, array $members) { |
|
144 | + throw new Exception('Setting members of the group is not supported yet'); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @param string $path |
|
149 | + * @param PropPatch $propPatch |
|
150 | + * @return int |
|
151 | + */ |
|
152 | + function updatePrincipal($path, PropPatch $propPatch) { |
|
153 | + return 0; |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * @param string $prefixPath |
|
158 | + * @param array $searchProperties |
|
159 | + * @param string $test |
|
160 | + * @return array |
|
161 | + */ |
|
162 | + function searchPrincipals($prefixPath, array $searchProperties, $test = 'allof') { |
|
163 | + return []; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * @param string $uri |
|
168 | + * @param string $principalPrefix |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + function findByUri($uri, $principalPrefix) { |
|
172 | + return ''; |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * @param IGroup $group |
|
177 | + * @return array |
|
178 | + */ |
|
179 | + protected function groupToPrincipal($group) { |
|
180 | + $groupId = $group->getGID(); |
|
181 | + $principal = [ |
|
182 | + 'uri' => 'principals/groups/' . urlencode($groupId), |
|
183 | + '{DAV:}displayname' => $groupId, |
|
184 | + ]; |
|
185 | + |
|
186 | + return $principal; |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * @param IUser $user |
|
191 | + * @return array |
|
192 | + */ |
|
193 | + protected function userToPrincipal($user) { |
|
194 | + $principal = [ |
|
195 | + 'uri' => 'principals/users/' . $user->getUID(), |
|
196 | + '{DAV:}displayname' => $user->getDisplayName(), |
|
197 | + ]; |
|
198 | + |
|
199 | + return $principal; |
|
200 | + } |
|
201 | 201 | } |
@@ -45,114 +45,114 @@ |
||
45 | 45 | * @package OCA\DAV\Connector\Sabre |
46 | 46 | */ |
47 | 47 | class FakeLockerPlugin extends ServerPlugin { |
48 | - /** @var \Sabre\DAV\Server */ |
|
49 | - private $server; |
|
48 | + /** @var \Sabre\DAV\Server */ |
|
49 | + private $server; |
|
50 | 50 | |
51 | - /** {@inheritDoc} */ |
|
52 | - public function initialize(\Sabre\DAV\Server $server) { |
|
53 | - $this->server = $server; |
|
54 | - $this->server->on('method:LOCK', [$this, 'fakeLockProvider'], 1); |
|
55 | - $this->server->on('method:UNLOCK', [$this, 'fakeUnlockProvider'], 1); |
|
56 | - $server->on('propFind', [$this, 'propFind']); |
|
57 | - $server->on('validateTokens', [$this, 'validateTokens']); |
|
58 | - } |
|
51 | + /** {@inheritDoc} */ |
|
52 | + public function initialize(\Sabre\DAV\Server $server) { |
|
53 | + $this->server = $server; |
|
54 | + $this->server->on('method:LOCK', [$this, 'fakeLockProvider'], 1); |
|
55 | + $this->server->on('method:UNLOCK', [$this, 'fakeUnlockProvider'], 1); |
|
56 | + $server->on('propFind', [$this, 'propFind']); |
|
57 | + $server->on('validateTokens', [$this, 'validateTokens']); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Indicate that we support LOCK and UNLOCK |
|
62 | - * |
|
63 | - * @param string $path |
|
64 | - * @return string[] |
|
65 | - */ |
|
66 | - public function getHTTPMethods($path) { |
|
67 | - return [ |
|
68 | - 'LOCK', |
|
69 | - 'UNLOCK', |
|
70 | - ]; |
|
71 | - } |
|
60 | + /** |
|
61 | + * Indicate that we support LOCK and UNLOCK |
|
62 | + * |
|
63 | + * @param string $path |
|
64 | + * @return string[] |
|
65 | + */ |
|
66 | + public function getHTTPMethods($path) { |
|
67 | + return [ |
|
68 | + 'LOCK', |
|
69 | + 'UNLOCK', |
|
70 | + ]; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Indicate that we support locking |
|
75 | - * |
|
76 | - * @return integer[] |
|
77 | - */ |
|
78 | - function getFeatures() { |
|
79 | - return [2]; |
|
80 | - } |
|
73 | + /** |
|
74 | + * Indicate that we support locking |
|
75 | + * |
|
76 | + * @return integer[] |
|
77 | + */ |
|
78 | + function getFeatures() { |
|
79 | + return [2]; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Return some dummy response for PROPFIND requests with regard to locking |
|
84 | - * |
|
85 | - * @param PropFind $propFind |
|
86 | - * @param INode $node |
|
87 | - * @return void |
|
88 | - */ |
|
89 | - function propFind(PropFind $propFind, INode $node) { |
|
90 | - $propFind->handle('{DAV:}supportedlock', function() { |
|
91 | - return new SupportedLock(true); |
|
92 | - }); |
|
93 | - $propFind->handle('{DAV:}lockdiscovery', function() use ($propFind) { |
|
94 | - return new LockDiscovery([]); |
|
95 | - }); |
|
96 | - } |
|
82 | + /** |
|
83 | + * Return some dummy response for PROPFIND requests with regard to locking |
|
84 | + * |
|
85 | + * @param PropFind $propFind |
|
86 | + * @param INode $node |
|
87 | + * @return void |
|
88 | + */ |
|
89 | + function propFind(PropFind $propFind, INode $node) { |
|
90 | + $propFind->handle('{DAV:}supportedlock', function() { |
|
91 | + return new SupportedLock(true); |
|
92 | + }); |
|
93 | + $propFind->handle('{DAV:}lockdiscovery', function() use ($propFind) { |
|
94 | + return new LockDiscovery([]); |
|
95 | + }); |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Mark a locking token always as valid |
|
100 | - * |
|
101 | - * @param RequestInterface $request |
|
102 | - * @param array $conditions |
|
103 | - */ |
|
104 | - public function validateTokens(RequestInterface $request, &$conditions) { |
|
105 | - foreach($conditions as &$fileCondition) { |
|
106 | - if(isset($fileCondition['tokens'])) { |
|
107 | - foreach($fileCondition['tokens'] as &$token) { |
|
108 | - if(isset($token['token'])) { |
|
109 | - if(substr($token['token'], 0, 16) === 'opaquelocktoken:') { |
|
110 | - $token['validToken'] = true; |
|
111 | - } |
|
112 | - } |
|
113 | - } |
|
114 | - } |
|
115 | - } |
|
116 | - } |
|
98 | + /** |
|
99 | + * Mark a locking token always as valid |
|
100 | + * |
|
101 | + * @param RequestInterface $request |
|
102 | + * @param array $conditions |
|
103 | + */ |
|
104 | + public function validateTokens(RequestInterface $request, &$conditions) { |
|
105 | + foreach($conditions as &$fileCondition) { |
|
106 | + if(isset($fileCondition['tokens'])) { |
|
107 | + foreach($fileCondition['tokens'] as &$token) { |
|
108 | + if(isset($token['token'])) { |
|
109 | + if(substr($token['token'], 0, 16) === 'opaquelocktoken:') { |
|
110 | + $token['validToken'] = true; |
|
111 | + } |
|
112 | + } |
|
113 | + } |
|
114 | + } |
|
115 | + } |
|
116 | + } |
|
117 | 117 | |
118 | - /** |
|
119 | - * Fakes a successful LOCK |
|
120 | - * |
|
121 | - * @param RequestInterface $request |
|
122 | - * @param ResponseInterface $response |
|
123 | - * @return bool |
|
124 | - */ |
|
125 | - public function fakeLockProvider(RequestInterface $request, |
|
126 | - ResponseInterface $response) { |
|
118 | + /** |
|
119 | + * Fakes a successful LOCK |
|
120 | + * |
|
121 | + * @param RequestInterface $request |
|
122 | + * @param ResponseInterface $response |
|
123 | + * @return bool |
|
124 | + */ |
|
125 | + public function fakeLockProvider(RequestInterface $request, |
|
126 | + ResponseInterface $response) { |
|
127 | 127 | |
128 | - $lockInfo = new LockInfo(); |
|
129 | - $lockInfo->token = md5($request->getPath()); |
|
130 | - $lockInfo->uri = $request->getPath(); |
|
131 | - $lockInfo->depth = \Sabre\DAV\Server::DEPTH_INFINITY; |
|
132 | - $lockInfo->timeout = 1800; |
|
128 | + $lockInfo = new LockInfo(); |
|
129 | + $lockInfo->token = md5($request->getPath()); |
|
130 | + $lockInfo->uri = $request->getPath(); |
|
131 | + $lockInfo->depth = \Sabre\DAV\Server::DEPTH_INFINITY; |
|
132 | + $lockInfo->timeout = 1800; |
|
133 | 133 | |
134 | - $body = $this->server->xml->write('{DAV:}prop', [ |
|
135 | - '{DAV:}lockdiscovery' => |
|
136 | - new LockDiscovery([$lockInfo]) |
|
137 | - ]); |
|
134 | + $body = $this->server->xml->write('{DAV:}prop', [ |
|
135 | + '{DAV:}lockdiscovery' => |
|
136 | + new LockDiscovery([$lockInfo]) |
|
137 | + ]); |
|
138 | 138 | |
139 | - $response->setStatus(200); |
|
140 | - $response->setBody($body); |
|
139 | + $response->setStatus(200); |
|
140 | + $response->setBody($body); |
|
141 | 141 | |
142 | - return false; |
|
143 | - } |
|
142 | + return false; |
|
143 | + } |
|
144 | 144 | |
145 | - /** |
|
146 | - * Fakes a successful LOCK |
|
147 | - * |
|
148 | - * @param RequestInterface $request |
|
149 | - * @param ResponseInterface $response |
|
150 | - * @return bool |
|
151 | - */ |
|
152 | - public function fakeUnlockProvider(RequestInterface $request, |
|
153 | - ResponseInterface $response) { |
|
154 | - $response->setStatus(204); |
|
155 | - $response->setHeader('Content-Length', '0'); |
|
156 | - return false; |
|
157 | - } |
|
145 | + /** |
|
146 | + * Fakes a successful LOCK |
|
147 | + * |
|
148 | + * @param RequestInterface $request |
|
149 | + * @param ResponseInterface $response |
|
150 | + * @return bool |
|
151 | + */ |
|
152 | + public function fakeUnlockProvider(RequestInterface $request, |
|
153 | + ResponseInterface $response) { |
|
154 | + $response->setStatus(204); |
|
155 | + $response->setHeader('Content-Length', '0'); |
|
156 | + return false; |
|
157 | + } |
|
158 | 158 | } |
@@ -27,41 +27,41 @@ |
||
27 | 27 | * @since 12.0.0 |
28 | 28 | */ |
29 | 29 | interface ISearchQuery { |
30 | - /** |
|
31 | - * @return ISearchOperator |
|
32 | - * @since 12.0.0 |
|
33 | - */ |
|
34 | - public function getSearchOperation(); |
|
30 | + /** |
|
31 | + * @return ISearchOperator |
|
32 | + * @since 12.0.0 |
|
33 | + */ |
|
34 | + public function getSearchOperation(); |
|
35 | 35 | |
36 | - /** |
|
37 | - * Get the maximum number of results to return |
|
38 | - * |
|
39 | - * @return integer |
|
40 | - * @since 12.0.0 |
|
41 | - */ |
|
42 | - public function getLimit(); |
|
36 | + /** |
|
37 | + * Get the maximum number of results to return |
|
38 | + * |
|
39 | + * @return integer |
|
40 | + * @since 12.0.0 |
|
41 | + */ |
|
42 | + public function getLimit(); |
|
43 | 43 | |
44 | - /** |
|
45 | - * Get the offset for returned results |
|
46 | - * |
|
47 | - * @return integer |
|
48 | - * @since 12.0.0 |
|
49 | - */ |
|
50 | - public function getOffset(); |
|
44 | + /** |
|
45 | + * Get the offset for returned results |
|
46 | + * |
|
47 | + * @return integer |
|
48 | + * @since 12.0.0 |
|
49 | + */ |
|
50 | + public function getOffset(); |
|
51 | 51 | |
52 | - /** |
|
53 | - * The fields and directions to order by |
|
54 | - * |
|
55 | - * @return ISearchOrder[] |
|
56 | - * @since 12.0.0 |
|
57 | - */ |
|
58 | - public function getOrder(); |
|
52 | + /** |
|
53 | + * The fields and directions to order by |
|
54 | + * |
|
55 | + * @return ISearchOrder[] |
|
56 | + * @since 12.0.0 |
|
57 | + */ |
|
58 | + public function getOrder(); |
|
59 | 59 | |
60 | - /** |
|
61 | - * The user that issued the search |
|
62 | - * |
|
63 | - * @return IUser |
|
64 | - * @since 12.0.0 |
|
65 | - */ |
|
66 | - public function getUser(); |
|
60 | + /** |
|
61 | + * The user that issued the search |
|
62 | + * |
|
63 | + * @return IUser |
|
64 | + * @since 12.0.0 |
|
65 | + */ |
|
66 | + public function getUser(); |
|
67 | 67 | } |