@@ -59,9 +59,9 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function __construct($appName, |
61 | 61 | IRequest $request, |
62 | - $corsMethods='PUT, POST, GET, DELETE, PATCH', |
|
63 | - $corsAllowedHeaders='Authorization, Content-Type, Accept', |
|
64 | - $corsMaxAge=1728000){ |
|
62 | + $corsMethods = 'PUT, POST, GET, DELETE, PATCH', |
|
63 | + $corsAllowedHeaders = 'Authorization, Content-Type, Accept', |
|
64 | + $corsMaxAge = 1728000) { |
|
65 | 65 | parent::__construct($appName, $request); |
66 | 66 | $this->corsMethods = $corsMethods; |
67 | 67 | $this->corsAllowedHeaders = $corsAllowedHeaders; |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @since 7.0.0 |
80 | 80 | */ |
81 | 81 | public function preflightedCors() { |
82 | - if(isset($this->request->server['HTTP_ORIGIN'])) { |
|
82 | + if (isset($this->request->server['HTTP_ORIGIN'])) { |
|
83 | 83 | $origin = $this->request->server['HTTP_ORIGIN']; |
84 | 84 | } else { |
85 | 85 | $origin = '*'; |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | $response = new Response(); |
89 | 89 | $response->addHeader('Access-Control-Allow-Origin', $origin); |
90 | 90 | $response->addHeader('Access-Control-Allow-Methods', $this->corsMethods); |
91 | - $response->addHeader('Access-Control-Max-Age', (string)$this->corsMaxAge); |
|
91 | + $response->addHeader('Access-Control-Max-Age', (string) $this->corsMaxAge); |
|
92 | 92 | $response->addHeader('Access-Control-Allow-Headers', $this->corsAllowedHeaders); |
93 | 93 | $response->addHeader('Access-Control-Allow-Credentials', 'false'); |
94 | 94 | return $response; |
@@ -47,8 +47,8 @@ discard block |
||
47 | 47 | * @param array $headers additional key value based headers |
48 | 48 | * @since 8.1.0 |
49 | 49 | */ |
50 | - public function __construct($data='', $statusCode=Http::STATUS_OK, |
|
51 | - $headers=[]) { |
|
50 | + public function __construct($data = '', $statusCode = Http::STATUS_OK, |
|
51 | + $headers = []) { |
|
52 | 52 | parent::__construct(); |
53 | 53 | |
54 | 54 | $this->data = $data; |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @return DataDisplayResponse Reference to this object |
74 | 74 | * @since 8.1.0 |
75 | 75 | */ |
76 | - public function setData($data){ |
|
76 | + public function setData($data) { |
|
77 | 77 | $this->data = $data; |
78 | 78 | |
79 | 79 | return $this; |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @return string the data |
86 | 86 | * @since 8.1.0 |
87 | 87 | */ |
88 | - public function getData(){ |
|
88 | + public function getData() { |
|
89 | 89 | return $this->data; |
90 | 90 | } |
91 | 91 |
@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | */ |
41 | 41 | class TemplateResponse extends Response { |
42 | 42 | |
43 | - const EVENT_LOAD_ADDITIONAL_SCRIPTS = self::class . '::loadAdditionalScripts'; |
|
44 | - const EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN = self::class . '::loadAdditionalScriptsLoggedIn'; |
|
43 | + const EVENT_LOAD_ADDITIONAL_SCRIPTS = self::class.'::loadAdditionalScripts'; |
|
44 | + const EVENT_LOAD_ADDITIONAL_SCRIPTS_LOGGEDIN = self::class.'::loadAdditionalScriptsLoggedIn'; |
|
45 | 45 | |
46 | 46 | /** |
47 | 47 | * name of the template |
@@ -76,8 +76,8 @@ discard block |
||
76 | 76 | * @param string $renderAs how the page should be rendered, defaults to user |
77 | 77 | * @since 6.0.0 - parameters $params and $renderAs were added in 7.0.0 |
78 | 78 | */ |
79 | - public function __construct($appName, $templateName, array $params=[], |
|
80 | - $renderAs='user') { |
|
79 | + public function __construct($appName, $templateName, array $params = [], |
|
80 | + $renderAs = 'user') { |
|
81 | 81 | parent::__construct(); |
82 | 82 | |
83 | 83 | $this->templateName = $templateName; |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * @return TemplateResponse Reference to this object |
98 | 98 | * @since 6.0.0 - return value was added in 7.0.0 |
99 | 99 | */ |
100 | - public function setParams(array $params){ |
|
100 | + public function setParams(array $params) { |
|
101 | 101 | $this->params = $params; |
102 | 102 | |
103 | 103 | return $this; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @return array the params |
110 | 110 | * @since 6.0.0 |
111 | 111 | */ |
112 | - public function getParams(){ |
|
112 | + public function getParams() { |
|
113 | 113 | return $this->params; |
114 | 114 | } |
115 | 115 | |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @return string the name of the used template |
120 | 120 | * @since 6.0.0 |
121 | 121 | */ |
122 | - public function getTemplateName(){ |
|
122 | + public function getTemplateName() { |
|
123 | 123 | return $this->templateName; |
124 | 124 | } |
125 | 125 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | * @return TemplateResponse Reference to this object |
134 | 134 | * @since 6.0.0 - return value was added in 7.0.0 |
135 | 135 | */ |
136 | - public function renderAs($renderAs){ |
|
136 | + public function renderAs($renderAs) { |
|
137 | 137 | $this->renderAs = $renderAs; |
138 | 138 | |
139 | 139 | return $this; |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | * @return string the renderAs value |
146 | 146 | * @since 6.0.0 |
147 | 147 | */ |
148 | - public function getRenderAs(){ |
|
148 | + public function getRenderAs() { |
|
149 | 149 | return $this->renderAs; |
150 | 150 | } |
151 | 151 | |
@@ -155,13 +155,13 @@ discard block |
||
155 | 155 | * @return string the rendered html |
156 | 156 | * @since 6.0.0 |
157 | 157 | */ |
158 | - public function render(){ |
|
158 | + public function render() { |
|
159 | 159 | // \OCP\Template needs an empty string instead of 'blank' for an unwrapped response |
160 | 160 | $renderAs = $this->renderAs === 'blank' ? '' : $this->renderAs; |
161 | 161 | |
162 | 162 | $template = new \OCP\Template($this->appName, $this->templateName, $renderAs); |
163 | 163 | |
164 | - foreach($this->params as $key => $value){ |
|
164 | + foreach ($this->params as $key => $value) { |
|
165 | 165 | $template->assign($key, $value); |
166 | 166 | } |
167 | 167 |
@@ -106,8 +106,8 @@ discard block |
||
106 | 106 | * @since 6.0.0 - return value was added in 7.0.0 |
107 | 107 | */ |
108 | 108 | public function cacheFor(int $cacheSeconds) { |
109 | - if($cacheSeconds > 0) { |
|
110 | - $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate'); |
|
109 | + if ($cacheSeconds > 0) { |
|
110 | + $this->addHeader('Cache-Control', 'max-age='.$cacheSeconds.', must-revalidate'); |
|
111 | 111 | |
112 | 112 | // Old scool prama caching |
113 | 113 | $this->addHeader('Pragma', 'public'); |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | * @since 8.0.0 |
174 | 174 | */ |
175 | 175 | public function invalidateCookies(array $cookieNames) { |
176 | - foreach($cookieNames as $cookieName) { |
|
176 | + foreach ($cookieNames as $cookieName) { |
|
177 | 177 | $this->invalidateCookie($cookieName); |
178 | 178 | } |
179 | 179 | return $this; |
@@ -197,11 +197,11 @@ discard block |
||
197 | 197 | * @since 6.0.0 - return value was added in 7.0.0 |
198 | 198 | */ |
199 | 199 | public function addHeader($name, $value) { |
200 | - $name = trim($name); // always remove leading and trailing whitespace |
|
200 | + $name = trim($name); // always remove leading and trailing whitespace |
|
201 | 201 | // to be able to reliably check for security |
202 | 202 | // headers |
203 | 203 | |
204 | - if(is_null($value)) { |
|
204 | + if (is_null($value)) { |
|
205 | 205 | unset($this->headers[$name]); |
206 | 206 | } else { |
207 | 207 | $this->headers[$name] = $value; |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | public function getHeaders() { |
233 | 233 | $mergeWith = []; |
234 | 234 | |
235 | - if($this->lastModified) { |
|
235 | + if ($this->lastModified) { |
|
236 | 236 | $mergeWith['Last-Modified'] = |
237 | 237 | $this->lastModified->format(\DateTime::RFC2822); |
238 | 238 | } |
@@ -240,8 +240,8 @@ discard block |
||
240 | 240 | $this->headers['Content-Security-Policy'] = $this->getContentSecurityPolicy()->buildPolicy(); |
241 | 241 | $this->headers['Feature-Policy'] = $this->getFeaturePolicy()->buildPolicy(); |
242 | 242 | |
243 | - if($this->ETag) { |
|
244 | - $mergeWith['ETag'] = '"' . $this->ETag . '"'; |
|
243 | + if ($this->ETag) { |
|
244 | + $mergeWith['ETag'] = '"'.$this->ETag.'"'; |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | return array_merge($mergeWith, $this->headers); |
@@ -52,8 +52,8 @@ discard block |
||
52 | 52 | * @param array $headers additional key value based headers |
53 | 53 | * @since 8.0.0 |
54 | 54 | */ |
55 | - public function __construct($data=[], $statusCode=Http::STATUS_OK, |
|
56 | - array $headers=[]) { |
|
55 | + public function __construct($data = [], $statusCode = Http::STATUS_OK, |
|
56 | + array $headers = []) { |
|
57 | 57 | parent::__construct(); |
58 | 58 | |
59 | 59 | $this->data = $data; |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @return DataResponse Reference to this object |
69 | 69 | * @since 8.0.0 |
70 | 70 | */ |
71 | - public function setData($data){ |
|
71 | + public function setData($data) { |
|
72 | 72 | $this->data = $data; |
73 | 73 | |
74 | 74 | return $this; |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * @return array the data |
81 | 81 | * @since 8.0.0 |
82 | 82 | */ |
83 | - public function getData(){ |
|
83 | + public function getData() { |
|
84 | 84 | return $this->data; |
85 | 85 | } |
86 | 86 |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | } |
137 | 137 | $this->tags = $this->mapper->loadTags($this->owners, $this->type); |
138 | 138 | |
139 | - if(count($defaultTags) > 0 && count($this->tags) === 0) { |
|
139 | + if (count($defaultTags) > 0 && count($this->tags) === 0) { |
|
140 | 140 | $this->addMultiple($defaultTags, true); |
141 | 141 | } |
142 | 142 | } |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | * @return array |
178 | 178 | */ |
179 | 179 | public function getTags() { |
180 | - if(!count($this->tags)) { |
|
180 | + if (!count($this->tags)) { |
|
181 | 181 | return []; |
182 | 182 | } |
183 | 183 | |
@@ -186,8 +186,8 @@ discard block |
||
186 | 186 | }); |
187 | 187 | $tagMap = []; |
188 | 188 | |
189 | - foreach($this->tags as $tag) { |
|
190 | - if($tag->getName() !== ITags::TAG_FAVORITE) { |
|
189 | + foreach ($this->tags as $tag) { |
|
190 | + if ($tag->getName() !== ITags::TAG_FAVORITE) { |
|
191 | 191 | $tagMap[] = $this->tagMap($tag); |
192 | 192 | } |
193 | 193 | } |
@@ -225,25 +225,25 @@ discard block |
||
225 | 225 | $chunks = array_chunk($objIds, 900, false); |
226 | 226 | foreach ($chunks as $chunk) { |
227 | 227 | $result = $conn->executeQuery( |
228 | - 'SELECT `category`, `categoryid`, `objid` ' . |
|
229 | - 'FROM `' . self::RELATION_TABLE . '` r, `' . self::TAG_TABLE . '` ' . |
|
228 | + 'SELECT `category`, `categoryid`, `objid` '. |
|
229 | + 'FROM `'.self::RELATION_TABLE.'` r, `'.self::TAG_TABLE.'` '. |
|
230 | 230 | 'WHERE `categoryid` = `id` AND `uid` = ? AND r.`type` = ? AND `objid` IN (?)', |
231 | 231 | [$this->user, $this->type, $chunk], |
232 | 232 | [null, null, IQueryBuilder::PARAM_INT_ARRAY] |
233 | 233 | ); |
234 | 234 | while ($row = $result->fetch()) { |
235 | - $objId = (int)$row['objid']; |
|
235 | + $objId = (int) $row['objid']; |
|
236 | 236 | if (!isset($entries[$objId])) { |
237 | 237 | $entries[$objId] = []; |
238 | 238 | } |
239 | 239 | $entries[$objId][] = $row['category']; |
240 | 240 | } |
241 | 241 | if ($result === null) { |
242 | - \OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OC::$server->getDatabaseConnection()->getError(), ILogger::ERROR); |
|
242 | + \OCP\Util::writeLog('core', __METHOD__.'DB error: '.\OC::$server->getDatabaseConnection()->getError(), ILogger::ERROR); |
|
243 | 243 | return false; |
244 | 244 | } |
245 | 245 | } |
246 | - } catch(\Exception $e) { |
|
246 | + } catch (\Exception $e) { |
|
247 | 247 | \OC::$server->getLogger()->logException($e, [ |
248 | 248 | 'message' => __METHOD__, |
249 | 249 | 'level' => ILogger::ERROR, |
@@ -267,18 +267,18 @@ discard block |
||
267 | 267 | public function getIdsForTag($tag) { |
268 | 268 | $result = null; |
269 | 269 | $tagId = false; |
270 | - if(is_numeric($tag)) { |
|
270 | + if (is_numeric($tag)) { |
|
271 | 271 | $tagId = $tag; |
272 | - } elseif(is_string($tag)) { |
|
272 | + } elseif (is_string($tag)) { |
|
273 | 273 | $tag = trim($tag); |
274 | - if($tag === '') { |
|
274 | + if ($tag === '') { |
|
275 | 275 | \OCP\Util::writeLog('core', __METHOD__.', Cannot use empty tag names', ILogger::DEBUG); |
276 | 276 | return false; |
277 | 277 | } |
278 | 278 | $tagId = $this->getTagId($tag); |
279 | 279 | } |
280 | 280 | |
281 | - if($tagId === false) { |
|
281 | + if ($tagId === false) { |
|
282 | 282 | $l10n = \OC::$server->getL10N('core'); |
283 | 283 | throw new \Exception( |
284 | 284 | $l10n->t('Could not find category "%s"', [$tag]) |
@@ -286,17 +286,17 @@ discard block |
||
286 | 286 | } |
287 | 287 | |
288 | 288 | $ids = []; |
289 | - $sql = 'SELECT `objid` FROM `' . self::RELATION_TABLE |
|
289 | + $sql = 'SELECT `objid` FROM `'.self::RELATION_TABLE |
|
290 | 290 | . '` WHERE `categoryid` = ?'; |
291 | 291 | |
292 | 292 | try { |
293 | 293 | $stmt = \OC_DB::prepare($sql); |
294 | 294 | $result = $stmt->execute([$tagId]); |
295 | 295 | if ($result === null) { |
296 | - \OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OC::$server->getDatabaseConnection()->getError(), ILogger::ERROR); |
|
296 | + \OCP\Util::writeLog('core', __METHOD__.'DB error: '.\OC::$server->getDatabaseConnection()->getError(), ILogger::ERROR); |
|
297 | 297 | return false; |
298 | 298 | } |
299 | - } catch(\Exception $e) { |
|
299 | + } catch (\Exception $e) { |
|
300 | 300 | \OC::$server->getLogger()->logException($e, [ |
301 | 301 | 'message' => __METHOD__, |
302 | 302 | 'level' => ILogger::ERROR, |
@@ -305,9 +305,9 @@ discard block |
||
305 | 305 | return false; |
306 | 306 | } |
307 | 307 | |
308 | - if(!is_null($result)) { |
|
309 | - while( $row = $result->fetchRow()) { |
|
310 | - $id = (int)$row['objid']; |
|
308 | + if (!is_null($result)) { |
|
309 | + while ($row = $result->fetchRow()) { |
|
310 | + $id = (int) $row['objid']; |
|
311 | 311 | |
312 | 312 | if ($this->includeShared) { |
313 | 313 | // We have to check if we are really allowed to access the |
@@ -361,19 +361,19 @@ discard block |
||
361 | 361 | public function add($name) { |
362 | 362 | $name = trim($name); |
363 | 363 | |
364 | - if($name === '') { |
|
364 | + if ($name === '') { |
|
365 | 365 | \OCP\Util::writeLog('core', __METHOD__.', Cannot add an empty tag', ILogger::DEBUG); |
366 | 366 | return false; |
367 | 367 | } |
368 | - if($this->userHasTag($name, $this->user)) { |
|
369 | - \OCP\Util::writeLog('core', __METHOD__.', name: ' . $name. ' exists already', ILogger::DEBUG); |
|
368 | + if ($this->userHasTag($name, $this->user)) { |
|
369 | + \OCP\Util::writeLog('core', __METHOD__.', name: '.$name.' exists already', ILogger::DEBUG); |
|
370 | 370 | return false; |
371 | 371 | } |
372 | 372 | try { |
373 | 373 | $tag = new Tag($this->user, $this->type, $name); |
374 | 374 | $tag = $this->mapper->insert($tag); |
375 | 375 | $this->tags[] = $tag; |
376 | - } catch(\Exception $e) { |
|
376 | + } catch (\Exception $e) { |
|
377 | 377 | \OC::$server->getLogger()->logException($e, [ |
378 | 378 | 'message' => __METHOD__, |
379 | 379 | 'level' => ILogger::ERROR, |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | ]); |
382 | 382 | return false; |
383 | 383 | } |
384 | - \OCP\Util::writeLog('core', __METHOD__.', id: ' . $tag->getId(), ILogger::DEBUG); |
|
384 | + \OCP\Util::writeLog('core', __METHOD__.', id: '.$tag->getId(), ILogger::DEBUG); |
|
385 | 385 | return $tag->getId(); |
386 | 386 | } |
387 | 387 | |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | $from = trim($from); |
397 | 397 | $to = trim($to); |
398 | 398 | |
399 | - if($to === '' || $from === '') { |
|
399 | + if ($to === '' || $from === '') { |
|
400 | 400 | \OCP\Util::writeLog('core', __METHOD__.', Cannot use empty tag names', ILogger::DEBUG); |
401 | 401 | return false; |
402 | 402 | } |
@@ -406,21 +406,21 @@ discard block |
||
406 | 406 | } else { |
407 | 407 | $key = $this->getTagByName($from); |
408 | 408 | } |
409 | - if($key === false) { |
|
410 | - \OCP\Util::writeLog('core', __METHOD__.', tag: ' . $from. ' does not exist', ILogger::DEBUG); |
|
409 | + if ($key === false) { |
|
410 | + \OCP\Util::writeLog('core', __METHOD__.', tag: '.$from.' does not exist', ILogger::DEBUG); |
|
411 | 411 | return false; |
412 | 412 | } |
413 | 413 | $tag = $this->tags[$key]; |
414 | 414 | |
415 | - if($this->userHasTag($to, $tag->getOwner())) { |
|
416 | - \OCP\Util::writeLog('core', __METHOD__.', A tag named ' . $to. ' already exists for user ' . $tag->getOwner() . '.', ILogger::DEBUG); |
|
415 | + if ($this->userHasTag($to, $tag->getOwner())) { |
|
416 | + \OCP\Util::writeLog('core', __METHOD__.', A tag named '.$to.' already exists for user '.$tag->getOwner().'.', ILogger::DEBUG); |
|
417 | 417 | return false; |
418 | 418 | } |
419 | 419 | |
420 | 420 | try { |
421 | 421 | $tag->setName($to); |
422 | 422 | $this->tags[$key] = $this->mapper->update($tag); |
423 | - } catch(\Exception $e) { |
|
423 | + } catch (\Exception $e) { |
|
424 | 424 | \OC::$server->getLogger()->logException($e, [ |
425 | 425 | 'message' => __METHOD__, |
426 | 426 | 'level' => ILogger::ERROR, |
@@ -440,25 +440,25 @@ discard block |
||
440 | 440 | * @param int|null $id int Optional object id to add to this|these tag(s) |
441 | 441 | * @return bool Returns false on error. |
442 | 442 | */ |
443 | - public function addMultiple($names, $sync=false, $id = null) { |
|
444 | - if(!is_array($names)) { |
|
443 | + public function addMultiple($names, $sync = false, $id = null) { |
|
444 | + if (!is_array($names)) { |
|
445 | 445 | $names = [$names]; |
446 | 446 | } |
447 | 447 | $names = array_map('trim', $names); |
448 | 448 | array_filter($names); |
449 | 449 | |
450 | 450 | $newones = []; |
451 | - foreach($names as $name) { |
|
452 | - if(!$this->hasTag($name) && $name !== '') { |
|
451 | + foreach ($names as $name) { |
|
452 | + if (!$this->hasTag($name) && $name !== '') { |
|
453 | 453 | $newones[] = new Tag($this->user, $this->type, $name); |
454 | 454 | } |
455 | - if(!is_null($id) ) { |
|
455 | + if (!is_null($id)) { |
|
456 | 456 | // Insert $objectid, $categoryid pairs if not exist. |
457 | 457 | self::$relations[] = ['objid' => $id, 'tag' => $name]; |
458 | 458 | } |
459 | 459 | } |
460 | 460 | $this->tags = array_merge($this->tags, $newones); |
461 | - if($sync === true) { |
|
461 | + if ($sync === true) { |
|
462 | 462 | $this->save(); |
463 | 463 | } |
464 | 464 | |
@@ -469,13 +469,13 @@ discard block |
||
469 | 469 | * Save the list of tags and their object relations |
470 | 470 | */ |
471 | 471 | protected function save() { |
472 | - if(is_array($this->tags)) { |
|
473 | - foreach($this->tags as $tag) { |
|
472 | + if (is_array($this->tags)) { |
|
473 | + foreach ($this->tags as $tag) { |
|
474 | 474 | try { |
475 | 475 | if (!$this->mapper->tagExists($tag)) { |
476 | 476 | $this->mapper->insert($tag); |
477 | 477 | } |
478 | - } catch(\Exception $e) { |
|
478 | + } catch (\Exception $e) { |
|
479 | 479 | \OC::$server->getLogger()->logException($e, [ |
480 | 480 | 'message' => __METHOD__, |
481 | 481 | 'level' => ILogger::ERROR, |
@@ -486,7 +486,7 @@ discard block |
||
486 | 486 | |
487 | 487 | // reload tags to get the proper ids. |
488 | 488 | $this->tags = $this->mapper->loadTags($this->owners, $this->type); |
489 | - \OCP\Util::writeLog('core', __METHOD__.', tags: ' . print_r($this->tags, true), |
|
489 | + \OCP\Util::writeLog('core', __METHOD__.', tags: '.print_r($this->tags, true), |
|
490 | 490 | ILogger::DEBUG); |
491 | 491 | // Loop through temporarily cached objectid/tagname pairs |
492 | 492 | // and save relations. |
@@ -494,10 +494,10 @@ discard block |
||
494 | 494 | // For some reason this is needed or array_search(i) will return 0..? |
495 | 495 | ksort($tags); |
496 | 496 | $dbConnection = \OC::$server->getDatabaseConnection(); |
497 | - foreach(self::$relations as $relation) { |
|
497 | + foreach (self::$relations as $relation) { |
|
498 | 498 | $tagId = $this->getTagId($relation['tag']); |
499 | - \OCP\Util::writeLog('core', __METHOD__ . 'catid, ' . $relation['tag'] . ' ' . $tagId, ILogger::DEBUG); |
|
500 | - if($tagId) { |
|
499 | + \OCP\Util::writeLog('core', __METHOD__.'catid, '.$relation['tag'].' '.$tagId, ILogger::DEBUG); |
|
500 | + if ($tagId) { |
|
501 | 501 | try { |
502 | 502 | $dbConnection->insertIfNotExist(self::RELATION_TABLE, |
503 | 503 | [ |
@@ -505,7 +505,7 @@ discard block |
||
505 | 505 | 'categoryid' => $tagId, |
506 | 506 | 'type' => $this->type, |
507 | 507 | ]); |
508 | - } catch(\Exception $e) { |
|
508 | + } catch (\Exception $e) { |
|
509 | 509 | \OC::$server->getLogger()->logException($e, [ |
510 | 510 | 'message' => __METHOD__, |
511 | 511 | 'level' => ILogger::ERROR, |
@@ -532,13 +532,13 @@ discard block |
||
532 | 532 | // Find all objectid/tagId pairs. |
533 | 533 | $result = null; |
534 | 534 | try { |
535 | - $stmt = \OC_DB::prepare('SELECT `id` FROM `' . self::TAG_TABLE . '` ' |
|
535 | + $stmt = \OC_DB::prepare('SELECT `id` FROM `'.self::TAG_TABLE.'` ' |
|
536 | 536 | . 'WHERE `uid` = ?'); |
537 | 537 | $result = $stmt->execute([$arguments['uid']]); |
538 | 538 | if ($result === null) { |
539 | - \OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OC::$server->getDatabaseConnection()->getError(), ILogger::ERROR); |
|
539 | + \OCP\Util::writeLog('core', __METHOD__.'DB error: '.\OC::$server->getDatabaseConnection()->getError(), ILogger::ERROR); |
|
540 | 540 | } |
541 | - } catch(\Exception $e) { |
|
541 | + } catch (\Exception $e) { |
|
542 | 542 | \OC::$server->getLogger()->logException($e, [ |
543 | 543 | 'message' => __METHOD__, |
544 | 544 | 'level' => ILogger::ERROR, |
@@ -546,14 +546,14 @@ discard block |
||
546 | 546 | ]); |
547 | 547 | } |
548 | 548 | |
549 | - if(!is_null($result)) { |
|
549 | + if (!is_null($result)) { |
|
550 | 550 | try { |
551 | - $stmt = \OC_DB::prepare('DELETE FROM `' . self::RELATION_TABLE . '` ' |
|
551 | + $stmt = \OC_DB::prepare('DELETE FROM `'.self::RELATION_TABLE.'` ' |
|
552 | 552 | . 'WHERE `categoryid` = ?'); |
553 | - while( $row = $result->fetchRow()) { |
|
553 | + while ($row = $result->fetchRow()) { |
|
554 | 554 | try { |
555 | 555 | $stmt->execute([$row['id']]); |
556 | - } catch(\Exception $e) { |
|
556 | + } catch (\Exception $e) { |
|
557 | 557 | \OC::$server->getLogger()->logException($e, [ |
558 | 558 | 'message' => __METHOD__, |
559 | 559 | 'level' => ILogger::ERROR, |
@@ -561,7 +561,7 @@ discard block |
||
561 | 561 | ]); |
562 | 562 | } |
563 | 563 | } |
564 | - } catch(\Exception $e) { |
|
564 | + } catch (\Exception $e) { |
|
565 | 565 | \OC::$server->getLogger()->logException($e, [ |
566 | 566 | 'message' => __METHOD__, |
567 | 567 | 'level' => ILogger::ERROR, |
@@ -570,13 +570,13 @@ discard block |
||
570 | 570 | } |
571 | 571 | } |
572 | 572 | try { |
573 | - $stmt = \OC_DB::prepare('DELETE FROM `' . self::TAG_TABLE . '` ' |
|
573 | + $stmt = \OC_DB::prepare('DELETE FROM `'.self::TAG_TABLE.'` ' |
|
574 | 574 | . 'WHERE `uid` = ?'); |
575 | 575 | $result = $stmt->execute([$arguments['uid']]); |
576 | 576 | if ($result === null) { |
577 | - \OCP\Util::writeLog('core', __METHOD__. ', DB error: ' . \OC::$server->getDatabaseConnection()->getError(), ILogger::ERROR); |
|
577 | + \OCP\Util::writeLog('core', __METHOD__.', DB error: '.\OC::$server->getDatabaseConnection()->getError(), ILogger::ERROR); |
|
578 | 578 | } |
579 | - } catch(\Exception $e) { |
|
579 | + } catch (\Exception $e) { |
|
580 | 580 | \OC::$server->getLogger()->logException($e, [ |
581 | 581 | 'message' => __METHOD__, |
582 | 582 | 'level' => ILogger::ERROR, |
@@ -592,23 +592,23 @@ discard block |
||
592 | 592 | * @return boolean Returns false on error. |
593 | 593 | */ |
594 | 594 | public function purgeObjects(array $ids) { |
595 | - if(count($ids) === 0) { |
|
595 | + if (count($ids) === 0) { |
|
596 | 596 | // job done ;) |
597 | 597 | return true; |
598 | 598 | } |
599 | 599 | $updates = $ids; |
600 | 600 | try { |
601 | - $query = 'DELETE FROM `' . self::RELATION_TABLE . '` '; |
|
602 | - $query .= 'WHERE `objid` IN (' . str_repeat('?,', count($ids)-1) . '?) '; |
|
601 | + $query = 'DELETE FROM `'.self::RELATION_TABLE.'` '; |
|
602 | + $query .= 'WHERE `objid` IN ('.str_repeat('?,', count($ids) - 1).'?) '; |
|
603 | 603 | $query .= 'AND `type`= ?'; |
604 | 604 | $updates[] = $this->type; |
605 | 605 | $stmt = \OC_DB::prepare($query); |
606 | 606 | $result = $stmt->execute($updates); |
607 | 607 | if ($result === null) { |
608 | - \OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OC::$server->getDatabaseConnection()->getError(), ILogger::ERROR); |
|
608 | + \OCP\Util::writeLog('core', __METHOD__.'DB error: '.\OC::$server->getDatabaseConnection()->getError(), ILogger::ERROR); |
|
609 | 609 | return false; |
610 | 610 | } |
611 | - } catch(\Exception $e) { |
|
611 | + } catch (\Exception $e) { |
|
612 | 612 | \OC::$server->getLogger()->logException($e, [ |
613 | 613 | 'message' => __METHOD__, |
614 | 614 | 'level' => ILogger::ERROR, |
@@ -625,13 +625,13 @@ discard block |
||
625 | 625 | * @return array|false An array of object ids. |
626 | 626 | */ |
627 | 627 | public function getFavorites() { |
628 | - if(!$this->userHasTag(ITags::TAG_FAVORITE, $this->user)) { |
|
628 | + if (!$this->userHasTag(ITags::TAG_FAVORITE, $this->user)) { |
|
629 | 629 | return []; |
630 | 630 | } |
631 | 631 | |
632 | 632 | try { |
633 | 633 | return $this->getIdsForTag(ITags::TAG_FAVORITE); |
634 | - } catch(\Exception $e) { |
|
634 | + } catch (\Exception $e) { |
|
635 | 635 | \OC::$server->getLogger()->logException($e, [ |
636 | 636 | 'message' => __METHOD__, |
637 | 637 | 'level' => ILogger::ERROR, |
@@ -648,7 +648,7 @@ discard block |
||
648 | 648 | * @return boolean |
649 | 649 | */ |
650 | 650 | public function addToFavorites($objid) { |
651 | - if(!$this->userHasTag(ITags::TAG_FAVORITE, $this->user)) { |
|
651 | + if (!$this->userHasTag(ITags::TAG_FAVORITE, $this->user)) { |
|
652 | 652 | $this->add(ITags::TAG_FAVORITE); |
653 | 653 | } |
654 | 654 | return $this->tagAs($objid, ITags::TAG_FAVORITE); |
@@ -672,16 +672,16 @@ discard block |
||
672 | 672 | * @return boolean Returns false on error. |
673 | 673 | */ |
674 | 674 | public function tagAs($objid, $tag) { |
675 | - if(is_string($tag) && !is_numeric($tag)) { |
|
675 | + if (is_string($tag) && !is_numeric($tag)) { |
|
676 | 676 | $tag = trim($tag); |
677 | - if($tag === '') { |
|
677 | + if ($tag === '') { |
|
678 | 678 | \OCP\Util::writeLog('core', __METHOD__.', Cannot add an empty tag', ILogger::DEBUG); |
679 | 679 | return false; |
680 | 680 | } |
681 | - if(!$this->hasTag($tag)) { |
|
681 | + if (!$this->hasTag($tag)) { |
|
682 | 682 | $this->add($tag); |
683 | 683 | } |
684 | - $tagId = $this->getTagId($tag); |
|
684 | + $tagId = $this->getTagId($tag); |
|
685 | 685 | } else { |
686 | 686 | $tagId = $tag; |
687 | 687 | } |
@@ -692,7 +692,7 @@ discard block |
||
692 | 692 | 'categoryid' => $tagId, |
693 | 693 | 'type' => $this->type, |
694 | 694 | ]); |
695 | - } catch(\Exception $e) { |
|
695 | + } catch (\Exception $e) { |
|
696 | 696 | \OC::$server->getLogger()->logException($e, [ |
697 | 697 | 'message' => __METHOD__, |
698 | 698 | 'level' => ILogger::ERROR, |
@@ -711,23 +711,23 @@ discard block |
||
711 | 711 | * @return boolean |
712 | 712 | */ |
713 | 713 | public function unTag($objid, $tag) { |
714 | - if(is_string($tag) && !is_numeric($tag)) { |
|
714 | + if (is_string($tag) && !is_numeric($tag)) { |
|
715 | 715 | $tag = trim($tag); |
716 | - if($tag === '') { |
|
716 | + if ($tag === '') { |
|
717 | 717 | \OCP\Util::writeLog('core', __METHOD__.', Tag name is empty', ILogger::DEBUG); |
718 | 718 | return false; |
719 | 719 | } |
720 | - $tagId = $this->getTagId($tag); |
|
720 | + $tagId = $this->getTagId($tag); |
|
721 | 721 | } else { |
722 | 722 | $tagId = $tag; |
723 | 723 | } |
724 | 724 | |
725 | 725 | try { |
726 | - $sql = 'DELETE FROM `' . self::RELATION_TABLE . '` ' |
|
726 | + $sql = 'DELETE FROM `'.self::RELATION_TABLE.'` ' |
|
727 | 727 | . 'WHERE `objid` = ? AND `categoryid` = ? AND `type` = ?'; |
728 | 728 | $stmt = \OC_DB::prepare($sql); |
729 | 729 | $stmt->execute([$objid, $tagId, $this->type]); |
730 | - } catch(\Exception $e) { |
|
730 | + } catch (\Exception $e) { |
|
731 | 731 | \OC::$server->getLogger()->logException($e, [ |
732 | 732 | 'message' => __METHOD__, |
733 | 733 | 'level' => ILogger::ERROR, |
@@ -745,16 +745,16 @@ discard block |
||
745 | 745 | * @return bool Returns false on error |
746 | 746 | */ |
747 | 747 | public function delete($names) { |
748 | - if(!is_array($names)) { |
|
748 | + if (!is_array($names)) { |
|
749 | 749 | $names = [$names]; |
750 | 750 | } |
751 | 751 | |
752 | 752 | $names = array_map('trim', $names); |
753 | 753 | array_filter($names); |
754 | 754 | |
755 | - \OCP\Util::writeLog('core', __METHOD__ . ', before: ' |
|
755 | + \OCP\Util::writeLog('core', __METHOD__.', before: ' |
|
756 | 756 | . print_r($this->tags, true), ILogger::DEBUG); |
757 | - foreach($names as $name) { |
|
757 | + foreach ($names as $name) { |
|
758 | 758 | $id = null; |
759 | 759 | |
760 | 760 | if (is_numeric($name)) { |
@@ -768,22 +768,22 @@ discard block |
||
768 | 768 | unset($this->tags[$key]); |
769 | 769 | $this->mapper->delete($tag); |
770 | 770 | } else { |
771 | - \OCP\Util::writeLog('core', __METHOD__ . 'Cannot delete tag ' . $name |
|
771 | + \OCP\Util::writeLog('core', __METHOD__.'Cannot delete tag '.$name |
|
772 | 772 | . ': not found.', ILogger::ERROR); |
773 | 773 | } |
774 | - if(!is_null($id) && $id !== false) { |
|
774 | + if (!is_null($id) && $id !== false) { |
|
775 | 775 | try { |
776 | - $sql = 'DELETE FROM `' . self::RELATION_TABLE . '` ' |
|
776 | + $sql = 'DELETE FROM `'.self::RELATION_TABLE.'` ' |
|
777 | 777 | . 'WHERE `categoryid` = ?'; |
778 | 778 | $stmt = \OC_DB::prepare($sql); |
779 | 779 | $result = $stmt->execute([$id]); |
780 | 780 | if ($result === null) { |
781 | 781 | \OCP\Util::writeLog('core', |
782 | - __METHOD__. 'DB error: ' . \OC::$server->getDatabaseConnection()->getError(), |
|
782 | + __METHOD__.'DB error: '.\OC::$server->getDatabaseConnection()->getError(), |
|
783 | 783 | ILogger::ERROR); |
784 | 784 | return false; |
785 | 785 | } |
786 | - } catch(\Exception $e) { |
|
786 | + } catch (\Exception $e) { |
|
787 | 787 | \OC::$server->getLogger()->logException($e, [ |
788 | 788 | 'message' => __METHOD__, |
789 | 789 | 'level' => ILogger::ERROR, |
@@ -797,8 +797,8 @@ discard block |
||
797 | 797 | } |
798 | 798 | |
799 | 799 | // case-insensitive array_search |
800 | - protected function array_searchi($needle, $haystack, $mem='getName') { |
|
801 | - if(!is_array($haystack)) { |
|
800 | + protected function array_searchi($needle, $haystack, $mem = 'getName') { |
|
801 | + if (!is_array($haystack)) { |
|
802 | 802 | return false; |
803 | 803 | } |
804 | 804 | return array_search(strtolower($needle), array_map( |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | return true; |
90 | 90 | } |
91 | 91 | // Reject misformed domains in any case |
92 | - if (strpos($domain,'-') === 0 || strpos($domain,'..') !== false) { |
|
92 | + if (strpos($domain, '-') === 0 || strpos($domain, '..') !== false) { |
|
93 | 93 | return false; |
94 | 94 | } |
95 | 95 | // Match, allowing for * wildcards |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | if (gettype($trusted) !== 'string') { |
98 | 98 | break; |
99 | 99 | } |
100 | - $regex = '/^' . implode('[-\.a-zA-Z0-9]*', array_map(function($v) { return preg_quote($v, '/'); }, explode('*', $trusted))) . '$/i'; |
|
100 | + $regex = '/^'.implode('[-\.a-zA-Z0-9]*', array_map(function($v) { return preg_quote($v, '/'); }, explode('*', $trusted))).'$/i'; |
|
101 | 101 | if (preg_match($regex, $domain) || preg_match($regex, $domainWithPort)) { |
102 | 102 | return true; |
103 | 103 | } |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * the comments database scheme |
55 | 55 | */ |
56 | 56 | public function __construct(array $data = null) { |
57 | - if(is_array($data)) { |
|
57 | + if (is_array($data)) { |
|
58 | 58 | $this->fromArray($data); |
59 | 59 | } |
60 | 60 | } |
@@ -87,12 +87,12 @@ discard block |
||
87 | 87 | * @since 9.0.0 |
88 | 88 | */ |
89 | 89 | public function setId($id) { |
90 | - if(!is_string($id)) { |
|
90 | + if (!is_string($id)) { |
|
91 | 91 | throw new \InvalidArgumentException('String expected.'); |
92 | 92 | } |
93 | 93 | |
94 | 94 | $id = trim($id); |
95 | - if($this->data['id'] === '' || ($this->data['id'] !== '' && $id === '')) { |
|
95 | + if ($this->data['id'] === '' || ($this->data['id'] !== '' && $id === '')) { |
|
96 | 96 | $this->data['id'] = $id; |
97 | 97 | return $this; |
98 | 98 | } |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * @since 9.0.0 |
119 | 119 | */ |
120 | 120 | public function setParentId($parentId) { |
121 | - if(!is_string($parentId)) { |
|
121 | + if (!is_string($parentId)) { |
|
122 | 122 | throw new \InvalidArgumentException('String expected.'); |
123 | 123 | } |
124 | 124 | $this->data['parentId'] = trim($parentId); |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @since 9.0.0 |
145 | 145 | */ |
146 | 146 | public function setTopmostParentId($id) { |
147 | - if(!is_string($id)) { |
|
147 | + if (!is_string($id)) { |
|
148 | 148 | throw new \InvalidArgumentException('String expected.'); |
149 | 149 | } |
150 | 150 | $this->data['topmostParentId'] = trim($id); |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | * @since 9.0.0 |
170 | 170 | */ |
171 | 171 | public function setChildrenCount($count) { |
172 | - if(!is_int($count)) { |
|
172 | + if (!is_int($count)) { |
|
173 | 173 | throw new \InvalidArgumentException('Integer expected.'); |
174 | 174 | } |
175 | 175 | $this->data['childrenCount'] = $count; |
@@ -196,12 +196,12 @@ discard block |
||
196 | 196 | * @since 9.0.0 |
197 | 197 | */ |
198 | 198 | public function setMessage($message, $maxLength = self::MAX_MESSAGE_LENGTH) { |
199 | - if(!is_string($message)) { |
|
199 | + if (!is_string($message)) { |
|
200 | 200 | throw new \InvalidArgumentException('String expected.'); |
201 | 201 | } |
202 | 202 | $message = trim($message); |
203 | 203 | if ($maxLength && mb_strlen($message, 'UTF-8') > $maxLength) { |
204 | - throw new MessageTooLongException('Comment message must not exceed ' . $maxLength. ' characters'); |
|
204 | + throw new MessageTooLongException('Comment message must not exceed '.$maxLength.' characters'); |
|
205 | 205 | } |
206 | 206 | $this->data['message'] = $message; |
207 | 207 | return $this; |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | */ |
230 | 230 | public function getMentions() { |
231 | 231 | $ok = preg_match_all("/\B(?<![^a-z0-9_\-@\.\'\s])@(\"guest\/[a-f0-9]+\"|\"[a-z0-9_\-@\.\' ]+\"|[a-z0-9_\-@\.\']+)/i", $this->getMessage(), $mentions); |
232 | - if(!$ok || !isset($mentions[0]) || !is_array($mentions[0])) { |
|
232 | + if (!$ok || !isset($mentions[0]) || !is_array($mentions[0])) { |
|
233 | 233 | return []; |
234 | 234 | } |
235 | 235 | $uids = array_unique($mentions[0]); |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | * @since 9.0.0 |
264 | 264 | */ |
265 | 265 | public function setVerb($verb) { |
266 | - if(!is_string($verb) || !trim($verb)) { |
|
266 | + if (!is_string($verb) || !trim($verb)) { |
|
267 | 267 | throw new \InvalidArgumentException('Non-empty String expected.'); |
268 | 268 | } |
269 | 269 | $this->data['verb'] = trim($verb); |
@@ -299,9 +299,9 @@ discard block |
||
299 | 299 | * @since 9.0.0 |
300 | 300 | */ |
301 | 301 | public function setActor($actorType, $actorId) { |
302 | - if( |
|
302 | + if ( |
|
303 | 303 | !is_string($actorType) || !trim($actorType) |
304 | - || !is_string($actorId) || $actorId === '' |
|
304 | + || !is_string($actorId) || $actorId === '' |
|
305 | 305 | ) { |
306 | 306 | throw new \InvalidArgumentException('String expected.'); |
307 | 307 | } |
@@ -385,9 +385,9 @@ discard block |
||
385 | 385 | * @since 9.0.0 |
386 | 386 | */ |
387 | 387 | public function setObject($objectType, $objectId) { |
388 | - if( |
|
388 | + if ( |
|
389 | 389 | !is_string($objectType) || !trim($objectType) |
390 | - || !is_string($objectId) || trim($objectId) === '' |
|
390 | + || !is_string($objectId) || trim($objectId) === '' |
|
391 | 391 | ) { |
392 | 392 | throw new \InvalidArgumentException('String expected.'); |
393 | 393 | } |
@@ -434,20 +434,20 @@ discard block |
||
434 | 434 | * @return IComment |
435 | 435 | */ |
436 | 436 | protected function fromArray($data) { |
437 | - foreach(array_keys($data) as $key) { |
|
437 | + foreach (array_keys($data) as $key) { |
|
438 | 438 | // translate DB keys to internal setter names |
439 | - $setter = 'set' . implode('', array_map('ucfirst', explode('_', $key))); |
|
439 | + $setter = 'set'.implode('', array_map('ucfirst', explode('_', $key))); |
|
440 | 440 | $setter = str_replace('Timestamp', 'DateTime', $setter); |
441 | 441 | |
442 | - if(method_exists($this, $setter)) { |
|
442 | + if (method_exists($this, $setter)) { |
|
443 | 443 | $this->$setter($data[$key]); |
444 | 444 | } |
445 | 445 | } |
446 | 446 | |
447 | - foreach(['actor', 'object'] as $role) { |
|
448 | - if(isset($data[$role . '_type']) && isset($data[$role . '_id'])) { |
|
449 | - $setter = 'set' . ucfirst($role); |
|
450 | - $this->$setter($data[$role . '_type'], $data[$role . '_id']); |
|
447 | + foreach (['actor', 'object'] as $role) { |
|
448 | + if (isset($data[$role.'_type']) && isset($data[$role.'_id'])) { |
|
449 | + $setter = 'set'.ucfirst($role); |
|
450 | + $this->$setter($data[$role.'_type'], $data[$role.'_id']); |
|
451 | 451 | } |
452 | 452 | } |
453 | 453 |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * @todo migrate existing database columns to the correct names |
64 | 64 | * to be able to drop this direct mapping |
65 | 65 | */ |
66 | - public function columnToProperty($columnName){ |
|
66 | + public function columnToProperty($columnName) { |
|
67 | 67 | if ($columnName === 'category') { |
68 | 68 | return 'name'; |
69 | 69 | } elseif ($columnName === 'uid') { |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @param string $property the name of the property |
80 | 80 | * @return string the column name |
81 | 81 | */ |
82 | - public function propertyToColumn($property){ |
|
82 | + public function propertyToColumn($property) { |
|
83 | 83 | if ($property === 'name') { |
84 | 84 | return 'category'; |
85 | 85 | } elseif ($property === 'owner') { |