@@ -275,7 +275,7 @@ |
||
275 | 275 | return $this->getAppValues($app); |
276 | 276 | } else { |
277 | 277 | $appIds = $this->getApps(); |
278 | - $values = array_map(function ($appId) use ($key) { |
|
278 | + $values = array_map(function($appId) use ($key) { |
|
279 | 279 | return isset($this->cache[$appId][$key]) ? $this->cache[$appId][$key] : null; |
280 | 280 | }, $appIds); |
281 | 281 | $result = array_combine($appIds, $values); |
@@ -43,328 +43,328 @@ |
||
43 | 43 | */ |
44 | 44 | class AppConfig implements IAppConfig { |
45 | 45 | |
46 | - /** @var array[] */ |
|
47 | - protected $sensitiveValues = [ |
|
48 | - 'external' => [ |
|
49 | - '/^sites$/', |
|
50 | - ], |
|
51 | - 'spreed' => [ |
|
52 | - '/^bridge_bot_password/', |
|
53 | - '/^signaling_servers$/', |
|
54 | - '/^signaling_ticket_secret$/', |
|
55 | - '/^stun_servers$/', |
|
56 | - '/^turn_servers$/', |
|
57 | - '/^turn_server_secret$/', |
|
58 | - ], |
|
59 | - 'theming' => [ |
|
60 | - '/^imprintUrl$/', |
|
61 | - '/^privacyUrl$/', |
|
62 | - '/^slogan$/', |
|
63 | - '/^url$/', |
|
64 | - ], |
|
65 | - 'user_ldap' => [ |
|
66 | - '/^(s..)?ldap_agent_password$/', |
|
67 | - ], |
|
68 | - ]; |
|
69 | - |
|
70 | - /** @var \OCP\IDBConnection */ |
|
71 | - protected $conn; |
|
72 | - |
|
73 | - /** @var array[] */ |
|
74 | - private $cache = []; |
|
75 | - |
|
76 | - /** @var bool */ |
|
77 | - private $configLoaded = false; |
|
78 | - |
|
79 | - /** |
|
80 | - * @param IDBConnection $conn |
|
81 | - */ |
|
82 | - public function __construct(IDBConnection $conn) { |
|
83 | - $this->conn = $conn; |
|
84 | - $this->configLoaded = false; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @param string $app |
|
89 | - * @return array |
|
90 | - */ |
|
91 | - private function getAppValues($app) { |
|
92 | - $this->loadConfigValues(); |
|
93 | - |
|
94 | - if (isset($this->cache[$app])) { |
|
95 | - return $this->cache[$app]; |
|
96 | - } |
|
97 | - |
|
98 | - return []; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Get all apps using the config |
|
103 | - * |
|
104 | - * @return array an array of app ids |
|
105 | - * |
|
106 | - * This function returns a list of all apps that have at least one |
|
107 | - * entry in the appconfig table. |
|
108 | - */ |
|
109 | - public function getApps() { |
|
110 | - $this->loadConfigValues(); |
|
111 | - |
|
112 | - return $this->getSortedKeys($this->cache); |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Get the available keys for an app |
|
117 | - * |
|
118 | - * @param string $app the app we are looking for |
|
119 | - * @return array an array of key names |
|
120 | - * |
|
121 | - * This function gets all keys of an app. Please note that the values are |
|
122 | - * not returned. |
|
123 | - */ |
|
124 | - public function getKeys($app) { |
|
125 | - $this->loadConfigValues(); |
|
126 | - |
|
127 | - if (isset($this->cache[$app])) { |
|
128 | - return $this->getSortedKeys($this->cache[$app]); |
|
129 | - } |
|
130 | - |
|
131 | - return []; |
|
132 | - } |
|
133 | - |
|
134 | - public function getSortedKeys($data) { |
|
135 | - $keys = array_keys($data); |
|
136 | - sort($keys); |
|
137 | - return $keys; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Gets the config value |
|
142 | - * |
|
143 | - * @param string $app app |
|
144 | - * @param string $key key |
|
145 | - * @param string $default = null, default value if the key does not exist |
|
146 | - * @return string the value or $default |
|
147 | - * |
|
148 | - * This function gets a value from the appconfig table. If the key does |
|
149 | - * not exist the default value will be returned |
|
150 | - */ |
|
151 | - public function getValue($app, $key, $default = null) { |
|
152 | - $this->loadConfigValues(); |
|
153 | - |
|
154 | - if ($this->hasKey($app, $key)) { |
|
155 | - return $this->cache[$app][$key]; |
|
156 | - } |
|
157 | - |
|
158 | - return $default; |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * check if a key is set in the appconfig |
|
163 | - * |
|
164 | - * @param string $app |
|
165 | - * @param string $key |
|
166 | - * @return bool |
|
167 | - */ |
|
168 | - public function hasKey($app, $key) { |
|
169 | - $this->loadConfigValues(); |
|
170 | - |
|
171 | - return isset($this->cache[$app][$key]); |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Sets a value. If the key did not exist before it will be created. |
|
176 | - * |
|
177 | - * @param string $app app |
|
178 | - * @param string $key key |
|
179 | - * @param string|float|int $value value |
|
180 | - * @return bool True if the value was inserted or updated, false if the value was the same |
|
181 | - */ |
|
182 | - public function setValue($app, $key, $value) { |
|
183 | - if (!$this->hasKey($app, $key)) { |
|
184 | - $inserted = (bool) $this->conn->insertIfNotExist('*PREFIX*appconfig', [ |
|
185 | - 'appid' => $app, |
|
186 | - 'configkey' => $key, |
|
187 | - 'configvalue' => $value, |
|
188 | - ], [ |
|
189 | - 'appid', |
|
190 | - 'configkey', |
|
191 | - ]); |
|
192 | - |
|
193 | - if ($inserted) { |
|
194 | - if (!isset($this->cache[$app])) { |
|
195 | - $this->cache[$app] = []; |
|
196 | - } |
|
197 | - |
|
198 | - $this->cache[$app][$key] = $value; |
|
199 | - return true; |
|
200 | - } |
|
201 | - } |
|
202 | - |
|
203 | - $sql = $this->conn->getQueryBuilder(); |
|
204 | - $sql->update('appconfig') |
|
205 | - ->set('configvalue', $sql->createNamedParameter($value)) |
|
206 | - ->where($sql->expr()->eq('appid', $sql->createNamedParameter($app))) |
|
207 | - ->andWhere($sql->expr()->eq('configkey', $sql->createNamedParameter($key))); |
|
208 | - |
|
209 | - /* |
|
46 | + /** @var array[] */ |
|
47 | + protected $sensitiveValues = [ |
|
48 | + 'external' => [ |
|
49 | + '/^sites$/', |
|
50 | + ], |
|
51 | + 'spreed' => [ |
|
52 | + '/^bridge_bot_password/', |
|
53 | + '/^signaling_servers$/', |
|
54 | + '/^signaling_ticket_secret$/', |
|
55 | + '/^stun_servers$/', |
|
56 | + '/^turn_servers$/', |
|
57 | + '/^turn_server_secret$/', |
|
58 | + ], |
|
59 | + 'theming' => [ |
|
60 | + '/^imprintUrl$/', |
|
61 | + '/^privacyUrl$/', |
|
62 | + '/^slogan$/', |
|
63 | + '/^url$/', |
|
64 | + ], |
|
65 | + 'user_ldap' => [ |
|
66 | + '/^(s..)?ldap_agent_password$/', |
|
67 | + ], |
|
68 | + ]; |
|
69 | + |
|
70 | + /** @var \OCP\IDBConnection */ |
|
71 | + protected $conn; |
|
72 | + |
|
73 | + /** @var array[] */ |
|
74 | + private $cache = []; |
|
75 | + |
|
76 | + /** @var bool */ |
|
77 | + private $configLoaded = false; |
|
78 | + |
|
79 | + /** |
|
80 | + * @param IDBConnection $conn |
|
81 | + */ |
|
82 | + public function __construct(IDBConnection $conn) { |
|
83 | + $this->conn = $conn; |
|
84 | + $this->configLoaded = false; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @param string $app |
|
89 | + * @return array |
|
90 | + */ |
|
91 | + private function getAppValues($app) { |
|
92 | + $this->loadConfigValues(); |
|
93 | + |
|
94 | + if (isset($this->cache[$app])) { |
|
95 | + return $this->cache[$app]; |
|
96 | + } |
|
97 | + |
|
98 | + return []; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Get all apps using the config |
|
103 | + * |
|
104 | + * @return array an array of app ids |
|
105 | + * |
|
106 | + * This function returns a list of all apps that have at least one |
|
107 | + * entry in the appconfig table. |
|
108 | + */ |
|
109 | + public function getApps() { |
|
110 | + $this->loadConfigValues(); |
|
111 | + |
|
112 | + return $this->getSortedKeys($this->cache); |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Get the available keys for an app |
|
117 | + * |
|
118 | + * @param string $app the app we are looking for |
|
119 | + * @return array an array of key names |
|
120 | + * |
|
121 | + * This function gets all keys of an app. Please note that the values are |
|
122 | + * not returned. |
|
123 | + */ |
|
124 | + public function getKeys($app) { |
|
125 | + $this->loadConfigValues(); |
|
126 | + |
|
127 | + if (isset($this->cache[$app])) { |
|
128 | + return $this->getSortedKeys($this->cache[$app]); |
|
129 | + } |
|
130 | + |
|
131 | + return []; |
|
132 | + } |
|
133 | + |
|
134 | + public function getSortedKeys($data) { |
|
135 | + $keys = array_keys($data); |
|
136 | + sort($keys); |
|
137 | + return $keys; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Gets the config value |
|
142 | + * |
|
143 | + * @param string $app app |
|
144 | + * @param string $key key |
|
145 | + * @param string $default = null, default value if the key does not exist |
|
146 | + * @return string the value or $default |
|
147 | + * |
|
148 | + * This function gets a value from the appconfig table. If the key does |
|
149 | + * not exist the default value will be returned |
|
150 | + */ |
|
151 | + public function getValue($app, $key, $default = null) { |
|
152 | + $this->loadConfigValues(); |
|
153 | + |
|
154 | + if ($this->hasKey($app, $key)) { |
|
155 | + return $this->cache[$app][$key]; |
|
156 | + } |
|
157 | + |
|
158 | + return $default; |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * check if a key is set in the appconfig |
|
163 | + * |
|
164 | + * @param string $app |
|
165 | + * @param string $key |
|
166 | + * @return bool |
|
167 | + */ |
|
168 | + public function hasKey($app, $key) { |
|
169 | + $this->loadConfigValues(); |
|
170 | + |
|
171 | + return isset($this->cache[$app][$key]); |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Sets a value. If the key did not exist before it will be created. |
|
176 | + * |
|
177 | + * @param string $app app |
|
178 | + * @param string $key key |
|
179 | + * @param string|float|int $value value |
|
180 | + * @return bool True if the value was inserted or updated, false if the value was the same |
|
181 | + */ |
|
182 | + public function setValue($app, $key, $value) { |
|
183 | + if (!$this->hasKey($app, $key)) { |
|
184 | + $inserted = (bool) $this->conn->insertIfNotExist('*PREFIX*appconfig', [ |
|
185 | + 'appid' => $app, |
|
186 | + 'configkey' => $key, |
|
187 | + 'configvalue' => $value, |
|
188 | + ], [ |
|
189 | + 'appid', |
|
190 | + 'configkey', |
|
191 | + ]); |
|
192 | + |
|
193 | + if ($inserted) { |
|
194 | + if (!isset($this->cache[$app])) { |
|
195 | + $this->cache[$app] = []; |
|
196 | + } |
|
197 | + |
|
198 | + $this->cache[$app][$key] = $value; |
|
199 | + return true; |
|
200 | + } |
|
201 | + } |
|
202 | + |
|
203 | + $sql = $this->conn->getQueryBuilder(); |
|
204 | + $sql->update('appconfig') |
|
205 | + ->set('configvalue', $sql->createNamedParameter($value)) |
|
206 | + ->where($sql->expr()->eq('appid', $sql->createNamedParameter($app))) |
|
207 | + ->andWhere($sql->expr()->eq('configkey', $sql->createNamedParameter($key))); |
|
208 | + |
|
209 | + /* |
|
210 | 210 | * Only limit to the existing value for non-Oracle DBs: |
211 | 211 | * http://docs.oracle.com/cd/E11882_01/server.112/e26088/conditions002.htm#i1033286 |
212 | 212 | * > Large objects (LOBs) are not supported in comparison conditions. |
213 | 213 | */ |
214 | - if (!($this->conn instanceof OracleConnection)) { |
|
214 | + if (!($this->conn instanceof OracleConnection)) { |
|
215 | 215 | |
216 | - /* |
|
216 | + /* |
|
217 | 217 | * Only update the value when it is not the same |
218 | 218 | * Note that NULL requires some special handling. Since comparing |
219 | 219 | * against null can have special results. |
220 | 220 | */ |
221 | 221 | |
222 | - if ($value === null) { |
|
223 | - $sql->andWhere( |
|
224 | - $sql->expr()->isNotNull('configvalue') |
|
225 | - ); |
|
226 | - } else { |
|
227 | - $sql->andWhere( |
|
228 | - $sql->expr()->orX( |
|
229 | - $sql->expr()->isNull('configvalue'), |
|
230 | - $sql->expr()->neq('configvalue', $sql->createNamedParameter($value)) |
|
231 | - ) |
|
232 | - ); |
|
233 | - } |
|
234 | - } |
|
235 | - |
|
236 | - $changedRow = (bool) $sql->execute(); |
|
237 | - |
|
238 | - $this->cache[$app][$key] = $value; |
|
239 | - |
|
240 | - return $changedRow; |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * Deletes a key |
|
245 | - * |
|
246 | - * @param string $app app |
|
247 | - * @param string $key key |
|
248 | - * @return boolean |
|
249 | - */ |
|
250 | - public function deleteKey($app, $key) { |
|
251 | - $this->loadConfigValues(); |
|
252 | - |
|
253 | - $sql = $this->conn->getQueryBuilder(); |
|
254 | - $sql->delete('appconfig') |
|
255 | - ->where($sql->expr()->eq('appid', $sql->createParameter('app'))) |
|
256 | - ->andWhere($sql->expr()->eq('configkey', $sql->createParameter('configkey'))) |
|
257 | - ->setParameter('app', $app) |
|
258 | - ->setParameter('configkey', $key); |
|
259 | - $sql->execute(); |
|
260 | - |
|
261 | - unset($this->cache[$app][$key]); |
|
262 | - return false; |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * Remove app from appconfig |
|
267 | - * |
|
268 | - * @param string $app app |
|
269 | - * @return boolean |
|
270 | - * |
|
271 | - * Removes all keys in appconfig belonging to the app. |
|
272 | - */ |
|
273 | - public function deleteApp($app) { |
|
274 | - $this->loadConfigValues(); |
|
275 | - |
|
276 | - $sql = $this->conn->getQueryBuilder(); |
|
277 | - $sql->delete('appconfig') |
|
278 | - ->where($sql->expr()->eq('appid', $sql->createParameter('app'))) |
|
279 | - ->setParameter('app', $app); |
|
280 | - $sql->execute(); |
|
281 | - |
|
282 | - unset($this->cache[$app]); |
|
283 | - return false; |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * get multiple values, either the app or key can be used as wildcard by setting it to false |
|
288 | - * |
|
289 | - * @param string|false $app |
|
290 | - * @param string|false $key |
|
291 | - * @return array|false |
|
292 | - */ |
|
293 | - public function getValues($app, $key) { |
|
294 | - if (($app !== false) === ($key !== false)) { |
|
295 | - return false; |
|
296 | - } |
|
297 | - |
|
298 | - if ($key === false) { |
|
299 | - return $this->getAppValues($app); |
|
300 | - } else { |
|
301 | - $appIds = $this->getApps(); |
|
302 | - $values = array_map(function ($appId) use ($key) { |
|
303 | - return isset($this->cache[$appId][$key]) ? $this->cache[$appId][$key] : null; |
|
304 | - }, $appIds); |
|
305 | - $result = array_combine($appIds, $values); |
|
306 | - |
|
307 | - return array_filter($result); |
|
308 | - } |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * get all values of the app or and filters out sensitive data |
|
313 | - * |
|
314 | - * @param string $app |
|
315 | - * @return array |
|
316 | - */ |
|
317 | - public function getFilteredValues($app) { |
|
318 | - $values = $this->getValues($app, false); |
|
319 | - |
|
320 | - if (isset($this->sensitiveValues[$app])) { |
|
321 | - foreach ($this->sensitiveValues[$app] as $sensitiveKeyExp) { |
|
322 | - $sensitiveKeys = preg_grep($sensitiveKeyExp, array_keys($values)); |
|
323 | - foreach ($sensitiveKeys as $sensitiveKey) { |
|
324 | - $values[$sensitiveKey] = IConfig::SENSITIVE_VALUE; |
|
325 | - } |
|
326 | - } |
|
327 | - } |
|
328 | - |
|
329 | - return $values; |
|
330 | - } |
|
331 | - |
|
332 | - /** |
|
333 | - * Load all the app config values |
|
334 | - */ |
|
335 | - protected function loadConfigValues() { |
|
336 | - if ($this->configLoaded) { |
|
337 | - return; |
|
338 | - } |
|
339 | - |
|
340 | - $this->cache = []; |
|
341 | - |
|
342 | - $sql = $this->conn->getQueryBuilder(); |
|
343 | - $sql->select('*') |
|
344 | - ->from('appconfig'); |
|
345 | - $result = $sql->execute(); |
|
346 | - |
|
347 | - // we are going to store the result in memory anyway |
|
348 | - $rows = $result->fetchAll(); |
|
349 | - foreach ($rows as $row) { |
|
350 | - if (!isset($this->cache[$row['appid']])) { |
|
351 | - $this->cache[$row['appid']] = []; |
|
352 | - } |
|
353 | - |
|
354 | - $this->cache[$row['appid']][$row['configkey']] = $row['configvalue']; |
|
355 | - } |
|
356 | - $result->closeCursor(); |
|
357 | - |
|
358 | - $this->configLoaded = true; |
|
359 | - } |
|
360 | - |
|
361 | - /** |
|
362 | - * Clear all the cached app config values |
|
363 | - * |
|
364 | - * WARNING: do not use this - this is only for usage with the SCSSCacher to |
|
365 | - * clear the memory cache of the app config |
|
366 | - */ |
|
367 | - public function clearCachedConfig() { |
|
368 | - $this->configLoaded = false; |
|
369 | - } |
|
222 | + if ($value === null) { |
|
223 | + $sql->andWhere( |
|
224 | + $sql->expr()->isNotNull('configvalue') |
|
225 | + ); |
|
226 | + } else { |
|
227 | + $sql->andWhere( |
|
228 | + $sql->expr()->orX( |
|
229 | + $sql->expr()->isNull('configvalue'), |
|
230 | + $sql->expr()->neq('configvalue', $sql->createNamedParameter($value)) |
|
231 | + ) |
|
232 | + ); |
|
233 | + } |
|
234 | + } |
|
235 | + |
|
236 | + $changedRow = (bool) $sql->execute(); |
|
237 | + |
|
238 | + $this->cache[$app][$key] = $value; |
|
239 | + |
|
240 | + return $changedRow; |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * Deletes a key |
|
245 | + * |
|
246 | + * @param string $app app |
|
247 | + * @param string $key key |
|
248 | + * @return boolean |
|
249 | + */ |
|
250 | + public function deleteKey($app, $key) { |
|
251 | + $this->loadConfigValues(); |
|
252 | + |
|
253 | + $sql = $this->conn->getQueryBuilder(); |
|
254 | + $sql->delete('appconfig') |
|
255 | + ->where($sql->expr()->eq('appid', $sql->createParameter('app'))) |
|
256 | + ->andWhere($sql->expr()->eq('configkey', $sql->createParameter('configkey'))) |
|
257 | + ->setParameter('app', $app) |
|
258 | + ->setParameter('configkey', $key); |
|
259 | + $sql->execute(); |
|
260 | + |
|
261 | + unset($this->cache[$app][$key]); |
|
262 | + return false; |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * Remove app from appconfig |
|
267 | + * |
|
268 | + * @param string $app app |
|
269 | + * @return boolean |
|
270 | + * |
|
271 | + * Removes all keys in appconfig belonging to the app. |
|
272 | + */ |
|
273 | + public function deleteApp($app) { |
|
274 | + $this->loadConfigValues(); |
|
275 | + |
|
276 | + $sql = $this->conn->getQueryBuilder(); |
|
277 | + $sql->delete('appconfig') |
|
278 | + ->where($sql->expr()->eq('appid', $sql->createParameter('app'))) |
|
279 | + ->setParameter('app', $app); |
|
280 | + $sql->execute(); |
|
281 | + |
|
282 | + unset($this->cache[$app]); |
|
283 | + return false; |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * get multiple values, either the app or key can be used as wildcard by setting it to false |
|
288 | + * |
|
289 | + * @param string|false $app |
|
290 | + * @param string|false $key |
|
291 | + * @return array|false |
|
292 | + */ |
|
293 | + public function getValues($app, $key) { |
|
294 | + if (($app !== false) === ($key !== false)) { |
|
295 | + return false; |
|
296 | + } |
|
297 | + |
|
298 | + if ($key === false) { |
|
299 | + return $this->getAppValues($app); |
|
300 | + } else { |
|
301 | + $appIds = $this->getApps(); |
|
302 | + $values = array_map(function ($appId) use ($key) { |
|
303 | + return isset($this->cache[$appId][$key]) ? $this->cache[$appId][$key] : null; |
|
304 | + }, $appIds); |
|
305 | + $result = array_combine($appIds, $values); |
|
306 | + |
|
307 | + return array_filter($result); |
|
308 | + } |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * get all values of the app or and filters out sensitive data |
|
313 | + * |
|
314 | + * @param string $app |
|
315 | + * @return array |
|
316 | + */ |
|
317 | + public function getFilteredValues($app) { |
|
318 | + $values = $this->getValues($app, false); |
|
319 | + |
|
320 | + if (isset($this->sensitiveValues[$app])) { |
|
321 | + foreach ($this->sensitiveValues[$app] as $sensitiveKeyExp) { |
|
322 | + $sensitiveKeys = preg_grep($sensitiveKeyExp, array_keys($values)); |
|
323 | + foreach ($sensitiveKeys as $sensitiveKey) { |
|
324 | + $values[$sensitiveKey] = IConfig::SENSITIVE_VALUE; |
|
325 | + } |
|
326 | + } |
|
327 | + } |
|
328 | + |
|
329 | + return $values; |
|
330 | + } |
|
331 | + |
|
332 | + /** |
|
333 | + * Load all the app config values |
|
334 | + */ |
|
335 | + protected function loadConfigValues() { |
|
336 | + if ($this->configLoaded) { |
|
337 | + return; |
|
338 | + } |
|
339 | + |
|
340 | + $this->cache = []; |
|
341 | + |
|
342 | + $sql = $this->conn->getQueryBuilder(); |
|
343 | + $sql->select('*') |
|
344 | + ->from('appconfig'); |
|
345 | + $result = $sql->execute(); |
|
346 | + |
|
347 | + // we are going to store the result in memory anyway |
|
348 | + $rows = $result->fetchAll(); |
|
349 | + foreach ($rows as $row) { |
|
350 | + if (!isset($this->cache[$row['appid']])) { |
|
351 | + $this->cache[$row['appid']] = []; |
|
352 | + } |
|
353 | + |
|
354 | + $this->cache[$row['appid']][$row['configkey']] = $row['configvalue']; |
|
355 | + } |
|
356 | + $result->closeCursor(); |
|
357 | + |
|
358 | + $this->configLoaded = true; |
|
359 | + } |
|
360 | + |
|
361 | + /** |
|
362 | + * Clear all the cached app config values |
|
363 | + * |
|
364 | + * WARNING: do not use this - this is only for usage with the SCSSCacher to |
|
365 | + * clear the memory cache of the app config |
|
366 | + */ |
|
367 | + public function clearCachedConfig() { |
|
368 | + $this->configLoaded = false; |
|
369 | + } |
|
370 | 370 | } |
@@ -28,51 +28,51 @@ |
||
28 | 28 | |
29 | 29 | class MoveUpdaterStepFile implements IRepairStep { |
30 | 30 | |
31 | - /** @var \OCP\IConfig */ |
|
32 | - protected $config; |
|
31 | + /** @var \OCP\IConfig */ |
|
32 | + protected $config; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param \OCP\IConfig $config |
|
36 | - */ |
|
37 | - public function __construct($config) { |
|
38 | - $this->config = $config; |
|
39 | - } |
|
34 | + /** |
|
35 | + * @param \OCP\IConfig $config |
|
36 | + */ |
|
37 | + public function __construct($config) { |
|
38 | + $this->config = $config; |
|
39 | + } |
|
40 | 40 | |
41 | - public function getName() { |
|
42 | - return 'Move .step file of updater to backup location'; |
|
43 | - } |
|
41 | + public function getName() { |
|
42 | + return 'Move .step file of updater to backup location'; |
|
43 | + } |
|
44 | 44 | |
45 | - public function run(IOutput $output) { |
|
46 | - $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
47 | - $instanceId = $this->config->getSystemValue('instanceid', null); |
|
45 | + public function run(IOutput $output) { |
|
46 | + $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
47 | + $instanceId = $this->config->getSystemValue('instanceid', null); |
|
48 | 48 | |
49 | - if (!is_string($instanceId) || empty($instanceId)) { |
|
50 | - return; |
|
51 | - } |
|
49 | + if (!is_string($instanceId) || empty($instanceId)) { |
|
50 | + return; |
|
51 | + } |
|
52 | 52 | |
53 | - $updaterFolderPath = $dataDir . '/updater-' . $instanceId; |
|
54 | - $stepFile = $updaterFolderPath . '/.step'; |
|
55 | - if (file_exists($stepFile)) { |
|
56 | - $output->info('.step file exists'); |
|
53 | + $updaterFolderPath = $dataDir . '/updater-' . $instanceId; |
|
54 | + $stepFile = $updaterFolderPath . '/.step'; |
|
55 | + if (file_exists($stepFile)) { |
|
56 | + $output->info('.step file exists'); |
|
57 | 57 | |
58 | - $previousStepFile = $updaterFolderPath . '/.step-previous-update'; |
|
58 | + $previousStepFile = $updaterFolderPath . '/.step-previous-update'; |
|
59 | 59 | |
60 | - // cleanup |
|
61 | - if (file_exists($previousStepFile)) { |
|
62 | - if (\OC_Helper::rmdirr($previousStepFile)) { |
|
63 | - $output->info('.step-previous-update removed'); |
|
64 | - } else { |
|
65 | - $output->info('.step-previous-update can\'t be removed - abort move of .step file'); |
|
66 | - return; |
|
67 | - } |
|
68 | - } |
|
60 | + // cleanup |
|
61 | + if (file_exists($previousStepFile)) { |
|
62 | + if (\OC_Helper::rmdirr($previousStepFile)) { |
|
63 | + $output->info('.step-previous-update removed'); |
|
64 | + } else { |
|
65 | + $output->info('.step-previous-update can\'t be removed - abort move of .step file'); |
|
66 | + return; |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - // move step file |
|
71 | - if (rename($stepFile, $previousStepFile)) { |
|
72 | - $output->info('.step file moved to .step-previous-update'); |
|
73 | - } else { |
|
74 | - $output->warning('.step file can\'t be moved'); |
|
75 | - } |
|
76 | - } |
|
77 | - } |
|
70 | + // move step file |
|
71 | + if (rename($stepFile, $previousStepFile)) { |
|
72 | + $output->info('.step file moved to .step-previous-update'); |
|
73 | + } else { |
|
74 | + $output->warning('.step file can\'t be moved'); |
|
75 | + } |
|
76 | + } |
|
77 | + } |
|
78 | 78 | } |
@@ -43,19 +43,19 @@ |
||
43 | 43 | } |
44 | 44 | |
45 | 45 | public function run(IOutput $output) { |
46 | - $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data'); |
|
46 | + $dataDir = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data'); |
|
47 | 47 | $instanceId = $this->config->getSystemValue('instanceid', null); |
48 | 48 | |
49 | 49 | if (!is_string($instanceId) || empty($instanceId)) { |
50 | 50 | return; |
51 | 51 | } |
52 | 52 | |
53 | - $updaterFolderPath = $dataDir . '/updater-' . $instanceId; |
|
54 | - $stepFile = $updaterFolderPath . '/.step'; |
|
53 | + $updaterFolderPath = $dataDir.'/updater-'.$instanceId; |
|
54 | + $stepFile = $updaterFolderPath.'/.step'; |
|
55 | 55 | if (file_exists($stepFile)) { |
56 | 56 | $output->info('.step file exists'); |
57 | 57 | |
58 | - $previousStepFile = $updaterFolderPath . '/.step-previous-update'; |
|
58 | + $previousStepFile = $updaterFolderPath.'/.step-previous-update'; |
|
59 | 59 | |
60 | 60 | // cleanup |
61 | 61 | if (file_exists($previousStepFile)) { |
@@ -53,7 +53,7 @@ |
||
53 | 53 | public function sort($a, $b) { |
54 | 54 | if (!isset($a[$this->key]) || !isset($b[$this->key])) { |
55 | 55 | if (!is_null($this->log)) { |
56 | - $this->log->error('Sharing dialogue: cannot sort due to ' . |
|
56 | + $this->log->error('Sharing dialogue: cannot sort due to '. |
|
57 | 57 | 'missing array key', ['app' => 'core']); |
58 | 58 | } |
59 | 59 | return 0; |
@@ -29,50 +29,50 @@ |
||
29 | 29 | use OCP\ILogger; |
30 | 30 | |
31 | 31 | class SearchResultSorter { |
32 | - private $search; |
|
33 | - private $encoding; |
|
34 | - private $key; |
|
35 | - private $log; |
|
32 | + private $search; |
|
33 | + private $encoding; |
|
34 | + private $key; |
|
35 | + private $log; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param string $search the search term as was given by the user |
|
39 | - * @param string $key the array key containing the value that should be compared |
|
40 | - * against |
|
41 | - * @param string $encoding optional, encoding to use, defaults to UTF-8 |
|
42 | - * @param ILogger $log optional |
|
43 | - */ |
|
44 | - public function __construct($search, $key, ILogger $log = null, $encoding = 'UTF-8') { |
|
45 | - $this->encoding = $encoding; |
|
46 | - $this->key = $key; |
|
47 | - $this->log = $log; |
|
48 | - $this->search = mb_strtolower($search, $this->encoding); |
|
49 | - } |
|
37 | + /** |
|
38 | + * @param string $search the search term as was given by the user |
|
39 | + * @param string $key the array key containing the value that should be compared |
|
40 | + * against |
|
41 | + * @param string $encoding optional, encoding to use, defaults to UTF-8 |
|
42 | + * @param ILogger $log optional |
|
43 | + */ |
|
44 | + public function __construct($search, $key, ILogger $log = null, $encoding = 'UTF-8') { |
|
45 | + $this->encoding = $encoding; |
|
46 | + $this->key = $key; |
|
47 | + $this->log = $log; |
|
48 | + $this->search = mb_strtolower($search, $this->encoding); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * User and Group names matching the search term at the beginning shall appear |
|
53 | - * on top of the share dialog. Following entries in alphabetical order. |
|
54 | - * Callback function for usort. http://php.net/usort |
|
55 | - */ |
|
56 | - public function sort($a, $b) { |
|
57 | - if (!isset($a[$this->key]) || !isset($b[$this->key])) { |
|
58 | - if (!is_null($this->log)) { |
|
59 | - $this->log->error('Sharing dialogue: cannot sort due to ' . |
|
60 | - 'missing array key', ['app' => 'core']); |
|
61 | - } |
|
62 | - return 0; |
|
63 | - } |
|
64 | - $nameA = mb_strtolower($a[$this->key], $this->encoding); |
|
65 | - $nameB = mb_strtolower($b[$this->key], $this->encoding); |
|
66 | - $i = mb_strpos($nameA, $this->search, 0, $this->encoding); |
|
67 | - $j = mb_strpos($nameB, $this->search, 0, $this->encoding); |
|
51 | + /** |
|
52 | + * User and Group names matching the search term at the beginning shall appear |
|
53 | + * on top of the share dialog. Following entries in alphabetical order. |
|
54 | + * Callback function for usort. http://php.net/usort |
|
55 | + */ |
|
56 | + public function sort($a, $b) { |
|
57 | + if (!isset($a[$this->key]) || !isset($b[$this->key])) { |
|
58 | + if (!is_null($this->log)) { |
|
59 | + $this->log->error('Sharing dialogue: cannot sort due to ' . |
|
60 | + 'missing array key', ['app' => 'core']); |
|
61 | + } |
|
62 | + return 0; |
|
63 | + } |
|
64 | + $nameA = mb_strtolower($a[$this->key], $this->encoding); |
|
65 | + $nameB = mb_strtolower($b[$this->key], $this->encoding); |
|
66 | + $i = mb_strpos($nameA, $this->search, 0, $this->encoding); |
|
67 | + $j = mb_strpos($nameB, $this->search, 0, $this->encoding); |
|
68 | 68 | |
69 | - if ($i === $j || $i > 0 && $j > 0) { |
|
70 | - return strcmp(mb_strtolower($nameA, $this->encoding), |
|
71 | - mb_strtolower($nameB, $this->encoding)); |
|
72 | - } elseif ($i === 0) { |
|
73 | - return -1; |
|
74 | - } else { |
|
75 | - return 1; |
|
76 | - } |
|
77 | - } |
|
69 | + if ($i === $j || $i > 0 && $j > 0) { |
|
70 | + return strcmp(mb_strtolower($nameA, $this->encoding), |
|
71 | + mb_strtolower($nameB, $this->encoding)); |
|
72 | + } elseif ($i === 0) { |
|
73 | + return -1; |
|
74 | + } else { |
|
75 | + return 1; |
|
76 | + } |
|
77 | + } |
|
78 | 78 | } |
@@ -60,7 +60,7 @@ |
||
60 | 60 | $capabilities = array_replace_recursive($capabilities, $c->getCapabilities()); |
61 | 61 | } |
62 | 62 | } else { |
63 | - throw new \InvalidArgumentException('The given Capability (' . get_class($c) . ') does not implement the ICapability interface'); |
|
63 | + throw new \InvalidArgumentException('The given Capability ('.get_class($c).') does not implement the ICapability interface'); |
|
64 | 64 | } |
65 | 65 | } |
66 | 66 |
@@ -36,58 +36,58 @@ |
||
36 | 36 | |
37 | 37 | class CapabilitiesManager { |
38 | 38 | |
39 | - /** @var \Closure[] */ |
|
40 | - private $capabilities = []; |
|
39 | + /** @var \Closure[] */ |
|
40 | + private $capabilities = []; |
|
41 | 41 | |
42 | - /** @var ILogger */ |
|
43 | - private $logger; |
|
42 | + /** @var ILogger */ |
|
43 | + private $logger; |
|
44 | 44 | |
45 | - public function __construct(ILogger $logger) { |
|
46 | - $this->logger = $logger; |
|
47 | - } |
|
45 | + public function __construct(ILogger $logger) { |
|
46 | + $this->logger = $logger; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Get an array of al the capabilities that are registered at this manager |
|
51 | - * |
|
52 | - * @param bool $public get public capabilities only |
|
53 | - * @throws \InvalidArgumentException |
|
54 | - * @return array |
|
55 | - */ |
|
56 | - public function getCapabilities(bool $public = false) : array { |
|
57 | - $capabilities = []; |
|
58 | - foreach ($this->capabilities as $capability) { |
|
59 | - try { |
|
60 | - $c = $capability(); |
|
61 | - } catch (QueryException $e) { |
|
62 | - $this->logger->logException($e, [ |
|
63 | - 'message' => 'CapabilitiesManager', |
|
64 | - 'level' => ILogger::ERROR, |
|
65 | - 'app' => 'core', |
|
66 | - ]); |
|
67 | - continue; |
|
68 | - } |
|
49 | + /** |
|
50 | + * Get an array of al the capabilities that are registered at this manager |
|
51 | + * |
|
52 | + * @param bool $public get public capabilities only |
|
53 | + * @throws \InvalidArgumentException |
|
54 | + * @return array |
|
55 | + */ |
|
56 | + public function getCapabilities(bool $public = false) : array { |
|
57 | + $capabilities = []; |
|
58 | + foreach ($this->capabilities as $capability) { |
|
59 | + try { |
|
60 | + $c = $capability(); |
|
61 | + } catch (QueryException $e) { |
|
62 | + $this->logger->logException($e, [ |
|
63 | + 'message' => 'CapabilitiesManager', |
|
64 | + 'level' => ILogger::ERROR, |
|
65 | + 'app' => 'core', |
|
66 | + ]); |
|
67 | + continue; |
|
68 | + } |
|
69 | 69 | |
70 | - if ($c instanceof ICapability) { |
|
71 | - if (!$public || $c instanceof IPublicCapability) { |
|
72 | - $capabilities = array_replace_recursive($capabilities, $c->getCapabilities()); |
|
73 | - } |
|
74 | - } else { |
|
75 | - throw new \InvalidArgumentException('The given Capability (' . get_class($c) . ') does not implement the ICapability interface'); |
|
76 | - } |
|
77 | - } |
|
70 | + if ($c instanceof ICapability) { |
|
71 | + if (!$public || $c instanceof IPublicCapability) { |
|
72 | + $capabilities = array_replace_recursive($capabilities, $c->getCapabilities()); |
|
73 | + } |
|
74 | + } else { |
|
75 | + throw new \InvalidArgumentException('The given Capability (' . get_class($c) . ') does not implement the ICapability interface'); |
|
76 | + } |
|
77 | + } |
|
78 | 78 | |
79 | - return $capabilities; |
|
80 | - } |
|
79 | + return $capabilities; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * In order to improve lazy loading a closure can be registered which will be called in case |
|
84 | - * capabilities are actually requested |
|
85 | - * |
|
86 | - * $callable has to return an instance of OCP\Capabilities\ICapability |
|
87 | - * |
|
88 | - * @param \Closure $callable |
|
89 | - */ |
|
90 | - public function registerCapability(\Closure $callable) { |
|
91 | - $this->capabilities[] = $callable; |
|
92 | - } |
|
82 | + /** |
|
83 | + * In order to improve lazy loading a closure can be registered which will be called in case |
|
84 | + * capabilities are actually requested |
|
85 | + * |
|
86 | + * $callable has to return an instance of OCP\Capabilities\ICapability |
|
87 | + * |
|
88 | + * @param \Closure $callable |
|
89 | + */ |
|
90 | + public function registerCapability(\Closure $callable) { |
|
91 | + $this->capabilities[] = $callable; |
|
92 | + } |
|
93 | 93 | } |
@@ -32,127 +32,127 @@ |
||
32 | 32 | |
33 | 33 | class Result { |
34 | 34 | |
35 | - /** @var array */ |
|
36 | - protected $data; |
|
37 | - |
|
38 | - /** @var null|string */ |
|
39 | - protected $message; |
|
40 | - |
|
41 | - /** @var int */ |
|
42 | - protected $statusCode; |
|
43 | - |
|
44 | - /** @var integer */ |
|
45 | - protected $items; |
|
46 | - |
|
47 | - /** @var integer */ |
|
48 | - protected $perPage; |
|
49 | - |
|
50 | - /** @var array */ |
|
51 | - private $headers = []; |
|
52 | - |
|
53 | - /** |
|
54 | - * create the OCS_Result object |
|
55 | - * @param mixed $data the data to return |
|
56 | - * @param int $code |
|
57 | - * @param null|string $message |
|
58 | - * @param array $headers |
|
59 | - */ |
|
60 | - public function __construct($data = null, $code = 100, $message = null, $headers = []) { |
|
61 | - if ($data === null) { |
|
62 | - $this->data = []; |
|
63 | - } elseif (!is_array($data)) { |
|
64 | - $this->data = [$this->data]; |
|
65 | - } else { |
|
66 | - $this->data = $data; |
|
67 | - } |
|
68 | - $this->statusCode = $code; |
|
69 | - $this->message = $message; |
|
70 | - $this->headers = $headers; |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * optionally set the total number of items available |
|
75 | - * @param int $items |
|
76 | - */ |
|
77 | - public function setTotalItems($items) { |
|
78 | - $this->items = $items; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * optionally set the the number of items per page |
|
83 | - * @param int $items |
|
84 | - */ |
|
85 | - public function setItemsPerPage($items) { |
|
86 | - $this->perPage = $items; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * get the status code |
|
91 | - * @return int |
|
92 | - */ |
|
93 | - public function getStatusCode() { |
|
94 | - return $this->statusCode; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * get the meta data for the result |
|
99 | - * @return array |
|
100 | - */ |
|
101 | - public function getMeta() { |
|
102 | - $meta = []; |
|
103 | - $meta['status'] = $this->succeeded() ? 'ok' : 'failure'; |
|
104 | - $meta['statuscode'] = $this->statusCode; |
|
105 | - $meta['message'] = $this->message; |
|
106 | - if (isset($this->items)) { |
|
107 | - $meta['totalitems'] = $this->items; |
|
108 | - } |
|
109 | - if (isset($this->perPage)) { |
|
110 | - $meta['itemsperpage'] = $this->perPage; |
|
111 | - } |
|
112 | - return $meta; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * get the result data |
|
117 | - * @return array |
|
118 | - */ |
|
119 | - public function getData() { |
|
120 | - return $this->data; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * return bool Whether the method succeeded |
|
125 | - * @return bool |
|
126 | - */ |
|
127 | - public function succeeded() { |
|
128 | - return ($this->statusCode == 100); |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Adds a new header to the response |
|
133 | - * @param string $name The name of the HTTP header |
|
134 | - * @param string $value The value, null will delete it |
|
135 | - * @return $this |
|
136 | - */ |
|
137 | - public function addHeader($name, $value) { |
|
138 | - $name = trim($name); // always remove leading and trailing whitespace |
|
139 | - // to be able to reliably check for security |
|
140 | - // headers |
|
141 | - |
|
142 | - if (is_null($value)) { |
|
143 | - unset($this->headers[$name]); |
|
144 | - } else { |
|
145 | - $this->headers[$name] = $value; |
|
146 | - } |
|
147 | - |
|
148 | - return $this; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Returns the set headers |
|
153 | - * @return array the headers |
|
154 | - */ |
|
155 | - public function getHeaders() { |
|
156 | - return $this->headers; |
|
157 | - } |
|
35 | + /** @var array */ |
|
36 | + protected $data; |
|
37 | + |
|
38 | + /** @var null|string */ |
|
39 | + protected $message; |
|
40 | + |
|
41 | + /** @var int */ |
|
42 | + protected $statusCode; |
|
43 | + |
|
44 | + /** @var integer */ |
|
45 | + protected $items; |
|
46 | + |
|
47 | + /** @var integer */ |
|
48 | + protected $perPage; |
|
49 | + |
|
50 | + /** @var array */ |
|
51 | + private $headers = []; |
|
52 | + |
|
53 | + /** |
|
54 | + * create the OCS_Result object |
|
55 | + * @param mixed $data the data to return |
|
56 | + * @param int $code |
|
57 | + * @param null|string $message |
|
58 | + * @param array $headers |
|
59 | + */ |
|
60 | + public function __construct($data = null, $code = 100, $message = null, $headers = []) { |
|
61 | + if ($data === null) { |
|
62 | + $this->data = []; |
|
63 | + } elseif (!is_array($data)) { |
|
64 | + $this->data = [$this->data]; |
|
65 | + } else { |
|
66 | + $this->data = $data; |
|
67 | + } |
|
68 | + $this->statusCode = $code; |
|
69 | + $this->message = $message; |
|
70 | + $this->headers = $headers; |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * optionally set the total number of items available |
|
75 | + * @param int $items |
|
76 | + */ |
|
77 | + public function setTotalItems($items) { |
|
78 | + $this->items = $items; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * optionally set the the number of items per page |
|
83 | + * @param int $items |
|
84 | + */ |
|
85 | + public function setItemsPerPage($items) { |
|
86 | + $this->perPage = $items; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * get the status code |
|
91 | + * @return int |
|
92 | + */ |
|
93 | + public function getStatusCode() { |
|
94 | + return $this->statusCode; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * get the meta data for the result |
|
99 | + * @return array |
|
100 | + */ |
|
101 | + public function getMeta() { |
|
102 | + $meta = []; |
|
103 | + $meta['status'] = $this->succeeded() ? 'ok' : 'failure'; |
|
104 | + $meta['statuscode'] = $this->statusCode; |
|
105 | + $meta['message'] = $this->message; |
|
106 | + if (isset($this->items)) { |
|
107 | + $meta['totalitems'] = $this->items; |
|
108 | + } |
|
109 | + if (isset($this->perPage)) { |
|
110 | + $meta['itemsperpage'] = $this->perPage; |
|
111 | + } |
|
112 | + return $meta; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * get the result data |
|
117 | + * @return array |
|
118 | + */ |
|
119 | + public function getData() { |
|
120 | + return $this->data; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * return bool Whether the method succeeded |
|
125 | + * @return bool |
|
126 | + */ |
|
127 | + public function succeeded() { |
|
128 | + return ($this->statusCode == 100); |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Adds a new header to the response |
|
133 | + * @param string $name The name of the HTTP header |
|
134 | + * @param string $value The value, null will delete it |
|
135 | + * @return $this |
|
136 | + */ |
|
137 | + public function addHeader($name, $value) { |
|
138 | + $name = trim($name); // always remove leading and trailing whitespace |
|
139 | + // to be able to reliably check for security |
|
140 | + // headers |
|
141 | + |
|
142 | + if (is_null($value)) { |
|
143 | + unset($this->headers[$name]); |
|
144 | + } else { |
|
145 | + $this->headers[$name] = $value; |
|
146 | + } |
|
147 | + |
|
148 | + return $this; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Returns the set headers |
|
153 | + * @return array the headers |
|
154 | + */ |
|
155 | + public function getHeaders() { |
|
156 | + return $this->headers; |
|
157 | + } |
|
158 | 158 | } |
@@ -135,7 +135,7 @@ |
||
135 | 135 | * @return $this |
136 | 136 | */ |
137 | 137 | public function addHeader($name, $value) { |
138 | - $name = trim($name); // always remove leading and trailing whitespace |
|
138 | + $name = trim($name); // always remove leading and trailing whitespace |
|
139 | 139 | // to be able to reliably check for security |
140 | 140 | // headers |
141 | 141 |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * @return int|null |
152 | 152 | */ |
153 | 153 | public function getId() { |
154 | - return isset($this->data['fileid']) ? (int) $this->data['fileid'] : null; |
|
154 | + return isset($this->data['fileid']) ? (int) $this->data['fileid'] : null; |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | public function getEtag() { |
182 | 182 | $this->updateEntryfromSubMounts(); |
183 | 183 | if (count($this->childEtags) > 0) { |
184 | - $combinedEtag = $this->data['etag'] . '::' . implode('::', $this->childEtags); |
|
184 | + $combinedEtag = $this->data['etag'].'::'.implode('::', $this->childEtags); |
|
185 | 185 | return md5($combinedEtag); |
186 | 186 | } else { |
187 | 187 | return $this->data['etag']; |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | $relativeEntryPath = substr($entryPath, strlen($this->getPath())); |
378 | 378 | // attach the permissions to propagate etag on permision changes of submounts |
379 | 379 | $permissions = isset($data['permissions']) ? $data['permissions'] : 0; |
380 | - $this->childEtags[] = $relativeEntryPath . '/' . $data['etag'] . $permissions; |
|
380 | + $this->childEtags[] = $relativeEntryPath.'/'.$data['etag'].$permissions; |
|
381 | 381 | } |
382 | 382 | } |
383 | 383 |
@@ -38,380 +38,380 @@ |
||
38 | 38 | use OCP\IUser; |
39 | 39 | |
40 | 40 | class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess { |
41 | - /** |
|
42 | - * @var array $data |
|
43 | - */ |
|
44 | - private $data; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var string $path |
|
48 | - */ |
|
49 | - private $path; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var \OC\Files\Storage\Storage $storage |
|
53 | - */ |
|
54 | - private $storage; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var string $internalPath |
|
58 | - */ |
|
59 | - private $internalPath; |
|
60 | - |
|
61 | - /** |
|
62 | - * @var \OCP\Files\Mount\IMountPoint |
|
63 | - */ |
|
64 | - private $mount; |
|
65 | - |
|
66 | - /** |
|
67 | - * @var IUser |
|
68 | - */ |
|
69 | - private $owner; |
|
70 | - |
|
71 | - /** |
|
72 | - * @var string[] |
|
73 | - */ |
|
74 | - private $childEtags = []; |
|
75 | - |
|
76 | - /** |
|
77 | - * @var IMountPoint[] |
|
78 | - */ |
|
79 | - private $subMounts = []; |
|
80 | - |
|
81 | - private $subMountsUsed = false; |
|
82 | - |
|
83 | - /** |
|
84 | - * The size of the file/folder without any sub mount |
|
85 | - * |
|
86 | - * @var int |
|
87 | - */ |
|
88 | - private $rawSize = 0; |
|
89 | - |
|
90 | - /** |
|
91 | - * @param string|boolean $path |
|
92 | - * @param Storage\Storage $storage |
|
93 | - * @param string $internalPath |
|
94 | - * @param array|ICacheEntry $data |
|
95 | - * @param \OCP\Files\Mount\IMountPoint $mount |
|
96 | - * @param \OCP\IUser|null $owner |
|
97 | - */ |
|
98 | - public function __construct($path, $storage, $internalPath, $data, $mount, $owner = null) { |
|
99 | - $this->path = $path; |
|
100 | - $this->storage = $storage; |
|
101 | - $this->internalPath = $internalPath; |
|
102 | - $this->data = $data; |
|
103 | - $this->mount = $mount; |
|
104 | - $this->owner = $owner; |
|
105 | - $this->rawSize = $this->data['size'] ?? 0; |
|
106 | - } |
|
107 | - |
|
108 | - public function offsetSet($offset, $value) { |
|
109 | - $this->data[$offset] = $value; |
|
110 | - } |
|
111 | - |
|
112 | - public function offsetExists($offset) { |
|
113 | - return isset($this->data[$offset]); |
|
114 | - } |
|
115 | - |
|
116 | - public function offsetUnset($offset) { |
|
117 | - unset($this->data[$offset]); |
|
118 | - } |
|
119 | - |
|
120 | - public function offsetGet($offset) { |
|
121 | - if ($offset === 'type') { |
|
122 | - return $this->getType(); |
|
123 | - } elseif ($offset === 'etag') { |
|
124 | - return $this->getEtag(); |
|
125 | - } elseif ($offset === 'size') { |
|
126 | - return $this->getSize(); |
|
127 | - } elseif ($offset === 'mtime') { |
|
128 | - return $this->getMTime(); |
|
129 | - } elseif ($offset === 'permissions') { |
|
130 | - return $this->getPermissions(); |
|
131 | - } elseif (isset($this->data[$offset])) { |
|
132 | - return $this->data[$offset]; |
|
133 | - } else { |
|
134 | - return null; |
|
135 | - } |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * @return string |
|
140 | - */ |
|
141 | - public function getPath() { |
|
142 | - return $this->path; |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * @return \OCP\Files\Storage |
|
147 | - */ |
|
148 | - public function getStorage() { |
|
149 | - return $this->storage; |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * @return string |
|
154 | - */ |
|
155 | - public function getInternalPath() { |
|
156 | - return $this->internalPath; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Get FileInfo ID or null in case of part file |
|
161 | - * |
|
162 | - * @return int|null |
|
163 | - */ |
|
164 | - public function getId() { |
|
165 | - return isset($this->data['fileid']) ? (int) $this->data['fileid'] : null; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - public function getMimetype() { |
|
172 | - return $this->data['mimetype']; |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * @return string |
|
177 | - */ |
|
178 | - public function getMimePart() { |
|
179 | - return $this->data['mimepart']; |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * @return string |
|
184 | - */ |
|
185 | - public function getName() { |
|
186 | - return isset($this->data['name']) ? $this->data['name'] : basename($this->getPath()); |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * @return string |
|
191 | - */ |
|
192 | - public function getEtag() { |
|
193 | - $this->updateEntryfromSubMounts(); |
|
194 | - if (count($this->childEtags) > 0) { |
|
195 | - $combinedEtag = $this->data['etag'] . '::' . implode('::', $this->childEtags); |
|
196 | - return md5($combinedEtag); |
|
197 | - } else { |
|
198 | - return $this->data['etag']; |
|
199 | - } |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * @return int |
|
204 | - */ |
|
205 | - public function getSize($includeMounts = true) { |
|
206 | - if ($includeMounts) { |
|
207 | - $this->updateEntryfromSubMounts(); |
|
208 | - return isset($this->data['size']) ? 0 + $this->data['size'] : 0; |
|
209 | - } else { |
|
210 | - return $this->rawSize; |
|
211 | - } |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * @return int |
|
216 | - */ |
|
217 | - public function getMTime() { |
|
218 | - $this->updateEntryfromSubMounts(); |
|
219 | - return (int) $this->data['mtime']; |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * @return bool |
|
224 | - */ |
|
225 | - public function isEncrypted() { |
|
226 | - return $this->data['encrypted']; |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Return the currently version used for the HMAC in the encryption app |
|
231 | - * |
|
232 | - * @return int |
|
233 | - */ |
|
234 | - public function getEncryptedVersion() { |
|
235 | - return isset($this->data['encryptedVersion']) ? (int) $this->data['encryptedVersion'] : 1; |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * @return int |
|
240 | - */ |
|
241 | - public function getPermissions() { |
|
242 | - $perms = (int) $this->data['permissions']; |
|
243 | - if (\OCP\Util::isSharingDisabledForUser() || ($this->isShared() && !\OC\Share\Share::isResharingAllowed())) { |
|
244 | - $perms = $perms & ~\OCP\Constants::PERMISSION_SHARE; |
|
245 | - } |
|
246 | - return (int) $perms; |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * @return string \OCP\Files\FileInfo::TYPE_FILE|\OCP\Files\FileInfo::TYPE_FOLDER |
|
251 | - */ |
|
252 | - public function getType() { |
|
253 | - if (!isset($this->data['type'])) { |
|
254 | - $this->data['type'] = ($this->getMimetype() === 'httpd/unix-directory') ? self::TYPE_FOLDER : self::TYPE_FILE; |
|
255 | - } |
|
256 | - return $this->data['type']; |
|
257 | - } |
|
258 | - |
|
259 | - public function getData() { |
|
260 | - return $this->data; |
|
261 | - } |
|
262 | - |
|
263 | - /** |
|
264 | - * @param int $permissions |
|
265 | - * @return bool |
|
266 | - */ |
|
267 | - protected function checkPermissions($permissions) { |
|
268 | - return ($this->getPermissions() & $permissions) === $permissions; |
|
269 | - } |
|
270 | - |
|
271 | - /** |
|
272 | - * @return bool |
|
273 | - */ |
|
274 | - public function isReadable() { |
|
275 | - return $this->checkPermissions(\OCP\Constants::PERMISSION_READ); |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * @return bool |
|
280 | - */ |
|
281 | - public function isUpdateable() { |
|
282 | - return $this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE); |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * Check whether new files or folders can be created inside this folder |
|
287 | - * |
|
288 | - * @return bool |
|
289 | - */ |
|
290 | - public function isCreatable() { |
|
291 | - return $this->checkPermissions(\OCP\Constants::PERMISSION_CREATE); |
|
292 | - } |
|
293 | - |
|
294 | - /** |
|
295 | - * @return bool |
|
296 | - */ |
|
297 | - public function isDeletable() { |
|
298 | - return $this->checkPermissions(\OCP\Constants::PERMISSION_DELETE); |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
302 | - * @return bool |
|
303 | - */ |
|
304 | - public function isShareable() { |
|
305 | - return $this->checkPermissions(\OCP\Constants::PERMISSION_SHARE); |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Check if a file or folder is shared |
|
310 | - * |
|
311 | - * @return bool |
|
312 | - */ |
|
313 | - public function isShared() { |
|
314 | - $sid = $this->getStorage()->getId(); |
|
315 | - if (!is_null($sid)) { |
|
316 | - $sid = explode(':', $sid); |
|
317 | - return ($sid[0] === 'shared'); |
|
318 | - } |
|
319 | - |
|
320 | - return false; |
|
321 | - } |
|
322 | - |
|
323 | - public function isMounted() { |
|
324 | - $storage = $this->getStorage(); |
|
325 | - if ($storage->instanceOfStorage('\OCP\Files\IHomeStorage')) { |
|
326 | - return false; |
|
327 | - } |
|
328 | - $sid = $storage->getId(); |
|
329 | - if (!is_null($sid)) { |
|
330 | - $sid = explode(':', $sid); |
|
331 | - return ($sid[0] !== 'home' and $sid[0] !== 'shared'); |
|
332 | - } |
|
333 | - |
|
334 | - return false; |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * Get the mountpoint the file belongs to |
|
339 | - * |
|
340 | - * @return \OCP\Files\Mount\IMountPoint |
|
341 | - */ |
|
342 | - public function getMountPoint() { |
|
343 | - return $this->mount; |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * Get the owner of the file |
|
348 | - * |
|
349 | - * @return \OCP\IUser |
|
350 | - */ |
|
351 | - public function getOwner() { |
|
352 | - return $this->owner; |
|
353 | - } |
|
354 | - |
|
355 | - /** |
|
356 | - * @param IMountPoint[] $mounts |
|
357 | - */ |
|
358 | - public function setSubMounts(array $mounts) { |
|
359 | - $this->subMounts = $mounts; |
|
360 | - } |
|
361 | - |
|
362 | - private function updateEntryfromSubMounts() { |
|
363 | - if ($this->subMountsUsed) { |
|
364 | - return; |
|
365 | - } |
|
366 | - $this->subMountsUsed = true; |
|
367 | - foreach ($this->subMounts as $mount) { |
|
368 | - $subStorage = $mount->getStorage(); |
|
369 | - if ($subStorage) { |
|
370 | - $subCache = $subStorage->getCache(''); |
|
371 | - $rootEntry = $subCache->get(''); |
|
372 | - $this->addSubEntry($rootEntry, $mount->getMountPoint()); |
|
373 | - } |
|
374 | - } |
|
375 | - } |
|
376 | - |
|
377 | - /** |
|
378 | - * Add a cache entry which is the child of this folder |
|
379 | - * |
|
380 | - * Sets the size, etag and size to for cross-storage childs |
|
381 | - * |
|
382 | - * @param array|ICacheEntry $data cache entry for the child |
|
383 | - * @param string $entryPath full path of the child entry |
|
384 | - */ |
|
385 | - public function addSubEntry($data, $entryPath) { |
|
386 | - $this->data['size'] += isset($data['size']) ? $data['size'] : 0; |
|
387 | - if (isset($data['mtime'])) { |
|
388 | - $this->data['mtime'] = max($this->data['mtime'], $data['mtime']); |
|
389 | - } |
|
390 | - if (isset($data['etag'])) { |
|
391 | - // prefix the etag with the relative path of the subentry to propagate etag on mount moves |
|
392 | - $relativeEntryPath = substr($entryPath, strlen($this->getPath())); |
|
393 | - // attach the permissions to propagate etag on permision changes of submounts |
|
394 | - $permissions = isset($data['permissions']) ? $data['permissions'] : 0; |
|
395 | - $this->childEtags[] = $relativeEntryPath . '/' . $data['etag'] . $permissions; |
|
396 | - } |
|
397 | - } |
|
398 | - |
|
399 | - /** |
|
400 | - * @inheritdoc |
|
401 | - */ |
|
402 | - public function getChecksum() { |
|
403 | - return $this->data['checksum']; |
|
404 | - } |
|
405 | - |
|
406 | - public function getExtension(): string { |
|
407 | - return pathinfo($this->getName(), PATHINFO_EXTENSION); |
|
408 | - } |
|
409 | - |
|
410 | - public function getCreationTime(): int { |
|
411 | - return (int) $this->data['creation_time']; |
|
412 | - } |
|
413 | - |
|
414 | - public function getUploadTime(): int { |
|
415 | - return (int) $this->data['upload_time']; |
|
416 | - } |
|
41 | + /** |
|
42 | + * @var array $data |
|
43 | + */ |
|
44 | + private $data; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var string $path |
|
48 | + */ |
|
49 | + private $path; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var \OC\Files\Storage\Storage $storage |
|
53 | + */ |
|
54 | + private $storage; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var string $internalPath |
|
58 | + */ |
|
59 | + private $internalPath; |
|
60 | + |
|
61 | + /** |
|
62 | + * @var \OCP\Files\Mount\IMountPoint |
|
63 | + */ |
|
64 | + private $mount; |
|
65 | + |
|
66 | + /** |
|
67 | + * @var IUser |
|
68 | + */ |
|
69 | + private $owner; |
|
70 | + |
|
71 | + /** |
|
72 | + * @var string[] |
|
73 | + */ |
|
74 | + private $childEtags = []; |
|
75 | + |
|
76 | + /** |
|
77 | + * @var IMountPoint[] |
|
78 | + */ |
|
79 | + private $subMounts = []; |
|
80 | + |
|
81 | + private $subMountsUsed = false; |
|
82 | + |
|
83 | + /** |
|
84 | + * The size of the file/folder without any sub mount |
|
85 | + * |
|
86 | + * @var int |
|
87 | + */ |
|
88 | + private $rawSize = 0; |
|
89 | + |
|
90 | + /** |
|
91 | + * @param string|boolean $path |
|
92 | + * @param Storage\Storage $storage |
|
93 | + * @param string $internalPath |
|
94 | + * @param array|ICacheEntry $data |
|
95 | + * @param \OCP\Files\Mount\IMountPoint $mount |
|
96 | + * @param \OCP\IUser|null $owner |
|
97 | + */ |
|
98 | + public function __construct($path, $storage, $internalPath, $data, $mount, $owner = null) { |
|
99 | + $this->path = $path; |
|
100 | + $this->storage = $storage; |
|
101 | + $this->internalPath = $internalPath; |
|
102 | + $this->data = $data; |
|
103 | + $this->mount = $mount; |
|
104 | + $this->owner = $owner; |
|
105 | + $this->rawSize = $this->data['size'] ?? 0; |
|
106 | + } |
|
107 | + |
|
108 | + public function offsetSet($offset, $value) { |
|
109 | + $this->data[$offset] = $value; |
|
110 | + } |
|
111 | + |
|
112 | + public function offsetExists($offset) { |
|
113 | + return isset($this->data[$offset]); |
|
114 | + } |
|
115 | + |
|
116 | + public function offsetUnset($offset) { |
|
117 | + unset($this->data[$offset]); |
|
118 | + } |
|
119 | + |
|
120 | + public function offsetGet($offset) { |
|
121 | + if ($offset === 'type') { |
|
122 | + return $this->getType(); |
|
123 | + } elseif ($offset === 'etag') { |
|
124 | + return $this->getEtag(); |
|
125 | + } elseif ($offset === 'size') { |
|
126 | + return $this->getSize(); |
|
127 | + } elseif ($offset === 'mtime') { |
|
128 | + return $this->getMTime(); |
|
129 | + } elseif ($offset === 'permissions') { |
|
130 | + return $this->getPermissions(); |
|
131 | + } elseif (isset($this->data[$offset])) { |
|
132 | + return $this->data[$offset]; |
|
133 | + } else { |
|
134 | + return null; |
|
135 | + } |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * @return string |
|
140 | + */ |
|
141 | + public function getPath() { |
|
142 | + return $this->path; |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * @return \OCP\Files\Storage |
|
147 | + */ |
|
148 | + public function getStorage() { |
|
149 | + return $this->storage; |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * @return string |
|
154 | + */ |
|
155 | + public function getInternalPath() { |
|
156 | + return $this->internalPath; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Get FileInfo ID or null in case of part file |
|
161 | + * |
|
162 | + * @return int|null |
|
163 | + */ |
|
164 | + public function getId() { |
|
165 | + return isset($this->data['fileid']) ? (int) $this->data['fileid'] : null; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + public function getMimetype() { |
|
172 | + return $this->data['mimetype']; |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * @return string |
|
177 | + */ |
|
178 | + public function getMimePart() { |
|
179 | + return $this->data['mimepart']; |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * @return string |
|
184 | + */ |
|
185 | + public function getName() { |
|
186 | + return isset($this->data['name']) ? $this->data['name'] : basename($this->getPath()); |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * @return string |
|
191 | + */ |
|
192 | + public function getEtag() { |
|
193 | + $this->updateEntryfromSubMounts(); |
|
194 | + if (count($this->childEtags) > 0) { |
|
195 | + $combinedEtag = $this->data['etag'] . '::' . implode('::', $this->childEtags); |
|
196 | + return md5($combinedEtag); |
|
197 | + } else { |
|
198 | + return $this->data['etag']; |
|
199 | + } |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * @return int |
|
204 | + */ |
|
205 | + public function getSize($includeMounts = true) { |
|
206 | + if ($includeMounts) { |
|
207 | + $this->updateEntryfromSubMounts(); |
|
208 | + return isset($this->data['size']) ? 0 + $this->data['size'] : 0; |
|
209 | + } else { |
|
210 | + return $this->rawSize; |
|
211 | + } |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * @return int |
|
216 | + */ |
|
217 | + public function getMTime() { |
|
218 | + $this->updateEntryfromSubMounts(); |
|
219 | + return (int) $this->data['mtime']; |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * @return bool |
|
224 | + */ |
|
225 | + public function isEncrypted() { |
|
226 | + return $this->data['encrypted']; |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Return the currently version used for the HMAC in the encryption app |
|
231 | + * |
|
232 | + * @return int |
|
233 | + */ |
|
234 | + public function getEncryptedVersion() { |
|
235 | + return isset($this->data['encryptedVersion']) ? (int) $this->data['encryptedVersion'] : 1; |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * @return int |
|
240 | + */ |
|
241 | + public function getPermissions() { |
|
242 | + $perms = (int) $this->data['permissions']; |
|
243 | + if (\OCP\Util::isSharingDisabledForUser() || ($this->isShared() && !\OC\Share\Share::isResharingAllowed())) { |
|
244 | + $perms = $perms & ~\OCP\Constants::PERMISSION_SHARE; |
|
245 | + } |
|
246 | + return (int) $perms; |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * @return string \OCP\Files\FileInfo::TYPE_FILE|\OCP\Files\FileInfo::TYPE_FOLDER |
|
251 | + */ |
|
252 | + public function getType() { |
|
253 | + if (!isset($this->data['type'])) { |
|
254 | + $this->data['type'] = ($this->getMimetype() === 'httpd/unix-directory') ? self::TYPE_FOLDER : self::TYPE_FILE; |
|
255 | + } |
|
256 | + return $this->data['type']; |
|
257 | + } |
|
258 | + |
|
259 | + public function getData() { |
|
260 | + return $this->data; |
|
261 | + } |
|
262 | + |
|
263 | + /** |
|
264 | + * @param int $permissions |
|
265 | + * @return bool |
|
266 | + */ |
|
267 | + protected function checkPermissions($permissions) { |
|
268 | + return ($this->getPermissions() & $permissions) === $permissions; |
|
269 | + } |
|
270 | + |
|
271 | + /** |
|
272 | + * @return bool |
|
273 | + */ |
|
274 | + public function isReadable() { |
|
275 | + return $this->checkPermissions(\OCP\Constants::PERMISSION_READ); |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * @return bool |
|
280 | + */ |
|
281 | + public function isUpdateable() { |
|
282 | + return $this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE); |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * Check whether new files or folders can be created inside this folder |
|
287 | + * |
|
288 | + * @return bool |
|
289 | + */ |
|
290 | + public function isCreatable() { |
|
291 | + return $this->checkPermissions(\OCP\Constants::PERMISSION_CREATE); |
|
292 | + } |
|
293 | + |
|
294 | + /** |
|
295 | + * @return bool |
|
296 | + */ |
|
297 | + public function isDeletable() { |
|
298 | + return $this->checkPermissions(\OCP\Constants::PERMISSION_DELETE); |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | + * @return bool |
|
303 | + */ |
|
304 | + public function isShareable() { |
|
305 | + return $this->checkPermissions(\OCP\Constants::PERMISSION_SHARE); |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Check if a file or folder is shared |
|
310 | + * |
|
311 | + * @return bool |
|
312 | + */ |
|
313 | + public function isShared() { |
|
314 | + $sid = $this->getStorage()->getId(); |
|
315 | + if (!is_null($sid)) { |
|
316 | + $sid = explode(':', $sid); |
|
317 | + return ($sid[0] === 'shared'); |
|
318 | + } |
|
319 | + |
|
320 | + return false; |
|
321 | + } |
|
322 | + |
|
323 | + public function isMounted() { |
|
324 | + $storage = $this->getStorage(); |
|
325 | + if ($storage->instanceOfStorage('\OCP\Files\IHomeStorage')) { |
|
326 | + return false; |
|
327 | + } |
|
328 | + $sid = $storage->getId(); |
|
329 | + if (!is_null($sid)) { |
|
330 | + $sid = explode(':', $sid); |
|
331 | + return ($sid[0] !== 'home' and $sid[0] !== 'shared'); |
|
332 | + } |
|
333 | + |
|
334 | + return false; |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * Get the mountpoint the file belongs to |
|
339 | + * |
|
340 | + * @return \OCP\Files\Mount\IMountPoint |
|
341 | + */ |
|
342 | + public function getMountPoint() { |
|
343 | + return $this->mount; |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * Get the owner of the file |
|
348 | + * |
|
349 | + * @return \OCP\IUser |
|
350 | + */ |
|
351 | + public function getOwner() { |
|
352 | + return $this->owner; |
|
353 | + } |
|
354 | + |
|
355 | + /** |
|
356 | + * @param IMountPoint[] $mounts |
|
357 | + */ |
|
358 | + public function setSubMounts(array $mounts) { |
|
359 | + $this->subMounts = $mounts; |
|
360 | + } |
|
361 | + |
|
362 | + private function updateEntryfromSubMounts() { |
|
363 | + if ($this->subMountsUsed) { |
|
364 | + return; |
|
365 | + } |
|
366 | + $this->subMountsUsed = true; |
|
367 | + foreach ($this->subMounts as $mount) { |
|
368 | + $subStorage = $mount->getStorage(); |
|
369 | + if ($subStorage) { |
|
370 | + $subCache = $subStorage->getCache(''); |
|
371 | + $rootEntry = $subCache->get(''); |
|
372 | + $this->addSubEntry($rootEntry, $mount->getMountPoint()); |
|
373 | + } |
|
374 | + } |
|
375 | + } |
|
376 | + |
|
377 | + /** |
|
378 | + * Add a cache entry which is the child of this folder |
|
379 | + * |
|
380 | + * Sets the size, etag and size to for cross-storage childs |
|
381 | + * |
|
382 | + * @param array|ICacheEntry $data cache entry for the child |
|
383 | + * @param string $entryPath full path of the child entry |
|
384 | + */ |
|
385 | + public function addSubEntry($data, $entryPath) { |
|
386 | + $this->data['size'] += isset($data['size']) ? $data['size'] : 0; |
|
387 | + if (isset($data['mtime'])) { |
|
388 | + $this->data['mtime'] = max($this->data['mtime'], $data['mtime']); |
|
389 | + } |
|
390 | + if (isset($data['etag'])) { |
|
391 | + // prefix the etag with the relative path of the subentry to propagate etag on mount moves |
|
392 | + $relativeEntryPath = substr($entryPath, strlen($this->getPath())); |
|
393 | + // attach the permissions to propagate etag on permision changes of submounts |
|
394 | + $permissions = isset($data['permissions']) ? $data['permissions'] : 0; |
|
395 | + $this->childEtags[] = $relativeEntryPath . '/' . $data['etag'] . $permissions; |
|
396 | + } |
|
397 | + } |
|
398 | + |
|
399 | + /** |
|
400 | + * @inheritdoc |
|
401 | + */ |
|
402 | + public function getChecksum() { |
|
403 | + return $this->data['checksum']; |
|
404 | + } |
|
405 | + |
|
406 | + public function getExtension(): string { |
|
407 | + return pathinfo($this->getName(), PATHINFO_EXTENSION); |
|
408 | + } |
|
409 | + |
|
410 | + public function getCreationTime(): int { |
|
411 | + return (int) $this->data['creation_time']; |
|
412 | + } |
|
413 | + |
|
414 | + public function getUploadTime(): int { |
|
415 | + return (int) $this->data['upload_time']; |
|
416 | + } |
|
417 | 417 | } |
@@ -33,53 +33,53 @@ |
||
33 | 33 | namespace OC\Files\Storage; |
34 | 34 | |
35 | 35 | class CommonTest extends \OC\Files\Storage\Common { |
36 | - /** |
|
37 | - * underlying local storage used for missing functions |
|
38 | - * @var \OC\Files\Storage\Local |
|
39 | - */ |
|
40 | - private $storage; |
|
36 | + /** |
|
37 | + * underlying local storage used for missing functions |
|
38 | + * @var \OC\Files\Storage\Local |
|
39 | + */ |
|
40 | + private $storage; |
|
41 | 41 | |
42 | - public function __construct($params) { |
|
43 | - $this->storage = new \OC\Files\Storage\Local($params); |
|
44 | - } |
|
42 | + public function __construct($params) { |
|
43 | + $this->storage = new \OC\Files\Storage\Local($params); |
|
44 | + } |
|
45 | 45 | |
46 | - public function getId() { |
|
47 | - return 'test::'.$this->storage->getId(); |
|
48 | - } |
|
49 | - public function mkdir($path) { |
|
50 | - return $this->storage->mkdir($path); |
|
51 | - } |
|
52 | - public function rmdir($path) { |
|
53 | - return $this->storage->rmdir($path); |
|
54 | - } |
|
55 | - public function opendir($path) { |
|
56 | - return $this->storage->opendir($path); |
|
57 | - } |
|
58 | - public function stat($path) { |
|
59 | - return $this->storage->stat($path); |
|
60 | - } |
|
61 | - public function filetype($path) { |
|
62 | - return @$this->storage->filetype($path); |
|
63 | - } |
|
64 | - public function isReadable($path) { |
|
65 | - return $this->storage->isReadable($path); |
|
66 | - } |
|
67 | - public function isUpdatable($path) { |
|
68 | - return $this->storage->isUpdatable($path); |
|
69 | - } |
|
70 | - public function file_exists($path) { |
|
71 | - return $this->storage->file_exists($path); |
|
72 | - } |
|
73 | - public function unlink($path) { |
|
74 | - return $this->storage->unlink($path); |
|
75 | - } |
|
76 | - public function fopen($path, $mode) { |
|
77 | - return $this->storage->fopen($path, $mode); |
|
78 | - } |
|
79 | - public function free_space($path) { |
|
80 | - return $this->storage->free_space($path); |
|
81 | - } |
|
82 | - public function touch($path, $mtime = null) { |
|
83 | - return $this->storage->touch($path, $mtime); |
|
84 | - } |
|
46 | + public function getId() { |
|
47 | + return 'test::'.$this->storage->getId(); |
|
48 | + } |
|
49 | + public function mkdir($path) { |
|
50 | + return $this->storage->mkdir($path); |
|
51 | + } |
|
52 | + public function rmdir($path) { |
|
53 | + return $this->storage->rmdir($path); |
|
54 | + } |
|
55 | + public function opendir($path) { |
|
56 | + return $this->storage->opendir($path); |
|
57 | + } |
|
58 | + public function stat($path) { |
|
59 | + return $this->storage->stat($path); |
|
60 | + } |
|
61 | + public function filetype($path) { |
|
62 | + return @$this->storage->filetype($path); |
|
63 | + } |
|
64 | + public function isReadable($path) { |
|
65 | + return $this->storage->isReadable($path); |
|
66 | + } |
|
67 | + public function isUpdatable($path) { |
|
68 | + return $this->storage->isUpdatable($path); |
|
69 | + } |
|
70 | + public function file_exists($path) { |
|
71 | + return $this->storage->file_exists($path); |
|
72 | + } |
|
73 | + public function unlink($path) { |
|
74 | + return $this->storage->unlink($path); |
|
75 | + } |
|
76 | + public function fopen($path, $mode) { |
|
77 | + return $this->storage->fopen($path, $mode); |
|
78 | + } |
|
79 | + public function free_space($path) { |
|
80 | + return $this->storage->free_space($path); |
|
81 | + } |
|
82 | + public function touch($path, $mtime = null) { |
|
83 | + return $this->storage->touch($path, $mtime); |
|
84 | + } |
|
85 | 85 | } |
@@ -29,20 +29,20 @@ |
||
29 | 29 | * local storage backend in temporary folder for testing purpose |
30 | 30 | */ |
31 | 31 | class Temporary extends Local { |
32 | - public function __construct($arguments = null) { |
|
33 | - parent::__construct(['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]); |
|
34 | - } |
|
32 | + public function __construct($arguments = null) { |
|
33 | + parent::__construct(['datadir' => \OC::$server->getTempManager()->getTemporaryFolder()]); |
|
34 | + } |
|
35 | 35 | |
36 | - public function cleanUp() { |
|
37 | - \OC_Helper::rmdirr($this->datadir); |
|
38 | - } |
|
36 | + public function cleanUp() { |
|
37 | + \OC_Helper::rmdirr($this->datadir); |
|
38 | + } |
|
39 | 39 | |
40 | - public function __destruct() { |
|
41 | - parent::__destruct(); |
|
42 | - $this->cleanUp(); |
|
43 | - } |
|
40 | + public function __destruct() { |
|
41 | + parent::__destruct(); |
|
42 | + $this->cleanUp(); |
|
43 | + } |
|
44 | 44 | |
45 | - public function getDataDir() { |
|
46 | - return $this->datadir; |
|
47 | - } |
|
45 | + public function getDataDir() { |
|
46 | + return $this->datadir; |
|
47 | + } |
|
48 | 48 | } |
@@ -50,7 +50,7 @@ |
||
50 | 50 | public function __construct($arguments) { |
51 | 51 | $this->user = $arguments['user']; |
52 | 52 | $datadir = $this->user->getHome(); |
53 | - $this->id = 'home::' . $this->user->getUID(); |
|
53 | + $this->id = 'home::'.$this->user->getUID(); |
|
54 | 54 | |
55 | 55 | parent::__construct(['datadir' => $datadir]); |
56 | 56 | } |
@@ -33,80 +33,80 @@ |
||
33 | 33 | * Specialized version of Local storage for home directory usage |
34 | 34 | */ |
35 | 35 | class Home extends Local implements \OCP\Files\IHomeStorage { |
36 | - /** |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - protected $id; |
|
36 | + /** |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + protected $id; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @var \OC\User\User $user |
|
43 | - */ |
|
44 | - protected $user; |
|
41 | + /** |
|
42 | + * @var \OC\User\User $user |
|
43 | + */ |
|
44 | + protected $user; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Construct a Home storage instance |
|
48 | - * |
|
49 | - * @param array $arguments array with "user" containing the |
|
50 | - * storage owner |
|
51 | - */ |
|
52 | - public function __construct($arguments) { |
|
53 | - $this->user = $arguments['user']; |
|
54 | - $datadir = $this->user->getHome(); |
|
55 | - $this->id = 'home::' . $this->user->getUID(); |
|
46 | + /** |
|
47 | + * Construct a Home storage instance |
|
48 | + * |
|
49 | + * @param array $arguments array with "user" containing the |
|
50 | + * storage owner |
|
51 | + */ |
|
52 | + public function __construct($arguments) { |
|
53 | + $this->user = $arguments['user']; |
|
54 | + $datadir = $this->user->getHome(); |
|
55 | + $this->id = 'home::' . $this->user->getUID(); |
|
56 | 56 | |
57 | - parent::__construct(['datadir' => $datadir]); |
|
58 | - } |
|
57 | + parent::__construct(['datadir' => $datadir]); |
|
58 | + } |
|
59 | 59 | |
60 | - public function getId() { |
|
61 | - return $this->id; |
|
62 | - } |
|
60 | + public function getId() { |
|
61 | + return $this->id; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * @return \OC\Files\Cache\HomeCache |
|
66 | - */ |
|
67 | - public function getCache($path = '', $storage = null) { |
|
68 | - if (!$storage) { |
|
69 | - $storage = $this; |
|
70 | - } |
|
71 | - if (!isset($this->cache)) { |
|
72 | - $this->cache = new \OC\Files\Cache\HomeCache($storage); |
|
73 | - } |
|
74 | - return $this->cache; |
|
75 | - } |
|
64 | + /** |
|
65 | + * @return \OC\Files\Cache\HomeCache |
|
66 | + */ |
|
67 | + public function getCache($path = '', $storage = null) { |
|
68 | + if (!$storage) { |
|
69 | + $storage = $this; |
|
70 | + } |
|
71 | + if (!isset($this->cache)) { |
|
72 | + $this->cache = new \OC\Files\Cache\HomeCache($storage); |
|
73 | + } |
|
74 | + return $this->cache; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * get a propagator instance for the cache |
|
79 | - * |
|
80 | - * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher |
|
81 | - * @return \OC\Files\Cache\Propagator |
|
82 | - */ |
|
83 | - public function getPropagator($storage = null) { |
|
84 | - if (!$storage) { |
|
85 | - $storage = $this; |
|
86 | - } |
|
87 | - if (!isset($this->propagator)) { |
|
88 | - $this->propagator = new HomePropagator($storage, \OC::$server->getDatabaseConnection()); |
|
89 | - } |
|
90 | - return $this->propagator; |
|
91 | - } |
|
77 | + /** |
|
78 | + * get a propagator instance for the cache |
|
79 | + * |
|
80 | + * @param \OC\Files\Storage\Storage (optional) the storage to pass to the watcher |
|
81 | + * @return \OC\Files\Cache\Propagator |
|
82 | + */ |
|
83 | + public function getPropagator($storage = null) { |
|
84 | + if (!$storage) { |
|
85 | + $storage = $this; |
|
86 | + } |
|
87 | + if (!isset($this->propagator)) { |
|
88 | + $this->propagator = new HomePropagator($storage, \OC::$server->getDatabaseConnection()); |
|
89 | + } |
|
90 | + return $this->propagator; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | |
94 | - /** |
|
95 | - * Returns the owner of this home storage |
|
96 | - * |
|
97 | - * @return \OC\User\User owner of this home storage |
|
98 | - */ |
|
99 | - public function getUser() { |
|
100 | - return $this->user; |
|
101 | - } |
|
94 | + /** |
|
95 | + * Returns the owner of this home storage |
|
96 | + * |
|
97 | + * @return \OC\User\User owner of this home storage |
|
98 | + */ |
|
99 | + public function getUser() { |
|
100 | + return $this->user; |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * get the owner of a path |
|
105 | - * |
|
106 | - * @param string $path The path to get the owner |
|
107 | - * @return string uid or false |
|
108 | - */ |
|
109 | - public function getOwner($path) { |
|
110 | - return $this->user->getUID(); |
|
111 | - } |
|
103 | + /** |
|
104 | + * get the owner of a path |
|
105 | + * |
|
106 | + * @param string $path The path to get the owner |
|
107 | + * @return string uid or false |
|
108 | + */ |
|
109 | + public function getOwner($path) { |
|
110 | + return $this->user->getUID(); |
|
111 | + } |
|
112 | 112 | } |