Completed
Pull Request — stable10 (#5732)
by Morris
14:18
created
lib/private/Tags.php 3 patches
Doc Comments   +10 added lines, -2 removed lines patch added patch discarded remove patch
@@ -742,11 +742,19 @@  discard block
 block discarded – undo
742 742
 	}
743 743
 
744 744
 	// case-insensitive array_search
745
+
746
+	/**
747
+	 * @param string $needle
748
+	 */
745 749
 	protected function array_searchi($needle, $haystack, $mem='getName') {
746 750
 		if(!is_array($haystack)) {
747 751
 			return false;
748 752
 		}
749 753
 		return array_search(strtolower($needle), array_map(
754
+
755
+			/**
756
+			 * @param string $tag
757
+			 */
750 758
 			function($tag) use($mem) {
751 759
 				return strtolower(call_user_func(array($tag, $mem)));
752 760
 			}, $haystack)
@@ -771,7 +779,7 @@  discard block
 block discarded – undo
771 779
 	* Get a tag by its name.
772 780
 	*
773 781
 	* @param string $name The tag name.
774
-	* @return integer|bool The tag object's offset within the $this->tags
782
+	* @return \OCP\AppFramework\Db\Entity The tag object's offset within the $this->tags
775 783
 	*                      array or false if it doesn't exist.
776 784
 	*/
777 785
 	private function getTagByName($name) {
@@ -782,7 +790,7 @@  discard block
 block discarded – undo
782 790
 	* Get a tag by its ID.
783 791
 	*
784 792
 	* @param string $id The tag ID to look for.
785
-	* @return integer|bool The tag object's offset within the $this->tags
793
+	* @return \OCP\AppFramework\Db\Entity The tag object's offset within the $this->tags
786 794
 	*                      array or false if it doesn't exist.
787 795
 	*/
788 796
 	private function getTagById($id) {
Please login to merge, or discard this patch.
Indentation   +757 added lines, -757 removed lines patch added patch discarded remove patch
@@ -48,761 +48,761 @@
 block discarded – undo
48 48
 
49 49
 class Tags implements \OCP\ITags {
50 50
 
51
-	/**
52
-	 * Tags
53
-	 *
54
-	 * @var array
55
-	 */
56
-	private $tags = array();
57
-
58
-	/**
59
-	 * Used for storing objectid/categoryname pairs while rescanning.
60
-	 *
61
-	 * @var array
62
-	 */
63
-	private static $relations = array();
64
-
65
-	/**
66
-	 * Type
67
-	 *
68
-	 * @var string
69
-	 */
70
-	private $type;
71
-
72
-	/**
73
-	 * User
74
-	 *
75
-	 * @var string
76
-	 */
77
-	private $user;
78
-
79
-	/**
80
-	 * Are we including tags for shared items?
81
-	 *
82
-	 * @var bool
83
-	 */
84
-	private $includeShared = false;
85
-
86
-	/**
87
-	 * The current user, plus any owners of the items shared with the current
88
-	 * user, if $this->includeShared === true.
89
-	 *
90
-	 * @var array
91
-	 */
92
-	private $owners = array();
93
-
94
-	/**
95
-	 * The Mapper we're using to communicate our Tag objects to the database.
96
-	 *
97
-	 * @var TagMapper
98
-	 */
99
-	private $mapper;
100
-
101
-	/**
102
-	 * The sharing backend for objects of $this->type. Required if
103
-	 * $this->includeShared === true to determine ownership of items.
104
-	 *
105
-	 * @var \OCP\Share_Backend
106
-	 */
107
-	private $backend;
108
-
109
-	const TAG_TABLE = '*PREFIX*vcategory';
110
-	const RELATION_TABLE = '*PREFIX*vcategory_to_object';
111
-
112
-	const TAG_FAVORITE = '_$!<Favorite>!$_';
113
-
114
-	/**
115
-	* Constructor.
116
-	*
117
-	* @param TagMapper $mapper Instance of the TagMapper abstraction layer.
118
-	* @param string $user The user whose data the object will operate on.
119
-	* @param string $type The type of items for which tags will be loaded.
120
-	* @param array $defaultTags Tags that should be created at construction.
121
-	* @param boolean $includeShared Whether to include tags for items shared with this user by others.
122
-	*/
123
-	public function __construct(TagMapper $mapper, $user, $type, $defaultTags = array(), $includeShared = false) {
124
-		$this->mapper = $mapper;
125
-		$this->user = $user;
126
-		$this->type = $type;
127
-		$this->includeShared = $includeShared;
128
-		$this->owners = array($this->user);
129
-		if ($this->includeShared) {
130
-			$this->owners = array_merge($this->owners, \OC\Share\Share::getSharedItemsOwners($this->user, $this->type, true));
131
-			$this->backend = \OC\Share\Share::getBackend($this->type);
132
-		}
133
-		$this->tags = $this->mapper->loadTags($this->owners, $this->type);
134
-
135
-		if(count($defaultTags) > 0 && count($this->tags) === 0) {
136
-			$this->addMultiple($defaultTags, true);
137
-		}
138
-	}
139
-
140
-	/**
141
-	* Check if any tags are saved for this type and user.
142
-	*
143
-	* @return boolean.
144
-	*/
145
-	public function isEmpty() {
146
-		return count($this->tags) === 0;
147
-	}
148
-
149
-	/**
150
-	* Returns an array mapping a given tag's properties to its values:
151
-	* ['id' => 0, 'name' = 'Tag', 'owner' = 'User', 'type' => 'tagtype']
152
-	*
153
-	* @param string $id The ID of the tag that is going to be mapped
154
-	* @return array|false
155
-	*/
156
-	public function getTag($id) {
157
-		$key = $this->getTagById($id);
158
-		if ($key !== false) {
159
-			return $this->tagMap($this->tags[$key]);
160
-		}
161
-		return false;
162
-	}
163
-
164
-	/**
165
-	* Get the tags for a specific user.
166
-	*
167
-	* This returns an array with maps containing each tag's properties:
168
-	* [
169
-	* 	['id' => 0, 'name' = 'First tag', 'owner' = 'User', 'type' => 'tagtype'],
170
-	* 	['id' => 1, 'name' = 'Shared tag', 'owner' = 'Other user', 'type' => 'tagtype'],
171
-	* ]
172
-	*
173
-	* @return array
174
-	*/
175
-	public function getTags() {
176
-		if(!count($this->tags)) {
177
-			return array();
178
-		}
179
-
180
-		usort($this->tags, function($a, $b) {
181
-			return strnatcasecmp($a->getName(), $b->getName());
182
-		});
183
-		$tagMap = array();
184
-
185
-		foreach($this->tags as $tag) {
186
-			if($tag->getName() !== self::TAG_FAVORITE) {
187
-				$tagMap[] = $this->tagMap($tag);
188
-			}
189
-		}
190
-		return $tagMap;
191
-
192
-	}
193
-
194
-	/**
195
-	* Return only the tags owned by the given user, omitting any tags shared
196
-	* by other users.
197
-	*
198
-	* @param string $user The user whose tags are to be checked.
199
-	* @return array An array of Tag objects.
200
-	*/
201
-	public function getTagsForUser($user) {
202
-		return array_filter($this->tags,
203
-			function($tag) use($user) {
204
-				return $tag->getOwner() === $user;
205
-			}
206
-		);
207
-	}
208
-
209
-	/**
210
-	 * Get the list of tags for the given ids.
211
-	 *
212
-	 * @param array $objIds array of object ids
213
-	 * @return array|boolean of tags id as key to array of tag names
214
-	 * or false if an error occurred
215
-	 */
216
-	public function getTagsForObjects(array $objIds) {
217
-		$entries = array();
218
-
219
-		try {
220
-			$conn = \OC::$server->getDatabaseConnection();
221
-			$chunks = array_chunk($objIds, 900, false);
222
-			foreach ($chunks as $chunk) {
223
-				$result = $conn->executeQuery(
224
-					'SELECT `category`, `categoryid`, `objid` ' .
225
-					'FROM `' . self::RELATION_TABLE . '` r, `' . self::TAG_TABLE . '` ' .
226
-					'WHERE `categoryid` = `id` AND `uid` = ? AND r.`type` = ? AND `objid` IN (?)',
227
-					array($this->user, $this->type, $chunk),
228
-					array(null, null, IQueryBuilder::PARAM_INT_ARRAY)
229
-				);
230
-				while ($row = $result->fetch()) {
231
-					$objId = (int)$row['objid'];
232
-					if (!isset($entries[$objId])) {
233
-						$entries[$objId] = array();
234
-					}
235
-					$entries[$objId][] = $row['category'];
236
-				}
237
-				if (\OCP\DB::isError($result)) {
238
-					\OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
239
-					return false;
240
-				}
241
-			}
242
-		} catch(\Exception $e) {
243
-			\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
244
-				\OCP\Util::ERROR);
245
-			return false;
246
-		}
247
-
248
-		return $entries;
249
-	}
250
-
251
-	/**
252
-	* Get the a list if items tagged with $tag.
253
-	*
254
-	* Throws an exception if the tag could not be found.
255
-	*
256
-	* @param string $tag Tag id or name.
257
-	* @return array|false An array of object ids or false on error.
258
-	* @throws \Exception
259
-	*/
260
-	public function getIdsForTag($tag) {
261
-		$result = null;
262
-		$tagId = false;
263
-		if(is_numeric($tag)) {
264
-			$tagId = $tag;
265
-		} elseif(is_string($tag)) {
266
-			$tag = trim($tag);
267
-			if($tag === '') {
268
-				\OCP\Util::writeLog('core', __METHOD__.', Cannot use empty tag names', \OCP\Util::DEBUG);
269
-				return false;
270
-			}
271
-			$tagId = $this->getTagId($tag);
272
-		}
273
-
274
-		if($tagId === false) {
275
-			$l10n = \OC::$server->getL10N('core');
276
-			throw new \Exception(
277
-				$l10n->t('Could not find category "%s"', $tag)
278
-			);
279
-		}
280
-
281
-		$ids = array();
282
-		$sql = 'SELECT `objid` FROM `' . self::RELATION_TABLE
283
-			. '` WHERE `categoryid` = ?';
284
-
285
-		try {
286
-			$stmt = \OCP\DB::prepare($sql);
287
-			$result = $stmt->execute(array($tagId));
288
-			if (\OCP\DB::isError($result)) {
289
-				\OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
290
-				return false;
291
-			}
292
-		} catch(\Exception $e) {
293
-			\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
294
-				\OCP\Util::ERROR);
295
-			return false;
296
-		}
297
-
298
-		if(!is_null($result)) {
299
-			while( $row = $result->fetchRow()) {
300
-				$id = (int)$row['objid'];
301
-
302
-				if ($this->includeShared) {
303
-					// We have to check if we are really allowed to access the
304
-					// items that are tagged with $tag. To that end, we ask the
305
-					// corresponding sharing backend if the item identified by $id
306
-					// is owned by any of $this->owners.
307
-					foreach ($this->owners as $owner) {
308
-						if ($this->backend->isValidSource($id, $owner)) {
309
-							$ids[] = $id;
310
-							break;
311
-						}
312
-					}
313
-				} else {
314
-					$ids[] = $id;
315
-				}
316
-			}
317
-		}
318
-
319
-		return $ids;
320
-	}
321
-
322
-	/**
323
-	* Checks whether a tag is saved for the given user,
324
-	* disregarding the ones shared with him or her.
325
-	*
326
-	* @param string $name The tag name to check for.
327
-	* @param string $user The user whose tags are to be checked.
328
-	* @return bool
329
-	*/
330
-	public function userHasTag($name, $user) {
331
-		$key = $this->array_searchi($name, $this->getTagsForUser($user));
332
-		return ($key !== false) ? $this->tags[$key]->getId() : false;
333
-	}
334
-
335
-	/**
336
-	* Checks whether a tag is saved for or shared with the current user.
337
-	*
338
-	* @param string $name The tag name to check for.
339
-	* @return bool
340
-	*/
341
-	public function hasTag($name) {
342
-		return $this->getTagId($name) !== false;
343
-	}
344
-
345
-	/**
346
-	* Add a new tag.
347
-	*
348
-	* @param string $name A string with a name of the tag
349
-	* @return false|int the id of the added tag or false on error.
350
-	*/
351
-	public function add($name) {
352
-		$name = trim($name);
353
-
354
-		if($name === '') {
355
-			\OCP\Util::writeLog('core', __METHOD__.', Cannot add an empty tag', \OCP\Util::DEBUG);
356
-			return false;
357
-		}
358
-		if($this->userHasTag($name, $this->user)) {
359
-			\OCP\Util::writeLog('core', __METHOD__.', name: ' . $name. ' exists already', \OCP\Util::DEBUG);
360
-			return false;
361
-		}
362
-		try {
363
-			$tag = new Tag($this->user, $this->type, $name);
364
-			$tag = $this->mapper->insert($tag);
365
-			$this->tags[] = $tag;
366
-		} catch(\Exception $e) {
367
-			\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
368
-				\OCP\Util::ERROR);
369
-			return false;
370
-		}
371
-		\OCP\Util::writeLog('core', __METHOD__.', id: ' . $tag->getId(), \OCP\Util::DEBUG);
372
-		return $tag->getId();
373
-	}
374
-
375
-	/**
376
-	* Rename tag.
377
-	*
378
-	* @param string|integer $from The name or ID of the existing tag
379
-	* @param string $to The new name of the tag.
380
-	* @return bool
381
-	*/
382
-	public function rename($from, $to) {
383
-		$from = trim($from);
384
-		$to = trim($to);
385
-
386
-		if($to === '' || $from === '') {
387
-			\OCP\Util::writeLog('core', __METHOD__.', Cannot use empty tag names', \OCP\Util::DEBUG);
388
-			return false;
389
-		}
390
-
391
-		if (is_numeric($from)) {
392
-			$key = $this->getTagById($from);
393
-		} else {
394
-			$key = $this->getTagByName($from);
395
-		}
396
-		if($key === false) {
397
-			\OCP\Util::writeLog('core', __METHOD__.', tag: ' . $from. ' does not exist', \OCP\Util::DEBUG);
398
-			return false;
399
-		}
400
-		$tag = $this->tags[$key];
401
-
402
-		if($this->userHasTag($to, $tag->getOwner())) {
403
-			\OCP\Util::writeLog('core', __METHOD__.', A tag named ' . $to. ' already exists for user ' . $tag->getOwner() . '.', \OCP\Util::DEBUG);
404
-			return false;
405
-		}
406
-
407
-		try {
408
-			$tag->setName($to);
409
-			$this->tags[$key] = $this->mapper->update($tag);
410
-		} catch(\Exception $e) {
411
-			\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
412
-				\OCP\Util::ERROR);
413
-			return false;
414
-		}
415
-		return true;
416
-	}
417
-
418
-	/**
419
-	* Add a list of new tags.
420
-	*
421
-	* @param string[] $names A string with a name or an array of strings containing
422
-	* the name(s) of the tag(s) to add.
423
-	* @param bool $sync When true, save the tags
424
-	* @param int|null $id int Optional object id to add to this|these tag(s)
425
-	* @return bool Returns false on error.
426
-	*/
427
-	public function addMultiple($names, $sync=false, $id = null) {
428
-		if(!is_array($names)) {
429
-			$names = array($names);
430
-		}
431
-		$names = array_map('trim', $names);
432
-		array_filter($names);
433
-
434
-		$newones = array();
435
-		foreach($names as $name) {
436
-			if(!$this->hasTag($name) && $name !== '') {
437
-				$newones[] = new Tag($this->user, $this->type, $name);
438
-			}
439
-			if(!is_null($id) ) {
440
-				// Insert $objectid, $categoryid  pairs if not exist.
441
-				self::$relations[] = array('objid' => $id, 'tag' => $name);
442
-			}
443
-		}
444
-		$this->tags = array_merge($this->tags, $newones);
445
-		if($sync === true) {
446
-			$this->save();
447
-		}
448
-
449
-		return true;
450
-	}
451
-
452
-	/**
453
-	 * Save the list of tags and their object relations
454
-	 */
455
-	protected function save() {
456
-		if(is_array($this->tags)) {
457
-			foreach($this->tags as $tag) {
458
-				try {
459
-					if (!$this->mapper->tagExists($tag)) {
460
-						$this->mapper->insert($tag);
461
-					}
462
-				} catch(\Exception $e) {
463
-					\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
464
-						\OCP\Util::ERROR);
465
-				}
466
-			}
467
-
468
-			// reload tags to get the proper ids.
469
-			$this->tags = $this->mapper->loadTags($this->owners, $this->type);
470
-			\OCP\Util::writeLog('core', __METHOD__.', tags: ' . print_r($this->tags, true),
471
-				\OCP\Util::DEBUG);
472
-			// Loop through temporarily cached objectid/tagname pairs
473
-			// and save relations.
474
-			$tags = $this->tags;
475
-			// For some reason this is needed or array_search(i) will return 0..?
476
-			ksort($tags);
477
-			foreach(self::$relations as $relation) {
478
-				$tagId = $this->getTagId($relation['tag']);
479
-				\OCP\Util::writeLog('core', __METHOD__ . 'catid, ' . $relation['tag'] . ' ' . $tagId, \OCP\Util::DEBUG);
480
-				if($tagId) {
481
-					try {
482
-						\OCP\DB::insertIfNotExist(self::RELATION_TABLE,
483
-							array(
484
-								'objid' => $relation['objid'],
485
-								'categoryid' => $tagId,
486
-								'type' => $this->type,
487
-								));
488
-					} catch(\Exception $e) {
489
-						\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
490
-							\OCP\Util::ERROR);
491
-					}
492
-				}
493
-			}
494
-			self::$relations = array(); // reset
495
-		} else {
496
-			\OCP\Util::writeLog('core', __METHOD__.', $this->tags is not an array! '
497
-				. print_r($this->tags, true), \OCP\Util::ERROR);
498
-		}
499
-	}
500
-
501
-	/**
502
-	* Delete tags and tag/object relations for a user.
503
-	*
504
-	* For hooking up on post_deleteUser
505
-	*
506
-	* @param array $arguments
507
-	*/
508
-	public static function post_deleteUser($arguments) {
509
-		// Find all objectid/tagId pairs.
510
-		$result = null;
511
-		try {
512
-			$stmt = \OCP\DB::prepare('SELECT `id` FROM `' . self::TAG_TABLE . '` '
513
-				. 'WHERE `uid` = ?');
514
-			$result = $stmt->execute(array($arguments['uid']));
515
-			if (\OCP\DB::isError($result)) {
516
-				\OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
517
-			}
518
-		} catch(\Exception $e) {
519
-			\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
520
-				\OCP\Util::ERROR);
521
-		}
522
-
523
-		if(!is_null($result)) {
524
-			try {
525
-				$stmt = \OCP\DB::prepare('DELETE FROM `' . self::RELATION_TABLE . '` '
526
-					. 'WHERE `categoryid` = ?');
527
-				while( $row = $result->fetchRow()) {
528
-					try {
529
-						$stmt->execute(array($row['id']));
530
-					} catch(\Exception $e) {
531
-						\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
532
-							\OCP\Util::ERROR);
533
-					}
534
-				}
535
-			} catch(\Exception $e) {
536
-				\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
537
-					\OCP\Util::ERROR);
538
-			}
539
-		}
540
-		try {
541
-			$stmt = \OCP\DB::prepare('DELETE FROM `' . self::TAG_TABLE . '` '
542
-				. 'WHERE `uid` = ?');
543
-			$result = $stmt->execute(array($arguments['uid']));
544
-			if (\OCP\DB::isError($result)) {
545
-				\OCP\Util::writeLog('core', __METHOD__. ', DB error: ' . \OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
546
-			}
547
-		} catch(\Exception $e) {
548
-			\OCP\Util::writeLog('core', __METHOD__ . ', exception: '
549
-				. $e->getMessage(), \OCP\Util::ERROR);
550
-		}
551
-	}
552
-
553
-	/**
554
-	* Delete tag/object relations from the db
555
-	*
556
-	* @param array $ids The ids of the objects
557
-	* @return boolean Returns false on error.
558
-	*/
559
-	public function purgeObjects(array $ids) {
560
-		if(count($ids) === 0) {
561
-			// job done ;)
562
-			return true;
563
-		}
564
-		$updates = $ids;
565
-		try {
566
-			$query = 'DELETE FROM `' . self::RELATION_TABLE . '` ';
567
-			$query .= 'WHERE `objid` IN (' . str_repeat('?,', count($ids)-1) . '?) ';
568
-			$query .= 'AND `type`= ?';
569
-			$updates[] = $this->type;
570
-			$stmt = \OCP\DB::prepare($query);
571
-			$result = $stmt->execute($updates);
572
-			if (\OCP\DB::isError($result)) {
573
-				\OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
574
-				return false;
575
-			}
576
-		} catch(\Exception $e) {
577
-			\OCP\Util::writeLog('core', __METHOD__.', exception: ' . $e->getMessage(),
578
-				\OCP\Util::ERROR);
579
-			return false;
580
-		}
581
-		return true;
582
-	}
583
-
584
-	/**
585
-	* Get favorites for an object type
586
-	*
587
-	* @return array|false An array of object ids.
588
-	*/
589
-	public function getFavorites() {
590
-		try {
591
-			return $this->getIdsForTag(self::TAG_FAVORITE);
592
-		} catch(\Exception $e) {
593
-			\OCP\Util::writeLog('core', __METHOD__.', exception: ' . $e->getMessage(),
594
-				\OCP\Util::DEBUG);
595
-			return array();
596
-		}
597
-	}
598
-
599
-	/**
600
-	* Add an object to favorites
601
-	*
602
-	* @param int $objid The id of the object
603
-	* @return boolean
604
-	*/
605
-	public function addToFavorites($objid) {
606
-		if(!$this->userHasTag(self::TAG_FAVORITE, $this->user)) {
607
-			$this->add(self::TAG_FAVORITE);
608
-		}
609
-		return $this->tagAs($objid, self::TAG_FAVORITE);
610
-	}
611
-
612
-	/**
613
-	* Remove an object from favorites
614
-	*
615
-	* @param int $objid The id of the object
616
-	* @return boolean
617
-	*/
618
-	public function removeFromFavorites($objid) {
619
-		return $this->unTag($objid, self::TAG_FAVORITE);
620
-	}
621
-
622
-	/**
623
-	* Creates a tag/object relation.
624
-	*
625
-	* @param int $objid The id of the object
626
-	* @param string $tag The id or name of the tag
627
-	* @return boolean Returns false on error.
628
-	*/
629
-	public function tagAs($objid, $tag) {
630
-		if(is_string($tag) && !is_numeric($tag)) {
631
-			$tag = trim($tag);
632
-			if($tag === '') {
633
-				\OCP\Util::writeLog('core', __METHOD__.', Cannot add an empty tag', \OCP\Util::DEBUG);
634
-				return false;
635
-			}
636
-			if(!$this->hasTag($tag)) {
637
-				$this->add($tag);
638
-			}
639
-			$tagId =  $this->getTagId($tag);
640
-		} else {
641
-			$tagId = $tag;
642
-		}
643
-		try {
644
-			\OCP\DB::insertIfNotExist(self::RELATION_TABLE,
645
-				array(
646
-					'objid' => $objid,
647
-					'categoryid' => $tagId,
648
-					'type' => $this->type,
649
-				));
650
-		} catch(\Exception $e) {
651
-			\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
652
-				\OCP\Util::ERROR);
653
-			return false;
654
-		}
655
-		return true;
656
-	}
657
-
658
-	/**
659
-	* Delete single tag/object relation from the db
660
-	*
661
-	* @param int $objid The id of the object
662
-	* @param string $tag The id or name of the tag
663
-	* @return boolean
664
-	*/
665
-	public function unTag($objid, $tag) {
666
-		if(is_string($tag) && !is_numeric($tag)) {
667
-			$tag = trim($tag);
668
-			if($tag === '') {
669
-				\OCP\Util::writeLog('core', __METHOD__.', Tag name is empty', \OCP\Util::DEBUG);
670
-				return false;
671
-			}
672
-			$tagId =  $this->getTagId($tag);
673
-		} else {
674
-			$tagId = $tag;
675
-		}
676
-
677
-		try {
678
-			$sql = 'DELETE FROM `' . self::RELATION_TABLE . '` '
679
-					. 'WHERE `objid` = ? AND `categoryid` = ? AND `type` = ?';
680
-			$stmt = \OCP\DB::prepare($sql);
681
-			$stmt->execute(array($objid, $tagId, $this->type));
682
-		} catch(\Exception $e) {
683
-			\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
684
-				\OCP\Util::ERROR);
685
-			return false;
686
-		}
687
-		return true;
688
-	}
689
-
690
-	/**
691
-	* Delete tags from the database.
692
-	*
693
-	* @param string[]|integer[] $names An array of tags (names or IDs) to delete
694
-	* @return bool Returns false on error
695
-	*/
696
-	public function delete($names) {
697
-		if(!is_array($names)) {
698
-			$names = array($names);
699
-		}
700
-
701
-		$names = array_map('trim', $names);
702
-		array_filter($names);
703
-
704
-		\OCP\Util::writeLog('core', __METHOD__ . ', before: '
705
-			. print_r($this->tags, true), \OCP\Util::DEBUG);
706
-		foreach($names as $name) {
707
-			$id = null;
708
-
709
-			if (is_numeric($name)) {
710
-				$key = $this->getTagById($name);
711
-			} else {
712
-				$key = $this->getTagByName($name);
713
-			}
714
-			if ($key !== false) {
715
-				$tag = $this->tags[$key];
716
-				$id = $tag->getId();
717
-				unset($this->tags[$key]);
718
-				$this->mapper->delete($tag);
719
-			} else {
720
-				\OCP\Util::writeLog('core', __METHOD__ . 'Cannot delete tag ' . $name
721
-					. ': not found.', \OCP\Util::ERROR);
722
-			}
723
-			if(!is_null($id) && $id !== false) {
724
-				try {
725
-					$sql = 'DELETE FROM `' . self::RELATION_TABLE . '` '
726
-							. 'WHERE `categoryid` = ?';
727
-					$stmt = \OCP\DB::prepare($sql);
728
-					$result = $stmt->execute(array($id));
729
-					if (\OCP\DB::isError($result)) {
730
-						\OCP\Util::writeLog('core',
731
-							__METHOD__. 'DB error: ' . \OCP\DB::getErrorMessage(),
732
-							\OCP\Util::ERROR);
733
-						return false;
734
-					}
735
-				} catch(\Exception $e) {
736
-					\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
737
-						\OCP\Util::ERROR);
738
-					return false;
739
-				}
740
-			}
741
-		}
742
-		return true;
743
-	}
744
-
745
-	// case-insensitive array_search
746
-	protected function array_searchi($needle, $haystack, $mem='getName') {
747
-		if(!is_array($haystack)) {
748
-			return false;
749
-		}
750
-		return array_search(strtolower($needle), array_map(
751
-			function($tag) use($mem) {
752
-				return strtolower(call_user_func(array($tag, $mem)));
753
-			}, $haystack)
754
-		);
755
-	}
756
-
757
-	/**
758
-	* Get a tag's ID.
759
-	*
760
-	* @param string $name The tag name to look for.
761
-	* @return string|bool The tag's id or false if no matching tag is found.
762
-	*/
763
-	private function getTagId($name) {
764
-		$key = $this->array_searchi($name, $this->tags);
765
-		if ($key !== false) {
766
-			return $this->tags[$key]->getId();
767
-		}
768
-		return false;
769
-	}
770
-
771
-	/**
772
-	* Get a tag by its name.
773
-	*
774
-	* @param string $name The tag name.
775
-	* @return integer|bool The tag object's offset within the $this->tags
776
-	*                      array or false if it doesn't exist.
777
-	*/
778
-	private function getTagByName($name) {
779
-		return $this->array_searchi($name, $this->tags, 'getName');
780
-	}
781
-
782
-	/**
783
-	* Get a tag by its ID.
784
-	*
785
-	* @param string $id The tag ID to look for.
786
-	* @return integer|bool The tag object's offset within the $this->tags
787
-	*                      array or false if it doesn't exist.
788
-	*/
789
-	private function getTagById($id) {
790
-		return $this->array_searchi($id, $this->tags, 'getId');
791
-	}
792
-
793
-	/**
794
-	* Returns an array mapping a given tag's properties to its values:
795
-	* ['id' => 0, 'name' = 'Tag', 'owner' = 'User', 'type' => 'tagtype']
796
-	*
797
-	* @param Tag $tag The tag that is going to be mapped
798
-	* @return array
799
-	*/
800
-	private function tagMap(Tag $tag) {
801
-		return array(
802
-			'id'    => $tag->getId(),
803
-			'name'  => $tag->getName(),
804
-			'owner' => $tag->getOwner(),
805
-			'type'  => $tag->getType()
806
-		);
807
-	}
51
+    /**
52
+     * Tags
53
+     *
54
+     * @var array
55
+     */
56
+    private $tags = array();
57
+
58
+    /**
59
+     * Used for storing objectid/categoryname pairs while rescanning.
60
+     *
61
+     * @var array
62
+     */
63
+    private static $relations = array();
64
+
65
+    /**
66
+     * Type
67
+     *
68
+     * @var string
69
+     */
70
+    private $type;
71
+
72
+    /**
73
+     * User
74
+     *
75
+     * @var string
76
+     */
77
+    private $user;
78
+
79
+    /**
80
+     * Are we including tags for shared items?
81
+     *
82
+     * @var bool
83
+     */
84
+    private $includeShared = false;
85
+
86
+    /**
87
+     * The current user, plus any owners of the items shared with the current
88
+     * user, if $this->includeShared === true.
89
+     *
90
+     * @var array
91
+     */
92
+    private $owners = array();
93
+
94
+    /**
95
+     * The Mapper we're using to communicate our Tag objects to the database.
96
+     *
97
+     * @var TagMapper
98
+     */
99
+    private $mapper;
100
+
101
+    /**
102
+     * The sharing backend for objects of $this->type. Required if
103
+     * $this->includeShared === true to determine ownership of items.
104
+     *
105
+     * @var \OCP\Share_Backend
106
+     */
107
+    private $backend;
108
+
109
+    const TAG_TABLE = '*PREFIX*vcategory';
110
+    const RELATION_TABLE = '*PREFIX*vcategory_to_object';
111
+
112
+    const TAG_FAVORITE = '_$!<Favorite>!$_';
113
+
114
+    /**
115
+     * Constructor.
116
+     *
117
+     * @param TagMapper $mapper Instance of the TagMapper abstraction layer.
118
+     * @param string $user The user whose data the object will operate on.
119
+     * @param string $type The type of items for which tags will be loaded.
120
+     * @param array $defaultTags Tags that should be created at construction.
121
+     * @param boolean $includeShared Whether to include tags for items shared with this user by others.
122
+     */
123
+    public function __construct(TagMapper $mapper, $user, $type, $defaultTags = array(), $includeShared = false) {
124
+        $this->mapper = $mapper;
125
+        $this->user = $user;
126
+        $this->type = $type;
127
+        $this->includeShared = $includeShared;
128
+        $this->owners = array($this->user);
129
+        if ($this->includeShared) {
130
+            $this->owners = array_merge($this->owners, \OC\Share\Share::getSharedItemsOwners($this->user, $this->type, true));
131
+            $this->backend = \OC\Share\Share::getBackend($this->type);
132
+        }
133
+        $this->tags = $this->mapper->loadTags($this->owners, $this->type);
134
+
135
+        if(count($defaultTags) > 0 && count($this->tags) === 0) {
136
+            $this->addMultiple($defaultTags, true);
137
+        }
138
+    }
139
+
140
+    /**
141
+     * Check if any tags are saved for this type and user.
142
+     *
143
+     * @return boolean.
144
+     */
145
+    public function isEmpty() {
146
+        return count($this->tags) === 0;
147
+    }
148
+
149
+    /**
150
+     * Returns an array mapping a given tag's properties to its values:
151
+     * ['id' => 0, 'name' = 'Tag', 'owner' = 'User', 'type' => 'tagtype']
152
+     *
153
+     * @param string $id The ID of the tag that is going to be mapped
154
+     * @return array|false
155
+     */
156
+    public function getTag($id) {
157
+        $key = $this->getTagById($id);
158
+        if ($key !== false) {
159
+            return $this->tagMap($this->tags[$key]);
160
+        }
161
+        return false;
162
+    }
163
+
164
+    /**
165
+     * Get the tags for a specific user.
166
+     *
167
+     * This returns an array with maps containing each tag's properties:
168
+     * [
169
+     * 	['id' => 0, 'name' = 'First tag', 'owner' = 'User', 'type' => 'tagtype'],
170
+     * 	['id' => 1, 'name' = 'Shared tag', 'owner' = 'Other user', 'type' => 'tagtype'],
171
+     * ]
172
+     *
173
+     * @return array
174
+     */
175
+    public function getTags() {
176
+        if(!count($this->tags)) {
177
+            return array();
178
+        }
179
+
180
+        usort($this->tags, function($a, $b) {
181
+            return strnatcasecmp($a->getName(), $b->getName());
182
+        });
183
+        $tagMap = array();
184
+
185
+        foreach($this->tags as $tag) {
186
+            if($tag->getName() !== self::TAG_FAVORITE) {
187
+                $tagMap[] = $this->tagMap($tag);
188
+            }
189
+        }
190
+        return $tagMap;
191
+
192
+    }
193
+
194
+    /**
195
+     * Return only the tags owned by the given user, omitting any tags shared
196
+     * by other users.
197
+     *
198
+     * @param string $user The user whose tags are to be checked.
199
+     * @return array An array of Tag objects.
200
+     */
201
+    public function getTagsForUser($user) {
202
+        return array_filter($this->tags,
203
+            function($tag) use($user) {
204
+                return $tag->getOwner() === $user;
205
+            }
206
+        );
207
+    }
208
+
209
+    /**
210
+     * Get the list of tags for the given ids.
211
+     *
212
+     * @param array $objIds array of object ids
213
+     * @return array|boolean of tags id as key to array of tag names
214
+     * or false if an error occurred
215
+     */
216
+    public function getTagsForObjects(array $objIds) {
217
+        $entries = array();
218
+
219
+        try {
220
+            $conn = \OC::$server->getDatabaseConnection();
221
+            $chunks = array_chunk($objIds, 900, false);
222
+            foreach ($chunks as $chunk) {
223
+                $result = $conn->executeQuery(
224
+                    'SELECT `category`, `categoryid`, `objid` ' .
225
+                    'FROM `' . self::RELATION_TABLE . '` r, `' . self::TAG_TABLE . '` ' .
226
+                    'WHERE `categoryid` = `id` AND `uid` = ? AND r.`type` = ? AND `objid` IN (?)',
227
+                    array($this->user, $this->type, $chunk),
228
+                    array(null, null, IQueryBuilder::PARAM_INT_ARRAY)
229
+                );
230
+                while ($row = $result->fetch()) {
231
+                    $objId = (int)$row['objid'];
232
+                    if (!isset($entries[$objId])) {
233
+                        $entries[$objId] = array();
234
+                    }
235
+                    $entries[$objId][] = $row['category'];
236
+                }
237
+                if (\OCP\DB::isError($result)) {
238
+                    \OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
239
+                    return false;
240
+                }
241
+            }
242
+        } catch(\Exception $e) {
243
+            \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
244
+                \OCP\Util::ERROR);
245
+            return false;
246
+        }
247
+
248
+        return $entries;
249
+    }
250
+
251
+    /**
252
+     * Get the a list if items tagged with $tag.
253
+     *
254
+     * Throws an exception if the tag could not be found.
255
+     *
256
+     * @param string $tag Tag id or name.
257
+     * @return array|false An array of object ids or false on error.
258
+     * @throws \Exception
259
+     */
260
+    public function getIdsForTag($tag) {
261
+        $result = null;
262
+        $tagId = false;
263
+        if(is_numeric($tag)) {
264
+            $tagId = $tag;
265
+        } elseif(is_string($tag)) {
266
+            $tag = trim($tag);
267
+            if($tag === '') {
268
+                \OCP\Util::writeLog('core', __METHOD__.', Cannot use empty tag names', \OCP\Util::DEBUG);
269
+                return false;
270
+            }
271
+            $tagId = $this->getTagId($tag);
272
+        }
273
+
274
+        if($tagId === false) {
275
+            $l10n = \OC::$server->getL10N('core');
276
+            throw new \Exception(
277
+                $l10n->t('Could not find category "%s"', $tag)
278
+            );
279
+        }
280
+
281
+        $ids = array();
282
+        $sql = 'SELECT `objid` FROM `' . self::RELATION_TABLE
283
+            . '` WHERE `categoryid` = ?';
284
+
285
+        try {
286
+            $stmt = \OCP\DB::prepare($sql);
287
+            $result = $stmt->execute(array($tagId));
288
+            if (\OCP\DB::isError($result)) {
289
+                \OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
290
+                return false;
291
+            }
292
+        } catch(\Exception $e) {
293
+            \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
294
+                \OCP\Util::ERROR);
295
+            return false;
296
+        }
297
+
298
+        if(!is_null($result)) {
299
+            while( $row = $result->fetchRow()) {
300
+                $id = (int)$row['objid'];
301
+
302
+                if ($this->includeShared) {
303
+                    // We have to check if we are really allowed to access the
304
+                    // items that are tagged with $tag. To that end, we ask the
305
+                    // corresponding sharing backend if the item identified by $id
306
+                    // is owned by any of $this->owners.
307
+                    foreach ($this->owners as $owner) {
308
+                        if ($this->backend->isValidSource($id, $owner)) {
309
+                            $ids[] = $id;
310
+                            break;
311
+                        }
312
+                    }
313
+                } else {
314
+                    $ids[] = $id;
315
+                }
316
+            }
317
+        }
318
+
319
+        return $ids;
320
+    }
321
+
322
+    /**
323
+     * Checks whether a tag is saved for the given user,
324
+     * disregarding the ones shared with him or her.
325
+     *
326
+     * @param string $name The tag name to check for.
327
+     * @param string $user The user whose tags are to be checked.
328
+     * @return bool
329
+     */
330
+    public function userHasTag($name, $user) {
331
+        $key = $this->array_searchi($name, $this->getTagsForUser($user));
332
+        return ($key !== false) ? $this->tags[$key]->getId() : false;
333
+    }
334
+
335
+    /**
336
+     * Checks whether a tag is saved for or shared with the current user.
337
+     *
338
+     * @param string $name The tag name to check for.
339
+     * @return bool
340
+     */
341
+    public function hasTag($name) {
342
+        return $this->getTagId($name) !== false;
343
+    }
344
+
345
+    /**
346
+     * Add a new tag.
347
+     *
348
+     * @param string $name A string with a name of the tag
349
+     * @return false|int the id of the added tag or false on error.
350
+     */
351
+    public function add($name) {
352
+        $name = trim($name);
353
+
354
+        if($name === '') {
355
+            \OCP\Util::writeLog('core', __METHOD__.', Cannot add an empty tag', \OCP\Util::DEBUG);
356
+            return false;
357
+        }
358
+        if($this->userHasTag($name, $this->user)) {
359
+            \OCP\Util::writeLog('core', __METHOD__.', name: ' . $name. ' exists already', \OCP\Util::DEBUG);
360
+            return false;
361
+        }
362
+        try {
363
+            $tag = new Tag($this->user, $this->type, $name);
364
+            $tag = $this->mapper->insert($tag);
365
+            $this->tags[] = $tag;
366
+        } catch(\Exception $e) {
367
+            \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
368
+                \OCP\Util::ERROR);
369
+            return false;
370
+        }
371
+        \OCP\Util::writeLog('core', __METHOD__.', id: ' . $tag->getId(), \OCP\Util::DEBUG);
372
+        return $tag->getId();
373
+    }
374
+
375
+    /**
376
+     * Rename tag.
377
+     *
378
+     * @param string|integer $from The name or ID of the existing tag
379
+     * @param string $to The new name of the tag.
380
+     * @return bool
381
+     */
382
+    public function rename($from, $to) {
383
+        $from = trim($from);
384
+        $to = trim($to);
385
+
386
+        if($to === '' || $from === '') {
387
+            \OCP\Util::writeLog('core', __METHOD__.', Cannot use empty tag names', \OCP\Util::DEBUG);
388
+            return false;
389
+        }
390
+
391
+        if (is_numeric($from)) {
392
+            $key = $this->getTagById($from);
393
+        } else {
394
+            $key = $this->getTagByName($from);
395
+        }
396
+        if($key === false) {
397
+            \OCP\Util::writeLog('core', __METHOD__.', tag: ' . $from. ' does not exist', \OCP\Util::DEBUG);
398
+            return false;
399
+        }
400
+        $tag = $this->tags[$key];
401
+
402
+        if($this->userHasTag($to, $tag->getOwner())) {
403
+            \OCP\Util::writeLog('core', __METHOD__.', A tag named ' . $to. ' already exists for user ' . $tag->getOwner() . '.', \OCP\Util::DEBUG);
404
+            return false;
405
+        }
406
+
407
+        try {
408
+            $tag->setName($to);
409
+            $this->tags[$key] = $this->mapper->update($tag);
410
+        } catch(\Exception $e) {
411
+            \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
412
+                \OCP\Util::ERROR);
413
+            return false;
414
+        }
415
+        return true;
416
+    }
417
+
418
+    /**
419
+     * Add a list of new tags.
420
+     *
421
+     * @param string[] $names A string with a name or an array of strings containing
422
+     * the name(s) of the tag(s) to add.
423
+     * @param bool $sync When true, save the tags
424
+     * @param int|null $id int Optional object id to add to this|these tag(s)
425
+     * @return bool Returns false on error.
426
+     */
427
+    public function addMultiple($names, $sync=false, $id = null) {
428
+        if(!is_array($names)) {
429
+            $names = array($names);
430
+        }
431
+        $names = array_map('trim', $names);
432
+        array_filter($names);
433
+
434
+        $newones = array();
435
+        foreach($names as $name) {
436
+            if(!$this->hasTag($name) && $name !== '') {
437
+                $newones[] = new Tag($this->user, $this->type, $name);
438
+            }
439
+            if(!is_null($id) ) {
440
+                // Insert $objectid, $categoryid  pairs if not exist.
441
+                self::$relations[] = array('objid' => $id, 'tag' => $name);
442
+            }
443
+        }
444
+        $this->tags = array_merge($this->tags, $newones);
445
+        if($sync === true) {
446
+            $this->save();
447
+        }
448
+
449
+        return true;
450
+    }
451
+
452
+    /**
453
+     * Save the list of tags and their object relations
454
+     */
455
+    protected function save() {
456
+        if(is_array($this->tags)) {
457
+            foreach($this->tags as $tag) {
458
+                try {
459
+                    if (!$this->mapper->tagExists($tag)) {
460
+                        $this->mapper->insert($tag);
461
+                    }
462
+                } catch(\Exception $e) {
463
+                    \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
464
+                        \OCP\Util::ERROR);
465
+                }
466
+            }
467
+
468
+            // reload tags to get the proper ids.
469
+            $this->tags = $this->mapper->loadTags($this->owners, $this->type);
470
+            \OCP\Util::writeLog('core', __METHOD__.', tags: ' . print_r($this->tags, true),
471
+                \OCP\Util::DEBUG);
472
+            // Loop through temporarily cached objectid/tagname pairs
473
+            // and save relations.
474
+            $tags = $this->tags;
475
+            // For some reason this is needed or array_search(i) will return 0..?
476
+            ksort($tags);
477
+            foreach(self::$relations as $relation) {
478
+                $tagId = $this->getTagId($relation['tag']);
479
+                \OCP\Util::writeLog('core', __METHOD__ . 'catid, ' . $relation['tag'] . ' ' . $tagId, \OCP\Util::DEBUG);
480
+                if($tagId) {
481
+                    try {
482
+                        \OCP\DB::insertIfNotExist(self::RELATION_TABLE,
483
+                            array(
484
+                                'objid' => $relation['objid'],
485
+                                'categoryid' => $tagId,
486
+                                'type' => $this->type,
487
+                                ));
488
+                    } catch(\Exception $e) {
489
+                        \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
490
+                            \OCP\Util::ERROR);
491
+                    }
492
+                }
493
+            }
494
+            self::$relations = array(); // reset
495
+        } else {
496
+            \OCP\Util::writeLog('core', __METHOD__.', $this->tags is not an array! '
497
+                . print_r($this->tags, true), \OCP\Util::ERROR);
498
+        }
499
+    }
500
+
501
+    /**
502
+     * Delete tags and tag/object relations for a user.
503
+     *
504
+     * For hooking up on post_deleteUser
505
+     *
506
+     * @param array $arguments
507
+     */
508
+    public static function post_deleteUser($arguments) {
509
+        // Find all objectid/tagId pairs.
510
+        $result = null;
511
+        try {
512
+            $stmt = \OCP\DB::prepare('SELECT `id` FROM `' . self::TAG_TABLE . '` '
513
+                . 'WHERE `uid` = ?');
514
+            $result = $stmt->execute(array($arguments['uid']));
515
+            if (\OCP\DB::isError($result)) {
516
+                \OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
517
+            }
518
+        } catch(\Exception $e) {
519
+            \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
520
+                \OCP\Util::ERROR);
521
+        }
522
+
523
+        if(!is_null($result)) {
524
+            try {
525
+                $stmt = \OCP\DB::prepare('DELETE FROM `' . self::RELATION_TABLE . '` '
526
+                    . 'WHERE `categoryid` = ?');
527
+                while( $row = $result->fetchRow()) {
528
+                    try {
529
+                        $stmt->execute(array($row['id']));
530
+                    } catch(\Exception $e) {
531
+                        \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
532
+                            \OCP\Util::ERROR);
533
+                    }
534
+                }
535
+            } catch(\Exception $e) {
536
+                \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
537
+                    \OCP\Util::ERROR);
538
+            }
539
+        }
540
+        try {
541
+            $stmt = \OCP\DB::prepare('DELETE FROM `' . self::TAG_TABLE . '` '
542
+                . 'WHERE `uid` = ?');
543
+            $result = $stmt->execute(array($arguments['uid']));
544
+            if (\OCP\DB::isError($result)) {
545
+                \OCP\Util::writeLog('core', __METHOD__. ', DB error: ' . \OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
546
+            }
547
+        } catch(\Exception $e) {
548
+            \OCP\Util::writeLog('core', __METHOD__ . ', exception: '
549
+                . $e->getMessage(), \OCP\Util::ERROR);
550
+        }
551
+    }
552
+
553
+    /**
554
+     * Delete tag/object relations from the db
555
+     *
556
+     * @param array $ids The ids of the objects
557
+     * @return boolean Returns false on error.
558
+     */
559
+    public function purgeObjects(array $ids) {
560
+        if(count($ids) === 0) {
561
+            // job done ;)
562
+            return true;
563
+        }
564
+        $updates = $ids;
565
+        try {
566
+            $query = 'DELETE FROM `' . self::RELATION_TABLE . '` ';
567
+            $query .= 'WHERE `objid` IN (' . str_repeat('?,', count($ids)-1) . '?) ';
568
+            $query .= 'AND `type`= ?';
569
+            $updates[] = $this->type;
570
+            $stmt = \OCP\DB::prepare($query);
571
+            $result = $stmt->execute($updates);
572
+            if (\OCP\DB::isError($result)) {
573
+                \OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
574
+                return false;
575
+            }
576
+        } catch(\Exception $e) {
577
+            \OCP\Util::writeLog('core', __METHOD__.', exception: ' . $e->getMessage(),
578
+                \OCP\Util::ERROR);
579
+            return false;
580
+        }
581
+        return true;
582
+    }
583
+
584
+    /**
585
+     * Get favorites for an object type
586
+     *
587
+     * @return array|false An array of object ids.
588
+     */
589
+    public function getFavorites() {
590
+        try {
591
+            return $this->getIdsForTag(self::TAG_FAVORITE);
592
+        } catch(\Exception $e) {
593
+            \OCP\Util::writeLog('core', __METHOD__.', exception: ' . $e->getMessage(),
594
+                \OCP\Util::DEBUG);
595
+            return array();
596
+        }
597
+    }
598
+
599
+    /**
600
+     * Add an object to favorites
601
+     *
602
+     * @param int $objid The id of the object
603
+     * @return boolean
604
+     */
605
+    public function addToFavorites($objid) {
606
+        if(!$this->userHasTag(self::TAG_FAVORITE, $this->user)) {
607
+            $this->add(self::TAG_FAVORITE);
608
+        }
609
+        return $this->tagAs($objid, self::TAG_FAVORITE);
610
+    }
611
+
612
+    /**
613
+     * Remove an object from favorites
614
+     *
615
+     * @param int $objid The id of the object
616
+     * @return boolean
617
+     */
618
+    public function removeFromFavorites($objid) {
619
+        return $this->unTag($objid, self::TAG_FAVORITE);
620
+    }
621
+
622
+    /**
623
+     * Creates a tag/object relation.
624
+     *
625
+     * @param int $objid The id of the object
626
+     * @param string $tag The id or name of the tag
627
+     * @return boolean Returns false on error.
628
+     */
629
+    public function tagAs($objid, $tag) {
630
+        if(is_string($tag) && !is_numeric($tag)) {
631
+            $tag = trim($tag);
632
+            if($tag === '') {
633
+                \OCP\Util::writeLog('core', __METHOD__.', Cannot add an empty tag', \OCP\Util::DEBUG);
634
+                return false;
635
+            }
636
+            if(!$this->hasTag($tag)) {
637
+                $this->add($tag);
638
+            }
639
+            $tagId =  $this->getTagId($tag);
640
+        } else {
641
+            $tagId = $tag;
642
+        }
643
+        try {
644
+            \OCP\DB::insertIfNotExist(self::RELATION_TABLE,
645
+                array(
646
+                    'objid' => $objid,
647
+                    'categoryid' => $tagId,
648
+                    'type' => $this->type,
649
+                ));
650
+        } catch(\Exception $e) {
651
+            \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
652
+                \OCP\Util::ERROR);
653
+            return false;
654
+        }
655
+        return true;
656
+    }
657
+
658
+    /**
659
+     * Delete single tag/object relation from the db
660
+     *
661
+     * @param int $objid The id of the object
662
+     * @param string $tag The id or name of the tag
663
+     * @return boolean
664
+     */
665
+    public function unTag($objid, $tag) {
666
+        if(is_string($tag) && !is_numeric($tag)) {
667
+            $tag = trim($tag);
668
+            if($tag === '') {
669
+                \OCP\Util::writeLog('core', __METHOD__.', Tag name is empty', \OCP\Util::DEBUG);
670
+                return false;
671
+            }
672
+            $tagId =  $this->getTagId($tag);
673
+        } else {
674
+            $tagId = $tag;
675
+        }
676
+
677
+        try {
678
+            $sql = 'DELETE FROM `' . self::RELATION_TABLE . '` '
679
+                    . 'WHERE `objid` = ? AND `categoryid` = ? AND `type` = ?';
680
+            $stmt = \OCP\DB::prepare($sql);
681
+            $stmt->execute(array($objid, $tagId, $this->type));
682
+        } catch(\Exception $e) {
683
+            \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
684
+                \OCP\Util::ERROR);
685
+            return false;
686
+        }
687
+        return true;
688
+    }
689
+
690
+    /**
691
+     * Delete tags from the database.
692
+     *
693
+     * @param string[]|integer[] $names An array of tags (names or IDs) to delete
694
+     * @return bool Returns false on error
695
+     */
696
+    public function delete($names) {
697
+        if(!is_array($names)) {
698
+            $names = array($names);
699
+        }
700
+
701
+        $names = array_map('trim', $names);
702
+        array_filter($names);
703
+
704
+        \OCP\Util::writeLog('core', __METHOD__ . ', before: '
705
+            . print_r($this->tags, true), \OCP\Util::DEBUG);
706
+        foreach($names as $name) {
707
+            $id = null;
708
+
709
+            if (is_numeric($name)) {
710
+                $key = $this->getTagById($name);
711
+            } else {
712
+                $key = $this->getTagByName($name);
713
+            }
714
+            if ($key !== false) {
715
+                $tag = $this->tags[$key];
716
+                $id = $tag->getId();
717
+                unset($this->tags[$key]);
718
+                $this->mapper->delete($tag);
719
+            } else {
720
+                \OCP\Util::writeLog('core', __METHOD__ . 'Cannot delete tag ' . $name
721
+                    . ': not found.', \OCP\Util::ERROR);
722
+            }
723
+            if(!is_null($id) && $id !== false) {
724
+                try {
725
+                    $sql = 'DELETE FROM `' . self::RELATION_TABLE . '` '
726
+                            . 'WHERE `categoryid` = ?';
727
+                    $stmt = \OCP\DB::prepare($sql);
728
+                    $result = $stmt->execute(array($id));
729
+                    if (\OCP\DB::isError($result)) {
730
+                        \OCP\Util::writeLog('core',
731
+                            __METHOD__. 'DB error: ' . \OCP\DB::getErrorMessage(),
732
+                            \OCP\Util::ERROR);
733
+                        return false;
734
+                    }
735
+                } catch(\Exception $e) {
736
+                    \OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
737
+                        \OCP\Util::ERROR);
738
+                    return false;
739
+                }
740
+            }
741
+        }
742
+        return true;
743
+    }
744
+
745
+    // case-insensitive array_search
746
+    protected function array_searchi($needle, $haystack, $mem='getName') {
747
+        if(!is_array($haystack)) {
748
+            return false;
749
+        }
750
+        return array_search(strtolower($needle), array_map(
751
+            function($tag) use($mem) {
752
+                return strtolower(call_user_func(array($tag, $mem)));
753
+            }, $haystack)
754
+        );
755
+    }
756
+
757
+    /**
758
+     * Get a tag's ID.
759
+     *
760
+     * @param string $name The tag name to look for.
761
+     * @return string|bool The tag's id or false if no matching tag is found.
762
+     */
763
+    private function getTagId($name) {
764
+        $key = $this->array_searchi($name, $this->tags);
765
+        if ($key !== false) {
766
+            return $this->tags[$key]->getId();
767
+        }
768
+        return false;
769
+    }
770
+
771
+    /**
772
+     * Get a tag by its name.
773
+     *
774
+     * @param string $name The tag name.
775
+     * @return integer|bool The tag object's offset within the $this->tags
776
+     *                      array or false if it doesn't exist.
777
+     */
778
+    private function getTagByName($name) {
779
+        return $this->array_searchi($name, $this->tags, 'getName');
780
+    }
781
+
782
+    /**
783
+     * Get a tag by its ID.
784
+     *
785
+     * @param string $id The tag ID to look for.
786
+     * @return integer|bool The tag object's offset within the $this->tags
787
+     *                      array or false if it doesn't exist.
788
+     */
789
+    private function getTagById($id) {
790
+        return $this->array_searchi($id, $this->tags, 'getId');
791
+    }
792
+
793
+    /**
794
+     * Returns an array mapping a given tag's properties to its values:
795
+     * ['id' => 0, 'name' = 'Tag', 'owner' = 'User', 'type' => 'tagtype']
796
+     *
797
+     * @param Tag $tag The tag that is going to be mapped
798
+     * @return array
799
+     */
800
+    private function tagMap(Tag $tag) {
801
+        return array(
802
+            'id'    => $tag->getId(),
803
+            'name'  => $tag->getName(),
804
+            'owner' => $tag->getOwner(),
805
+            'type'  => $tag->getType()
806
+        );
807
+    }
808 808
 }
Please login to merge, or discard this patch.
Spacing   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 		}
133 133
 		$this->tags = $this->mapper->loadTags($this->owners, $this->type);
134 134
 
135
-		if(count($defaultTags) > 0 && count($this->tags) === 0) {
135
+		if (count($defaultTags) > 0 && count($this->tags) === 0) {
136 136
 			$this->addMultiple($defaultTags, true);
137 137
 		}
138 138
 	}
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 	* @return array
174 174
 	*/
175 175
 	public function getTags() {
176
-		if(!count($this->tags)) {
176
+		if (!count($this->tags)) {
177 177
 			return array();
178 178
 		}
179 179
 
@@ -182,8 +182,8 @@  discard block
 block discarded – undo
182 182
 		});
183 183
 		$tagMap = array();
184 184
 
185
-		foreach($this->tags as $tag) {
186
-			if($tag->getName() !== self::TAG_FAVORITE) {
185
+		foreach ($this->tags as $tag) {
186
+			if ($tag->getName() !== self::TAG_FAVORITE) {
187 187
 				$tagMap[] = $this->tagMap($tag);
188 188
 			}
189 189
 		}
@@ -221,25 +221,25 @@  discard block
 block discarded – undo
221 221
 			$chunks = array_chunk($objIds, 900, false);
222 222
 			foreach ($chunks as $chunk) {
223 223
 				$result = $conn->executeQuery(
224
-					'SELECT `category`, `categoryid`, `objid` ' .
225
-					'FROM `' . self::RELATION_TABLE . '` r, `' . self::TAG_TABLE . '` ' .
224
+					'SELECT `category`, `categoryid`, `objid` '.
225
+					'FROM `'.self::RELATION_TABLE.'` r, `'.self::TAG_TABLE.'` '.
226 226
 					'WHERE `categoryid` = `id` AND `uid` = ? AND r.`type` = ? AND `objid` IN (?)',
227 227
 					array($this->user, $this->type, $chunk),
228 228
 					array(null, null, IQueryBuilder::PARAM_INT_ARRAY)
229 229
 				);
230 230
 				while ($row = $result->fetch()) {
231
-					$objId = (int)$row['objid'];
231
+					$objId = (int) $row['objid'];
232 232
 					if (!isset($entries[$objId])) {
233 233
 						$entries[$objId] = array();
234 234
 					}
235 235
 					$entries[$objId][] = $row['category'];
236 236
 				}
237 237
 				if (\OCP\DB::isError($result)) {
238
-					\OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
238
+					\OCP\Util::writeLog('core', __METHOD__.'DB error: '.\OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
239 239
 					return false;
240 240
 				}
241 241
 			}
242
-		} catch(\Exception $e) {
242
+		} catch (\Exception $e) {
243 243
 			\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
244 244
 				\OCP\Util::ERROR);
245 245
 			return false;
@@ -260,18 +260,18 @@  discard block
 block discarded – undo
260 260
 	public function getIdsForTag($tag) {
261 261
 		$result = null;
262 262
 		$tagId = false;
263
-		if(is_numeric($tag)) {
263
+		if (is_numeric($tag)) {
264 264
 			$tagId = $tag;
265
-		} elseif(is_string($tag)) {
265
+		} elseif (is_string($tag)) {
266 266
 			$tag = trim($tag);
267
-			if($tag === '') {
267
+			if ($tag === '') {
268 268
 				\OCP\Util::writeLog('core', __METHOD__.', Cannot use empty tag names', \OCP\Util::DEBUG);
269 269
 				return false;
270 270
 			}
271 271
 			$tagId = $this->getTagId($tag);
272 272
 		}
273 273
 
274
-		if($tagId === false) {
274
+		if ($tagId === false) {
275 275
 			$l10n = \OC::$server->getL10N('core');
276 276
 			throw new \Exception(
277 277
 				$l10n->t('Could not find category "%s"', $tag)
@@ -279,25 +279,25 @@  discard block
 block discarded – undo
279 279
 		}
280 280
 
281 281
 		$ids = array();
282
-		$sql = 'SELECT `objid` FROM `' . self::RELATION_TABLE
282
+		$sql = 'SELECT `objid` FROM `'.self::RELATION_TABLE
283 283
 			. '` WHERE `categoryid` = ?';
284 284
 
285 285
 		try {
286 286
 			$stmt = \OCP\DB::prepare($sql);
287 287
 			$result = $stmt->execute(array($tagId));
288 288
 			if (\OCP\DB::isError($result)) {
289
-				\OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
289
+				\OCP\Util::writeLog('core', __METHOD__.'DB error: '.\OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
290 290
 				return false;
291 291
 			}
292
-		} catch(\Exception $e) {
292
+		} catch (\Exception $e) {
293 293
 			\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
294 294
 				\OCP\Util::ERROR);
295 295
 			return false;
296 296
 		}
297 297
 
298
-		if(!is_null($result)) {
299
-			while( $row = $result->fetchRow()) {
300
-				$id = (int)$row['objid'];
298
+		if (!is_null($result)) {
299
+			while ($row = $result->fetchRow()) {
300
+				$id = (int) $row['objid'];
301 301
 
302 302
 				if ($this->includeShared) {
303 303
 					// We have to check if we are really allowed to access the
@@ -351,24 +351,24 @@  discard block
 block discarded – undo
351 351
 	public function add($name) {
352 352
 		$name = trim($name);
353 353
 
354
-		if($name === '') {
354
+		if ($name === '') {
355 355
 			\OCP\Util::writeLog('core', __METHOD__.', Cannot add an empty tag', \OCP\Util::DEBUG);
356 356
 			return false;
357 357
 		}
358
-		if($this->userHasTag($name, $this->user)) {
359
-			\OCP\Util::writeLog('core', __METHOD__.', name: ' . $name. ' exists already', \OCP\Util::DEBUG);
358
+		if ($this->userHasTag($name, $this->user)) {
359
+			\OCP\Util::writeLog('core', __METHOD__.', name: '.$name.' exists already', \OCP\Util::DEBUG);
360 360
 			return false;
361 361
 		}
362 362
 		try {
363 363
 			$tag = new Tag($this->user, $this->type, $name);
364 364
 			$tag = $this->mapper->insert($tag);
365 365
 			$this->tags[] = $tag;
366
-		} catch(\Exception $e) {
366
+		} catch (\Exception $e) {
367 367
 			\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
368 368
 				\OCP\Util::ERROR);
369 369
 			return false;
370 370
 		}
371
-		\OCP\Util::writeLog('core', __METHOD__.', id: ' . $tag->getId(), \OCP\Util::DEBUG);
371
+		\OCP\Util::writeLog('core', __METHOD__.', id: '.$tag->getId(), \OCP\Util::DEBUG);
372 372
 		return $tag->getId();
373 373
 	}
374 374
 
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
 		$from = trim($from);
384 384
 		$to = trim($to);
385 385
 
386
-		if($to === '' || $from === '') {
386
+		if ($to === '' || $from === '') {
387 387
 			\OCP\Util::writeLog('core', __METHOD__.', Cannot use empty tag names', \OCP\Util::DEBUG);
388 388
 			return false;
389 389
 		}
@@ -393,21 +393,21 @@  discard block
 block discarded – undo
393 393
 		} else {
394 394
 			$key = $this->getTagByName($from);
395 395
 		}
396
-		if($key === false) {
397
-			\OCP\Util::writeLog('core', __METHOD__.', tag: ' . $from. ' does not exist', \OCP\Util::DEBUG);
396
+		if ($key === false) {
397
+			\OCP\Util::writeLog('core', __METHOD__.', tag: '.$from.' does not exist', \OCP\Util::DEBUG);
398 398
 			return false;
399 399
 		}
400 400
 		$tag = $this->tags[$key];
401 401
 
402
-		if($this->userHasTag($to, $tag->getOwner())) {
403
-			\OCP\Util::writeLog('core', __METHOD__.', A tag named ' . $to. ' already exists for user ' . $tag->getOwner() . '.', \OCP\Util::DEBUG);
402
+		if ($this->userHasTag($to, $tag->getOwner())) {
403
+			\OCP\Util::writeLog('core', __METHOD__.', A tag named '.$to.' already exists for user '.$tag->getOwner().'.', \OCP\Util::DEBUG);
404 404
 			return false;
405 405
 		}
406 406
 
407 407
 		try {
408 408
 			$tag->setName($to);
409 409
 			$this->tags[$key] = $this->mapper->update($tag);
410
-		} catch(\Exception $e) {
410
+		} catch (\Exception $e) {
411 411
 			\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
412 412
 				\OCP\Util::ERROR);
413 413
 			return false;
@@ -424,25 +424,25 @@  discard block
 block discarded – undo
424 424
 	* @param int|null $id int Optional object id to add to this|these tag(s)
425 425
 	* @return bool Returns false on error.
426 426
 	*/
427
-	public function addMultiple($names, $sync=false, $id = null) {
428
-		if(!is_array($names)) {
427
+	public function addMultiple($names, $sync = false, $id = null) {
428
+		if (!is_array($names)) {
429 429
 			$names = array($names);
430 430
 		}
431 431
 		$names = array_map('trim', $names);
432 432
 		array_filter($names);
433 433
 
434 434
 		$newones = array();
435
-		foreach($names as $name) {
436
-			if(!$this->hasTag($name) && $name !== '') {
435
+		foreach ($names as $name) {
436
+			if (!$this->hasTag($name) && $name !== '') {
437 437
 				$newones[] = new Tag($this->user, $this->type, $name);
438 438
 			}
439
-			if(!is_null($id) ) {
439
+			if (!is_null($id)) {
440 440
 				// Insert $objectid, $categoryid  pairs if not exist.
441 441
 				self::$relations[] = array('objid' => $id, 'tag' => $name);
442 442
 			}
443 443
 		}
444 444
 		$this->tags = array_merge($this->tags, $newones);
445
-		if($sync === true) {
445
+		if ($sync === true) {
446 446
 			$this->save();
447 447
 		}
448 448
 
@@ -453,13 +453,13 @@  discard block
 block discarded – undo
453 453
 	 * Save the list of tags and their object relations
454 454
 	 */
455 455
 	protected function save() {
456
-		if(is_array($this->tags)) {
457
-			foreach($this->tags as $tag) {
456
+		if (is_array($this->tags)) {
457
+			foreach ($this->tags as $tag) {
458 458
 				try {
459 459
 					if (!$this->mapper->tagExists($tag)) {
460 460
 						$this->mapper->insert($tag);
461 461
 					}
462
-				} catch(\Exception $e) {
462
+				} catch (\Exception $e) {
463 463
 					\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
464 464
 						\OCP\Util::ERROR);
465 465
 				}
@@ -467,17 +467,17 @@  discard block
 block discarded – undo
467 467
 
468 468
 			// reload tags to get the proper ids.
469 469
 			$this->tags = $this->mapper->loadTags($this->owners, $this->type);
470
-			\OCP\Util::writeLog('core', __METHOD__.', tags: ' . print_r($this->tags, true),
470
+			\OCP\Util::writeLog('core', __METHOD__.', tags: '.print_r($this->tags, true),
471 471
 				\OCP\Util::DEBUG);
472 472
 			// Loop through temporarily cached objectid/tagname pairs
473 473
 			// and save relations.
474 474
 			$tags = $this->tags;
475 475
 			// For some reason this is needed or array_search(i) will return 0..?
476 476
 			ksort($tags);
477
-			foreach(self::$relations as $relation) {
477
+			foreach (self::$relations as $relation) {
478 478
 				$tagId = $this->getTagId($relation['tag']);
479
-				\OCP\Util::writeLog('core', __METHOD__ . 'catid, ' . $relation['tag'] . ' ' . $tagId, \OCP\Util::DEBUG);
480
-				if($tagId) {
479
+				\OCP\Util::writeLog('core', __METHOD__.'catid, '.$relation['tag'].' '.$tagId, \OCP\Util::DEBUG);
480
+				if ($tagId) {
481 481
 					try {
482 482
 						\OCP\DB::insertIfNotExist(self::RELATION_TABLE,
483 483
 							array(
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
 								'categoryid' => $tagId,
486 486
 								'type' => $this->type,
487 487
 								));
488
-					} catch(\Exception $e) {
488
+					} catch (\Exception $e) {
489 489
 						\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
490 490
 							\OCP\Util::ERROR);
491 491
 					}
@@ -509,43 +509,43 @@  discard block
 block discarded – undo
509 509
 		// Find all objectid/tagId pairs.
510 510
 		$result = null;
511 511
 		try {
512
-			$stmt = \OCP\DB::prepare('SELECT `id` FROM `' . self::TAG_TABLE . '` '
512
+			$stmt = \OCP\DB::prepare('SELECT `id` FROM `'.self::TAG_TABLE.'` '
513 513
 				. 'WHERE `uid` = ?');
514 514
 			$result = $stmt->execute(array($arguments['uid']));
515 515
 			if (\OCP\DB::isError($result)) {
516
-				\OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
516
+				\OCP\Util::writeLog('core', __METHOD__.'DB error: '.\OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
517 517
 			}
518
-		} catch(\Exception $e) {
518
+		} catch (\Exception $e) {
519 519
 			\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
520 520
 				\OCP\Util::ERROR);
521 521
 		}
522 522
 
523
-		if(!is_null($result)) {
523
+		if (!is_null($result)) {
524 524
 			try {
525
-				$stmt = \OCP\DB::prepare('DELETE FROM `' . self::RELATION_TABLE . '` '
525
+				$stmt = \OCP\DB::prepare('DELETE FROM `'.self::RELATION_TABLE.'` '
526 526
 					. 'WHERE `categoryid` = ?');
527
-				while( $row = $result->fetchRow()) {
527
+				while ($row = $result->fetchRow()) {
528 528
 					try {
529 529
 						$stmt->execute(array($row['id']));
530
-					} catch(\Exception $e) {
530
+					} catch (\Exception $e) {
531 531
 						\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
532 532
 							\OCP\Util::ERROR);
533 533
 					}
534 534
 				}
535
-			} catch(\Exception $e) {
535
+			} catch (\Exception $e) {
536 536
 				\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
537 537
 					\OCP\Util::ERROR);
538 538
 			}
539 539
 		}
540 540
 		try {
541
-			$stmt = \OCP\DB::prepare('DELETE FROM `' . self::TAG_TABLE . '` '
541
+			$stmt = \OCP\DB::prepare('DELETE FROM `'.self::TAG_TABLE.'` '
542 542
 				. 'WHERE `uid` = ?');
543 543
 			$result = $stmt->execute(array($arguments['uid']));
544 544
 			if (\OCP\DB::isError($result)) {
545
-				\OCP\Util::writeLog('core', __METHOD__. ', DB error: ' . \OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
545
+				\OCP\Util::writeLog('core', __METHOD__.', DB error: '.\OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
546 546
 			}
547
-		} catch(\Exception $e) {
548
-			\OCP\Util::writeLog('core', __METHOD__ . ', exception: '
547
+		} catch (\Exception $e) {
548
+			\OCP\Util::writeLog('core', __METHOD__.', exception: '
549 549
 				. $e->getMessage(), \OCP\Util::ERROR);
550 550
 		}
551 551
 	}
@@ -557,24 +557,24 @@  discard block
 block discarded – undo
557 557
 	* @return boolean Returns false on error.
558 558
 	*/
559 559
 	public function purgeObjects(array $ids) {
560
-		if(count($ids) === 0) {
560
+		if (count($ids) === 0) {
561 561
 			// job done ;)
562 562
 			return true;
563 563
 		}
564 564
 		$updates = $ids;
565 565
 		try {
566
-			$query = 'DELETE FROM `' . self::RELATION_TABLE . '` ';
567
-			$query .= 'WHERE `objid` IN (' . str_repeat('?,', count($ids)-1) . '?) ';
566
+			$query = 'DELETE FROM `'.self::RELATION_TABLE.'` ';
567
+			$query .= 'WHERE `objid` IN ('.str_repeat('?,', count($ids) - 1).'?) ';
568 568
 			$query .= 'AND `type`= ?';
569 569
 			$updates[] = $this->type;
570 570
 			$stmt = \OCP\DB::prepare($query);
571 571
 			$result = $stmt->execute($updates);
572 572
 			if (\OCP\DB::isError($result)) {
573
-				\OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
573
+				\OCP\Util::writeLog('core', __METHOD__.'DB error: '.\OCP\DB::getErrorMessage(), \OCP\Util::ERROR);
574 574
 				return false;
575 575
 			}
576
-		} catch(\Exception $e) {
577
-			\OCP\Util::writeLog('core', __METHOD__.', exception: ' . $e->getMessage(),
576
+		} catch (\Exception $e) {
577
+			\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
578 578
 				\OCP\Util::ERROR);
579 579
 			return false;
580 580
 		}
@@ -589,8 +589,8 @@  discard block
 block discarded – undo
589 589
 	public function getFavorites() {
590 590
 		try {
591 591
 			return $this->getIdsForTag(self::TAG_FAVORITE);
592
-		} catch(\Exception $e) {
593
-			\OCP\Util::writeLog('core', __METHOD__.', exception: ' . $e->getMessage(),
592
+		} catch (\Exception $e) {
593
+			\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
594 594
 				\OCP\Util::DEBUG);
595 595
 			return array();
596 596
 		}
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
 	* @return boolean
604 604
 	*/
605 605
 	public function addToFavorites($objid) {
606
-		if(!$this->userHasTag(self::TAG_FAVORITE, $this->user)) {
606
+		if (!$this->userHasTag(self::TAG_FAVORITE, $this->user)) {
607 607
 			$this->add(self::TAG_FAVORITE);
608 608
 		}
609 609
 		return $this->tagAs($objid, self::TAG_FAVORITE);
@@ -627,16 +627,16 @@  discard block
 block discarded – undo
627 627
 	* @return boolean Returns false on error.
628 628
 	*/
629 629
 	public function tagAs($objid, $tag) {
630
-		if(is_string($tag) && !is_numeric($tag)) {
630
+		if (is_string($tag) && !is_numeric($tag)) {
631 631
 			$tag = trim($tag);
632
-			if($tag === '') {
632
+			if ($tag === '') {
633 633
 				\OCP\Util::writeLog('core', __METHOD__.', Cannot add an empty tag', \OCP\Util::DEBUG);
634 634
 				return false;
635 635
 			}
636
-			if(!$this->hasTag($tag)) {
636
+			if (!$this->hasTag($tag)) {
637 637
 				$this->add($tag);
638 638
 			}
639
-			$tagId =  $this->getTagId($tag);
639
+			$tagId = $this->getTagId($tag);
640 640
 		} else {
641 641
 			$tagId = $tag;
642 642
 		}
@@ -647,7 +647,7 @@  discard block
 block discarded – undo
647 647
 					'categoryid' => $tagId,
648 648
 					'type' => $this->type,
649 649
 				));
650
-		} catch(\Exception $e) {
650
+		} catch (\Exception $e) {
651 651
 			\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
652 652
 				\OCP\Util::ERROR);
653 653
 			return false;
@@ -663,23 +663,23 @@  discard block
 block discarded – undo
663 663
 	* @return boolean
664 664
 	*/
665 665
 	public function unTag($objid, $tag) {
666
-		if(is_string($tag) && !is_numeric($tag)) {
666
+		if (is_string($tag) && !is_numeric($tag)) {
667 667
 			$tag = trim($tag);
668
-			if($tag === '') {
668
+			if ($tag === '') {
669 669
 				\OCP\Util::writeLog('core', __METHOD__.', Tag name is empty', \OCP\Util::DEBUG);
670 670
 				return false;
671 671
 			}
672
-			$tagId =  $this->getTagId($tag);
672
+			$tagId = $this->getTagId($tag);
673 673
 		} else {
674 674
 			$tagId = $tag;
675 675
 		}
676 676
 
677 677
 		try {
678
-			$sql = 'DELETE FROM `' . self::RELATION_TABLE . '` '
678
+			$sql = 'DELETE FROM `'.self::RELATION_TABLE.'` '
679 679
 					. 'WHERE `objid` = ? AND `categoryid` = ? AND `type` = ?';
680 680
 			$stmt = \OCP\DB::prepare($sql);
681 681
 			$stmt->execute(array($objid, $tagId, $this->type));
682
-		} catch(\Exception $e) {
682
+		} catch (\Exception $e) {
683 683
 			\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
684 684
 				\OCP\Util::ERROR);
685 685
 			return false;
@@ -694,16 +694,16 @@  discard block
 block discarded – undo
694 694
 	* @return bool Returns false on error
695 695
 	*/
696 696
 	public function delete($names) {
697
-		if(!is_array($names)) {
697
+		if (!is_array($names)) {
698 698
 			$names = array($names);
699 699
 		}
700 700
 
701 701
 		$names = array_map('trim', $names);
702 702
 		array_filter($names);
703 703
 
704
-		\OCP\Util::writeLog('core', __METHOD__ . ', before: '
704
+		\OCP\Util::writeLog('core', __METHOD__.', before: '
705 705
 			. print_r($this->tags, true), \OCP\Util::DEBUG);
706
-		foreach($names as $name) {
706
+		foreach ($names as $name) {
707 707
 			$id = null;
708 708
 
709 709
 			if (is_numeric($name)) {
@@ -717,22 +717,22 @@  discard block
 block discarded – undo
717 717
 				unset($this->tags[$key]);
718 718
 				$this->mapper->delete($tag);
719 719
 			} else {
720
-				\OCP\Util::writeLog('core', __METHOD__ . 'Cannot delete tag ' . $name
720
+				\OCP\Util::writeLog('core', __METHOD__.'Cannot delete tag '.$name
721 721
 					. ': not found.', \OCP\Util::ERROR);
722 722
 			}
723
-			if(!is_null($id) && $id !== false) {
723
+			if (!is_null($id) && $id !== false) {
724 724
 				try {
725
-					$sql = 'DELETE FROM `' . self::RELATION_TABLE . '` '
725
+					$sql = 'DELETE FROM `'.self::RELATION_TABLE.'` '
726 726
 							. 'WHERE `categoryid` = ?';
727 727
 					$stmt = \OCP\DB::prepare($sql);
728 728
 					$result = $stmt->execute(array($id));
729 729
 					if (\OCP\DB::isError($result)) {
730 730
 						\OCP\Util::writeLog('core',
731
-							__METHOD__. 'DB error: ' . \OCP\DB::getErrorMessage(),
731
+							__METHOD__.'DB error: '.\OCP\DB::getErrorMessage(),
732 732
 							\OCP\Util::ERROR);
733 733
 						return false;
734 734
 					}
735
-				} catch(\Exception $e) {
735
+				} catch (\Exception $e) {
736 736
 					\OCP\Util::writeLog('core', __METHOD__.', exception: '.$e->getMessage(),
737 737
 						\OCP\Util::ERROR);
738 738
 					return false;
@@ -743,8 +743,8 @@  discard block
 block discarded – undo
743 743
 	}
744 744
 
745 745
 	// case-insensitive array_search
746
-	protected function array_searchi($needle, $haystack, $mem='getName') {
747
-		if(!is_array($haystack)) {
746
+	protected function array_searchi($needle, $haystack, $mem = 'getName') {
747
+		if (!is_array($haystack)) {
748 748
 			return false;
749 749
 		}
750 750
 		return array_search(strtolower($needle), array_map(
Please login to merge, or discard this patch.
lib/private/Template/Base.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -103,7 +103,7 @@
 block discarded – undo
103 103
 	/**
104 104
 	 * Appends a variable
105 105
 	 * @param string $key key
106
-	 * @param mixed $value value
106
+	 * @param string $value value
107 107
 	 * @return boolean|null
108 108
 	 *
109 109
 	 * This function assigns a variable in an array context. If the key already
Please login to merge, or discard this patch.
Indentation   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -29,158 +29,158 @@
 block discarded – undo
29 29
 namespace OC\Template;
30 30
 
31 31
 class Base {
32
-	private $template; // The template
33
-	private $vars; // Vars
34
-
35
-	/** @var \OCP\IL10N */
36
-	private $l10n;
37
-
38
-	/** @var \OC_Defaults */
39
-	private $theme;
40
-
41
-	/**
42
-	 * @param string $template
43
-	 * @param string $requestToken
44
-	 * @param \OCP\IL10N $l10n
45
-	 * @param \OC_Defaults $theme
46
-	 */
47
-	public function __construct($template, $requestToken, $l10n, $theme ) {
48
-		$this->vars = array();
49
-		$this->vars['requesttoken'] = $requestToken;
50
-		$this->l10n = $l10n;
51
-		$this->template = $template;
52
-		$this->theme = $theme;
53
-	}
54
-
55
-	/**
56
-	 * @param string $serverRoot
57
-	 * @param string|false $app_dir
58
-	 * @param string $theme
59
-	 * @param string $app
60
-	 * @return string[]
61
-	 */
62
-	protected function getAppTemplateDirs($theme, $app, $serverRoot, $app_dir) {
63
-		// Check if the app is in the app folder or in the root
64
-		if( file_exists($app_dir.'/templates/' )) {
65
-			return [
66
-				$serverRoot.'/themes/'.$theme.'/apps/'.$app.'/templates/',
67
-				$app_dir.'/templates/',
68
-			];
69
-		}
70
-		return [
71
-			$serverRoot.'/themes/'.$theme.'/'.$app.'/templates/',
72
-			$serverRoot.'/'.$app.'/templates/',
73
-		];
74
-	}
75
-
76
-	/**
77
-	 * @param string $serverRoot
78
-	 * @param string $theme
79
-	 * @return string[]
80
-	 */
81
-	protected function getCoreTemplateDirs($theme, $serverRoot) {
82
-		return [
83
-			$serverRoot.'/themes/'.$theme.'/core/templates/',
84
-			$serverRoot.'/core/templates/',
85
-		];
86
-	}
87
-
88
-	/**
89
-	 * Assign variables
90
-	 * @param string $key key
91
-	 * @param array|bool|integer|string $value value
92
-	 * @return bool
93
-	 *
94
-	 * This function assigns a variable. It can be accessed via $_[$key] in
95
-	 * the template.
96
-	 *
97
-	 * If the key existed before, it will be overwritten
98
-	 */
99
-	public function assign( $key, $value) {
100
-		$this->vars[$key] = $value;
101
-		return true;
102
-	}
103
-
104
-	/**
105
-	 * Appends a variable
106
-	 * @param string $key key
107
-	 * @param mixed $value value
108
-	 * @return boolean|null
109
-	 *
110
-	 * This function assigns a variable in an array context. If the key already
111
-	 * exists, the value will be appended. It can be accessed via
112
-	 * $_[$key][$position] in the template.
113
-	 */
114
-	public function append( $key, $value ) {
115
-		if( array_key_exists( $key, $this->vars )) {
116
-			$this->vars[$key][] = $value;
117
-		}
118
-		else{
119
-			$this->vars[$key] = array( $value );
120
-		}
121
-	}
122
-
123
-	/**
124
-	 * Prints the proceeded template
125
-	 * @return bool
126
-	 *
127
-	 * This function proceeds the template and prints its output.
128
-	 */
129
-	public function printPage() {
130
-		$data = $this->fetchPage();
131
-		if( $data === false ) {
132
-			return false;
133
-		}
134
-		else{
135
-			print $data;
136
-			return true;
137
-		}
138
-	}
139
-
140
-	/**
141
-	 * Process the template
142
-	 *
143
-	 * @param array|null $additionalParams
144
-	 * @return string This function processes the template.
145
-	 *
146
-	 * This function processes the template.
147
-	 */
148
-	public function fetchPage($additionalParams = null) {
149
-		return $this->load($this->template, $additionalParams);
150
-	}
151
-
152
-	/**
153
-	 * doing the actual work
154
-	 *
155
-	 * @param string $file
156
-	 * @param array|null $additionalParams
157
-	 * @return string content
158
-	 *
159
-	 * Includes the template file, fetches its output
160
-	 */
161
-	protected function load($file, $additionalParams = null) {
162
-		// Register the variables
163
-		$_ = $this->vars;
164
-		$l = $this->l10n;
165
-		$theme = $this->theme;
166
-
167
-		if( !is_null($additionalParams)) {
168
-			$_ = array_merge( $additionalParams, $this->vars );
169
-		}
170
-
171
-		// Include
172
-		ob_start();
173
-		try {
174
-			include $file;
175
-			$data = ob_get_contents();
176
-		} catch (\Exception $e) {
177
-			@ob_end_clean();
178
-			throw $e;
179
-		}
180
-		@ob_end_clean();
181
-
182
-		// Return data
183
-		return $data;
184
-	}
32
+    private $template; // The template
33
+    private $vars; // Vars
34
+
35
+    /** @var \OCP\IL10N */
36
+    private $l10n;
37
+
38
+    /** @var \OC_Defaults */
39
+    private $theme;
40
+
41
+    /**
42
+     * @param string $template
43
+     * @param string $requestToken
44
+     * @param \OCP\IL10N $l10n
45
+     * @param \OC_Defaults $theme
46
+     */
47
+    public function __construct($template, $requestToken, $l10n, $theme ) {
48
+        $this->vars = array();
49
+        $this->vars['requesttoken'] = $requestToken;
50
+        $this->l10n = $l10n;
51
+        $this->template = $template;
52
+        $this->theme = $theme;
53
+    }
54
+
55
+    /**
56
+     * @param string $serverRoot
57
+     * @param string|false $app_dir
58
+     * @param string $theme
59
+     * @param string $app
60
+     * @return string[]
61
+     */
62
+    protected function getAppTemplateDirs($theme, $app, $serverRoot, $app_dir) {
63
+        // Check if the app is in the app folder or in the root
64
+        if( file_exists($app_dir.'/templates/' )) {
65
+            return [
66
+                $serverRoot.'/themes/'.$theme.'/apps/'.$app.'/templates/',
67
+                $app_dir.'/templates/',
68
+            ];
69
+        }
70
+        return [
71
+            $serverRoot.'/themes/'.$theme.'/'.$app.'/templates/',
72
+            $serverRoot.'/'.$app.'/templates/',
73
+        ];
74
+    }
75
+
76
+    /**
77
+     * @param string $serverRoot
78
+     * @param string $theme
79
+     * @return string[]
80
+     */
81
+    protected function getCoreTemplateDirs($theme, $serverRoot) {
82
+        return [
83
+            $serverRoot.'/themes/'.$theme.'/core/templates/',
84
+            $serverRoot.'/core/templates/',
85
+        ];
86
+    }
87
+
88
+    /**
89
+     * Assign variables
90
+     * @param string $key key
91
+     * @param array|bool|integer|string $value value
92
+     * @return bool
93
+     *
94
+     * This function assigns a variable. It can be accessed via $_[$key] in
95
+     * the template.
96
+     *
97
+     * If the key existed before, it will be overwritten
98
+     */
99
+    public function assign( $key, $value) {
100
+        $this->vars[$key] = $value;
101
+        return true;
102
+    }
103
+
104
+    /**
105
+     * Appends a variable
106
+     * @param string $key key
107
+     * @param mixed $value value
108
+     * @return boolean|null
109
+     *
110
+     * This function assigns a variable in an array context. If the key already
111
+     * exists, the value will be appended. It can be accessed via
112
+     * $_[$key][$position] in the template.
113
+     */
114
+    public function append( $key, $value ) {
115
+        if( array_key_exists( $key, $this->vars )) {
116
+            $this->vars[$key][] = $value;
117
+        }
118
+        else{
119
+            $this->vars[$key] = array( $value );
120
+        }
121
+    }
122
+
123
+    /**
124
+     * Prints the proceeded template
125
+     * @return bool
126
+     *
127
+     * This function proceeds the template and prints its output.
128
+     */
129
+    public function printPage() {
130
+        $data = $this->fetchPage();
131
+        if( $data === false ) {
132
+            return false;
133
+        }
134
+        else{
135
+            print $data;
136
+            return true;
137
+        }
138
+    }
139
+
140
+    /**
141
+     * Process the template
142
+     *
143
+     * @param array|null $additionalParams
144
+     * @return string This function processes the template.
145
+     *
146
+     * This function processes the template.
147
+     */
148
+    public function fetchPage($additionalParams = null) {
149
+        return $this->load($this->template, $additionalParams);
150
+    }
151
+
152
+    /**
153
+     * doing the actual work
154
+     *
155
+     * @param string $file
156
+     * @param array|null $additionalParams
157
+     * @return string content
158
+     *
159
+     * Includes the template file, fetches its output
160
+     */
161
+    protected function load($file, $additionalParams = null) {
162
+        // Register the variables
163
+        $_ = $this->vars;
164
+        $l = $this->l10n;
165
+        $theme = $this->theme;
166
+
167
+        if( !is_null($additionalParams)) {
168
+            $_ = array_merge( $additionalParams, $this->vars );
169
+        }
170
+
171
+        // Include
172
+        ob_start();
173
+        try {
174
+            include $file;
175
+            $data = ob_get_contents();
176
+        } catch (\Exception $e) {
177
+            @ob_end_clean();
178
+            throw $e;
179
+        }
180
+        @ob_end_clean();
181
+
182
+        // Return data
183
+        return $data;
184
+    }
185 185
 
186 186
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 	 * @param \OCP\IL10N $l10n
45 45
 	 * @param \OC_Defaults $theme
46 46
 	 */
47
-	public function __construct($template, $requestToken, $l10n, $theme ) {
47
+	public function __construct($template, $requestToken, $l10n, $theme) {
48 48
 		$this->vars = array();
49 49
 		$this->vars['requesttoken'] = $requestToken;
50 50
 		$this->l10n = $l10n;
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	 */
62 62
 	protected function getAppTemplateDirs($theme, $app, $serverRoot, $app_dir) {
63 63
 		// Check if the app is in the app folder or in the root
64
-		if( file_exists($app_dir.'/templates/' )) {
64
+		if (file_exists($app_dir.'/templates/')) {
65 65
 			return [
66 66
 				$serverRoot.'/themes/'.$theme.'/apps/'.$app.'/templates/',
67 67
 				$app_dir.'/templates/',
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	 *
97 97
 	 * If the key existed before, it will be overwritten
98 98
 	 */
99
-	public function assign( $key, $value) {
99
+	public function assign($key, $value) {
100 100
 		$this->vars[$key] = $value;
101 101
 		return true;
102 102
 	}
@@ -111,12 +111,12 @@  discard block
 block discarded – undo
111 111
 	 * exists, the value will be appended. It can be accessed via
112 112
 	 * $_[$key][$position] in the template.
113 113
 	 */
114
-	public function append( $key, $value ) {
115
-		if( array_key_exists( $key, $this->vars )) {
114
+	public function append($key, $value) {
115
+		if (array_key_exists($key, $this->vars)) {
116 116
 			$this->vars[$key][] = $value;
117 117
 		}
118
-		else{
119
-			$this->vars[$key] = array( $value );
118
+		else {
119
+			$this->vars[$key] = array($value);
120 120
 		}
121 121
 	}
122 122
 
@@ -128,10 +128,10 @@  discard block
 block discarded – undo
128 128
 	 */
129 129
 	public function printPage() {
130 130
 		$data = $this->fetchPage();
131
-		if( $data === false ) {
131
+		if ($data === false) {
132 132
 			return false;
133 133
 		}
134
-		else{
134
+		else {
135 135
 			print $data;
136 136
 			return true;
137 137
 		}
@@ -164,8 +164,8 @@  discard block
 block discarded – undo
164 164
 		$l = $this->l10n;
165 165
 		$theme = $this->theme;
166 166
 
167
-		if( !is_null($additionalParams)) {
168
-			$_ = array_merge( $additionalParams, $this->vars );
167
+		if (!is_null($additionalParams)) {
168
+			$_ = array_merge($additionalParams, $this->vars);
169 169
 		}
170 170
 
171 171
 		// Include
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -114,8 +114,7 @@  discard block
 block discarded – undo
114 114
 	public function append( $key, $value ) {
115 115
 		if( array_key_exists( $key, $this->vars )) {
116 116
 			$this->vars[$key][] = $value;
117
-		}
118
-		else{
117
+		} else{
119 118
 			$this->vars[$key] = array( $value );
120 119
 		}
121 120
 	}
@@ -130,8 +129,7 @@  discard block
 block discarded – undo
130 129
 		$data = $this->fetchPage();
131 130
 		if( $data === false ) {
132 131
 			return false;
133
-		}
134
-		else{
132
+		} else{
135 133
 			print $data;
136 134
 			return true;
137 135
 		}
Please login to merge, or discard this patch.
lib/public/App/ManagerEvent.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@
 block discarded – undo
46 46
 	 * DispatcherEvent constructor.
47 47
 	 *
48 48
 	 * @param string $event
49
-	 * @param $appID
49
+	 * @param string $appID
50 50
 	 * @param \OCP\IGroup[] $groups
51 51
 	 * @since 9.0.0
52 52
 	 */
Please login to merge, or discard this patch.
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -32,61 +32,61 @@
 block discarded – undo
32 32
  */
33 33
 class ManagerEvent extends Event {
34 34
 
35
-	const EVENT_APP_ENABLE = 'OCP\App\IAppManager::enableApp';
36
-	const EVENT_APP_ENABLE_FOR_GROUPS = 'OCP\App\IAppManager::enableAppForGroups';
37
-	const EVENT_APP_DISABLE = 'OCP\App\IAppManager::disableApp';
35
+    const EVENT_APP_ENABLE = 'OCP\App\IAppManager::enableApp';
36
+    const EVENT_APP_ENABLE_FOR_GROUPS = 'OCP\App\IAppManager::enableAppForGroups';
37
+    const EVENT_APP_DISABLE = 'OCP\App\IAppManager::disableApp';
38 38
 
39
-	/**
40
-	 * @since 9.1.0
41
-	 */
42
-	const EVENT_APP_UPDATE = 'OCP\App\IAppManager::updateApp';
39
+    /**
40
+     * @since 9.1.0
41
+     */
42
+    const EVENT_APP_UPDATE = 'OCP\App\IAppManager::updateApp';
43 43
 
44
-	/** @var string */
45
-	protected $event;
46
-	/** @var string */
47
-	protected $appID;
48
-	/** @var \OCP\IGroup[] */
49
-	protected $groups;
44
+    /** @var string */
45
+    protected $event;
46
+    /** @var string */
47
+    protected $appID;
48
+    /** @var \OCP\IGroup[] */
49
+    protected $groups;
50 50
 
51
-	/**
52
-	 * DispatcherEvent constructor.
53
-	 *
54
-	 * @param string $event
55
-	 * @param $appID
56
-	 * @param \OCP\IGroup[] $groups
57
-	 * @since 9.0.0
58
-	 */
59
-	public function __construct($event, $appID, array $groups = null) {
60
-		$this->event = $event;
61
-		$this->appID = $appID;
62
-		$this->groups = $groups;
63
-	}
51
+    /**
52
+     * DispatcherEvent constructor.
53
+     *
54
+     * @param string $event
55
+     * @param $appID
56
+     * @param \OCP\IGroup[] $groups
57
+     * @since 9.0.0
58
+     */
59
+    public function __construct($event, $appID, array $groups = null) {
60
+        $this->event = $event;
61
+        $this->appID = $appID;
62
+        $this->groups = $groups;
63
+    }
64 64
 
65
-	/**
66
-	 * @return string
67
-	 * @since 9.0.0
68
-	 */
69
-	public function getEvent() {
70
-		return $this->event;
71
-	}
65
+    /**
66
+     * @return string
67
+     * @since 9.0.0
68
+     */
69
+    public function getEvent() {
70
+        return $this->event;
71
+    }
72 72
 
73
-	/**
74
-	 * @return string
75
-	 * @since 9.0.0
76
-	 */
77
-	public function getAppID() {
78
-		return $this->appID;
79
-	}
73
+    /**
74
+     * @return string
75
+     * @since 9.0.0
76
+     */
77
+    public function getAppID() {
78
+        return $this->appID;
79
+    }
80 80
 
81
-	/**
82
-	 * returns the group Ids
83
-	 * @return string[]
84
-	 * @since 9.0.0
85
-	 */
86
-	public function getGroups() {
87
-		return array_map(function ($group) {
88
-			/** @var \OCP\IGroup $group */
89
-			return $group->getGID();
90
-		}, $this->groups);
91
-	}
81
+    /**
82
+     * returns the group Ids
83
+     * @return string[]
84
+     * @since 9.0.0
85
+     */
86
+    public function getGroups() {
87
+        return array_map(function ($group) {
88
+            /** @var \OCP\IGroup $group */
89
+            return $group->getGID();
90
+        }, $this->groups);
91
+    }
92 92
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@
 block discarded – undo
84 84
 	 * @since 9.0.0
85 85
 	 */
86 86
 	public function getGroups() {
87
-		return array_map(function ($group) {
87
+		return array_map(function($group) {
88 88
 			/** @var \OCP\IGroup $group */
89 89
 			return $group->getGID();
90 90
 		}, $this->groups);
Please login to merge, or discard this patch.
lib/public/AppFramework/Db/Mapper.php 3 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -308,6 +308,7 @@  discard block
 block discarded – undo
308 308
 	 * @param array $params the parameters of the sql query
309 309
 	 * @param int $limit the maximum number of rows
310 310
 	 * @param int $offset from which row we want to start
311
+	 * @param string $msg
311 312
 	 * @return string formatted error message string
312 313
 	 * @since 9.1.0
313 314
 	 */
@@ -360,7 +361,7 @@  discard block
 block discarded – undo
360 361
 	 * Returns an db result and throws exceptions when there are more or less
361 362
 	 * results
362 363
 	 * @param string $sql the sql query
363
-	 * @param array $params the parameters of the sql query
364
+	 * @param string[] $params the parameters of the sql query
364 365
 	 * @param int $limit the maximum number of rows
365 366
 	 * @param int $offset from which row we want to start
366 367
 	 * @throws DoesNotExistException if the item does not exist
Please login to merge, or discard this patch.
Indentation   +334 added lines, -334 removed lines patch added patch discarded remove patch
@@ -38,340 +38,340 @@
 block discarded – undo
38 38
  */
39 39
 abstract class Mapper {
40 40
 
41
-	protected $tableName;
42
-	protected $entityClass;
43
-	protected $db;
44
-
45
-	/**
46
-	 * @param IDBConnection $db Instance of the Db abstraction layer
47
-	 * @param string $tableName the name of the table. set this to allow entity
48
-	 * @param string $entityClass the name of the entity that the sql should be
49
-	 * mapped to queries without using sql
50
-	 * @since 7.0.0
51
-	 */
52
-	public function __construct(IDBConnection $db, $tableName, $entityClass=null){
53
-		$this->db = $db;
54
-		$this->tableName = '*PREFIX*' . $tableName;
55
-
56
-		// if not given set the entity name to the class without the mapper part
57
-		// cache it here for later use since reflection is slow
58
-		if($entityClass === null) {
59
-			$this->entityClass = str_replace('Mapper', '', get_class($this));
60
-		} else {
61
-			$this->entityClass = $entityClass;
62
-		}
63
-	}
64
-
65
-
66
-	/**
67
-	 * @return string the table name
68
-	 * @since 7.0.0
69
-	 */
70
-	public function getTableName(){
71
-		return $this->tableName;
72
-	}
73
-
74
-
75
-	/**
76
-	 * Deletes an entity from the table
77
-	 * @param Entity $entity the entity that should be deleted
78
-	 * @return Entity the deleted entity
79
-	 * @since 7.0.0 - return value added in 8.1.0
80
-	 */
81
-	public function delete(Entity $entity){
82
-		$sql = 'DELETE FROM `' . $this->tableName . '` WHERE `id` = ?';
83
-		$stmt = $this->execute($sql, [$entity->getId()]);
84
-		$stmt->closeCursor();
85
-		return $entity;
86
-	}
87
-
88
-
89
-	/**
90
-	 * Creates a new entry in the db from an entity
91
-	 * @param Entity $entity the entity that should be created
92
-	 * @return Entity the saved entity with the set id
93
-	 * @since 7.0.0
94
-	 */
95
-	public function insert(Entity $entity){
96
-		// get updated fields to save, fields have to be set using a setter to
97
-		// be saved
98
-		$properties = $entity->getUpdatedFields();
99
-		$values = '';
100
-		$columns = '';
101
-		$params = [];
102
-
103
-		// build the fields
104
-		$i = 0;
105
-		foreach($properties as $property => $updated) {
106
-			$column = $entity->propertyToColumn($property);
107
-			$getter = 'get' . ucfirst($property);
108
-
109
-			$columns .= '`' . $column . '`';
110
-			$values .= '?';
111
-
112
-			// only append colon if there are more entries
113
-			if($i < count($properties)-1){
114
-				$columns .= ',';
115
-				$values .= ',';
116
-			}
117
-
118
-			$params[] = $entity->$getter();
119
-			$i++;
120
-
121
-		}
122
-
123
-		$sql = 'INSERT INTO `' . $this->tableName . '`(' .
124
-				$columns . ') VALUES(' . $values . ')';
125
-
126
-		$stmt = $this->execute($sql, $params);
127
-
128
-		$entity->setId((int) $this->db->lastInsertId($this->tableName));
129
-
130
-		$stmt->closeCursor();
131
-
132
-		return $entity;
133
-	}
134
-
135
-
136
-
137
-	/**
138
-	 * Updates an entry in the db from an entity
139
-	 * @throws \InvalidArgumentException if entity has no id
140
-	 * @param Entity $entity the entity that should be created
141
-	 * @return Entity the saved entity with the set id
142
-	 * @since 7.0.0 - return value was added in 8.0.0
143
-	 */
144
-	public function update(Entity $entity){
145
-		// if entity wasn't changed it makes no sense to run a db query
146
-		$properties = $entity->getUpdatedFields();
147
-		if(count($properties) === 0) {
148
-			return $entity;
149
-		}
150
-
151
-		// entity needs an id
152
-		$id = $entity->getId();
153
-		if($id === null){
154
-			throw new \InvalidArgumentException(
155
-				'Entity which should be updated has no id');
156
-		}
157
-
158
-		// get updated fields to save, fields have to be set using a setter to
159
-		// be saved
160
-		// do not update the id field
161
-		unset($properties['id']);
162
-
163
-		$columns = '';
164
-		$params = [];
165
-
166
-		// build the fields
167
-		$i = 0;
168
-		foreach($properties as $property => $updated) {
169
-
170
-			$column = $entity->propertyToColumn($property);
171
-			$getter = 'get' . ucfirst($property);
172
-
173
-			$columns .= '`' . $column . '` = ?';
174
-
175
-			// only append colon if there are more entries
176
-			if($i < count($properties)-1){
177
-				$columns .= ',';
178
-			}
179
-
180
-			$params[] = $entity->$getter();
181
-			$i++;
182
-		}
183
-
184
-		$sql = 'UPDATE `' . $this->tableName . '` SET ' .
185
-				$columns . ' WHERE `id` = ?';
186
-		$params[] = $id;
187
-
188
-		$stmt = $this->execute($sql, $params);
189
-		$stmt->closeCursor();
190
-
191
-		return $entity;
192
-	}
193
-
194
-	/**
195
-	 * Checks if an array is associative
196
-	 * @param array $array
197
-	 * @return bool true if associative
198
-	 * @since 8.1.0
199
-	 */
200
-	private function isAssocArray(array $array) {
201
-		return array_values($array) !== $array;
202
-	}
203
-
204
-	/**
205
-	 * Returns the correct PDO constant based on the value type
206
-	 * @param $value
207
-	 * @return int PDO constant
208
-	 * @since 8.1.0
209
-	 */
210
-	private function getPDOType($value) {
211
-		switch (gettype($value)) {
212
-			case 'integer':
213
-				return \PDO::PARAM_INT;
214
-			case 'boolean':
215
-				return \PDO::PARAM_BOOL;
216
-			default:
217
-				return \PDO::PARAM_STR;
218
-		}
219
-	}
220
-
221
-
222
-	/**
223
-	 * Runs an sql query
224
-	 * @param string $sql the prepare string
225
-	 * @param array $params the params which should replace the ? in the sql query
226
-	 * @param int $limit the maximum number of rows
227
-	 * @param int $offset from which row we want to start
228
-	 * @return \PDOStatement the database query result
229
-	 * @since 7.0.0
230
-	 */
231
-	protected function execute($sql, array $params=[], $limit=null, $offset=null){
232
-		if ($this->db instanceof IDb) {
233
-			$query = $this->db->prepareQuery($sql, $limit, $offset);
234
-		} else {
235
-			$query = $this->db->prepare($sql, $limit, $offset);
236
-		}
237
-
238
-		if ($this->isAssocArray($params)) {
239
-			foreach ($params as $key => $param) {
240
-				$pdoConstant = $this->getPDOType($param);
241
-				$query->bindValue($key, $param, $pdoConstant);
242
-			}
243
-		} else {
244
-			$index = 1;  // bindParam is 1 indexed
245
-			foreach ($params as $param) {
246
-				$pdoConstant = $this->getPDOType($param);
247
-				$query->bindValue($index, $param, $pdoConstant);
248
-				$index++;
249
-			}
250
-		}
251
-
252
-		$result = $query->execute();
253
-
254
-		// this is only for backwards compatibility reasons and can be removed
255
-		// in owncloud 10. IDb returns a StatementWrapper from execute, PDO,
256
-		// Doctrine and IDbConnection don't so this needs to be done in order
257
-		// to stay backwards compatible for the things that rely on the
258
-		// StatementWrapper being returned
259
-		if ($result instanceof \OC_DB_StatementWrapper) {
260
-			return $result;
261
-		}
262
-
263
-		return $query;
264
-	}
265
-
266
-
267
-	/**
268
-	 * Returns an db result and throws exceptions when there are more or less
269
-	 * results
270
-	 * @see findEntity
271
-	 * @param string $sql the sql query
272
-	 * @param array $params the parameters of the sql query
273
-	 * @param int $limit the maximum number of rows
274
-	 * @param int $offset from which row we want to start
275
-	 * @throws DoesNotExistException if the item does not exist
276
-	 * @throws MultipleObjectsReturnedException if more than one item exist
277
-	 * @return array the result as row
278
-	 * @since 7.0.0
279
-	 */
280
-	protected function findOneQuery($sql, array $params=[], $limit=null, $offset=null){
281
-		$stmt = $this->execute($sql, $params, $limit, $offset);
282
-		$row = $stmt->fetch();
283
-
284
-		if($row === false || $row === null){
285
-			$stmt->closeCursor();
286
-			$msg = $this->buildDebugMessage(
287
-				'Did expect one result but found none when executing', $sql, $params, $limit, $offset
288
-			);
289
-			throw new DoesNotExistException($msg);
290
-		}
291
-		$row2 = $stmt->fetch();
292
-		$stmt->closeCursor();
293
-		//MDB2 returns null, PDO and doctrine false when no row is available
294
-		if( ! ($row2 === false || $row2 === null )) {
295
-			$msg = $this->buildDebugMessage(
296
-				'Did not expect more than one result when executing', $sql, $params, $limit, $offset
297
-			);
298
-			throw new MultipleObjectsReturnedException($msg);
299
-		} else {
300
-			return $row;
301
-		}
302
-	}
303
-
304
-	/**
305
-	 * Builds an error message by prepending the $msg to an error message which
306
-	 * has the parameters
307
-	 * @see findEntity
308
-	 * @param string $sql the sql query
309
-	 * @param array $params the parameters of the sql query
310
-	 * @param int $limit the maximum number of rows
311
-	 * @param int $offset from which row we want to start
312
-	 * @return string formatted error message string
313
-	 * @since 9.1.0
314
-	 */
315
-	private function buildDebugMessage($msg, $sql, array $params=[], $limit=null, $offset=null) {
316
-		return $msg .
317
-					': query "' .	$sql . '"; ' .
318
-					'parameters ' . print_r($params, true) . '; ' .
319
-					'limit "' . $limit . '"; '.
320
-					'offset "' . $offset . '"';
321
-	}
322
-
323
-
324
-	/**
325
-	 * Creates an entity from a row. Automatically determines the entity class
326
-	 * from the current mapper name (MyEntityMapper -> MyEntity)
327
-	 * @param array $row the row which should be converted to an entity
328
-	 * @return Entity the entity
329
-	 * @since 7.0.0
330
-	 */
331
-	protected function mapRowToEntity($row) {
332
-		return call_user_func($this->entityClass .'::fromRow', $row);
333
-	}
334
-
335
-
336
-	/**
337
-	 * Runs a sql query and returns an array of entities
338
-	 * @param string $sql the prepare string
339
-	 * @param array $params the params which should replace the ? in the sql query
340
-	 * @param int $limit the maximum number of rows
341
-	 * @param int $offset from which row we want to start
342
-	 * @return array all fetched entities
343
-	 * @since 7.0.0
344
-	 */
345
-	protected function findEntities($sql, array $params=[], $limit=null, $offset=null) {
346
-		$stmt = $this->execute($sql, $params, $limit, $offset);
347
-
348
-		$entities = [];
349
-
350
-		while($row = $stmt->fetch()){
351
-			$entities[] = $this->mapRowToEntity($row);
352
-		}
353
-
354
-		$stmt->closeCursor();
355
-
356
-		return $entities;
357
-	}
358
-
359
-
360
-	/**
361
-	 * Returns an db result and throws exceptions when there are more or less
362
-	 * results
363
-	 * @param string $sql the sql query
364
-	 * @param array $params the parameters of the sql query
365
-	 * @param int $limit the maximum number of rows
366
-	 * @param int $offset from which row we want to start
367
-	 * @throws DoesNotExistException if the item does not exist
368
-	 * @throws MultipleObjectsReturnedException if more than one item exist
369
-	 * @return Entity the entity
370
-	 * @since 7.0.0
371
-	 */
372
-	protected function findEntity($sql, array $params=[], $limit=null, $offset=null){
373
-		return $this->mapRowToEntity($this->findOneQuery($sql, $params, $limit, $offset));
374
-	}
41
+    protected $tableName;
42
+    protected $entityClass;
43
+    protected $db;
44
+
45
+    /**
46
+     * @param IDBConnection $db Instance of the Db abstraction layer
47
+     * @param string $tableName the name of the table. set this to allow entity
48
+     * @param string $entityClass the name of the entity that the sql should be
49
+     * mapped to queries without using sql
50
+     * @since 7.0.0
51
+     */
52
+    public function __construct(IDBConnection $db, $tableName, $entityClass=null){
53
+        $this->db = $db;
54
+        $this->tableName = '*PREFIX*' . $tableName;
55
+
56
+        // if not given set the entity name to the class without the mapper part
57
+        // cache it here for later use since reflection is slow
58
+        if($entityClass === null) {
59
+            $this->entityClass = str_replace('Mapper', '', get_class($this));
60
+        } else {
61
+            $this->entityClass = $entityClass;
62
+        }
63
+    }
64
+
65
+
66
+    /**
67
+     * @return string the table name
68
+     * @since 7.0.0
69
+     */
70
+    public function getTableName(){
71
+        return $this->tableName;
72
+    }
73
+
74
+
75
+    /**
76
+     * Deletes an entity from the table
77
+     * @param Entity $entity the entity that should be deleted
78
+     * @return Entity the deleted entity
79
+     * @since 7.0.0 - return value added in 8.1.0
80
+     */
81
+    public function delete(Entity $entity){
82
+        $sql = 'DELETE FROM `' . $this->tableName . '` WHERE `id` = ?';
83
+        $stmt = $this->execute($sql, [$entity->getId()]);
84
+        $stmt->closeCursor();
85
+        return $entity;
86
+    }
87
+
88
+
89
+    /**
90
+     * Creates a new entry in the db from an entity
91
+     * @param Entity $entity the entity that should be created
92
+     * @return Entity the saved entity with the set id
93
+     * @since 7.0.0
94
+     */
95
+    public function insert(Entity $entity){
96
+        // get updated fields to save, fields have to be set using a setter to
97
+        // be saved
98
+        $properties = $entity->getUpdatedFields();
99
+        $values = '';
100
+        $columns = '';
101
+        $params = [];
102
+
103
+        // build the fields
104
+        $i = 0;
105
+        foreach($properties as $property => $updated) {
106
+            $column = $entity->propertyToColumn($property);
107
+            $getter = 'get' . ucfirst($property);
108
+
109
+            $columns .= '`' . $column . '`';
110
+            $values .= '?';
111
+
112
+            // only append colon if there are more entries
113
+            if($i < count($properties)-1){
114
+                $columns .= ',';
115
+                $values .= ',';
116
+            }
117
+
118
+            $params[] = $entity->$getter();
119
+            $i++;
120
+
121
+        }
122
+
123
+        $sql = 'INSERT INTO `' . $this->tableName . '`(' .
124
+                $columns . ') VALUES(' . $values . ')';
125
+
126
+        $stmt = $this->execute($sql, $params);
127
+
128
+        $entity->setId((int) $this->db->lastInsertId($this->tableName));
129
+
130
+        $stmt->closeCursor();
131
+
132
+        return $entity;
133
+    }
134
+
135
+
136
+
137
+    /**
138
+     * Updates an entry in the db from an entity
139
+     * @throws \InvalidArgumentException if entity has no id
140
+     * @param Entity $entity the entity that should be created
141
+     * @return Entity the saved entity with the set id
142
+     * @since 7.0.0 - return value was added in 8.0.0
143
+     */
144
+    public function update(Entity $entity){
145
+        // if entity wasn't changed it makes no sense to run a db query
146
+        $properties = $entity->getUpdatedFields();
147
+        if(count($properties) === 0) {
148
+            return $entity;
149
+        }
150
+
151
+        // entity needs an id
152
+        $id = $entity->getId();
153
+        if($id === null){
154
+            throw new \InvalidArgumentException(
155
+                'Entity which should be updated has no id');
156
+        }
157
+
158
+        // get updated fields to save, fields have to be set using a setter to
159
+        // be saved
160
+        // do not update the id field
161
+        unset($properties['id']);
162
+
163
+        $columns = '';
164
+        $params = [];
165
+
166
+        // build the fields
167
+        $i = 0;
168
+        foreach($properties as $property => $updated) {
169
+
170
+            $column = $entity->propertyToColumn($property);
171
+            $getter = 'get' . ucfirst($property);
172
+
173
+            $columns .= '`' . $column . '` = ?';
174
+
175
+            // only append colon if there are more entries
176
+            if($i < count($properties)-1){
177
+                $columns .= ',';
178
+            }
179
+
180
+            $params[] = $entity->$getter();
181
+            $i++;
182
+        }
183
+
184
+        $sql = 'UPDATE `' . $this->tableName . '` SET ' .
185
+                $columns . ' WHERE `id` = ?';
186
+        $params[] = $id;
187
+
188
+        $stmt = $this->execute($sql, $params);
189
+        $stmt->closeCursor();
190
+
191
+        return $entity;
192
+    }
193
+
194
+    /**
195
+     * Checks if an array is associative
196
+     * @param array $array
197
+     * @return bool true if associative
198
+     * @since 8.1.0
199
+     */
200
+    private function isAssocArray(array $array) {
201
+        return array_values($array) !== $array;
202
+    }
203
+
204
+    /**
205
+     * Returns the correct PDO constant based on the value type
206
+     * @param $value
207
+     * @return int PDO constant
208
+     * @since 8.1.0
209
+     */
210
+    private function getPDOType($value) {
211
+        switch (gettype($value)) {
212
+            case 'integer':
213
+                return \PDO::PARAM_INT;
214
+            case 'boolean':
215
+                return \PDO::PARAM_BOOL;
216
+            default:
217
+                return \PDO::PARAM_STR;
218
+        }
219
+    }
220
+
221
+
222
+    /**
223
+     * Runs an sql query
224
+     * @param string $sql the prepare string
225
+     * @param array $params the params which should replace the ? in the sql query
226
+     * @param int $limit the maximum number of rows
227
+     * @param int $offset from which row we want to start
228
+     * @return \PDOStatement the database query result
229
+     * @since 7.0.0
230
+     */
231
+    protected function execute($sql, array $params=[], $limit=null, $offset=null){
232
+        if ($this->db instanceof IDb) {
233
+            $query = $this->db->prepareQuery($sql, $limit, $offset);
234
+        } else {
235
+            $query = $this->db->prepare($sql, $limit, $offset);
236
+        }
237
+
238
+        if ($this->isAssocArray($params)) {
239
+            foreach ($params as $key => $param) {
240
+                $pdoConstant = $this->getPDOType($param);
241
+                $query->bindValue($key, $param, $pdoConstant);
242
+            }
243
+        } else {
244
+            $index = 1;  // bindParam is 1 indexed
245
+            foreach ($params as $param) {
246
+                $pdoConstant = $this->getPDOType($param);
247
+                $query->bindValue($index, $param, $pdoConstant);
248
+                $index++;
249
+            }
250
+        }
251
+
252
+        $result = $query->execute();
253
+
254
+        // this is only for backwards compatibility reasons and can be removed
255
+        // in owncloud 10. IDb returns a StatementWrapper from execute, PDO,
256
+        // Doctrine and IDbConnection don't so this needs to be done in order
257
+        // to stay backwards compatible for the things that rely on the
258
+        // StatementWrapper being returned
259
+        if ($result instanceof \OC_DB_StatementWrapper) {
260
+            return $result;
261
+        }
262
+
263
+        return $query;
264
+    }
265
+
266
+
267
+    /**
268
+     * Returns an db result and throws exceptions when there are more or less
269
+     * results
270
+     * @see findEntity
271
+     * @param string $sql the sql query
272
+     * @param array $params the parameters of the sql query
273
+     * @param int $limit the maximum number of rows
274
+     * @param int $offset from which row we want to start
275
+     * @throws DoesNotExistException if the item does not exist
276
+     * @throws MultipleObjectsReturnedException if more than one item exist
277
+     * @return array the result as row
278
+     * @since 7.0.0
279
+     */
280
+    protected function findOneQuery($sql, array $params=[], $limit=null, $offset=null){
281
+        $stmt = $this->execute($sql, $params, $limit, $offset);
282
+        $row = $stmt->fetch();
283
+
284
+        if($row === false || $row === null){
285
+            $stmt->closeCursor();
286
+            $msg = $this->buildDebugMessage(
287
+                'Did expect one result but found none when executing', $sql, $params, $limit, $offset
288
+            );
289
+            throw new DoesNotExistException($msg);
290
+        }
291
+        $row2 = $stmt->fetch();
292
+        $stmt->closeCursor();
293
+        //MDB2 returns null, PDO and doctrine false when no row is available
294
+        if( ! ($row2 === false || $row2 === null )) {
295
+            $msg = $this->buildDebugMessage(
296
+                'Did not expect more than one result when executing', $sql, $params, $limit, $offset
297
+            );
298
+            throw new MultipleObjectsReturnedException($msg);
299
+        } else {
300
+            return $row;
301
+        }
302
+    }
303
+
304
+    /**
305
+     * Builds an error message by prepending the $msg to an error message which
306
+     * has the parameters
307
+     * @see findEntity
308
+     * @param string $sql the sql query
309
+     * @param array $params the parameters of the sql query
310
+     * @param int $limit the maximum number of rows
311
+     * @param int $offset from which row we want to start
312
+     * @return string formatted error message string
313
+     * @since 9.1.0
314
+     */
315
+    private function buildDebugMessage($msg, $sql, array $params=[], $limit=null, $offset=null) {
316
+        return $msg .
317
+                    ': query "' .	$sql . '"; ' .
318
+                    'parameters ' . print_r($params, true) . '; ' .
319
+                    'limit "' . $limit . '"; '.
320
+                    'offset "' . $offset . '"';
321
+    }
322
+
323
+
324
+    /**
325
+     * Creates an entity from a row. Automatically determines the entity class
326
+     * from the current mapper name (MyEntityMapper -> MyEntity)
327
+     * @param array $row the row which should be converted to an entity
328
+     * @return Entity the entity
329
+     * @since 7.0.0
330
+     */
331
+    protected function mapRowToEntity($row) {
332
+        return call_user_func($this->entityClass .'::fromRow', $row);
333
+    }
334
+
335
+
336
+    /**
337
+     * Runs a sql query and returns an array of entities
338
+     * @param string $sql the prepare string
339
+     * @param array $params the params which should replace the ? in the sql query
340
+     * @param int $limit the maximum number of rows
341
+     * @param int $offset from which row we want to start
342
+     * @return array all fetched entities
343
+     * @since 7.0.0
344
+     */
345
+    protected function findEntities($sql, array $params=[], $limit=null, $offset=null) {
346
+        $stmt = $this->execute($sql, $params, $limit, $offset);
347
+
348
+        $entities = [];
349
+
350
+        while($row = $stmt->fetch()){
351
+            $entities[] = $this->mapRowToEntity($row);
352
+        }
353
+
354
+        $stmt->closeCursor();
355
+
356
+        return $entities;
357
+    }
358
+
359
+
360
+    /**
361
+     * Returns an db result and throws exceptions when there are more or less
362
+     * results
363
+     * @param string $sql the sql query
364
+     * @param array $params the parameters of the sql query
365
+     * @param int $limit the maximum number of rows
366
+     * @param int $offset from which row we want to start
367
+     * @throws DoesNotExistException if the item does not exist
368
+     * @throws MultipleObjectsReturnedException if more than one item exist
369
+     * @return Entity the entity
370
+     * @since 7.0.0
371
+     */
372
+    protected function findEntity($sql, array $params=[], $limit=null, $offset=null){
373
+        return $this->mapRowToEntity($this->findOneQuery($sql, $params, $limit, $offset));
374
+    }
375 375
 
376 376
 
377 377
 }
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -49,13 +49,13 @@  discard block
 block discarded – undo
49 49
 	 * mapped to queries without using sql
50 50
 	 * @since 7.0.0
51 51
 	 */
52
-	public function __construct(IDBConnection $db, $tableName, $entityClass=null){
52
+	public function __construct(IDBConnection $db, $tableName, $entityClass = null) {
53 53
 		$this->db = $db;
54
-		$this->tableName = '*PREFIX*' . $tableName;
54
+		$this->tableName = '*PREFIX*'.$tableName;
55 55
 
56 56
 		// if not given set the entity name to the class without the mapper part
57 57
 		// cache it here for later use since reflection is slow
58
-		if($entityClass === null) {
58
+		if ($entityClass === null) {
59 59
 			$this->entityClass = str_replace('Mapper', '', get_class($this));
60 60
 		} else {
61 61
 			$this->entityClass = $entityClass;
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	 * @return string the table name
68 68
 	 * @since 7.0.0
69 69
 	 */
70
-	public function getTableName(){
70
+	public function getTableName() {
71 71
 		return $this->tableName;
72 72
 	}
73 73
 
@@ -78,8 +78,8 @@  discard block
 block discarded – undo
78 78
 	 * @return Entity the deleted entity
79 79
 	 * @since 7.0.0 - return value added in 8.1.0
80 80
 	 */
81
-	public function delete(Entity $entity){
82
-		$sql = 'DELETE FROM `' . $this->tableName . '` WHERE `id` = ?';
81
+	public function delete(Entity $entity) {
82
+		$sql = 'DELETE FROM `'.$this->tableName.'` WHERE `id` = ?';
83 83
 		$stmt = $this->execute($sql, [$entity->getId()]);
84 84
 		$stmt->closeCursor();
85 85
 		return $entity;
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 	 * @return Entity the saved entity with the set id
93 93
 	 * @since 7.0.0
94 94
 	 */
95
-	public function insert(Entity $entity){
95
+	public function insert(Entity $entity) {
96 96
 		// get updated fields to save, fields have to be set using a setter to
97 97
 		// be saved
98 98
 		$properties = $entity->getUpdatedFields();
@@ -102,15 +102,15 @@  discard block
 block discarded – undo
102 102
 
103 103
 		// build the fields
104 104
 		$i = 0;
105
-		foreach($properties as $property => $updated) {
105
+		foreach ($properties as $property => $updated) {
106 106
 			$column = $entity->propertyToColumn($property);
107
-			$getter = 'get' . ucfirst($property);
107
+			$getter = 'get'.ucfirst($property);
108 108
 
109
-			$columns .= '`' . $column . '`';
109
+			$columns .= '`'.$column.'`';
110 110
 			$values .= '?';
111 111
 
112 112
 			// only append colon if there are more entries
113
-			if($i < count($properties)-1){
113
+			if ($i < count($properties) - 1) {
114 114
 				$columns .= ',';
115 115
 				$values .= ',';
116 116
 			}
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
 
121 121
 		}
122 122
 
123
-		$sql = 'INSERT INTO `' . $this->tableName . '`(' .
124
-				$columns . ') VALUES(' . $values . ')';
123
+		$sql = 'INSERT INTO `'.$this->tableName.'`('.
124
+				$columns.') VALUES('.$values.')';
125 125
 
126 126
 		$stmt = $this->execute($sql, $params);
127 127
 
@@ -141,16 +141,16 @@  discard block
 block discarded – undo
141 141
 	 * @return Entity the saved entity with the set id
142 142
 	 * @since 7.0.0 - return value was added in 8.0.0
143 143
 	 */
144
-	public function update(Entity $entity){
144
+	public function update(Entity $entity) {
145 145
 		// if entity wasn't changed it makes no sense to run a db query
146 146
 		$properties = $entity->getUpdatedFields();
147
-		if(count($properties) === 0) {
147
+		if (count($properties) === 0) {
148 148
 			return $entity;
149 149
 		}
150 150
 
151 151
 		// entity needs an id
152 152
 		$id = $entity->getId();
153
-		if($id === null){
153
+		if ($id === null) {
154 154
 			throw new \InvalidArgumentException(
155 155
 				'Entity which should be updated has no id');
156 156
 		}
@@ -165,15 +165,15 @@  discard block
 block discarded – undo
165 165
 
166 166
 		// build the fields
167 167
 		$i = 0;
168
-		foreach($properties as $property => $updated) {
168
+		foreach ($properties as $property => $updated) {
169 169
 
170 170
 			$column = $entity->propertyToColumn($property);
171
-			$getter = 'get' . ucfirst($property);
171
+			$getter = 'get'.ucfirst($property);
172 172
 
173
-			$columns .= '`' . $column . '` = ?';
173
+			$columns .= '`'.$column.'` = ?';
174 174
 
175 175
 			// only append colon if there are more entries
176
-			if($i < count($properties)-1){
176
+			if ($i < count($properties) - 1) {
177 177
 				$columns .= ',';
178 178
 			}
179 179
 
@@ -181,8 +181,8 @@  discard block
 block discarded – undo
181 181
 			$i++;
182 182
 		}
183 183
 
184
-		$sql = 'UPDATE `' . $this->tableName . '` SET ' .
185
-				$columns . ' WHERE `id` = ?';
184
+		$sql = 'UPDATE `'.$this->tableName.'` SET '.
185
+				$columns.' WHERE `id` = ?';
186 186
 		$params[] = $id;
187 187
 
188 188
 		$stmt = $this->execute($sql, $params);
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 	 * @return \PDOStatement the database query result
229 229
 	 * @since 7.0.0
230 230
 	 */
231
-	protected function execute($sql, array $params=[], $limit=null, $offset=null){
231
+	protected function execute($sql, array $params = [], $limit = null, $offset = null) {
232 232
 		if ($this->db instanceof IDb) {
233 233
 			$query = $this->db->prepareQuery($sql, $limit, $offset);
234 234
 		} else {
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 				$query->bindValue($key, $param, $pdoConstant);
242 242
 			}
243 243
 		} else {
244
-			$index = 1;  // bindParam is 1 indexed
244
+			$index = 1; // bindParam is 1 indexed
245 245
 			foreach ($params as $param) {
246 246
 				$pdoConstant = $this->getPDOType($param);
247 247
 				$query->bindValue($index, $param, $pdoConstant);
@@ -277,11 +277,11 @@  discard block
 block discarded – undo
277 277
 	 * @return array the result as row
278 278
 	 * @since 7.0.0
279 279
 	 */
280
-	protected function findOneQuery($sql, array $params=[], $limit=null, $offset=null){
280
+	protected function findOneQuery($sql, array $params = [], $limit = null, $offset = null) {
281 281
 		$stmt = $this->execute($sql, $params, $limit, $offset);
282 282
 		$row = $stmt->fetch();
283 283
 
284
-		if($row === false || $row === null){
284
+		if ($row === false || $row === null) {
285 285
 			$stmt->closeCursor();
286 286
 			$msg = $this->buildDebugMessage(
287 287
 				'Did expect one result but found none when executing', $sql, $params, $limit, $offset
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
 		$row2 = $stmt->fetch();
292 292
 		$stmt->closeCursor();
293 293
 		//MDB2 returns null, PDO and doctrine false when no row is available
294
-		if( ! ($row2 === false || $row2 === null )) {
294
+		if (!($row2 === false || $row2 === null)) {
295 295
 			$msg = $this->buildDebugMessage(
296 296
 				'Did not expect more than one result when executing', $sql, $params, $limit, $offset
297 297
 			);
@@ -312,12 +312,12 @@  discard block
 block discarded – undo
312 312
 	 * @return string formatted error message string
313 313
 	 * @since 9.1.0
314 314
 	 */
315
-	private function buildDebugMessage($msg, $sql, array $params=[], $limit=null, $offset=null) {
316
-		return $msg .
317
-					': query "' .	$sql . '"; ' .
318
-					'parameters ' . print_r($params, true) . '; ' .
319
-					'limit "' . $limit . '"; '.
320
-					'offset "' . $offset . '"';
315
+	private function buildDebugMessage($msg, $sql, array $params = [], $limit = null, $offset = null) {
316
+		return $msg.
317
+					': query "'.$sql.'"; '.
318
+					'parameters '.print_r($params, true).'; '.
319
+					'limit "'.$limit.'"; '.
320
+					'offset "'.$offset.'"';
321 321
 	}
322 322
 
323 323
 
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 	 * @since 7.0.0
330 330
 	 */
331 331
 	protected function mapRowToEntity($row) {
332
-		return call_user_func($this->entityClass .'::fromRow', $row);
332
+		return call_user_func($this->entityClass.'::fromRow', $row);
333 333
 	}
334 334
 
335 335
 
@@ -342,12 +342,12 @@  discard block
 block discarded – undo
342 342
 	 * @return array all fetched entities
343 343
 	 * @since 7.0.0
344 344
 	 */
345
-	protected function findEntities($sql, array $params=[], $limit=null, $offset=null) {
345
+	protected function findEntities($sql, array $params = [], $limit = null, $offset = null) {
346 346
 		$stmt = $this->execute($sql, $params, $limit, $offset);
347 347
 
348 348
 		$entities = [];
349 349
 
350
-		while($row = $stmt->fetch()){
350
+		while ($row = $stmt->fetch()) {
351 351
 			$entities[] = $this->mapRowToEntity($row);
352 352
 		}
353 353
 
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
 	 * @return Entity the entity
370 370
 	 * @since 7.0.0
371 371
 	 */
372
-	protected function findEntity($sql, array $params=[], $limit=null, $offset=null){
372
+	protected function findEntity($sql, array $params = [], $limit = null, $offset = null) {
373 373
 		return $this->mapRowToEntity($this->findOneQuery($sql, $params, $limit, $offset));
374 374
 	}
375 375
 
Please login to merge, or discard this patch.
lib/public/Files.php 3 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -46,6 +46,7 @@  discard block
 block discarded – undo
46 46
 class Files {
47 47
 	/**
48 48
 	 * Recusive deletion of folders
49
+	 * @param string $dir
49 50
 	 * @return bool
50 51
 	 * @since 5.0.0
51 52
 	 */
@@ -67,7 +68,7 @@  discard block
 block discarded – undo
67 68
 	/**
68 69
 	 * Search for files by mimetype
69 70
 	 * @param string $mimetype
70
-	 * @return array
71
+	 * @return \OC\Files\FileInfo[]
71 72
 	 * @since 6.0.0
72 73
 	 */
73 74
 	static public function searchByMime( $mimetype ) {
Please login to merge, or discard this patch.
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -45,92 +45,92 @@
 block discarded – undo
45 45
  * @since 5.0.0
46 46
  */
47 47
 class Files {
48
-	/**
49
-	 * Recusive deletion of folders
50
-	 * @return bool
51
-	 * @since 5.0.0
52
-	 */
53
-	static function rmdirr( $dir ) {
54
-		return \OC_Helper::rmdirr( $dir );
55
-	}
48
+    /**
49
+     * Recusive deletion of folders
50
+     * @return bool
51
+     * @since 5.0.0
52
+     */
53
+    static function rmdirr( $dir ) {
54
+        return \OC_Helper::rmdirr( $dir );
55
+    }
56 56
 
57
-	/**
58
-	 * Get the mimetype form a local file
59
-	 * @param string $path
60
-	 * @return string
61
-	 * does NOT work for ownClouds filesystem, use OC_FileSystem::getMimeType instead
62
-	 * @since 5.0.0
63
-	 */
64
-	static function getMimeType( $path ) {
65
-		return \OC::$server->getMimeTypeDetector()->detect($path);
66
-	}
57
+    /**
58
+     * Get the mimetype form a local file
59
+     * @param string $path
60
+     * @return string
61
+     * does NOT work for ownClouds filesystem, use OC_FileSystem::getMimeType instead
62
+     * @since 5.0.0
63
+     */
64
+    static function getMimeType( $path ) {
65
+        return \OC::$server->getMimeTypeDetector()->detect($path);
66
+    }
67 67
 
68
-	/**
69
-	 * Search for files by mimetype
70
-	 * @param string $mimetype
71
-	 * @return array
72
-	 * @since 6.0.0
73
-	 */
74
-	static public function searchByMime( $mimetype ) {
75
-		return(\OC\Files\Filesystem::searchByMime( $mimetype ));
76
-	}
68
+    /**
69
+     * Search for files by mimetype
70
+     * @param string $mimetype
71
+     * @return array
72
+     * @since 6.0.0
73
+     */
74
+    static public function searchByMime( $mimetype ) {
75
+        return(\OC\Files\Filesystem::searchByMime( $mimetype ));
76
+    }
77 77
 
78
-	/**
79
-	 * Copy the contents of one stream to another
80
-	 * @param resource $source
81
-	 * @param resource $target
82
-	 * @return int the number of bytes copied
83
-	 * @since 5.0.0
84
-	 */
85
-	public static function streamCopy( $source, $target ) {
86
-		list($count, ) = \OC_Helper::streamCopy( $source, $target );
87
-		return $count;
88
-	}
78
+    /**
79
+     * Copy the contents of one stream to another
80
+     * @param resource $source
81
+     * @param resource $target
82
+     * @return int the number of bytes copied
83
+     * @since 5.0.0
84
+     */
85
+    public static function streamCopy( $source, $target ) {
86
+        list($count, ) = \OC_Helper::streamCopy( $source, $target );
87
+        return $count;
88
+    }
89 89
 
90
-	/**
91
-	 * Create a temporary file with an unique filename
92
-	 * @param string $postfix
93
-	 * @return string
94
-	 *
95
-	 * temporary files are automatically cleaned up after the script is finished
96
-	 * @deprecated 8.1.0 use getTemporaryFile() of \OCP\ITempManager - \OC::$server->getTempManager()
97
-	 * @since 5.0.0
98
-	 */
99
-	public static function tmpFile( $postfix='' ) {
100
-		return \OC::$server->getTempManager()->getTemporaryFile($postfix);
101
-	}
90
+    /**
91
+     * Create a temporary file with an unique filename
92
+     * @param string $postfix
93
+     * @return string
94
+     *
95
+     * temporary files are automatically cleaned up after the script is finished
96
+     * @deprecated 8.1.0 use getTemporaryFile() of \OCP\ITempManager - \OC::$server->getTempManager()
97
+     * @since 5.0.0
98
+     */
99
+    public static function tmpFile( $postfix='' ) {
100
+        return \OC::$server->getTempManager()->getTemporaryFile($postfix);
101
+    }
102 102
 
103
-	/**
104
-	 * Create a temporary folder with an unique filename
105
-	 * @return string
106
-	 *
107
-	 * temporary files are automatically cleaned up after the script is finished
108
-	 * @deprecated 8.1.0 use getTemporaryFolder() of \OCP\ITempManager - \OC::$server->getTempManager()
109
-	 * @since 5.0.0
110
-	 */
111
-	public static function tmpFolder() {
112
-		return \OC::$server->getTempManager()->getTemporaryFolder();
113
-	}
103
+    /**
104
+     * Create a temporary folder with an unique filename
105
+     * @return string
106
+     *
107
+     * temporary files are automatically cleaned up after the script is finished
108
+     * @deprecated 8.1.0 use getTemporaryFolder() of \OCP\ITempManager - \OC::$server->getTempManager()
109
+     * @since 5.0.0
110
+     */
111
+    public static function tmpFolder() {
112
+        return \OC::$server->getTempManager()->getTemporaryFolder();
113
+    }
114 114
 
115
-	/**
116
-	 * Adds a suffix to the name in case the file exists
117
-	 * @param string $path
118
-	 * @param string $filename
119
-	 * @return string
120
-	 * @since 5.0.0
121
-	 */
122
-	public static function buildNotExistingFileName( $path, $filename ) {
123
-		return(\OC_Helper::buildNotExistingFileName( $path, $filename ));
124
-	}
115
+    /**
116
+     * Adds a suffix to the name in case the file exists
117
+     * @param string $path
118
+     * @param string $filename
119
+     * @return string
120
+     * @since 5.0.0
121
+     */
122
+    public static function buildNotExistingFileName( $path, $filename ) {
123
+        return(\OC_Helper::buildNotExistingFileName( $path, $filename ));
124
+    }
125 125
 
126
-	/**
127
-	 * Gets the Storage for an app - creates the needed folder if they are not
128
-	 * existent
129
-	 * @param string $app
130
-	 * @return \OC\Files\View
131
-	 * @since 5.0.0
132
-	 */
133
-	public static function getStorage( $app ) {
134
-		return \OC_App::getStorage( $app );
135
-	}
126
+    /**
127
+     * Gets the Storage for an app - creates the needed folder if they are not
128
+     * existent
129
+     * @param string $app
130
+     * @return \OC\Files\View
131
+     * @since 5.0.0
132
+     */
133
+    public static function getStorage( $app ) {
134
+        return \OC_App::getStorage( $app );
135
+    }
136 136
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -50,8 +50,8 @@  discard block
 block discarded – undo
50 50
 	 * @return bool
51 51
 	 * @since 5.0.0
52 52
 	 */
53
-	static function rmdirr( $dir ) {
54
-		return \OC_Helper::rmdirr( $dir );
53
+	static function rmdirr($dir) {
54
+		return \OC_Helper::rmdirr($dir);
55 55
 	}
56 56
 
57 57
 	/**
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	 * does NOT work for ownClouds filesystem, use OC_FileSystem::getMimeType instead
62 62
 	 * @since 5.0.0
63 63
 	 */
64
-	static function getMimeType( $path ) {
64
+	static function getMimeType($path) {
65 65
 		return \OC::$server->getMimeTypeDetector()->detect($path);
66 66
 	}
67 67
 
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
71 71
 	 * @return array
72 72
 	 * @since 6.0.0
73 73
 	 */
74
-	static public function searchByMime( $mimetype ) {
75
-		return(\OC\Files\Filesystem::searchByMime( $mimetype ));
74
+	static public function searchByMime($mimetype) {
75
+		return(\OC\Files\Filesystem::searchByMime($mimetype));
76 76
 	}
77 77
 
78 78
 	/**
@@ -82,8 +82,8 @@  discard block
 block discarded – undo
82 82
 	 * @return int the number of bytes copied
83 83
 	 * @since 5.0.0
84 84
 	 */
85
-	public static function streamCopy( $source, $target ) {
86
-		list($count, ) = \OC_Helper::streamCopy( $source, $target );
85
+	public static function streamCopy($source, $target) {
86
+		list($count,) = \OC_Helper::streamCopy($source, $target);
87 87
 		return $count;
88 88
 	}
89 89
 
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	 * @deprecated 8.1.0 use getTemporaryFile() of \OCP\ITempManager - \OC::$server->getTempManager()
97 97
 	 * @since 5.0.0
98 98
 	 */
99
-	public static function tmpFile( $postfix='' ) {
99
+	public static function tmpFile($postfix = '') {
100 100
 		return \OC::$server->getTempManager()->getTemporaryFile($postfix);
101 101
 	}
102 102
 
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
 	 * @return string
120 120
 	 * @since 5.0.0
121 121
 	 */
122
-	public static function buildNotExistingFileName( $path, $filename ) {
123
-		return(\OC_Helper::buildNotExistingFileName( $path, $filename ));
122
+	public static function buildNotExistingFileName($path, $filename) {
123
+		return(\OC_Helper::buildNotExistingFileName($path, $filename));
124 124
 	}
125 125
 
126 126
 	/**
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 	 * @return \OC\Files\View
131 131
 	 * @since 5.0.0
132 132
 	 */
133
-	public static function getStorage( $app ) {
134
-		return \OC_App::getStorage( $app );
133
+	public static function getStorage($app) {
134
+		return \OC_App::getStorage($app);
135 135
 	}
136 136
 }
Please login to merge, or discard this patch.
lib/public/Files/StorageAuthException.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,6 @@
 block discarded – undo
30 30
 	 * StorageAuthException constructor.
31 31
 	 *
32 32
 	 * @param string $message
33
-	 * @param int $code
34 33
 	 * @param \Exception $previous
35 34
 	 * @since 9.0.0
36 35
 	 */
Please login to merge, or discard this patch.
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -27,16 +27,16 @@
 block discarded – undo
27 27
  */
28 28
 class StorageAuthException extends StorageNotAvailableException {
29 29
 
30
-	/**
31
-	 * StorageAuthException constructor.
32
-	 *
33
-	 * @param string $message
34
-	 * @param int $code
35
-	 * @param \Exception $previous
36
-	 * @since 9.0.0
37
-	 */
38
-	public function __construct($message = '', \Exception $previous = null) {
39
-		$l = \OC::$server->getL10N('core');
40
-		parent::__construct($l->t('Storage unauthorized. %s', $message), self::STATUS_UNAUTHORIZED, $previous);
41
-	}
30
+    /**
31
+     * StorageAuthException constructor.
32
+     *
33
+     * @param string $message
34
+     * @param int $code
35
+     * @param \Exception $previous
36
+     * @since 9.0.0
37
+     */
38
+    public function __construct($message = '', \Exception $previous = null) {
39
+        $l = \OC::$server->getL10N('core');
40
+        parent::__construct($l->t('Storage unauthorized. %s', $message), self::STATUS_UNAUTHORIZED, $previous);
41
+    }
42 42
 }
Please login to merge, or discard this patch.
lib/public/Files/StorageBadConfigException.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,6 @@
 block discarded – undo
30 30
 	 * ExtStorageBadConfigException constructor.
31 31
 	 *
32 32
 	 * @param string $message
33
-	 * @param int $code
34 33
 	 * @param \Exception $previous
35 34
 	 * @since 9.0.0
36 35
 	 */
Please login to merge, or discard this patch.
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -27,17 +27,17 @@
 block discarded – undo
27 27
  */
28 28
 class StorageBadConfigException extends StorageNotAvailableException {
29 29
 
30
-	/**
31
-	 * ExtStorageBadConfigException constructor.
32
-	 *
33
-	 * @param string $message
34
-	 * @param int $code
35
-	 * @param \Exception $previous
36
-	 * @since 9.0.0
37
-	 */
38
-	public function __construct($message = '', \Exception $previous = null) {
39
-		$l = \OC::$server->getL10N('core');
40
-		parent::__construct($l->t('Storage incomplete configuration. %s', $message), self::STATUS_INCOMPLETE_CONF, $previous);
41
-	}
30
+    /**
31
+     * ExtStorageBadConfigException constructor.
32
+     *
33
+     * @param string $message
34
+     * @param int $code
35
+     * @param \Exception $previous
36
+     * @since 9.0.0
37
+     */
38
+    public function __construct($message = '', \Exception $previous = null) {
39
+        $l = \OC::$server->getL10N('core');
40
+        parent::__construct($l->t('Storage incomplete configuration. %s', $message), self::STATUS_INCOMPLETE_CONF, $previous);
41
+    }
42 42
 
43 43
 }
Please login to merge, or discard this patch.
lib/public/Files/StorageConnectionException.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,6 @@
 block discarded – undo
30 30
 	 * StorageConnectionException constructor.
31 31
 	 *
32 32
 	 * @param string $message
33
-	 * @param int $code
34 33
 	 * @param \Exception $previous
35 34
 	 * @since 9.0.0
36 35
 	 */
Please login to merge, or discard this patch.
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -27,16 +27,16 @@
 block discarded – undo
27 27
  */
28 28
 class StorageConnectionException extends StorageNotAvailableException {
29 29
 
30
-	/**
31
-	 * StorageConnectionException constructor.
32
-	 *
33
-	 * @param string $message
34
-	 * @param int $code
35
-	 * @param \Exception $previous
36
-	 * @since 9.0.0
37
-	 */
38
-	public function __construct($message = '', \Exception $previous = null) {
39
-		$l = \OC::$server->getL10N('core');
40
-		parent::__construct($l->t('Storage connection error. %s', $message), self::STATUS_NETWORK_ERROR, $previous);
41
-	}
30
+    /**
31
+     * StorageConnectionException constructor.
32
+     *
33
+     * @param string $message
34
+     * @param int $code
35
+     * @param \Exception $previous
36
+     * @since 9.0.0
37
+     */
38
+    public function __construct($message = '', \Exception $previous = null) {
39
+        $l = \OC::$server->getL10N('core');
40
+        parent::__construct($l->t('Storage connection error. %s', $message), self::STATUS_NETWORK_ERROR, $previous);
41
+    }
42 42
 }
Please login to merge, or discard this patch.
lib/public/Files/StorageTimeoutException.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,6 @@
 block discarded – undo
30 30
 	 * StorageTimeoutException constructor.
31 31
 	 *
32 32
 	 * @param string $message
33
-	 * @param int $code
34 33
 	 * @param \Exception $previous
35 34
 	 * @since 9.0.0
36 35
 	 */
Please login to merge, or discard this patch.
Indentation   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -27,16 +27,16 @@
 block discarded – undo
27 27
  */
28 28
 class StorageTimeoutException extends StorageNotAvailableException {
29 29
 
30
-	/**
31
-	 * StorageTimeoutException constructor.
32
-	 *
33
-	 * @param string $message
34
-	 * @param int $code
35
-	 * @param \Exception $previous
36
-	 * @since 9.0.0
37
-	 */
38
-	public function __construct($message = '', \Exception $previous = null) {
39
-		$l = \OC::$server->getL10N('core');
40
-		parent::__construct($l->t('Storage connection timeout. %s', $message), self::STATUS_TIMEOUT, $previous);
41
-	}
30
+    /**
31
+     * StorageTimeoutException constructor.
32
+     *
33
+     * @param string $message
34
+     * @param int $code
35
+     * @param \Exception $previous
36
+     * @since 9.0.0
37
+     */
38
+    public function __construct($message = '', \Exception $previous = null) {
39
+        $l = \OC::$server->getL10N('core');
40
+        parent::__construct($l->t('Storage connection timeout. %s', $message), self::STATUS_TIMEOUT, $previous);
41
+    }
42 42
 }
Please login to merge, or discard this patch.