Passed
Push — master ( 1dce30...f6efd5 )
by Joas
15:03 queued 13s
created
lib/private/SystemTag/SystemTagObjectMapper.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 		$result->closeCursor();
242 242
 
243 243
 		if ($all) {
244
-			return ((int)$row[0] === \count($objIds));
244
+			return ((int) $row[0] === \count($objIds));
245 245
 		}
246 246
 
247 247
 		return (bool) $row;
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 		if (\count($tags) !== \count($tagIds)) {
260 260
 			// at least one tag missing, bail out
261 261
 			$foundTagIds = array_map(
262
-				function (ISystemTag $tag) {
262
+				function(ISystemTag $tag) {
263 263
 					return $tag->getId();
264 264
 				},
265 265
 				$tags
Please login to merge, or discard this patch.
Indentation   +231 added lines, -231 removed lines patch added patch discarded remove patch
@@ -39,235 +39,235 @@
 block discarded – undo
39 39
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
40 40
 
41 41
 class SystemTagObjectMapper implements ISystemTagObjectMapper {
42
-	public const RELATION_TABLE = 'systemtag_object_mapping';
43
-
44
-	/** @var ISystemTagManager */
45
-	protected $tagManager;
46
-
47
-	/** @var IDBConnection */
48
-	protected $connection;
49
-
50
-	/** @var EventDispatcherInterface */
51
-	protected $dispatcher;
52
-
53
-	/**
54
-	 * Constructor.
55
-	 *
56
-	 * @param IDBConnection $connection database connection
57
-	 * @param ISystemTagManager $tagManager system tag manager
58
-	 * @param EventDispatcherInterface $dispatcher
59
-	 */
60
-	public function __construct(IDBConnection $connection, ISystemTagManager $tagManager, EventDispatcherInterface $dispatcher) {
61
-		$this->connection = $connection;
62
-		$this->tagManager = $tagManager;
63
-		$this->dispatcher = $dispatcher;
64
-	}
65
-
66
-	/**
67
-	 * {@inheritdoc}
68
-	 */
69
-	public function getTagIdsForObjects($objIds, string $objectType): array {
70
-		if (!\is_array($objIds)) {
71
-			$objIds = [$objIds];
72
-		} elseif (empty($objIds)) {
73
-			return [];
74
-		}
75
-
76
-		$query = $this->connection->getQueryBuilder();
77
-		$query->select(['systemtagid', 'objectid'])
78
-			->from(self::RELATION_TABLE)
79
-			->where($query->expr()->in('objectid', $query->createParameter('objectids')))
80
-			->andWhere($query->expr()->eq('objecttype', $query->createParameter('objecttype')))
81
-			->setParameter('objectids', $objIds, IQueryBuilder::PARAM_STR_ARRAY)
82
-			->setParameter('objecttype', $objectType)
83
-			->addOrderBy('objectid', 'ASC')
84
-			->addOrderBy('systemtagid', 'ASC');
85
-
86
-		$mapping = [];
87
-		foreach ($objIds as $objId) {
88
-			$mapping[$objId] = [];
89
-		}
90
-
91
-		$result = $query->execute();
92
-		while ($row = $result->fetch()) {
93
-			$objectId = $row['objectid'];
94
-			$mapping[$objectId][] = $row['systemtagid'];
95
-		}
96
-
97
-		$result->closeCursor();
98
-
99
-		return $mapping;
100
-	}
101
-
102
-	/**
103
-	 * {@inheritdoc}
104
-	 */
105
-	public function getObjectIdsForTags($tagIds, string $objectType, int $limit = 0, string $offset = ''): array {
106
-		if (!\is_array($tagIds)) {
107
-			$tagIds = [$tagIds];
108
-		}
109
-
110
-		$this->assertTagsExist($tagIds);
111
-
112
-		$query = $this->connection->getQueryBuilder();
113
-		$query->selectDistinct('objectid')
114
-			->from(self::RELATION_TABLE)
115
-			->where($query->expr()->in('systemtagid', $query->createNamedParameter($tagIds, IQueryBuilder::PARAM_INT_ARRAY)))
116
-			->andWhere($query->expr()->eq('objecttype', $query->createNamedParameter($objectType)));
117
-
118
-		if ($limit) {
119
-			if (\count($tagIds) !== 1) {
120
-				throw new \InvalidArgumentException('Limit is only allowed with a single tag');
121
-			}
122
-
123
-			$query->setMaxResults($limit)
124
-				->orderBy('objectid', 'ASC');
125
-
126
-			if ($offset !== '') {
127
-				$query->andWhere($query->expr()->gt('objectid', $query->createNamedParameter($offset)));
128
-			}
129
-		}
130
-
131
-		$objectIds = [];
132
-
133
-		$result = $query->execute();
134
-		while ($row = $result->fetch()) {
135
-			$objectIds[] = $row['objectid'];
136
-		}
137
-
138
-		return $objectIds;
139
-	}
140
-
141
-	/**
142
-	 * {@inheritdoc}
143
-	 */
144
-	public function assignTags(string $objId, string $objectType, $tagIds) {
145
-		if (!\is_array($tagIds)) {
146
-			$tagIds = [$tagIds];
147
-		}
148
-
149
-		$this->assertTagsExist($tagIds);
150
-
151
-		$query = $this->connection->getQueryBuilder();
152
-		$query->insert(self::RELATION_TABLE)
153
-			->values([
154
-				'objectid' => $query->createNamedParameter($objId),
155
-				'objecttype' => $query->createNamedParameter($objectType),
156
-				'systemtagid' => $query->createParameter('tagid'),
157
-			]);
158
-
159
-		$tagsAssigned = [];
160
-		foreach ($tagIds as $tagId) {
161
-			try {
162
-				$query->setParameter('tagid', $tagId);
163
-				$query->execute();
164
-				$tagsAssigned[] = $tagId;
165
-			} catch (UniqueConstraintViolationException $e) {
166
-				// ignore existing relations
167
-			}
168
-		}
169
-
170
-		if (empty($tagsAssigned)) {
171
-			return;
172
-		}
173
-
174
-		$this->dispatcher->dispatch(MapperEvent::EVENT_ASSIGN, new MapperEvent(
175
-			MapperEvent::EVENT_ASSIGN,
176
-			$objectType,
177
-			$objId,
178
-			$tagsAssigned
179
-		));
180
-	}
181
-
182
-	/**
183
-	 * {@inheritdoc}
184
-	 */
185
-	public function unassignTags(string $objId, string $objectType, $tagIds) {
186
-		if (!\is_array($tagIds)) {
187
-			$tagIds = [$tagIds];
188
-		}
189
-
190
-		$this->assertTagsExist($tagIds);
191
-
192
-		$query = $this->connection->getQueryBuilder();
193
-		$query->delete(self::RELATION_TABLE)
194
-			->where($query->expr()->eq('objectid', $query->createParameter('objectid')))
195
-			->andWhere($query->expr()->eq('objecttype', $query->createParameter('objecttype')))
196
-			->andWhere($query->expr()->in('systemtagid', $query->createParameter('tagids')))
197
-			->setParameter('objectid', $objId)
198
-			->setParameter('objecttype', $objectType)
199
-			->setParameter('tagids', $tagIds, IQueryBuilder::PARAM_INT_ARRAY)
200
-			->execute();
201
-
202
-		$this->dispatcher->dispatch(MapperEvent::EVENT_UNASSIGN, new MapperEvent(
203
-			MapperEvent::EVENT_UNASSIGN,
204
-			$objectType,
205
-			$objId,
206
-			$tagIds
207
-		));
208
-	}
209
-
210
-	/**
211
-	 * {@inheritdoc}
212
-	 */
213
-	public function haveTag($objIds, string $objectType, string $tagId, bool $all = true): bool {
214
-		$this->assertTagsExist([$tagId]);
215
-
216
-		if (!\is_array($objIds)) {
217
-			$objIds = [$objIds];
218
-		}
219
-
220
-		$query = $this->connection->getQueryBuilder();
221
-
222
-		if (!$all) {
223
-			// If we only need one entry, we make the query lighter, by not
224
-			// counting the elements
225
-			$query->select('*')
226
-				->setMaxResults(1);
227
-		} else {
228
-			$query->select($query->func()->count($query->expr()->literal(1)));
229
-		}
230
-
231
-		$query->from(self::RELATION_TABLE)
232
-			->where($query->expr()->in('objectid', $query->createParameter('objectids')))
233
-			->andWhere($query->expr()->eq('objecttype', $query->createParameter('objecttype')))
234
-			->andWhere($query->expr()->eq('systemtagid', $query->createParameter('tagid')))
235
-			->setParameter('objectids', $objIds, IQueryBuilder::PARAM_STR_ARRAY)
236
-			->setParameter('tagid', $tagId)
237
-			->setParameter('objecttype', $objectType);
238
-
239
-		$result = $query->execute();
240
-		$row = $result->fetch(\PDO::FETCH_NUM);
241
-		$result->closeCursor();
242
-
243
-		if ($all) {
244
-			return ((int)$row[0] === \count($objIds));
245
-		}
246
-
247
-		return (bool) $row;
248
-	}
249
-
250
-	/**
251
-	 * Asserts that all the given tag ids exist.
252
-	 *
253
-	 * @param string[] $tagIds tag ids to check
254
-	 *
255
-	 * @throws \OCP\SystemTag\TagNotFoundException if at least one tag did not exist
256
-	 */
257
-	private function assertTagsExist($tagIds) {
258
-		$tags = $this->tagManager->getTagsByIds($tagIds);
259
-		if (\count($tags) !== \count($tagIds)) {
260
-			// at least one tag missing, bail out
261
-			$foundTagIds = array_map(
262
-				function (ISystemTag $tag) {
263
-					return $tag->getId();
264
-				},
265
-				$tags
266
-			);
267
-			$missingTagIds = array_diff($tagIds, $foundTagIds);
268
-			throw new TagNotFoundException(
269
-				'Tags not found', 0, null, $missingTagIds
270
-			);
271
-		}
272
-	}
42
+    public const RELATION_TABLE = 'systemtag_object_mapping';
43
+
44
+    /** @var ISystemTagManager */
45
+    protected $tagManager;
46
+
47
+    /** @var IDBConnection */
48
+    protected $connection;
49
+
50
+    /** @var EventDispatcherInterface */
51
+    protected $dispatcher;
52
+
53
+    /**
54
+     * Constructor.
55
+     *
56
+     * @param IDBConnection $connection database connection
57
+     * @param ISystemTagManager $tagManager system tag manager
58
+     * @param EventDispatcherInterface $dispatcher
59
+     */
60
+    public function __construct(IDBConnection $connection, ISystemTagManager $tagManager, EventDispatcherInterface $dispatcher) {
61
+        $this->connection = $connection;
62
+        $this->tagManager = $tagManager;
63
+        $this->dispatcher = $dispatcher;
64
+    }
65
+
66
+    /**
67
+     * {@inheritdoc}
68
+     */
69
+    public function getTagIdsForObjects($objIds, string $objectType): array {
70
+        if (!\is_array($objIds)) {
71
+            $objIds = [$objIds];
72
+        } elseif (empty($objIds)) {
73
+            return [];
74
+        }
75
+
76
+        $query = $this->connection->getQueryBuilder();
77
+        $query->select(['systemtagid', 'objectid'])
78
+            ->from(self::RELATION_TABLE)
79
+            ->where($query->expr()->in('objectid', $query->createParameter('objectids')))
80
+            ->andWhere($query->expr()->eq('objecttype', $query->createParameter('objecttype')))
81
+            ->setParameter('objectids', $objIds, IQueryBuilder::PARAM_STR_ARRAY)
82
+            ->setParameter('objecttype', $objectType)
83
+            ->addOrderBy('objectid', 'ASC')
84
+            ->addOrderBy('systemtagid', 'ASC');
85
+
86
+        $mapping = [];
87
+        foreach ($objIds as $objId) {
88
+            $mapping[$objId] = [];
89
+        }
90
+
91
+        $result = $query->execute();
92
+        while ($row = $result->fetch()) {
93
+            $objectId = $row['objectid'];
94
+            $mapping[$objectId][] = $row['systemtagid'];
95
+        }
96
+
97
+        $result->closeCursor();
98
+
99
+        return $mapping;
100
+    }
101
+
102
+    /**
103
+     * {@inheritdoc}
104
+     */
105
+    public function getObjectIdsForTags($tagIds, string $objectType, int $limit = 0, string $offset = ''): array {
106
+        if (!\is_array($tagIds)) {
107
+            $tagIds = [$tagIds];
108
+        }
109
+
110
+        $this->assertTagsExist($tagIds);
111
+
112
+        $query = $this->connection->getQueryBuilder();
113
+        $query->selectDistinct('objectid')
114
+            ->from(self::RELATION_TABLE)
115
+            ->where($query->expr()->in('systemtagid', $query->createNamedParameter($tagIds, IQueryBuilder::PARAM_INT_ARRAY)))
116
+            ->andWhere($query->expr()->eq('objecttype', $query->createNamedParameter($objectType)));
117
+
118
+        if ($limit) {
119
+            if (\count($tagIds) !== 1) {
120
+                throw new \InvalidArgumentException('Limit is only allowed with a single tag');
121
+            }
122
+
123
+            $query->setMaxResults($limit)
124
+                ->orderBy('objectid', 'ASC');
125
+
126
+            if ($offset !== '') {
127
+                $query->andWhere($query->expr()->gt('objectid', $query->createNamedParameter($offset)));
128
+            }
129
+        }
130
+
131
+        $objectIds = [];
132
+
133
+        $result = $query->execute();
134
+        while ($row = $result->fetch()) {
135
+            $objectIds[] = $row['objectid'];
136
+        }
137
+
138
+        return $objectIds;
139
+    }
140
+
141
+    /**
142
+     * {@inheritdoc}
143
+     */
144
+    public function assignTags(string $objId, string $objectType, $tagIds) {
145
+        if (!\is_array($tagIds)) {
146
+            $tagIds = [$tagIds];
147
+        }
148
+
149
+        $this->assertTagsExist($tagIds);
150
+
151
+        $query = $this->connection->getQueryBuilder();
152
+        $query->insert(self::RELATION_TABLE)
153
+            ->values([
154
+                'objectid' => $query->createNamedParameter($objId),
155
+                'objecttype' => $query->createNamedParameter($objectType),
156
+                'systemtagid' => $query->createParameter('tagid'),
157
+            ]);
158
+
159
+        $tagsAssigned = [];
160
+        foreach ($tagIds as $tagId) {
161
+            try {
162
+                $query->setParameter('tagid', $tagId);
163
+                $query->execute();
164
+                $tagsAssigned[] = $tagId;
165
+            } catch (UniqueConstraintViolationException $e) {
166
+                // ignore existing relations
167
+            }
168
+        }
169
+
170
+        if (empty($tagsAssigned)) {
171
+            return;
172
+        }
173
+
174
+        $this->dispatcher->dispatch(MapperEvent::EVENT_ASSIGN, new MapperEvent(
175
+            MapperEvent::EVENT_ASSIGN,
176
+            $objectType,
177
+            $objId,
178
+            $tagsAssigned
179
+        ));
180
+    }
181
+
182
+    /**
183
+     * {@inheritdoc}
184
+     */
185
+    public function unassignTags(string $objId, string $objectType, $tagIds) {
186
+        if (!\is_array($tagIds)) {
187
+            $tagIds = [$tagIds];
188
+        }
189
+
190
+        $this->assertTagsExist($tagIds);
191
+
192
+        $query = $this->connection->getQueryBuilder();
193
+        $query->delete(self::RELATION_TABLE)
194
+            ->where($query->expr()->eq('objectid', $query->createParameter('objectid')))
195
+            ->andWhere($query->expr()->eq('objecttype', $query->createParameter('objecttype')))
196
+            ->andWhere($query->expr()->in('systemtagid', $query->createParameter('tagids')))
197
+            ->setParameter('objectid', $objId)
198
+            ->setParameter('objecttype', $objectType)
199
+            ->setParameter('tagids', $tagIds, IQueryBuilder::PARAM_INT_ARRAY)
200
+            ->execute();
201
+
202
+        $this->dispatcher->dispatch(MapperEvent::EVENT_UNASSIGN, new MapperEvent(
203
+            MapperEvent::EVENT_UNASSIGN,
204
+            $objectType,
205
+            $objId,
206
+            $tagIds
207
+        ));
208
+    }
209
+
210
+    /**
211
+     * {@inheritdoc}
212
+     */
213
+    public function haveTag($objIds, string $objectType, string $tagId, bool $all = true): bool {
214
+        $this->assertTagsExist([$tagId]);
215
+
216
+        if (!\is_array($objIds)) {
217
+            $objIds = [$objIds];
218
+        }
219
+
220
+        $query = $this->connection->getQueryBuilder();
221
+
222
+        if (!$all) {
223
+            // If we only need one entry, we make the query lighter, by not
224
+            // counting the elements
225
+            $query->select('*')
226
+                ->setMaxResults(1);
227
+        } else {
228
+            $query->select($query->func()->count($query->expr()->literal(1)));
229
+        }
230
+
231
+        $query->from(self::RELATION_TABLE)
232
+            ->where($query->expr()->in('objectid', $query->createParameter('objectids')))
233
+            ->andWhere($query->expr()->eq('objecttype', $query->createParameter('objecttype')))
234
+            ->andWhere($query->expr()->eq('systemtagid', $query->createParameter('tagid')))
235
+            ->setParameter('objectids', $objIds, IQueryBuilder::PARAM_STR_ARRAY)
236
+            ->setParameter('tagid', $tagId)
237
+            ->setParameter('objecttype', $objectType);
238
+
239
+        $result = $query->execute();
240
+        $row = $result->fetch(\PDO::FETCH_NUM);
241
+        $result->closeCursor();
242
+
243
+        if ($all) {
244
+            return ((int)$row[0] === \count($objIds));
245
+        }
246
+
247
+        return (bool) $row;
248
+    }
249
+
250
+    /**
251
+     * Asserts that all the given tag ids exist.
252
+     *
253
+     * @param string[] $tagIds tag ids to check
254
+     *
255
+     * @throws \OCP\SystemTag\TagNotFoundException if at least one tag did not exist
256
+     */
257
+    private function assertTagsExist($tagIds) {
258
+        $tags = $this->tagManager->getTagsByIds($tagIds);
259
+        if (\count($tags) !== \count($tagIds)) {
260
+            // at least one tag missing, bail out
261
+            $foundTagIds = array_map(
262
+                function (ISystemTag $tag) {
263
+                    return $tag->getId();
264
+                },
265
+                $tags
266
+            );
267
+            $missingTagIds = array_diff($tagIds, $foundTagIds);
268
+            throw new TagNotFoundException(
269
+                'Tags not found', 0, null, $missingTagIds
270
+            );
271
+        }
272
+    }
273 273
 }
Please login to merge, or discard this patch.
lib/private/Collaboration/Resources/Collection.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 	 * @since 16.0.0
127 127
 	 */
128 128
 	public function addResource(IResource $resource): void {
129
-		array_map(function (IResource $r) use ($resource) {
129
+		array_map(function(IResource $r) use ($resource) {
130 130
 			if ($this->isSameResource($r, $resource)) {
131 131
 				throw new ResourceException('Already part of the collection');
132 132
 			}
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
 	 * @since 16.0.0
159 159
 	 */
160 160
 	public function removeResource(IResource $resource): void {
161
-		$this->resources = array_filter($this->getResources(), function (IResource $r) use ($resource) {
161
+		$this->resources = array_filter($this->getResources(), function(IResource $r) use ($resource) {
162 162
 			return !$this->isSameResource($r, $resource);
163 163
 		});
164 164
 
Please login to merge, or discard this patch.
Indentation   +190 added lines, -190 removed lines patch added patch discarded remove patch
@@ -38,194 +38,194 @@
 block discarded – undo
38 38
 
39 39
 class Collection implements ICollection {
40 40
 
41
-	/** @var IManager|Manager */
42
-	protected $manager;
43
-
44
-	/** @var IDBConnection */
45
-	protected $connection;
46
-
47
-	/** @var int */
48
-	protected $id;
49
-
50
-	/** @var string */
51
-	protected $name;
52
-
53
-	/** @var IUser|null */
54
-	protected $userForAccess;
55
-
56
-	/** @var bool|null */
57
-	protected $access;
58
-
59
-	/** @var IResource[] */
60
-	protected $resources;
61
-
62
-	public function __construct(
63
-		IManager $manager,
64
-		IDBConnection $connection,
65
-		int $id,
66
-		string $name,
67
-		?IUser $userForAccess = null,
68
-		?bool $access = null
69
-	) {
70
-		$this->manager = $manager;
71
-		$this->connection = $connection;
72
-		$this->id = $id;
73
-		$this->name = $name;
74
-		$this->userForAccess = $userForAccess;
75
-		$this->access = $access;
76
-		$this->resources = [];
77
-	}
78
-
79
-	/**
80
-	 * @return int
81
-	 * @since 16.0.0
82
-	 */
83
-	public function getId(): int {
84
-		return $this->id;
85
-	}
86
-
87
-	/**
88
-	 * @return string
89
-	 * @since 16.0.0
90
-	 */
91
-	public function getName(): string {
92
-		return $this->name;
93
-	}
94
-
95
-	/**
96
-	 * @param string $name
97
-	 * @since 16.0.0
98
-	 */
99
-	public function setName(string $name): void {
100
-		$query = $this->connection->getQueryBuilder();
101
-		$query->update(Manager::TABLE_COLLECTIONS)
102
-			->set('name', $query->createNamedParameter($name))
103
-			->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
104
-		$query->execute();
105
-
106
-		$this->name = $name;
107
-	}
108
-
109
-	/**
110
-	 * @return IResource[]
111
-	 * @since 16.0.0
112
-	 */
113
-	public function getResources(): array {
114
-		if (empty($this->resources)) {
115
-			$this->resources = $this->manager->getResourcesByCollectionForUser($this, $this->userForAccess);
116
-		}
117
-
118
-		return $this->resources;
119
-	}
120
-
121
-	/**
122
-	 * Adds a resource to a collection
123
-	 *
124
-	 * @param IResource $resource
125
-	 * @throws ResourceException when the resource is already part of the collection
126
-	 * @since 16.0.0
127
-	 */
128
-	public function addResource(IResource $resource): void {
129
-		array_map(function (IResource $r) use ($resource) {
130
-			if ($this->isSameResource($r, $resource)) {
131
-				throw new ResourceException('Already part of the collection');
132
-			}
133
-		}, $this->getResources());
134
-
135
-		$this->resources[] = $resource;
136
-
137
-		$query = $this->connection->getQueryBuilder();
138
-		$query->insert(Manager::TABLE_RESOURCES)
139
-			->values([
140
-				'collection_id' => $query->createNamedParameter($this->id, IQueryBuilder::PARAM_INT),
141
-				'resource_type' => $query->createNamedParameter($resource->getType()),
142
-				'resource_id' => $query->createNamedParameter($resource->getId()),
143
-			]);
144
-
145
-		try {
146
-			$query->execute();
147
-		} catch (ConstraintViolationException $e) {
148
-			throw new ResourceException('Already part of the collection');
149
-		}
150
-
151
-		$this->manager->invalidateAccessCacheForCollection($this);
152
-	}
153
-
154
-	/**
155
-	 * Removes a resource from a collection
156
-	 *
157
-	 * @param IResource $resource
158
-	 * @since 16.0.0
159
-	 */
160
-	public function removeResource(IResource $resource): void {
161
-		$this->resources = array_filter($this->getResources(), function (IResource $r) use ($resource) {
162
-			return !$this->isSameResource($r, $resource);
163
-		});
164
-
165
-		$query = $this->connection->getQueryBuilder();
166
-		$query->delete(Manager::TABLE_RESOURCES)
167
-			->where($query->expr()->eq('collection_id', $query->createNamedParameter($this->id, IQueryBuilder::PARAM_INT)))
168
-			->andWhere($query->expr()->eq('resource_type', $query->createNamedParameter($resource->getType())))
169
-			->andWhere($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId())));
170
-		$query->execute();
171
-
172
-		if (empty($this->resources)) {
173
-			$this->removeCollection();
174
-		} else {
175
-			$this->manager->invalidateAccessCacheForCollection($this);
176
-		}
177
-	}
178
-
179
-	/**
180
-	 * Can a user/guest access the collection
181
-	 *
182
-	 * @param IUser|null $user
183
-	 * @return bool
184
-	 * @since 16.0.0
185
-	 */
186
-	public function canAccess(?IUser $user): bool {
187
-		if ($user instanceof IUser) {
188
-			return $this->canUserAccess($user);
189
-		}
190
-		return $this->canGuestAccess();
191
-	}
192
-
193
-	protected function canUserAccess(IUser $user): bool {
194
-		if (\is_bool($this->access) && $this->userForAccess instanceof IUser && $user->getUID() === $this->userForAccess->getUID()) {
195
-			return $this->access;
196
-		}
197
-
198
-		$access = $this->manager->canAccessCollection($this, $user);
199
-		if ($this->userForAccess instanceof IUser && $user->getUID() === $this->userForAccess->getUID()) {
200
-			$this->access = $access;
201
-		}
202
-		return $access;
203
-	}
204
-
205
-	protected function canGuestAccess(): bool {
206
-		if (\is_bool($this->access) && !$this->userForAccess instanceof IUser) {
207
-			return $this->access;
208
-		}
209
-
210
-		$access = $this->manager->canAccessCollection($this, null);
211
-		if (!$this->userForAccess instanceof IUser) {
212
-			$this->access = $access;
213
-		}
214
-		return $access;
215
-	}
216
-
217
-	protected function isSameResource(IResource $resource1, IResource $resource2): bool {
218
-		return $resource1->getType() === $resource2->getType() &&
219
-			$resource1->getId() === $resource2->getId();
220
-	}
221
-
222
-	protected function removeCollection(): void {
223
-		$query = $this->connection->getQueryBuilder();
224
-		$query->delete(Manager::TABLE_COLLECTIONS)
225
-			->where($query->expr()->eq('id', $query->createNamedParameter($this->id, IQueryBuilder::PARAM_INT)));
226
-		$query->execute();
227
-
228
-		$this->manager->invalidateAccessCacheForCollection($this);
229
-		$this->id = 0;
230
-	}
41
+    /** @var IManager|Manager */
42
+    protected $manager;
43
+
44
+    /** @var IDBConnection */
45
+    protected $connection;
46
+
47
+    /** @var int */
48
+    protected $id;
49
+
50
+    /** @var string */
51
+    protected $name;
52
+
53
+    /** @var IUser|null */
54
+    protected $userForAccess;
55
+
56
+    /** @var bool|null */
57
+    protected $access;
58
+
59
+    /** @var IResource[] */
60
+    protected $resources;
61
+
62
+    public function __construct(
63
+        IManager $manager,
64
+        IDBConnection $connection,
65
+        int $id,
66
+        string $name,
67
+        ?IUser $userForAccess = null,
68
+        ?bool $access = null
69
+    ) {
70
+        $this->manager = $manager;
71
+        $this->connection = $connection;
72
+        $this->id = $id;
73
+        $this->name = $name;
74
+        $this->userForAccess = $userForAccess;
75
+        $this->access = $access;
76
+        $this->resources = [];
77
+    }
78
+
79
+    /**
80
+     * @return int
81
+     * @since 16.0.0
82
+     */
83
+    public function getId(): int {
84
+        return $this->id;
85
+    }
86
+
87
+    /**
88
+     * @return string
89
+     * @since 16.0.0
90
+     */
91
+    public function getName(): string {
92
+        return $this->name;
93
+    }
94
+
95
+    /**
96
+     * @param string $name
97
+     * @since 16.0.0
98
+     */
99
+    public function setName(string $name): void {
100
+        $query = $this->connection->getQueryBuilder();
101
+        $query->update(Manager::TABLE_COLLECTIONS)
102
+            ->set('name', $query->createNamedParameter($name))
103
+            ->where($query->expr()->eq('id', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
104
+        $query->execute();
105
+
106
+        $this->name = $name;
107
+    }
108
+
109
+    /**
110
+     * @return IResource[]
111
+     * @since 16.0.0
112
+     */
113
+    public function getResources(): array {
114
+        if (empty($this->resources)) {
115
+            $this->resources = $this->manager->getResourcesByCollectionForUser($this, $this->userForAccess);
116
+        }
117
+
118
+        return $this->resources;
119
+    }
120
+
121
+    /**
122
+     * Adds a resource to a collection
123
+     *
124
+     * @param IResource $resource
125
+     * @throws ResourceException when the resource is already part of the collection
126
+     * @since 16.0.0
127
+     */
128
+    public function addResource(IResource $resource): void {
129
+        array_map(function (IResource $r) use ($resource) {
130
+            if ($this->isSameResource($r, $resource)) {
131
+                throw new ResourceException('Already part of the collection');
132
+            }
133
+        }, $this->getResources());
134
+
135
+        $this->resources[] = $resource;
136
+
137
+        $query = $this->connection->getQueryBuilder();
138
+        $query->insert(Manager::TABLE_RESOURCES)
139
+            ->values([
140
+                'collection_id' => $query->createNamedParameter($this->id, IQueryBuilder::PARAM_INT),
141
+                'resource_type' => $query->createNamedParameter($resource->getType()),
142
+                'resource_id' => $query->createNamedParameter($resource->getId()),
143
+            ]);
144
+
145
+        try {
146
+            $query->execute();
147
+        } catch (ConstraintViolationException $e) {
148
+            throw new ResourceException('Already part of the collection');
149
+        }
150
+
151
+        $this->manager->invalidateAccessCacheForCollection($this);
152
+    }
153
+
154
+    /**
155
+     * Removes a resource from a collection
156
+     *
157
+     * @param IResource $resource
158
+     * @since 16.0.0
159
+     */
160
+    public function removeResource(IResource $resource): void {
161
+        $this->resources = array_filter($this->getResources(), function (IResource $r) use ($resource) {
162
+            return !$this->isSameResource($r, $resource);
163
+        });
164
+
165
+        $query = $this->connection->getQueryBuilder();
166
+        $query->delete(Manager::TABLE_RESOURCES)
167
+            ->where($query->expr()->eq('collection_id', $query->createNamedParameter($this->id, IQueryBuilder::PARAM_INT)))
168
+            ->andWhere($query->expr()->eq('resource_type', $query->createNamedParameter($resource->getType())))
169
+            ->andWhere($query->expr()->eq('resource_id', $query->createNamedParameter($resource->getId())));
170
+        $query->execute();
171
+
172
+        if (empty($this->resources)) {
173
+            $this->removeCollection();
174
+        } else {
175
+            $this->manager->invalidateAccessCacheForCollection($this);
176
+        }
177
+    }
178
+
179
+    /**
180
+     * Can a user/guest access the collection
181
+     *
182
+     * @param IUser|null $user
183
+     * @return bool
184
+     * @since 16.0.0
185
+     */
186
+    public function canAccess(?IUser $user): bool {
187
+        if ($user instanceof IUser) {
188
+            return $this->canUserAccess($user);
189
+        }
190
+        return $this->canGuestAccess();
191
+    }
192
+
193
+    protected function canUserAccess(IUser $user): bool {
194
+        if (\is_bool($this->access) && $this->userForAccess instanceof IUser && $user->getUID() === $this->userForAccess->getUID()) {
195
+            return $this->access;
196
+        }
197
+
198
+        $access = $this->manager->canAccessCollection($this, $user);
199
+        if ($this->userForAccess instanceof IUser && $user->getUID() === $this->userForAccess->getUID()) {
200
+            $this->access = $access;
201
+        }
202
+        return $access;
203
+    }
204
+
205
+    protected function canGuestAccess(): bool {
206
+        if (\is_bool($this->access) && !$this->userForAccess instanceof IUser) {
207
+            return $this->access;
208
+        }
209
+
210
+        $access = $this->manager->canAccessCollection($this, null);
211
+        if (!$this->userForAccess instanceof IUser) {
212
+            $this->access = $access;
213
+        }
214
+        return $access;
215
+    }
216
+
217
+    protected function isSameResource(IResource $resource1, IResource $resource2): bool {
218
+        return $resource1->getType() === $resource2->getType() &&
219
+            $resource1->getId() === $resource2->getId();
220
+    }
221
+
222
+    protected function removeCollection(): void {
223
+        $query = $this->connection->getQueryBuilder();
224
+        $query->delete(Manager::TABLE_COLLECTIONS)
225
+            ->where($query->expr()->eq('id', $query->createNamedParameter($this->id, IQueryBuilder::PARAM_INT)));
226
+        $query->execute();
227
+
228
+        $this->manager->invalidateAccessCacheForCollection($this);
229
+        $this->id = 0;
230
+    }
231 231
 }
Please login to merge, or discard this patch.
lib/public/Accounts/PropertyDoesNotExistException.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -32,13 +32,13 @@
 block discarded – undo
32 32
  */
33 33
 class PropertyDoesNotExistException extends \Exception {
34 34
 
35
-	/**
36
-	 * Constructor
37
-	 * @param string $msg the error message
38
-	 * @since 15.0.0
39
-	 */
40
-	public function __construct($property) {
41
-		parent::__construct('Property ' . $property . ' does not exist.');
42
-	}
35
+    /**
36
+     * Constructor
37
+     * @param string $msg the error message
38
+     * @since 15.0.0
39
+     */
40
+    public function __construct($property) {
41
+        parent::__construct('Property ' . $property . ' does not exist.');
42
+    }
43 43
 
44 44
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@
 block discarded – undo
38 38
 	 * @since 15.0.0
39 39
 	 */
40 40
 	public function __construct($property) {
41
-		parent::__construct('Property ' . $property . ' does not exist.');
41
+		parent::__construct('Property '.$property.' does not exist.');
42 42
 	}
43 43
 
44 44
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/StreamResponse.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -35,35 +35,35 @@
 block discarded – undo
35 35
  * @since 8.1.0
36 36
  */
37 37
 class StreamResponse extends Response implements ICallbackResponse {
38
-	/** @var string */
39
-	private $filePath;
38
+    /** @var string */
39
+    private $filePath;
40 40
 
41
-	/**
42
-	 * @param string|resource $filePath the path to the file or a file handle which should be streamed
43
-	 * @since 8.1.0
44
-	 */
45
-	public function __construct($filePath) {
46
-		parent::__construct();
41
+    /**
42
+     * @param string|resource $filePath the path to the file or a file handle which should be streamed
43
+     * @since 8.1.0
44
+     */
45
+    public function __construct($filePath) {
46
+        parent::__construct();
47 47
 
48
-		$this->filePath = $filePath;
49
-	}
48
+        $this->filePath = $filePath;
49
+    }
50 50
 
51 51
 
52
-	/**
53
-	 * Streams the file using readfile
54
-	 *
55
-	 * @param IOutput $output a small wrapper that handles output
56
-	 * @since 8.1.0
57
-	 */
58
-	public function callback(IOutput $output) {
59
-		// handle caching
60
-		if ($output->getHttpResponseCode() !== Http::STATUS_NOT_MODIFIED) {
61
-			if (!(is_resource($this->filePath) || file_exists($this->filePath))) {
62
-				$output->setHttpResponseCode(Http::STATUS_NOT_FOUND);
63
-			} elseif ($output->setReadfile($this->filePath) === false) {
64
-				$output->setHttpResponseCode(Http::STATUS_BAD_REQUEST);
65
-			}
66
-		}
67
-	}
52
+    /**
53
+     * Streams the file using readfile
54
+     *
55
+     * @param IOutput $output a small wrapper that handles output
56
+     * @since 8.1.0
57
+     */
58
+    public function callback(IOutput $output) {
59
+        // handle caching
60
+        if ($output->getHttpResponseCode() !== Http::STATUS_NOT_MODIFIED) {
61
+            if (!(is_resource($this->filePath) || file_exists($this->filePath))) {
62
+                $output->setHttpResponseCode(Http::STATUS_NOT_FOUND);
63
+            } elseif ($output->setReadfile($this->filePath) === false) {
64
+                $output->setHttpResponseCode(Http::STATUS_BAD_REQUEST);
65
+            }
66
+        }
67
+    }
68 68
 
69 69
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/Db/DoesNotExistException.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -34,13 +34,13 @@
 block discarded – undo
34 34
  */
35 35
 class DoesNotExistException extends \Exception implements IMapperException {
36 36
 
37
-	/**
38
-	 * Constructor
39
-	 * @param string $msg the error message
40
-	 * @since 7.0.0
41
-	 */
42
-	public function __construct($msg) {
43
-		parent::__construct($msg);
44
-	}
37
+    /**
38
+     * Constructor
39
+     * @param string $msg the error message
40
+     * @since 7.0.0
41
+     */
42
+    public function __construct($msg) {
43
+        parent::__construct($msg);
44
+    }
45 45
 
46 46
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/Db/MultipleObjectsReturnedException.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -34,13 +34,13 @@
 block discarded – undo
34 34
  */
35 35
 class MultipleObjectsReturnedException extends \Exception implements IMapperException {
36 36
 
37
-	/**
38
-	 * Constructor
39
-	 * @param string $msg the error message
40
-	 * @since 7.0.0
41
-	 */
42
-	public function __construct($msg) {
43
-		parent::__construct($msg);
44
-	}
37
+    /**
38
+     * Constructor
39
+     * @param string $msg the error message
40
+     * @since 7.0.0
41
+     */
42
+    public function __construct($msg) {
43
+        parent::__construct($msg);
44
+    }
45 45
 
46 46
 }
Please login to merge, or discard this patch.
lib/public/Diagnostics/IQueryLogger.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -34,43 +34,43 @@
 block discarded – undo
34 34
  * @since 8.0.0
35 35
  */
36 36
 interface IQueryLogger extends SQLLogger {
37
-	/**
38
-	 * Mark the start of a query providing query SQL statement, its parameters and types.
39
-	 * This method should be called as close to the DB as possible and after
40
-	 * query is finished finalized with stopQuery() method.
41
-	 *
42
-	 * @param string $sql
43
-	 * @param array|null $params
44
-	 * @param array|null $types
45
-	 * @since 8.0.0
46
-	 */
47
-	public function startQuery($sql, array $params = null, array $types = null);
37
+    /**
38
+     * Mark the start of a query providing query SQL statement, its parameters and types.
39
+     * This method should be called as close to the DB as possible and after
40
+     * query is finished finalized with stopQuery() method.
41
+     *
42
+     * @param string $sql
43
+     * @param array|null $params
44
+     * @param array|null $types
45
+     * @since 8.0.0
46
+     */
47
+    public function startQuery($sql, array $params = null, array $types = null);
48 48
 
49
-	/**
50
-	 * Mark the end of the current active query. Ending query should store \OCP\Diagnostics\IQuery to
51
-	 * be returned with getQueries() method.
52
-	 *
53
-	 * @return mixed
54
-	 * @since 8.0.0
55
-	 */
56
-	public function stopQuery();
49
+    /**
50
+     * Mark the end of the current active query. Ending query should store \OCP\Diagnostics\IQuery to
51
+     * be returned with getQueries() method.
52
+     *
53
+     * @return mixed
54
+     * @since 8.0.0
55
+     */
56
+    public function stopQuery();
57 57
 
58
-	/**
59
-	 * This method should return all \OCP\Diagnostics\IQuery objects stored using
60
-	 * startQuery()/stopQuery() methods.
61
-	 *
62
-	 * @return \OCP\Diagnostics\IQuery[]
63
-	 * @since 8.0.0
64
-	 */
65
-	public function getQueries();
58
+    /**
59
+     * This method should return all \OCP\Diagnostics\IQuery objects stored using
60
+     * startQuery()/stopQuery() methods.
61
+     *
62
+     * @return \OCP\Diagnostics\IQuery[]
63
+     * @since 8.0.0
64
+     */
65
+    public function getQueries();
66 66
 
67
-	/**
68
-	 * Activate the module for the duration of the request. Deactivated module
69
-	 * does not create and store \OCP\Diagnostics\IQuery objects.
70
-	 * Only activated module should create and store objects to be
71
-	 * returned with getQueries() call.
72
-	 *
73
-	 * @since 12.0.0
74
-	 */
75
-	public function activate();
67
+    /**
68
+     * Activate the module for the duration of the request. Deactivated module
69
+     * does not create and store \OCP\Diagnostics\IQuery objects.
70
+     * Only activated module should create and store objects to be
71
+     * returned with getQueries() call.
72
+     *
73
+     * @since 12.0.0
74
+     */
75
+    public function activate();
76 76
 }
Please login to merge, or discard this patch.
lib/private/Collaboration/Collaborators/RemotePlugin.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 							$searchResult->markExactIdMatch($resultType);
113 113
 						}
114 114
 						$result['exact'][] = [
115
-							'label' => $contact['FN'] . " ($cloudId)",
115
+							'label' => $contact['FN']." ($cloudId)",
116 116
 							'uuid' => $contact['UID'],
117 117
 							'name' => $contact['FN'],
118 118
 							'type' => $cloudIdType,
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 						];
125 125
 					} else {
126 126
 						$result['wide'][] = [
127
-							'label' => $contact['FN'] . " ($cloudId)",
127
+							'label' => $contact['FN']." ($cloudId)",
128 128
 							'uuid' => $contact['UID'],
129 129
 							'name' => $contact['FN'],
130 130
 							'type' => $cloudIdType,
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 				$localUser = $this->userManager->get($remoteUser);
155 155
 				if ($localUser === null || $search !== $localUser->getCloudId()) {
156 156
 					$result['exact'][] = [
157
-						'label' => $remoteUser . " ($serverUrl)",
157
+						'label' => $remoteUser." ($serverUrl)",
158 158
 						'uuid' => $remoteUser,
159 159
 						'name' => $remoteUser,
160 160
 						'value' => [
Please login to merge, or discard this patch.
Indentation   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -37,160 +37,160 @@
 block discarded – undo
37 37
 use OCP\Share\IShare;
38 38
 
39 39
 class RemotePlugin implements ISearchPlugin {
40
-	protected $shareeEnumeration;
40
+    protected $shareeEnumeration;
41 41
 
42
-	/** @var IManager */
43
-	private $contactsManager;
44
-	/** @var ICloudIdManager */
45
-	private $cloudIdManager;
46
-	/** @var IConfig */
47
-	private $config;
48
-	/** @var IUserManager */
49
-	private $userManager;
50
-	/** @var string */
51
-	private $userId = '';
42
+    /** @var IManager */
43
+    private $contactsManager;
44
+    /** @var ICloudIdManager */
45
+    private $cloudIdManager;
46
+    /** @var IConfig */
47
+    private $config;
48
+    /** @var IUserManager */
49
+    private $userManager;
50
+    /** @var string */
51
+    private $userId = '';
52 52
 
53
-	public function __construct(IManager $contactsManager, ICloudIdManager $cloudIdManager, IConfig $config, IUserManager $userManager, IUserSession $userSession) {
54
-		$this->contactsManager = $contactsManager;
55
-		$this->cloudIdManager = $cloudIdManager;
56
-		$this->config = $config;
57
-		$this->userManager = $userManager;
58
-		$user = $userSession->getUser();
59
-		if ($user !== null) {
60
-			$this->userId = $user->getUID();
61
-		}
62
-		$this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
63
-	}
53
+    public function __construct(IManager $contactsManager, ICloudIdManager $cloudIdManager, IConfig $config, IUserManager $userManager, IUserSession $userSession) {
54
+        $this->contactsManager = $contactsManager;
55
+        $this->cloudIdManager = $cloudIdManager;
56
+        $this->config = $config;
57
+        $this->userManager = $userManager;
58
+        $user = $userSession->getUser();
59
+        if ($user !== null) {
60
+            $this->userId = $user->getUID();
61
+        }
62
+        $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
63
+    }
64 64
 
65
-	public function search($search, $limit, $offset, ISearchResult $searchResult) {
66
-		$result = ['wide' => [], 'exact' => []];
67
-		$resultType = new SearchResultType('remotes');
65
+    public function search($search, $limit, $offset, ISearchResult $searchResult) {
66
+        $result = ['wide' => [], 'exact' => []];
67
+        $resultType = new SearchResultType('remotes');
68 68
 
69
-		// Search in contacts
70
-		$addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN'], [
71
-			'limit' => $limit,
72
-			'offset' => $offset,
73
-			'enumeration' => false,
74
-			'fullmatch' => false,
75
-		]);
76
-		foreach ($addressBookContacts as $contact) {
77
-			if (isset($contact['isLocalSystemBook'])) {
78
-				continue;
79
-			}
80
-			if (isset($contact['CLOUD'])) {
81
-				$cloudIds = $contact['CLOUD'];
82
-				if (is_string($cloudIds)) {
83
-					$cloudIds = [$cloudIds];
84
-				}
85
-				$lowerSearch = strtolower($search);
86
-				foreach ($cloudIds as $cloudId) {
87
-					$cloudIdType = '';
88
-					if (\is_array($cloudId)) {
89
-						$cloudIdData = $cloudId;
90
-						$cloudId = $cloudIdData['value'];
91
-						$cloudIdType = $cloudIdData['type'];
92
-					}
93
-					try {
94
-						[$remoteUser, $serverUrl] = $this->splitUserRemote($cloudId);
95
-					} catch (\InvalidArgumentException $e) {
96
-						continue;
97
-					}
69
+        // Search in contacts
70
+        $addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN'], [
71
+            'limit' => $limit,
72
+            'offset' => $offset,
73
+            'enumeration' => false,
74
+            'fullmatch' => false,
75
+        ]);
76
+        foreach ($addressBookContacts as $contact) {
77
+            if (isset($contact['isLocalSystemBook'])) {
78
+                continue;
79
+            }
80
+            if (isset($contact['CLOUD'])) {
81
+                $cloudIds = $contact['CLOUD'];
82
+                if (is_string($cloudIds)) {
83
+                    $cloudIds = [$cloudIds];
84
+                }
85
+                $lowerSearch = strtolower($search);
86
+                foreach ($cloudIds as $cloudId) {
87
+                    $cloudIdType = '';
88
+                    if (\is_array($cloudId)) {
89
+                        $cloudIdData = $cloudId;
90
+                        $cloudId = $cloudIdData['value'];
91
+                        $cloudIdType = $cloudIdData['type'];
92
+                    }
93
+                    try {
94
+                        [$remoteUser, $serverUrl] = $this->splitUserRemote($cloudId);
95
+                    } catch (\InvalidArgumentException $e) {
96
+                        continue;
97
+                    }
98 98
 
99
-					$localUser = $this->userManager->get($remoteUser);
100
-					/**
101
-					 * Add local share if remote cloud id matches a local user ones
102
-					 */
103
-					if ($localUser !== null && $remoteUser !== $this->userId && $cloudId === $localUser->getCloudId()) {
104
-						$result['wide'][] = [
105
-							'label' => $contact['FN'],
106
-							'uuid' => $contact['UID'],
107
-							'value' => [
108
-								'shareType' => IShare::TYPE_USER,
109
-								'shareWith' => $remoteUser
110
-							],
111
-							'shareWithDisplayNameUnique' => $contact['EMAIL'] !== null && $contact['EMAIL'] !== '' ? $contact['EMAIL'] : $contact['UID'],
112
-						];
113
-					}
99
+                    $localUser = $this->userManager->get($remoteUser);
100
+                    /**
101
+                     * Add local share if remote cloud id matches a local user ones
102
+                     */
103
+                    if ($localUser !== null && $remoteUser !== $this->userId && $cloudId === $localUser->getCloudId()) {
104
+                        $result['wide'][] = [
105
+                            'label' => $contact['FN'],
106
+                            'uuid' => $contact['UID'],
107
+                            'value' => [
108
+                                'shareType' => IShare::TYPE_USER,
109
+                                'shareWith' => $remoteUser
110
+                            ],
111
+                            'shareWithDisplayNameUnique' => $contact['EMAIL'] !== null && $contact['EMAIL'] !== '' ? $contact['EMAIL'] : $contact['UID'],
112
+                        ];
113
+                    }
114 114
 
115
-					if (strtolower($contact['FN']) === $lowerSearch || strtolower($cloudId) === $lowerSearch) {
116
-						if (strtolower($cloudId) === $lowerSearch) {
117
-							$searchResult->markExactIdMatch($resultType);
118
-						}
119
-						$result['exact'][] = [
120
-							'label' => $contact['FN'] . " ($cloudId)",
121
-							'uuid' => $contact['UID'],
122
-							'name' => $contact['FN'],
123
-							'type' => $cloudIdType,
124
-							'value' => [
125
-								'shareType' => IShare::TYPE_REMOTE,
126
-								'shareWith' => $cloudId,
127
-								'server' => $serverUrl,
128
-							],
129
-						];
130
-					} else {
131
-						$result['wide'][] = [
132
-							'label' => $contact['FN'] . " ($cloudId)",
133
-							'uuid' => $contact['UID'],
134
-							'name' => $contact['FN'],
135
-							'type' => $cloudIdType,
136
-							'value' => [
137
-								'shareType' => IShare::TYPE_REMOTE,
138
-								'shareWith' => $cloudId,
139
-								'server' => $serverUrl,
140
-							],
141
-						];
142
-					}
143
-				}
144
-			}
145
-		}
115
+                    if (strtolower($contact['FN']) === $lowerSearch || strtolower($cloudId) === $lowerSearch) {
116
+                        if (strtolower($cloudId) === $lowerSearch) {
117
+                            $searchResult->markExactIdMatch($resultType);
118
+                        }
119
+                        $result['exact'][] = [
120
+                            'label' => $contact['FN'] . " ($cloudId)",
121
+                            'uuid' => $contact['UID'],
122
+                            'name' => $contact['FN'],
123
+                            'type' => $cloudIdType,
124
+                            'value' => [
125
+                                'shareType' => IShare::TYPE_REMOTE,
126
+                                'shareWith' => $cloudId,
127
+                                'server' => $serverUrl,
128
+                            ],
129
+                        ];
130
+                    } else {
131
+                        $result['wide'][] = [
132
+                            'label' => $contact['FN'] . " ($cloudId)",
133
+                            'uuid' => $contact['UID'],
134
+                            'name' => $contact['FN'],
135
+                            'type' => $cloudIdType,
136
+                            'value' => [
137
+                                'shareType' => IShare::TYPE_REMOTE,
138
+                                'shareWith' => $cloudId,
139
+                                'server' => $serverUrl,
140
+                            ],
141
+                        ];
142
+                    }
143
+                }
144
+            }
145
+        }
146 146
 
147
-		if (!$this->shareeEnumeration) {
148
-			$result['wide'] = [];
149
-		} else {
150
-			$result['wide'] = array_slice($result['wide'], $offset, $limit);
151
-		}
147
+        if (!$this->shareeEnumeration) {
148
+            $result['wide'] = [];
149
+        } else {
150
+            $result['wide'] = array_slice($result['wide'], $offset, $limit);
151
+        }
152 152
 
153
-		/**
154
-		 * Add generic share with remote item for valid cloud ids that are not users of the local instance
155
-		 */
156
-		if (!$searchResult->hasExactIdMatch($resultType) && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) {
157
-			try {
158
-				[$remoteUser, $serverUrl] = $this->splitUserRemote($search);
159
-				$localUser = $this->userManager->get($remoteUser);
160
-				if ($localUser === null || $search !== $localUser->getCloudId()) {
161
-					$result['exact'][] = [
162
-						'label' => $remoteUser . " ($serverUrl)",
163
-						'uuid' => $remoteUser,
164
-						'name' => $remoteUser,
165
-						'value' => [
166
-							'shareType' => IShare::TYPE_REMOTE,
167
-							'shareWith' => $search,
168
-							'server' => $serverUrl,
169
-						],
170
-					];
171
-				}
172
-			} catch (\InvalidArgumentException $e) {
173
-			}
174
-		}
153
+        /**
154
+         * Add generic share with remote item for valid cloud ids that are not users of the local instance
155
+         */
156
+        if (!$searchResult->hasExactIdMatch($resultType) && $this->cloudIdManager->isValidCloudId($search) && $offset === 0) {
157
+            try {
158
+                [$remoteUser, $serverUrl] = $this->splitUserRemote($search);
159
+                $localUser = $this->userManager->get($remoteUser);
160
+                if ($localUser === null || $search !== $localUser->getCloudId()) {
161
+                    $result['exact'][] = [
162
+                        'label' => $remoteUser . " ($serverUrl)",
163
+                        'uuid' => $remoteUser,
164
+                        'name' => $remoteUser,
165
+                        'value' => [
166
+                            'shareType' => IShare::TYPE_REMOTE,
167
+                            'shareWith' => $search,
168
+                            'server' => $serverUrl,
169
+                        ],
170
+                    ];
171
+                }
172
+            } catch (\InvalidArgumentException $e) {
173
+            }
174
+        }
175 175
 
176
-		$searchResult->addResultSet($resultType, $result['wide'], $result['exact']);
176
+        $searchResult->addResultSet($resultType, $result['wide'], $result['exact']);
177 177
 
178
-		return true;
179
-	}
178
+        return true;
179
+    }
180 180
 
181
-	/**
182
-	 * split user and remote from federated cloud id
183
-	 *
184
-	 * @param string $address federated share address
185
-	 * @return array [user, remoteURL]
186
-	 * @throws \InvalidArgumentException
187
-	 */
188
-	public function splitUserRemote($address) {
189
-		try {
190
-			$cloudId = $this->cloudIdManager->resolveCloudId($address);
191
-			return [$cloudId->getUser(), $cloudId->getRemote()];
192
-		} catch (\InvalidArgumentException $e) {
193
-			throw new \InvalidArgumentException('Invalid Federated Cloud ID', 0, $e);
194
-		}
195
-	}
181
+    /**
182
+     * split user and remote from federated cloud id
183
+     *
184
+     * @param string $address federated share address
185
+     * @return array [user, remoteURL]
186
+     * @throws \InvalidArgumentException
187
+     */
188
+    public function splitUserRemote($address) {
189
+        try {
190
+            $cloudId = $this->cloudIdManager->resolveCloudId($address);
191
+            return [$cloudId->getUser(), $cloudId->getRemote()];
192
+        } catch (\InvalidArgumentException $e) {
193
+            throw new \InvalidArgumentException('Invalid Federated Cloud ID', 0, $e);
194
+        }
195
+    }
196 196
 }
Please login to merge, or discard this patch.
lib/private/Color.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -24,12 +24,12 @@
 block discarded – undo
24 24
 namespace OC;
25 25
 
26 26
 class Color {
27
-	public $r;
28
-	public $g;
29
-	public $b;
30
-	public function __construct($r, $g, $b) {
31
-		$this->r = $r;
32
-		$this->g = $g;
33
-		$this->b = $b;
34
-	}
27
+    public $r;
28
+    public $g;
29
+    public $b;
30
+    public function __construct($r, $g, $b) {
31
+        $this->r = $r;
32
+        $this->g = $g;
33
+        $this->b = $b;
34
+    }
35 35
 }
Please login to merge, or discard this patch.