@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | |
227 | 227 | /** |
228 | 228 | * By default renders no output |
229 | - * @return null |
|
229 | + * @return string |
|
230 | 230 | * @since 6.0.0 |
231 | 231 | */ |
232 | 232 | public function render() { |
@@ -259,7 +259,7 @@ discard block |
||
259 | 259 | |
260 | 260 | /** |
261 | 261 | * Get the currently used Content-Security-Policy |
262 | - * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if |
|
262 | + * @return ContentSecurityPolicy|null Used Content-Security-Policy or null if |
|
263 | 263 | * none specified. |
264 | 264 | * @since 8.1.0 |
265 | 265 | */ |
@@ -91,8 +91,8 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function cacheFor($cacheSeconds) { |
93 | 93 | |
94 | - if($cacheSeconds > 0) { |
|
95 | - $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate'); |
|
94 | + if ($cacheSeconds > 0) { |
|
95 | + $this->addHeader('Cache-Control', 'max-age='.$cacheSeconds.', must-revalidate'); |
|
96 | 96 | } else { |
97 | 97 | $this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate'); |
98 | 98 | } |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | * @since 8.0.0 |
147 | 147 | */ |
148 | 148 | public function invalidateCookies(array $cookieNames) { |
149 | - foreach($cookieNames as $cookieName) { |
|
149 | + foreach ($cookieNames as $cookieName) { |
|
150 | 150 | $this->invalidateCookie($cookieName); |
151 | 151 | } |
152 | 152 | return $this; |
@@ -170,11 +170,11 @@ discard block |
||
170 | 170 | * @since 6.0.0 - return value was added in 7.0.0 |
171 | 171 | */ |
172 | 172 | public function addHeader($name, $value) { |
173 | - $name = trim($name); // always remove leading and trailing whitespace |
|
173 | + $name = trim($name); // always remove leading and trailing whitespace |
|
174 | 174 | // to be able to reliably check for security |
175 | 175 | // headers |
176 | 176 | |
177 | - if(is_null($value)) { |
|
177 | + if (is_null($value)) { |
|
178 | 178 | unset($this->headers[$name]); |
179 | 179 | } else { |
180 | 180 | $this->headers[$name] = $value; |
@@ -205,19 +205,19 @@ discard block |
||
205 | 205 | public function getHeaders() { |
206 | 206 | $mergeWith = []; |
207 | 207 | |
208 | - if($this->lastModified) { |
|
208 | + if ($this->lastModified) { |
|
209 | 209 | $mergeWith['Last-Modified'] = |
210 | 210 | $this->lastModified->format(\DateTime::RFC2822); |
211 | 211 | } |
212 | 212 | |
213 | 213 | // Build Content-Security-Policy and use default if none has been specified |
214 | - if(is_null($this->contentSecurityPolicy)) { |
|
214 | + if (is_null($this->contentSecurityPolicy)) { |
|
215 | 215 | $this->setContentSecurityPolicy(new ContentSecurityPolicy()); |
216 | 216 | } |
217 | 217 | $this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy(); |
218 | 218 | |
219 | - if($this->ETag) { |
|
220 | - $mergeWith['ETag'] = '"' . $this->ETag . '"'; |
|
219 | + if ($this->ETag) { |
|
220 | + $mergeWith['ETag'] = '"'.$this->ETag.'"'; |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | return array_merge($mergeWith, $this->headers); |
@@ -42,304 +42,304 @@ |
||
42 | 42 | */ |
43 | 43 | class Response { |
44 | 44 | |
45 | - /** |
|
46 | - * Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate'] |
|
47 | - * @var array |
|
48 | - */ |
|
49 | - private $headers = array( |
|
50 | - 'Cache-Control' => 'no-cache, no-store, must-revalidate' |
|
51 | - ); |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * Cookies that will be need to be constructed as header |
|
56 | - * @var array |
|
57 | - */ |
|
58 | - private $cookies = array(); |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * HTTP status code - defaults to STATUS OK |
|
63 | - * @var int |
|
64 | - */ |
|
65 | - private $status = Http::STATUS_OK; |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * Last modified date |
|
70 | - * @var \DateTime |
|
71 | - */ |
|
72 | - private $lastModified; |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * ETag |
|
77 | - * @var string |
|
78 | - */ |
|
79 | - private $ETag; |
|
80 | - |
|
81 | - /** @var ContentSecurityPolicy|null Used Content-Security-Policy */ |
|
82 | - private $contentSecurityPolicy = null; |
|
83 | - |
|
84 | - /** @var bool */ |
|
85 | - private $throttled = false; |
|
86 | - |
|
87 | - /** |
|
88 | - * Caches the response |
|
89 | - * @param int $cacheSeconds the amount of seconds that should be cached |
|
90 | - * if 0 then caching will be disabled |
|
91 | - * @return $this |
|
92 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
93 | - */ |
|
94 | - public function cacheFor($cacheSeconds) { |
|
95 | - |
|
96 | - if($cacheSeconds > 0) { |
|
97 | - $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate'); |
|
98 | - } else { |
|
99 | - $this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate'); |
|
100 | - } |
|
101 | - |
|
102 | - return $this; |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Adds a new cookie to the response |
|
107 | - * @param string $name The name of the cookie |
|
108 | - * @param string $value The value of the cookie |
|
109 | - * @param \DateTime|null $expireDate Date on that the cookie should expire, if set |
|
110 | - * to null cookie will be considered as session |
|
111 | - * cookie. |
|
112 | - * @return $this |
|
113 | - * @since 8.0.0 |
|
114 | - */ |
|
115 | - public function addCookie($name, $value, \DateTime $expireDate = null) { |
|
116 | - $this->cookies[$name] = array('value' => $value, 'expireDate' => $expireDate); |
|
117 | - return $this; |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * Set the specified cookies |
|
123 | - * @param array $cookies array('foo' => array('value' => 'bar', 'expire' => null)) |
|
124 | - * @return $this |
|
125 | - * @since 8.0.0 |
|
126 | - */ |
|
127 | - public function setCookies(array $cookies) { |
|
128 | - $this->cookies = $cookies; |
|
129 | - return $this; |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * Invalidates the specified cookie |
|
135 | - * @param string $name |
|
136 | - * @return $this |
|
137 | - * @since 8.0.0 |
|
138 | - */ |
|
139 | - public function invalidateCookie($name) { |
|
140 | - $this->addCookie($name, 'expired', new \DateTime('1971-01-01 00:00')); |
|
141 | - return $this; |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Invalidates the specified cookies |
|
146 | - * @param array $cookieNames array('foo', 'bar') |
|
147 | - * @return $this |
|
148 | - * @since 8.0.0 |
|
149 | - */ |
|
150 | - public function invalidateCookies(array $cookieNames) { |
|
151 | - foreach($cookieNames as $cookieName) { |
|
152 | - $this->invalidateCookie($cookieName); |
|
153 | - } |
|
154 | - return $this; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Returns the cookies |
|
159 | - * @return array |
|
160 | - * @since 8.0.0 |
|
161 | - */ |
|
162 | - public function getCookies() { |
|
163 | - return $this->cookies; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Adds a new header to the response that will be called before the render |
|
168 | - * function |
|
169 | - * @param string $name The name of the HTTP header |
|
170 | - * @param string $value The value, null will delete it |
|
171 | - * @return $this |
|
172 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
173 | - */ |
|
174 | - public function addHeader($name, $value) { |
|
175 | - $name = trim($name); // always remove leading and trailing whitespace |
|
176 | - // to be able to reliably check for security |
|
177 | - // headers |
|
178 | - |
|
179 | - if(is_null($value)) { |
|
180 | - unset($this->headers[$name]); |
|
181 | - } else { |
|
182 | - $this->headers[$name] = $value; |
|
183 | - } |
|
184 | - |
|
185 | - return $this; |
|
186 | - } |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * Set the headers |
|
191 | - * @param array $headers value header pairs |
|
192 | - * @return $this |
|
193 | - * @since 8.0.0 |
|
194 | - */ |
|
195 | - public function setHeaders(array $headers) { |
|
196 | - $this->headers = $headers; |
|
197 | - |
|
198 | - return $this; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * Returns the set headers |
|
204 | - * @return array the headers |
|
205 | - * @since 6.0.0 |
|
206 | - */ |
|
207 | - public function getHeaders() { |
|
208 | - $mergeWith = []; |
|
209 | - |
|
210 | - if($this->lastModified) { |
|
211 | - $mergeWith['Last-Modified'] = |
|
212 | - $this->lastModified->format(\DateTime::RFC2822); |
|
213 | - } |
|
214 | - |
|
215 | - // Build Content-Security-Policy and use default if none has been specified |
|
216 | - if(is_null($this->contentSecurityPolicy)) { |
|
217 | - $this->setContentSecurityPolicy(new ContentSecurityPolicy()); |
|
218 | - } |
|
219 | - $this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy(); |
|
220 | - |
|
221 | - if($this->ETag) { |
|
222 | - $mergeWith['ETag'] = '"' . $this->ETag . '"'; |
|
223 | - } |
|
224 | - |
|
225 | - return array_merge($mergeWith, $this->headers); |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * By default renders no output |
|
231 | - * @return null |
|
232 | - * @since 6.0.0 |
|
233 | - */ |
|
234 | - public function render() { |
|
235 | - return null; |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * Set response status |
|
241 | - * @param int $status a HTTP status code, see also the STATUS constants |
|
242 | - * @return Response Reference to this object |
|
243 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
244 | - */ |
|
245 | - public function setStatus($status) { |
|
246 | - $this->status = $status; |
|
247 | - |
|
248 | - return $this; |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * Set a Content-Security-Policy |
|
253 | - * @param EmptyContentSecurityPolicy $csp Policy to set for the response object |
|
254 | - * @return $this |
|
255 | - * @since 8.1.0 |
|
256 | - */ |
|
257 | - public function setContentSecurityPolicy(EmptyContentSecurityPolicy $csp) { |
|
258 | - $this->contentSecurityPolicy = $csp; |
|
259 | - return $this; |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Get the currently used Content-Security-Policy |
|
264 | - * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if |
|
265 | - * none specified. |
|
266 | - * @since 8.1.0 |
|
267 | - */ |
|
268 | - public function getContentSecurityPolicy() { |
|
269 | - return $this->contentSecurityPolicy; |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * Get response status |
|
275 | - * @since 6.0.0 |
|
276 | - */ |
|
277 | - public function getStatus() { |
|
278 | - return $this->status; |
|
279 | - } |
|
280 | - |
|
281 | - |
|
282 | - /** |
|
283 | - * Get the ETag |
|
284 | - * @return string the etag |
|
285 | - * @since 6.0.0 |
|
286 | - */ |
|
287 | - public function getETag() { |
|
288 | - return $this->ETag; |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * Get "last modified" date |
|
294 | - * @return \DateTime RFC2822 formatted last modified date |
|
295 | - * @since 6.0.0 |
|
296 | - */ |
|
297 | - public function getLastModified() { |
|
298 | - return $this->lastModified; |
|
299 | - } |
|
300 | - |
|
301 | - |
|
302 | - /** |
|
303 | - * Set the ETag |
|
304 | - * @param string $ETag |
|
305 | - * @return Response Reference to this object |
|
306 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
307 | - */ |
|
308 | - public function setETag($ETag) { |
|
309 | - $this->ETag = $ETag; |
|
310 | - |
|
311 | - return $this; |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * Set "last modified" date |
|
317 | - * @param \DateTime $lastModified |
|
318 | - * @return Response Reference to this object |
|
319 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
320 | - */ |
|
321 | - public function setLastModified($lastModified) { |
|
322 | - $this->lastModified = $lastModified; |
|
323 | - |
|
324 | - return $this; |
|
325 | - } |
|
326 | - |
|
327 | - /** |
|
328 | - * Marks the response as to throttle. Will be throttled when the |
|
329 | - * @BruteForceProtection annotation is added. |
|
330 | - * |
|
331 | - * @since 12.0.0 |
|
332 | - */ |
|
333 | - public function throttle() { |
|
334 | - $this->throttled = true; |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * Whether the current response is throttled. |
|
339 | - * |
|
340 | - * @since 12.0.0 |
|
341 | - */ |
|
342 | - public function isThrottled() { |
|
343 | - return $this->throttled; |
|
344 | - } |
|
45 | + /** |
|
46 | + * Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate'] |
|
47 | + * @var array |
|
48 | + */ |
|
49 | + private $headers = array( |
|
50 | + 'Cache-Control' => 'no-cache, no-store, must-revalidate' |
|
51 | + ); |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * Cookies that will be need to be constructed as header |
|
56 | + * @var array |
|
57 | + */ |
|
58 | + private $cookies = array(); |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * HTTP status code - defaults to STATUS OK |
|
63 | + * @var int |
|
64 | + */ |
|
65 | + private $status = Http::STATUS_OK; |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * Last modified date |
|
70 | + * @var \DateTime |
|
71 | + */ |
|
72 | + private $lastModified; |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * ETag |
|
77 | + * @var string |
|
78 | + */ |
|
79 | + private $ETag; |
|
80 | + |
|
81 | + /** @var ContentSecurityPolicy|null Used Content-Security-Policy */ |
|
82 | + private $contentSecurityPolicy = null; |
|
83 | + |
|
84 | + /** @var bool */ |
|
85 | + private $throttled = false; |
|
86 | + |
|
87 | + /** |
|
88 | + * Caches the response |
|
89 | + * @param int $cacheSeconds the amount of seconds that should be cached |
|
90 | + * if 0 then caching will be disabled |
|
91 | + * @return $this |
|
92 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
93 | + */ |
|
94 | + public function cacheFor($cacheSeconds) { |
|
95 | + |
|
96 | + if($cacheSeconds > 0) { |
|
97 | + $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate'); |
|
98 | + } else { |
|
99 | + $this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate'); |
|
100 | + } |
|
101 | + |
|
102 | + return $this; |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Adds a new cookie to the response |
|
107 | + * @param string $name The name of the cookie |
|
108 | + * @param string $value The value of the cookie |
|
109 | + * @param \DateTime|null $expireDate Date on that the cookie should expire, if set |
|
110 | + * to null cookie will be considered as session |
|
111 | + * cookie. |
|
112 | + * @return $this |
|
113 | + * @since 8.0.0 |
|
114 | + */ |
|
115 | + public function addCookie($name, $value, \DateTime $expireDate = null) { |
|
116 | + $this->cookies[$name] = array('value' => $value, 'expireDate' => $expireDate); |
|
117 | + return $this; |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * Set the specified cookies |
|
123 | + * @param array $cookies array('foo' => array('value' => 'bar', 'expire' => null)) |
|
124 | + * @return $this |
|
125 | + * @since 8.0.0 |
|
126 | + */ |
|
127 | + public function setCookies(array $cookies) { |
|
128 | + $this->cookies = $cookies; |
|
129 | + return $this; |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * Invalidates the specified cookie |
|
135 | + * @param string $name |
|
136 | + * @return $this |
|
137 | + * @since 8.0.0 |
|
138 | + */ |
|
139 | + public function invalidateCookie($name) { |
|
140 | + $this->addCookie($name, 'expired', new \DateTime('1971-01-01 00:00')); |
|
141 | + return $this; |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Invalidates the specified cookies |
|
146 | + * @param array $cookieNames array('foo', 'bar') |
|
147 | + * @return $this |
|
148 | + * @since 8.0.0 |
|
149 | + */ |
|
150 | + public function invalidateCookies(array $cookieNames) { |
|
151 | + foreach($cookieNames as $cookieName) { |
|
152 | + $this->invalidateCookie($cookieName); |
|
153 | + } |
|
154 | + return $this; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Returns the cookies |
|
159 | + * @return array |
|
160 | + * @since 8.0.0 |
|
161 | + */ |
|
162 | + public function getCookies() { |
|
163 | + return $this->cookies; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Adds a new header to the response that will be called before the render |
|
168 | + * function |
|
169 | + * @param string $name The name of the HTTP header |
|
170 | + * @param string $value The value, null will delete it |
|
171 | + * @return $this |
|
172 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
173 | + */ |
|
174 | + public function addHeader($name, $value) { |
|
175 | + $name = trim($name); // always remove leading and trailing whitespace |
|
176 | + // to be able to reliably check for security |
|
177 | + // headers |
|
178 | + |
|
179 | + if(is_null($value)) { |
|
180 | + unset($this->headers[$name]); |
|
181 | + } else { |
|
182 | + $this->headers[$name] = $value; |
|
183 | + } |
|
184 | + |
|
185 | + return $this; |
|
186 | + } |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * Set the headers |
|
191 | + * @param array $headers value header pairs |
|
192 | + * @return $this |
|
193 | + * @since 8.0.0 |
|
194 | + */ |
|
195 | + public function setHeaders(array $headers) { |
|
196 | + $this->headers = $headers; |
|
197 | + |
|
198 | + return $this; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * Returns the set headers |
|
204 | + * @return array the headers |
|
205 | + * @since 6.0.0 |
|
206 | + */ |
|
207 | + public function getHeaders() { |
|
208 | + $mergeWith = []; |
|
209 | + |
|
210 | + if($this->lastModified) { |
|
211 | + $mergeWith['Last-Modified'] = |
|
212 | + $this->lastModified->format(\DateTime::RFC2822); |
|
213 | + } |
|
214 | + |
|
215 | + // Build Content-Security-Policy and use default if none has been specified |
|
216 | + if(is_null($this->contentSecurityPolicy)) { |
|
217 | + $this->setContentSecurityPolicy(new ContentSecurityPolicy()); |
|
218 | + } |
|
219 | + $this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy(); |
|
220 | + |
|
221 | + if($this->ETag) { |
|
222 | + $mergeWith['ETag'] = '"' . $this->ETag . '"'; |
|
223 | + } |
|
224 | + |
|
225 | + return array_merge($mergeWith, $this->headers); |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * By default renders no output |
|
231 | + * @return null |
|
232 | + * @since 6.0.0 |
|
233 | + */ |
|
234 | + public function render() { |
|
235 | + return null; |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * Set response status |
|
241 | + * @param int $status a HTTP status code, see also the STATUS constants |
|
242 | + * @return Response Reference to this object |
|
243 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
244 | + */ |
|
245 | + public function setStatus($status) { |
|
246 | + $this->status = $status; |
|
247 | + |
|
248 | + return $this; |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * Set a Content-Security-Policy |
|
253 | + * @param EmptyContentSecurityPolicy $csp Policy to set for the response object |
|
254 | + * @return $this |
|
255 | + * @since 8.1.0 |
|
256 | + */ |
|
257 | + public function setContentSecurityPolicy(EmptyContentSecurityPolicy $csp) { |
|
258 | + $this->contentSecurityPolicy = $csp; |
|
259 | + return $this; |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Get the currently used Content-Security-Policy |
|
264 | + * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if |
|
265 | + * none specified. |
|
266 | + * @since 8.1.0 |
|
267 | + */ |
|
268 | + public function getContentSecurityPolicy() { |
|
269 | + return $this->contentSecurityPolicy; |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * Get response status |
|
275 | + * @since 6.0.0 |
|
276 | + */ |
|
277 | + public function getStatus() { |
|
278 | + return $this->status; |
|
279 | + } |
|
280 | + |
|
281 | + |
|
282 | + /** |
|
283 | + * Get the ETag |
|
284 | + * @return string the etag |
|
285 | + * @since 6.0.0 |
|
286 | + */ |
|
287 | + public function getETag() { |
|
288 | + return $this->ETag; |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * Get "last modified" date |
|
294 | + * @return \DateTime RFC2822 formatted last modified date |
|
295 | + * @since 6.0.0 |
|
296 | + */ |
|
297 | + public function getLastModified() { |
|
298 | + return $this->lastModified; |
|
299 | + } |
|
300 | + |
|
301 | + |
|
302 | + /** |
|
303 | + * Set the ETag |
|
304 | + * @param string $ETag |
|
305 | + * @return Response Reference to this object |
|
306 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
307 | + */ |
|
308 | + public function setETag($ETag) { |
|
309 | + $this->ETag = $ETag; |
|
310 | + |
|
311 | + return $this; |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * Set "last modified" date |
|
317 | + * @param \DateTime $lastModified |
|
318 | + * @return Response Reference to this object |
|
319 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
320 | + */ |
|
321 | + public function setLastModified($lastModified) { |
|
322 | + $this->lastModified = $lastModified; |
|
323 | + |
|
324 | + return $this; |
|
325 | + } |
|
326 | + |
|
327 | + /** |
|
328 | + * Marks the response as to throttle. Will be throttled when the |
|
329 | + * @BruteForceProtection annotation is added. |
|
330 | + * |
|
331 | + * @since 12.0.0 |
|
332 | + */ |
|
333 | + public function throttle() { |
|
334 | + $this->throttled = true; |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * Whether the current response is throttled. |
|
339 | + * |
|
340 | + * @since 12.0.0 |
|
341 | + */ |
|
342 | + public function isThrottled() { |
|
343 | + return $this->throttled; |
|
344 | + } |
|
345 | 345 | } |
@@ -134,7 +134,7 @@ |
||
134 | 134 | * @param RequestInterface $request |
135 | 135 | * @param ResponseInterface $response |
136 | 136 | * |
137 | - * @return void|bool |
|
137 | + * @return null|false |
|
138 | 138 | */ |
139 | 139 | public function httpPost(RequestInterface $request, ResponseInterface $response) { |
140 | 140 | $path = $request->getPath(); |
@@ -34,194 +34,194 @@ |
||
34 | 34 | use OCP\IConfig; |
35 | 35 | |
36 | 36 | class PublishPlugin extends ServerPlugin { |
37 | - const NS_CALENDARSERVER = 'http://calendarserver.org/ns/'; |
|
38 | - |
|
39 | - /** |
|
40 | - * Reference to SabreDAV server object. |
|
41 | - * |
|
42 | - * @var \Sabre\DAV\Server |
|
43 | - */ |
|
44 | - protected $server; |
|
45 | - |
|
46 | - /** |
|
47 | - * Config instance to get instance secret. |
|
48 | - * |
|
49 | - * @var IConfig |
|
50 | - */ |
|
51 | - protected $config; |
|
52 | - |
|
53 | - /** |
|
54 | - * URL Generator for absolute URLs. |
|
55 | - * |
|
56 | - * @var IURLGenerator |
|
57 | - */ |
|
58 | - protected $urlGenerator; |
|
59 | - |
|
60 | - /** |
|
61 | - * PublishPlugin constructor. |
|
62 | - * |
|
63 | - * @param IConfig $config |
|
64 | - * @param IURLGenerator $urlGenerator |
|
65 | - */ |
|
66 | - public function __construct(IConfig $config, IURLGenerator $urlGenerator) { |
|
67 | - $this->config = $config; |
|
68 | - $this->urlGenerator = $urlGenerator; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * This method should return a list of server-features. |
|
73 | - * |
|
74 | - * This is for example 'versioning' and is added to the DAV: header |
|
75 | - * in an OPTIONS response. |
|
76 | - * |
|
77 | - * @return string[] |
|
78 | - */ |
|
79 | - public function getFeatures() { |
|
80 | - // May have to be changed to be detected |
|
81 | - return ['oc-calendar-publishing', 'calendarserver-sharing']; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Returns a plugin name. |
|
86 | - * |
|
87 | - * Using this name other plugins will be able to access other plugins |
|
88 | - * using Sabre\DAV\Server::getPlugin |
|
89 | - * |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - public function getPluginName() { |
|
93 | - return 'oc-calendar-publishing'; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * This initializes the plugin. |
|
98 | - * |
|
99 | - * This function is called by Sabre\DAV\Server, after |
|
100 | - * addPlugin is called. |
|
101 | - * |
|
102 | - * This method should set up the required event subscriptions. |
|
103 | - * |
|
104 | - * @param Server $server |
|
105 | - */ |
|
106 | - public function initialize(Server $server) { |
|
107 | - $this->server = $server; |
|
108 | - |
|
109 | - $this->server->on('method:POST', [$this, 'httpPost']); |
|
110 | - $this->server->on('propFind', [$this, 'propFind']); |
|
111 | - } |
|
112 | - |
|
113 | - public function propFind(PropFind $propFind, INode $node) { |
|
114 | - if ($node instanceof Calendar) { |
|
115 | - $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) { |
|
116 | - if ($node->getPublishStatus()) { |
|
117 | - // We return the publish-url only if the calendar is published. |
|
118 | - $token = $node->getPublishStatus(); |
|
119 | - $publishUrl = $this->urlGenerator->getAbsoluteURL($this->server->getBaseUri().'public-calendars/').$token; |
|
120 | - |
|
121 | - return new Publisher($publishUrl, true); |
|
122 | - } |
|
123 | - }); |
|
124 | - |
|
125 | - $propFind->handle('{'.self::NS_CALENDARSERVER.'}allowed-sharing-modes', function() use ($node) { |
|
126 | - return new AllowedSharingModes(!$node->isSubscription(), !$node->isSubscription()); |
|
127 | - }); |
|
128 | - } |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * We intercept this to handle POST requests on calendars. |
|
133 | - * |
|
134 | - * @param RequestInterface $request |
|
135 | - * @param ResponseInterface $response |
|
136 | - * |
|
137 | - * @return void|bool |
|
138 | - */ |
|
139 | - public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
140 | - $path = $request->getPath(); |
|
141 | - |
|
142 | - // Only handling xml |
|
143 | - $contentType = $request->getHeader('Content-Type'); |
|
144 | - if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) { |
|
145 | - return; |
|
146 | - } |
|
147 | - |
|
148 | - // Making sure the node exists |
|
149 | - try { |
|
150 | - $node = $this->server->tree->getNodeForPath($path); |
|
151 | - } catch (NotFound $e) { |
|
152 | - return; |
|
153 | - } |
|
154 | - |
|
155 | - $requestBody = $request->getBodyAsString(); |
|
156 | - |
|
157 | - // If this request handler could not deal with this POST request, it |
|
158 | - // will return 'null' and other plugins get a chance to handle the |
|
159 | - // request. |
|
160 | - // |
|
161 | - // However, we already requested the full body. This is a problem, |
|
162 | - // because a body can only be read once. This is why we preemptively |
|
163 | - // re-populated the request body with the existing data. |
|
164 | - $request->setBody($requestBody); |
|
165 | - |
|
166 | - $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
167 | - |
|
168 | - switch ($documentType) { |
|
169 | - |
|
170 | - case '{'.self::NS_CALENDARSERVER.'}publish-calendar' : |
|
171 | - |
|
172 | - // We can only deal with IShareableCalendar objects |
|
173 | - if (!$node instanceof Calendar) { |
|
174 | - return; |
|
175 | - } |
|
176 | - $this->server->transactionType = 'post-publish-calendar'; |
|
177 | - |
|
178 | - // Getting ACL info |
|
179 | - $acl = $this->server->getPlugin('acl'); |
|
180 | - |
|
181 | - // If there's no ACL support, we allow everything |
|
182 | - if ($acl) { |
|
183 | - $acl->checkPrivileges($path, '{DAV:}write'); |
|
184 | - } |
|
185 | - |
|
186 | - $node->setPublishStatus(true); |
|
187 | - |
|
188 | - // iCloud sends back the 202, so we will too. |
|
189 | - $response->setStatus(202); |
|
190 | - |
|
191 | - // Adding this because sending a response body may cause issues, |
|
192 | - // and I wanted some type of indicator the response was handled. |
|
193 | - $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
194 | - |
|
195 | - // Breaking the event chain |
|
196 | - return false; |
|
197 | - |
|
198 | - case '{'.self::NS_CALENDARSERVER.'}unpublish-calendar' : |
|
199 | - |
|
200 | - // We can only deal with IShareableCalendar objects |
|
201 | - if (!$node instanceof Calendar) { |
|
202 | - return; |
|
203 | - } |
|
204 | - $this->server->transactionType = 'post-unpublish-calendar'; |
|
205 | - |
|
206 | - // Getting ACL info |
|
207 | - $acl = $this->server->getPlugin('acl'); |
|
208 | - |
|
209 | - // If there's no ACL support, we allow everything |
|
210 | - if ($acl) { |
|
211 | - $acl->checkPrivileges($path, '{DAV:}write'); |
|
212 | - } |
|
213 | - |
|
214 | - $node->setPublishStatus(false); |
|
215 | - |
|
216 | - $response->setStatus(200); |
|
217 | - |
|
218 | - // Adding this because sending a response body may cause issues, |
|
219 | - // and I wanted some type of indicator the response was handled. |
|
220 | - $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
221 | - |
|
222 | - // Breaking the event chain |
|
223 | - return false; |
|
37 | + const NS_CALENDARSERVER = 'http://calendarserver.org/ns/'; |
|
38 | + |
|
39 | + /** |
|
40 | + * Reference to SabreDAV server object. |
|
41 | + * |
|
42 | + * @var \Sabre\DAV\Server |
|
43 | + */ |
|
44 | + protected $server; |
|
45 | + |
|
46 | + /** |
|
47 | + * Config instance to get instance secret. |
|
48 | + * |
|
49 | + * @var IConfig |
|
50 | + */ |
|
51 | + protected $config; |
|
52 | + |
|
53 | + /** |
|
54 | + * URL Generator for absolute URLs. |
|
55 | + * |
|
56 | + * @var IURLGenerator |
|
57 | + */ |
|
58 | + protected $urlGenerator; |
|
59 | + |
|
60 | + /** |
|
61 | + * PublishPlugin constructor. |
|
62 | + * |
|
63 | + * @param IConfig $config |
|
64 | + * @param IURLGenerator $urlGenerator |
|
65 | + */ |
|
66 | + public function __construct(IConfig $config, IURLGenerator $urlGenerator) { |
|
67 | + $this->config = $config; |
|
68 | + $this->urlGenerator = $urlGenerator; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * This method should return a list of server-features. |
|
73 | + * |
|
74 | + * This is for example 'versioning' and is added to the DAV: header |
|
75 | + * in an OPTIONS response. |
|
76 | + * |
|
77 | + * @return string[] |
|
78 | + */ |
|
79 | + public function getFeatures() { |
|
80 | + // May have to be changed to be detected |
|
81 | + return ['oc-calendar-publishing', 'calendarserver-sharing']; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Returns a plugin name. |
|
86 | + * |
|
87 | + * Using this name other plugins will be able to access other plugins |
|
88 | + * using Sabre\DAV\Server::getPlugin |
|
89 | + * |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + public function getPluginName() { |
|
93 | + return 'oc-calendar-publishing'; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * This initializes the plugin. |
|
98 | + * |
|
99 | + * This function is called by Sabre\DAV\Server, after |
|
100 | + * addPlugin is called. |
|
101 | + * |
|
102 | + * This method should set up the required event subscriptions. |
|
103 | + * |
|
104 | + * @param Server $server |
|
105 | + */ |
|
106 | + public function initialize(Server $server) { |
|
107 | + $this->server = $server; |
|
108 | + |
|
109 | + $this->server->on('method:POST', [$this, 'httpPost']); |
|
110 | + $this->server->on('propFind', [$this, 'propFind']); |
|
111 | + } |
|
112 | + |
|
113 | + public function propFind(PropFind $propFind, INode $node) { |
|
114 | + if ($node instanceof Calendar) { |
|
115 | + $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) { |
|
116 | + if ($node->getPublishStatus()) { |
|
117 | + // We return the publish-url only if the calendar is published. |
|
118 | + $token = $node->getPublishStatus(); |
|
119 | + $publishUrl = $this->urlGenerator->getAbsoluteURL($this->server->getBaseUri().'public-calendars/').$token; |
|
120 | + |
|
121 | + return new Publisher($publishUrl, true); |
|
122 | + } |
|
123 | + }); |
|
124 | + |
|
125 | + $propFind->handle('{'.self::NS_CALENDARSERVER.'}allowed-sharing-modes', function() use ($node) { |
|
126 | + return new AllowedSharingModes(!$node->isSubscription(), !$node->isSubscription()); |
|
127 | + }); |
|
128 | + } |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * We intercept this to handle POST requests on calendars. |
|
133 | + * |
|
134 | + * @param RequestInterface $request |
|
135 | + * @param ResponseInterface $response |
|
136 | + * |
|
137 | + * @return void|bool |
|
138 | + */ |
|
139 | + public function httpPost(RequestInterface $request, ResponseInterface $response) { |
|
140 | + $path = $request->getPath(); |
|
141 | + |
|
142 | + // Only handling xml |
|
143 | + $contentType = $request->getHeader('Content-Type'); |
|
144 | + if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) { |
|
145 | + return; |
|
146 | + } |
|
147 | + |
|
148 | + // Making sure the node exists |
|
149 | + try { |
|
150 | + $node = $this->server->tree->getNodeForPath($path); |
|
151 | + } catch (NotFound $e) { |
|
152 | + return; |
|
153 | + } |
|
154 | + |
|
155 | + $requestBody = $request->getBodyAsString(); |
|
156 | + |
|
157 | + // If this request handler could not deal with this POST request, it |
|
158 | + // will return 'null' and other plugins get a chance to handle the |
|
159 | + // request. |
|
160 | + // |
|
161 | + // However, we already requested the full body. This is a problem, |
|
162 | + // because a body can only be read once. This is why we preemptively |
|
163 | + // re-populated the request body with the existing data. |
|
164 | + $request->setBody($requestBody); |
|
165 | + |
|
166 | + $this->server->xml->parse($requestBody, $request->getUrl(), $documentType); |
|
167 | + |
|
168 | + switch ($documentType) { |
|
169 | + |
|
170 | + case '{'.self::NS_CALENDARSERVER.'}publish-calendar' : |
|
171 | + |
|
172 | + // We can only deal with IShareableCalendar objects |
|
173 | + if (!$node instanceof Calendar) { |
|
174 | + return; |
|
175 | + } |
|
176 | + $this->server->transactionType = 'post-publish-calendar'; |
|
177 | + |
|
178 | + // Getting ACL info |
|
179 | + $acl = $this->server->getPlugin('acl'); |
|
180 | + |
|
181 | + // If there's no ACL support, we allow everything |
|
182 | + if ($acl) { |
|
183 | + $acl->checkPrivileges($path, '{DAV:}write'); |
|
184 | + } |
|
185 | + |
|
186 | + $node->setPublishStatus(true); |
|
187 | + |
|
188 | + // iCloud sends back the 202, so we will too. |
|
189 | + $response->setStatus(202); |
|
190 | + |
|
191 | + // Adding this because sending a response body may cause issues, |
|
192 | + // and I wanted some type of indicator the response was handled. |
|
193 | + $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
194 | + |
|
195 | + // Breaking the event chain |
|
196 | + return false; |
|
197 | + |
|
198 | + case '{'.self::NS_CALENDARSERVER.'}unpublish-calendar' : |
|
199 | + |
|
200 | + // We can only deal with IShareableCalendar objects |
|
201 | + if (!$node instanceof Calendar) { |
|
202 | + return; |
|
203 | + } |
|
204 | + $this->server->transactionType = 'post-unpublish-calendar'; |
|
205 | + |
|
206 | + // Getting ACL info |
|
207 | + $acl = $this->server->getPlugin('acl'); |
|
208 | + |
|
209 | + // If there's no ACL support, we allow everything |
|
210 | + if ($acl) { |
|
211 | + $acl->checkPrivileges($path, '{DAV:}write'); |
|
212 | + } |
|
213 | + |
|
214 | + $node->setPublishStatus(false); |
|
215 | + |
|
216 | + $response->setStatus(200); |
|
217 | + |
|
218 | + // Adding this because sending a response body may cause issues, |
|
219 | + // and I wanted some type of indicator the response was handled. |
|
220 | + $response->setHeader('X-Sabre-Status', 'everything-went-well'); |
|
221 | + |
|
222 | + // Breaking the event chain |
|
223 | + return false; |
|
224 | 224 | |
225 | - } |
|
226 | - } |
|
225 | + } |
|
226 | + } |
|
227 | 227 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @return string |
91 | 91 | */ |
92 | - public function getPluginName() { |
|
92 | + public function getPluginName() { |
|
93 | 93 | return 'oc-calendar-publishing'; |
94 | 94 | } |
95 | 95 | |
@@ -107,12 +107,12 @@ discard block |
||
107 | 107 | $this->server = $server; |
108 | 108 | |
109 | 109 | $this->server->on('method:POST', [$this, 'httpPost']); |
110 | - $this->server->on('propFind', [$this, 'propFind']); |
|
110 | + $this->server->on('propFind', [$this, 'propFind']); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | public function propFind(PropFind $propFind, INode $node) { |
114 | 114 | if ($node instanceof Calendar) { |
115 | - $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) { |
|
115 | + $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function() use ($node) { |
|
116 | 116 | if ($node->getPublishStatus()) { |
117 | 117 | // We return the publish-url only if the calendar is published. |
118 | 118 | $token = $node->getPublishStatus(); |
@@ -30,7 +30,7 @@ |
||
30 | 30 | |
31 | 31 | /** |
32 | 32 | * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend |
33 | - * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend |
|
33 | + * @param CardDavBackend $carddavBackend |
|
34 | 34 | * @param string $principalPrefix |
35 | 35 | */ |
36 | 36 | public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend, \Sabre\CardDAV\Backend\BackendInterface $carddavBackend, $principalPrefix = 'principals') { |
@@ -25,46 +25,46 @@ |
||
25 | 25 | |
26 | 26 | class AddressBookRoot extends \Sabre\CardDAV\AddressBookRoot { |
27 | 27 | |
28 | - /** @var IL10N */ |
|
29 | - protected $l10n; |
|
28 | + /** @var IL10N */ |
|
29 | + protected $l10n; |
|
30 | 30 | |
31 | - /** |
|
32 | - * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend |
|
33 | - * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend |
|
34 | - * @param string $principalPrefix |
|
35 | - */ |
|
36 | - public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend, \Sabre\CardDAV\Backend\BackendInterface $carddavBackend, $principalPrefix = 'principals') { |
|
37 | - parent::__construct($principalBackend, $carddavBackend, $principalPrefix); |
|
38 | - $this->l10n = \OC::$server->getL10N('dav'); |
|
39 | - } |
|
31 | + /** |
|
32 | + * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend |
|
33 | + * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend |
|
34 | + * @param string $principalPrefix |
|
35 | + */ |
|
36 | + public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend, \Sabre\CardDAV\Backend\BackendInterface $carddavBackend, $principalPrefix = 'principals') { |
|
37 | + parent::__construct($principalBackend, $carddavBackend, $principalPrefix); |
|
38 | + $this->l10n = \OC::$server->getL10N('dav'); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * This method returns a node for a principal. |
|
43 | - * |
|
44 | - * The passed array contains principal information, and is guaranteed to |
|
45 | - * at least contain a uri item. Other properties may or may not be |
|
46 | - * supplied by the authentication backend. |
|
47 | - * |
|
48 | - * @param array $principal |
|
49 | - * @return \Sabre\DAV\INode |
|
50 | - */ |
|
51 | - function getChildForPrincipal(array $principal) { |
|
41 | + /** |
|
42 | + * This method returns a node for a principal. |
|
43 | + * |
|
44 | + * The passed array contains principal information, and is guaranteed to |
|
45 | + * at least contain a uri item. Other properties may or may not be |
|
46 | + * supplied by the authentication backend. |
|
47 | + * |
|
48 | + * @param array $principal |
|
49 | + * @return \Sabre\DAV\INode |
|
50 | + */ |
|
51 | + function getChildForPrincipal(array $principal) { |
|
52 | 52 | |
53 | - return new UserAddressBooks($this->carddavBackend, $principal['uri'], $this->l10n); |
|
53 | + return new UserAddressBooks($this->carddavBackend, $principal['uri'], $this->l10n); |
|
54 | 54 | |
55 | - } |
|
55 | + } |
|
56 | 56 | |
57 | - function getName() { |
|
57 | + function getName() { |
|
58 | 58 | |
59 | - if ($this->principalPrefix === 'principals') { |
|
60 | - return parent::getName(); |
|
61 | - } |
|
62 | - // Grabbing all the components of the principal path. |
|
63 | - $parts = explode('/', $this->principalPrefix); |
|
59 | + if ($this->principalPrefix === 'principals') { |
|
60 | + return parent::getName(); |
|
61 | + } |
|
62 | + // Grabbing all the components of the principal path. |
|
63 | + $parts = explode('/', $this->principalPrefix); |
|
64 | 64 | |
65 | - // We are only interested in the second part. |
|
66 | - return $parts[1]; |
|
65 | + // We are only interested in the second part. |
|
66 | + return $parts[1]; |
|
67 | 67 | |
68 | - } |
|
68 | + } |
|
69 | 69 | |
70 | 70 | } |
@@ -770,7 +770,7 @@ |
||
770 | 770 | |
771 | 771 | /** |
772 | 772 | * @param Share[] $shares |
773 | - * @param $userId |
|
773 | + * @param string $userId |
|
774 | 774 | * @return Share[] The updates shares if no update is found for a share return the original |
775 | 775 | */ |
776 | 776 | private function resolveGroupShares($shares, $userId) { |
@@ -24,7 +24,6 @@ |
||
24 | 24 | namespace OC\Share20; |
25 | 25 | |
26 | 26 | use OC\Files\Cache\Cache; |
27 | -use OC\Files\Cache\CacheEntry; |
|
28 | 27 | use OCP\Files\File; |
29 | 28 | use OCP\Files\Folder; |
30 | 29 | use OCP\Share\IShareProvider; |
@@ -47,1138 +47,1138 @@ |
||
47 | 47 | */ |
48 | 48 | class DefaultShareProvider implements IShareProvider { |
49 | 49 | |
50 | - // Special share type for user modified group shares |
|
51 | - const SHARE_TYPE_USERGROUP = 2; |
|
52 | - |
|
53 | - /** @var IDBConnection */ |
|
54 | - private $dbConn; |
|
55 | - |
|
56 | - /** @var IUserManager */ |
|
57 | - private $userManager; |
|
58 | - |
|
59 | - /** @var IGroupManager */ |
|
60 | - private $groupManager; |
|
61 | - |
|
62 | - /** @var IRootFolder */ |
|
63 | - private $rootFolder; |
|
64 | - |
|
65 | - /** |
|
66 | - * DefaultShareProvider constructor. |
|
67 | - * |
|
68 | - * @param IDBConnection $connection |
|
69 | - * @param IUserManager $userManager |
|
70 | - * @param IGroupManager $groupManager |
|
71 | - * @param IRootFolder $rootFolder |
|
72 | - */ |
|
73 | - public function __construct( |
|
74 | - IDBConnection $connection, |
|
75 | - IUserManager $userManager, |
|
76 | - IGroupManager $groupManager, |
|
77 | - IRootFolder $rootFolder) { |
|
78 | - $this->dbConn = $connection; |
|
79 | - $this->userManager = $userManager; |
|
80 | - $this->groupManager = $groupManager; |
|
81 | - $this->rootFolder = $rootFolder; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Return the identifier of this provider. |
|
86 | - * |
|
87 | - * @return string Containing only [a-zA-Z0-9] |
|
88 | - */ |
|
89 | - public function identifier() { |
|
90 | - return 'ocinternal'; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Share a path |
|
95 | - * |
|
96 | - * @param \OCP\Share\IShare $share |
|
97 | - * @return \OCP\Share\IShare The share object |
|
98 | - * @throws ShareNotFound |
|
99 | - * @throws \Exception |
|
100 | - */ |
|
101 | - public function create(\OCP\Share\IShare $share) { |
|
102 | - $qb = $this->dbConn->getQueryBuilder(); |
|
103 | - |
|
104 | - $qb->insert('share'); |
|
105 | - $qb->setValue('share_type', $qb->createNamedParameter($share->getShareType())); |
|
106 | - |
|
107 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
108 | - //Set the UID of the user we share with |
|
109 | - $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith())); |
|
110 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
111 | - //Set the GID of the group we share with |
|
112 | - $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith())); |
|
113 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
114 | - //Set the token of the share |
|
115 | - $qb->setValue('token', $qb->createNamedParameter($share->getToken())); |
|
116 | - |
|
117 | - //If a password is set store it |
|
118 | - if ($share->getPassword() !== null) { |
|
119 | - $qb->setValue('password', $qb->createNamedParameter($share->getPassword())); |
|
120 | - } |
|
121 | - |
|
122 | - //If an expiration date is set store it |
|
123 | - if ($share->getExpirationDate() !== null) { |
|
124 | - $qb->setValue('expiration', $qb->createNamedParameter($share->getExpirationDate(), 'datetime')); |
|
125 | - } |
|
126 | - |
|
127 | - if (method_exists($share, 'getParent')) { |
|
128 | - $qb->setValue('parent', $qb->createNamedParameter($share->getParent())); |
|
129 | - } |
|
130 | - } else { |
|
131 | - throw new \Exception('invalid share type!'); |
|
132 | - } |
|
133 | - |
|
134 | - // Set what is shares |
|
135 | - $qb->setValue('item_type', $qb->createParameter('itemType')); |
|
136 | - if ($share->getNode() instanceof \OCP\Files\File) { |
|
137 | - $qb->setParameter('itemType', 'file'); |
|
138 | - } else { |
|
139 | - $qb->setParameter('itemType', 'folder'); |
|
140 | - } |
|
141 | - |
|
142 | - // Set the file id |
|
143 | - $qb->setValue('item_source', $qb->createNamedParameter($share->getNode()->getId())); |
|
144 | - $qb->setValue('file_source', $qb->createNamedParameter($share->getNode()->getId())); |
|
145 | - |
|
146 | - // set the permissions |
|
147 | - $qb->setValue('permissions', $qb->createNamedParameter($share->getPermissions())); |
|
148 | - |
|
149 | - // Set who created this share |
|
150 | - $qb->setValue('uid_initiator', $qb->createNamedParameter($share->getSharedBy())); |
|
151 | - |
|
152 | - // Set who is the owner of this file/folder (and this the owner of the share) |
|
153 | - $qb->setValue('uid_owner', $qb->createNamedParameter($share->getShareOwner())); |
|
154 | - |
|
155 | - // Set the file target |
|
156 | - $qb->setValue('file_target', $qb->createNamedParameter($share->getTarget())); |
|
157 | - |
|
158 | - // Set the time this share was created |
|
159 | - $qb->setValue('stime', $qb->createNamedParameter(time())); |
|
160 | - |
|
161 | - // insert the data and fetch the id of the share |
|
162 | - $this->dbConn->beginTransaction(); |
|
163 | - $qb->execute(); |
|
164 | - $id = $this->dbConn->lastInsertId('*PREFIX*share'); |
|
165 | - |
|
166 | - // Now fetch the inserted share and create a complete share object |
|
167 | - $qb = $this->dbConn->getQueryBuilder(); |
|
168 | - $qb->select('*') |
|
169 | - ->from('share') |
|
170 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
171 | - |
|
172 | - $cursor = $qb->execute(); |
|
173 | - $data = $cursor->fetch(); |
|
174 | - $this->dbConn->commit(); |
|
175 | - $cursor->closeCursor(); |
|
176 | - |
|
177 | - if ($data === false) { |
|
178 | - throw new ShareNotFound(); |
|
179 | - } |
|
180 | - |
|
181 | - $share = $this->createShare($data); |
|
182 | - return $share; |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * Update a share |
|
187 | - * |
|
188 | - * @param \OCP\Share\IShare $share |
|
189 | - * @return \OCP\Share\IShare The share object |
|
190 | - */ |
|
191 | - public function update(\OCP\Share\IShare $share) { |
|
192 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
193 | - /* |
|
50 | + // Special share type for user modified group shares |
|
51 | + const SHARE_TYPE_USERGROUP = 2; |
|
52 | + |
|
53 | + /** @var IDBConnection */ |
|
54 | + private $dbConn; |
|
55 | + |
|
56 | + /** @var IUserManager */ |
|
57 | + private $userManager; |
|
58 | + |
|
59 | + /** @var IGroupManager */ |
|
60 | + private $groupManager; |
|
61 | + |
|
62 | + /** @var IRootFolder */ |
|
63 | + private $rootFolder; |
|
64 | + |
|
65 | + /** |
|
66 | + * DefaultShareProvider constructor. |
|
67 | + * |
|
68 | + * @param IDBConnection $connection |
|
69 | + * @param IUserManager $userManager |
|
70 | + * @param IGroupManager $groupManager |
|
71 | + * @param IRootFolder $rootFolder |
|
72 | + */ |
|
73 | + public function __construct( |
|
74 | + IDBConnection $connection, |
|
75 | + IUserManager $userManager, |
|
76 | + IGroupManager $groupManager, |
|
77 | + IRootFolder $rootFolder) { |
|
78 | + $this->dbConn = $connection; |
|
79 | + $this->userManager = $userManager; |
|
80 | + $this->groupManager = $groupManager; |
|
81 | + $this->rootFolder = $rootFolder; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Return the identifier of this provider. |
|
86 | + * |
|
87 | + * @return string Containing only [a-zA-Z0-9] |
|
88 | + */ |
|
89 | + public function identifier() { |
|
90 | + return 'ocinternal'; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Share a path |
|
95 | + * |
|
96 | + * @param \OCP\Share\IShare $share |
|
97 | + * @return \OCP\Share\IShare The share object |
|
98 | + * @throws ShareNotFound |
|
99 | + * @throws \Exception |
|
100 | + */ |
|
101 | + public function create(\OCP\Share\IShare $share) { |
|
102 | + $qb = $this->dbConn->getQueryBuilder(); |
|
103 | + |
|
104 | + $qb->insert('share'); |
|
105 | + $qb->setValue('share_type', $qb->createNamedParameter($share->getShareType())); |
|
106 | + |
|
107 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
108 | + //Set the UID of the user we share with |
|
109 | + $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith())); |
|
110 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
111 | + //Set the GID of the group we share with |
|
112 | + $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith())); |
|
113 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
114 | + //Set the token of the share |
|
115 | + $qb->setValue('token', $qb->createNamedParameter($share->getToken())); |
|
116 | + |
|
117 | + //If a password is set store it |
|
118 | + if ($share->getPassword() !== null) { |
|
119 | + $qb->setValue('password', $qb->createNamedParameter($share->getPassword())); |
|
120 | + } |
|
121 | + |
|
122 | + //If an expiration date is set store it |
|
123 | + if ($share->getExpirationDate() !== null) { |
|
124 | + $qb->setValue('expiration', $qb->createNamedParameter($share->getExpirationDate(), 'datetime')); |
|
125 | + } |
|
126 | + |
|
127 | + if (method_exists($share, 'getParent')) { |
|
128 | + $qb->setValue('parent', $qb->createNamedParameter($share->getParent())); |
|
129 | + } |
|
130 | + } else { |
|
131 | + throw new \Exception('invalid share type!'); |
|
132 | + } |
|
133 | + |
|
134 | + // Set what is shares |
|
135 | + $qb->setValue('item_type', $qb->createParameter('itemType')); |
|
136 | + if ($share->getNode() instanceof \OCP\Files\File) { |
|
137 | + $qb->setParameter('itemType', 'file'); |
|
138 | + } else { |
|
139 | + $qb->setParameter('itemType', 'folder'); |
|
140 | + } |
|
141 | + |
|
142 | + // Set the file id |
|
143 | + $qb->setValue('item_source', $qb->createNamedParameter($share->getNode()->getId())); |
|
144 | + $qb->setValue('file_source', $qb->createNamedParameter($share->getNode()->getId())); |
|
145 | + |
|
146 | + // set the permissions |
|
147 | + $qb->setValue('permissions', $qb->createNamedParameter($share->getPermissions())); |
|
148 | + |
|
149 | + // Set who created this share |
|
150 | + $qb->setValue('uid_initiator', $qb->createNamedParameter($share->getSharedBy())); |
|
151 | + |
|
152 | + // Set who is the owner of this file/folder (and this the owner of the share) |
|
153 | + $qb->setValue('uid_owner', $qb->createNamedParameter($share->getShareOwner())); |
|
154 | + |
|
155 | + // Set the file target |
|
156 | + $qb->setValue('file_target', $qb->createNamedParameter($share->getTarget())); |
|
157 | + |
|
158 | + // Set the time this share was created |
|
159 | + $qb->setValue('stime', $qb->createNamedParameter(time())); |
|
160 | + |
|
161 | + // insert the data and fetch the id of the share |
|
162 | + $this->dbConn->beginTransaction(); |
|
163 | + $qb->execute(); |
|
164 | + $id = $this->dbConn->lastInsertId('*PREFIX*share'); |
|
165 | + |
|
166 | + // Now fetch the inserted share and create a complete share object |
|
167 | + $qb = $this->dbConn->getQueryBuilder(); |
|
168 | + $qb->select('*') |
|
169 | + ->from('share') |
|
170 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))); |
|
171 | + |
|
172 | + $cursor = $qb->execute(); |
|
173 | + $data = $cursor->fetch(); |
|
174 | + $this->dbConn->commit(); |
|
175 | + $cursor->closeCursor(); |
|
176 | + |
|
177 | + if ($data === false) { |
|
178 | + throw new ShareNotFound(); |
|
179 | + } |
|
180 | + |
|
181 | + $share = $this->createShare($data); |
|
182 | + return $share; |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * Update a share |
|
187 | + * |
|
188 | + * @param \OCP\Share\IShare $share |
|
189 | + * @return \OCP\Share\IShare The share object |
|
190 | + */ |
|
191 | + public function update(\OCP\Share\IShare $share) { |
|
192 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
193 | + /* |
|
194 | 194 | * We allow updating the recipient on user shares. |
195 | 195 | */ |
196 | - $qb = $this->dbConn->getQueryBuilder(); |
|
197 | - $qb->update('share') |
|
198 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
199 | - ->set('share_with', $qb->createNamedParameter($share->getSharedWith())) |
|
200 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
201 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
202 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
203 | - ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
204 | - ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
205 | - ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
206 | - ->execute(); |
|
207 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
208 | - $qb = $this->dbConn->getQueryBuilder(); |
|
209 | - $qb->update('share') |
|
210 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
211 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
212 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
213 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
214 | - ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
215 | - ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
216 | - ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
217 | - ->execute(); |
|
218 | - |
|
219 | - /* |
|
196 | + $qb = $this->dbConn->getQueryBuilder(); |
|
197 | + $qb->update('share') |
|
198 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
199 | + ->set('share_with', $qb->createNamedParameter($share->getSharedWith())) |
|
200 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
201 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
202 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
203 | + ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
204 | + ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
205 | + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
206 | + ->execute(); |
|
207 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
208 | + $qb = $this->dbConn->getQueryBuilder(); |
|
209 | + $qb->update('share') |
|
210 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
211 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
212 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
213 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
214 | + ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
215 | + ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
216 | + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
217 | + ->execute(); |
|
218 | + |
|
219 | + /* |
|
220 | 220 | * Update all user defined group shares |
221 | 221 | */ |
222 | - $qb = $this->dbConn->getQueryBuilder(); |
|
223 | - $qb->update('share') |
|
224 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
225 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
226 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
227 | - ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
228 | - ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
229 | - ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
230 | - ->execute(); |
|
231 | - |
|
232 | - /* |
|
222 | + $qb = $this->dbConn->getQueryBuilder(); |
|
223 | + $qb->update('share') |
|
224 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
225 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
226 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
227 | + ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
228 | + ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
229 | + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
230 | + ->execute(); |
|
231 | + |
|
232 | + /* |
|
233 | 233 | * Now update the permissions for all children that have not set it to 0 |
234 | 234 | */ |
235 | - $qb = $this->dbConn->getQueryBuilder(); |
|
236 | - $qb->update('share') |
|
237 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
238 | - ->andWhere($qb->expr()->neq('permissions', $qb->createNamedParameter(0))) |
|
239 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
240 | - ->execute(); |
|
241 | - |
|
242 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
243 | - $qb = $this->dbConn->getQueryBuilder(); |
|
244 | - $qb->update('share') |
|
245 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
246 | - ->set('password', $qb->createNamedParameter($share->getPassword())) |
|
247 | - ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
248 | - ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
249 | - ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
250 | - ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
251 | - ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
252 | - ->set('token', $qb->createNamedParameter($share->getToken())) |
|
253 | - ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
254 | - ->execute(); |
|
255 | - } |
|
256 | - |
|
257 | - return $share; |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Get all children of this share |
|
262 | - * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in |
|
263 | - * |
|
264 | - * @param \OCP\Share\IShare $parent |
|
265 | - * @return \OCP\Share\IShare[] |
|
266 | - */ |
|
267 | - public function getChildren(\OCP\Share\IShare $parent) { |
|
268 | - $children = []; |
|
269 | - |
|
270 | - $qb = $this->dbConn->getQueryBuilder(); |
|
271 | - $qb->select('*') |
|
272 | - ->from('share') |
|
273 | - ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
274 | - ->andWhere( |
|
275 | - $qb->expr()->in( |
|
276 | - 'share_type', |
|
277 | - $qb->createNamedParameter([ |
|
278 | - \OCP\Share::SHARE_TYPE_USER, |
|
279 | - \OCP\Share::SHARE_TYPE_GROUP, |
|
280 | - \OCP\Share::SHARE_TYPE_LINK, |
|
281 | - ], IQueryBuilder::PARAM_INT_ARRAY) |
|
282 | - ) |
|
283 | - ) |
|
284 | - ->andWhere($qb->expr()->orX( |
|
285 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
286 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
287 | - )) |
|
288 | - ->orderBy('id'); |
|
289 | - |
|
290 | - $cursor = $qb->execute(); |
|
291 | - while($data = $cursor->fetch()) { |
|
292 | - $children[] = $this->createShare($data); |
|
293 | - } |
|
294 | - $cursor->closeCursor(); |
|
295 | - |
|
296 | - return $children; |
|
297 | - } |
|
298 | - |
|
299 | - /** |
|
300 | - * Delete a share |
|
301 | - * |
|
302 | - * @param \OCP\Share\IShare $share |
|
303 | - */ |
|
304 | - public function delete(\OCP\Share\IShare $share) { |
|
305 | - $qb = $this->dbConn->getQueryBuilder(); |
|
306 | - $qb->delete('share') |
|
307 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))); |
|
308 | - |
|
309 | - /* |
|
235 | + $qb = $this->dbConn->getQueryBuilder(); |
|
236 | + $qb->update('share') |
|
237 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
238 | + ->andWhere($qb->expr()->neq('permissions', $qb->createNamedParameter(0))) |
|
239 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
240 | + ->execute(); |
|
241 | + |
|
242 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
243 | + $qb = $this->dbConn->getQueryBuilder(); |
|
244 | + $qb->update('share') |
|
245 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
246 | + ->set('password', $qb->createNamedParameter($share->getPassword())) |
|
247 | + ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner())) |
|
248 | + ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy())) |
|
249 | + ->set('permissions', $qb->createNamedParameter($share->getPermissions())) |
|
250 | + ->set('item_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
251 | + ->set('file_source', $qb->createNamedParameter($share->getNode()->getId())) |
|
252 | + ->set('token', $qb->createNamedParameter($share->getToken())) |
|
253 | + ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE)) |
|
254 | + ->execute(); |
|
255 | + } |
|
256 | + |
|
257 | + return $share; |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Get all children of this share |
|
262 | + * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in |
|
263 | + * |
|
264 | + * @param \OCP\Share\IShare $parent |
|
265 | + * @return \OCP\Share\IShare[] |
|
266 | + */ |
|
267 | + public function getChildren(\OCP\Share\IShare $parent) { |
|
268 | + $children = []; |
|
269 | + |
|
270 | + $qb = $this->dbConn->getQueryBuilder(); |
|
271 | + $qb->select('*') |
|
272 | + ->from('share') |
|
273 | + ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId()))) |
|
274 | + ->andWhere( |
|
275 | + $qb->expr()->in( |
|
276 | + 'share_type', |
|
277 | + $qb->createNamedParameter([ |
|
278 | + \OCP\Share::SHARE_TYPE_USER, |
|
279 | + \OCP\Share::SHARE_TYPE_GROUP, |
|
280 | + \OCP\Share::SHARE_TYPE_LINK, |
|
281 | + ], IQueryBuilder::PARAM_INT_ARRAY) |
|
282 | + ) |
|
283 | + ) |
|
284 | + ->andWhere($qb->expr()->orX( |
|
285 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
286 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
287 | + )) |
|
288 | + ->orderBy('id'); |
|
289 | + |
|
290 | + $cursor = $qb->execute(); |
|
291 | + while($data = $cursor->fetch()) { |
|
292 | + $children[] = $this->createShare($data); |
|
293 | + } |
|
294 | + $cursor->closeCursor(); |
|
295 | + |
|
296 | + return $children; |
|
297 | + } |
|
298 | + |
|
299 | + /** |
|
300 | + * Delete a share |
|
301 | + * |
|
302 | + * @param \OCP\Share\IShare $share |
|
303 | + */ |
|
304 | + public function delete(\OCP\Share\IShare $share) { |
|
305 | + $qb = $this->dbConn->getQueryBuilder(); |
|
306 | + $qb->delete('share') |
|
307 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))); |
|
308 | + |
|
309 | + /* |
|
310 | 310 | * If the share is a group share delete all possible |
311 | 311 | * user defined groups shares. |
312 | 312 | */ |
313 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
314 | - $qb->orWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))); |
|
315 | - } |
|
316 | - |
|
317 | - $qb->execute(); |
|
318 | - } |
|
319 | - |
|
320 | - /** |
|
321 | - * Unshare a share from the recipient. If this is a group share |
|
322 | - * this means we need a special entry in the share db. |
|
323 | - * |
|
324 | - * @param \OCP\Share\IShare $share |
|
325 | - * @param string $recipient UserId of recipient |
|
326 | - * @throws BackendError |
|
327 | - * @throws ProviderException |
|
328 | - */ |
|
329 | - public function deleteFromSelf(\OCP\Share\IShare $share, $recipient) { |
|
330 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
331 | - |
|
332 | - $group = $this->groupManager->get($share->getSharedWith()); |
|
333 | - $user = $this->userManager->get($recipient); |
|
334 | - |
|
335 | - if (is_null($group)) { |
|
336 | - throw new ProviderException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
337 | - } |
|
338 | - |
|
339 | - if (!$group->inGroup($user)) { |
|
340 | - throw new ProviderException('Recipient not in receiving group'); |
|
341 | - } |
|
342 | - |
|
343 | - // Try to fetch user specific share |
|
344 | - $qb = $this->dbConn->getQueryBuilder(); |
|
345 | - $stmt = $qb->select('*') |
|
346 | - ->from('share') |
|
347 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
348 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient))) |
|
349 | - ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
350 | - ->andWhere($qb->expr()->orX( |
|
351 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
352 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
353 | - )) |
|
354 | - ->execute(); |
|
355 | - |
|
356 | - $data = $stmt->fetch(); |
|
357 | - |
|
358 | - /* |
|
313 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
314 | + $qb->orWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))); |
|
315 | + } |
|
316 | + |
|
317 | + $qb->execute(); |
|
318 | + } |
|
319 | + |
|
320 | + /** |
|
321 | + * Unshare a share from the recipient. If this is a group share |
|
322 | + * this means we need a special entry in the share db. |
|
323 | + * |
|
324 | + * @param \OCP\Share\IShare $share |
|
325 | + * @param string $recipient UserId of recipient |
|
326 | + * @throws BackendError |
|
327 | + * @throws ProviderException |
|
328 | + */ |
|
329 | + public function deleteFromSelf(\OCP\Share\IShare $share, $recipient) { |
|
330 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
331 | + |
|
332 | + $group = $this->groupManager->get($share->getSharedWith()); |
|
333 | + $user = $this->userManager->get($recipient); |
|
334 | + |
|
335 | + if (is_null($group)) { |
|
336 | + throw new ProviderException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
337 | + } |
|
338 | + |
|
339 | + if (!$group->inGroup($user)) { |
|
340 | + throw new ProviderException('Recipient not in receiving group'); |
|
341 | + } |
|
342 | + |
|
343 | + // Try to fetch user specific share |
|
344 | + $qb = $this->dbConn->getQueryBuilder(); |
|
345 | + $stmt = $qb->select('*') |
|
346 | + ->from('share') |
|
347 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
348 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient))) |
|
349 | + ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
350 | + ->andWhere($qb->expr()->orX( |
|
351 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
352 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
353 | + )) |
|
354 | + ->execute(); |
|
355 | + |
|
356 | + $data = $stmt->fetch(); |
|
357 | + |
|
358 | + /* |
|
359 | 359 | * Check if there already is a user specific group share. |
360 | 360 | * If there is update it (if required). |
361 | 361 | */ |
362 | - if ($data === false) { |
|
363 | - $qb = $this->dbConn->getQueryBuilder(); |
|
364 | - |
|
365 | - $type = $share->getNodeType(); |
|
366 | - |
|
367 | - //Insert new share |
|
368 | - $qb->insert('share') |
|
369 | - ->values([ |
|
370 | - 'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP), |
|
371 | - 'share_with' => $qb->createNamedParameter($recipient), |
|
372 | - 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()), |
|
373 | - 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()), |
|
374 | - 'parent' => $qb->createNamedParameter($share->getId()), |
|
375 | - 'item_type' => $qb->createNamedParameter($type), |
|
376 | - 'item_source' => $qb->createNamedParameter($share->getNodeId()), |
|
377 | - 'file_source' => $qb->createNamedParameter($share->getNodeId()), |
|
378 | - 'file_target' => $qb->createNamedParameter($share->getTarget()), |
|
379 | - 'permissions' => $qb->createNamedParameter(0), |
|
380 | - 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()), |
|
381 | - ])->execute(); |
|
382 | - |
|
383 | - } else if ($data['permissions'] !== 0) { |
|
384 | - |
|
385 | - // Update existing usergroup share |
|
386 | - $qb = $this->dbConn->getQueryBuilder(); |
|
387 | - $qb->update('share') |
|
388 | - ->set('permissions', $qb->createNamedParameter(0)) |
|
389 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id']))) |
|
390 | - ->execute(); |
|
391 | - } |
|
392 | - |
|
393 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
394 | - |
|
395 | - if ($share->getSharedWith() !== $recipient) { |
|
396 | - throw new ProviderException('Recipient does not match'); |
|
397 | - } |
|
398 | - |
|
399 | - // We can just delete user and link shares |
|
400 | - $this->delete($share); |
|
401 | - } else { |
|
402 | - throw new ProviderException('Invalid shareType'); |
|
403 | - } |
|
404 | - } |
|
405 | - |
|
406 | - /** |
|
407 | - * @inheritdoc |
|
408 | - */ |
|
409 | - public function move(\OCP\Share\IShare $share, $recipient) { |
|
410 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
411 | - // Just update the target |
|
412 | - $qb = $this->dbConn->getQueryBuilder(); |
|
413 | - $qb->update('share') |
|
414 | - ->set('file_target', $qb->createNamedParameter($share->getTarget())) |
|
415 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
416 | - ->execute(); |
|
417 | - |
|
418 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
419 | - |
|
420 | - // Check if there is a usergroup share |
|
421 | - $qb = $this->dbConn->getQueryBuilder(); |
|
422 | - $stmt = $qb->select('id') |
|
423 | - ->from('share') |
|
424 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
425 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient))) |
|
426 | - ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
427 | - ->andWhere($qb->expr()->orX( |
|
428 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
429 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
430 | - )) |
|
431 | - ->setMaxResults(1) |
|
432 | - ->execute(); |
|
433 | - |
|
434 | - $data = $stmt->fetch(); |
|
435 | - $stmt->closeCursor(); |
|
436 | - |
|
437 | - if ($data === false) { |
|
438 | - // No usergroup share yet. Create one. |
|
439 | - $qb = $this->dbConn->getQueryBuilder(); |
|
440 | - $qb->insert('share') |
|
441 | - ->values([ |
|
442 | - 'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP), |
|
443 | - 'share_with' => $qb->createNamedParameter($recipient), |
|
444 | - 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()), |
|
445 | - 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()), |
|
446 | - 'parent' => $qb->createNamedParameter($share->getId()), |
|
447 | - 'item_type' => $qb->createNamedParameter($share->getNode() instanceof File ? 'file' : 'folder'), |
|
448 | - 'item_source' => $qb->createNamedParameter($share->getNode()->getId()), |
|
449 | - 'file_source' => $qb->createNamedParameter($share->getNode()->getId()), |
|
450 | - 'file_target' => $qb->createNamedParameter($share->getTarget()), |
|
451 | - 'permissions' => $qb->createNamedParameter($share->getPermissions()), |
|
452 | - 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()), |
|
453 | - ])->execute(); |
|
454 | - } else { |
|
455 | - // Already a usergroup share. Update it. |
|
456 | - $qb = $this->dbConn->getQueryBuilder(); |
|
457 | - $qb->update('share') |
|
458 | - ->set('file_target', $qb->createNamedParameter($share->getTarget())) |
|
459 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id']))) |
|
460 | - ->execute(); |
|
461 | - } |
|
462 | - } |
|
463 | - |
|
464 | - return $share; |
|
465 | - } |
|
466 | - |
|
467 | - public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
468 | - $qb = $this->dbConn->getQueryBuilder(); |
|
469 | - $qb->select('*') |
|
470 | - ->from('share', 's') |
|
471 | - ->andWhere($qb->expr()->orX( |
|
472 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
473 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
474 | - )); |
|
475 | - |
|
476 | - $qb->andWhere($qb->expr()->orX( |
|
477 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
478 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
479 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)) |
|
480 | - )); |
|
481 | - |
|
482 | - /** |
|
483 | - * Reshares for this user are shares where they are the owner. |
|
484 | - */ |
|
485 | - if ($reshares === false) { |
|
486 | - $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
487 | - } else { |
|
488 | - $qb->andWhere( |
|
489 | - $qb->expr()->orX( |
|
490 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
491 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
492 | - ) |
|
493 | - ); |
|
494 | - } |
|
495 | - |
|
496 | - $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
497 | - $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
498 | - |
|
499 | - $qb->orderBy('id'); |
|
500 | - |
|
501 | - $cursor = $qb->execute(); |
|
502 | - $shares = []; |
|
503 | - while ($data = $cursor->fetch()) { |
|
504 | - $shares[$data['fileid']][] = $this->createShare($data); |
|
505 | - } |
|
506 | - $cursor->closeCursor(); |
|
507 | - |
|
508 | - return $shares; |
|
509 | - } |
|
510 | - |
|
511 | - /** |
|
512 | - * @inheritdoc |
|
513 | - */ |
|
514 | - public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
515 | - $qb = $this->dbConn->getQueryBuilder(); |
|
516 | - $qb->select('*') |
|
517 | - ->from('share') |
|
518 | - ->andWhere($qb->expr()->orX( |
|
519 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
520 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
521 | - )); |
|
522 | - |
|
523 | - $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter($shareType))); |
|
524 | - |
|
525 | - /** |
|
526 | - * Reshares for this user are shares where they are the owner. |
|
527 | - */ |
|
528 | - if ($reshares === false) { |
|
529 | - $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
530 | - } else { |
|
531 | - $qb->andWhere( |
|
532 | - $qb->expr()->orX( |
|
533 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
534 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
535 | - ) |
|
536 | - ); |
|
537 | - } |
|
538 | - |
|
539 | - if ($node !== null) { |
|
540 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
541 | - } |
|
542 | - |
|
543 | - if ($limit !== -1) { |
|
544 | - $qb->setMaxResults($limit); |
|
545 | - } |
|
546 | - |
|
547 | - $qb->setFirstResult($offset); |
|
548 | - $qb->orderBy('id'); |
|
549 | - |
|
550 | - $cursor = $qb->execute(); |
|
551 | - $shares = []; |
|
552 | - while($data = $cursor->fetch()) { |
|
553 | - $shares[] = $this->createShare($data); |
|
554 | - } |
|
555 | - $cursor->closeCursor(); |
|
556 | - |
|
557 | - return $shares; |
|
558 | - } |
|
559 | - |
|
560 | - /** |
|
561 | - * @inheritdoc |
|
562 | - */ |
|
563 | - public function getShareById($id, $recipientId = null) { |
|
564 | - $qb = $this->dbConn->getQueryBuilder(); |
|
565 | - |
|
566 | - $qb->select('*') |
|
567 | - ->from('share') |
|
568 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
569 | - ->andWhere( |
|
570 | - $qb->expr()->in( |
|
571 | - 'share_type', |
|
572 | - $qb->createNamedParameter([ |
|
573 | - \OCP\Share::SHARE_TYPE_USER, |
|
574 | - \OCP\Share::SHARE_TYPE_GROUP, |
|
575 | - \OCP\Share::SHARE_TYPE_LINK, |
|
576 | - ], IQueryBuilder::PARAM_INT_ARRAY) |
|
577 | - ) |
|
578 | - ) |
|
579 | - ->andWhere($qb->expr()->orX( |
|
580 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
581 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
582 | - )); |
|
583 | - |
|
584 | - $cursor = $qb->execute(); |
|
585 | - $data = $cursor->fetch(); |
|
586 | - $cursor->closeCursor(); |
|
587 | - |
|
588 | - if ($data === false) { |
|
589 | - throw new ShareNotFound(); |
|
590 | - } |
|
591 | - |
|
592 | - try { |
|
593 | - $share = $this->createShare($data); |
|
594 | - } catch (InvalidShare $e) { |
|
595 | - throw new ShareNotFound(); |
|
596 | - } |
|
597 | - |
|
598 | - // If the recipient is set for a group share resolve to that user |
|
599 | - if ($recipientId !== null && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
600 | - $share = $this->resolveGroupShares([$share], $recipientId)[0]; |
|
601 | - } |
|
602 | - |
|
603 | - return $share; |
|
604 | - } |
|
605 | - |
|
606 | - /** |
|
607 | - * Get shares for a given path |
|
608 | - * |
|
609 | - * @param \OCP\Files\Node $path |
|
610 | - * @return \OCP\Share\IShare[] |
|
611 | - */ |
|
612 | - public function getSharesByPath(Node $path) { |
|
613 | - $qb = $this->dbConn->getQueryBuilder(); |
|
614 | - |
|
615 | - $cursor = $qb->select('*') |
|
616 | - ->from('share') |
|
617 | - ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
618 | - ->andWhere( |
|
619 | - $qb->expr()->orX( |
|
620 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
621 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)) |
|
622 | - ) |
|
623 | - ) |
|
624 | - ->andWhere($qb->expr()->orX( |
|
625 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
626 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
627 | - )) |
|
628 | - ->execute(); |
|
629 | - |
|
630 | - $shares = []; |
|
631 | - while($data = $cursor->fetch()) { |
|
632 | - $shares[] = $this->createShare($data); |
|
633 | - } |
|
634 | - $cursor->closeCursor(); |
|
635 | - |
|
636 | - return $shares; |
|
637 | - } |
|
638 | - |
|
639 | - /** |
|
640 | - * Returns whether the given database result can be interpreted as |
|
641 | - * a share with accessible file (not trashed, not deleted) |
|
642 | - */ |
|
643 | - private function isAccessibleResult($data) { |
|
644 | - // exclude shares leading to deleted file entries |
|
645 | - if ($data['fileid'] === null) { |
|
646 | - return false; |
|
647 | - } |
|
648 | - |
|
649 | - // exclude shares leading to trashbin on home storages |
|
650 | - $pathSections = explode('/', $data['path'], 2); |
|
651 | - // FIXME: would not detect rare md5'd home storage case properly |
|
652 | - if ($pathSections[0] !== 'files' |
|
653 | - && in_array(explode(':', $data['storage_string_id'], 2)[0], array('home', 'object'))) { |
|
654 | - return false; |
|
655 | - } |
|
656 | - return true; |
|
657 | - } |
|
658 | - |
|
659 | - /** |
|
660 | - * @inheritdoc |
|
661 | - */ |
|
662 | - public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
663 | - /** @var Share[] $shares */ |
|
664 | - $shares = []; |
|
665 | - |
|
666 | - if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
667 | - //Get shares directly with this user |
|
668 | - $qb = $this->dbConn->getQueryBuilder(); |
|
669 | - $qb->select('s.*', |
|
670 | - 'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash', |
|
671 | - 'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime', |
|
672 | - 'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum' |
|
673 | - ) |
|
674 | - ->selectAlias('st.id', 'storage_string_id') |
|
675 | - ->from('share', 's') |
|
676 | - ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')) |
|
677 | - ->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id')); |
|
678 | - |
|
679 | - // Order by id |
|
680 | - $qb->orderBy('s.id'); |
|
681 | - |
|
682 | - // Set limit and offset |
|
683 | - if ($limit !== -1) { |
|
684 | - $qb->setMaxResults($limit); |
|
685 | - } |
|
686 | - $qb->setFirstResult($offset); |
|
687 | - |
|
688 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER))) |
|
689 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))) |
|
690 | - ->andWhere($qb->expr()->orX( |
|
691 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
692 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
693 | - )); |
|
694 | - |
|
695 | - // Filter by node if provided |
|
696 | - if ($node !== null) { |
|
697 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
698 | - } |
|
699 | - |
|
700 | - $cursor = $qb->execute(); |
|
701 | - |
|
702 | - while($data = $cursor->fetch()) { |
|
703 | - if ($this->isAccessibleResult($data)) { |
|
704 | - $shares[] = $this->createShare($data); |
|
705 | - } |
|
706 | - } |
|
707 | - $cursor->closeCursor(); |
|
708 | - |
|
709 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
710 | - $user = $this->userManager->get($userId); |
|
711 | - $allGroups = $this->groupManager->getUserGroups($user); |
|
712 | - |
|
713 | - /** @var Share[] $shares2 */ |
|
714 | - $shares2 = []; |
|
715 | - |
|
716 | - $start = 0; |
|
717 | - while(true) { |
|
718 | - $groups = array_slice($allGroups, $start, 100); |
|
719 | - $start += 100; |
|
720 | - |
|
721 | - if ($groups === []) { |
|
722 | - break; |
|
723 | - } |
|
724 | - |
|
725 | - $qb = $this->dbConn->getQueryBuilder(); |
|
726 | - $qb->select('s.*', |
|
727 | - 'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash', |
|
728 | - 'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime', |
|
729 | - 'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum' |
|
730 | - ) |
|
731 | - ->selectAlias('st.id', 'storage_string_id') |
|
732 | - ->from('share', 's') |
|
733 | - ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')) |
|
734 | - ->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id')) |
|
735 | - ->orderBy('s.id') |
|
736 | - ->setFirstResult(0); |
|
737 | - |
|
738 | - if ($limit !== -1) { |
|
739 | - $qb->setMaxResults($limit - count($shares)); |
|
740 | - } |
|
741 | - |
|
742 | - // Filter by node if provided |
|
743 | - if ($node !== null) { |
|
744 | - $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
745 | - } |
|
746 | - |
|
747 | - $groups = array_map(function(IGroup $group) { return $group->getGID(); }, $groups); |
|
748 | - |
|
749 | - $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
750 | - ->andWhere($qb->expr()->in('share_with', $qb->createNamedParameter( |
|
751 | - $groups, |
|
752 | - IQueryBuilder::PARAM_STR_ARRAY |
|
753 | - ))) |
|
754 | - ->andWhere($qb->expr()->orX( |
|
755 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
756 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
757 | - )); |
|
758 | - |
|
759 | - $cursor = $qb->execute(); |
|
760 | - while($data = $cursor->fetch()) { |
|
761 | - if ($offset > 0) { |
|
762 | - $offset--; |
|
763 | - continue; |
|
764 | - } |
|
765 | - |
|
766 | - if ($this->isAccessibleResult($data)) { |
|
767 | - $shares2[] = $this->createShare($data); |
|
768 | - } |
|
769 | - } |
|
770 | - $cursor->closeCursor(); |
|
771 | - } |
|
772 | - |
|
773 | - /* |
|
362 | + if ($data === false) { |
|
363 | + $qb = $this->dbConn->getQueryBuilder(); |
|
364 | + |
|
365 | + $type = $share->getNodeType(); |
|
366 | + |
|
367 | + //Insert new share |
|
368 | + $qb->insert('share') |
|
369 | + ->values([ |
|
370 | + 'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP), |
|
371 | + 'share_with' => $qb->createNamedParameter($recipient), |
|
372 | + 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()), |
|
373 | + 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()), |
|
374 | + 'parent' => $qb->createNamedParameter($share->getId()), |
|
375 | + 'item_type' => $qb->createNamedParameter($type), |
|
376 | + 'item_source' => $qb->createNamedParameter($share->getNodeId()), |
|
377 | + 'file_source' => $qb->createNamedParameter($share->getNodeId()), |
|
378 | + 'file_target' => $qb->createNamedParameter($share->getTarget()), |
|
379 | + 'permissions' => $qb->createNamedParameter(0), |
|
380 | + 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()), |
|
381 | + ])->execute(); |
|
382 | + |
|
383 | + } else if ($data['permissions'] !== 0) { |
|
384 | + |
|
385 | + // Update existing usergroup share |
|
386 | + $qb = $this->dbConn->getQueryBuilder(); |
|
387 | + $qb->update('share') |
|
388 | + ->set('permissions', $qb->createNamedParameter(0)) |
|
389 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id']))) |
|
390 | + ->execute(); |
|
391 | + } |
|
392 | + |
|
393 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
394 | + |
|
395 | + if ($share->getSharedWith() !== $recipient) { |
|
396 | + throw new ProviderException('Recipient does not match'); |
|
397 | + } |
|
398 | + |
|
399 | + // We can just delete user and link shares |
|
400 | + $this->delete($share); |
|
401 | + } else { |
|
402 | + throw new ProviderException('Invalid shareType'); |
|
403 | + } |
|
404 | + } |
|
405 | + |
|
406 | + /** |
|
407 | + * @inheritdoc |
|
408 | + */ |
|
409 | + public function move(\OCP\Share\IShare $share, $recipient) { |
|
410 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
411 | + // Just update the target |
|
412 | + $qb = $this->dbConn->getQueryBuilder(); |
|
413 | + $qb->update('share') |
|
414 | + ->set('file_target', $qb->createNamedParameter($share->getTarget())) |
|
415 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId()))) |
|
416 | + ->execute(); |
|
417 | + |
|
418 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
419 | + |
|
420 | + // Check if there is a usergroup share |
|
421 | + $qb = $this->dbConn->getQueryBuilder(); |
|
422 | + $stmt = $qb->select('id') |
|
423 | + ->from('share') |
|
424 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
425 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient))) |
|
426 | + ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId()))) |
|
427 | + ->andWhere($qb->expr()->orX( |
|
428 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
429 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
430 | + )) |
|
431 | + ->setMaxResults(1) |
|
432 | + ->execute(); |
|
433 | + |
|
434 | + $data = $stmt->fetch(); |
|
435 | + $stmt->closeCursor(); |
|
436 | + |
|
437 | + if ($data === false) { |
|
438 | + // No usergroup share yet. Create one. |
|
439 | + $qb = $this->dbConn->getQueryBuilder(); |
|
440 | + $qb->insert('share') |
|
441 | + ->values([ |
|
442 | + 'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP), |
|
443 | + 'share_with' => $qb->createNamedParameter($recipient), |
|
444 | + 'uid_owner' => $qb->createNamedParameter($share->getShareOwner()), |
|
445 | + 'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()), |
|
446 | + 'parent' => $qb->createNamedParameter($share->getId()), |
|
447 | + 'item_type' => $qb->createNamedParameter($share->getNode() instanceof File ? 'file' : 'folder'), |
|
448 | + 'item_source' => $qb->createNamedParameter($share->getNode()->getId()), |
|
449 | + 'file_source' => $qb->createNamedParameter($share->getNode()->getId()), |
|
450 | + 'file_target' => $qb->createNamedParameter($share->getTarget()), |
|
451 | + 'permissions' => $qb->createNamedParameter($share->getPermissions()), |
|
452 | + 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()), |
|
453 | + ])->execute(); |
|
454 | + } else { |
|
455 | + // Already a usergroup share. Update it. |
|
456 | + $qb = $this->dbConn->getQueryBuilder(); |
|
457 | + $qb->update('share') |
|
458 | + ->set('file_target', $qb->createNamedParameter($share->getTarget())) |
|
459 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id']))) |
|
460 | + ->execute(); |
|
461 | + } |
|
462 | + } |
|
463 | + |
|
464 | + return $share; |
|
465 | + } |
|
466 | + |
|
467 | + public function getSharesInFolder($userId, Folder $node, $reshares) { |
|
468 | + $qb = $this->dbConn->getQueryBuilder(); |
|
469 | + $qb->select('*') |
|
470 | + ->from('share', 's') |
|
471 | + ->andWhere($qb->expr()->orX( |
|
472 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
473 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
474 | + )); |
|
475 | + |
|
476 | + $qb->andWhere($qb->expr()->orX( |
|
477 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
478 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
479 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)) |
|
480 | + )); |
|
481 | + |
|
482 | + /** |
|
483 | + * Reshares for this user are shares where they are the owner. |
|
484 | + */ |
|
485 | + if ($reshares === false) { |
|
486 | + $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
487 | + } else { |
|
488 | + $qb->andWhere( |
|
489 | + $qb->expr()->orX( |
|
490 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
491 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
492 | + ) |
|
493 | + ); |
|
494 | + } |
|
495 | + |
|
496 | + $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
497 | + $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
|
498 | + |
|
499 | + $qb->orderBy('id'); |
|
500 | + |
|
501 | + $cursor = $qb->execute(); |
|
502 | + $shares = []; |
|
503 | + while ($data = $cursor->fetch()) { |
|
504 | + $shares[$data['fileid']][] = $this->createShare($data); |
|
505 | + } |
|
506 | + $cursor->closeCursor(); |
|
507 | + |
|
508 | + return $shares; |
|
509 | + } |
|
510 | + |
|
511 | + /** |
|
512 | + * @inheritdoc |
|
513 | + */ |
|
514 | + public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) { |
|
515 | + $qb = $this->dbConn->getQueryBuilder(); |
|
516 | + $qb->select('*') |
|
517 | + ->from('share') |
|
518 | + ->andWhere($qb->expr()->orX( |
|
519 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
520 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
521 | + )); |
|
522 | + |
|
523 | + $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter($shareType))); |
|
524 | + |
|
525 | + /** |
|
526 | + * Reshares for this user are shares where they are the owner. |
|
527 | + */ |
|
528 | + if ($reshares === false) { |
|
529 | + $qb->andWhere($qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))); |
|
530 | + } else { |
|
531 | + $qb->andWhere( |
|
532 | + $qb->expr()->orX( |
|
533 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)), |
|
534 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)) |
|
535 | + ) |
|
536 | + ); |
|
537 | + } |
|
538 | + |
|
539 | + if ($node !== null) { |
|
540 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
541 | + } |
|
542 | + |
|
543 | + if ($limit !== -1) { |
|
544 | + $qb->setMaxResults($limit); |
|
545 | + } |
|
546 | + |
|
547 | + $qb->setFirstResult($offset); |
|
548 | + $qb->orderBy('id'); |
|
549 | + |
|
550 | + $cursor = $qb->execute(); |
|
551 | + $shares = []; |
|
552 | + while($data = $cursor->fetch()) { |
|
553 | + $shares[] = $this->createShare($data); |
|
554 | + } |
|
555 | + $cursor->closeCursor(); |
|
556 | + |
|
557 | + return $shares; |
|
558 | + } |
|
559 | + |
|
560 | + /** |
|
561 | + * @inheritdoc |
|
562 | + */ |
|
563 | + public function getShareById($id, $recipientId = null) { |
|
564 | + $qb = $this->dbConn->getQueryBuilder(); |
|
565 | + |
|
566 | + $qb->select('*') |
|
567 | + ->from('share') |
|
568 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
569 | + ->andWhere( |
|
570 | + $qb->expr()->in( |
|
571 | + 'share_type', |
|
572 | + $qb->createNamedParameter([ |
|
573 | + \OCP\Share::SHARE_TYPE_USER, |
|
574 | + \OCP\Share::SHARE_TYPE_GROUP, |
|
575 | + \OCP\Share::SHARE_TYPE_LINK, |
|
576 | + ], IQueryBuilder::PARAM_INT_ARRAY) |
|
577 | + ) |
|
578 | + ) |
|
579 | + ->andWhere($qb->expr()->orX( |
|
580 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
581 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
582 | + )); |
|
583 | + |
|
584 | + $cursor = $qb->execute(); |
|
585 | + $data = $cursor->fetch(); |
|
586 | + $cursor->closeCursor(); |
|
587 | + |
|
588 | + if ($data === false) { |
|
589 | + throw new ShareNotFound(); |
|
590 | + } |
|
591 | + |
|
592 | + try { |
|
593 | + $share = $this->createShare($data); |
|
594 | + } catch (InvalidShare $e) { |
|
595 | + throw new ShareNotFound(); |
|
596 | + } |
|
597 | + |
|
598 | + // If the recipient is set for a group share resolve to that user |
|
599 | + if ($recipientId !== null && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
600 | + $share = $this->resolveGroupShares([$share], $recipientId)[0]; |
|
601 | + } |
|
602 | + |
|
603 | + return $share; |
|
604 | + } |
|
605 | + |
|
606 | + /** |
|
607 | + * Get shares for a given path |
|
608 | + * |
|
609 | + * @param \OCP\Files\Node $path |
|
610 | + * @return \OCP\Share\IShare[] |
|
611 | + */ |
|
612 | + public function getSharesByPath(Node $path) { |
|
613 | + $qb = $this->dbConn->getQueryBuilder(); |
|
614 | + |
|
615 | + $cursor = $qb->select('*') |
|
616 | + ->from('share') |
|
617 | + ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId()))) |
|
618 | + ->andWhere( |
|
619 | + $qb->expr()->orX( |
|
620 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
621 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)) |
|
622 | + ) |
|
623 | + ) |
|
624 | + ->andWhere($qb->expr()->orX( |
|
625 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
626 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
627 | + )) |
|
628 | + ->execute(); |
|
629 | + |
|
630 | + $shares = []; |
|
631 | + while($data = $cursor->fetch()) { |
|
632 | + $shares[] = $this->createShare($data); |
|
633 | + } |
|
634 | + $cursor->closeCursor(); |
|
635 | + |
|
636 | + return $shares; |
|
637 | + } |
|
638 | + |
|
639 | + /** |
|
640 | + * Returns whether the given database result can be interpreted as |
|
641 | + * a share with accessible file (not trashed, not deleted) |
|
642 | + */ |
|
643 | + private function isAccessibleResult($data) { |
|
644 | + // exclude shares leading to deleted file entries |
|
645 | + if ($data['fileid'] === null) { |
|
646 | + return false; |
|
647 | + } |
|
648 | + |
|
649 | + // exclude shares leading to trashbin on home storages |
|
650 | + $pathSections = explode('/', $data['path'], 2); |
|
651 | + // FIXME: would not detect rare md5'd home storage case properly |
|
652 | + if ($pathSections[0] !== 'files' |
|
653 | + && in_array(explode(':', $data['storage_string_id'], 2)[0], array('home', 'object'))) { |
|
654 | + return false; |
|
655 | + } |
|
656 | + return true; |
|
657 | + } |
|
658 | + |
|
659 | + /** |
|
660 | + * @inheritdoc |
|
661 | + */ |
|
662 | + public function getSharedWith($userId, $shareType, $node, $limit, $offset) { |
|
663 | + /** @var Share[] $shares */ |
|
664 | + $shares = []; |
|
665 | + |
|
666 | + if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
667 | + //Get shares directly with this user |
|
668 | + $qb = $this->dbConn->getQueryBuilder(); |
|
669 | + $qb->select('s.*', |
|
670 | + 'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash', |
|
671 | + 'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime', |
|
672 | + 'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum' |
|
673 | + ) |
|
674 | + ->selectAlias('st.id', 'storage_string_id') |
|
675 | + ->from('share', 's') |
|
676 | + ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')) |
|
677 | + ->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id')); |
|
678 | + |
|
679 | + // Order by id |
|
680 | + $qb->orderBy('s.id'); |
|
681 | + |
|
682 | + // Set limit and offset |
|
683 | + if ($limit !== -1) { |
|
684 | + $qb->setMaxResults($limit); |
|
685 | + } |
|
686 | + $qb->setFirstResult($offset); |
|
687 | + |
|
688 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER))) |
|
689 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))) |
|
690 | + ->andWhere($qb->expr()->orX( |
|
691 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
692 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
693 | + )); |
|
694 | + |
|
695 | + // Filter by node if provided |
|
696 | + if ($node !== null) { |
|
697 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
698 | + } |
|
699 | + |
|
700 | + $cursor = $qb->execute(); |
|
701 | + |
|
702 | + while($data = $cursor->fetch()) { |
|
703 | + if ($this->isAccessibleResult($data)) { |
|
704 | + $shares[] = $this->createShare($data); |
|
705 | + } |
|
706 | + } |
|
707 | + $cursor->closeCursor(); |
|
708 | + |
|
709 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
710 | + $user = $this->userManager->get($userId); |
|
711 | + $allGroups = $this->groupManager->getUserGroups($user); |
|
712 | + |
|
713 | + /** @var Share[] $shares2 */ |
|
714 | + $shares2 = []; |
|
715 | + |
|
716 | + $start = 0; |
|
717 | + while(true) { |
|
718 | + $groups = array_slice($allGroups, $start, 100); |
|
719 | + $start += 100; |
|
720 | + |
|
721 | + if ($groups === []) { |
|
722 | + break; |
|
723 | + } |
|
724 | + |
|
725 | + $qb = $this->dbConn->getQueryBuilder(); |
|
726 | + $qb->select('s.*', |
|
727 | + 'f.fileid', 'f.path', 'f.permissions AS f_permissions', 'f.storage', 'f.path_hash', |
|
728 | + 'f.parent AS f_parent', 'f.name', 'f.mimetype', 'f.mimepart', 'f.size', 'f.mtime', 'f.storage_mtime', |
|
729 | + 'f.encrypted', 'f.unencrypted_size', 'f.etag', 'f.checksum' |
|
730 | + ) |
|
731 | + ->selectAlias('st.id', 'storage_string_id') |
|
732 | + ->from('share', 's') |
|
733 | + ->leftJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')) |
|
734 | + ->leftJoin('f', 'storages', 'st', $qb->expr()->eq('f.storage', 'st.numeric_id')) |
|
735 | + ->orderBy('s.id') |
|
736 | + ->setFirstResult(0); |
|
737 | + |
|
738 | + if ($limit !== -1) { |
|
739 | + $qb->setMaxResults($limit - count($shares)); |
|
740 | + } |
|
741 | + |
|
742 | + // Filter by node if provided |
|
743 | + if ($node !== null) { |
|
744 | + $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId()))); |
|
745 | + } |
|
746 | + |
|
747 | + $groups = array_map(function(IGroup $group) { return $group->getGID(); }, $groups); |
|
748 | + |
|
749 | + $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
750 | + ->andWhere($qb->expr()->in('share_with', $qb->createNamedParameter( |
|
751 | + $groups, |
|
752 | + IQueryBuilder::PARAM_STR_ARRAY |
|
753 | + ))) |
|
754 | + ->andWhere($qb->expr()->orX( |
|
755 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
756 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
757 | + )); |
|
758 | + |
|
759 | + $cursor = $qb->execute(); |
|
760 | + while($data = $cursor->fetch()) { |
|
761 | + if ($offset > 0) { |
|
762 | + $offset--; |
|
763 | + continue; |
|
764 | + } |
|
765 | + |
|
766 | + if ($this->isAccessibleResult($data)) { |
|
767 | + $shares2[] = $this->createShare($data); |
|
768 | + } |
|
769 | + } |
|
770 | + $cursor->closeCursor(); |
|
771 | + } |
|
772 | + |
|
773 | + /* |
|
774 | 774 | * Resolve all group shares to user specific shares |
775 | 775 | */ |
776 | - $shares = $this->resolveGroupShares($shares2, $userId); |
|
777 | - } else { |
|
778 | - throw new BackendError('Invalid backend'); |
|
779 | - } |
|
780 | - |
|
781 | - |
|
782 | - return $shares; |
|
783 | - } |
|
784 | - |
|
785 | - /** |
|
786 | - * Get a share by token |
|
787 | - * |
|
788 | - * @param string $token |
|
789 | - * @return \OCP\Share\IShare |
|
790 | - * @throws ShareNotFound |
|
791 | - */ |
|
792 | - public function getShareByToken($token) { |
|
793 | - $qb = $this->dbConn->getQueryBuilder(); |
|
794 | - |
|
795 | - $cursor = $qb->select('*') |
|
796 | - ->from('share') |
|
797 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))) |
|
798 | - ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
799 | - ->andWhere($qb->expr()->orX( |
|
800 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
801 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
802 | - )) |
|
803 | - ->execute(); |
|
804 | - |
|
805 | - $data = $cursor->fetch(); |
|
806 | - |
|
807 | - if ($data === false) { |
|
808 | - throw new ShareNotFound(); |
|
809 | - } |
|
810 | - |
|
811 | - try { |
|
812 | - $share = $this->createShare($data); |
|
813 | - } catch (InvalidShare $e) { |
|
814 | - throw new ShareNotFound(); |
|
815 | - } |
|
816 | - |
|
817 | - return $share; |
|
818 | - } |
|
819 | - |
|
820 | - /** |
|
821 | - * Create a share object from an database row |
|
822 | - * |
|
823 | - * @param mixed[] $data |
|
824 | - * @return \OCP\Share\IShare |
|
825 | - * @throws InvalidShare |
|
826 | - */ |
|
827 | - private function createShare($data) { |
|
828 | - $share = new Share($this->rootFolder, $this->userManager); |
|
829 | - $share->setId((int)$data['id']) |
|
830 | - ->setShareType((int)$data['share_type']) |
|
831 | - ->setPermissions((int)$data['permissions']) |
|
832 | - ->setTarget($data['file_target']) |
|
833 | - ->setMailSend((bool)$data['mail_send']); |
|
834 | - |
|
835 | - $shareTime = new \DateTime(); |
|
836 | - $shareTime->setTimestamp((int)$data['stime']); |
|
837 | - $share->setShareTime($shareTime); |
|
838 | - |
|
839 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
840 | - $share->setSharedWith($data['share_with']); |
|
841 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
842 | - $share->setSharedWith($data['share_with']); |
|
843 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
844 | - $share->setPassword($data['password']); |
|
845 | - $share->setToken($data['token']); |
|
846 | - } |
|
847 | - |
|
848 | - $share->setSharedBy($data['uid_initiator']); |
|
849 | - $share->setShareOwner($data['uid_owner']); |
|
850 | - |
|
851 | - $share->setNodeId((int)$data['file_source']); |
|
852 | - $share->setNodeType($data['item_type']); |
|
853 | - |
|
854 | - if ($data['expiration'] !== null) { |
|
855 | - $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); |
|
856 | - $share->setExpirationDate($expiration); |
|
857 | - } |
|
858 | - |
|
859 | - if (isset($data['f_permissions'])) { |
|
860 | - $entryData = $data; |
|
861 | - $entryData['permissions'] = $entryData['f_permissions']; |
|
862 | - $entryData['parent'] = $entryData['f_parent'];; |
|
863 | - $share->setNodeCacheEntry(Cache::cacheEntryFromData($entryData, |
|
864 | - \OC::$server->getMimeTypeLoader())); |
|
865 | - } |
|
866 | - |
|
867 | - $share->setProviderId($this->identifier()); |
|
868 | - |
|
869 | - return $share; |
|
870 | - } |
|
871 | - |
|
872 | - /** |
|
873 | - * @param Share[] $shares |
|
874 | - * @param $userId |
|
875 | - * @return Share[] The updates shares if no update is found for a share return the original |
|
876 | - */ |
|
877 | - private function resolveGroupShares($shares, $userId) { |
|
878 | - $result = []; |
|
879 | - |
|
880 | - $start = 0; |
|
881 | - while(true) { |
|
882 | - /** @var Share[] $shareSlice */ |
|
883 | - $shareSlice = array_slice($shares, $start, 100); |
|
884 | - $start += 100; |
|
885 | - |
|
886 | - if ($shareSlice === []) { |
|
887 | - break; |
|
888 | - } |
|
889 | - |
|
890 | - /** @var int[] $ids */ |
|
891 | - $ids = []; |
|
892 | - /** @var Share[] $shareMap */ |
|
893 | - $shareMap = []; |
|
894 | - |
|
895 | - foreach ($shareSlice as $share) { |
|
896 | - $ids[] = (int)$share->getId(); |
|
897 | - $shareMap[$share->getId()] = $share; |
|
898 | - } |
|
899 | - |
|
900 | - $qb = $this->dbConn->getQueryBuilder(); |
|
901 | - |
|
902 | - $query = $qb->select('*') |
|
903 | - ->from('share') |
|
904 | - ->where($qb->expr()->in('parent', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
905 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))) |
|
906 | - ->andWhere($qb->expr()->orX( |
|
907 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
908 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
909 | - )); |
|
910 | - |
|
911 | - $stmt = $query->execute(); |
|
912 | - |
|
913 | - while($data = $stmt->fetch()) { |
|
914 | - $shareMap[$data['parent']]->setPermissions((int)$data['permissions']); |
|
915 | - $shareMap[$data['parent']]->setTarget($data['file_target']); |
|
916 | - } |
|
917 | - |
|
918 | - $stmt->closeCursor(); |
|
919 | - |
|
920 | - foreach ($shareMap as $share) { |
|
921 | - $result[] = $share; |
|
922 | - } |
|
923 | - } |
|
924 | - |
|
925 | - return $result; |
|
926 | - } |
|
927 | - |
|
928 | - /** |
|
929 | - * A user is deleted from the system |
|
930 | - * So clean up the relevant shares. |
|
931 | - * |
|
932 | - * @param string $uid |
|
933 | - * @param int $shareType |
|
934 | - */ |
|
935 | - public function userDeleted($uid, $shareType) { |
|
936 | - $qb = $this->dbConn->getQueryBuilder(); |
|
937 | - |
|
938 | - $qb->delete('share'); |
|
939 | - |
|
940 | - if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
941 | - /* |
|
776 | + $shares = $this->resolveGroupShares($shares2, $userId); |
|
777 | + } else { |
|
778 | + throw new BackendError('Invalid backend'); |
|
779 | + } |
|
780 | + |
|
781 | + |
|
782 | + return $shares; |
|
783 | + } |
|
784 | + |
|
785 | + /** |
|
786 | + * Get a share by token |
|
787 | + * |
|
788 | + * @param string $token |
|
789 | + * @return \OCP\Share\IShare |
|
790 | + * @throws ShareNotFound |
|
791 | + */ |
|
792 | + public function getShareByToken($token) { |
|
793 | + $qb = $this->dbConn->getQueryBuilder(); |
|
794 | + |
|
795 | + $cursor = $qb->select('*') |
|
796 | + ->from('share') |
|
797 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))) |
|
798 | + ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
799 | + ->andWhere($qb->expr()->orX( |
|
800 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
801 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
802 | + )) |
|
803 | + ->execute(); |
|
804 | + |
|
805 | + $data = $cursor->fetch(); |
|
806 | + |
|
807 | + if ($data === false) { |
|
808 | + throw new ShareNotFound(); |
|
809 | + } |
|
810 | + |
|
811 | + try { |
|
812 | + $share = $this->createShare($data); |
|
813 | + } catch (InvalidShare $e) { |
|
814 | + throw new ShareNotFound(); |
|
815 | + } |
|
816 | + |
|
817 | + return $share; |
|
818 | + } |
|
819 | + |
|
820 | + /** |
|
821 | + * Create a share object from an database row |
|
822 | + * |
|
823 | + * @param mixed[] $data |
|
824 | + * @return \OCP\Share\IShare |
|
825 | + * @throws InvalidShare |
|
826 | + */ |
|
827 | + private function createShare($data) { |
|
828 | + $share = new Share($this->rootFolder, $this->userManager); |
|
829 | + $share->setId((int)$data['id']) |
|
830 | + ->setShareType((int)$data['share_type']) |
|
831 | + ->setPermissions((int)$data['permissions']) |
|
832 | + ->setTarget($data['file_target']) |
|
833 | + ->setMailSend((bool)$data['mail_send']); |
|
834 | + |
|
835 | + $shareTime = new \DateTime(); |
|
836 | + $shareTime->setTimestamp((int)$data['stime']); |
|
837 | + $share->setShareTime($shareTime); |
|
838 | + |
|
839 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
|
840 | + $share->setSharedWith($data['share_with']); |
|
841 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) { |
|
842 | + $share->setSharedWith($data['share_with']); |
|
843 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { |
|
844 | + $share->setPassword($data['password']); |
|
845 | + $share->setToken($data['token']); |
|
846 | + } |
|
847 | + |
|
848 | + $share->setSharedBy($data['uid_initiator']); |
|
849 | + $share->setShareOwner($data['uid_owner']); |
|
850 | + |
|
851 | + $share->setNodeId((int)$data['file_source']); |
|
852 | + $share->setNodeType($data['item_type']); |
|
853 | + |
|
854 | + if ($data['expiration'] !== null) { |
|
855 | + $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']); |
|
856 | + $share->setExpirationDate($expiration); |
|
857 | + } |
|
858 | + |
|
859 | + if (isset($data['f_permissions'])) { |
|
860 | + $entryData = $data; |
|
861 | + $entryData['permissions'] = $entryData['f_permissions']; |
|
862 | + $entryData['parent'] = $entryData['f_parent'];; |
|
863 | + $share->setNodeCacheEntry(Cache::cacheEntryFromData($entryData, |
|
864 | + \OC::$server->getMimeTypeLoader())); |
|
865 | + } |
|
866 | + |
|
867 | + $share->setProviderId($this->identifier()); |
|
868 | + |
|
869 | + return $share; |
|
870 | + } |
|
871 | + |
|
872 | + /** |
|
873 | + * @param Share[] $shares |
|
874 | + * @param $userId |
|
875 | + * @return Share[] The updates shares if no update is found for a share return the original |
|
876 | + */ |
|
877 | + private function resolveGroupShares($shares, $userId) { |
|
878 | + $result = []; |
|
879 | + |
|
880 | + $start = 0; |
|
881 | + while(true) { |
|
882 | + /** @var Share[] $shareSlice */ |
|
883 | + $shareSlice = array_slice($shares, $start, 100); |
|
884 | + $start += 100; |
|
885 | + |
|
886 | + if ($shareSlice === []) { |
|
887 | + break; |
|
888 | + } |
|
889 | + |
|
890 | + /** @var int[] $ids */ |
|
891 | + $ids = []; |
|
892 | + /** @var Share[] $shareMap */ |
|
893 | + $shareMap = []; |
|
894 | + |
|
895 | + foreach ($shareSlice as $share) { |
|
896 | + $ids[] = (int)$share->getId(); |
|
897 | + $shareMap[$share->getId()] = $share; |
|
898 | + } |
|
899 | + |
|
900 | + $qb = $this->dbConn->getQueryBuilder(); |
|
901 | + |
|
902 | + $query = $qb->select('*') |
|
903 | + ->from('share') |
|
904 | + ->where($qb->expr()->in('parent', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
905 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId))) |
|
906 | + ->andWhere($qb->expr()->orX( |
|
907 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
908 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
909 | + )); |
|
910 | + |
|
911 | + $stmt = $query->execute(); |
|
912 | + |
|
913 | + while($data = $stmt->fetch()) { |
|
914 | + $shareMap[$data['parent']]->setPermissions((int)$data['permissions']); |
|
915 | + $shareMap[$data['parent']]->setTarget($data['file_target']); |
|
916 | + } |
|
917 | + |
|
918 | + $stmt->closeCursor(); |
|
919 | + |
|
920 | + foreach ($shareMap as $share) { |
|
921 | + $result[] = $share; |
|
922 | + } |
|
923 | + } |
|
924 | + |
|
925 | + return $result; |
|
926 | + } |
|
927 | + |
|
928 | + /** |
|
929 | + * A user is deleted from the system |
|
930 | + * So clean up the relevant shares. |
|
931 | + * |
|
932 | + * @param string $uid |
|
933 | + * @param int $shareType |
|
934 | + */ |
|
935 | + public function userDeleted($uid, $shareType) { |
|
936 | + $qb = $this->dbConn->getQueryBuilder(); |
|
937 | + |
|
938 | + $qb->delete('share'); |
|
939 | + |
|
940 | + if ($shareType === \OCP\Share::SHARE_TYPE_USER) { |
|
941 | + /* |
|
942 | 942 | * Delete all user shares that are owned by this user |
943 | 943 | * or that are received by this user |
944 | 944 | */ |
945 | 945 | |
946 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER))); |
|
946 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER))); |
|
947 | 947 | |
948 | - $qb->andWhere( |
|
949 | - $qb->expr()->orX( |
|
950 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)), |
|
951 | - $qb->expr()->eq('share_with', $qb->createNamedParameter($uid)) |
|
952 | - ) |
|
953 | - ); |
|
954 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
955 | - /* |
|
948 | + $qb->andWhere( |
|
949 | + $qb->expr()->orX( |
|
950 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)), |
|
951 | + $qb->expr()->eq('share_with', $qb->createNamedParameter($uid)) |
|
952 | + ) |
|
953 | + ); |
|
954 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) { |
|
955 | + /* |
|
956 | 956 | * Delete all group shares that are owned by this user |
957 | 957 | * Or special user group shares that are received by this user |
958 | 958 | */ |
959 | - $qb->where( |
|
960 | - $qb->expr()->andX( |
|
961 | - $qb->expr()->orX( |
|
962 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
963 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)) |
|
964 | - ), |
|
965 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)) |
|
966 | - ) |
|
967 | - ); |
|
968 | - |
|
969 | - $qb->orWhere( |
|
970 | - $qb->expr()->andX( |
|
971 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)), |
|
972 | - $qb->expr()->eq('share_with', $qb->createNamedParameter($uid)) |
|
973 | - ) |
|
974 | - ); |
|
975 | - } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { |
|
976 | - /* |
|
959 | + $qb->where( |
|
960 | + $qb->expr()->andX( |
|
961 | + $qb->expr()->orX( |
|
962 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
963 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)) |
|
964 | + ), |
|
965 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)) |
|
966 | + ) |
|
967 | + ); |
|
968 | + |
|
969 | + $qb->orWhere( |
|
970 | + $qb->expr()->andX( |
|
971 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)), |
|
972 | + $qb->expr()->eq('share_with', $qb->createNamedParameter($uid)) |
|
973 | + ) |
|
974 | + ); |
|
975 | + } else if ($shareType === \OCP\Share::SHARE_TYPE_LINK) { |
|
976 | + /* |
|
977 | 977 | * Delete all link shares owned by this user. |
978 | 978 | * And all link shares initiated by this user (until #22327 is in) |
979 | 979 | */ |
980 | - $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))); |
|
981 | - |
|
982 | - $qb->andWhere( |
|
983 | - $qb->expr()->orX( |
|
984 | - $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)), |
|
985 | - $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($uid)) |
|
986 | - ) |
|
987 | - ); |
|
988 | - } |
|
989 | - |
|
990 | - $qb->execute(); |
|
991 | - } |
|
992 | - |
|
993 | - /** |
|
994 | - * Delete all shares received by this group. As well as any custom group |
|
995 | - * shares for group members. |
|
996 | - * |
|
997 | - * @param string $gid |
|
998 | - */ |
|
999 | - public function groupDeleted($gid) { |
|
1000 | - /* |
|
980 | + $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK))); |
|
981 | + |
|
982 | + $qb->andWhere( |
|
983 | + $qb->expr()->orX( |
|
984 | + $qb->expr()->eq('uid_owner', $qb->createNamedParameter($uid)), |
|
985 | + $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($uid)) |
|
986 | + ) |
|
987 | + ); |
|
988 | + } |
|
989 | + |
|
990 | + $qb->execute(); |
|
991 | + } |
|
992 | + |
|
993 | + /** |
|
994 | + * Delete all shares received by this group. As well as any custom group |
|
995 | + * shares for group members. |
|
996 | + * |
|
997 | + * @param string $gid |
|
998 | + */ |
|
999 | + public function groupDeleted($gid) { |
|
1000 | + /* |
|
1001 | 1001 | * First delete all custom group shares for group members |
1002 | 1002 | */ |
1003 | - $qb = $this->dbConn->getQueryBuilder(); |
|
1004 | - $qb->select('id') |
|
1005 | - ->from('share') |
|
1006 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
1007 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
1008 | - |
|
1009 | - $cursor = $qb->execute(); |
|
1010 | - $ids = []; |
|
1011 | - while($row = $cursor->fetch()) { |
|
1012 | - $ids[] = (int)$row['id']; |
|
1013 | - } |
|
1014 | - $cursor->closeCursor(); |
|
1015 | - |
|
1016 | - if (!empty($ids)) { |
|
1017 | - $chunks = array_chunk($ids, 100); |
|
1018 | - foreach ($chunks as $chunk) { |
|
1019 | - $qb->delete('share') |
|
1020 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
1021 | - ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY))); |
|
1022 | - $qb->execute(); |
|
1023 | - } |
|
1024 | - } |
|
1025 | - |
|
1026 | - /* |
|
1003 | + $qb = $this->dbConn->getQueryBuilder(); |
|
1004 | + $qb->select('id') |
|
1005 | + ->from('share') |
|
1006 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
1007 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
1008 | + |
|
1009 | + $cursor = $qb->execute(); |
|
1010 | + $ids = []; |
|
1011 | + while($row = $cursor->fetch()) { |
|
1012 | + $ids[] = (int)$row['id']; |
|
1013 | + } |
|
1014 | + $cursor->closeCursor(); |
|
1015 | + |
|
1016 | + if (!empty($ids)) { |
|
1017 | + $chunks = array_chunk($ids, 100); |
|
1018 | + foreach ($chunks as $chunk) { |
|
1019 | + $qb->delete('share') |
|
1020 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
1021 | + ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY))); |
|
1022 | + $qb->execute(); |
|
1023 | + } |
|
1024 | + } |
|
1025 | + |
|
1026 | + /* |
|
1027 | 1027 | * Now delete all the group shares |
1028 | 1028 | */ |
1029 | - $qb = $this->dbConn->getQueryBuilder(); |
|
1030 | - $qb->delete('share') |
|
1031 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
1032 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
1033 | - $qb->execute(); |
|
1034 | - } |
|
1035 | - |
|
1036 | - /** |
|
1037 | - * Delete custom group shares to this group for this user |
|
1038 | - * |
|
1039 | - * @param string $uid |
|
1040 | - * @param string $gid |
|
1041 | - */ |
|
1042 | - public function userDeletedFromGroup($uid, $gid) { |
|
1043 | - /* |
|
1029 | + $qb = $this->dbConn->getQueryBuilder(); |
|
1030 | + $qb->delete('share') |
|
1031 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
1032 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
1033 | + $qb->execute(); |
|
1034 | + } |
|
1035 | + |
|
1036 | + /** |
|
1037 | + * Delete custom group shares to this group for this user |
|
1038 | + * |
|
1039 | + * @param string $uid |
|
1040 | + * @param string $gid |
|
1041 | + */ |
|
1042 | + public function userDeletedFromGroup($uid, $gid) { |
|
1043 | + /* |
|
1044 | 1044 | * Get all group shares |
1045 | 1045 | */ |
1046 | - $qb = $this->dbConn->getQueryBuilder(); |
|
1047 | - $qb->select('id') |
|
1048 | - ->from('share') |
|
1049 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
1050 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
1051 | - |
|
1052 | - $cursor = $qb->execute(); |
|
1053 | - $ids = []; |
|
1054 | - while($row = $cursor->fetch()) { |
|
1055 | - $ids[] = (int)$row['id']; |
|
1056 | - } |
|
1057 | - $cursor->closeCursor(); |
|
1058 | - |
|
1059 | - if (!empty($ids)) { |
|
1060 | - $chunks = array_chunk($ids, 100); |
|
1061 | - foreach ($chunks as $chunk) { |
|
1062 | - /* |
|
1046 | + $qb = $this->dbConn->getQueryBuilder(); |
|
1047 | + $qb->select('id') |
|
1048 | + ->from('share') |
|
1049 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))) |
|
1050 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($gid))); |
|
1051 | + |
|
1052 | + $cursor = $qb->execute(); |
|
1053 | + $ids = []; |
|
1054 | + while($row = $cursor->fetch()) { |
|
1055 | + $ids[] = (int)$row['id']; |
|
1056 | + } |
|
1057 | + $cursor->closeCursor(); |
|
1058 | + |
|
1059 | + if (!empty($ids)) { |
|
1060 | + $chunks = array_chunk($ids, 100); |
|
1061 | + foreach ($chunks as $chunk) { |
|
1062 | + /* |
|
1063 | 1063 | * Delete all special shares wit this users for the found group shares |
1064 | 1064 | */ |
1065 | - $qb->delete('share') |
|
1066 | - ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
1067 | - ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($uid))) |
|
1068 | - ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY))); |
|
1069 | - $qb->execute(); |
|
1070 | - } |
|
1071 | - } |
|
1072 | - } |
|
1073 | - |
|
1074 | - /** |
|
1075 | - * @inheritdoc |
|
1076 | - */ |
|
1077 | - public function getAccessList($nodes, $currentAccess) { |
|
1078 | - $ids = []; |
|
1079 | - foreach ($nodes as $node) { |
|
1080 | - $ids[] = $node->getId(); |
|
1081 | - } |
|
1082 | - |
|
1083 | - $qb = $this->dbConn->getQueryBuilder(); |
|
1084 | - |
|
1085 | - $or = $qb->expr()->orX( |
|
1086 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
1087 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
1088 | - $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)) |
|
1089 | - ); |
|
1090 | - |
|
1091 | - if ($currentAccess) { |
|
1092 | - $or->add($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))); |
|
1093 | - } |
|
1094 | - |
|
1095 | - $qb->select('id', 'parent', 'share_type', 'share_with', 'file_source', 'file_target', 'permissions') |
|
1096 | - ->from('share') |
|
1097 | - ->where( |
|
1098 | - $or |
|
1099 | - ) |
|
1100 | - ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
1101 | - ->andWhere($qb->expr()->orX( |
|
1102 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
1103 | - $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
1104 | - )); |
|
1105 | - $cursor = $qb->execute(); |
|
1106 | - |
|
1107 | - $users = []; |
|
1108 | - $link = false; |
|
1109 | - while($row = $cursor->fetch()) { |
|
1110 | - $type = (int)$row['share_type']; |
|
1111 | - if ($type === \OCP\Share::SHARE_TYPE_USER) { |
|
1112 | - $uid = $row['share_with']; |
|
1113 | - $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
1114 | - $users[$uid][$row['id']] = $row; |
|
1115 | - } else if ($type === \OCP\Share::SHARE_TYPE_GROUP) { |
|
1116 | - $gid = $row['share_with']; |
|
1117 | - $group = $this->groupManager->get($gid); |
|
1118 | - |
|
1119 | - if ($gid === null) { |
|
1120 | - continue; |
|
1121 | - } |
|
1122 | - |
|
1123 | - $userList = $group->getUsers(); |
|
1124 | - foreach ($userList as $user) { |
|
1125 | - $uid = $user->getUID(); |
|
1126 | - $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
1127 | - $users[$uid][$row['id']] = $row; |
|
1128 | - } |
|
1129 | - } else if ($type === \OCP\Share::SHARE_TYPE_LINK) { |
|
1130 | - $link = true; |
|
1131 | - } else if ($type === self::SHARE_TYPE_USERGROUP && $currentAccess === true) { |
|
1132 | - $uid = $row['share_with']; |
|
1133 | - $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
1134 | - $users[$uid][$row['id']] = $row; |
|
1135 | - } |
|
1136 | - } |
|
1137 | - $cursor->closeCursor(); |
|
1138 | - |
|
1139 | - if ($currentAccess === true) { |
|
1140 | - $users = array_map([$this, 'filterSharesOfUser'], $users); |
|
1141 | - $users = array_filter($users); |
|
1142 | - } else { |
|
1143 | - $users = array_keys($users); |
|
1144 | - } |
|
1145 | - |
|
1146 | - return ['users' => $users, 'public' => $link]; |
|
1147 | - } |
|
1148 | - |
|
1149 | - /** |
|
1150 | - * For each user the path with the fewest slashes is returned |
|
1151 | - * @param array $shares |
|
1152 | - * @return array |
|
1153 | - */ |
|
1154 | - protected function filterSharesOfUser(array $shares) { |
|
1155 | - // Group shares when the user has a share exception |
|
1156 | - foreach ($shares as $id => $share) { |
|
1157 | - $type = (int) $share['share_type']; |
|
1158 | - $permissions = (int) $share['permissions']; |
|
1159 | - |
|
1160 | - if ($type === self::SHARE_TYPE_USERGROUP) { |
|
1161 | - unset($shares[$share['parent']]); |
|
1162 | - |
|
1163 | - if ($permissions === 0) { |
|
1164 | - unset($shares[$id]); |
|
1165 | - } |
|
1166 | - } |
|
1167 | - } |
|
1168 | - |
|
1169 | - $best = []; |
|
1170 | - $bestDepth = 0; |
|
1171 | - foreach ($shares as $id => $share) { |
|
1172 | - $depth = substr_count($share['file_target'], '/'); |
|
1173 | - if (empty($best) || $depth < $bestDepth) { |
|
1174 | - $bestDepth = $depth; |
|
1175 | - $best = [ |
|
1176 | - 'node_id' => $share['file_source'], |
|
1177 | - 'node_path' => $share['file_target'], |
|
1178 | - ]; |
|
1179 | - } |
|
1180 | - } |
|
1181 | - |
|
1182 | - return $best; |
|
1183 | - } |
|
1065 | + $qb->delete('share') |
|
1066 | + ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))) |
|
1067 | + ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($uid))) |
|
1068 | + ->andWhere($qb->expr()->in('parent', $qb->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY))); |
|
1069 | + $qb->execute(); |
|
1070 | + } |
|
1071 | + } |
|
1072 | + } |
|
1073 | + |
|
1074 | + /** |
|
1075 | + * @inheritdoc |
|
1076 | + */ |
|
1077 | + public function getAccessList($nodes, $currentAccess) { |
|
1078 | + $ids = []; |
|
1079 | + foreach ($nodes as $node) { |
|
1080 | + $ids[] = $node->getId(); |
|
1081 | + } |
|
1082 | + |
|
1083 | + $qb = $this->dbConn->getQueryBuilder(); |
|
1084 | + |
|
1085 | + $or = $qb->expr()->orX( |
|
1086 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)), |
|
1087 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)), |
|
1088 | + $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)) |
|
1089 | + ); |
|
1090 | + |
|
1091 | + if ($currentAccess) { |
|
1092 | + $or->add($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP))); |
|
1093 | + } |
|
1094 | + |
|
1095 | + $qb->select('id', 'parent', 'share_type', 'share_with', 'file_source', 'file_target', 'permissions') |
|
1096 | + ->from('share') |
|
1097 | + ->where( |
|
1098 | + $or |
|
1099 | + ) |
|
1100 | + ->andWhere($qb->expr()->in('file_source', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY))) |
|
1101 | + ->andWhere($qb->expr()->orX( |
|
1102 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('file')), |
|
1103 | + $qb->expr()->eq('item_type', $qb->createNamedParameter('folder')) |
|
1104 | + )); |
|
1105 | + $cursor = $qb->execute(); |
|
1106 | + |
|
1107 | + $users = []; |
|
1108 | + $link = false; |
|
1109 | + while($row = $cursor->fetch()) { |
|
1110 | + $type = (int)$row['share_type']; |
|
1111 | + if ($type === \OCP\Share::SHARE_TYPE_USER) { |
|
1112 | + $uid = $row['share_with']; |
|
1113 | + $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
1114 | + $users[$uid][$row['id']] = $row; |
|
1115 | + } else if ($type === \OCP\Share::SHARE_TYPE_GROUP) { |
|
1116 | + $gid = $row['share_with']; |
|
1117 | + $group = $this->groupManager->get($gid); |
|
1118 | + |
|
1119 | + if ($gid === null) { |
|
1120 | + continue; |
|
1121 | + } |
|
1122 | + |
|
1123 | + $userList = $group->getUsers(); |
|
1124 | + foreach ($userList as $user) { |
|
1125 | + $uid = $user->getUID(); |
|
1126 | + $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
1127 | + $users[$uid][$row['id']] = $row; |
|
1128 | + } |
|
1129 | + } else if ($type === \OCP\Share::SHARE_TYPE_LINK) { |
|
1130 | + $link = true; |
|
1131 | + } else if ($type === self::SHARE_TYPE_USERGROUP && $currentAccess === true) { |
|
1132 | + $uid = $row['share_with']; |
|
1133 | + $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
|
1134 | + $users[$uid][$row['id']] = $row; |
|
1135 | + } |
|
1136 | + } |
|
1137 | + $cursor->closeCursor(); |
|
1138 | + |
|
1139 | + if ($currentAccess === true) { |
|
1140 | + $users = array_map([$this, 'filterSharesOfUser'], $users); |
|
1141 | + $users = array_filter($users); |
|
1142 | + } else { |
|
1143 | + $users = array_keys($users); |
|
1144 | + } |
|
1145 | + |
|
1146 | + return ['users' => $users, 'public' => $link]; |
|
1147 | + } |
|
1148 | + |
|
1149 | + /** |
|
1150 | + * For each user the path with the fewest slashes is returned |
|
1151 | + * @param array $shares |
|
1152 | + * @return array |
|
1153 | + */ |
|
1154 | + protected function filterSharesOfUser(array $shares) { |
|
1155 | + // Group shares when the user has a share exception |
|
1156 | + foreach ($shares as $id => $share) { |
|
1157 | + $type = (int) $share['share_type']; |
|
1158 | + $permissions = (int) $share['permissions']; |
|
1159 | + |
|
1160 | + if ($type === self::SHARE_TYPE_USERGROUP) { |
|
1161 | + unset($shares[$share['parent']]); |
|
1162 | + |
|
1163 | + if ($permissions === 0) { |
|
1164 | + unset($shares[$id]); |
|
1165 | + } |
|
1166 | + } |
|
1167 | + } |
|
1168 | + |
|
1169 | + $best = []; |
|
1170 | + $bestDepth = 0; |
|
1171 | + foreach ($shares as $id => $share) { |
|
1172 | + $depth = substr_count($share['file_target'], '/'); |
|
1173 | + if (empty($best) || $depth < $bestDepth) { |
|
1174 | + $bestDepth = $depth; |
|
1175 | + $best = [ |
|
1176 | + 'node_id' => $share['file_source'], |
|
1177 | + 'node_path' => $share['file_target'], |
|
1178 | + ]; |
|
1179 | + } |
|
1180 | + } |
|
1181 | + |
|
1182 | + return $best; |
|
1183 | + } |
|
1184 | 1184 | } |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | ->orderBy('id'); |
289 | 289 | |
290 | 290 | $cursor = $qb->execute(); |
291 | - while($data = $cursor->fetch()) { |
|
291 | + while ($data = $cursor->fetch()) { |
|
292 | 292 | $children[] = $this->createShare($data); |
293 | 293 | } |
294 | 294 | $cursor->closeCursor(); |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | $user = $this->userManager->get($recipient); |
334 | 334 | |
335 | 335 | if (is_null($group)) { |
336 | - throw new ProviderException('Group "' . $share->getSharedWith() . '" does not exist'); |
|
336 | + throw new ProviderException('Group "'.$share->getSharedWith().'" does not exist'); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | if (!$group->inGroup($user)) { |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | ); |
494 | 494 | } |
495 | 495 | |
496 | - $qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
496 | + $qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid')); |
|
497 | 497 | $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); |
498 | 498 | |
499 | 499 | $qb->orderBy('id'); |
@@ -549,7 +549,7 @@ discard block |
||
549 | 549 | |
550 | 550 | $cursor = $qb->execute(); |
551 | 551 | $shares = []; |
552 | - while($data = $cursor->fetch()) { |
|
552 | + while ($data = $cursor->fetch()) { |
|
553 | 553 | $shares[] = $this->createShare($data); |
554 | 554 | } |
555 | 555 | $cursor->closeCursor(); |
@@ -628,7 +628,7 @@ discard block |
||
628 | 628 | ->execute(); |
629 | 629 | |
630 | 630 | $shares = []; |
631 | - while($data = $cursor->fetch()) { |
|
631 | + while ($data = $cursor->fetch()) { |
|
632 | 632 | $shares[] = $this->createShare($data); |
633 | 633 | } |
634 | 634 | $cursor->closeCursor(); |
@@ -699,7 +699,7 @@ discard block |
||
699 | 699 | |
700 | 700 | $cursor = $qb->execute(); |
701 | 701 | |
702 | - while($data = $cursor->fetch()) { |
|
702 | + while ($data = $cursor->fetch()) { |
|
703 | 703 | if ($this->isAccessibleResult($data)) { |
704 | 704 | $shares[] = $this->createShare($data); |
705 | 705 | } |
@@ -714,7 +714,7 @@ discard block |
||
714 | 714 | $shares2 = []; |
715 | 715 | |
716 | 716 | $start = 0; |
717 | - while(true) { |
|
717 | + while (true) { |
|
718 | 718 | $groups = array_slice($allGroups, $start, 100); |
719 | 719 | $start += 100; |
720 | 720 | |
@@ -757,7 +757,7 @@ discard block |
||
757 | 757 | )); |
758 | 758 | |
759 | 759 | $cursor = $qb->execute(); |
760 | - while($data = $cursor->fetch()) { |
|
760 | + while ($data = $cursor->fetch()) { |
|
761 | 761 | if ($offset > 0) { |
762 | 762 | $offset--; |
763 | 763 | continue; |
@@ -826,14 +826,14 @@ discard block |
||
826 | 826 | */ |
827 | 827 | private function createShare($data) { |
828 | 828 | $share = new Share($this->rootFolder, $this->userManager); |
829 | - $share->setId((int)$data['id']) |
|
830 | - ->setShareType((int)$data['share_type']) |
|
831 | - ->setPermissions((int)$data['permissions']) |
|
829 | + $share->setId((int) $data['id']) |
|
830 | + ->setShareType((int) $data['share_type']) |
|
831 | + ->setPermissions((int) $data['permissions']) |
|
832 | 832 | ->setTarget($data['file_target']) |
833 | - ->setMailSend((bool)$data['mail_send']); |
|
833 | + ->setMailSend((bool) $data['mail_send']); |
|
834 | 834 | |
835 | 835 | $shareTime = new \DateTime(); |
836 | - $shareTime->setTimestamp((int)$data['stime']); |
|
836 | + $shareTime->setTimestamp((int) $data['stime']); |
|
837 | 837 | $share->setShareTime($shareTime); |
838 | 838 | |
839 | 839 | if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) { |
@@ -848,7 +848,7 @@ discard block |
||
848 | 848 | $share->setSharedBy($data['uid_initiator']); |
849 | 849 | $share->setShareOwner($data['uid_owner']); |
850 | 850 | |
851 | - $share->setNodeId((int)$data['file_source']); |
|
851 | + $share->setNodeId((int) $data['file_source']); |
|
852 | 852 | $share->setNodeType($data['item_type']); |
853 | 853 | |
854 | 854 | if ($data['expiration'] !== null) { |
@@ -859,7 +859,7 @@ discard block |
||
859 | 859 | if (isset($data['f_permissions'])) { |
860 | 860 | $entryData = $data; |
861 | 861 | $entryData['permissions'] = $entryData['f_permissions']; |
862 | - $entryData['parent'] = $entryData['f_parent'];; |
|
862 | + $entryData['parent'] = $entryData['f_parent']; ; |
|
863 | 863 | $share->setNodeCacheEntry(Cache::cacheEntryFromData($entryData, |
864 | 864 | \OC::$server->getMimeTypeLoader())); |
865 | 865 | } |
@@ -878,7 +878,7 @@ discard block |
||
878 | 878 | $result = []; |
879 | 879 | |
880 | 880 | $start = 0; |
881 | - while(true) { |
|
881 | + while (true) { |
|
882 | 882 | /** @var Share[] $shareSlice */ |
883 | 883 | $shareSlice = array_slice($shares, $start, 100); |
884 | 884 | $start += 100; |
@@ -893,7 +893,7 @@ discard block |
||
893 | 893 | $shareMap = []; |
894 | 894 | |
895 | 895 | foreach ($shareSlice as $share) { |
896 | - $ids[] = (int)$share->getId(); |
|
896 | + $ids[] = (int) $share->getId(); |
|
897 | 897 | $shareMap[$share->getId()] = $share; |
898 | 898 | } |
899 | 899 | |
@@ -910,8 +910,8 @@ discard block |
||
910 | 910 | |
911 | 911 | $stmt = $query->execute(); |
912 | 912 | |
913 | - while($data = $stmt->fetch()) { |
|
914 | - $shareMap[$data['parent']]->setPermissions((int)$data['permissions']); |
|
913 | + while ($data = $stmt->fetch()) { |
|
914 | + $shareMap[$data['parent']]->setPermissions((int) $data['permissions']); |
|
915 | 915 | $shareMap[$data['parent']]->setTarget($data['file_target']); |
916 | 916 | } |
917 | 917 | |
@@ -1008,8 +1008,8 @@ discard block |
||
1008 | 1008 | |
1009 | 1009 | $cursor = $qb->execute(); |
1010 | 1010 | $ids = []; |
1011 | - while($row = $cursor->fetch()) { |
|
1012 | - $ids[] = (int)$row['id']; |
|
1011 | + while ($row = $cursor->fetch()) { |
|
1012 | + $ids[] = (int) $row['id']; |
|
1013 | 1013 | } |
1014 | 1014 | $cursor->closeCursor(); |
1015 | 1015 | |
@@ -1051,8 +1051,8 @@ discard block |
||
1051 | 1051 | |
1052 | 1052 | $cursor = $qb->execute(); |
1053 | 1053 | $ids = []; |
1054 | - while($row = $cursor->fetch()) { |
|
1055 | - $ids[] = (int)$row['id']; |
|
1054 | + while ($row = $cursor->fetch()) { |
|
1055 | + $ids[] = (int) $row['id']; |
|
1056 | 1056 | } |
1057 | 1057 | $cursor->closeCursor(); |
1058 | 1058 | |
@@ -1106,8 +1106,8 @@ discard block |
||
1106 | 1106 | |
1107 | 1107 | $users = []; |
1108 | 1108 | $link = false; |
1109 | - while($row = $cursor->fetch()) { |
|
1110 | - $type = (int)$row['share_type']; |
|
1109 | + while ($row = $cursor->fetch()) { |
|
1110 | + $type = (int) $row['share_type']; |
|
1111 | 1111 | if ($type === \OCP\Share::SHARE_TYPE_USER) { |
1112 | 1112 | $uid = $row['share_with']; |
1113 | 1113 | $users[$uid] = isset($users[$uid]) ? $users[$uid] : []; |
@@ -61,7 +61,7 @@ |
||
61 | 61 | * The deserialize method is called during xml parsing. |
62 | 62 | * |
63 | 63 | * @param Reader $reader |
64 | - * @return mixed |
|
64 | + * @return null|ShareTypeList |
|
65 | 65 | */ |
66 | 66 | static function xmlDeserialize(Reader $reader) { |
67 | 67 | $shareTypes = []; |
@@ -32,61 +32,61 @@ |
||
32 | 32 | * This property contains multiple "share-type" elements, each containing a share type. |
33 | 33 | */ |
34 | 34 | class ShareTypeList implements Element { |
35 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
35 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Share types |
|
39 | - * |
|
40 | - * @var int[] |
|
41 | - */ |
|
42 | - private $shareTypes; |
|
37 | + /** |
|
38 | + * Share types |
|
39 | + * |
|
40 | + * @var int[] |
|
41 | + */ |
|
42 | + private $shareTypes; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @param int[] $shareTypes |
|
46 | - */ |
|
47 | - public function __construct($shareTypes) { |
|
48 | - $this->shareTypes = $shareTypes; |
|
49 | - } |
|
44 | + /** |
|
45 | + * @param int[] $shareTypes |
|
46 | + */ |
|
47 | + public function __construct($shareTypes) { |
|
48 | + $this->shareTypes = $shareTypes; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Returns the share types |
|
53 | - * |
|
54 | - * @return int[] |
|
55 | - */ |
|
56 | - public function getShareTypes() { |
|
57 | - return $this->shareTypes; |
|
58 | - } |
|
51 | + /** |
|
52 | + * Returns the share types |
|
53 | + * |
|
54 | + * @return int[] |
|
55 | + */ |
|
56 | + public function getShareTypes() { |
|
57 | + return $this->shareTypes; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * The deserialize method is called during xml parsing. |
|
62 | - * |
|
63 | - * @param Reader $reader |
|
64 | - * @return mixed |
|
65 | - */ |
|
66 | - static function xmlDeserialize(Reader $reader) { |
|
67 | - $shareTypes = []; |
|
60 | + /** |
|
61 | + * The deserialize method is called during xml parsing. |
|
62 | + * |
|
63 | + * @param Reader $reader |
|
64 | + * @return mixed |
|
65 | + */ |
|
66 | + static function xmlDeserialize(Reader $reader) { |
|
67 | + $shareTypes = []; |
|
68 | 68 | |
69 | - $tree = $reader->parseInnerTree(); |
|
70 | - if ($tree === null) { |
|
71 | - return null; |
|
72 | - } |
|
73 | - foreach ($tree as $elem) { |
|
74 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') { |
|
75 | - $shareTypes[] = (int)$elem['value']; |
|
76 | - } |
|
77 | - } |
|
78 | - return new self($shareTypes); |
|
79 | - } |
|
69 | + $tree = $reader->parseInnerTree(); |
|
70 | + if ($tree === null) { |
|
71 | + return null; |
|
72 | + } |
|
73 | + foreach ($tree as $elem) { |
|
74 | + if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') { |
|
75 | + $shareTypes[] = (int)$elem['value']; |
|
76 | + } |
|
77 | + } |
|
78 | + return new self($shareTypes); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * The xmlSerialize metod is called during xml writing. |
|
83 | - * |
|
84 | - * @param Writer $writer |
|
85 | - * @return void |
|
86 | - */ |
|
87 | - function xmlSerialize(Writer $writer) { |
|
88 | - foreach ($this->shareTypes as $shareType) { |
|
89 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', $shareType); |
|
90 | - } |
|
91 | - } |
|
81 | + /** |
|
82 | + * The xmlSerialize metod is called during xml writing. |
|
83 | + * |
|
84 | + * @param Writer $writer |
|
85 | + * @return void |
|
86 | + */ |
|
87 | + function xmlSerialize(Writer $writer) { |
|
88 | + foreach ($this->shareTypes as $shareType) { |
|
89 | + $writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', $shareType); |
|
90 | + } |
|
91 | + } |
|
92 | 92 | } |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | return null; |
72 | 72 | } |
73 | 73 | foreach ($tree as $elem) { |
74 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}share-type') { |
|
75 | - $shareTypes[] = (int)$elem['value']; |
|
74 | + if ($elem['name'] === '{'.self::NS_OWNCLOUD.'}share-type') { |
|
75 | + $shareTypes[] = (int) $elem['value']; |
|
76 | 76 | } |
77 | 77 | } |
78 | 78 | return new self($shareTypes); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | */ |
87 | 87 | function xmlSerialize(Writer $writer) { |
88 | 88 | foreach ($this->shareTypes as $shareType) { |
89 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}share-type', $shareType); |
|
89 | + $writer->writeElement('{'.self::NS_OWNCLOUD.'}share-type', $shareType); |
|
90 | 90 | } |
91 | 91 | } |
92 | 92 | } |
@@ -80,7 +80,7 @@ |
||
80 | 80 | * the next element. |
81 | 81 | * |
82 | 82 | * @param Reader $reader |
83 | - * @return mixed |
|
83 | + * @return null|TagList |
|
84 | 84 | */ |
85 | 85 | static function xmlDeserialize(Reader $reader) { |
86 | 86 | $tags = []; |
@@ -34,92 +34,92 @@ |
||
34 | 34 | * This property contains multiple "tag" elements, each containing a tag name. |
35 | 35 | */ |
36 | 36 | class TagList implements Element { |
37 | - const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
37 | + const NS_OWNCLOUD = 'http://owncloud.org/ns'; |
|
38 | 38 | |
39 | - /** |
|
40 | - * tags |
|
41 | - * |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - private $tags; |
|
39 | + /** |
|
40 | + * tags |
|
41 | + * |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + private $tags; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @param array $tags |
|
48 | - */ |
|
49 | - public function __construct(array $tags) { |
|
50 | - $this->tags = $tags; |
|
51 | - } |
|
46 | + /** |
|
47 | + * @param array $tags |
|
48 | + */ |
|
49 | + public function __construct(array $tags) { |
|
50 | + $this->tags = $tags; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Returns the tags |
|
55 | - * |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public function getTags() { |
|
53 | + /** |
|
54 | + * Returns the tags |
|
55 | + * |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public function getTags() { |
|
59 | 59 | |
60 | - return $this->tags; |
|
60 | + return $this->tags; |
|
61 | 61 | |
62 | - } |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * The deserialize method is called during xml parsing. |
|
66 | - * |
|
67 | - * This method is called statictly, this is because in theory this method |
|
68 | - * may be used as a type of constructor, or factory method. |
|
69 | - * |
|
70 | - * Often you want to return an instance of the current class, but you are |
|
71 | - * free to return other data as well. |
|
72 | - * |
|
73 | - * You are responsible for advancing the reader to the next element. Not |
|
74 | - * doing anything will result in a never-ending loop. |
|
75 | - * |
|
76 | - * If you just want to skip parsing for this element altogether, you can |
|
77 | - * just call $reader->next(); |
|
78 | - * |
|
79 | - * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
80 | - * the next element. |
|
81 | - * |
|
82 | - * @param Reader $reader |
|
83 | - * @return mixed |
|
84 | - */ |
|
85 | - static function xmlDeserialize(Reader $reader) { |
|
86 | - $tags = []; |
|
64 | + /** |
|
65 | + * The deserialize method is called during xml parsing. |
|
66 | + * |
|
67 | + * This method is called statictly, this is because in theory this method |
|
68 | + * may be used as a type of constructor, or factory method. |
|
69 | + * |
|
70 | + * Often you want to return an instance of the current class, but you are |
|
71 | + * free to return other data as well. |
|
72 | + * |
|
73 | + * You are responsible for advancing the reader to the next element. Not |
|
74 | + * doing anything will result in a never-ending loop. |
|
75 | + * |
|
76 | + * If you just want to skip parsing for this element altogether, you can |
|
77 | + * just call $reader->next(); |
|
78 | + * |
|
79 | + * $reader->parseInnerTree() will parse the entire sub-tree, and advance to |
|
80 | + * the next element. |
|
81 | + * |
|
82 | + * @param Reader $reader |
|
83 | + * @return mixed |
|
84 | + */ |
|
85 | + static function xmlDeserialize(Reader $reader) { |
|
86 | + $tags = []; |
|
87 | 87 | |
88 | - $tree = $reader->parseInnerTree(); |
|
89 | - if ($tree === null) { |
|
90 | - return null; |
|
91 | - } |
|
92 | - foreach ($tree as $elem) { |
|
93 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
94 | - $tags[] = $elem['value']; |
|
95 | - } |
|
96 | - } |
|
97 | - return new self($tags); |
|
98 | - } |
|
88 | + $tree = $reader->parseInnerTree(); |
|
89 | + if ($tree === null) { |
|
90 | + return null; |
|
91 | + } |
|
92 | + foreach ($tree as $elem) { |
|
93 | + if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
94 | + $tags[] = $elem['value']; |
|
95 | + } |
|
96 | + } |
|
97 | + return new self($tags); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * The xmlSerialize metod is called during xml writing. |
|
102 | - * |
|
103 | - * Use the $writer argument to write its own xml serialization. |
|
104 | - * |
|
105 | - * An important note: do _not_ create a parent element. Any element |
|
106 | - * implementing XmlSerializble should only ever write what's considered |
|
107 | - * its 'inner xml'. |
|
108 | - * |
|
109 | - * The parent of the current element is responsible for writing a |
|
110 | - * containing element. |
|
111 | - * |
|
112 | - * This allows serializers to be re-used for different element names. |
|
113 | - * |
|
114 | - * If you are opening new elements, you must also close them again. |
|
115 | - * |
|
116 | - * @param Writer $writer |
|
117 | - * @return void |
|
118 | - */ |
|
119 | - function xmlSerialize(Writer $writer) { |
|
100 | + /** |
|
101 | + * The xmlSerialize metod is called during xml writing. |
|
102 | + * |
|
103 | + * Use the $writer argument to write its own xml serialization. |
|
104 | + * |
|
105 | + * An important note: do _not_ create a parent element. Any element |
|
106 | + * implementing XmlSerializble should only ever write what's considered |
|
107 | + * its 'inner xml'. |
|
108 | + * |
|
109 | + * The parent of the current element is responsible for writing a |
|
110 | + * containing element. |
|
111 | + * |
|
112 | + * This allows serializers to be re-used for different element names. |
|
113 | + * |
|
114 | + * If you are opening new elements, you must also close them again. |
|
115 | + * |
|
116 | + * @param Writer $writer |
|
117 | + * @return void |
|
118 | + */ |
|
119 | + function xmlSerialize(Writer $writer) { |
|
120 | 120 | |
121 | - foreach ($this->tags as $tag) { |
|
122 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
123 | - } |
|
124 | - } |
|
121 | + foreach ($this->tags as $tag) { |
|
122 | + $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
123 | + } |
|
124 | + } |
|
125 | 125 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | return null; |
91 | 91 | } |
92 | 92 | foreach ($tree as $elem) { |
93 | - if ($elem['name'] === '{' . self::NS_OWNCLOUD . '}tag') { |
|
93 | + if ($elem['name'] === '{'.self::NS_OWNCLOUD.'}tag') { |
|
94 | 94 | $tags[] = $elem['value']; |
95 | 95 | } |
96 | 96 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | function xmlSerialize(Writer $writer) { |
120 | 120 | |
121 | 121 | foreach ($this->tags as $tag) { |
122 | - $writer->writeElement('{' . self::NS_OWNCLOUD . '}tag', $tag); |
|
122 | + $writer->writeElement('{'.self::NS_OWNCLOUD.'}tag', $tag); |
|
123 | 123 | } |
124 | 124 | } |
125 | 125 | } |
@@ -51,7 +51,6 @@ |
||
51 | 51 | use OC\App\InfoParser; |
52 | 52 | use OC\App\Platform; |
53 | 53 | use OC\Installer; |
54 | -use OC\OCSClient; |
|
55 | 54 | use OC\Repair; |
56 | 55 | use OCP\App\ManagerEvent; |
57 | 56 |
@@ -1063,7 +1063,7 @@ discard block |
||
1063 | 1063 | * @param string $app |
1064 | 1064 | * @param \OCP\IConfig $config |
1065 | 1065 | * @param \OCP\IL10N $l |
1066 | - * @return bool |
|
1066 | + * @return string |
|
1067 | 1067 | * |
1068 | 1068 | * @throws Exception if app is not compatible with this version of ownCloud |
1069 | 1069 | * @throws Exception if no app-name was specified |
@@ -1243,6 +1243,11 @@ discard block |
||
1243 | 1243 | } |
1244 | 1244 | } |
1245 | 1245 | |
1246 | + /** |
|
1247 | + * @param string $lang |
|
1248 | + * |
|
1249 | + * @return string |
|
1250 | + */ |
|
1246 | 1251 | protected static function findBestL10NOption($options, $lang) { |
1247 | 1252 | $fallback = $similarLangFallback = $englishFallback = false; |
1248 | 1253 |
@@ -61,1280 +61,1280 @@ |
||
61 | 61 | * upgrading and removing apps. |
62 | 62 | */ |
63 | 63 | class OC_App { |
64 | - static private $appVersion = []; |
|
65 | - static private $adminForms = array(); |
|
66 | - static private $personalForms = array(); |
|
67 | - static private $appInfo = array(); |
|
68 | - static private $appTypes = array(); |
|
69 | - static private $loadedApps = array(); |
|
70 | - static private $altLogin = array(); |
|
71 | - static private $alreadyRegistered = []; |
|
72 | - const officialApp = 200; |
|
73 | - |
|
74 | - /** |
|
75 | - * clean the appId |
|
76 | - * |
|
77 | - * @param string|boolean $app AppId that needs to be cleaned |
|
78 | - * @return string |
|
79 | - */ |
|
80 | - public static function cleanAppId($app) { |
|
81 | - return str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Check if an app is loaded |
|
86 | - * |
|
87 | - * @param string $app |
|
88 | - * @return bool |
|
89 | - */ |
|
90 | - public static function isAppLoaded($app) { |
|
91 | - return in_array($app, self::$loadedApps, true); |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * loads all apps |
|
96 | - * |
|
97 | - * @param string[] | string | null $types |
|
98 | - * @return bool |
|
99 | - * |
|
100 | - * This function walks through the ownCloud directory and loads all apps |
|
101 | - * it can find. A directory contains an app if the file /appinfo/info.xml |
|
102 | - * exists. |
|
103 | - * |
|
104 | - * if $types is set, only apps of those types will be loaded |
|
105 | - */ |
|
106 | - public static function loadApps($types = null) { |
|
107 | - if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
108 | - return false; |
|
109 | - } |
|
110 | - // Load the enabled apps here |
|
111 | - $apps = self::getEnabledApps(); |
|
112 | - |
|
113 | - // Add each apps' folder as allowed class path |
|
114 | - foreach($apps as $app) { |
|
115 | - $path = self::getAppPath($app); |
|
116 | - if($path !== false) { |
|
117 | - self::registerAutoloading($app, $path); |
|
118 | - } |
|
119 | - } |
|
120 | - |
|
121 | - // prevent app.php from printing output |
|
122 | - ob_start(); |
|
123 | - foreach ($apps as $app) { |
|
124 | - if ((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) { |
|
125 | - self::loadApp($app); |
|
126 | - } |
|
127 | - } |
|
128 | - ob_end_clean(); |
|
129 | - |
|
130 | - return true; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * load a single app |
|
135 | - * |
|
136 | - * @param string $app |
|
137 | - */ |
|
138 | - public static function loadApp($app) { |
|
139 | - self::$loadedApps[] = $app; |
|
140 | - $appPath = self::getAppPath($app); |
|
141 | - if($appPath === false) { |
|
142 | - return; |
|
143 | - } |
|
144 | - |
|
145 | - // in case someone calls loadApp() directly |
|
146 | - self::registerAutoloading($app, $appPath); |
|
147 | - |
|
148 | - if (is_file($appPath . '/appinfo/app.php')) { |
|
149 | - \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
150 | - self::requireAppFile($app); |
|
151 | - if (self::isType($app, array('authentication'))) { |
|
152 | - // since authentication apps affect the "is app enabled for group" check, |
|
153 | - // the enabled apps cache needs to be cleared to make sure that the |
|
154 | - // next time getEnableApps() is called it will also include apps that were |
|
155 | - // enabled for groups |
|
156 | - self::$enabledAppsCache = array(); |
|
157 | - } |
|
158 | - \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
159 | - } |
|
160 | - |
|
161 | - $info = self::getAppInfo($app); |
|
162 | - if (!empty($info['activity']['filters'])) { |
|
163 | - foreach ($info['activity']['filters'] as $filter) { |
|
164 | - \OC::$server->getActivityManager()->registerFilter($filter); |
|
165 | - } |
|
166 | - } |
|
167 | - if (!empty($info['activity']['settings'])) { |
|
168 | - foreach ($info['activity']['settings'] as $setting) { |
|
169 | - \OC::$server->getActivityManager()->registerSetting($setting); |
|
170 | - } |
|
171 | - } |
|
172 | - if (!empty($info['activity']['providers'])) { |
|
173 | - foreach ($info['activity']['providers'] as $provider) { |
|
174 | - \OC::$server->getActivityManager()->registerProvider($provider); |
|
175 | - } |
|
176 | - } |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * @internal |
|
181 | - * @param string $app |
|
182 | - * @param string $path |
|
183 | - */ |
|
184 | - public static function registerAutoloading($app, $path) { |
|
185 | - $key = $app . '-' . $path; |
|
186 | - if(isset(self::$alreadyRegistered[$key])) { |
|
187 | - return; |
|
188 | - } |
|
189 | - self::$alreadyRegistered[$key] = true; |
|
190 | - // Register on PSR-4 composer autoloader |
|
191 | - $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
|
192 | - \OC::$server->registerNamespace($app, $appNamespace); |
|
193 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
194 | - if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
|
195 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
196 | - } |
|
197 | - |
|
198 | - // Register on legacy autoloader |
|
199 | - \OC::$loader->addValidRoot($path); |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Load app.php from the given app |
|
204 | - * |
|
205 | - * @param string $app app name |
|
206 | - */ |
|
207 | - private static function requireAppFile($app) { |
|
208 | - try { |
|
209 | - // encapsulated here to avoid variable scope conflicts |
|
210 | - require_once $app . '/appinfo/app.php'; |
|
211 | - } catch (Error $ex) { |
|
212 | - \OC::$server->getLogger()->logException($ex); |
|
213 | - $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
|
214 | - if (!in_array($app, $blacklist)) { |
|
215 | - self::disable($app); |
|
216 | - } |
|
217 | - } |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * check if an app is of a specific type |
|
222 | - * |
|
223 | - * @param string $app |
|
224 | - * @param string|array $types |
|
225 | - * @return bool |
|
226 | - */ |
|
227 | - public static function isType($app, $types) { |
|
228 | - if (is_string($types)) { |
|
229 | - $types = array($types); |
|
230 | - } |
|
231 | - $appTypes = self::getAppTypes($app); |
|
232 | - foreach ($types as $type) { |
|
233 | - if (array_search($type, $appTypes) !== false) { |
|
234 | - return true; |
|
235 | - } |
|
236 | - } |
|
237 | - return false; |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * get the types of an app |
|
242 | - * |
|
243 | - * @param string $app |
|
244 | - * @return array |
|
245 | - */ |
|
246 | - private static function getAppTypes($app) { |
|
247 | - //load the cache |
|
248 | - if (count(self::$appTypes) == 0) { |
|
249 | - self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types'); |
|
250 | - } |
|
251 | - |
|
252 | - if (isset(self::$appTypes[$app])) { |
|
253 | - return explode(',', self::$appTypes[$app]); |
|
254 | - } else { |
|
255 | - return array(); |
|
256 | - } |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * read app types from info.xml and cache them in the database |
|
261 | - */ |
|
262 | - public static function setAppTypes($app) { |
|
263 | - $appData = self::getAppInfo($app); |
|
264 | - if(!is_array($appData)) { |
|
265 | - return; |
|
266 | - } |
|
267 | - |
|
268 | - if (isset($appData['types'])) { |
|
269 | - $appTypes = implode(',', $appData['types']); |
|
270 | - } else { |
|
271 | - $appTypes = ''; |
|
272 | - $appData['types'] = []; |
|
273 | - } |
|
274 | - |
|
275 | - \OC::$server->getAppConfig()->setValue($app, 'types', $appTypes); |
|
276 | - |
|
277 | - if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) { |
|
278 | - $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'yes'); |
|
279 | - if ($enabled !== 'yes' && $enabled !== 'no') { |
|
280 | - \OC::$server->getAppConfig()->setValue($app, 'enabled', 'yes'); |
|
281 | - } |
|
282 | - } |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * check if app is shipped |
|
287 | - * |
|
288 | - * @param string $appId the id of the app to check |
|
289 | - * @return bool |
|
290 | - * |
|
291 | - * Check if an app that is installed is a shipped app or installed from the appstore. |
|
292 | - */ |
|
293 | - public static function isShipped($appId) { |
|
294 | - return \OC::$server->getAppManager()->isShipped($appId); |
|
295 | - } |
|
296 | - |
|
297 | - /** |
|
298 | - * get all enabled apps |
|
299 | - */ |
|
300 | - protected static $enabledAppsCache = array(); |
|
301 | - |
|
302 | - /** |
|
303 | - * Returns apps enabled for the current user. |
|
304 | - * |
|
305 | - * @param bool $forceRefresh whether to refresh the cache |
|
306 | - * @param bool $all whether to return apps for all users, not only the |
|
307 | - * currently logged in one |
|
308 | - * @return string[] |
|
309 | - */ |
|
310 | - public static function getEnabledApps($forceRefresh = false, $all = false) { |
|
311 | - if (!\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
312 | - return array(); |
|
313 | - } |
|
314 | - // in incognito mode or when logged out, $user will be false, |
|
315 | - // which is also the case during an upgrade |
|
316 | - $appManager = \OC::$server->getAppManager(); |
|
317 | - if ($all) { |
|
318 | - $user = null; |
|
319 | - } else { |
|
320 | - $user = \OC::$server->getUserSession()->getUser(); |
|
321 | - } |
|
322 | - |
|
323 | - if (is_null($user)) { |
|
324 | - $apps = $appManager->getInstalledApps(); |
|
325 | - } else { |
|
326 | - $apps = $appManager->getEnabledAppsForUser($user); |
|
327 | - } |
|
328 | - $apps = array_filter($apps, function ($app) { |
|
329 | - return $app !== 'files';//we add this manually |
|
330 | - }); |
|
331 | - sort($apps); |
|
332 | - array_unshift($apps, 'files'); |
|
333 | - return $apps; |
|
334 | - } |
|
335 | - |
|
336 | - /** |
|
337 | - * checks whether or not an app is enabled |
|
338 | - * |
|
339 | - * @param string $app app |
|
340 | - * @return bool |
|
341 | - * |
|
342 | - * This function checks whether or not an app is enabled. |
|
343 | - */ |
|
344 | - public static function isEnabled($app) { |
|
345 | - return \OC::$server->getAppManager()->isEnabledForUser($app); |
|
346 | - } |
|
347 | - |
|
348 | - /** |
|
349 | - * enables an app |
|
350 | - * |
|
351 | - * @param string $appId |
|
352 | - * @param array $groups (optional) when set, only these groups will have access to the app |
|
353 | - * @throws \Exception |
|
354 | - * @return void |
|
355 | - * |
|
356 | - * This function set an app as enabled in appconfig. |
|
357 | - */ |
|
358 | - public function enable($appId, |
|
359 | - $groups = null) { |
|
360 | - self::$enabledAppsCache = []; // flush |
|
361 | - $l = \OC::$server->getL10N('core'); |
|
362 | - $config = \OC::$server->getConfig(); |
|
363 | - |
|
364 | - // Check if app is already downloaded |
|
365 | - $installer = new Installer( |
|
366 | - \OC::$server->getAppFetcher(), |
|
367 | - \OC::$server->getHTTPClientService(), |
|
368 | - \OC::$server->getTempManager(), |
|
369 | - \OC::$server->getLogger() |
|
370 | - ); |
|
371 | - $isDownloaded = $installer->isDownloaded($appId); |
|
372 | - |
|
373 | - if(!$isDownloaded) { |
|
374 | - $installer->downloadApp($appId); |
|
375 | - } |
|
376 | - |
|
377 | - if (!Installer::isInstalled($appId)) { |
|
378 | - $appId = self::installApp( |
|
379 | - $appId, |
|
380 | - $config, |
|
381 | - $l |
|
382 | - ); |
|
383 | - $appPath = self::getAppPath($appId); |
|
384 | - self::registerAutoloading($appId, $appPath); |
|
385 | - $installer->installApp($appId); |
|
386 | - } else { |
|
387 | - // check for required dependencies |
|
388 | - $info = self::getAppInfo($appId); |
|
389 | - self::checkAppDependencies($config, $l, $info); |
|
390 | - $appPath = self::getAppPath($appId); |
|
391 | - self::registerAutoloading($appId, $appPath); |
|
392 | - $installer->installApp($appId); |
|
393 | - } |
|
394 | - |
|
395 | - $appManager = \OC::$server->getAppManager(); |
|
396 | - if (!is_null($groups)) { |
|
397 | - $groupManager = \OC::$server->getGroupManager(); |
|
398 | - $groupsList = []; |
|
399 | - foreach ($groups as $group) { |
|
400 | - $groupItem = $groupManager->get($group); |
|
401 | - if ($groupItem instanceof \OCP\IGroup) { |
|
402 | - $groupsList[] = $groupManager->get($group); |
|
403 | - } |
|
404 | - } |
|
405 | - $appManager->enableAppForGroups($appId, $groupsList); |
|
406 | - } else { |
|
407 | - $appManager->enableApp($appId); |
|
408 | - } |
|
409 | - |
|
410 | - $info = self::getAppInfo($appId); |
|
411 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
412 | - $appPath = self::getAppPath($appId); |
|
413 | - self::registerAutoloading($appId, $appPath); |
|
414 | - \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
415 | - } |
|
416 | - } |
|
417 | - |
|
418 | - /** |
|
419 | - * @param string $app |
|
420 | - * @return bool |
|
421 | - */ |
|
422 | - public static function removeApp($app) { |
|
423 | - if (self::isShipped($app)) { |
|
424 | - return false; |
|
425 | - } |
|
426 | - |
|
427 | - $installer = new Installer( |
|
428 | - \OC::$server->getAppFetcher(), |
|
429 | - \OC::$server->getHTTPClientService(), |
|
430 | - \OC::$server->getTempManager(), |
|
431 | - \OC::$server->getLogger() |
|
432 | - ); |
|
433 | - return $installer->removeApp($app); |
|
434 | - } |
|
435 | - |
|
436 | - /** |
|
437 | - * This function set an app as disabled in appconfig. |
|
438 | - * |
|
439 | - * @param string $app app |
|
440 | - * @throws Exception |
|
441 | - */ |
|
442 | - public static function disable($app) { |
|
443 | - // flush |
|
444 | - self::$enabledAppsCache = array(); |
|
445 | - |
|
446 | - // run uninstall steps |
|
447 | - $appData = OC_App::getAppInfo($app); |
|
448 | - if (!is_null($appData)) { |
|
449 | - OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']); |
|
450 | - } |
|
451 | - |
|
452 | - // emit disable hook - needed anymore ? |
|
453 | - \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app)); |
|
454 | - |
|
455 | - // finally disable it |
|
456 | - $appManager = \OC::$server->getAppManager(); |
|
457 | - $appManager->disableApp($app); |
|
458 | - } |
|
459 | - |
|
460 | - // This is private as well. It simply works, so don't ask for more details |
|
461 | - private static function proceedNavigation($list) { |
|
462 | - usort($list, function($a, $b) { |
|
463 | - if (isset($a['order']) && isset($b['order'])) { |
|
464 | - return ($a['order'] < $b['order']) ? -1 : 1; |
|
465 | - } else if (isset($a['order']) || isset($b['order'])) { |
|
466 | - return isset($a['order']) ? -1 : 1; |
|
467 | - } else { |
|
468 | - return ($a['name'] < $b['name']) ? -1 : 1; |
|
469 | - } |
|
470 | - }); |
|
471 | - |
|
472 | - $activeAppIndex = -1; |
|
473 | - $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); |
|
474 | - foreach ($list as $index => &$navEntry) { |
|
475 | - $navEntry['showInHeader'] = true; |
|
476 | - if ($navEntry['id'] == $activeApp) { |
|
477 | - $navEntry['active'] = true; |
|
478 | - $activeAppIndex = $index; |
|
479 | - } else { |
|
480 | - $navEntry['active'] = false; |
|
481 | - } |
|
482 | - } |
|
483 | - unset($navEntry); |
|
484 | - |
|
485 | - if (count($list) <= 8) { |
|
486 | - return $list; |
|
487 | - } |
|
488 | - |
|
489 | - $headerIconCount = 7; |
|
490 | - if($activeAppIndex > ($headerIconCount-1)) { |
|
491 | - $active = $list[$activeAppIndex]; |
|
492 | - $lastInHeader = $list[$headerIconCount-1]; |
|
493 | - $list[$headerIconCount-1] = $active; |
|
494 | - $list[$activeAppIndex] = $lastInHeader; |
|
495 | - } |
|
496 | - |
|
497 | - foreach ($list as $index => &$navEntry) { |
|
498 | - if($index >= $headerIconCount) { |
|
499 | - $navEntry['showInHeader'] = false; |
|
500 | - } |
|
501 | - } |
|
502 | - |
|
503 | - return $list; |
|
504 | - } |
|
505 | - |
|
506 | - public static function proceedAppNavigation($entries) { |
|
507 | - $activeAppIndex = -1; |
|
508 | - $list = self::proceedNavigation($entries); |
|
509 | - |
|
510 | - $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); |
|
511 | - foreach ($list as $index => &$navEntry) { |
|
512 | - if ($navEntry['id'] == $activeApp) { |
|
513 | - $navEntry['active'] = true; |
|
514 | - $activeAppIndex = $index; |
|
515 | - } else { |
|
516 | - $navEntry['active'] = false; |
|
517 | - } |
|
518 | - } |
|
519 | - |
|
520 | - |
|
521 | - if (count($list) <= 8) { |
|
522 | - return $list; |
|
523 | - } |
|
524 | - |
|
525 | - $headerIconCount = 7; |
|
526 | - // move active item to last position |
|
527 | - if($activeAppIndex > ($headerIconCount-1)) { |
|
528 | - $active = $list[$activeAppIndex]; |
|
529 | - $lastInHeader = $list[$headerIconCount-1]; |
|
530 | - $list[$headerIconCount-1] = $active; |
|
531 | - $list[$activeAppIndex] = $lastInHeader; |
|
532 | - } |
|
533 | - $list = array_slice($list, 0, $headerIconCount); |
|
534 | - |
|
535 | - return $list; |
|
536 | - } |
|
537 | - |
|
538 | - /** |
|
539 | - * Get the path where to install apps |
|
540 | - * |
|
541 | - * @return string|false |
|
542 | - */ |
|
543 | - public static function getInstallPath() { |
|
544 | - if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) { |
|
545 | - return false; |
|
546 | - } |
|
547 | - |
|
548 | - foreach (OC::$APPSROOTS as $dir) { |
|
549 | - if (isset($dir['writable']) && $dir['writable'] === true) { |
|
550 | - return $dir['path']; |
|
551 | - } |
|
552 | - } |
|
553 | - |
|
554 | - \OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR); |
|
555 | - return null; |
|
556 | - } |
|
557 | - |
|
558 | - |
|
559 | - /** |
|
560 | - * search for an app in all app-directories |
|
561 | - * |
|
562 | - * @param string $appId |
|
563 | - * @return false|string |
|
564 | - */ |
|
565 | - public static function findAppInDirectories($appId) { |
|
566 | - $sanitizedAppId = self::cleanAppId($appId); |
|
567 | - if($sanitizedAppId !== $appId) { |
|
568 | - return false; |
|
569 | - } |
|
570 | - static $app_dir = array(); |
|
571 | - |
|
572 | - if (isset($app_dir[$appId])) { |
|
573 | - return $app_dir[$appId]; |
|
574 | - } |
|
575 | - |
|
576 | - $possibleApps = array(); |
|
577 | - foreach (OC::$APPSROOTS as $dir) { |
|
578 | - if (file_exists($dir['path'] . '/' . $appId)) { |
|
579 | - $possibleApps[] = $dir; |
|
580 | - } |
|
581 | - } |
|
582 | - |
|
583 | - if (empty($possibleApps)) { |
|
584 | - return false; |
|
585 | - } elseif (count($possibleApps) === 1) { |
|
586 | - $dir = array_shift($possibleApps); |
|
587 | - $app_dir[$appId] = $dir; |
|
588 | - return $dir; |
|
589 | - } else { |
|
590 | - $versionToLoad = array(); |
|
591 | - foreach ($possibleApps as $possibleApp) { |
|
592 | - $version = self::getAppVersionByPath($possibleApp['path']); |
|
593 | - if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) { |
|
594 | - $versionToLoad = array( |
|
595 | - 'dir' => $possibleApp, |
|
596 | - 'version' => $version, |
|
597 | - ); |
|
598 | - } |
|
599 | - } |
|
600 | - $app_dir[$appId] = $versionToLoad['dir']; |
|
601 | - return $versionToLoad['dir']; |
|
602 | - //TODO - write test |
|
603 | - } |
|
604 | - } |
|
605 | - |
|
606 | - /** |
|
607 | - * Get the directory for the given app. |
|
608 | - * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
609 | - * |
|
610 | - * @param string $appId |
|
611 | - * @return string|false |
|
612 | - */ |
|
613 | - public static function getAppPath($appId) { |
|
614 | - if ($appId === null || trim($appId) === '') { |
|
615 | - return false; |
|
616 | - } |
|
617 | - |
|
618 | - if (($dir = self::findAppInDirectories($appId)) != false) { |
|
619 | - return $dir['path'] . '/' . $appId; |
|
620 | - } |
|
621 | - return false; |
|
622 | - } |
|
623 | - |
|
624 | - /** |
|
625 | - * Get the path for the given app on the access |
|
626 | - * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
627 | - * |
|
628 | - * @param string $appId |
|
629 | - * @return string|false |
|
630 | - */ |
|
631 | - public static function getAppWebPath($appId) { |
|
632 | - if (($dir = self::findAppInDirectories($appId)) != false) { |
|
633 | - return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
634 | - } |
|
635 | - return false; |
|
636 | - } |
|
637 | - |
|
638 | - /** |
|
639 | - * get the last version of the app from appinfo/info.xml |
|
640 | - * |
|
641 | - * @param string $appId |
|
642 | - * @param bool $useCache |
|
643 | - * @return string |
|
644 | - */ |
|
645 | - public static function getAppVersion($appId, $useCache = true) { |
|
646 | - if($useCache && isset(self::$appVersion[$appId])) { |
|
647 | - return self::$appVersion[$appId]; |
|
648 | - } |
|
649 | - |
|
650 | - $file = self::getAppPath($appId); |
|
651 | - self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0'; |
|
652 | - return self::$appVersion[$appId]; |
|
653 | - } |
|
654 | - |
|
655 | - /** |
|
656 | - * get app's version based on it's path |
|
657 | - * |
|
658 | - * @param string $path |
|
659 | - * @return string |
|
660 | - */ |
|
661 | - public static function getAppVersionByPath($path) { |
|
662 | - $infoFile = $path . '/appinfo/info.xml'; |
|
663 | - $appData = self::getAppInfo($infoFile, true); |
|
664 | - return isset($appData['version']) ? $appData['version'] : ''; |
|
665 | - } |
|
666 | - |
|
667 | - |
|
668 | - /** |
|
669 | - * Read all app metadata from the info.xml file |
|
670 | - * |
|
671 | - * @param string $appId id of the app or the path of the info.xml file |
|
672 | - * @param bool $path |
|
673 | - * @param string $lang |
|
674 | - * @return array|null |
|
675 | - * @note all data is read from info.xml, not just pre-defined fields |
|
676 | - */ |
|
677 | - public static function getAppInfo($appId, $path = false, $lang = null) { |
|
678 | - if ($path) { |
|
679 | - $file = $appId; |
|
680 | - } else { |
|
681 | - if ($lang === null && isset(self::$appInfo[$appId])) { |
|
682 | - return self::$appInfo[$appId]; |
|
683 | - } |
|
684 | - $appPath = self::getAppPath($appId); |
|
685 | - if($appPath === false) { |
|
686 | - return null; |
|
687 | - } |
|
688 | - $file = $appPath . '/appinfo/info.xml'; |
|
689 | - } |
|
690 | - |
|
691 | - $parser = new InfoParser(\OC::$server->getMemCacheFactory()->create('core.appinfo')); |
|
692 | - $data = $parser->parse($file); |
|
693 | - |
|
694 | - if (is_array($data)) { |
|
695 | - $data = OC_App::parseAppInfo($data, $lang); |
|
696 | - } |
|
697 | - if(isset($data['ocsid'])) { |
|
698 | - $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
|
699 | - if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
700 | - $data['ocsid'] = $storedId; |
|
701 | - } |
|
702 | - } |
|
703 | - |
|
704 | - if ($lang === null) { |
|
705 | - self::$appInfo[$appId] = $data; |
|
706 | - } |
|
707 | - |
|
708 | - return $data; |
|
709 | - } |
|
710 | - |
|
711 | - /** |
|
712 | - * Returns the navigation |
|
713 | - * |
|
714 | - * @return array |
|
715 | - * |
|
716 | - * This function returns an array containing all entries added. The |
|
717 | - * entries are sorted by the key 'order' ascending. Additional to the keys |
|
718 | - * given for each app the following keys exist: |
|
719 | - * - active: boolean, signals if the user is on this navigation entry |
|
720 | - */ |
|
721 | - public static function getNavigation() { |
|
722 | - $entries = OC::$server->getNavigationManager()->getAll(); |
|
723 | - return self::proceedNavigation($entries); |
|
724 | - } |
|
725 | - |
|
726 | - /** |
|
727 | - * Returns the navigation inside the header bar |
|
728 | - * |
|
729 | - * @return array |
|
730 | - * |
|
731 | - * This function returns an array containing all entries added. The |
|
732 | - * entries are sorted by the key 'order' ascending. Additional to the keys |
|
733 | - * given for each app the following keys exist: |
|
734 | - * - active: boolean, signals if the user is on this navigation entry |
|
735 | - */ |
|
736 | - public static function getHeaderNavigation() { |
|
737 | - $entries = OC::$server->getNavigationManager()->getAll(); |
|
738 | - return self::proceedAppNavigation($entries); |
|
739 | - } |
|
740 | - |
|
741 | - /** |
|
742 | - * Returns the Settings Navigation |
|
743 | - * |
|
744 | - * @return string[] |
|
745 | - * |
|
746 | - * This function returns an array containing all settings pages added. The |
|
747 | - * entries are sorted by the key 'order' ascending. |
|
748 | - */ |
|
749 | - public static function getSettingsNavigation() { |
|
750 | - $entries = OC::$server->getNavigationManager()->getAll('settings'); |
|
751 | - return self::proceedNavigation($entries); |
|
752 | - } |
|
753 | - |
|
754 | - /** |
|
755 | - * get the id of loaded app |
|
756 | - * |
|
757 | - * @return string |
|
758 | - */ |
|
759 | - public static function getCurrentApp() { |
|
760 | - $request = \OC::$server->getRequest(); |
|
761 | - $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1); |
|
762 | - $topFolder = substr($script, 0, strpos($script, '/')); |
|
763 | - if (empty($topFolder)) { |
|
764 | - $path_info = $request->getPathInfo(); |
|
765 | - if ($path_info) { |
|
766 | - $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1); |
|
767 | - } |
|
768 | - } |
|
769 | - if ($topFolder == 'apps') { |
|
770 | - $length = strlen($topFolder); |
|
771 | - return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1); |
|
772 | - } else { |
|
773 | - return $topFolder; |
|
774 | - } |
|
775 | - } |
|
776 | - |
|
777 | - /** |
|
778 | - * @param string $type |
|
779 | - * @return array |
|
780 | - */ |
|
781 | - public static function getForms($type) { |
|
782 | - $forms = array(); |
|
783 | - switch ($type) { |
|
784 | - case 'admin': |
|
785 | - $source = self::$adminForms; |
|
786 | - break; |
|
787 | - case 'personal': |
|
788 | - $source = self::$personalForms; |
|
789 | - break; |
|
790 | - default: |
|
791 | - return array(); |
|
792 | - } |
|
793 | - foreach ($source as $form) { |
|
794 | - $forms[] = include $form; |
|
795 | - } |
|
796 | - return $forms; |
|
797 | - } |
|
798 | - |
|
799 | - /** |
|
800 | - * register an admin form to be shown |
|
801 | - * |
|
802 | - * @param string $app |
|
803 | - * @param string $page |
|
804 | - */ |
|
805 | - public static function registerAdmin($app, $page) { |
|
806 | - self::$adminForms[] = $app . '/' . $page . '.php'; |
|
807 | - } |
|
808 | - |
|
809 | - /** |
|
810 | - * register a personal form to be shown |
|
811 | - * @param string $app |
|
812 | - * @param string $page |
|
813 | - */ |
|
814 | - public static function registerPersonal($app, $page) { |
|
815 | - self::$personalForms[] = $app . '/' . $page . '.php'; |
|
816 | - } |
|
817 | - |
|
818 | - /** |
|
819 | - * @param array $entry |
|
820 | - */ |
|
821 | - public static function registerLogIn(array $entry) { |
|
822 | - self::$altLogin[] = $entry; |
|
823 | - } |
|
824 | - |
|
825 | - /** |
|
826 | - * @return array |
|
827 | - */ |
|
828 | - public static function getAlternativeLogIns() { |
|
829 | - return self::$altLogin; |
|
830 | - } |
|
831 | - |
|
832 | - /** |
|
833 | - * get a list of all apps in the apps folder |
|
834 | - * |
|
835 | - * @return array an array of app names (string IDs) |
|
836 | - * @todo: change the name of this method to getInstalledApps, which is more accurate |
|
837 | - */ |
|
838 | - public static function getAllApps() { |
|
839 | - |
|
840 | - $apps = array(); |
|
841 | - |
|
842 | - foreach (OC::$APPSROOTS as $apps_dir) { |
|
843 | - if (!is_readable($apps_dir['path'])) { |
|
844 | - \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
845 | - continue; |
|
846 | - } |
|
847 | - $dh = opendir($apps_dir['path']); |
|
848 | - |
|
849 | - if (is_resource($dh)) { |
|
850 | - while (($file = readdir($dh)) !== false) { |
|
851 | - |
|
852 | - if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
853 | - |
|
854 | - $apps[] = $file; |
|
855 | - } |
|
856 | - } |
|
857 | - } |
|
858 | - } |
|
859 | - |
|
860 | - return $apps; |
|
861 | - } |
|
862 | - |
|
863 | - /** |
|
864 | - * List all apps, this is used in apps.php |
|
865 | - * |
|
866 | - * @return array |
|
867 | - */ |
|
868 | - public function listAllApps() { |
|
869 | - $installedApps = OC_App::getAllApps(); |
|
870 | - |
|
871 | - //we don't want to show configuration for these |
|
872 | - $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
|
873 | - $appList = array(); |
|
874 | - $langCode = \OC::$server->getL10N('core')->getLanguageCode(); |
|
875 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
876 | - |
|
877 | - foreach ($installedApps as $app) { |
|
878 | - if (array_search($app, $blacklist) === false) { |
|
879 | - |
|
880 | - $info = OC_App::getAppInfo($app, false, $langCode); |
|
881 | - if (!is_array($info)) { |
|
882 | - \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
883 | - continue; |
|
884 | - } |
|
885 | - |
|
886 | - if (!isset($info['name'])) { |
|
887 | - \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
888 | - continue; |
|
889 | - } |
|
890 | - |
|
891 | - $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'no'); |
|
892 | - $info['groups'] = null; |
|
893 | - if ($enabled === 'yes') { |
|
894 | - $active = true; |
|
895 | - } else if ($enabled === 'no') { |
|
896 | - $active = false; |
|
897 | - } else { |
|
898 | - $active = true; |
|
899 | - $info['groups'] = $enabled; |
|
900 | - } |
|
901 | - |
|
902 | - $info['active'] = $active; |
|
903 | - |
|
904 | - if (self::isShipped($app)) { |
|
905 | - $info['internal'] = true; |
|
906 | - $info['level'] = self::officialApp; |
|
907 | - $info['removable'] = false; |
|
908 | - } else { |
|
909 | - $info['internal'] = false; |
|
910 | - $info['removable'] = true; |
|
911 | - } |
|
912 | - |
|
913 | - $appPath = self::getAppPath($app); |
|
914 | - if($appPath !== false) { |
|
915 | - $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
916 | - if (file_exists($appIcon)) { |
|
917 | - $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app . '.svg'); |
|
918 | - $info['previewAsIcon'] = true; |
|
919 | - } else { |
|
920 | - $appIcon = $appPath . '/img/app.svg'; |
|
921 | - if (file_exists($appIcon)) { |
|
922 | - $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, 'app.svg'); |
|
923 | - $info['previewAsIcon'] = true; |
|
924 | - } |
|
925 | - } |
|
926 | - } |
|
927 | - // fix documentation |
|
928 | - if (isset($info['documentation']) && is_array($info['documentation'])) { |
|
929 | - foreach ($info['documentation'] as $key => $url) { |
|
930 | - // If it is not an absolute URL we assume it is a key |
|
931 | - // i.e. admin-ldap will get converted to go.php?to=admin-ldap |
|
932 | - if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) { |
|
933 | - $url = $urlGenerator->linkToDocs($url); |
|
934 | - } |
|
935 | - |
|
936 | - $info['documentation'][$key] = $url; |
|
937 | - } |
|
938 | - } |
|
939 | - |
|
940 | - $info['version'] = OC_App::getAppVersion($app); |
|
941 | - $appList[] = $info; |
|
942 | - } |
|
943 | - } |
|
944 | - |
|
945 | - return $appList; |
|
946 | - } |
|
947 | - |
|
948 | - /** |
|
949 | - * Returns the internal app ID or false |
|
950 | - * @param string $ocsID |
|
951 | - * @return string|false |
|
952 | - */ |
|
953 | - public static function getInternalAppIdByOcs($ocsID) { |
|
954 | - if(is_numeric($ocsID)) { |
|
955 | - $idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid'); |
|
956 | - if(array_search($ocsID, $idArray)) { |
|
957 | - return array_search($ocsID, $idArray); |
|
958 | - } |
|
959 | - } |
|
960 | - return false; |
|
961 | - } |
|
962 | - |
|
963 | - public static function shouldUpgrade($app) { |
|
964 | - $versions = self::getAppVersions(); |
|
965 | - $currentVersion = OC_App::getAppVersion($app); |
|
966 | - if ($currentVersion && isset($versions[$app])) { |
|
967 | - $installedVersion = $versions[$app]; |
|
968 | - if (!version_compare($currentVersion, $installedVersion, '=')) { |
|
969 | - return true; |
|
970 | - } |
|
971 | - } |
|
972 | - return false; |
|
973 | - } |
|
974 | - |
|
975 | - /** |
|
976 | - * Adjust the number of version parts of $version1 to match |
|
977 | - * the number of version parts of $version2. |
|
978 | - * |
|
979 | - * @param string $version1 version to adjust |
|
980 | - * @param string $version2 version to take the number of parts from |
|
981 | - * @return string shortened $version1 |
|
982 | - */ |
|
983 | - private static function adjustVersionParts($version1, $version2) { |
|
984 | - $version1 = explode('.', $version1); |
|
985 | - $version2 = explode('.', $version2); |
|
986 | - // reduce $version1 to match the number of parts in $version2 |
|
987 | - while (count($version1) > count($version2)) { |
|
988 | - array_pop($version1); |
|
989 | - } |
|
990 | - // if $version1 does not have enough parts, add some |
|
991 | - while (count($version1) < count($version2)) { |
|
992 | - $version1[] = '0'; |
|
993 | - } |
|
994 | - return implode('.', $version1); |
|
995 | - } |
|
996 | - |
|
997 | - /** |
|
998 | - * Check whether the current ownCloud version matches the given |
|
999 | - * application's version requirements. |
|
1000 | - * |
|
1001 | - * The comparison is made based on the number of parts that the |
|
1002 | - * app info version has. For example for ownCloud 6.0.3 if the |
|
1003 | - * app info version is expecting version 6.0, the comparison is |
|
1004 | - * made on the first two parts of the ownCloud version. |
|
1005 | - * This means that it's possible to specify "requiremin" => 6 |
|
1006 | - * and "requiremax" => 6 and it will still match ownCloud 6.0.3. |
|
1007 | - * |
|
1008 | - * @param string $ocVersion ownCloud version to check against |
|
1009 | - * @param array $appInfo app info (from xml) |
|
1010 | - * |
|
1011 | - * @return boolean true if compatible, otherwise false |
|
1012 | - */ |
|
1013 | - public static function isAppCompatible($ocVersion, $appInfo) { |
|
1014 | - $requireMin = ''; |
|
1015 | - $requireMax = ''; |
|
1016 | - if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) { |
|
1017 | - $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version']; |
|
1018 | - } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) { |
|
1019 | - $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version']; |
|
1020 | - } else if (isset($appInfo['requiremin'])) { |
|
1021 | - $requireMin = $appInfo['requiremin']; |
|
1022 | - } else if (isset($appInfo['require'])) { |
|
1023 | - $requireMin = $appInfo['require']; |
|
1024 | - } |
|
1025 | - |
|
1026 | - if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) { |
|
1027 | - $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version']; |
|
1028 | - } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) { |
|
1029 | - $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version']; |
|
1030 | - } else if (isset($appInfo['requiremax'])) { |
|
1031 | - $requireMax = $appInfo['requiremax']; |
|
1032 | - } |
|
1033 | - |
|
1034 | - if (is_array($ocVersion)) { |
|
1035 | - $ocVersion = implode('.', $ocVersion); |
|
1036 | - } |
|
1037 | - |
|
1038 | - if (!empty($requireMin) |
|
1039 | - && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<') |
|
1040 | - ) { |
|
1041 | - |
|
1042 | - return false; |
|
1043 | - } |
|
1044 | - |
|
1045 | - if (!empty($requireMax) |
|
1046 | - && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>') |
|
1047 | - ) { |
|
1048 | - return false; |
|
1049 | - } |
|
1050 | - |
|
1051 | - return true; |
|
1052 | - } |
|
1053 | - |
|
1054 | - /** |
|
1055 | - * get the installed version of all apps |
|
1056 | - */ |
|
1057 | - public static function getAppVersions() { |
|
1058 | - static $versions; |
|
1059 | - |
|
1060 | - if(!$versions) { |
|
1061 | - $appConfig = \OC::$server->getAppConfig(); |
|
1062 | - $versions = $appConfig->getValues(false, 'installed_version'); |
|
1063 | - } |
|
1064 | - return $versions; |
|
1065 | - } |
|
1066 | - |
|
1067 | - /** |
|
1068 | - * @param string $app |
|
1069 | - * @param \OCP\IConfig $config |
|
1070 | - * @param \OCP\IL10N $l |
|
1071 | - * @return bool |
|
1072 | - * |
|
1073 | - * @throws Exception if app is not compatible with this version of ownCloud |
|
1074 | - * @throws Exception if no app-name was specified |
|
1075 | - */ |
|
1076 | - public function installApp($app, |
|
1077 | - \OCP\IConfig $config, |
|
1078 | - \OCP\IL10N $l) { |
|
1079 | - if ($app !== false) { |
|
1080 | - // check if the app is compatible with this version of ownCloud |
|
1081 | - $info = self::getAppInfo($app); |
|
1082 | - if(!is_array($info)) { |
|
1083 | - throw new \Exception( |
|
1084 | - $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
1085 | - [$info['name']] |
|
1086 | - ) |
|
1087 | - ); |
|
1088 | - } |
|
1089 | - |
|
1090 | - $version = \OCP\Util::getVersion(); |
|
1091 | - if (!self::isAppCompatible($version, $info)) { |
|
1092 | - throw new \Exception( |
|
1093 | - $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
1094 | - array($info['name']) |
|
1095 | - ) |
|
1096 | - ); |
|
1097 | - } |
|
1098 | - |
|
1099 | - // check for required dependencies |
|
1100 | - self::checkAppDependencies($config, $l, $info); |
|
1101 | - |
|
1102 | - $config->setAppValue($app, 'enabled', 'yes'); |
|
1103 | - if (isset($appData['id'])) { |
|
1104 | - $config->setAppValue($app, 'ocsid', $appData['id']); |
|
1105 | - } |
|
1106 | - |
|
1107 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
1108 | - $appPath = self::getAppPath($app); |
|
1109 | - self::registerAutoloading($app, $appPath); |
|
1110 | - \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
1111 | - } |
|
1112 | - |
|
1113 | - \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
|
1114 | - } else { |
|
1115 | - if(empty($appName) ) { |
|
1116 | - throw new \Exception($l->t("No app name specified")); |
|
1117 | - } else { |
|
1118 | - throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
|
1119 | - } |
|
1120 | - } |
|
1121 | - |
|
1122 | - return $app; |
|
1123 | - } |
|
1124 | - |
|
1125 | - /** |
|
1126 | - * update the database for the app and call the update script |
|
1127 | - * |
|
1128 | - * @param string $appId |
|
1129 | - * @return bool |
|
1130 | - */ |
|
1131 | - public static function updateApp($appId) { |
|
1132 | - $appPath = self::getAppPath($appId); |
|
1133 | - if($appPath === false) { |
|
1134 | - return false; |
|
1135 | - } |
|
1136 | - $appData = self::getAppInfo($appId); |
|
1137 | - self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
|
1138 | - if (file_exists($appPath . '/appinfo/database.xml')) { |
|
1139 | - OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
1140 | - } |
|
1141 | - self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
|
1142 | - self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
|
1143 | - unset(self::$appVersion[$appId]); |
|
1144 | - // run upgrade code |
|
1145 | - if (file_exists($appPath . '/appinfo/update.php')) { |
|
1146 | - self::loadApp($appId); |
|
1147 | - include $appPath . '/appinfo/update.php'; |
|
1148 | - } |
|
1149 | - self::setupBackgroundJobs($appData['background-jobs']); |
|
1150 | - if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
1151 | - $appPath = self::getAppPath($appId); |
|
1152 | - self::registerAutoloading($appId, $appPath); |
|
1153 | - \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
|
1154 | - } |
|
1155 | - |
|
1156 | - //set remote/public handlers |
|
1157 | - if (array_key_exists('ocsid', $appData)) { |
|
1158 | - \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
|
1159 | - } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
1160 | - \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
|
1161 | - } |
|
1162 | - foreach ($appData['remote'] as $name => $path) { |
|
1163 | - \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
1164 | - } |
|
1165 | - foreach ($appData['public'] as $name => $path) { |
|
1166 | - \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
1167 | - } |
|
1168 | - |
|
1169 | - self::setAppTypes($appId); |
|
1170 | - |
|
1171 | - $version = \OC_App::getAppVersion($appId); |
|
1172 | - \OC::$server->getAppConfig()->setValue($appId, 'installed_version', $version); |
|
1173 | - |
|
1174 | - \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( |
|
1175 | - ManagerEvent::EVENT_APP_UPDATE, $appId |
|
1176 | - )); |
|
1177 | - |
|
1178 | - return true; |
|
1179 | - } |
|
1180 | - |
|
1181 | - /** |
|
1182 | - * @param string $appId |
|
1183 | - * @param string[] $steps |
|
1184 | - * @throws \OC\NeedsUpdateException |
|
1185 | - */ |
|
1186 | - public static function executeRepairSteps($appId, array $steps) { |
|
1187 | - if (empty($steps)) { |
|
1188 | - return; |
|
1189 | - } |
|
1190 | - // load the app |
|
1191 | - self::loadApp($appId); |
|
1192 | - |
|
1193 | - $dispatcher = OC::$server->getEventDispatcher(); |
|
1194 | - |
|
1195 | - // load the steps |
|
1196 | - $r = new Repair([], $dispatcher); |
|
1197 | - foreach ($steps as $step) { |
|
1198 | - try { |
|
1199 | - $r->addStep($step); |
|
1200 | - } catch (Exception $ex) { |
|
1201 | - $r->emit('\OC\Repair', 'error', [$ex->getMessage()]); |
|
1202 | - \OC::$server->getLogger()->logException($ex); |
|
1203 | - } |
|
1204 | - } |
|
1205 | - // run the steps |
|
1206 | - $r->run(); |
|
1207 | - } |
|
1208 | - |
|
1209 | - public static function setupBackgroundJobs(array $jobs) { |
|
1210 | - $queue = \OC::$server->getJobList(); |
|
1211 | - foreach ($jobs as $job) { |
|
1212 | - $queue->add($job); |
|
1213 | - } |
|
1214 | - } |
|
1215 | - |
|
1216 | - /** |
|
1217 | - * @param string $appId |
|
1218 | - * @param string[] $steps |
|
1219 | - */ |
|
1220 | - private static function setupLiveMigrations($appId, array $steps) { |
|
1221 | - $queue = \OC::$server->getJobList(); |
|
1222 | - foreach ($steps as $step) { |
|
1223 | - $queue->add('OC\Migration\BackgroundRepair', [ |
|
1224 | - 'app' => $appId, |
|
1225 | - 'step' => $step]); |
|
1226 | - } |
|
1227 | - } |
|
1228 | - |
|
1229 | - /** |
|
1230 | - * @param string $appId |
|
1231 | - * @return \OC\Files\View|false |
|
1232 | - */ |
|
1233 | - public static function getStorage($appId) { |
|
1234 | - if (OC_App::isEnabled($appId)) { //sanity check |
|
1235 | - if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
1236 | - $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
1237 | - if (!$view->file_exists($appId)) { |
|
1238 | - $view->mkdir($appId); |
|
1239 | - } |
|
1240 | - return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
1241 | - } else { |
|
1242 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
1243 | - return false; |
|
1244 | - } |
|
1245 | - } else { |
|
1246 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
1247 | - return false; |
|
1248 | - } |
|
1249 | - } |
|
1250 | - |
|
1251 | - protected static function findBestL10NOption($options, $lang) { |
|
1252 | - $fallback = $similarLangFallback = $englishFallback = false; |
|
1253 | - |
|
1254 | - $lang = strtolower($lang); |
|
1255 | - $similarLang = $lang; |
|
1256 | - if (strpos($similarLang, '_')) { |
|
1257 | - // For "de_DE" we want to find "de" and the other way around |
|
1258 | - $similarLang = substr($lang, 0, strpos($lang, '_')); |
|
1259 | - } |
|
1260 | - |
|
1261 | - foreach ($options as $option) { |
|
1262 | - if (is_array($option)) { |
|
1263 | - if ($fallback === false) { |
|
1264 | - $fallback = $option['@value']; |
|
1265 | - } |
|
1266 | - |
|
1267 | - if (!isset($option['@attributes']['lang'])) { |
|
1268 | - continue; |
|
1269 | - } |
|
1270 | - |
|
1271 | - $attributeLang = strtolower($option['@attributes']['lang']); |
|
1272 | - if ($attributeLang === $lang) { |
|
1273 | - return $option['@value']; |
|
1274 | - } |
|
1275 | - |
|
1276 | - if ($attributeLang === $similarLang) { |
|
1277 | - $similarLangFallback = $option['@value']; |
|
1278 | - } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
1279 | - if ($similarLangFallback === false) { |
|
1280 | - $similarLangFallback = $option['@value']; |
|
1281 | - } |
|
1282 | - } |
|
1283 | - } else { |
|
1284 | - $englishFallback = $option; |
|
1285 | - } |
|
1286 | - } |
|
1287 | - |
|
1288 | - if ($similarLangFallback !== false) { |
|
1289 | - return $similarLangFallback; |
|
1290 | - } else if ($englishFallback !== false) { |
|
1291 | - return $englishFallback; |
|
1292 | - } |
|
1293 | - return (string) $fallback; |
|
1294 | - } |
|
1295 | - |
|
1296 | - /** |
|
1297 | - * parses the app data array and enhanced the 'description' value |
|
1298 | - * |
|
1299 | - * @param array $data the app data |
|
1300 | - * @param string $lang |
|
1301 | - * @return array improved app data |
|
1302 | - */ |
|
1303 | - public static function parseAppInfo(array $data, $lang = null) { |
|
1304 | - |
|
1305 | - if ($lang && isset($data['name']) && is_array($data['name'])) { |
|
1306 | - $data['name'] = self::findBestL10NOption($data['name'], $lang); |
|
1307 | - } |
|
1308 | - if ($lang && isset($data['summary']) && is_array($data['summary'])) { |
|
1309 | - $data['summary'] = self::findBestL10NOption($data['summary'], $lang); |
|
1310 | - } |
|
1311 | - if ($lang && isset($data['description']) && is_array($data['description'])) { |
|
1312 | - $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
|
1313 | - } else if (isset($data['description']) && is_string($data['description'])) { |
|
1314 | - $data['description'] = trim($data['description']); |
|
1315 | - } else { |
|
1316 | - $data['description'] = ''; |
|
1317 | - } |
|
1318 | - |
|
1319 | - return $data; |
|
1320 | - } |
|
1321 | - |
|
1322 | - /** |
|
1323 | - * @param \OCP\IConfig $config |
|
1324 | - * @param \OCP\IL10N $l |
|
1325 | - * @param array $info |
|
1326 | - * @throws \Exception |
|
1327 | - */ |
|
1328 | - protected static function checkAppDependencies($config, $l, $info) { |
|
1329 | - $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); |
|
1330 | - $missing = $dependencyAnalyzer->analyze($info); |
|
1331 | - if (!empty($missing)) { |
|
1332 | - $missingMsg = join(PHP_EOL, $missing); |
|
1333 | - throw new \Exception( |
|
1334 | - $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s', |
|
1335 | - [$info['name'], $missingMsg] |
|
1336 | - ) |
|
1337 | - ); |
|
1338 | - } |
|
1339 | - } |
|
64 | + static private $appVersion = []; |
|
65 | + static private $adminForms = array(); |
|
66 | + static private $personalForms = array(); |
|
67 | + static private $appInfo = array(); |
|
68 | + static private $appTypes = array(); |
|
69 | + static private $loadedApps = array(); |
|
70 | + static private $altLogin = array(); |
|
71 | + static private $alreadyRegistered = []; |
|
72 | + const officialApp = 200; |
|
73 | + |
|
74 | + /** |
|
75 | + * clean the appId |
|
76 | + * |
|
77 | + * @param string|boolean $app AppId that needs to be cleaned |
|
78 | + * @return string |
|
79 | + */ |
|
80 | + public static function cleanAppId($app) { |
|
81 | + return str_replace(array('\0', '/', '\\', '..'), '', $app); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Check if an app is loaded |
|
86 | + * |
|
87 | + * @param string $app |
|
88 | + * @return bool |
|
89 | + */ |
|
90 | + public static function isAppLoaded($app) { |
|
91 | + return in_array($app, self::$loadedApps, true); |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * loads all apps |
|
96 | + * |
|
97 | + * @param string[] | string | null $types |
|
98 | + * @return bool |
|
99 | + * |
|
100 | + * This function walks through the ownCloud directory and loads all apps |
|
101 | + * it can find. A directory contains an app if the file /appinfo/info.xml |
|
102 | + * exists. |
|
103 | + * |
|
104 | + * if $types is set, only apps of those types will be loaded |
|
105 | + */ |
|
106 | + public static function loadApps($types = null) { |
|
107 | + if (\OC::$server->getSystemConfig()->getValue('maintenance', false)) { |
|
108 | + return false; |
|
109 | + } |
|
110 | + // Load the enabled apps here |
|
111 | + $apps = self::getEnabledApps(); |
|
112 | + |
|
113 | + // Add each apps' folder as allowed class path |
|
114 | + foreach($apps as $app) { |
|
115 | + $path = self::getAppPath($app); |
|
116 | + if($path !== false) { |
|
117 | + self::registerAutoloading($app, $path); |
|
118 | + } |
|
119 | + } |
|
120 | + |
|
121 | + // prevent app.php from printing output |
|
122 | + ob_start(); |
|
123 | + foreach ($apps as $app) { |
|
124 | + if ((is_null($types) or self::isType($app, $types)) && !in_array($app, self::$loadedApps)) { |
|
125 | + self::loadApp($app); |
|
126 | + } |
|
127 | + } |
|
128 | + ob_end_clean(); |
|
129 | + |
|
130 | + return true; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * load a single app |
|
135 | + * |
|
136 | + * @param string $app |
|
137 | + */ |
|
138 | + public static function loadApp($app) { |
|
139 | + self::$loadedApps[] = $app; |
|
140 | + $appPath = self::getAppPath($app); |
|
141 | + if($appPath === false) { |
|
142 | + return; |
|
143 | + } |
|
144 | + |
|
145 | + // in case someone calls loadApp() directly |
|
146 | + self::registerAutoloading($app, $appPath); |
|
147 | + |
|
148 | + if (is_file($appPath . '/appinfo/app.php')) { |
|
149 | + \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
150 | + self::requireAppFile($app); |
|
151 | + if (self::isType($app, array('authentication'))) { |
|
152 | + // since authentication apps affect the "is app enabled for group" check, |
|
153 | + // the enabled apps cache needs to be cleared to make sure that the |
|
154 | + // next time getEnableApps() is called it will also include apps that were |
|
155 | + // enabled for groups |
|
156 | + self::$enabledAppsCache = array(); |
|
157 | + } |
|
158 | + \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
159 | + } |
|
160 | + |
|
161 | + $info = self::getAppInfo($app); |
|
162 | + if (!empty($info['activity']['filters'])) { |
|
163 | + foreach ($info['activity']['filters'] as $filter) { |
|
164 | + \OC::$server->getActivityManager()->registerFilter($filter); |
|
165 | + } |
|
166 | + } |
|
167 | + if (!empty($info['activity']['settings'])) { |
|
168 | + foreach ($info['activity']['settings'] as $setting) { |
|
169 | + \OC::$server->getActivityManager()->registerSetting($setting); |
|
170 | + } |
|
171 | + } |
|
172 | + if (!empty($info['activity']['providers'])) { |
|
173 | + foreach ($info['activity']['providers'] as $provider) { |
|
174 | + \OC::$server->getActivityManager()->registerProvider($provider); |
|
175 | + } |
|
176 | + } |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * @internal |
|
181 | + * @param string $app |
|
182 | + * @param string $path |
|
183 | + */ |
|
184 | + public static function registerAutoloading($app, $path) { |
|
185 | + $key = $app . '-' . $path; |
|
186 | + if(isset(self::$alreadyRegistered[$key])) { |
|
187 | + return; |
|
188 | + } |
|
189 | + self::$alreadyRegistered[$key] = true; |
|
190 | + // Register on PSR-4 composer autoloader |
|
191 | + $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
|
192 | + \OC::$server->registerNamespace($app, $appNamespace); |
|
193 | + \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
194 | + if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
|
195 | + \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
196 | + } |
|
197 | + |
|
198 | + // Register on legacy autoloader |
|
199 | + \OC::$loader->addValidRoot($path); |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Load app.php from the given app |
|
204 | + * |
|
205 | + * @param string $app app name |
|
206 | + */ |
|
207 | + private static function requireAppFile($app) { |
|
208 | + try { |
|
209 | + // encapsulated here to avoid variable scope conflicts |
|
210 | + require_once $app . '/appinfo/app.php'; |
|
211 | + } catch (Error $ex) { |
|
212 | + \OC::$server->getLogger()->logException($ex); |
|
213 | + $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
|
214 | + if (!in_array($app, $blacklist)) { |
|
215 | + self::disable($app); |
|
216 | + } |
|
217 | + } |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * check if an app is of a specific type |
|
222 | + * |
|
223 | + * @param string $app |
|
224 | + * @param string|array $types |
|
225 | + * @return bool |
|
226 | + */ |
|
227 | + public static function isType($app, $types) { |
|
228 | + if (is_string($types)) { |
|
229 | + $types = array($types); |
|
230 | + } |
|
231 | + $appTypes = self::getAppTypes($app); |
|
232 | + foreach ($types as $type) { |
|
233 | + if (array_search($type, $appTypes) !== false) { |
|
234 | + return true; |
|
235 | + } |
|
236 | + } |
|
237 | + return false; |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * get the types of an app |
|
242 | + * |
|
243 | + * @param string $app |
|
244 | + * @return array |
|
245 | + */ |
|
246 | + private static function getAppTypes($app) { |
|
247 | + //load the cache |
|
248 | + if (count(self::$appTypes) == 0) { |
|
249 | + self::$appTypes = \OC::$server->getAppConfig()->getValues(false, 'types'); |
|
250 | + } |
|
251 | + |
|
252 | + if (isset(self::$appTypes[$app])) { |
|
253 | + return explode(',', self::$appTypes[$app]); |
|
254 | + } else { |
|
255 | + return array(); |
|
256 | + } |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * read app types from info.xml and cache them in the database |
|
261 | + */ |
|
262 | + public static function setAppTypes($app) { |
|
263 | + $appData = self::getAppInfo($app); |
|
264 | + if(!is_array($appData)) { |
|
265 | + return; |
|
266 | + } |
|
267 | + |
|
268 | + if (isset($appData['types'])) { |
|
269 | + $appTypes = implode(',', $appData['types']); |
|
270 | + } else { |
|
271 | + $appTypes = ''; |
|
272 | + $appData['types'] = []; |
|
273 | + } |
|
274 | + |
|
275 | + \OC::$server->getAppConfig()->setValue($app, 'types', $appTypes); |
|
276 | + |
|
277 | + if (\OC::$server->getAppManager()->hasProtectedAppType($appData['types'])) { |
|
278 | + $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'yes'); |
|
279 | + if ($enabled !== 'yes' && $enabled !== 'no') { |
|
280 | + \OC::$server->getAppConfig()->setValue($app, 'enabled', 'yes'); |
|
281 | + } |
|
282 | + } |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * check if app is shipped |
|
287 | + * |
|
288 | + * @param string $appId the id of the app to check |
|
289 | + * @return bool |
|
290 | + * |
|
291 | + * Check if an app that is installed is a shipped app or installed from the appstore. |
|
292 | + */ |
|
293 | + public static function isShipped($appId) { |
|
294 | + return \OC::$server->getAppManager()->isShipped($appId); |
|
295 | + } |
|
296 | + |
|
297 | + /** |
|
298 | + * get all enabled apps |
|
299 | + */ |
|
300 | + protected static $enabledAppsCache = array(); |
|
301 | + |
|
302 | + /** |
|
303 | + * Returns apps enabled for the current user. |
|
304 | + * |
|
305 | + * @param bool $forceRefresh whether to refresh the cache |
|
306 | + * @param bool $all whether to return apps for all users, not only the |
|
307 | + * currently logged in one |
|
308 | + * @return string[] |
|
309 | + */ |
|
310 | + public static function getEnabledApps($forceRefresh = false, $all = false) { |
|
311 | + if (!\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
312 | + return array(); |
|
313 | + } |
|
314 | + // in incognito mode or when logged out, $user will be false, |
|
315 | + // which is also the case during an upgrade |
|
316 | + $appManager = \OC::$server->getAppManager(); |
|
317 | + if ($all) { |
|
318 | + $user = null; |
|
319 | + } else { |
|
320 | + $user = \OC::$server->getUserSession()->getUser(); |
|
321 | + } |
|
322 | + |
|
323 | + if (is_null($user)) { |
|
324 | + $apps = $appManager->getInstalledApps(); |
|
325 | + } else { |
|
326 | + $apps = $appManager->getEnabledAppsForUser($user); |
|
327 | + } |
|
328 | + $apps = array_filter($apps, function ($app) { |
|
329 | + return $app !== 'files';//we add this manually |
|
330 | + }); |
|
331 | + sort($apps); |
|
332 | + array_unshift($apps, 'files'); |
|
333 | + return $apps; |
|
334 | + } |
|
335 | + |
|
336 | + /** |
|
337 | + * checks whether or not an app is enabled |
|
338 | + * |
|
339 | + * @param string $app app |
|
340 | + * @return bool |
|
341 | + * |
|
342 | + * This function checks whether or not an app is enabled. |
|
343 | + */ |
|
344 | + public static function isEnabled($app) { |
|
345 | + return \OC::$server->getAppManager()->isEnabledForUser($app); |
|
346 | + } |
|
347 | + |
|
348 | + /** |
|
349 | + * enables an app |
|
350 | + * |
|
351 | + * @param string $appId |
|
352 | + * @param array $groups (optional) when set, only these groups will have access to the app |
|
353 | + * @throws \Exception |
|
354 | + * @return void |
|
355 | + * |
|
356 | + * This function set an app as enabled in appconfig. |
|
357 | + */ |
|
358 | + public function enable($appId, |
|
359 | + $groups = null) { |
|
360 | + self::$enabledAppsCache = []; // flush |
|
361 | + $l = \OC::$server->getL10N('core'); |
|
362 | + $config = \OC::$server->getConfig(); |
|
363 | + |
|
364 | + // Check if app is already downloaded |
|
365 | + $installer = new Installer( |
|
366 | + \OC::$server->getAppFetcher(), |
|
367 | + \OC::$server->getHTTPClientService(), |
|
368 | + \OC::$server->getTempManager(), |
|
369 | + \OC::$server->getLogger() |
|
370 | + ); |
|
371 | + $isDownloaded = $installer->isDownloaded($appId); |
|
372 | + |
|
373 | + if(!$isDownloaded) { |
|
374 | + $installer->downloadApp($appId); |
|
375 | + } |
|
376 | + |
|
377 | + if (!Installer::isInstalled($appId)) { |
|
378 | + $appId = self::installApp( |
|
379 | + $appId, |
|
380 | + $config, |
|
381 | + $l |
|
382 | + ); |
|
383 | + $appPath = self::getAppPath($appId); |
|
384 | + self::registerAutoloading($appId, $appPath); |
|
385 | + $installer->installApp($appId); |
|
386 | + } else { |
|
387 | + // check for required dependencies |
|
388 | + $info = self::getAppInfo($appId); |
|
389 | + self::checkAppDependencies($config, $l, $info); |
|
390 | + $appPath = self::getAppPath($appId); |
|
391 | + self::registerAutoloading($appId, $appPath); |
|
392 | + $installer->installApp($appId); |
|
393 | + } |
|
394 | + |
|
395 | + $appManager = \OC::$server->getAppManager(); |
|
396 | + if (!is_null($groups)) { |
|
397 | + $groupManager = \OC::$server->getGroupManager(); |
|
398 | + $groupsList = []; |
|
399 | + foreach ($groups as $group) { |
|
400 | + $groupItem = $groupManager->get($group); |
|
401 | + if ($groupItem instanceof \OCP\IGroup) { |
|
402 | + $groupsList[] = $groupManager->get($group); |
|
403 | + } |
|
404 | + } |
|
405 | + $appManager->enableAppForGroups($appId, $groupsList); |
|
406 | + } else { |
|
407 | + $appManager->enableApp($appId); |
|
408 | + } |
|
409 | + |
|
410 | + $info = self::getAppInfo($appId); |
|
411 | + if(isset($info['settings']) && is_array($info['settings'])) { |
|
412 | + $appPath = self::getAppPath($appId); |
|
413 | + self::registerAutoloading($appId, $appPath); |
|
414 | + \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
415 | + } |
|
416 | + } |
|
417 | + |
|
418 | + /** |
|
419 | + * @param string $app |
|
420 | + * @return bool |
|
421 | + */ |
|
422 | + public static function removeApp($app) { |
|
423 | + if (self::isShipped($app)) { |
|
424 | + return false; |
|
425 | + } |
|
426 | + |
|
427 | + $installer = new Installer( |
|
428 | + \OC::$server->getAppFetcher(), |
|
429 | + \OC::$server->getHTTPClientService(), |
|
430 | + \OC::$server->getTempManager(), |
|
431 | + \OC::$server->getLogger() |
|
432 | + ); |
|
433 | + return $installer->removeApp($app); |
|
434 | + } |
|
435 | + |
|
436 | + /** |
|
437 | + * This function set an app as disabled in appconfig. |
|
438 | + * |
|
439 | + * @param string $app app |
|
440 | + * @throws Exception |
|
441 | + */ |
|
442 | + public static function disable($app) { |
|
443 | + // flush |
|
444 | + self::$enabledAppsCache = array(); |
|
445 | + |
|
446 | + // run uninstall steps |
|
447 | + $appData = OC_App::getAppInfo($app); |
|
448 | + if (!is_null($appData)) { |
|
449 | + OC_App::executeRepairSteps($app, $appData['repair-steps']['uninstall']); |
|
450 | + } |
|
451 | + |
|
452 | + // emit disable hook - needed anymore ? |
|
453 | + \OC_Hook::emit('OC_App', 'pre_disable', array('app' => $app)); |
|
454 | + |
|
455 | + // finally disable it |
|
456 | + $appManager = \OC::$server->getAppManager(); |
|
457 | + $appManager->disableApp($app); |
|
458 | + } |
|
459 | + |
|
460 | + // This is private as well. It simply works, so don't ask for more details |
|
461 | + private static function proceedNavigation($list) { |
|
462 | + usort($list, function($a, $b) { |
|
463 | + if (isset($a['order']) && isset($b['order'])) { |
|
464 | + return ($a['order'] < $b['order']) ? -1 : 1; |
|
465 | + } else if (isset($a['order']) || isset($b['order'])) { |
|
466 | + return isset($a['order']) ? -1 : 1; |
|
467 | + } else { |
|
468 | + return ($a['name'] < $b['name']) ? -1 : 1; |
|
469 | + } |
|
470 | + }); |
|
471 | + |
|
472 | + $activeAppIndex = -1; |
|
473 | + $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); |
|
474 | + foreach ($list as $index => &$navEntry) { |
|
475 | + $navEntry['showInHeader'] = true; |
|
476 | + if ($navEntry['id'] == $activeApp) { |
|
477 | + $navEntry['active'] = true; |
|
478 | + $activeAppIndex = $index; |
|
479 | + } else { |
|
480 | + $navEntry['active'] = false; |
|
481 | + } |
|
482 | + } |
|
483 | + unset($navEntry); |
|
484 | + |
|
485 | + if (count($list) <= 8) { |
|
486 | + return $list; |
|
487 | + } |
|
488 | + |
|
489 | + $headerIconCount = 7; |
|
490 | + if($activeAppIndex > ($headerIconCount-1)) { |
|
491 | + $active = $list[$activeAppIndex]; |
|
492 | + $lastInHeader = $list[$headerIconCount-1]; |
|
493 | + $list[$headerIconCount-1] = $active; |
|
494 | + $list[$activeAppIndex] = $lastInHeader; |
|
495 | + } |
|
496 | + |
|
497 | + foreach ($list as $index => &$navEntry) { |
|
498 | + if($index >= $headerIconCount) { |
|
499 | + $navEntry['showInHeader'] = false; |
|
500 | + } |
|
501 | + } |
|
502 | + |
|
503 | + return $list; |
|
504 | + } |
|
505 | + |
|
506 | + public static function proceedAppNavigation($entries) { |
|
507 | + $activeAppIndex = -1; |
|
508 | + $list = self::proceedNavigation($entries); |
|
509 | + |
|
510 | + $activeApp = OC::$server->getNavigationManager()->getActiveEntry(); |
|
511 | + foreach ($list as $index => &$navEntry) { |
|
512 | + if ($navEntry['id'] == $activeApp) { |
|
513 | + $navEntry['active'] = true; |
|
514 | + $activeAppIndex = $index; |
|
515 | + } else { |
|
516 | + $navEntry['active'] = false; |
|
517 | + } |
|
518 | + } |
|
519 | + |
|
520 | + |
|
521 | + if (count($list) <= 8) { |
|
522 | + return $list; |
|
523 | + } |
|
524 | + |
|
525 | + $headerIconCount = 7; |
|
526 | + // move active item to last position |
|
527 | + if($activeAppIndex > ($headerIconCount-1)) { |
|
528 | + $active = $list[$activeAppIndex]; |
|
529 | + $lastInHeader = $list[$headerIconCount-1]; |
|
530 | + $list[$headerIconCount-1] = $active; |
|
531 | + $list[$activeAppIndex] = $lastInHeader; |
|
532 | + } |
|
533 | + $list = array_slice($list, 0, $headerIconCount); |
|
534 | + |
|
535 | + return $list; |
|
536 | + } |
|
537 | + |
|
538 | + /** |
|
539 | + * Get the path where to install apps |
|
540 | + * |
|
541 | + * @return string|false |
|
542 | + */ |
|
543 | + public static function getInstallPath() { |
|
544 | + if (\OC::$server->getSystemConfig()->getValue('appstoreenabled', true) == false) { |
|
545 | + return false; |
|
546 | + } |
|
547 | + |
|
548 | + foreach (OC::$APPSROOTS as $dir) { |
|
549 | + if (isset($dir['writable']) && $dir['writable'] === true) { |
|
550 | + return $dir['path']; |
|
551 | + } |
|
552 | + } |
|
553 | + |
|
554 | + \OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR); |
|
555 | + return null; |
|
556 | + } |
|
557 | + |
|
558 | + |
|
559 | + /** |
|
560 | + * search for an app in all app-directories |
|
561 | + * |
|
562 | + * @param string $appId |
|
563 | + * @return false|string |
|
564 | + */ |
|
565 | + public static function findAppInDirectories($appId) { |
|
566 | + $sanitizedAppId = self::cleanAppId($appId); |
|
567 | + if($sanitizedAppId !== $appId) { |
|
568 | + return false; |
|
569 | + } |
|
570 | + static $app_dir = array(); |
|
571 | + |
|
572 | + if (isset($app_dir[$appId])) { |
|
573 | + return $app_dir[$appId]; |
|
574 | + } |
|
575 | + |
|
576 | + $possibleApps = array(); |
|
577 | + foreach (OC::$APPSROOTS as $dir) { |
|
578 | + if (file_exists($dir['path'] . '/' . $appId)) { |
|
579 | + $possibleApps[] = $dir; |
|
580 | + } |
|
581 | + } |
|
582 | + |
|
583 | + if (empty($possibleApps)) { |
|
584 | + return false; |
|
585 | + } elseif (count($possibleApps) === 1) { |
|
586 | + $dir = array_shift($possibleApps); |
|
587 | + $app_dir[$appId] = $dir; |
|
588 | + return $dir; |
|
589 | + } else { |
|
590 | + $versionToLoad = array(); |
|
591 | + foreach ($possibleApps as $possibleApp) { |
|
592 | + $version = self::getAppVersionByPath($possibleApp['path']); |
|
593 | + if (empty($versionToLoad) || version_compare($version, $versionToLoad['version'], '>')) { |
|
594 | + $versionToLoad = array( |
|
595 | + 'dir' => $possibleApp, |
|
596 | + 'version' => $version, |
|
597 | + ); |
|
598 | + } |
|
599 | + } |
|
600 | + $app_dir[$appId] = $versionToLoad['dir']; |
|
601 | + return $versionToLoad['dir']; |
|
602 | + //TODO - write test |
|
603 | + } |
|
604 | + } |
|
605 | + |
|
606 | + /** |
|
607 | + * Get the directory for the given app. |
|
608 | + * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
609 | + * |
|
610 | + * @param string $appId |
|
611 | + * @return string|false |
|
612 | + */ |
|
613 | + public static function getAppPath($appId) { |
|
614 | + if ($appId === null || trim($appId) === '') { |
|
615 | + return false; |
|
616 | + } |
|
617 | + |
|
618 | + if (($dir = self::findAppInDirectories($appId)) != false) { |
|
619 | + return $dir['path'] . '/' . $appId; |
|
620 | + } |
|
621 | + return false; |
|
622 | + } |
|
623 | + |
|
624 | + /** |
|
625 | + * Get the path for the given app on the access |
|
626 | + * If the app is defined in multiple directories, the first one is taken. (false if not found) |
|
627 | + * |
|
628 | + * @param string $appId |
|
629 | + * @return string|false |
|
630 | + */ |
|
631 | + public static function getAppWebPath($appId) { |
|
632 | + if (($dir = self::findAppInDirectories($appId)) != false) { |
|
633 | + return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
634 | + } |
|
635 | + return false; |
|
636 | + } |
|
637 | + |
|
638 | + /** |
|
639 | + * get the last version of the app from appinfo/info.xml |
|
640 | + * |
|
641 | + * @param string $appId |
|
642 | + * @param bool $useCache |
|
643 | + * @return string |
|
644 | + */ |
|
645 | + public static function getAppVersion($appId, $useCache = true) { |
|
646 | + if($useCache && isset(self::$appVersion[$appId])) { |
|
647 | + return self::$appVersion[$appId]; |
|
648 | + } |
|
649 | + |
|
650 | + $file = self::getAppPath($appId); |
|
651 | + self::$appVersion[$appId] = ($file !== false) ? self::getAppVersionByPath($file) : '0'; |
|
652 | + return self::$appVersion[$appId]; |
|
653 | + } |
|
654 | + |
|
655 | + /** |
|
656 | + * get app's version based on it's path |
|
657 | + * |
|
658 | + * @param string $path |
|
659 | + * @return string |
|
660 | + */ |
|
661 | + public static function getAppVersionByPath($path) { |
|
662 | + $infoFile = $path . '/appinfo/info.xml'; |
|
663 | + $appData = self::getAppInfo($infoFile, true); |
|
664 | + return isset($appData['version']) ? $appData['version'] : ''; |
|
665 | + } |
|
666 | + |
|
667 | + |
|
668 | + /** |
|
669 | + * Read all app metadata from the info.xml file |
|
670 | + * |
|
671 | + * @param string $appId id of the app or the path of the info.xml file |
|
672 | + * @param bool $path |
|
673 | + * @param string $lang |
|
674 | + * @return array|null |
|
675 | + * @note all data is read from info.xml, not just pre-defined fields |
|
676 | + */ |
|
677 | + public static function getAppInfo($appId, $path = false, $lang = null) { |
|
678 | + if ($path) { |
|
679 | + $file = $appId; |
|
680 | + } else { |
|
681 | + if ($lang === null && isset(self::$appInfo[$appId])) { |
|
682 | + return self::$appInfo[$appId]; |
|
683 | + } |
|
684 | + $appPath = self::getAppPath($appId); |
|
685 | + if($appPath === false) { |
|
686 | + return null; |
|
687 | + } |
|
688 | + $file = $appPath . '/appinfo/info.xml'; |
|
689 | + } |
|
690 | + |
|
691 | + $parser = new InfoParser(\OC::$server->getMemCacheFactory()->create('core.appinfo')); |
|
692 | + $data = $parser->parse($file); |
|
693 | + |
|
694 | + if (is_array($data)) { |
|
695 | + $data = OC_App::parseAppInfo($data, $lang); |
|
696 | + } |
|
697 | + if(isset($data['ocsid'])) { |
|
698 | + $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
|
699 | + if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
700 | + $data['ocsid'] = $storedId; |
|
701 | + } |
|
702 | + } |
|
703 | + |
|
704 | + if ($lang === null) { |
|
705 | + self::$appInfo[$appId] = $data; |
|
706 | + } |
|
707 | + |
|
708 | + return $data; |
|
709 | + } |
|
710 | + |
|
711 | + /** |
|
712 | + * Returns the navigation |
|
713 | + * |
|
714 | + * @return array |
|
715 | + * |
|
716 | + * This function returns an array containing all entries added. The |
|
717 | + * entries are sorted by the key 'order' ascending. Additional to the keys |
|
718 | + * given for each app the following keys exist: |
|
719 | + * - active: boolean, signals if the user is on this navigation entry |
|
720 | + */ |
|
721 | + public static function getNavigation() { |
|
722 | + $entries = OC::$server->getNavigationManager()->getAll(); |
|
723 | + return self::proceedNavigation($entries); |
|
724 | + } |
|
725 | + |
|
726 | + /** |
|
727 | + * Returns the navigation inside the header bar |
|
728 | + * |
|
729 | + * @return array |
|
730 | + * |
|
731 | + * This function returns an array containing all entries added. The |
|
732 | + * entries are sorted by the key 'order' ascending. Additional to the keys |
|
733 | + * given for each app the following keys exist: |
|
734 | + * - active: boolean, signals if the user is on this navigation entry |
|
735 | + */ |
|
736 | + public static function getHeaderNavigation() { |
|
737 | + $entries = OC::$server->getNavigationManager()->getAll(); |
|
738 | + return self::proceedAppNavigation($entries); |
|
739 | + } |
|
740 | + |
|
741 | + /** |
|
742 | + * Returns the Settings Navigation |
|
743 | + * |
|
744 | + * @return string[] |
|
745 | + * |
|
746 | + * This function returns an array containing all settings pages added. The |
|
747 | + * entries are sorted by the key 'order' ascending. |
|
748 | + */ |
|
749 | + public static function getSettingsNavigation() { |
|
750 | + $entries = OC::$server->getNavigationManager()->getAll('settings'); |
|
751 | + return self::proceedNavigation($entries); |
|
752 | + } |
|
753 | + |
|
754 | + /** |
|
755 | + * get the id of loaded app |
|
756 | + * |
|
757 | + * @return string |
|
758 | + */ |
|
759 | + public static function getCurrentApp() { |
|
760 | + $request = \OC::$server->getRequest(); |
|
761 | + $script = substr($request->getScriptName(), strlen(OC::$WEBROOT) + 1); |
|
762 | + $topFolder = substr($script, 0, strpos($script, '/')); |
|
763 | + if (empty($topFolder)) { |
|
764 | + $path_info = $request->getPathInfo(); |
|
765 | + if ($path_info) { |
|
766 | + $topFolder = substr($path_info, 1, strpos($path_info, '/', 1) - 1); |
|
767 | + } |
|
768 | + } |
|
769 | + if ($topFolder == 'apps') { |
|
770 | + $length = strlen($topFolder); |
|
771 | + return substr($script, $length + 1, strpos($script, '/', $length + 1) - $length - 1); |
|
772 | + } else { |
|
773 | + return $topFolder; |
|
774 | + } |
|
775 | + } |
|
776 | + |
|
777 | + /** |
|
778 | + * @param string $type |
|
779 | + * @return array |
|
780 | + */ |
|
781 | + public static function getForms($type) { |
|
782 | + $forms = array(); |
|
783 | + switch ($type) { |
|
784 | + case 'admin': |
|
785 | + $source = self::$adminForms; |
|
786 | + break; |
|
787 | + case 'personal': |
|
788 | + $source = self::$personalForms; |
|
789 | + break; |
|
790 | + default: |
|
791 | + return array(); |
|
792 | + } |
|
793 | + foreach ($source as $form) { |
|
794 | + $forms[] = include $form; |
|
795 | + } |
|
796 | + return $forms; |
|
797 | + } |
|
798 | + |
|
799 | + /** |
|
800 | + * register an admin form to be shown |
|
801 | + * |
|
802 | + * @param string $app |
|
803 | + * @param string $page |
|
804 | + */ |
|
805 | + public static function registerAdmin($app, $page) { |
|
806 | + self::$adminForms[] = $app . '/' . $page . '.php'; |
|
807 | + } |
|
808 | + |
|
809 | + /** |
|
810 | + * register a personal form to be shown |
|
811 | + * @param string $app |
|
812 | + * @param string $page |
|
813 | + */ |
|
814 | + public static function registerPersonal($app, $page) { |
|
815 | + self::$personalForms[] = $app . '/' . $page . '.php'; |
|
816 | + } |
|
817 | + |
|
818 | + /** |
|
819 | + * @param array $entry |
|
820 | + */ |
|
821 | + public static function registerLogIn(array $entry) { |
|
822 | + self::$altLogin[] = $entry; |
|
823 | + } |
|
824 | + |
|
825 | + /** |
|
826 | + * @return array |
|
827 | + */ |
|
828 | + public static function getAlternativeLogIns() { |
|
829 | + return self::$altLogin; |
|
830 | + } |
|
831 | + |
|
832 | + /** |
|
833 | + * get a list of all apps in the apps folder |
|
834 | + * |
|
835 | + * @return array an array of app names (string IDs) |
|
836 | + * @todo: change the name of this method to getInstalledApps, which is more accurate |
|
837 | + */ |
|
838 | + public static function getAllApps() { |
|
839 | + |
|
840 | + $apps = array(); |
|
841 | + |
|
842 | + foreach (OC::$APPSROOTS as $apps_dir) { |
|
843 | + if (!is_readable($apps_dir['path'])) { |
|
844 | + \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
845 | + continue; |
|
846 | + } |
|
847 | + $dh = opendir($apps_dir['path']); |
|
848 | + |
|
849 | + if (is_resource($dh)) { |
|
850 | + while (($file = readdir($dh)) !== false) { |
|
851 | + |
|
852 | + if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
853 | + |
|
854 | + $apps[] = $file; |
|
855 | + } |
|
856 | + } |
|
857 | + } |
|
858 | + } |
|
859 | + |
|
860 | + return $apps; |
|
861 | + } |
|
862 | + |
|
863 | + /** |
|
864 | + * List all apps, this is used in apps.php |
|
865 | + * |
|
866 | + * @return array |
|
867 | + */ |
|
868 | + public function listAllApps() { |
|
869 | + $installedApps = OC_App::getAllApps(); |
|
870 | + |
|
871 | + //we don't want to show configuration for these |
|
872 | + $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
|
873 | + $appList = array(); |
|
874 | + $langCode = \OC::$server->getL10N('core')->getLanguageCode(); |
|
875 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
876 | + |
|
877 | + foreach ($installedApps as $app) { |
|
878 | + if (array_search($app, $blacklist) === false) { |
|
879 | + |
|
880 | + $info = OC_App::getAppInfo($app, false, $langCode); |
|
881 | + if (!is_array($info)) { |
|
882 | + \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
883 | + continue; |
|
884 | + } |
|
885 | + |
|
886 | + if (!isset($info['name'])) { |
|
887 | + \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
888 | + continue; |
|
889 | + } |
|
890 | + |
|
891 | + $enabled = \OC::$server->getAppConfig()->getValue($app, 'enabled', 'no'); |
|
892 | + $info['groups'] = null; |
|
893 | + if ($enabled === 'yes') { |
|
894 | + $active = true; |
|
895 | + } else if ($enabled === 'no') { |
|
896 | + $active = false; |
|
897 | + } else { |
|
898 | + $active = true; |
|
899 | + $info['groups'] = $enabled; |
|
900 | + } |
|
901 | + |
|
902 | + $info['active'] = $active; |
|
903 | + |
|
904 | + if (self::isShipped($app)) { |
|
905 | + $info['internal'] = true; |
|
906 | + $info['level'] = self::officialApp; |
|
907 | + $info['removable'] = false; |
|
908 | + } else { |
|
909 | + $info['internal'] = false; |
|
910 | + $info['removable'] = true; |
|
911 | + } |
|
912 | + |
|
913 | + $appPath = self::getAppPath($app); |
|
914 | + if($appPath !== false) { |
|
915 | + $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
916 | + if (file_exists($appIcon)) { |
|
917 | + $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app . '.svg'); |
|
918 | + $info['previewAsIcon'] = true; |
|
919 | + } else { |
|
920 | + $appIcon = $appPath . '/img/app.svg'; |
|
921 | + if (file_exists($appIcon)) { |
|
922 | + $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, 'app.svg'); |
|
923 | + $info['previewAsIcon'] = true; |
|
924 | + } |
|
925 | + } |
|
926 | + } |
|
927 | + // fix documentation |
|
928 | + if (isset($info['documentation']) && is_array($info['documentation'])) { |
|
929 | + foreach ($info['documentation'] as $key => $url) { |
|
930 | + // If it is not an absolute URL we assume it is a key |
|
931 | + // i.e. admin-ldap will get converted to go.php?to=admin-ldap |
|
932 | + if (stripos($url, 'https://') !== 0 && stripos($url, 'http://') !== 0) { |
|
933 | + $url = $urlGenerator->linkToDocs($url); |
|
934 | + } |
|
935 | + |
|
936 | + $info['documentation'][$key] = $url; |
|
937 | + } |
|
938 | + } |
|
939 | + |
|
940 | + $info['version'] = OC_App::getAppVersion($app); |
|
941 | + $appList[] = $info; |
|
942 | + } |
|
943 | + } |
|
944 | + |
|
945 | + return $appList; |
|
946 | + } |
|
947 | + |
|
948 | + /** |
|
949 | + * Returns the internal app ID or false |
|
950 | + * @param string $ocsID |
|
951 | + * @return string|false |
|
952 | + */ |
|
953 | + public static function getInternalAppIdByOcs($ocsID) { |
|
954 | + if(is_numeric($ocsID)) { |
|
955 | + $idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid'); |
|
956 | + if(array_search($ocsID, $idArray)) { |
|
957 | + return array_search($ocsID, $idArray); |
|
958 | + } |
|
959 | + } |
|
960 | + return false; |
|
961 | + } |
|
962 | + |
|
963 | + public static function shouldUpgrade($app) { |
|
964 | + $versions = self::getAppVersions(); |
|
965 | + $currentVersion = OC_App::getAppVersion($app); |
|
966 | + if ($currentVersion && isset($versions[$app])) { |
|
967 | + $installedVersion = $versions[$app]; |
|
968 | + if (!version_compare($currentVersion, $installedVersion, '=')) { |
|
969 | + return true; |
|
970 | + } |
|
971 | + } |
|
972 | + return false; |
|
973 | + } |
|
974 | + |
|
975 | + /** |
|
976 | + * Adjust the number of version parts of $version1 to match |
|
977 | + * the number of version parts of $version2. |
|
978 | + * |
|
979 | + * @param string $version1 version to adjust |
|
980 | + * @param string $version2 version to take the number of parts from |
|
981 | + * @return string shortened $version1 |
|
982 | + */ |
|
983 | + private static function adjustVersionParts($version1, $version2) { |
|
984 | + $version1 = explode('.', $version1); |
|
985 | + $version2 = explode('.', $version2); |
|
986 | + // reduce $version1 to match the number of parts in $version2 |
|
987 | + while (count($version1) > count($version2)) { |
|
988 | + array_pop($version1); |
|
989 | + } |
|
990 | + // if $version1 does not have enough parts, add some |
|
991 | + while (count($version1) < count($version2)) { |
|
992 | + $version1[] = '0'; |
|
993 | + } |
|
994 | + return implode('.', $version1); |
|
995 | + } |
|
996 | + |
|
997 | + /** |
|
998 | + * Check whether the current ownCloud version matches the given |
|
999 | + * application's version requirements. |
|
1000 | + * |
|
1001 | + * The comparison is made based on the number of parts that the |
|
1002 | + * app info version has. For example for ownCloud 6.0.3 if the |
|
1003 | + * app info version is expecting version 6.0, the comparison is |
|
1004 | + * made on the first two parts of the ownCloud version. |
|
1005 | + * This means that it's possible to specify "requiremin" => 6 |
|
1006 | + * and "requiremax" => 6 and it will still match ownCloud 6.0.3. |
|
1007 | + * |
|
1008 | + * @param string $ocVersion ownCloud version to check against |
|
1009 | + * @param array $appInfo app info (from xml) |
|
1010 | + * |
|
1011 | + * @return boolean true if compatible, otherwise false |
|
1012 | + */ |
|
1013 | + public static function isAppCompatible($ocVersion, $appInfo) { |
|
1014 | + $requireMin = ''; |
|
1015 | + $requireMax = ''; |
|
1016 | + if (isset($appInfo['dependencies']['nextcloud']['@attributes']['min-version'])) { |
|
1017 | + $requireMin = $appInfo['dependencies']['nextcloud']['@attributes']['min-version']; |
|
1018 | + } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['min-version'])) { |
|
1019 | + $requireMin = $appInfo['dependencies']['owncloud']['@attributes']['min-version']; |
|
1020 | + } else if (isset($appInfo['requiremin'])) { |
|
1021 | + $requireMin = $appInfo['requiremin']; |
|
1022 | + } else if (isset($appInfo['require'])) { |
|
1023 | + $requireMin = $appInfo['require']; |
|
1024 | + } |
|
1025 | + |
|
1026 | + if (isset($appInfo['dependencies']['nextcloud']['@attributes']['max-version'])) { |
|
1027 | + $requireMax = $appInfo['dependencies']['nextcloud']['@attributes']['max-version']; |
|
1028 | + } elseif (isset($appInfo['dependencies']['owncloud']['@attributes']['max-version'])) { |
|
1029 | + $requireMax = $appInfo['dependencies']['owncloud']['@attributes']['max-version']; |
|
1030 | + } else if (isset($appInfo['requiremax'])) { |
|
1031 | + $requireMax = $appInfo['requiremax']; |
|
1032 | + } |
|
1033 | + |
|
1034 | + if (is_array($ocVersion)) { |
|
1035 | + $ocVersion = implode('.', $ocVersion); |
|
1036 | + } |
|
1037 | + |
|
1038 | + if (!empty($requireMin) |
|
1039 | + && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<') |
|
1040 | + ) { |
|
1041 | + |
|
1042 | + return false; |
|
1043 | + } |
|
1044 | + |
|
1045 | + if (!empty($requireMax) |
|
1046 | + && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>') |
|
1047 | + ) { |
|
1048 | + return false; |
|
1049 | + } |
|
1050 | + |
|
1051 | + return true; |
|
1052 | + } |
|
1053 | + |
|
1054 | + /** |
|
1055 | + * get the installed version of all apps |
|
1056 | + */ |
|
1057 | + public static function getAppVersions() { |
|
1058 | + static $versions; |
|
1059 | + |
|
1060 | + if(!$versions) { |
|
1061 | + $appConfig = \OC::$server->getAppConfig(); |
|
1062 | + $versions = $appConfig->getValues(false, 'installed_version'); |
|
1063 | + } |
|
1064 | + return $versions; |
|
1065 | + } |
|
1066 | + |
|
1067 | + /** |
|
1068 | + * @param string $app |
|
1069 | + * @param \OCP\IConfig $config |
|
1070 | + * @param \OCP\IL10N $l |
|
1071 | + * @return bool |
|
1072 | + * |
|
1073 | + * @throws Exception if app is not compatible with this version of ownCloud |
|
1074 | + * @throws Exception if no app-name was specified |
|
1075 | + */ |
|
1076 | + public function installApp($app, |
|
1077 | + \OCP\IConfig $config, |
|
1078 | + \OCP\IL10N $l) { |
|
1079 | + if ($app !== false) { |
|
1080 | + // check if the app is compatible with this version of ownCloud |
|
1081 | + $info = self::getAppInfo($app); |
|
1082 | + if(!is_array($info)) { |
|
1083 | + throw new \Exception( |
|
1084 | + $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
|
1085 | + [$info['name']] |
|
1086 | + ) |
|
1087 | + ); |
|
1088 | + } |
|
1089 | + |
|
1090 | + $version = \OCP\Util::getVersion(); |
|
1091 | + if (!self::isAppCompatible($version, $info)) { |
|
1092 | + throw new \Exception( |
|
1093 | + $l->t('App "%s" cannot be installed because it is not compatible with this version of the server.', |
|
1094 | + array($info['name']) |
|
1095 | + ) |
|
1096 | + ); |
|
1097 | + } |
|
1098 | + |
|
1099 | + // check for required dependencies |
|
1100 | + self::checkAppDependencies($config, $l, $info); |
|
1101 | + |
|
1102 | + $config->setAppValue($app, 'enabled', 'yes'); |
|
1103 | + if (isset($appData['id'])) { |
|
1104 | + $config->setAppValue($app, 'ocsid', $appData['id']); |
|
1105 | + } |
|
1106 | + |
|
1107 | + if(isset($info['settings']) && is_array($info['settings'])) { |
|
1108 | + $appPath = self::getAppPath($app); |
|
1109 | + self::registerAutoloading($app, $appPath); |
|
1110 | + \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
1111 | + } |
|
1112 | + |
|
1113 | + \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
|
1114 | + } else { |
|
1115 | + if(empty($appName) ) { |
|
1116 | + throw new \Exception($l->t("No app name specified")); |
|
1117 | + } else { |
|
1118 | + throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
|
1119 | + } |
|
1120 | + } |
|
1121 | + |
|
1122 | + return $app; |
|
1123 | + } |
|
1124 | + |
|
1125 | + /** |
|
1126 | + * update the database for the app and call the update script |
|
1127 | + * |
|
1128 | + * @param string $appId |
|
1129 | + * @return bool |
|
1130 | + */ |
|
1131 | + public static function updateApp($appId) { |
|
1132 | + $appPath = self::getAppPath($appId); |
|
1133 | + if($appPath === false) { |
|
1134 | + return false; |
|
1135 | + } |
|
1136 | + $appData = self::getAppInfo($appId); |
|
1137 | + self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
|
1138 | + if (file_exists($appPath . '/appinfo/database.xml')) { |
|
1139 | + OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
1140 | + } |
|
1141 | + self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
|
1142 | + self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
|
1143 | + unset(self::$appVersion[$appId]); |
|
1144 | + // run upgrade code |
|
1145 | + if (file_exists($appPath . '/appinfo/update.php')) { |
|
1146 | + self::loadApp($appId); |
|
1147 | + include $appPath . '/appinfo/update.php'; |
|
1148 | + } |
|
1149 | + self::setupBackgroundJobs($appData['background-jobs']); |
|
1150 | + if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
1151 | + $appPath = self::getAppPath($appId); |
|
1152 | + self::registerAutoloading($appId, $appPath); |
|
1153 | + \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
|
1154 | + } |
|
1155 | + |
|
1156 | + //set remote/public handlers |
|
1157 | + if (array_key_exists('ocsid', $appData)) { |
|
1158 | + \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
|
1159 | + } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
1160 | + \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
|
1161 | + } |
|
1162 | + foreach ($appData['remote'] as $name => $path) { |
|
1163 | + \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
1164 | + } |
|
1165 | + foreach ($appData['public'] as $name => $path) { |
|
1166 | + \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
1167 | + } |
|
1168 | + |
|
1169 | + self::setAppTypes($appId); |
|
1170 | + |
|
1171 | + $version = \OC_App::getAppVersion($appId); |
|
1172 | + \OC::$server->getAppConfig()->setValue($appId, 'installed_version', $version); |
|
1173 | + |
|
1174 | + \OC::$server->getEventDispatcher()->dispatch(ManagerEvent::EVENT_APP_UPDATE, new ManagerEvent( |
|
1175 | + ManagerEvent::EVENT_APP_UPDATE, $appId |
|
1176 | + )); |
|
1177 | + |
|
1178 | + return true; |
|
1179 | + } |
|
1180 | + |
|
1181 | + /** |
|
1182 | + * @param string $appId |
|
1183 | + * @param string[] $steps |
|
1184 | + * @throws \OC\NeedsUpdateException |
|
1185 | + */ |
|
1186 | + public static function executeRepairSteps($appId, array $steps) { |
|
1187 | + if (empty($steps)) { |
|
1188 | + return; |
|
1189 | + } |
|
1190 | + // load the app |
|
1191 | + self::loadApp($appId); |
|
1192 | + |
|
1193 | + $dispatcher = OC::$server->getEventDispatcher(); |
|
1194 | + |
|
1195 | + // load the steps |
|
1196 | + $r = new Repair([], $dispatcher); |
|
1197 | + foreach ($steps as $step) { |
|
1198 | + try { |
|
1199 | + $r->addStep($step); |
|
1200 | + } catch (Exception $ex) { |
|
1201 | + $r->emit('\OC\Repair', 'error', [$ex->getMessage()]); |
|
1202 | + \OC::$server->getLogger()->logException($ex); |
|
1203 | + } |
|
1204 | + } |
|
1205 | + // run the steps |
|
1206 | + $r->run(); |
|
1207 | + } |
|
1208 | + |
|
1209 | + public static function setupBackgroundJobs(array $jobs) { |
|
1210 | + $queue = \OC::$server->getJobList(); |
|
1211 | + foreach ($jobs as $job) { |
|
1212 | + $queue->add($job); |
|
1213 | + } |
|
1214 | + } |
|
1215 | + |
|
1216 | + /** |
|
1217 | + * @param string $appId |
|
1218 | + * @param string[] $steps |
|
1219 | + */ |
|
1220 | + private static function setupLiveMigrations($appId, array $steps) { |
|
1221 | + $queue = \OC::$server->getJobList(); |
|
1222 | + foreach ($steps as $step) { |
|
1223 | + $queue->add('OC\Migration\BackgroundRepair', [ |
|
1224 | + 'app' => $appId, |
|
1225 | + 'step' => $step]); |
|
1226 | + } |
|
1227 | + } |
|
1228 | + |
|
1229 | + /** |
|
1230 | + * @param string $appId |
|
1231 | + * @return \OC\Files\View|false |
|
1232 | + */ |
|
1233 | + public static function getStorage($appId) { |
|
1234 | + if (OC_App::isEnabled($appId)) { //sanity check |
|
1235 | + if (\OC::$server->getUserSession()->isLoggedIn()) { |
|
1236 | + $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
1237 | + if (!$view->file_exists($appId)) { |
|
1238 | + $view->mkdir($appId); |
|
1239 | + } |
|
1240 | + return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
1241 | + } else { |
|
1242 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
1243 | + return false; |
|
1244 | + } |
|
1245 | + } else { |
|
1246 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
1247 | + return false; |
|
1248 | + } |
|
1249 | + } |
|
1250 | + |
|
1251 | + protected static function findBestL10NOption($options, $lang) { |
|
1252 | + $fallback = $similarLangFallback = $englishFallback = false; |
|
1253 | + |
|
1254 | + $lang = strtolower($lang); |
|
1255 | + $similarLang = $lang; |
|
1256 | + if (strpos($similarLang, '_')) { |
|
1257 | + // For "de_DE" we want to find "de" and the other way around |
|
1258 | + $similarLang = substr($lang, 0, strpos($lang, '_')); |
|
1259 | + } |
|
1260 | + |
|
1261 | + foreach ($options as $option) { |
|
1262 | + if (is_array($option)) { |
|
1263 | + if ($fallback === false) { |
|
1264 | + $fallback = $option['@value']; |
|
1265 | + } |
|
1266 | + |
|
1267 | + if (!isset($option['@attributes']['lang'])) { |
|
1268 | + continue; |
|
1269 | + } |
|
1270 | + |
|
1271 | + $attributeLang = strtolower($option['@attributes']['lang']); |
|
1272 | + if ($attributeLang === $lang) { |
|
1273 | + return $option['@value']; |
|
1274 | + } |
|
1275 | + |
|
1276 | + if ($attributeLang === $similarLang) { |
|
1277 | + $similarLangFallback = $option['@value']; |
|
1278 | + } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
1279 | + if ($similarLangFallback === false) { |
|
1280 | + $similarLangFallback = $option['@value']; |
|
1281 | + } |
|
1282 | + } |
|
1283 | + } else { |
|
1284 | + $englishFallback = $option; |
|
1285 | + } |
|
1286 | + } |
|
1287 | + |
|
1288 | + if ($similarLangFallback !== false) { |
|
1289 | + return $similarLangFallback; |
|
1290 | + } else if ($englishFallback !== false) { |
|
1291 | + return $englishFallback; |
|
1292 | + } |
|
1293 | + return (string) $fallback; |
|
1294 | + } |
|
1295 | + |
|
1296 | + /** |
|
1297 | + * parses the app data array and enhanced the 'description' value |
|
1298 | + * |
|
1299 | + * @param array $data the app data |
|
1300 | + * @param string $lang |
|
1301 | + * @return array improved app data |
|
1302 | + */ |
|
1303 | + public static function parseAppInfo(array $data, $lang = null) { |
|
1304 | + |
|
1305 | + if ($lang && isset($data['name']) && is_array($data['name'])) { |
|
1306 | + $data['name'] = self::findBestL10NOption($data['name'], $lang); |
|
1307 | + } |
|
1308 | + if ($lang && isset($data['summary']) && is_array($data['summary'])) { |
|
1309 | + $data['summary'] = self::findBestL10NOption($data['summary'], $lang); |
|
1310 | + } |
|
1311 | + if ($lang && isset($data['description']) && is_array($data['description'])) { |
|
1312 | + $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
|
1313 | + } else if (isset($data['description']) && is_string($data['description'])) { |
|
1314 | + $data['description'] = trim($data['description']); |
|
1315 | + } else { |
|
1316 | + $data['description'] = ''; |
|
1317 | + } |
|
1318 | + |
|
1319 | + return $data; |
|
1320 | + } |
|
1321 | + |
|
1322 | + /** |
|
1323 | + * @param \OCP\IConfig $config |
|
1324 | + * @param \OCP\IL10N $l |
|
1325 | + * @param array $info |
|
1326 | + * @throws \Exception |
|
1327 | + */ |
|
1328 | + protected static function checkAppDependencies($config, $l, $info) { |
|
1329 | + $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); |
|
1330 | + $missing = $dependencyAnalyzer->analyze($info); |
|
1331 | + if (!empty($missing)) { |
|
1332 | + $missingMsg = join(PHP_EOL, $missing); |
|
1333 | + throw new \Exception( |
|
1334 | + $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s', |
|
1335 | + [$info['name'], $missingMsg] |
|
1336 | + ) |
|
1337 | + ); |
|
1338 | + } |
|
1339 | + } |
|
1340 | 1340 | } |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | $apps = self::getEnabledApps(); |
112 | 112 | |
113 | 113 | // Add each apps' folder as allowed class path |
114 | - foreach($apps as $app) { |
|
114 | + foreach ($apps as $app) { |
|
115 | 115 | $path = self::getAppPath($app); |
116 | - if($path !== false) { |
|
116 | + if ($path !== false) { |
|
117 | 117 | self::registerAutoloading($app, $path); |
118 | 118 | } |
119 | 119 | } |
@@ -138,15 +138,15 @@ discard block |
||
138 | 138 | public static function loadApp($app) { |
139 | 139 | self::$loadedApps[] = $app; |
140 | 140 | $appPath = self::getAppPath($app); |
141 | - if($appPath === false) { |
|
141 | + if ($appPath === false) { |
|
142 | 142 | return; |
143 | 143 | } |
144 | 144 | |
145 | 145 | // in case someone calls loadApp() directly |
146 | 146 | self::registerAutoloading($app, $appPath); |
147 | 147 | |
148 | - if (is_file($appPath . '/appinfo/app.php')) { |
|
149 | - \OC::$server->getEventLogger()->start('load_app_' . $app, 'Load app: ' . $app); |
|
148 | + if (is_file($appPath.'/appinfo/app.php')) { |
|
149 | + \OC::$server->getEventLogger()->start('load_app_'.$app, 'Load app: '.$app); |
|
150 | 150 | self::requireAppFile($app); |
151 | 151 | if (self::isType($app, array('authentication'))) { |
152 | 152 | // since authentication apps affect the "is app enabled for group" check, |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | // enabled for groups |
156 | 156 | self::$enabledAppsCache = array(); |
157 | 157 | } |
158 | - \OC::$server->getEventLogger()->end('load_app_' . $app); |
|
158 | + \OC::$server->getEventLogger()->end('load_app_'.$app); |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | $info = self::getAppInfo($app); |
@@ -182,17 +182,17 @@ discard block |
||
182 | 182 | * @param string $path |
183 | 183 | */ |
184 | 184 | public static function registerAutoloading($app, $path) { |
185 | - $key = $app . '-' . $path; |
|
186 | - if(isset(self::$alreadyRegistered[$key])) { |
|
185 | + $key = $app.'-'.$path; |
|
186 | + if (isset(self::$alreadyRegistered[$key])) { |
|
187 | 187 | return; |
188 | 188 | } |
189 | 189 | self::$alreadyRegistered[$key] = true; |
190 | 190 | // Register on PSR-4 composer autoloader |
191 | 191 | $appNamespace = \OC\AppFramework\App::buildAppNamespace($app); |
192 | 192 | \OC::$server->registerNamespace($app, $appNamespace); |
193 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\', $path . '/lib/', true); |
|
193 | + \OC::$composerAutoloader->addPsr4($appNamespace.'\\', $path.'/lib/', true); |
|
194 | 194 | if (defined('PHPUNIT_RUN') || defined('CLI_TEST_RUN')) { |
195 | - \OC::$composerAutoloader->addPsr4($appNamespace . '\\Tests\\', $path . '/tests/', true); |
|
195 | + \OC::$composerAutoloader->addPsr4($appNamespace.'\\Tests\\', $path.'/tests/', true); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | // Register on legacy autoloader |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | private static function requireAppFile($app) { |
208 | 208 | try { |
209 | 209 | // encapsulated here to avoid variable scope conflicts |
210 | - require_once $app . '/appinfo/app.php'; |
|
210 | + require_once $app.'/appinfo/app.php'; |
|
211 | 211 | } catch (Error $ex) { |
212 | 212 | \OC::$server->getLogger()->logException($ex); |
213 | 213 | $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | */ |
262 | 262 | public static function setAppTypes($app) { |
263 | 263 | $appData = self::getAppInfo($app); |
264 | - if(!is_array($appData)) { |
|
264 | + if (!is_array($appData)) { |
|
265 | 265 | return; |
266 | 266 | } |
267 | 267 | |
@@ -325,8 +325,8 @@ discard block |
||
325 | 325 | } else { |
326 | 326 | $apps = $appManager->getEnabledAppsForUser($user); |
327 | 327 | } |
328 | - $apps = array_filter($apps, function ($app) { |
|
329 | - return $app !== 'files';//we add this manually |
|
328 | + $apps = array_filter($apps, function($app) { |
|
329 | + return $app !== 'files'; //we add this manually |
|
330 | 330 | }); |
331 | 331 | sort($apps); |
332 | 332 | array_unshift($apps, 'files'); |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | ); |
371 | 371 | $isDownloaded = $installer->isDownloaded($appId); |
372 | 372 | |
373 | - if(!$isDownloaded) { |
|
373 | + if (!$isDownloaded) { |
|
374 | 374 | $installer->downloadApp($appId); |
375 | 375 | } |
376 | 376 | |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | } |
409 | 409 | |
410 | 410 | $info = self::getAppInfo($appId); |
411 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
411 | + if (isset($info['settings']) && is_array($info['settings'])) { |
|
412 | 412 | $appPath = self::getAppPath($appId); |
413 | 413 | self::registerAutoloading($appId, $appPath); |
414 | 414 | \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
@@ -487,15 +487,15 @@ discard block |
||
487 | 487 | } |
488 | 488 | |
489 | 489 | $headerIconCount = 7; |
490 | - if($activeAppIndex > ($headerIconCount-1)) { |
|
490 | + if ($activeAppIndex > ($headerIconCount - 1)) { |
|
491 | 491 | $active = $list[$activeAppIndex]; |
492 | - $lastInHeader = $list[$headerIconCount-1]; |
|
493 | - $list[$headerIconCount-1] = $active; |
|
492 | + $lastInHeader = $list[$headerIconCount - 1]; |
|
493 | + $list[$headerIconCount - 1] = $active; |
|
494 | 494 | $list[$activeAppIndex] = $lastInHeader; |
495 | 495 | } |
496 | 496 | |
497 | 497 | foreach ($list as $index => &$navEntry) { |
498 | - if($index >= $headerIconCount) { |
|
498 | + if ($index >= $headerIconCount) { |
|
499 | 499 | $navEntry['showInHeader'] = false; |
500 | 500 | } |
501 | 501 | } |
@@ -524,10 +524,10 @@ discard block |
||
524 | 524 | |
525 | 525 | $headerIconCount = 7; |
526 | 526 | // move active item to last position |
527 | - if($activeAppIndex > ($headerIconCount-1)) { |
|
527 | + if ($activeAppIndex > ($headerIconCount - 1)) { |
|
528 | 528 | $active = $list[$activeAppIndex]; |
529 | - $lastInHeader = $list[$headerIconCount-1]; |
|
530 | - $list[$headerIconCount-1] = $active; |
|
529 | + $lastInHeader = $list[$headerIconCount - 1]; |
|
530 | + $list[$headerIconCount - 1] = $active; |
|
531 | 531 | $list[$activeAppIndex] = $lastInHeader; |
532 | 532 | } |
533 | 533 | $list = array_slice($list, 0, $headerIconCount); |
@@ -564,7 +564,7 @@ discard block |
||
564 | 564 | */ |
565 | 565 | public static function findAppInDirectories($appId) { |
566 | 566 | $sanitizedAppId = self::cleanAppId($appId); |
567 | - if($sanitizedAppId !== $appId) { |
|
567 | + if ($sanitizedAppId !== $appId) { |
|
568 | 568 | return false; |
569 | 569 | } |
570 | 570 | static $app_dir = array(); |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | |
576 | 576 | $possibleApps = array(); |
577 | 577 | foreach (OC::$APPSROOTS as $dir) { |
578 | - if (file_exists($dir['path'] . '/' . $appId)) { |
|
578 | + if (file_exists($dir['path'].'/'.$appId)) { |
|
579 | 579 | $possibleApps[] = $dir; |
580 | 580 | } |
581 | 581 | } |
@@ -616,7 +616,7 @@ discard block |
||
616 | 616 | } |
617 | 617 | |
618 | 618 | if (($dir = self::findAppInDirectories($appId)) != false) { |
619 | - return $dir['path'] . '/' . $appId; |
|
619 | + return $dir['path'].'/'.$appId; |
|
620 | 620 | } |
621 | 621 | return false; |
622 | 622 | } |
@@ -630,7 +630,7 @@ discard block |
||
630 | 630 | */ |
631 | 631 | public static function getAppWebPath($appId) { |
632 | 632 | if (($dir = self::findAppInDirectories($appId)) != false) { |
633 | - return OC::$WEBROOT . $dir['url'] . '/' . $appId; |
|
633 | + return OC::$WEBROOT.$dir['url'].'/'.$appId; |
|
634 | 634 | } |
635 | 635 | return false; |
636 | 636 | } |
@@ -643,7 +643,7 @@ discard block |
||
643 | 643 | * @return string |
644 | 644 | */ |
645 | 645 | public static function getAppVersion($appId, $useCache = true) { |
646 | - if($useCache && isset(self::$appVersion[$appId])) { |
|
646 | + if ($useCache && isset(self::$appVersion[$appId])) { |
|
647 | 647 | return self::$appVersion[$appId]; |
648 | 648 | } |
649 | 649 | |
@@ -659,7 +659,7 @@ discard block |
||
659 | 659 | * @return string |
660 | 660 | */ |
661 | 661 | public static function getAppVersionByPath($path) { |
662 | - $infoFile = $path . '/appinfo/info.xml'; |
|
662 | + $infoFile = $path.'/appinfo/info.xml'; |
|
663 | 663 | $appData = self::getAppInfo($infoFile, true); |
664 | 664 | return isset($appData['version']) ? $appData['version'] : ''; |
665 | 665 | } |
@@ -682,10 +682,10 @@ discard block |
||
682 | 682 | return self::$appInfo[$appId]; |
683 | 683 | } |
684 | 684 | $appPath = self::getAppPath($appId); |
685 | - if($appPath === false) { |
|
685 | + if ($appPath === false) { |
|
686 | 686 | return null; |
687 | 687 | } |
688 | - $file = $appPath . '/appinfo/info.xml'; |
|
688 | + $file = $appPath.'/appinfo/info.xml'; |
|
689 | 689 | } |
690 | 690 | |
691 | 691 | $parser = new InfoParser(\OC::$server->getMemCacheFactory()->create('core.appinfo')); |
@@ -694,9 +694,9 @@ discard block |
||
694 | 694 | if (is_array($data)) { |
695 | 695 | $data = OC_App::parseAppInfo($data, $lang); |
696 | 696 | } |
697 | - if(isset($data['ocsid'])) { |
|
697 | + if (isset($data['ocsid'])) { |
|
698 | 698 | $storedId = \OC::$server->getConfig()->getAppValue($appId, 'ocsid'); |
699 | - if($storedId !== '' && $storedId !== $data['ocsid']) { |
|
699 | + if ($storedId !== '' && $storedId !== $data['ocsid']) { |
|
700 | 700 | $data['ocsid'] = $storedId; |
701 | 701 | } |
702 | 702 | } |
@@ -803,7 +803,7 @@ discard block |
||
803 | 803 | * @param string $page |
804 | 804 | */ |
805 | 805 | public static function registerAdmin($app, $page) { |
806 | - self::$adminForms[] = $app . '/' . $page . '.php'; |
|
806 | + self::$adminForms[] = $app.'/'.$page.'.php'; |
|
807 | 807 | } |
808 | 808 | |
809 | 809 | /** |
@@ -812,7 +812,7 @@ discard block |
||
812 | 812 | * @param string $page |
813 | 813 | */ |
814 | 814 | public static function registerPersonal($app, $page) { |
815 | - self::$personalForms[] = $app . '/' . $page . '.php'; |
|
815 | + self::$personalForms[] = $app.'/'.$page.'.php'; |
|
816 | 816 | } |
817 | 817 | |
818 | 818 | /** |
@@ -841,7 +841,7 @@ discard block |
||
841 | 841 | |
842 | 842 | foreach (OC::$APPSROOTS as $apps_dir) { |
843 | 843 | if (!is_readable($apps_dir['path'])) { |
844 | - \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); |
|
844 | + \OCP\Util::writeLog('core', 'unable to read app folder : '.$apps_dir['path'], \OCP\Util::WARN); |
|
845 | 845 | continue; |
846 | 846 | } |
847 | 847 | $dh = opendir($apps_dir['path']); |
@@ -849,7 +849,7 @@ discard block |
||
849 | 849 | if (is_resource($dh)) { |
850 | 850 | while (($file = readdir($dh)) !== false) { |
851 | 851 | |
852 | - if ($file[0] != '.' and is_dir($apps_dir['path'] . '/' . $file) and is_file($apps_dir['path'] . '/' . $file . '/appinfo/info.xml')) { |
|
852 | + if ($file[0] != '.' and is_dir($apps_dir['path'].'/'.$file) and is_file($apps_dir['path'].'/'.$file.'/appinfo/info.xml')) { |
|
853 | 853 | |
854 | 854 | $apps[] = $file; |
855 | 855 | } |
@@ -879,12 +879,12 @@ discard block |
||
879 | 879 | |
880 | 880 | $info = OC_App::getAppInfo($app, false, $langCode); |
881 | 881 | if (!is_array($info)) { |
882 | - \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); |
|
882 | + \OCP\Util::writeLog('core', 'Could not read app info file for app "'.$app.'"', \OCP\Util::ERROR); |
|
883 | 883 | continue; |
884 | 884 | } |
885 | 885 | |
886 | 886 | if (!isset($info['name'])) { |
887 | - \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); |
|
887 | + \OCP\Util::writeLog('core', 'App id "'.$app.'" has no name in appinfo', \OCP\Util::ERROR); |
|
888 | 888 | continue; |
889 | 889 | } |
890 | 890 | |
@@ -911,13 +911,13 @@ discard block |
||
911 | 911 | } |
912 | 912 | |
913 | 913 | $appPath = self::getAppPath($app); |
914 | - if($appPath !== false) { |
|
915 | - $appIcon = $appPath . '/img/' . $app . '.svg'; |
|
914 | + if ($appPath !== false) { |
|
915 | + $appIcon = $appPath.'/img/'.$app.'.svg'; |
|
916 | 916 | if (file_exists($appIcon)) { |
917 | - $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app . '.svg'); |
|
917 | + $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, $app.'.svg'); |
|
918 | 918 | $info['previewAsIcon'] = true; |
919 | 919 | } else { |
920 | - $appIcon = $appPath . '/img/app.svg'; |
|
920 | + $appIcon = $appPath.'/img/app.svg'; |
|
921 | 921 | if (file_exists($appIcon)) { |
922 | 922 | $info['preview'] = \OC::$server->getURLGenerator()->imagePath($app, 'app.svg'); |
923 | 923 | $info['previewAsIcon'] = true; |
@@ -951,9 +951,9 @@ discard block |
||
951 | 951 | * @return string|false |
952 | 952 | */ |
953 | 953 | public static function getInternalAppIdByOcs($ocsID) { |
954 | - if(is_numeric($ocsID)) { |
|
954 | + if (is_numeric($ocsID)) { |
|
955 | 955 | $idArray = \OC::$server->getAppConfig()->getValues(false, 'ocsid'); |
956 | - if(array_search($ocsID, $idArray)) { |
|
956 | + if (array_search($ocsID, $idArray)) { |
|
957 | 957 | return array_search($ocsID, $idArray); |
958 | 958 | } |
959 | 959 | } |
@@ -1057,7 +1057,7 @@ discard block |
||
1057 | 1057 | public static function getAppVersions() { |
1058 | 1058 | static $versions; |
1059 | 1059 | |
1060 | - if(!$versions) { |
|
1060 | + if (!$versions) { |
|
1061 | 1061 | $appConfig = \OC::$server->getAppConfig(); |
1062 | 1062 | $versions = $appConfig->getValues(false, 'installed_version'); |
1063 | 1063 | } |
@@ -1079,7 +1079,7 @@ discard block |
||
1079 | 1079 | if ($app !== false) { |
1080 | 1080 | // check if the app is compatible with this version of ownCloud |
1081 | 1081 | $info = self::getAppInfo($app); |
1082 | - if(!is_array($info)) { |
|
1082 | + if (!is_array($info)) { |
|
1083 | 1083 | throw new \Exception( |
1084 | 1084 | $l->t('App "%s" cannot be installed because appinfo file cannot be read.', |
1085 | 1085 | [$info['name']] |
@@ -1104,7 +1104,7 @@ discard block |
||
1104 | 1104 | $config->setAppValue($app, 'ocsid', $appData['id']); |
1105 | 1105 | } |
1106 | 1106 | |
1107 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
1107 | + if (isset($info['settings']) && is_array($info['settings'])) { |
|
1108 | 1108 | $appPath = self::getAppPath($app); |
1109 | 1109 | self::registerAutoloading($app, $appPath); |
1110 | 1110 | \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
@@ -1112,7 +1112,7 @@ discard block |
||
1112 | 1112 | |
1113 | 1113 | \OC_Hook::emit('OC_App', 'post_enable', array('app' => $app)); |
1114 | 1114 | } else { |
1115 | - if(empty($appName) ) { |
|
1115 | + if (empty($appName)) { |
|
1116 | 1116 | throw new \Exception($l->t("No app name specified")); |
1117 | 1117 | } else { |
1118 | 1118 | throw new \Exception($l->t("App '%s' could not be installed!", $appName)); |
@@ -1130,24 +1130,24 @@ discard block |
||
1130 | 1130 | */ |
1131 | 1131 | public static function updateApp($appId) { |
1132 | 1132 | $appPath = self::getAppPath($appId); |
1133 | - if($appPath === false) { |
|
1133 | + if ($appPath === false) { |
|
1134 | 1134 | return false; |
1135 | 1135 | } |
1136 | 1136 | $appData = self::getAppInfo($appId); |
1137 | 1137 | self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); |
1138 | - if (file_exists($appPath . '/appinfo/database.xml')) { |
|
1139 | - OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); |
|
1138 | + if (file_exists($appPath.'/appinfo/database.xml')) { |
|
1139 | + OC_DB::updateDbFromStructure($appPath.'/appinfo/database.xml'); |
|
1140 | 1140 | } |
1141 | 1141 | self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); |
1142 | 1142 | self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); |
1143 | 1143 | unset(self::$appVersion[$appId]); |
1144 | 1144 | // run upgrade code |
1145 | - if (file_exists($appPath . '/appinfo/update.php')) { |
|
1145 | + if (file_exists($appPath.'/appinfo/update.php')) { |
|
1146 | 1146 | self::loadApp($appId); |
1147 | - include $appPath . '/appinfo/update.php'; |
|
1147 | + include $appPath.'/appinfo/update.php'; |
|
1148 | 1148 | } |
1149 | 1149 | self::setupBackgroundJobs($appData['background-jobs']); |
1150 | - if(isset($appData['settings']) && is_array($appData['settings'])) { |
|
1150 | + if (isset($appData['settings']) && is_array($appData['settings'])) { |
|
1151 | 1151 | $appPath = self::getAppPath($appId); |
1152 | 1152 | self::registerAutoloading($appId, $appPath); |
1153 | 1153 | \OC::$server->getSettingsManager()->setupSettings($appData['settings']); |
@@ -1156,14 +1156,14 @@ discard block |
||
1156 | 1156 | //set remote/public handlers |
1157 | 1157 | if (array_key_exists('ocsid', $appData)) { |
1158 | 1158 | \OC::$server->getConfig()->setAppValue($appId, 'ocsid', $appData['ocsid']); |
1159 | - } elseif(\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
1159 | + } elseif (\OC::$server->getConfig()->getAppValue($appId, 'ocsid', null) !== null) { |
|
1160 | 1160 | \OC::$server->getConfig()->deleteAppValue($appId, 'ocsid'); |
1161 | 1161 | } |
1162 | 1162 | foreach ($appData['remote'] as $name => $path) { |
1163 | - \OC::$server->getConfig()->setAppValue('core', 'remote_' . $name, $appId . '/' . $path); |
|
1163 | + \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $appId.'/'.$path); |
|
1164 | 1164 | } |
1165 | 1165 | foreach ($appData['public'] as $name => $path) { |
1166 | - \OC::$server->getConfig()->setAppValue('core', 'public_' . $name, $appId . '/' . $path); |
|
1166 | + \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $appId.'/'.$path); |
|
1167 | 1167 | } |
1168 | 1168 | |
1169 | 1169 | self::setAppTypes($appId); |
@@ -1233,17 +1233,17 @@ discard block |
||
1233 | 1233 | public static function getStorage($appId) { |
1234 | 1234 | if (OC_App::isEnabled($appId)) { //sanity check |
1235 | 1235 | if (\OC::$server->getUserSession()->isLoggedIn()) { |
1236 | - $view = new \OC\Files\View('/' . OC_User::getUser()); |
|
1236 | + $view = new \OC\Files\View('/'.OC_User::getUser()); |
|
1237 | 1237 | if (!$view->file_exists($appId)) { |
1238 | 1238 | $view->mkdir($appId); |
1239 | 1239 | } |
1240 | - return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); |
|
1240 | + return new \OC\Files\View('/'.OC_User::getUser().'/'.$appId); |
|
1241 | 1241 | } else { |
1242 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); |
|
1242 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app '.$appId.', user not logged in', \OCP\Util::ERROR); |
|
1243 | 1243 | return false; |
1244 | 1244 | } |
1245 | 1245 | } else { |
1246 | - \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); |
|
1246 | + \OCP\Util::writeLog('core', 'Can\'t get app storage, app '.$appId.' not enabled', \OCP\Util::ERROR); |
|
1247 | 1247 | return false; |
1248 | 1248 | } |
1249 | 1249 | } |
@@ -1275,9 +1275,9 @@ discard block |
||
1275 | 1275 | |
1276 | 1276 | if ($attributeLang === $similarLang) { |
1277 | 1277 | $similarLangFallback = $option['@value']; |
1278 | - } else if (strpos($attributeLang, $similarLang . '_') === 0) { |
|
1278 | + } else if (strpos($attributeLang, $similarLang.'_') === 0) { |
|
1279 | 1279 | if ($similarLangFallback === false) { |
1280 | - $similarLangFallback = $option['@value']; |
|
1280 | + $similarLangFallback = $option['@value']; |
|
1281 | 1281 | } |
1282 | 1282 | } |
1283 | 1283 | } else { |
@@ -1312,7 +1312,7 @@ discard block |
||
1312 | 1312 | $data['description'] = trim(self::findBestL10NOption($data['description'], $lang)); |
1313 | 1313 | } else if (isset($data['description']) && is_string($data['description'])) { |
1314 | 1314 | $data['description'] = trim($data['description']); |
1315 | - } else { |
|
1315 | + } else { |
|
1316 | 1316 | $data['description'] = ''; |
1317 | 1317 | } |
1318 | 1318 |
@@ -318,6 +318,11 @@ |
||
318 | 318 | */ |
319 | 319 | // FIXME This method is only public, until OC_L10N does not need it anymore, |
320 | 320 | // FIXME This is also the reason, why it is not in the public interface |
321 | + |
|
322 | + /** |
|
323 | + * @param string $app |
|
324 | + * @param string $lang |
|
325 | + */ |
|
321 | 326 | public function getL10nFilesForApp($app, $lang) { |
322 | 327 | $languageFiles = []; |
323 | 328 |
@@ -131,9 +131,9 @@ discard block |
||
131 | 131 | * |
132 | 132 | * @link https://github.com/owncloud/core/issues/21955 |
133 | 133 | */ |
134 | - if($this->config->getSystemValue('installed', false)) { |
|
135 | - $userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() : null; |
|
136 | - if(!is_null($userId)) { |
|
134 | + if ($this->config->getSystemValue('installed', false)) { |
|
135 | + $userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() : null; |
|
136 | + if (!is_null($userId)) { |
|
137 | 137 | $userLang = $this->config->getUserValue($userId, 'core', 'lang', null); |
138 | 138 | } else { |
139 | 139 | $userLang = null; |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | // merge with translations from theme |
203 | 203 | $theme = $this->config->getSystemValue('theme'); |
204 | 204 | if (!empty($theme)) { |
205 | - $themeDir = $this->serverRoot . '/themes/' . $theme . substr($dir, strlen($this->serverRoot)); |
|
205 | + $themeDir = $this->serverRoot.'/themes/'.$theme.substr($dir, strlen($this->serverRoot)); |
|
206 | 206 | |
207 | 207 | if (is_dir($themeDir)) { |
208 | 208 | $files = scandir($themeDir); |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | */ |
298 | 298 | private function isSubDirectory($sub, $parent) { |
299 | 299 | // Check whether $sub contains no ".." |
300 | - if(strpos($sub, '..') !== false) { |
|
300 | + if (strpos($sub, '..') !== false) { |
|
301 | 301 | return false; |
302 | 302 | } |
303 | 303 | |
@@ -322,12 +322,12 @@ discard block |
||
322 | 322 | $languageFiles = []; |
323 | 323 | |
324 | 324 | $i18nDir = $this->findL10nDir($app); |
325 | - $transFile = strip_tags($i18nDir) . strip_tags($lang) . '.json'; |
|
325 | + $transFile = strip_tags($i18nDir).strip_tags($lang).'.json'; |
|
326 | 326 | |
327 | - if (($this->isSubDirectory($transFile, $this->serverRoot . '/core/l10n/') |
|
328 | - || $this->isSubDirectory($transFile, $this->serverRoot . '/lib/l10n/') |
|
329 | - || $this->isSubDirectory($transFile, $this->serverRoot . '/settings/l10n/') |
|
330 | - || $this->isSubDirectory($transFile, \OC_App::getAppPath($app) . '/l10n/') |
|
327 | + if (($this->isSubDirectory($transFile, $this->serverRoot.'/core/l10n/') |
|
328 | + || $this->isSubDirectory($transFile, $this->serverRoot.'/lib/l10n/') |
|
329 | + || $this->isSubDirectory($transFile, $this->serverRoot.'/settings/l10n/') |
|
330 | + || $this->isSubDirectory($transFile, \OC_App::getAppPath($app).'/l10n/') |
|
331 | 331 | ) |
332 | 332 | && file_exists($transFile)) { |
333 | 333 | // load the translations file |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | // merge with translations from theme |
338 | 338 | $theme = $this->config->getSystemValue('theme'); |
339 | 339 | if (!empty($theme)) { |
340 | - $transFile = $this->serverRoot . '/themes/' . $theme . substr($transFile, strlen($this->serverRoot)); |
|
340 | + $transFile = $this->serverRoot.'/themes/'.$theme.substr($transFile, strlen($this->serverRoot)); |
|
341 | 341 | if (file_exists($transFile)) { |
342 | 342 | $languageFiles[] = $transFile; |
343 | 343 | } |
@@ -354,14 +354,14 @@ discard block |
||
354 | 354 | */ |
355 | 355 | protected function findL10nDir($app = null) { |
356 | 356 | if (in_array($app, ['core', 'lib', 'settings'])) { |
357 | - if (file_exists($this->serverRoot . '/' . $app . '/l10n/')) { |
|
358 | - return $this->serverRoot . '/' . $app . '/l10n/'; |
|
357 | + if (file_exists($this->serverRoot.'/'.$app.'/l10n/')) { |
|
358 | + return $this->serverRoot.'/'.$app.'/l10n/'; |
|
359 | 359 | } |
360 | 360 | } else if ($app && \OC_App::getAppPath($app) !== false) { |
361 | 361 | // Check if the app is in the app folder |
362 | - return \OC_App::getAppPath($app) . '/l10n/'; |
|
362 | + return \OC_App::getAppPath($app).'/l10n/'; |
|
363 | 363 | } |
364 | - return $this->serverRoot . '/core/l10n/'; |
|
364 | + return $this->serverRoot.'/core/l10n/'; |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | |
@@ -378,15 +378,15 @@ discard block |
||
378 | 378 | return $this->pluralFunctions[$string]; |
379 | 379 | } |
380 | 380 | |
381 | - if (preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) { |
|
381 | + if (preg_match('/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) { |
|
382 | 382 | // sanitize |
383 | - $nplurals = preg_replace( '/[^0-9]/', '', $matches[1] ); |
|
384 | - $plural = preg_replace( '#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2] ); |
|
383 | + $nplurals = preg_replace('/[^0-9]/', '', $matches[1]); |
|
384 | + $plural = preg_replace('#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2]); |
|
385 | 385 | |
386 | 386 | $body = str_replace( |
387 | - array( 'plural', 'n', '$n$plurals', ), |
|
388 | - array( '$plural', '$n', '$nplurals', ), |
|
389 | - 'nplurals='. $nplurals . '; plural=' . $plural |
|
387 | + array('plural', 'n', '$n$plurals',), |
|
388 | + array('$plural', '$n', '$nplurals',), |
|
389 | + 'nplurals='.$nplurals.'; plural='.$plural |
|
390 | 390 | ); |
391 | 391 | |
392 | 392 | // add parents |
@@ -394,9 +394,9 @@ discard block |
||
394 | 394 | $body .= ';'; |
395 | 395 | $res = ''; |
396 | 396 | $p = 0; |
397 | - for($i = 0; $i < strlen($body); $i++) { |
|
397 | + for ($i = 0; $i < strlen($body); $i++) { |
|
398 | 398 | $ch = $body[$i]; |
399 | - switch ( $ch ) { |
|
399 | + switch ($ch) { |
|
400 | 400 | case '?': |
401 | 401 | $res .= ' ? ('; |
402 | 402 | $p++; |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | $res .= ') : ('; |
406 | 406 | break; |
407 | 407 | case ';': |
408 | - $res .= str_repeat( ')', $p ) . ';'; |
|
408 | + $res .= str_repeat(')', $p).';'; |
|
409 | 409 | $p = 0; |
410 | 410 | break; |
411 | 411 | default: |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | } |
414 | 414 | } |
415 | 415 | |
416 | - $body = $res . 'return ($plural>=$nplurals?$nplurals-1:$plural);'; |
|
416 | + $body = $res.'return ($plural>=$nplurals?$nplurals-1:$plural);'; |
|
417 | 417 | $function = create_function('$n', $body); |
418 | 418 | $this->pluralFunctions[$string] = $function; |
419 | 419 | return $function; |
@@ -40,373 +40,373 @@ |
||
40 | 40 | */ |
41 | 41 | class Factory implements IFactory { |
42 | 42 | |
43 | - /** @var string */ |
|
44 | - protected $requestLanguage = ''; |
|
45 | - |
|
46 | - /** |
|
47 | - * cached instances |
|
48 | - * @var array Structure: Lang => App => \OCP\IL10N |
|
49 | - */ |
|
50 | - protected $instances = []; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var array Structure: App => string[] |
|
54 | - */ |
|
55 | - protected $availableLanguages = []; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var array Structure: string => callable |
|
59 | - */ |
|
60 | - protected $pluralFunctions = []; |
|
61 | - |
|
62 | - /** @var IConfig */ |
|
63 | - protected $config; |
|
64 | - |
|
65 | - /** @var IRequest */ |
|
66 | - protected $request; |
|
67 | - |
|
68 | - /** @var IUserSession */ |
|
69 | - protected $userSession; |
|
70 | - |
|
71 | - /** @var string */ |
|
72 | - protected $serverRoot; |
|
73 | - |
|
74 | - /** |
|
75 | - * @param IConfig $config |
|
76 | - * @param IRequest $request |
|
77 | - * @param IUserSession $userSession |
|
78 | - * @param string $serverRoot |
|
79 | - */ |
|
80 | - public function __construct(IConfig $config, |
|
81 | - IRequest $request, |
|
82 | - IUserSession $userSession, |
|
83 | - $serverRoot) { |
|
84 | - $this->config = $config; |
|
85 | - $this->request = $request; |
|
86 | - $this->userSession = $userSession; |
|
87 | - $this->serverRoot = $serverRoot; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Get a language instance |
|
92 | - * |
|
93 | - * @param string $app |
|
94 | - * @param string|null $lang |
|
95 | - * @return \OCP\IL10N |
|
96 | - */ |
|
97 | - public function get($app, $lang = null) { |
|
98 | - $app = \OC_App::cleanAppId($app); |
|
99 | - if ($lang !== null) { |
|
100 | - $lang = str_replace(array('\0', '/', '\\', '..'), '', (string) $lang); |
|
101 | - } |
|
102 | - if ($lang === null || !$this->languageExists($app, $lang)) { |
|
103 | - $lang = $this->findLanguage($app); |
|
104 | - } |
|
105 | - |
|
106 | - if (!isset($this->instances[$lang][$app])) { |
|
107 | - $this->instances[$lang][$app] = new L10N( |
|
108 | - $this, $app, $lang, |
|
109 | - $this->getL10nFilesForApp($app, $lang) |
|
110 | - ); |
|
111 | - } |
|
112 | - |
|
113 | - return $this->instances[$lang][$app]; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Find the best language |
|
118 | - * |
|
119 | - * @param string|null $app App id or null for core |
|
120 | - * @return string language If nothing works it returns 'en' |
|
121 | - */ |
|
122 | - public function findLanguage($app = null) { |
|
123 | - if ($this->requestLanguage !== '' && $this->languageExists($app, $this->requestLanguage)) { |
|
124 | - return $this->requestLanguage; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * At this point ownCloud might not yet be installed and thus the lookup |
|
129 | - * in the preferences table might fail. For this reason we need to check |
|
130 | - * whether the instance has already been installed |
|
131 | - * |
|
132 | - * @link https://github.com/owncloud/core/issues/21955 |
|
133 | - */ |
|
134 | - if($this->config->getSystemValue('installed', false)) { |
|
135 | - $userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() : null; |
|
136 | - if(!is_null($userId)) { |
|
137 | - $userLang = $this->config->getUserValue($userId, 'core', 'lang', null); |
|
138 | - } else { |
|
139 | - $userLang = null; |
|
140 | - } |
|
141 | - } else { |
|
142 | - $userId = null; |
|
143 | - $userLang = null; |
|
144 | - } |
|
145 | - |
|
146 | - if ($userLang) { |
|
147 | - $this->requestLanguage = $userLang; |
|
148 | - if ($this->languageExists($app, $userLang)) { |
|
149 | - return $userLang; |
|
150 | - } |
|
151 | - } |
|
152 | - |
|
153 | - try { |
|
154 | - // Try to get the language from the Request |
|
155 | - $lang = $this->getLanguageFromRequest($app); |
|
156 | - if ($userId !== null && $app === null && !$userLang) { |
|
157 | - $this->config->setUserValue($userId, 'core', 'lang', $lang); |
|
158 | - } |
|
159 | - return $lang; |
|
160 | - } catch (LanguageNotFoundException $e) { |
|
161 | - // Finding language from request failed fall back to default language |
|
162 | - $defaultLanguage = $this->config->getSystemValue('default_language', false); |
|
163 | - if ($defaultLanguage !== false && $this->languageExists($app, $defaultLanguage)) { |
|
164 | - return $defaultLanguage; |
|
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - // We could not find any language so fall back to english |
|
169 | - return 'en'; |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * Find all available languages for an app |
|
174 | - * |
|
175 | - * @param string|null $app App id or null for core |
|
176 | - * @return array an array of available languages |
|
177 | - */ |
|
178 | - public function findAvailableLanguages($app = null) { |
|
179 | - $key = $app; |
|
180 | - if ($key === null) { |
|
181 | - $key = 'null'; |
|
182 | - } |
|
183 | - |
|
184 | - // also works with null as key |
|
185 | - if (!empty($this->availableLanguages[$key])) { |
|
186 | - return $this->availableLanguages[$key]; |
|
187 | - } |
|
188 | - |
|
189 | - $available = ['en']; //english is always available |
|
190 | - $dir = $this->findL10nDir($app); |
|
191 | - if (is_dir($dir)) { |
|
192 | - $files = scandir($dir); |
|
193 | - if ($files !== false) { |
|
194 | - foreach ($files as $file) { |
|
195 | - if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') { |
|
196 | - $available[] = substr($file, 0, -5); |
|
197 | - } |
|
198 | - } |
|
199 | - } |
|
200 | - } |
|
201 | - |
|
202 | - // merge with translations from theme |
|
203 | - $theme = $this->config->getSystemValue('theme'); |
|
204 | - if (!empty($theme)) { |
|
205 | - $themeDir = $this->serverRoot . '/themes/' . $theme . substr($dir, strlen($this->serverRoot)); |
|
206 | - |
|
207 | - if (is_dir($themeDir)) { |
|
208 | - $files = scandir($themeDir); |
|
209 | - if ($files !== false) { |
|
210 | - foreach ($files as $file) { |
|
211 | - if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') { |
|
212 | - $available[] = substr($file, 0, -5); |
|
213 | - } |
|
214 | - } |
|
215 | - } |
|
216 | - } |
|
217 | - } |
|
218 | - |
|
219 | - $this->availableLanguages[$key] = $available; |
|
220 | - return $available; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * @param string|null $app App id or null for core |
|
225 | - * @param string $lang |
|
226 | - * @return bool |
|
227 | - */ |
|
228 | - public function languageExists($app, $lang) { |
|
229 | - if ($lang === 'en') {//english is always available |
|
230 | - return true; |
|
231 | - } |
|
232 | - |
|
233 | - $languages = $this->findAvailableLanguages($app); |
|
234 | - return array_search($lang, $languages) !== false; |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * @param string|null $app |
|
239 | - * @return string |
|
240 | - * @throws LanguageNotFoundException |
|
241 | - */ |
|
242 | - private function getLanguageFromRequest($app) { |
|
243 | - $header = $this->request->getHeader('ACCEPT_LANGUAGE'); |
|
244 | - if ($header) { |
|
245 | - $available = $this->findAvailableLanguages($app); |
|
246 | - |
|
247 | - // E.g. make sure that 'de' is before 'de_DE'. |
|
248 | - sort($available); |
|
249 | - |
|
250 | - $preferences = preg_split('/,\s*/', strtolower($header)); |
|
251 | - foreach ($preferences as $preference) { |
|
252 | - list($preferred_language) = explode(';', $preference); |
|
253 | - $preferred_language = str_replace('-', '_', $preferred_language); |
|
254 | - |
|
255 | - foreach ($available as $available_language) { |
|
256 | - if ($preferred_language === strtolower($available_language)) { |
|
257 | - return $available_language; |
|
258 | - } |
|
259 | - } |
|
260 | - |
|
261 | - // Fallback from de_De to de |
|
262 | - foreach ($available as $available_language) { |
|
263 | - if (substr($preferred_language, 0, 2) === $available_language) { |
|
264 | - return $available_language; |
|
265 | - } |
|
266 | - } |
|
267 | - } |
|
268 | - } |
|
269 | - |
|
270 | - throw new LanguageNotFoundException(); |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * Checks if $sub is a subdirectory of $parent |
|
275 | - * |
|
276 | - * @param string $sub |
|
277 | - * @param string $parent |
|
278 | - * @return bool |
|
279 | - */ |
|
280 | - private function isSubDirectory($sub, $parent) { |
|
281 | - // Check whether $sub contains no ".." |
|
282 | - if(strpos($sub, '..') !== false) { |
|
283 | - return false; |
|
284 | - } |
|
285 | - |
|
286 | - // Check whether $sub is a subdirectory of $parent |
|
287 | - if (strpos($sub, $parent) === 0) { |
|
288 | - return true; |
|
289 | - } |
|
290 | - |
|
291 | - return false; |
|
292 | - } |
|
293 | - |
|
294 | - /** |
|
295 | - * Get a list of language files that should be loaded |
|
296 | - * |
|
297 | - * @param string $app |
|
298 | - * @param string $lang |
|
299 | - * @return string[] |
|
300 | - */ |
|
301 | - // FIXME This method is only public, until OC_L10N does not need it anymore, |
|
302 | - // FIXME This is also the reason, why it is not in the public interface |
|
303 | - public function getL10nFilesForApp($app, $lang) { |
|
304 | - $languageFiles = []; |
|
305 | - |
|
306 | - $i18nDir = $this->findL10nDir($app); |
|
307 | - $transFile = strip_tags($i18nDir) . strip_tags($lang) . '.json'; |
|
308 | - |
|
309 | - if (($this->isSubDirectory($transFile, $this->serverRoot . '/core/l10n/') |
|
310 | - || $this->isSubDirectory($transFile, $this->serverRoot . '/lib/l10n/') |
|
311 | - || $this->isSubDirectory($transFile, $this->serverRoot . '/settings/l10n/') |
|
312 | - || $this->isSubDirectory($transFile, \OC_App::getAppPath($app) . '/l10n/') |
|
313 | - ) |
|
314 | - && file_exists($transFile)) { |
|
315 | - // load the translations file |
|
316 | - $languageFiles[] = $transFile; |
|
317 | - } |
|
318 | - |
|
319 | - // merge with translations from theme |
|
320 | - $theme = $this->config->getSystemValue('theme'); |
|
321 | - if (!empty($theme)) { |
|
322 | - $transFile = $this->serverRoot . '/themes/' . $theme . substr($transFile, strlen($this->serverRoot)); |
|
323 | - if (file_exists($transFile)) { |
|
324 | - $languageFiles[] = $transFile; |
|
325 | - } |
|
326 | - } |
|
327 | - |
|
328 | - return $languageFiles; |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * find the l10n directory |
|
333 | - * |
|
334 | - * @param string $app App id or empty string for core |
|
335 | - * @return string directory |
|
336 | - */ |
|
337 | - protected function findL10nDir($app = null) { |
|
338 | - if (in_array($app, ['core', 'lib', 'settings'])) { |
|
339 | - if (file_exists($this->serverRoot . '/' . $app . '/l10n/')) { |
|
340 | - return $this->serverRoot . '/' . $app . '/l10n/'; |
|
341 | - } |
|
342 | - } else if ($app && \OC_App::getAppPath($app) !== false) { |
|
343 | - // Check if the app is in the app folder |
|
344 | - return \OC_App::getAppPath($app) . '/l10n/'; |
|
345 | - } |
|
346 | - return $this->serverRoot . '/core/l10n/'; |
|
347 | - } |
|
348 | - |
|
349 | - |
|
350 | - /** |
|
351 | - * Creates a function from the plural string |
|
352 | - * |
|
353 | - * Parts of the code is copied from Habari: |
|
354 | - * https://github.com/habari/system/blob/master/classes/locale.php |
|
355 | - * @param string $string |
|
356 | - * @return string |
|
357 | - */ |
|
358 | - public function createPluralFunction($string) { |
|
359 | - if (isset($this->pluralFunctions[$string])) { |
|
360 | - return $this->pluralFunctions[$string]; |
|
361 | - } |
|
362 | - |
|
363 | - if (preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) { |
|
364 | - // sanitize |
|
365 | - $nplurals = preg_replace( '/[^0-9]/', '', $matches[1] ); |
|
366 | - $plural = preg_replace( '#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2] ); |
|
367 | - |
|
368 | - $body = str_replace( |
|
369 | - array( 'plural', 'n', '$n$plurals', ), |
|
370 | - array( '$plural', '$n', '$nplurals', ), |
|
371 | - 'nplurals='. $nplurals . '; plural=' . $plural |
|
372 | - ); |
|
373 | - |
|
374 | - // add parents |
|
375 | - // important since PHP's ternary evaluates from left to right |
|
376 | - $body .= ';'; |
|
377 | - $res = ''; |
|
378 | - $p = 0; |
|
379 | - for($i = 0; $i < strlen($body); $i++) { |
|
380 | - $ch = $body[$i]; |
|
381 | - switch ( $ch ) { |
|
382 | - case '?': |
|
383 | - $res .= ' ? ('; |
|
384 | - $p++; |
|
385 | - break; |
|
386 | - case ':': |
|
387 | - $res .= ') : ('; |
|
388 | - break; |
|
389 | - case ';': |
|
390 | - $res .= str_repeat( ')', $p ) . ';'; |
|
391 | - $p = 0; |
|
392 | - break; |
|
393 | - default: |
|
394 | - $res .= $ch; |
|
395 | - } |
|
396 | - } |
|
397 | - |
|
398 | - $body = $res . 'return ($plural>=$nplurals?$nplurals-1:$plural);'; |
|
399 | - $function = create_function('$n', $body); |
|
400 | - $this->pluralFunctions[$string] = $function; |
|
401 | - return $function; |
|
402 | - } else { |
|
403 | - // default: one plural form for all cases but n==1 (english) |
|
404 | - $function = create_function( |
|
405 | - '$n', |
|
406 | - '$nplurals=2;$plural=($n==1?0:1);return ($plural>=$nplurals?$nplurals-1:$plural);' |
|
407 | - ); |
|
408 | - $this->pluralFunctions[$string] = $function; |
|
409 | - return $function; |
|
410 | - } |
|
411 | - } |
|
43 | + /** @var string */ |
|
44 | + protected $requestLanguage = ''; |
|
45 | + |
|
46 | + /** |
|
47 | + * cached instances |
|
48 | + * @var array Structure: Lang => App => \OCP\IL10N |
|
49 | + */ |
|
50 | + protected $instances = []; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var array Structure: App => string[] |
|
54 | + */ |
|
55 | + protected $availableLanguages = []; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var array Structure: string => callable |
|
59 | + */ |
|
60 | + protected $pluralFunctions = []; |
|
61 | + |
|
62 | + /** @var IConfig */ |
|
63 | + protected $config; |
|
64 | + |
|
65 | + /** @var IRequest */ |
|
66 | + protected $request; |
|
67 | + |
|
68 | + /** @var IUserSession */ |
|
69 | + protected $userSession; |
|
70 | + |
|
71 | + /** @var string */ |
|
72 | + protected $serverRoot; |
|
73 | + |
|
74 | + /** |
|
75 | + * @param IConfig $config |
|
76 | + * @param IRequest $request |
|
77 | + * @param IUserSession $userSession |
|
78 | + * @param string $serverRoot |
|
79 | + */ |
|
80 | + public function __construct(IConfig $config, |
|
81 | + IRequest $request, |
|
82 | + IUserSession $userSession, |
|
83 | + $serverRoot) { |
|
84 | + $this->config = $config; |
|
85 | + $this->request = $request; |
|
86 | + $this->userSession = $userSession; |
|
87 | + $this->serverRoot = $serverRoot; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Get a language instance |
|
92 | + * |
|
93 | + * @param string $app |
|
94 | + * @param string|null $lang |
|
95 | + * @return \OCP\IL10N |
|
96 | + */ |
|
97 | + public function get($app, $lang = null) { |
|
98 | + $app = \OC_App::cleanAppId($app); |
|
99 | + if ($lang !== null) { |
|
100 | + $lang = str_replace(array('\0', '/', '\\', '..'), '', (string) $lang); |
|
101 | + } |
|
102 | + if ($lang === null || !$this->languageExists($app, $lang)) { |
|
103 | + $lang = $this->findLanguage($app); |
|
104 | + } |
|
105 | + |
|
106 | + if (!isset($this->instances[$lang][$app])) { |
|
107 | + $this->instances[$lang][$app] = new L10N( |
|
108 | + $this, $app, $lang, |
|
109 | + $this->getL10nFilesForApp($app, $lang) |
|
110 | + ); |
|
111 | + } |
|
112 | + |
|
113 | + return $this->instances[$lang][$app]; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Find the best language |
|
118 | + * |
|
119 | + * @param string|null $app App id or null for core |
|
120 | + * @return string language If nothing works it returns 'en' |
|
121 | + */ |
|
122 | + public function findLanguage($app = null) { |
|
123 | + if ($this->requestLanguage !== '' && $this->languageExists($app, $this->requestLanguage)) { |
|
124 | + return $this->requestLanguage; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * At this point ownCloud might not yet be installed and thus the lookup |
|
129 | + * in the preferences table might fail. For this reason we need to check |
|
130 | + * whether the instance has already been installed |
|
131 | + * |
|
132 | + * @link https://github.com/owncloud/core/issues/21955 |
|
133 | + */ |
|
134 | + if($this->config->getSystemValue('installed', false)) { |
|
135 | + $userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() : null; |
|
136 | + if(!is_null($userId)) { |
|
137 | + $userLang = $this->config->getUserValue($userId, 'core', 'lang', null); |
|
138 | + } else { |
|
139 | + $userLang = null; |
|
140 | + } |
|
141 | + } else { |
|
142 | + $userId = null; |
|
143 | + $userLang = null; |
|
144 | + } |
|
145 | + |
|
146 | + if ($userLang) { |
|
147 | + $this->requestLanguage = $userLang; |
|
148 | + if ($this->languageExists($app, $userLang)) { |
|
149 | + return $userLang; |
|
150 | + } |
|
151 | + } |
|
152 | + |
|
153 | + try { |
|
154 | + // Try to get the language from the Request |
|
155 | + $lang = $this->getLanguageFromRequest($app); |
|
156 | + if ($userId !== null && $app === null && !$userLang) { |
|
157 | + $this->config->setUserValue($userId, 'core', 'lang', $lang); |
|
158 | + } |
|
159 | + return $lang; |
|
160 | + } catch (LanguageNotFoundException $e) { |
|
161 | + // Finding language from request failed fall back to default language |
|
162 | + $defaultLanguage = $this->config->getSystemValue('default_language', false); |
|
163 | + if ($defaultLanguage !== false && $this->languageExists($app, $defaultLanguage)) { |
|
164 | + return $defaultLanguage; |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + // We could not find any language so fall back to english |
|
169 | + return 'en'; |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * Find all available languages for an app |
|
174 | + * |
|
175 | + * @param string|null $app App id or null for core |
|
176 | + * @return array an array of available languages |
|
177 | + */ |
|
178 | + public function findAvailableLanguages($app = null) { |
|
179 | + $key = $app; |
|
180 | + if ($key === null) { |
|
181 | + $key = 'null'; |
|
182 | + } |
|
183 | + |
|
184 | + // also works with null as key |
|
185 | + if (!empty($this->availableLanguages[$key])) { |
|
186 | + return $this->availableLanguages[$key]; |
|
187 | + } |
|
188 | + |
|
189 | + $available = ['en']; //english is always available |
|
190 | + $dir = $this->findL10nDir($app); |
|
191 | + if (is_dir($dir)) { |
|
192 | + $files = scandir($dir); |
|
193 | + if ($files !== false) { |
|
194 | + foreach ($files as $file) { |
|
195 | + if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') { |
|
196 | + $available[] = substr($file, 0, -5); |
|
197 | + } |
|
198 | + } |
|
199 | + } |
|
200 | + } |
|
201 | + |
|
202 | + // merge with translations from theme |
|
203 | + $theme = $this->config->getSystemValue('theme'); |
|
204 | + if (!empty($theme)) { |
|
205 | + $themeDir = $this->serverRoot . '/themes/' . $theme . substr($dir, strlen($this->serverRoot)); |
|
206 | + |
|
207 | + if (is_dir($themeDir)) { |
|
208 | + $files = scandir($themeDir); |
|
209 | + if ($files !== false) { |
|
210 | + foreach ($files as $file) { |
|
211 | + if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') { |
|
212 | + $available[] = substr($file, 0, -5); |
|
213 | + } |
|
214 | + } |
|
215 | + } |
|
216 | + } |
|
217 | + } |
|
218 | + |
|
219 | + $this->availableLanguages[$key] = $available; |
|
220 | + return $available; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * @param string|null $app App id or null for core |
|
225 | + * @param string $lang |
|
226 | + * @return bool |
|
227 | + */ |
|
228 | + public function languageExists($app, $lang) { |
|
229 | + if ($lang === 'en') {//english is always available |
|
230 | + return true; |
|
231 | + } |
|
232 | + |
|
233 | + $languages = $this->findAvailableLanguages($app); |
|
234 | + return array_search($lang, $languages) !== false; |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * @param string|null $app |
|
239 | + * @return string |
|
240 | + * @throws LanguageNotFoundException |
|
241 | + */ |
|
242 | + private function getLanguageFromRequest($app) { |
|
243 | + $header = $this->request->getHeader('ACCEPT_LANGUAGE'); |
|
244 | + if ($header) { |
|
245 | + $available = $this->findAvailableLanguages($app); |
|
246 | + |
|
247 | + // E.g. make sure that 'de' is before 'de_DE'. |
|
248 | + sort($available); |
|
249 | + |
|
250 | + $preferences = preg_split('/,\s*/', strtolower($header)); |
|
251 | + foreach ($preferences as $preference) { |
|
252 | + list($preferred_language) = explode(';', $preference); |
|
253 | + $preferred_language = str_replace('-', '_', $preferred_language); |
|
254 | + |
|
255 | + foreach ($available as $available_language) { |
|
256 | + if ($preferred_language === strtolower($available_language)) { |
|
257 | + return $available_language; |
|
258 | + } |
|
259 | + } |
|
260 | + |
|
261 | + // Fallback from de_De to de |
|
262 | + foreach ($available as $available_language) { |
|
263 | + if (substr($preferred_language, 0, 2) === $available_language) { |
|
264 | + return $available_language; |
|
265 | + } |
|
266 | + } |
|
267 | + } |
|
268 | + } |
|
269 | + |
|
270 | + throw new LanguageNotFoundException(); |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * Checks if $sub is a subdirectory of $parent |
|
275 | + * |
|
276 | + * @param string $sub |
|
277 | + * @param string $parent |
|
278 | + * @return bool |
|
279 | + */ |
|
280 | + private function isSubDirectory($sub, $parent) { |
|
281 | + // Check whether $sub contains no ".." |
|
282 | + if(strpos($sub, '..') !== false) { |
|
283 | + return false; |
|
284 | + } |
|
285 | + |
|
286 | + // Check whether $sub is a subdirectory of $parent |
|
287 | + if (strpos($sub, $parent) === 0) { |
|
288 | + return true; |
|
289 | + } |
|
290 | + |
|
291 | + return false; |
|
292 | + } |
|
293 | + |
|
294 | + /** |
|
295 | + * Get a list of language files that should be loaded |
|
296 | + * |
|
297 | + * @param string $app |
|
298 | + * @param string $lang |
|
299 | + * @return string[] |
|
300 | + */ |
|
301 | + // FIXME This method is only public, until OC_L10N does not need it anymore, |
|
302 | + // FIXME This is also the reason, why it is not in the public interface |
|
303 | + public function getL10nFilesForApp($app, $lang) { |
|
304 | + $languageFiles = []; |
|
305 | + |
|
306 | + $i18nDir = $this->findL10nDir($app); |
|
307 | + $transFile = strip_tags($i18nDir) . strip_tags($lang) . '.json'; |
|
308 | + |
|
309 | + if (($this->isSubDirectory($transFile, $this->serverRoot . '/core/l10n/') |
|
310 | + || $this->isSubDirectory($transFile, $this->serverRoot . '/lib/l10n/') |
|
311 | + || $this->isSubDirectory($transFile, $this->serverRoot . '/settings/l10n/') |
|
312 | + || $this->isSubDirectory($transFile, \OC_App::getAppPath($app) . '/l10n/') |
|
313 | + ) |
|
314 | + && file_exists($transFile)) { |
|
315 | + // load the translations file |
|
316 | + $languageFiles[] = $transFile; |
|
317 | + } |
|
318 | + |
|
319 | + // merge with translations from theme |
|
320 | + $theme = $this->config->getSystemValue('theme'); |
|
321 | + if (!empty($theme)) { |
|
322 | + $transFile = $this->serverRoot . '/themes/' . $theme . substr($transFile, strlen($this->serverRoot)); |
|
323 | + if (file_exists($transFile)) { |
|
324 | + $languageFiles[] = $transFile; |
|
325 | + } |
|
326 | + } |
|
327 | + |
|
328 | + return $languageFiles; |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * find the l10n directory |
|
333 | + * |
|
334 | + * @param string $app App id or empty string for core |
|
335 | + * @return string directory |
|
336 | + */ |
|
337 | + protected function findL10nDir($app = null) { |
|
338 | + if (in_array($app, ['core', 'lib', 'settings'])) { |
|
339 | + if (file_exists($this->serverRoot . '/' . $app . '/l10n/')) { |
|
340 | + return $this->serverRoot . '/' . $app . '/l10n/'; |
|
341 | + } |
|
342 | + } else if ($app && \OC_App::getAppPath($app) !== false) { |
|
343 | + // Check if the app is in the app folder |
|
344 | + return \OC_App::getAppPath($app) . '/l10n/'; |
|
345 | + } |
|
346 | + return $this->serverRoot . '/core/l10n/'; |
|
347 | + } |
|
348 | + |
|
349 | + |
|
350 | + /** |
|
351 | + * Creates a function from the plural string |
|
352 | + * |
|
353 | + * Parts of the code is copied from Habari: |
|
354 | + * https://github.com/habari/system/blob/master/classes/locale.php |
|
355 | + * @param string $string |
|
356 | + * @return string |
|
357 | + */ |
|
358 | + public function createPluralFunction($string) { |
|
359 | + if (isset($this->pluralFunctions[$string])) { |
|
360 | + return $this->pluralFunctions[$string]; |
|
361 | + } |
|
362 | + |
|
363 | + if (preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) { |
|
364 | + // sanitize |
|
365 | + $nplurals = preg_replace( '/[^0-9]/', '', $matches[1] ); |
|
366 | + $plural = preg_replace( '#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2] ); |
|
367 | + |
|
368 | + $body = str_replace( |
|
369 | + array( 'plural', 'n', '$n$plurals', ), |
|
370 | + array( '$plural', '$n', '$nplurals', ), |
|
371 | + 'nplurals='. $nplurals . '; plural=' . $plural |
|
372 | + ); |
|
373 | + |
|
374 | + // add parents |
|
375 | + // important since PHP's ternary evaluates from left to right |
|
376 | + $body .= ';'; |
|
377 | + $res = ''; |
|
378 | + $p = 0; |
|
379 | + for($i = 0; $i < strlen($body); $i++) { |
|
380 | + $ch = $body[$i]; |
|
381 | + switch ( $ch ) { |
|
382 | + case '?': |
|
383 | + $res .= ' ? ('; |
|
384 | + $p++; |
|
385 | + break; |
|
386 | + case ':': |
|
387 | + $res .= ') : ('; |
|
388 | + break; |
|
389 | + case ';': |
|
390 | + $res .= str_repeat( ')', $p ) . ';'; |
|
391 | + $p = 0; |
|
392 | + break; |
|
393 | + default: |
|
394 | + $res .= $ch; |
|
395 | + } |
|
396 | + } |
|
397 | + |
|
398 | + $body = $res . 'return ($plural>=$nplurals?$nplurals-1:$plural);'; |
|
399 | + $function = create_function('$n', $body); |
|
400 | + $this->pluralFunctions[$string] = $function; |
|
401 | + return $function; |
|
402 | + } else { |
|
403 | + // default: one plural form for all cases but n==1 (english) |
|
404 | + $function = create_function( |
|
405 | + '$n', |
|
406 | + '$nplurals=2;$plural=($n==1?0:1);return ($plural>=$nplurals?$nplurals-1:$plural);' |
|
407 | + ); |
|
408 | + $this->pluralFunctions[$string] = $function; |
|
409 | + return $function; |
|
410 | + } |
|
411 | + } |
|
412 | 412 | } |
@@ -45,7 +45,6 @@ |
||
45 | 45 | use OC\App\CodeChecker\CodeChecker; |
46 | 46 | use OC\App\CodeChecker\EmptyCheck; |
47 | 47 | use OC\App\CodeChecker\PrivateCheck; |
48 | -use OC\Archive\Archive; |
|
49 | 48 | use OC\Archive\TAR; |
50 | 49 | use OC_App; |
51 | 50 | use OC_DB; |
@@ -60,493 +60,493 @@ |
||
60 | 60 | * This class provides the functionality needed to install, update and remove apps |
61 | 61 | */ |
62 | 62 | class Installer { |
63 | - /** @var AppFetcher */ |
|
64 | - private $appFetcher; |
|
65 | - /** @var IClientService */ |
|
66 | - private $clientService; |
|
67 | - /** @var ITempManager */ |
|
68 | - private $tempManager; |
|
69 | - /** @var ILogger */ |
|
70 | - private $logger; |
|
71 | - |
|
72 | - /** |
|
73 | - * @param AppFetcher $appFetcher |
|
74 | - * @param IClientService $clientService |
|
75 | - * @param ITempManager $tempManager |
|
76 | - * @param ILogger $logger |
|
77 | - */ |
|
78 | - public function __construct(AppFetcher $appFetcher, |
|
79 | - IClientService $clientService, |
|
80 | - ITempManager $tempManager, |
|
81 | - ILogger $logger) { |
|
82 | - $this->appFetcher = $appFetcher; |
|
83 | - $this->clientService = $clientService; |
|
84 | - $this->tempManager = $tempManager; |
|
85 | - $this->logger = $logger; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Installs an app that is located in one of the app folders already |
|
90 | - * |
|
91 | - * @param string $appId App to install |
|
92 | - * @throws \Exception |
|
93 | - * @return integer |
|
94 | - */ |
|
95 | - public function installApp($appId) { |
|
96 | - $app = \OC_App::findAppInDirectories($appId); |
|
97 | - if($app === false) { |
|
98 | - throw new \Exception('App not found in any app directory'); |
|
99 | - } |
|
100 | - |
|
101 | - $basedir = $app['path'].'/'.$appId; |
|
102 | - $info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true); |
|
103 | - |
|
104 | - //install the database |
|
105 | - if(is_file($basedir.'/appinfo/database.xml')) { |
|
106 | - if (\OC::$server->getAppConfig()->getValue($info['id'], 'installed_version') === null) { |
|
107 | - OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
|
108 | - } else { |
|
109 | - OC_DB::updateDbFromStructure($basedir.'/appinfo/database.xml'); |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
114 | - |
|
115 | - //run appinfo/install.php |
|
116 | - if((!isset($data['noinstall']) or $data['noinstall']==false)) { |
|
117 | - self::includeAppScript($basedir . '/appinfo/install.php'); |
|
118 | - } |
|
119 | - |
|
120 | - $appData = OC_App::getAppInfo($appId); |
|
121 | - OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']); |
|
122 | - |
|
123 | - //set the installed version |
|
124 | - \OC::$server->getConfig()->setAppValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'], false)); |
|
125 | - \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
|
126 | - |
|
127 | - //set remote/public handlers |
|
128 | - foreach($info['remote'] as $name=>$path) { |
|
129 | - \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
|
130 | - } |
|
131 | - foreach($info['public'] as $name=>$path) { |
|
132 | - \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
|
133 | - } |
|
134 | - |
|
135 | - OC_App::setAppTypes($info['id']); |
|
136 | - |
|
137 | - return $info['id']; |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * @brief checks whether or not an app is installed |
|
142 | - * @param string $app app |
|
143 | - * @returns bool |
|
144 | - * |
|
145 | - * Checks whether or not an app is installed, i.e. registered in apps table. |
|
146 | - */ |
|
147 | - public static function isInstalled( $app ) { |
|
148 | - return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null); |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Updates the specified app from the appstore |
|
153 | - * |
|
154 | - * @param string $appId |
|
155 | - * @return bool |
|
156 | - */ |
|
157 | - public function updateAppstoreApp($appId) { |
|
158 | - if(self::isUpdateAvailable($appId, $this->appFetcher)) { |
|
159 | - try { |
|
160 | - $this->downloadApp($appId); |
|
161 | - } catch (\Exception $e) { |
|
162 | - $this->logger->error($e->getMessage(), ['app' => 'core']); |
|
163 | - return false; |
|
164 | - } |
|
165 | - return OC_App::updateApp($appId); |
|
166 | - } |
|
167 | - |
|
168 | - return false; |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * Downloads an app and puts it into the app directory |
|
173 | - * |
|
174 | - * @param string $appId |
|
175 | - * |
|
176 | - * @throws \Exception If the installation was not successful |
|
177 | - */ |
|
178 | - public function downloadApp($appId) { |
|
179 | - $appId = strtolower($appId); |
|
180 | - |
|
181 | - $apps = $this->appFetcher->get(); |
|
182 | - foreach($apps as $app) { |
|
183 | - if($app['id'] === $appId) { |
|
184 | - // Load the certificate |
|
185 | - $certificate = new X509(); |
|
186 | - $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
187 | - $loadedCertificate = $certificate->loadX509($app['certificate']); |
|
188 | - |
|
189 | - // Verify if the certificate has been revoked |
|
190 | - $crl = new X509(); |
|
191 | - $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
192 | - $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
193 | - if($crl->validateSignature() !== true) { |
|
194 | - throw new \Exception('Could not validate CRL signature'); |
|
195 | - } |
|
196 | - $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
|
197 | - $revoked = $crl->getRevoked($csn); |
|
198 | - if ($revoked !== false) { |
|
199 | - throw new \Exception( |
|
200 | - sprintf( |
|
201 | - 'Certificate "%s" has been revoked', |
|
202 | - $csn |
|
203 | - ) |
|
204 | - ); |
|
205 | - } |
|
206 | - |
|
207 | - // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
|
208 | - if($certificate->validateSignature() !== true) { |
|
209 | - throw new \Exception( |
|
210 | - sprintf( |
|
211 | - 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
|
212 | - $appId |
|
213 | - ) |
|
214 | - ); |
|
215 | - } |
|
216 | - |
|
217 | - // Verify if the certificate is issued for the requested app id |
|
218 | - $certInfo = openssl_x509_parse($app['certificate']); |
|
219 | - if(!isset($certInfo['subject']['CN'])) { |
|
220 | - throw new \Exception( |
|
221 | - sprintf( |
|
222 | - 'App with id %s has a cert with no CN', |
|
223 | - $appId |
|
224 | - ) |
|
225 | - ); |
|
226 | - } |
|
227 | - if($certInfo['subject']['CN'] !== $appId) { |
|
228 | - throw new \Exception( |
|
229 | - sprintf( |
|
230 | - 'App with id %s has a cert issued to %s', |
|
231 | - $appId, |
|
232 | - $certInfo['subject']['CN'] |
|
233 | - ) |
|
234 | - ); |
|
235 | - } |
|
236 | - |
|
237 | - // Download the release |
|
238 | - $tempFile = $this->tempManager->getTemporaryFile('.tar.gz'); |
|
239 | - $client = $this->clientService->newClient(); |
|
240 | - $client->get($app['releases'][0]['download'], ['save_to' => $tempFile]); |
|
241 | - |
|
242 | - // Check if the signature actually matches the downloaded content |
|
243 | - $certificate = openssl_get_publickey($app['certificate']); |
|
244 | - $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
245 | - openssl_free_key($certificate); |
|
246 | - |
|
247 | - if($verified === true) { |
|
248 | - // Seems to match, let's proceed |
|
249 | - $extractDir = $this->tempManager->getTemporaryFolder(); |
|
250 | - $archive = new TAR($tempFile); |
|
251 | - |
|
252 | - if($archive) { |
|
253 | - $archive->extract($extractDir); |
|
254 | - $allFiles = scandir($extractDir); |
|
255 | - $folders = array_diff($allFiles, ['.', '..']); |
|
256 | - $folders = array_values($folders); |
|
257 | - |
|
258 | - if(count($folders) > 1) { |
|
259 | - throw new \Exception( |
|
260 | - sprintf( |
|
261 | - 'Extracted app %s has more than 1 folder', |
|
262 | - $appId |
|
263 | - ) |
|
264 | - ); |
|
265 | - } |
|
266 | - |
|
267 | - // Check if appinfo/info.xml has the same app ID as well |
|
268 | - $loadEntities = libxml_disable_entity_loader(false); |
|
269 | - $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
270 | - libxml_disable_entity_loader($loadEntities); |
|
271 | - if((string)$xml->id !== $appId) { |
|
272 | - throw new \Exception( |
|
273 | - sprintf( |
|
274 | - 'App for id %s has a wrong app ID in info.xml: %s', |
|
275 | - $appId, |
|
276 | - (string)$xml->id |
|
277 | - ) |
|
278 | - ); |
|
279 | - } |
|
280 | - |
|
281 | - // Check if the version is lower than before |
|
282 | - $currentVersion = OC_App::getAppVersion($appId); |
|
283 | - $newVersion = (string)$xml->version; |
|
284 | - if(version_compare($currentVersion, $newVersion) === 1) { |
|
285 | - throw new \Exception( |
|
286 | - sprintf( |
|
287 | - 'App for id %s has version %s and tried to update to lower version %s', |
|
288 | - $appId, |
|
289 | - $currentVersion, |
|
290 | - $newVersion |
|
291 | - ) |
|
292 | - ); |
|
293 | - } |
|
294 | - |
|
295 | - $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
296 | - // Remove old app with the ID if existent |
|
297 | - OC_Helper::rmdirr($baseDir); |
|
298 | - // Move to app folder |
|
299 | - if(@mkdir($baseDir)) { |
|
300 | - $extractDir .= '/' . $folders[0]; |
|
301 | - OC_Helper::copyr($extractDir, $baseDir); |
|
302 | - } |
|
303 | - OC_Helper::copyr($extractDir, $baseDir); |
|
304 | - OC_Helper::rmdirr($extractDir); |
|
305 | - return; |
|
306 | - } else { |
|
307 | - throw new \Exception( |
|
308 | - sprintf( |
|
309 | - 'Could not extract app with ID %s to %s', |
|
310 | - $appId, |
|
311 | - $extractDir |
|
312 | - ) |
|
313 | - ); |
|
314 | - } |
|
315 | - } else { |
|
316 | - // Signature does not match |
|
317 | - throw new \Exception( |
|
318 | - sprintf( |
|
319 | - 'App with id %s has invalid signature', |
|
320 | - $appId |
|
321 | - ) |
|
322 | - ); |
|
323 | - } |
|
324 | - } |
|
325 | - } |
|
326 | - |
|
327 | - throw new \Exception( |
|
328 | - sprintf( |
|
329 | - 'Could not download app %s', |
|
330 | - $appId |
|
331 | - ) |
|
332 | - ); |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * Check if an update for the app is available |
|
337 | - * |
|
338 | - * @param string $appId |
|
339 | - * @param AppFetcher $appFetcher |
|
340 | - * @return string|false false or the version number of the update |
|
341 | - */ |
|
342 | - public static function isUpdateAvailable($appId, |
|
343 | - AppFetcher $appFetcher) { |
|
344 | - static $isInstanceReadyForUpdates = null; |
|
345 | - |
|
346 | - if ($isInstanceReadyForUpdates === null) { |
|
347 | - $installPath = OC_App::getInstallPath(); |
|
348 | - if ($installPath === false || $installPath === null) { |
|
349 | - $isInstanceReadyForUpdates = false; |
|
350 | - } else { |
|
351 | - $isInstanceReadyForUpdates = true; |
|
352 | - } |
|
353 | - } |
|
354 | - |
|
355 | - if ($isInstanceReadyForUpdates === false) { |
|
356 | - return false; |
|
357 | - } |
|
358 | - |
|
359 | - $apps = $appFetcher->get(); |
|
360 | - foreach($apps as $app) { |
|
361 | - if($app['id'] === $appId) { |
|
362 | - $currentVersion = OC_App::getAppVersion($appId); |
|
363 | - $newestVersion = $app['releases'][0]['version']; |
|
364 | - if (version_compare($newestVersion, $currentVersion, '>')) { |
|
365 | - return $newestVersion; |
|
366 | - } else { |
|
367 | - return false; |
|
368 | - } |
|
369 | - } |
|
370 | - } |
|
371 | - |
|
372 | - return false; |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * Check if app is already downloaded |
|
377 | - * @param string $name name of the application to remove |
|
378 | - * @return boolean |
|
379 | - * |
|
380 | - * The function will check if the app is already downloaded in the apps repository |
|
381 | - */ |
|
382 | - public function isDownloaded($name) { |
|
383 | - foreach(\OC::$APPSROOTS as $dir) { |
|
384 | - $dirToTest = $dir['path']; |
|
385 | - $dirToTest .= '/'; |
|
386 | - $dirToTest .= $name; |
|
387 | - $dirToTest .= '/'; |
|
388 | - |
|
389 | - if (is_dir($dirToTest)) { |
|
390 | - return true; |
|
391 | - } |
|
392 | - } |
|
393 | - |
|
394 | - return false; |
|
395 | - } |
|
396 | - |
|
397 | - /** |
|
398 | - * Removes an app |
|
399 | - * @param string $appId ID of the application to remove |
|
400 | - * @return boolean |
|
401 | - * |
|
402 | - * |
|
403 | - * This function works as follows |
|
404 | - * -# call uninstall repair steps |
|
405 | - * -# removing the files |
|
406 | - * |
|
407 | - * The function will not delete preferences, tables and the configuration, |
|
408 | - * this has to be done by the function oc_app_uninstall(). |
|
409 | - */ |
|
410 | - public function removeApp($appId) { |
|
411 | - if($this->isDownloaded( $appId )) { |
|
412 | - $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
413 | - OC_Helper::rmdirr($appDir); |
|
414 | - return true; |
|
415 | - }else{ |
|
416 | - \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
|
417 | - |
|
418 | - return false; |
|
419 | - } |
|
420 | - |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * Installs shipped apps |
|
425 | - * |
|
426 | - * This function installs all apps found in the 'apps' directory that should be enabled by default; |
|
427 | - * @param bool $softErrors When updating we ignore errors and simply log them, better to have a |
|
428 | - * working ownCloud at the end instead of an aborted update. |
|
429 | - * @return array Array of error messages (appid => Exception) |
|
430 | - */ |
|
431 | - public static function installShippedApps($softErrors = false) { |
|
432 | - $errors = []; |
|
433 | - foreach(\OC::$APPSROOTS as $app_dir) { |
|
434 | - if($dir = opendir( $app_dir['path'] )) { |
|
435 | - while( false !== ( $filename = readdir( $dir ))) { |
|
436 | - if( substr( $filename, 0, 1 ) != '.' and is_dir($app_dir['path']."/$filename") ) { |
|
437 | - if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
438 | - if(!Installer::isInstalled($filename)) { |
|
439 | - $info=OC_App::getAppInfo($filename); |
|
440 | - $enabled = isset($info['default_enable']); |
|
441 | - if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps())) |
|
442 | - && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') { |
|
443 | - if ($softErrors) { |
|
444 | - try { |
|
445 | - Installer::installShippedApp($filename); |
|
446 | - } catch (HintException $e) { |
|
447 | - if ($e->getPrevious() instanceof TableExistsException) { |
|
448 | - $errors[$filename] = $e; |
|
449 | - continue; |
|
450 | - } |
|
451 | - throw $e; |
|
452 | - } |
|
453 | - } else { |
|
454 | - Installer::installShippedApp($filename); |
|
455 | - } |
|
456 | - \OC::$server->getConfig()->setAppValue($filename, 'enabled', 'yes'); |
|
457 | - } |
|
458 | - } |
|
459 | - } |
|
460 | - } |
|
461 | - } |
|
462 | - closedir( $dir ); |
|
463 | - } |
|
464 | - } |
|
465 | - |
|
466 | - return $errors; |
|
467 | - } |
|
468 | - |
|
469 | - /** |
|
470 | - * install an app already placed in the app folder |
|
471 | - * @param string $app id of the app to install |
|
472 | - * @return integer |
|
473 | - */ |
|
474 | - public static function installShippedApp($app) { |
|
475 | - //install the database |
|
476 | - $appPath = OC_App::getAppPath($app); |
|
477 | - if(is_file("$appPath/appinfo/database.xml")) { |
|
478 | - try { |
|
479 | - OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
|
480 | - } catch (TableExistsException $e) { |
|
481 | - throw new HintException( |
|
482 | - 'Failed to enable app ' . $app, |
|
483 | - 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer">support channels</a>.', |
|
484 | - 0, $e |
|
485 | - ); |
|
486 | - } |
|
487 | - } |
|
488 | - |
|
489 | - //run appinfo/install.php |
|
490 | - \OC_App::registerAutoloading($app, $appPath); |
|
491 | - self::includeAppScript("$appPath/appinfo/install.php"); |
|
492 | - |
|
493 | - $info = OC_App::getAppInfo($app); |
|
494 | - if (is_null($info)) { |
|
495 | - return false; |
|
496 | - } |
|
497 | - \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
498 | - |
|
499 | - OC_App::executeRepairSteps($app, $info['repair-steps']['install']); |
|
500 | - |
|
501 | - $config = \OC::$server->getConfig(); |
|
502 | - |
|
503 | - $config->setAppValue($app, 'installed_version', OC_App::getAppVersion($app)); |
|
504 | - if (array_key_exists('ocsid', $info)) { |
|
505 | - $config->setAppValue($app, 'ocsid', $info['ocsid']); |
|
506 | - } |
|
507 | - |
|
508 | - //set remote/public handlers |
|
509 | - foreach($info['remote'] as $name=>$path) { |
|
510 | - $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
|
511 | - } |
|
512 | - foreach($info['public'] as $name=>$path) { |
|
513 | - $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
|
514 | - } |
|
515 | - |
|
516 | - OC_App::setAppTypes($info['id']); |
|
517 | - |
|
518 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
519 | - // requires that autoloading was registered for the app, |
|
520 | - // as happens before running the install.php some lines above |
|
521 | - \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
522 | - } |
|
523 | - |
|
524 | - return $info['id']; |
|
525 | - } |
|
526 | - |
|
527 | - /** |
|
528 | - * check the code of an app with some static code checks |
|
529 | - * @param string $folder the folder of the app to check |
|
530 | - * @return boolean true for app is o.k. and false for app is not o.k. |
|
531 | - */ |
|
532 | - public static function checkCode($folder) { |
|
533 | - // is the code checker enabled? |
|
534 | - if(!\OC::$server->getConfig()->getSystemValue('appcodechecker', false)) { |
|
535 | - return true; |
|
536 | - } |
|
537 | - |
|
538 | - $codeChecker = new CodeChecker(new PrivateCheck(new EmptyCheck())); |
|
539 | - $errors = $codeChecker->analyseFolder(basename($folder), $folder); |
|
540 | - |
|
541 | - return empty($errors); |
|
542 | - } |
|
543 | - |
|
544 | - /** |
|
545 | - * @param string $script |
|
546 | - */ |
|
547 | - private static function includeAppScript($script) { |
|
548 | - if ( file_exists($script) ){ |
|
549 | - include $script; |
|
550 | - } |
|
551 | - } |
|
63 | + /** @var AppFetcher */ |
|
64 | + private $appFetcher; |
|
65 | + /** @var IClientService */ |
|
66 | + private $clientService; |
|
67 | + /** @var ITempManager */ |
|
68 | + private $tempManager; |
|
69 | + /** @var ILogger */ |
|
70 | + private $logger; |
|
71 | + |
|
72 | + /** |
|
73 | + * @param AppFetcher $appFetcher |
|
74 | + * @param IClientService $clientService |
|
75 | + * @param ITempManager $tempManager |
|
76 | + * @param ILogger $logger |
|
77 | + */ |
|
78 | + public function __construct(AppFetcher $appFetcher, |
|
79 | + IClientService $clientService, |
|
80 | + ITempManager $tempManager, |
|
81 | + ILogger $logger) { |
|
82 | + $this->appFetcher = $appFetcher; |
|
83 | + $this->clientService = $clientService; |
|
84 | + $this->tempManager = $tempManager; |
|
85 | + $this->logger = $logger; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Installs an app that is located in one of the app folders already |
|
90 | + * |
|
91 | + * @param string $appId App to install |
|
92 | + * @throws \Exception |
|
93 | + * @return integer |
|
94 | + */ |
|
95 | + public function installApp($appId) { |
|
96 | + $app = \OC_App::findAppInDirectories($appId); |
|
97 | + if($app === false) { |
|
98 | + throw new \Exception('App not found in any app directory'); |
|
99 | + } |
|
100 | + |
|
101 | + $basedir = $app['path'].'/'.$appId; |
|
102 | + $info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true); |
|
103 | + |
|
104 | + //install the database |
|
105 | + if(is_file($basedir.'/appinfo/database.xml')) { |
|
106 | + if (\OC::$server->getAppConfig()->getValue($info['id'], 'installed_version') === null) { |
|
107 | + OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
|
108 | + } else { |
|
109 | + OC_DB::updateDbFromStructure($basedir.'/appinfo/database.xml'); |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
114 | + |
|
115 | + //run appinfo/install.php |
|
116 | + if((!isset($data['noinstall']) or $data['noinstall']==false)) { |
|
117 | + self::includeAppScript($basedir . '/appinfo/install.php'); |
|
118 | + } |
|
119 | + |
|
120 | + $appData = OC_App::getAppInfo($appId); |
|
121 | + OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']); |
|
122 | + |
|
123 | + //set the installed version |
|
124 | + \OC::$server->getConfig()->setAppValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'], false)); |
|
125 | + \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
|
126 | + |
|
127 | + //set remote/public handlers |
|
128 | + foreach($info['remote'] as $name=>$path) { |
|
129 | + \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
|
130 | + } |
|
131 | + foreach($info['public'] as $name=>$path) { |
|
132 | + \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
|
133 | + } |
|
134 | + |
|
135 | + OC_App::setAppTypes($info['id']); |
|
136 | + |
|
137 | + return $info['id']; |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * @brief checks whether or not an app is installed |
|
142 | + * @param string $app app |
|
143 | + * @returns bool |
|
144 | + * |
|
145 | + * Checks whether or not an app is installed, i.e. registered in apps table. |
|
146 | + */ |
|
147 | + public static function isInstalled( $app ) { |
|
148 | + return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null); |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Updates the specified app from the appstore |
|
153 | + * |
|
154 | + * @param string $appId |
|
155 | + * @return bool |
|
156 | + */ |
|
157 | + public function updateAppstoreApp($appId) { |
|
158 | + if(self::isUpdateAvailable($appId, $this->appFetcher)) { |
|
159 | + try { |
|
160 | + $this->downloadApp($appId); |
|
161 | + } catch (\Exception $e) { |
|
162 | + $this->logger->error($e->getMessage(), ['app' => 'core']); |
|
163 | + return false; |
|
164 | + } |
|
165 | + return OC_App::updateApp($appId); |
|
166 | + } |
|
167 | + |
|
168 | + return false; |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * Downloads an app and puts it into the app directory |
|
173 | + * |
|
174 | + * @param string $appId |
|
175 | + * |
|
176 | + * @throws \Exception If the installation was not successful |
|
177 | + */ |
|
178 | + public function downloadApp($appId) { |
|
179 | + $appId = strtolower($appId); |
|
180 | + |
|
181 | + $apps = $this->appFetcher->get(); |
|
182 | + foreach($apps as $app) { |
|
183 | + if($app['id'] === $appId) { |
|
184 | + // Load the certificate |
|
185 | + $certificate = new X509(); |
|
186 | + $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
187 | + $loadedCertificate = $certificate->loadX509($app['certificate']); |
|
188 | + |
|
189 | + // Verify if the certificate has been revoked |
|
190 | + $crl = new X509(); |
|
191 | + $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
192 | + $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
193 | + if($crl->validateSignature() !== true) { |
|
194 | + throw new \Exception('Could not validate CRL signature'); |
|
195 | + } |
|
196 | + $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
|
197 | + $revoked = $crl->getRevoked($csn); |
|
198 | + if ($revoked !== false) { |
|
199 | + throw new \Exception( |
|
200 | + sprintf( |
|
201 | + 'Certificate "%s" has been revoked', |
|
202 | + $csn |
|
203 | + ) |
|
204 | + ); |
|
205 | + } |
|
206 | + |
|
207 | + // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
|
208 | + if($certificate->validateSignature() !== true) { |
|
209 | + throw new \Exception( |
|
210 | + sprintf( |
|
211 | + 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
|
212 | + $appId |
|
213 | + ) |
|
214 | + ); |
|
215 | + } |
|
216 | + |
|
217 | + // Verify if the certificate is issued for the requested app id |
|
218 | + $certInfo = openssl_x509_parse($app['certificate']); |
|
219 | + if(!isset($certInfo['subject']['CN'])) { |
|
220 | + throw new \Exception( |
|
221 | + sprintf( |
|
222 | + 'App with id %s has a cert with no CN', |
|
223 | + $appId |
|
224 | + ) |
|
225 | + ); |
|
226 | + } |
|
227 | + if($certInfo['subject']['CN'] !== $appId) { |
|
228 | + throw new \Exception( |
|
229 | + sprintf( |
|
230 | + 'App with id %s has a cert issued to %s', |
|
231 | + $appId, |
|
232 | + $certInfo['subject']['CN'] |
|
233 | + ) |
|
234 | + ); |
|
235 | + } |
|
236 | + |
|
237 | + // Download the release |
|
238 | + $tempFile = $this->tempManager->getTemporaryFile('.tar.gz'); |
|
239 | + $client = $this->clientService->newClient(); |
|
240 | + $client->get($app['releases'][0]['download'], ['save_to' => $tempFile]); |
|
241 | + |
|
242 | + // Check if the signature actually matches the downloaded content |
|
243 | + $certificate = openssl_get_publickey($app['certificate']); |
|
244 | + $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
245 | + openssl_free_key($certificate); |
|
246 | + |
|
247 | + if($verified === true) { |
|
248 | + // Seems to match, let's proceed |
|
249 | + $extractDir = $this->tempManager->getTemporaryFolder(); |
|
250 | + $archive = new TAR($tempFile); |
|
251 | + |
|
252 | + if($archive) { |
|
253 | + $archive->extract($extractDir); |
|
254 | + $allFiles = scandir($extractDir); |
|
255 | + $folders = array_diff($allFiles, ['.', '..']); |
|
256 | + $folders = array_values($folders); |
|
257 | + |
|
258 | + if(count($folders) > 1) { |
|
259 | + throw new \Exception( |
|
260 | + sprintf( |
|
261 | + 'Extracted app %s has more than 1 folder', |
|
262 | + $appId |
|
263 | + ) |
|
264 | + ); |
|
265 | + } |
|
266 | + |
|
267 | + // Check if appinfo/info.xml has the same app ID as well |
|
268 | + $loadEntities = libxml_disable_entity_loader(false); |
|
269 | + $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
270 | + libxml_disable_entity_loader($loadEntities); |
|
271 | + if((string)$xml->id !== $appId) { |
|
272 | + throw new \Exception( |
|
273 | + sprintf( |
|
274 | + 'App for id %s has a wrong app ID in info.xml: %s', |
|
275 | + $appId, |
|
276 | + (string)$xml->id |
|
277 | + ) |
|
278 | + ); |
|
279 | + } |
|
280 | + |
|
281 | + // Check if the version is lower than before |
|
282 | + $currentVersion = OC_App::getAppVersion($appId); |
|
283 | + $newVersion = (string)$xml->version; |
|
284 | + if(version_compare($currentVersion, $newVersion) === 1) { |
|
285 | + throw new \Exception( |
|
286 | + sprintf( |
|
287 | + 'App for id %s has version %s and tried to update to lower version %s', |
|
288 | + $appId, |
|
289 | + $currentVersion, |
|
290 | + $newVersion |
|
291 | + ) |
|
292 | + ); |
|
293 | + } |
|
294 | + |
|
295 | + $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
296 | + // Remove old app with the ID if existent |
|
297 | + OC_Helper::rmdirr($baseDir); |
|
298 | + // Move to app folder |
|
299 | + if(@mkdir($baseDir)) { |
|
300 | + $extractDir .= '/' . $folders[0]; |
|
301 | + OC_Helper::copyr($extractDir, $baseDir); |
|
302 | + } |
|
303 | + OC_Helper::copyr($extractDir, $baseDir); |
|
304 | + OC_Helper::rmdirr($extractDir); |
|
305 | + return; |
|
306 | + } else { |
|
307 | + throw new \Exception( |
|
308 | + sprintf( |
|
309 | + 'Could not extract app with ID %s to %s', |
|
310 | + $appId, |
|
311 | + $extractDir |
|
312 | + ) |
|
313 | + ); |
|
314 | + } |
|
315 | + } else { |
|
316 | + // Signature does not match |
|
317 | + throw new \Exception( |
|
318 | + sprintf( |
|
319 | + 'App with id %s has invalid signature', |
|
320 | + $appId |
|
321 | + ) |
|
322 | + ); |
|
323 | + } |
|
324 | + } |
|
325 | + } |
|
326 | + |
|
327 | + throw new \Exception( |
|
328 | + sprintf( |
|
329 | + 'Could not download app %s', |
|
330 | + $appId |
|
331 | + ) |
|
332 | + ); |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * Check if an update for the app is available |
|
337 | + * |
|
338 | + * @param string $appId |
|
339 | + * @param AppFetcher $appFetcher |
|
340 | + * @return string|false false or the version number of the update |
|
341 | + */ |
|
342 | + public static function isUpdateAvailable($appId, |
|
343 | + AppFetcher $appFetcher) { |
|
344 | + static $isInstanceReadyForUpdates = null; |
|
345 | + |
|
346 | + if ($isInstanceReadyForUpdates === null) { |
|
347 | + $installPath = OC_App::getInstallPath(); |
|
348 | + if ($installPath === false || $installPath === null) { |
|
349 | + $isInstanceReadyForUpdates = false; |
|
350 | + } else { |
|
351 | + $isInstanceReadyForUpdates = true; |
|
352 | + } |
|
353 | + } |
|
354 | + |
|
355 | + if ($isInstanceReadyForUpdates === false) { |
|
356 | + return false; |
|
357 | + } |
|
358 | + |
|
359 | + $apps = $appFetcher->get(); |
|
360 | + foreach($apps as $app) { |
|
361 | + if($app['id'] === $appId) { |
|
362 | + $currentVersion = OC_App::getAppVersion($appId); |
|
363 | + $newestVersion = $app['releases'][0]['version']; |
|
364 | + if (version_compare($newestVersion, $currentVersion, '>')) { |
|
365 | + return $newestVersion; |
|
366 | + } else { |
|
367 | + return false; |
|
368 | + } |
|
369 | + } |
|
370 | + } |
|
371 | + |
|
372 | + return false; |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * Check if app is already downloaded |
|
377 | + * @param string $name name of the application to remove |
|
378 | + * @return boolean |
|
379 | + * |
|
380 | + * The function will check if the app is already downloaded in the apps repository |
|
381 | + */ |
|
382 | + public function isDownloaded($name) { |
|
383 | + foreach(\OC::$APPSROOTS as $dir) { |
|
384 | + $dirToTest = $dir['path']; |
|
385 | + $dirToTest .= '/'; |
|
386 | + $dirToTest .= $name; |
|
387 | + $dirToTest .= '/'; |
|
388 | + |
|
389 | + if (is_dir($dirToTest)) { |
|
390 | + return true; |
|
391 | + } |
|
392 | + } |
|
393 | + |
|
394 | + return false; |
|
395 | + } |
|
396 | + |
|
397 | + /** |
|
398 | + * Removes an app |
|
399 | + * @param string $appId ID of the application to remove |
|
400 | + * @return boolean |
|
401 | + * |
|
402 | + * |
|
403 | + * This function works as follows |
|
404 | + * -# call uninstall repair steps |
|
405 | + * -# removing the files |
|
406 | + * |
|
407 | + * The function will not delete preferences, tables and the configuration, |
|
408 | + * this has to be done by the function oc_app_uninstall(). |
|
409 | + */ |
|
410 | + public function removeApp($appId) { |
|
411 | + if($this->isDownloaded( $appId )) { |
|
412 | + $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
413 | + OC_Helper::rmdirr($appDir); |
|
414 | + return true; |
|
415 | + }else{ |
|
416 | + \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
|
417 | + |
|
418 | + return false; |
|
419 | + } |
|
420 | + |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * Installs shipped apps |
|
425 | + * |
|
426 | + * This function installs all apps found in the 'apps' directory that should be enabled by default; |
|
427 | + * @param bool $softErrors When updating we ignore errors and simply log them, better to have a |
|
428 | + * working ownCloud at the end instead of an aborted update. |
|
429 | + * @return array Array of error messages (appid => Exception) |
|
430 | + */ |
|
431 | + public static function installShippedApps($softErrors = false) { |
|
432 | + $errors = []; |
|
433 | + foreach(\OC::$APPSROOTS as $app_dir) { |
|
434 | + if($dir = opendir( $app_dir['path'] )) { |
|
435 | + while( false !== ( $filename = readdir( $dir ))) { |
|
436 | + if( substr( $filename, 0, 1 ) != '.' and is_dir($app_dir['path']."/$filename") ) { |
|
437 | + if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
438 | + if(!Installer::isInstalled($filename)) { |
|
439 | + $info=OC_App::getAppInfo($filename); |
|
440 | + $enabled = isset($info['default_enable']); |
|
441 | + if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps())) |
|
442 | + && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') { |
|
443 | + if ($softErrors) { |
|
444 | + try { |
|
445 | + Installer::installShippedApp($filename); |
|
446 | + } catch (HintException $e) { |
|
447 | + if ($e->getPrevious() instanceof TableExistsException) { |
|
448 | + $errors[$filename] = $e; |
|
449 | + continue; |
|
450 | + } |
|
451 | + throw $e; |
|
452 | + } |
|
453 | + } else { |
|
454 | + Installer::installShippedApp($filename); |
|
455 | + } |
|
456 | + \OC::$server->getConfig()->setAppValue($filename, 'enabled', 'yes'); |
|
457 | + } |
|
458 | + } |
|
459 | + } |
|
460 | + } |
|
461 | + } |
|
462 | + closedir( $dir ); |
|
463 | + } |
|
464 | + } |
|
465 | + |
|
466 | + return $errors; |
|
467 | + } |
|
468 | + |
|
469 | + /** |
|
470 | + * install an app already placed in the app folder |
|
471 | + * @param string $app id of the app to install |
|
472 | + * @return integer |
|
473 | + */ |
|
474 | + public static function installShippedApp($app) { |
|
475 | + //install the database |
|
476 | + $appPath = OC_App::getAppPath($app); |
|
477 | + if(is_file("$appPath/appinfo/database.xml")) { |
|
478 | + try { |
|
479 | + OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
|
480 | + } catch (TableExistsException $e) { |
|
481 | + throw new HintException( |
|
482 | + 'Failed to enable app ' . $app, |
|
483 | + 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer">support channels</a>.', |
|
484 | + 0, $e |
|
485 | + ); |
|
486 | + } |
|
487 | + } |
|
488 | + |
|
489 | + //run appinfo/install.php |
|
490 | + \OC_App::registerAutoloading($app, $appPath); |
|
491 | + self::includeAppScript("$appPath/appinfo/install.php"); |
|
492 | + |
|
493 | + $info = OC_App::getAppInfo($app); |
|
494 | + if (is_null($info)) { |
|
495 | + return false; |
|
496 | + } |
|
497 | + \OC_App::setupBackgroundJobs($info['background-jobs']); |
|
498 | + |
|
499 | + OC_App::executeRepairSteps($app, $info['repair-steps']['install']); |
|
500 | + |
|
501 | + $config = \OC::$server->getConfig(); |
|
502 | + |
|
503 | + $config->setAppValue($app, 'installed_version', OC_App::getAppVersion($app)); |
|
504 | + if (array_key_exists('ocsid', $info)) { |
|
505 | + $config->setAppValue($app, 'ocsid', $info['ocsid']); |
|
506 | + } |
|
507 | + |
|
508 | + //set remote/public handlers |
|
509 | + foreach($info['remote'] as $name=>$path) { |
|
510 | + $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
|
511 | + } |
|
512 | + foreach($info['public'] as $name=>$path) { |
|
513 | + $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
|
514 | + } |
|
515 | + |
|
516 | + OC_App::setAppTypes($info['id']); |
|
517 | + |
|
518 | + if(isset($info['settings']) && is_array($info['settings'])) { |
|
519 | + // requires that autoloading was registered for the app, |
|
520 | + // as happens before running the install.php some lines above |
|
521 | + \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
|
522 | + } |
|
523 | + |
|
524 | + return $info['id']; |
|
525 | + } |
|
526 | + |
|
527 | + /** |
|
528 | + * check the code of an app with some static code checks |
|
529 | + * @param string $folder the folder of the app to check |
|
530 | + * @return boolean true for app is o.k. and false for app is not o.k. |
|
531 | + */ |
|
532 | + public static function checkCode($folder) { |
|
533 | + // is the code checker enabled? |
|
534 | + if(!\OC::$server->getConfig()->getSystemValue('appcodechecker', false)) { |
|
535 | + return true; |
|
536 | + } |
|
537 | + |
|
538 | + $codeChecker = new CodeChecker(new PrivateCheck(new EmptyCheck())); |
|
539 | + $errors = $codeChecker->analyseFolder(basename($folder), $folder); |
|
540 | + |
|
541 | + return empty($errors); |
|
542 | + } |
|
543 | + |
|
544 | + /** |
|
545 | + * @param string $script |
|
546 | + */ |
|
547 | + private static function includeAppScript($script) { |
|
548 | + if ( file_exists($script) ){ |
|
549 | + include $script; |
|
550 | + } |
|
551 | + } |
|
552 | 552 | } |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | */ |
95 | 95 | public function installApp($appId) { |
96 | 96 | $app = \OC_App::findAppInDirectories($appId); |
97 | - if($app === false) { |
|
97 | + if ($app === false) { |
|
98 | 98 | throw new \Exception('App not found in any app directory'); |
99 | 99 | } |
100 | 100 | |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | $info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true); |
103 | 103 | |
104 | 104 | //install the database |
105 | - if(is_file($basedir.'/appinfo/database.xml')) { |
|
105 | + if (is_file($basedir.'/appinfo/database.xml')) { |
|
106 | 106 | if (\OC::$server->getAppConfig()->getValue($info['id'], 'installed_version') === null) { |
107 | 107 | OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); |
108 | 108 | } else { |
@@ -113,8 +113,8 @@ discard block |
||
113 | 113 | \OC_App::setupBackgroundJobs($info['background-jobs']); |
114 | 114 | |
115 | 115 | //run appinfo/install.php |
116 | - if((!isset($data['noinstall']) or $data['noinstall']==false)) { |
|
117 | - self::includeAppScript($basedir . '/appinfo/install.php'); |
|
116 | + if ((!isset($data['noinstall']) or $data['noinstall'] == false)) { |
|
117 | + self::includeAppScript($basedir.'/appinfo/install.php'); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | $appData = OC_App::getAppInfo($appId); |
@@ -125,10 +125,10 @@ discard block |
||
125 | 125 | \OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no'); |
126 | 126 | |
127 | 127 | //set remote/public handlers |
128 | - foreach($info['remote'] as $name=>$path) { |
|
128 | + foreach ($info['remote'] as $name=>$path) { |
|
129 | 129 | \OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); |
130 | 130 | } |
131 | - foreach($info['public'] as $name=>$path) { |
|
131 | + foreach ($info['public'] as $name=>$path) { |
|
132 | 132 | \OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); |
133 | 133 | } |
134 | 134 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * |
145 | 145 | * Checks whether or not an app is installed, i.e. registered in apps table. |
146 | 146 | */ |
147 | - public static function isInstalled( $app ) { |
|
147 | + public static function isInstalled($app) { |
|
148 | 148 | return (\OC::$server->getConfig()->getAppValue($app, "installed_version", null) !== null); |
149 | 149 | } |
150 | 150 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | * @return bool |
156 | 156 | */ |
157 | 157 | public function updateAppstoreApp($appId) { |
158 | - if(self::isUpdateAvailable($appId, $this->appFetcher)) { |
|
158 | + if (self::isUpdateAvailable($appId, $this->appFetcher)) { |
|
159 | 159 | try { |
160 | 160 | $this->downloadApp($appId); |
161 | 161 | } catch (\Exception $e) { |
@@ -179,18 +179,18 @@ discard block |
||
179 | 179 | $appId = strtolower($appId); |
180 | 180 | |
181 | 181 | $apps = $this->appFetcher->get(); |
182 | - foreach($apps as $app) { |
|
183 | - if($app['id'] === $appId) { |
|
182 | + foreach ($apps as $app) { |
|
183 | + if ($app['id'] === $appId) { |
|
184 | 184 | // Load the certificate |
185 | 185 | $certificate = new X509(); |
186 | - $certificate->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
186 | + $certificate->loadCA(file_get_contents(__DIR__.'/../../resources/codesigning/root.crt')); |
|
187 | 187 | $loadedCertificate = $certificate->loadX509($app['certificate']); |
188 | 188 | |
189 | 189 | // Verify if the certificate has been revoked |
190 | 190 | $crl = new X509(); |
191 | - $crl->loadCA(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crt')); |
|
192 | - $crl->loadCRL(file_get_contents(__DIR__ . '/../../resources/codesigning/root.crl')); |
|
193 | - if($crl->validateSignature() !== true) { |
|
191 | + $crl->loadCA(file_get_contents(__DIR__.'/../../resources/codesigning/root.crt')); |
|
192 | + $crl->loadCRL(file_get_contents(__DIR__.'/../../resources/codesigning/root.crl')); |
|
193 | + if ($crl->validateSignature() !== true) { |
|
194 | 194 | throw new \Exception('Could not validate CRL signature'); |
195 | 195 | } |
196 | 196 | $csn = $loadedCertificate['tbsCertificate']['serialNumber']->toString(); |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | } |
206 | 206 | |
207 | 207 | // Verify if the certificate has been issued by the Nextcloud Code Authority CA |
208 | - if($certificate->validateSignature() !== true) { |
|
208 | + if ($certificate->validateSignature() !== true) { |
|
209 | 209 | throw new \Exception( |
210 | 210 | sprintf( |
211 | 211 | 'App with id %s has a certificate not issued by a trusted Code Signing Authority', |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | |
217 | 217 | // Verify if the certificate is issued for the requested app id |
218 | 218 | $certInfo = openssl_x509_parse($app['certificate']); |
219 | - if(!isset($certInfo['subject']['CN'])) { |
|
219 | + if (!isset($certInfo['subject']['CN'])) { |
|
220 | 220 | throw new \Exception( |
221 | 221 | sprintf( |
222 | 222 | 'App with id %s has a cert with no CN', |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | ) |
225 | 225 | ); |
226 | 226 | } |
227 | - if($certInfo['subject']['CN'] !== $appId) { |
|
227 | + if ($certInfo['subject']['CN'] !== $appId) { |
|
228 | 228 | throw new \Exception( |
229 | 229 | sprintf( |
230 | 230 | 'App with id %s has a cert issued to %s', |
@@ -241,21 +241,21 @@ discard block |
||
241 | 241 | |
242 | 242 | // Check if the signature actually matches the downloaded content |
243 | 243 | $certificate = openssl_get_publickey($app['certificate']); |
244 | - $verified = (bool)openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
244 | + $verified = (bool) openssl_verify(file_get_contents($tempFile), base64_decode($app['releases'][0]['signature']), $certificate, OPENSSL_ALGO_SHA512); |
|
245 | 245 | openssl_free_key($certificate); |
246 | 246 | |
247 | - if($verified === true) { |
|
247 | + if ($verified === true) { |
|
248 | 248 | // Seems to match, let's proceed |
249 | 249 | $extractDir = $this->tempManager->getTemporaryFolder(); |
250 | 250 | $archive = new TAR($tempFile); |
251 | 251 | |
252 | - if($archive) { |
|
252 | + if ($archive) { |
|
253 | 253 | $archive->extract($extractDir); |
254 | 254 | $allFiles = scandir($extractDir); |
255 | 255 | $folders = array_diff($allFiles, ['.', '..']); |
256 | 256 | $folders = array_values($folders); |
257 | 257 | |
258 | - if(count($folders) > 1) { |
|
258 | + if (count($folders) > 1) { |
|
259 | 259 | throw new \Exception( |
260 | 260 | sprintf( |
261 | 261 | 'Extracted app %s has more than 1 folder', |
@@ -266,22 +266,22 @@ discard block |
||
266 | 266 | |
267 | 267 | // Check if appinfo/info.xml has the same app ID as well |
268 | 268 | $loadEntities = libxml_disable_entity_loader(false); |
269 | - $xml = simplexml_load_file($extractDir . '/' . $folders[0] . '/appinfo/info.xml'); |
|
269 | + $xml = simplexml_load_file($extractDir.'/'.$folders[0].'/appinfo/info.xml'); |
|
270 | 270 | libxml_disable_entity_loader($loadEntities); |
271 | - if((string)$xml->id !== $appId) { |
|
271 | + if ((string) $xml->id !== $appId) { |
|
272 | 272 | throw new \Exception( |
273 | 273 | sprintf( |
274 | 274 | 'App for id %s has a wrong app ID in info.xml: %s', |
275 | 275 | $appId, |
276 | - (string)$xml->id |
|
276 | + (string) $xml->id |
|
277 | 277 | ) |
278 | 278 | ); |
279 | 279 | } |
280 | 280 | |
281 | 281 | // Check if the version is lower than before |
282 | 282 | $currentVersion = OC_App::getAppVersion($appId); |
283 | - $newVersion = (string)$xml->version; |
|
284 | - if(version_compare($currentVersion, $newVersion) === 1) { |
|
283 | + $newVersion = (string) $xml->version; |
|
284 | + if (version_compare($currentVersion, $newVersion) === 1) { |
|
285 | 285 | throw new \Exception( |
286 | 286 | sprintf( |
287 | 287 | 'App for id %s has version %s and tried to update to lower version %s', |
@@ -292,12 +292,12 @@ discard block |
||
292 | 292 | ); |
293 | 293 | } |
294 | 294 | |
295 | - $baseDir = OC_App::getInstallPath() . '/' . $appId; |
|
295 | + $baseDir = OC_App::getInstallPath().'/'.$appId; |
|
296 | 296 | // Remove old app with the ID if existent |
297 | 297 | OC_Helper::rmdirr($baseDir); |
298 | 298 | // Move to app folder |
299 | - if(@mkdir($baseDir)) { |
|
300 | - $extractDir .= '/' . $folders[0]; |
|
299 | + if (@mkdir($baseDir)) { |
|
300 | + $extractDir .= '/'.$folders[0]; |
|
301 | 301 | OC_Helper::copyr($extractDir, $baseDir); |
302 | 302 | } |
303 | 303 | OC_Helper::copyr($extractDir, $baseDir); |
@@ -357,8 +357,8 @@ discard block |
||
357 | 357 | } |
358 | 358 | |
359 | 359 | $apps = $appFetcher->get(); |
360 | - foreach($apps as $app) { |
|
361 | - if($app['id'] === $appId) { |
|
360 | + foreach ($apps as $app) { |
|
361 | + if ($app['id'] === $appId) { |
|
362 | 362 | $currentVersion = OC_App::getAppVersion($appId); |
363 | 363 | $newestVersion = $app['releases'][0]['version']; |
364 | 364 | if (version_compare($newestVersion, $currentVersion, '>')) { |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | * The function will check if the app is already downloaded in the apps repository |
381 | 381 | */ |
382 | 382 | public function isDownloaded($name) { |
383 | - foreach(\OC::$APPSROOTS as $dir) { |
|
383 | + foreach (\OC::$APPSROOTS as $dir) { |
|
384 | 384 | $dirToTest = $dir['path']; |
385 | 385 | $dirToTest .= '/'; |
386 | 386 | $dirToTest .= $name; |
@@ -408,11 +408,11 @@ discard block |
||
408 | 408 | * this has to be done by the function oc_app_uninstall(). |
409 | 409 | */ |
410 | 410 | public function removeApp($appId) { |
411 | - if($this->isDownloaded( $appId )) { |
|
412 | - $appDir = OC_App::getInstallPath() . '/' . $appId; |
|
411 | + if ($this->isDownloaded($appId)) { |
|
412 | + $appDir = OC_App::getInstallPath().'/'.$appId; |
|
413 | 413 | OC_Helper::rmdirr($appDir); |
414 | 414 | return true; |
415 | - }else{ |
|
415 | + } else { |
|
416 | 416 | \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
417 | 417 | |
418 | 418 | return false; |
@@ -430,13 +430,13 @@ discard block |
||
430 | 430 | */ |
431 | 431 | public static function installShippedApps($softErrors = false) { |
432 | 432 | $errors = []; |
433 | - foreach(\OC::$APPSROOTS as $app_dir) { |
|
434 | - if($dir = opendir( $app_dir['path'] )) { |
|
435 | - while( false !== ( $filename = readdir( $dir ))) { |
|
436 | - if( substr( $filename, 0, 1 ) != '.' and is_dir($app_dir['path']."/$filename") ) { |
|
437 | - if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) { |
|
438 | - if(!Installer::isInstalled($filename)) { |
|
439 | - $info=OC_App::getAppInfo($filename); |
|
433 | + foreach (\OC::$APPSROOTS as $app_dir) { |
|
434 | + if ($dir = opendir($app_dir['path'])) { |
|
435 | + while (false !== ($filename = readdir($dir))) { |
|
436 | + if (substr($filename, 0, 1) != '.' and is_dir($app_dir['path']."/$filename")) { |
|
437 | + if (file_exists($app_dir['path']."/$filename/appinfo/info.xml")) { |
|
438 | + if (!Installer::isInstalled($filename)) { |
|
439 | + $info = OC_App::getAppInfo($filename); |
|
440 | 440 | $enabled = isset($info['default_enable']); |
441 | 441 | if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps())) |
442 | 442 | && \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') { |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | } |
460 | 460 | } |
461 | 461 | } |
462 | - closedir( $dir ); |
|
462 | + closedir($dir); |
|
463 | 463 | } |
464 | 464 | } |
465 | 465 | |
@@ -474,12 +474,12 @@ discard block |
||
474 | 474 | public static function installShippedApp($app) { |
475 | 475 | //install the database |
476 | 476 | $appPath = OC_App::getAppPath($app); |
477 | - if(is_file("$appPath/appinfo/database.xml")) { |
|
477 | + if (is_file("$appPath/appinfo/database.xml")) { |
|
478 | 478 | try { |
479 | 479 | OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); |
480 | 480 | } catch (TableExistsException $e) { |
481 | 481 | throw new HintException( |
482 | - 'Failed to enable app ' . $app, |
|
482 | + 'Failed to enable app '.$app, |
|
483 | 483 | 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer">support channels</a>.', |
484 | 484 | 0, $e |
485 | 485 | ); |
@@ -506,16 +506,16 @@ discard block |
||
506 | 506 | } |
507 | 507 | |
508 | 508 | //set remote/public handlers |
509 | - foreach($info['remote'] as $name=>$path) { |
|
509 | + foreach ($info['remote'] as $name=>$path) { |
|
510 | 510 | $config->setAppValue('core', 'remote_'.$name, $app.'/'.$path); |
511 | 511 | } |
512 | - foreach($info['public'] as $name=>$path) { |
|
512 | + foreach ($info['public'] as $name=>$path) { |
|
513 | 513 | $config->setAppValue('core', 'public_'.$name, $app.'/'.$path); |
514 | 514 | } |
515 | 515 | |
516 | 516 | OC_App::setAppTypes($info['id']); |
517 | 517 | |
518 | - if(isset($info['settings']) && is_array($info['settings'])) { |
|
518 | + if (isset($info['settings']) && is_array($info['settings'])) { |
|
519 | 519 | // requires that autoloading was registered for the app, |
520 | 520 | // as happens before running the install.php some lines above |
521 | 521 | \OC::$server->getSettingsManager()->setupSettings($info['settings']); |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | */ |
532 | 532 | public static function checkCode($folder) { |
533 | 533 | // is the code checker enabled? |
534 | - if(!\OC::$server->getConfig()->getSystemValue('appcodechecker', false)) { |
|
534 | + if (!\OC::$server->getConfig()->getSystemValue('appcodechecker', false)) { |
|
535 | 535 | return true; |
536 | 536 | } |
537 | 537 | |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | * @param string $script |
546 | 546 | */ |
547 | 547 | private static function includeAppScript($script) { |
548 | - if ( file_exists($script) ){ |
|
548 | + if (file_exists($script)) { |
|
549 | 549 | include $script; |
550 | 550 | } |
551 | 551 | } |
@@ -412,7 +412,7 @@ |
||
412 | 412 | $appDir = OC_App::getInstallPath() . '/' . $appId; |
413 | 413 | OC_Helper::rmdirr($appDir); |
414 | 414 | return true; |
415 | - }else{ |
|
415 | + } else{ |
|
416 | 416 | \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); |
417 | 417 | |
418 | 418 | return false; |