@@ -24,44 +24,44 @@ |
||
24 | 24 | use OCP\Files\Search\ISearchComparison; |
25 | 25 | |
26 | 26 | class SearchComparison implements ISearchComparison { |
27 | - /** @var string */ |
|
28 | - private $type; |
|
29 | - /** @var string */ |
|
30 | - private $field; |
|
31 | - /** @var string|integer|\DateTime */ |
|
32 | - private $value; |
|
27 | + /** @var string */ |
|
28 | + private $type; |
|
29 | + /** @var string */ |
|
30 | + private $field; |
|
31 | + /** @var string|integer|\DateTime */ |
|
32 | + private $value; |
|
33 | 33 | |
34 | - /** |
|
35 | - * SearchComparison constructor. |
|
36 | - * |
|
37 | - * @param string $type |
|
38 | - * @param string $field |
|
39 | - * @param \DateTime|int|string $value |
|
40 | - */ |
|
41 | - public function __construct($type, $field, $value) { |
|
42 | - $this->type = $type; |
|
43 | - $this->field = $field; |
|
44 | - $this->value = $value; |
|
45 | - } |
|
34 | + /** |
|
35 | + * SearchComparison constructor. |
|
36 | + * |
|
37 | + * @param string $type |
|
38 | + * @param string $field |
|
39 | + * @param \DateTime|int|string $value |
|
40 | + */ |
|
41 | + public function __construct($type, $field, $value) { |
|
42 | + $this->type = $type; |
|
43 | + $this->field = $field; |
|
44 | + $this->value = $value; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @return string |
|
49 | - */ |
|
50 | - public function getType() { |
|
51 | - return $this->type; |
|
52 | - } |
|
47 | + /** |
|
48 | + * @return string |
|
49 | + */ |
|
50 | + public function getType() { |
|
51 | + return $this->type; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - public function getField() { |
|
58 | - return $this->field; |
|
59 | - } |
|
54 | + /** |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + public function getField() { |
|
58 | + return $this->field; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @return \DateTime|int|string |
|
63 | - */ |
|
64 | - public function getValue() { |
|
65 | - return $this->value; |
|
66 | - } |
|
61 | + /** |
|
62 | + * @return \DateTime|int|string |
|
63 | + */ |
|
64 | + public function getValue() { |
|
65 | + return $this->value; |
|
66 | + } |
|
67 | 67 | } |
@@ -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'); |
@@ -31,82 +31,82 @@ |
||
31 | 31 | |
32 | 32 | class ImageManager { |
33 | 33 | |
34 | - /** @var IConfig */ |
|
35 | - private $config; |
|
36 | - /** @var IAppData */ |
|
37 | - private $appData; |
|
34 | + /** @var IConfig */ |
|
35 | + private $config; |
|
36 | + /** @var IAppData */ |
|
37 | + private $appData; |
|
38 | 38 | |
39 | - /** |
|
40 | - * ImageManager constructor. |
|
41 | - * |
|
42 | - * @param IConfig $config |
|
43 | - * @param IAppData $appData |
|
44 | - */ |
|
45 | - public function __construct(IConfig $config, |
|
46 | - IAppData $appData |
|
47 | - ) { |
|
48 | - $this->config = $config; |
|
49 | - $this->appData = $appData; |
|
50 | - } |
|
39 | + /** |
|
40 | + * ImageManager constructor. |
|
41 | + * |
|
42 | + * @param IConfig $config |
|
43 | + * @param IAppData $appData |
|
44 | + */ |
|
45 | + public function __construct(IConfig $config, |
|
46 | + IAppData $appData |
|
47 | + ) { |
|
48 | + $this->config = $config; |
|
49 | + $this->appData = $appData; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Get folder for current theming files |
|
54 | - * |
|
55 | - * @return \OCP\Files\SimpleFS\ISimpleFolder |
|
56 | - * @throws NotPermittedException |
|
57 | - * @throws \RuntimeException |
|
58 | - */ |
|
59 | - public function getCacheFolder() { |
|
60 | - $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
61 | - try { |
|
62 | - $folder = $this->appData->getFolder($cacheBusterValue); |
|
63 | - } catch (NotFoundException $e) { |
|
64 | - $folder = $this->appData->newFolder($cacheBusterValue); |
|
65 | - $this->cleanup(); |
|
66 | - } |
|
67 | - return $folder; |
|
68 | - } |
|
52 | + /** |
|
53 | + * Get folder for current theming files |
|
54 | + * |
|
55 | + * @return \OCP\Files\SimpleFS\ISimpleFolder |
|
56 | + * @throws NotPermittedException |
|
57 | + * @throws \RuntimeException |
|
58 | + */ |
|
59 | + public function getCacheFolder() { |
|
60 | + $cacheBusterValue = $this->config->getAppValue('theming', 'cachebuster', '0'); |
|
61 | + try { |
|
62 | + $folder = $this->appData->getFolder($cacheBusterValue); |
|
63 | + } catch (NotFoundException $e) { |
|
64 | + $folder = $this->appData->newFolder($cacheBusterValue); |
|
65 | + $this->cleanup(); |
|
66 | + } |
|
67 | + return $folder; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Get a file from AppData |
|
72 | - * |
|
73 | - * @param string $filename |
|
74 | - * @throws NotFoundException |
|
75 | - * @return \OCP\Files\SimpleFS\ISimpleFile |
|
76 | - */ |
|
77 | - public function getCachedImage($filename) { |
|
78 | - $currentFolder = $this->getCacheFolder(); |
|
79 | - return $currentFolder->getFile($filename); |
|
80 | - } |
|
70 | + /** |
|
71 | + * Get a file from AppData |
|
72 | + * |
|
73 | + * @param string $filename |
|
74 | + * @throws NotFoundException |
|
75 | + * @return \OCP\Files\SimpleFS\ISimpleFile |
|
76 | + */ |
|
77 | + public function getCachedImage($filename) { |
|
78 | + $currentFolder = $this->getCacheFolder(); |
|
79 | + return $currentFolder->getFile($filename); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Store a file for theming in AppData |
|
84 | - * |
|
85 | - * @param string $filename |
|
86 | - * @param string $data |
|
87 | - * @return \OCP\Files\SimpleFS\ISimpleFile |
|
88 | - */ |
|
89 | - public function setCachedImage($filename, $data) { |
|
90 | - $currentFolder = $this->getCacheFolder(); |
|
91 | - if ($currentFolder->fileExists($filename)) { |
|
92 | - $file = $currentFolder->getFile($filename); |
|
93 | - } else { |
|
94 | - $file = $currentFolder->newFile($filename); |
|
95 | - } |
|
96 | - $file->putContent($data); |
|
97 | - return $file; |
|
98 | - } |
|
82 | + /** |
|
83 | + * Store a file for theming in AppData |
|
84 | + * |
|
85 | + * @param string $filename |
|
86 | + * @param string $data |
|
87 | + * @return \OCP\Files\SimpleFS\ISimpleFile |
|
88 | + */ |
|
89 | + public function setCachedImage($filename, $data) { |
|
90 | + $currentFolder = $this->getCacheFolder(); |
|
91 | + if ($currentFolder->fileExists($filename)) { |
|
92 | + $file = $currentFolder->getFile($filename); |
|
93 | + } else { |
|
94 | + $file = $currentFolder->newFile($filename); |
|
95 | + } |
|
96 | + $file->putContent($data); |
|
97 | + return $file; |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * remove cached files that are not required any longer |
|
102 | - */ |
|
103 | - public function cleanup() { |
|
104 | - $currentFolder = $this->getCacheFolder(); |
|
105 | - $folders = $this->appData->getDirectoryListing(); |
|
106 | - foreach ($folders as $folder) { |
|
107 | - if ($folder->getName() !== 'images' && $folder->getName() !== $currentFolder->getName()) { |
|
108 | - $folder->delete(); |
|
109 | - } |
|
110 | - } |
|
111 | - } |
|
100 | + /** |
|
101 | + * remove cached files that are not required any longer |
|
102 | + */ |
|
103 | + public function cleanup() { |
|
104 | + $currentFolder = $this->getCacheFolder(); |
|
105 | + $folders = $this->appData->getDirectoryListing(); |
|
106 | + foreach ($folders as $folder) { |
|
107 | + if ($folder->getName() !== 'images' && $folder->getName() !== $currentFolder->getName()) { |
|
108 | + $folder->delete(); |
|
109 | + } |
|
110 | + } |
|
111 | + } |
|
112 | 112 | } |
@@ -37,179 +37,179 @@ |
||
37 | 37 | */ |
38 | 38 | class AddressBook extends \Sabre\CardDAV\AddressBook implements IShareable { |
39 | 39 | |
40 | - /** |
|
41 | - * AddressBook constructor. |
|
42 | - * |
|
43 | - * @param BackendInterface $carddavBackend |
|
44 | - * @param array $addressBookInfo |
|
45 | - * @param IL10N $l10n |
|
46 | - */ |
|
47 | - public function __construct(BackendInterface $carddavBackend, array $addressBookInfo, IL10N $l10n) { |
|
48 | - parent::__construct($carddavBackend, $addressBookInfo); |
|
49 | - |
|
50 | - if ($this->addressBookInfo['{DAV:}displayname'] === CardDavBackend::PERSONAL_ADDRESSBOOK_NAME && |
|
51 | - $this->getName() === CardDavBackend::PERSONAL_ADDRESSBOOK_URI) { |
|
52 | - $this->addressBookInfo['{DAV:}displayname'] = $l10n->t('Contacts'); |
|
53 | - } |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Updates the list of shares. |
|
58 | - * |
|
59 | - * The first array is a list of people that are to be added to the |
|
60 | - * addressbook. |
|
61 | - * |
|
62 | - * Every element in the add array has the following properties: |
|
63 | - * * href - A url. Usually a mailto: address |
|
64 | - * * commonName - Usually a first and last name, or false |
|
65 | - * * summary - A description of the share, can also be false |
|
66 | - * * readOnly - A boolean value |
|
67 | - * |
|
68 | - * Every element in the remove array is just the address string. |
|
69 | - * |
|
70 | - * @param array $add |
|
71 | - * @param array $remove |
|
72 | - * @return void |
|
73 | - * @throws Forbidden |
|
74 | - */ |
|
75 | - public function updateShares(array $add, array $remove) { |
|
76 | - if ($this->isShared()) { |
|
77 | - throw new Forbidden(); |
|
78 | - } |
|
79 | - $this->carddavBackend->updateShares($this, $add, $remove); |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Returns the list of people whom this addressbook is shared with. |
|
84 | - * |
|
85 | - * Every element in this array should have the following properties: |
|
86 | - * * href - Often a mailto: address |
|
87 | - * * commonName - Optional, for example a first + last name |
|
88 | - * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
89 | - * * readOnly - boolean |
|
90 | - * * summary - Optional, a description for the share |
|
91 | - * |
|
92 | - * @return array |
|
93 | - */ |
|
94 | - public function getShares() { |
|
95 | - if ($this->isShared()) { |
|
96 | - return []; |
|
97 | - } |
|
98 | - return $this->carddavBackend->getShares($this->getResourceId()); |
|
99 | - } |
|
100 | - |
|
101 | - public function getACL() { |
|
102 | - $acl = [ |
|
103 | - [ |
|
104 | - 'privilege' => '{DAV:}read', |
|
105 | - 'principal' => $this->getOwner(), |
|
106 | - 'protected' => true, |
|
107 | - ]]; |
|
108 | - $acl[] = [ |
|
109 | - 'privilege' => '{DAV:}write', |
|
110 | - 'principal' => $this->getOwner(), |
|
111 | - 'protected' => true, |
|
112 | - ]; |
|
113 | - if ($this->getOwner() !== parent::getOwner()) { |
|
114 | - $acl[] = [ |
|
115 | - 'privilege' => '{DAV:}read', |
|
116 | - 'principal' => parent::getOwner(), |
|
117 | - 'protected' => true, |
|
118 | - ]; |
|
119 | - if ($this->canWrite()) { |
|
120 | - $acl[] = [ |
|
121 | - 'privilege' => '{DAV:}write', |
|
122 | - 'principal' => parent::getOwner(), |
|
123 | - 'protected' => true, |
|
124 | - ]; |
|
125 | - } |
|
126 | - } |
|
127 | - if ($this->getOwner() === 'principals/system/system') { |
|
128 | - $acl[] = [ |
|
129 | - 'privilege' => '{DAV:}read', |
|
130 | - 'principal' => '{DAV:}authenticated', |
|
131 | - 'protected' => true, |
|
132 | - ]; |
|
133 | - } |
|
134 | - |
|
135 | - if ($this->isShared()) { |
|
136 | - return $acl; |
|
137 | - } |
|
138 | - |
|
139 | - return $this->carddavBackend->applyShareAcl($this->getResourceId(), $acl); |
|
140 | - } |
|
141 | - |
|
142 | - public function getChildACL() { |
|
143 | - return $this->getACL(); |
|
144 | - } |
|
145 | - |
|
146 | - public function getChild($name) { |
|
147 | - |
|
148 | - $obj = $this->carddavBackend->getCard($this->addressBookInfo['id'], $name); |
|
149 | - if (!$obj) { |
|
150 | - throw new NotFound('Card not found'); |
|
151 | - } |
|
152 | - $obj['acl'] = $this->getChildACL(); |
|
153 | - return new Card($this->carddavBackend, $this->addressBookInfo, $obj); |
|
154 | - |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * @return int |
|
159 | - */ |
|
160 | - public function getResourceId() { |
|
161 | - return $this->addressBookInfo['id']; |
|
162 | - } |
|
163 | - |
|
164 | - public function getOwner() { |
|
165 | - if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
166 | - return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal']; |
|
167 | - } |
|
168 | - return parent::getOwner(); |
|
169 | - } |
|
170 | - |
|
171 | - public function delete() { |
|
172 | - if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
173 | - $principal = 'principal:' . parent::getOwner(); |
|
174 | - $shares = $this->carddavBackend->getShares($this->getResourceId()); |
|
175 | - $shares = array_filter($shares, function($share) use ($principal){ |
|
176 | - return $share['href'] === $principal; |
|
177 | - }); |
|
178 | - if (empty($shares)) { |
|
179 | - throw new Forbidden(); |
|
180 | - } |
|
181 | - |
|
182 | - $this->carddavBackend->updateShares($this, [], [ |
|
183 | - 'href' => $principal |
|
184 | - ]); |
|
185 | - return; |
|
186 | - } |
|
187 | - parent::delete(); |
|
188 | - } |
|
189 | - |
|
190 | - public function propPatch(PropPatch $propPatch) { |
|
191 | - if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
192 | - throw new Forbidden(); |
|
193 | - } |
|
194 | - parent::propPatch($propPatch); |
|
195 | - } |
|
196 | - |
|
197 | - public function getContactsGroups() { |
|
198 | - return $this->carddavBackend->collectCardProperties($this->getResourceId(), 'CATEGORIES'); |
|
199 | - } |
|
200 | - |
|
201 | - private function isShared() { |
|
202 | - if (!isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
203 | - return false; |
|
204 | - } |
|
205 | - |
|
206 | - return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal'] !== $this->addressBookInfo['principaluri']; |
|
207 | - } |
|
208 | - |
|
209 | - private function canWrite() { |
|
210 | - if (isset($this->addressBookInfo['{http://owncloud.org/ns}read-only'])) { |
|
211 | - return !$this->addressBookInfo['{http://owncloud.org/ns}read-only']; |
|
212 | - } |
|
213 | - return true; |
|
214 | - } |
|
40 | + /** |
|
41 | + * AddressBook constructor. |
|
42 | + * |
|
43 | + * @param BackendInterface $carddavBackend |
|
44 | + * @param array $addressBookInfo |
|
45 | + * @param IL10N $l10n |
|
46 | + */ |
|
47 | + public function __construct(BackendInterface $carddavBackend, array $addressBookInfo, IL10N $l10n) { |
|
48 | + parent::__construct($carddavBackend, $addressBookInfo); |
|
49 | + |
|
50 | + if ($this->addressBookInfo['{DAV:}displayname'] === CardDavBackend::PERSONAL_ADDRESSBOOK_NAME && |
|
51 | + $this->getName() === CardDavBackend::PERSONAL_ADDRESSBOOK_URI) { |
|
52 | + $this->addressBookInfo['{DAV:}displayname'] = $l10n->t('Contacts'); |
|
53 | + } |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Updates the list of shares. |
|
58 | + * |
|
59 | + * The first array is a list of people that are to be added to the |
|
60 | + * addressbook. |
|
61 | + * |
|
62 | + * Every element in the add array has the following properties: |
|
63 | + * * href - A url. Usually a mailto: address |
|
64 | + * * commonName - Usually a first and last name, or false |
|
65 | + * * summary - A description of the share, can also be false |
|
66 | + * * readOnly - A boolean value |
|
67 | + * |
|
68 | + * Every element in the remove array is just the address string. |
|
69 | + * |
|
70 | + * @param array $add |
|
71 | + * @param array $remove |
|
72 | + * @return void |
|
73 | + * @throws Forbidden |
|
74 | + */ |
|
75 | + public function updateShares(array $add, array $remove) { |
|
76 | + if ($this->isShared()) { |
|
77 | + throw new Forbidden(); |
|
78 | + } |
|
79 | + $this->carddavBackend->updateShares($this, $add, $remove); |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Returns the list of people whom this addressbook is shared with. |
|
84 | + * |
|
85 | + * Every element in this array should have the following properties: |
|
86 | + * * href - Often a mailto: address |
|
87 | + * * commonName - Optional, for example a first + last name |
|
88 | + * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
89 | + * * readOnly - boolean |
|
90 | + * * summary - Optional, a description for the share |
|
91 | + * |
|
92 | + * @return array |
|
93 | + */ |
|
94 | + public function getShares() { |
|
95 | + if ($this->isShared()) { |
|
96 | + return []; |
|
97 | + } |
|
98 | + return $this->carddavBackend->getShares($this->getResourceId()); |
|
99 | + } |
|
100 | + |
|
101 | + public function getACL() { |
|
102 | + $acl = [ |
|
103 | + [ |
|
104 | + 'privilege' => '{DAV:}read', |
|
105 | + 'principal' => $this->getOwner(), |
|
106 | + 'protected' => true, |
|
107 | + ]]; |
|
108 | + $acl[] = [ |
|
109 | + 'privilege' => '{DAV:}write', |
|
110 | + 'principal' => $this->getOwner(), |
|
111 | + 'protected' => true, |
|
112 | + ]; |
|
113 | + if ($this->getOwner() !== parent::getOwner()) { |
|
114 | + $acl[] = [ |
|
115 | + 'privilege' => '{DAV:}read', |
|
116 | + 'principal' => parent::getOwner(), |
|
117 | + 'protected' => true, |
|
118 | + ]; |
|
119 | + if ($this->canWrite()) { |
|
120 | + $acl[] = [ |
|
121 | + 'privilege' => '{DAV:}write', |
|
122 | + 'principal' => parent::getOwner(), |
|
123 | + 'protected' => true, |
|
124 | + ]; |
|
125 | + } |
|
126 | + } |
|
127 | + if ($this->getOwner() === 'principals/system/system') { |
|
128 | + $acl[] = [ |
|
129 | + 'privilege' => '{DAV:}read', |
|
130 | + 'principal' => '{DAV:}authenticated', |
|
131 | + 'protected' => true, |
|
132 | + ]; |
|
133 | + } |
|
134 | + |
|
135 | + if ($this->isShared()) { |
|
136 | + return $acl; |
|
137 | + } |
|
138 | + |
|
139 | + return $this->carddavBackend->applyShareAcl($this->getResourceId(), $acl); |
|
140 | + } |
|
141 | + |
|
142 | + public function getChildACL() { |
|
143 | + return $this->getACL(); |
|
144 | + } |
|
145 | + |
|
146 | + public function getChild($name) { |
|
147 | + |
|
148 | + $obj = $this->carddavBackend->getCard($this->addressBookInfo['id'], $name); |
|
149 | + if (!$obj) { |
|
150 | + throw new NotFound('Card not found'); |
|
151 | + } |
|
152 | + $obj['acl'] = $this->getChildACL(); |
|
153 | + return new Card($this->carddavBackend, $this->addressBookInfo, $obj); |
|
154 | + |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * @return int |
|
159 | + */ |
|
160 | + public function getResourceId() { |
|
161 | + return $this->addressBookInfo['id']; |
|
162 | + } |
|
163 | + |
|
164 | + public function getOwner() { |
|
165 | + if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
166 | + return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal']; |
|
167 | + } |
|
168 | + return parent::getOwner(); |
|
169 | + } |
|
170 | + |
|
171 | + public function delete() { |
|
172 | + if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
173 | + $principal = 'principal:' . parent::getOwner(); |
|
174 | + $shares = $this->carddavBackend->getShares($this->getResourceId()); |
|
175 | + $shares = array_filter($shares, function($share) use ($principal){ |
|
176 | + return $share['href'] === $principal; |
|
177 | + }); |
|
178 | + if (empty($shares)) { |
|
179 | + throw new Forbidden(); |
|
180 | + } |
|
181 | + |
|
182 | + $this->carddavBackend->updateShares($this, [], [ |
|
183 | + 'href' => $principal |
|
184 | + ]); |
|
185 | + return; |
|
186 | + } |
|
187 | + parent::delete(); |
|
188 | + } |
|
189 | + |
|
190 | + public function propPatch(PropPatch $propPatch) { |
|
191 | + if (isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
192 | + throw new Forbidden(); |
|
193 | + } |
|
194 | + parent::propPatch($propPatch); |
|
195 | + } |
|
196 | + |
|
197 | + public function getContactsGroups() { |
|
198 | + return $this->carddavBackend->collectCardProperties($this->getResourceId(), 'CATEGORIES'); |
|
199 | + } |
|
200 | + |
|
201 | + private function isShared() { |
|
202 | + if (!isset($this->addressBookInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
203 | + return false; |
|
204 | + } |
|
205 | + |
|
206 | + return $this->addressBookInfo['{http://owncloud.org/ns}owner-principal'] !== $this->addressBookInfo['principaluri']; |
|
207 | + } |
|
208 | + |
|
209 | + private function canWrite() { |
|
210 | + if (isset($this->addressBookInfo['{http://owncloud.org/ns}read-only'])) { |
|
211 | + return !$this->addressBookInfo['{http://owncloud.org/ns}read-only']; |
|
212 | + } |
|
213 | + return true; |
|
214 | + } |
|
215 | 215 | } |
@@ -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 | } |