Completed
Push — master ( 7b60e3...8d70e9 )
by
unknown
20:41
created
apps/dav/lib/CalDAV/Plugin.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -26,30 +26,30 @@
 block discarded – undo
26 26
 namespace OCA\DAV\CalDAV;
27 27
 
28 28
 class Plugin extends \Sabre\CalDAV\Plugin {
29
-	public const SYSTEM_CALENDAR_ROOT = 'system-calendars';
29
+    public const SYSTEM_CALENDAR_ROOT = 'system-calendars';
30 30
 
31
-	/**
32
-	 * Returns the path to a principal's calendar home.
33
-	 *
34
-	 * The return url must not end with a slash.
35
-	 * This function should return null in case a principal did not have
36
-	 * a calendar home.
37
-	 *
38
-	 * @param string $principalUrl
39
-	 * @return string|null
40
-	 */
41
-	public function getCalendarHomeForPrincipal($principalUrl) {
42
-		if (strrpos($principalUrl, 'principals/users', -strlen($principalUrl)) !== false) {
43
-			[, $principalId] = \Sabre\Uri\split($principalUrl);
44
-			return self::CALENDAR_ROOT . '/' . $principalId;
45
-		}
46
-		if (strrpos($principalUrl, 'principals/calendar-resources', -strlen($principalUrl)) !== false) {
47
-			[, $principalId] = \Sabre\Uri\split($principalUrl);
48
-			return self::SYSTEM_CALENDAR_ROOT . '/calendar-resources/' . $principalId;
49
-		}
50
-		if (strrpos($principalUrl, 'principals/calendar-rooms', -strlen($principalUrl)) !== false) {
51
-			[, $principalId] = \Sabre\Uri\split($principalUrl);
52
-			return self::SYSTEM_CALENDAR_ROOT . '/calendar-rooms/' . $principalId;
53
-		}
54
-	}
31
+    /**
32
+     * Returns the path to a principal's calendar home.
33
+     *
34
+     * The return url must not end with a slash.
35
+     * This function should return null in case a principal did not have
36
+     * a calendar home.
37
+     *
38
+     * @param string $principalUrl
39
+     * @return string|null
40
+     */
41
+    public function getCalendarHomeForPrincipal($principalUrl) {
42
+        if (strrpos($principalUrl, 'principals/users', -strlen($principalUrl)) !== false) {
43
+            [, $principalId] = \Sabre\Uri\split($principalUrl);
44
+            return self::CALENDAR_ROOT . '/' . $principalId;
45
+        }
46
+        if (strrpos($principalUrl, 'principals/calendar-resources', -strlen($principalUrl)) !== false) {
47
+            [, $principalId] = \Sabre\Uri\split($principalUrl);
48
+            return self::SYSTEM_CALENDAR_ROOT . '/calendar-resources/' . $principalId;
49
+        }
50
+        if (strrpos($principalUrl, 'principals/calendar-rooms', -strlen($principalUrl)) !== false) {
51
+            [, $principalId] = \Sabre\Uri\split($principalUrl);
52
+            return self::SYSTEM_CALENDAR_ROOT . '/calendar-rooms/' . $principalId;
53
+        }
54
+    }
55 55
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -41,15 +41,15 @@
 block discarded – undo
41 41
 	public function getCalendarHomeForPrincipal($principalUrl) {
42 42
 		if (strrpos($principalUrl, 'principals/users', -strlen($principalUrl)) !== false) {
43 43
 			[, $principalId] = \Sabre\Uri\split($principalUrl);
44
-			return self::CALENDAR_ROOT . '/' . $principalId;
44
+			return self::CALENDAR_ROOT.'/'.$principalId;
45 45
 		}
46 46
 		if (strrpos($principalUrl, 'principals/calendar-resources', -strlen($principalUrl)) !== false) {
47 47
 			[, $principalId] = \Sabre\Uri\split($principalUrl);
48
-			return self::SYSTEM_CALENDAR_ROOT . '/calendar-resources/' . $principalId;
48
+			return self::SYSTEM_CALENDAR_ROOT.'/calendar-resources/'.$principalId;
49 49
 		}
50 50
 		if (strrpos($principalUrl, 'principals/calendar-rooms', -strlen($principalUrl)) !== false) {
51 51
 			[, $principalId] = \Sabre\Uri\split($principalUrl);
52
-			return self::SYSTEM_CALENDAR_ROOT . '/calendar-rooms/' . $principalId;
52
+			return self::SYSTEM_CALENDAR_ROOT.'/calendar-rooms/'.$principalId;
53 53
 		}
54 54
 	}
55 55
 }
Please login to merge, or discard this patch.
apps/settings/lib/Listener/AppPasswordCreatedActivityListener.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
 		try {
66 66
 			$this->activityManager->publish($activity);
67 67
 		} catch (BadMethodCallException $e) {
68
-			$this->logger->warning('Could not publish activity: ' . $e->getMessage(), [
68
+			$this->logger->warning('Could not publish activity: '.$e->getMessage(), [
69 69
 				'exception' => $e
70 70
 			]);
71 71
 		}
Please login to merge, or discard this patch.
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -21,32 +21,32 @@
 block discarded – undo
21 21
  * @template-implements IEventListener<\OC\Authentication\Events\AppPasswordCreatedEvent>
22 22
  */
23 23
 class AppPasswordCreatedActivityListener implements IEventListener {
24
-	public function __construct(
25
-		private IActivityManager $activityManager,
26
-		private IUserSession $userSession,
27
-		private LoggerInterface $logger,
28
-	) {
29
-	}
24
+    public function __construct(
25
+        private IActivityManager $activityManager,
26
+        private IUserSession $userSession,
27
+        private LoggerInterface $logger,
28
+    ) {
29
+    }
30 30
 
31
-	public function handle(Event $event): void {
32
-		if (!($event instanceof AppPasswordCreatedEvent)) {
33
-			return;
34
-		}
31
+    public function handle(Event $event): void {
32
+        if (!($event instanceof AppPasswordCreatedEvent)) {
33
+            return;
34
+        }
35 35
 
36
-		$activity = $this->activityManager->generateEvent();
37
-		$activity->setApp('settings')
38
-			->setType('security')
39
-			->setAffectedUser($event->getToken()->getUID())
40
-			->setAuthor($this->userSession->getUser() ? $this->userSession->getUser()->getUID() : '')
41
-			->setSubject(Provider::APP_TOKEN_CREATED, ['name' => $event->getToken()->getName()])
42
-			->setObject('app_token', $event->getToken()->getId());
36
+        $activity = $this->activityManager->generateEvent();
37
+        $activity->setApp('settings')
38
+            ->setType('security')
39
+            ->setAffectedUser($event->getToken()->getUID())
40
+            ->setAuthor($this->userSession->getUser() ? $this->userSession->getUser()->getUID() : '')
41
+            ->setSubject(Provider::APP_TOKEN_CREATED, ['name' => $event->getToken()->getName()])
42
+            ->setObject('app_token', $event->getToken()->getId());
43 43
 
44
-		try {
45
-			$this->activityManager->publish($activity);
46
-		} catch (BadMethodCallException $e) {
47
-			$this->logger->warning('Could not publish activity: ' . $e->getMessage(), [
48
-				'exception' => $e
49
-			]);
50
-		}
51
-	}
44
+        try {
45
+            $this->activityManager->publish($activity);
46
+        } catch (BadMethodCallException $e) {
47
+            $this->logger->warning('Could not publish activity: ' . $e->getMessage(), [
48
+                'exception' => $e
49
+            ]);
50
+        }
51
+    }
52 52
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Service/DBConfigService.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 		$stmt->closeCursor();
141 141
 
142 142
 		foreach ($result as $row) {
143
-			if ((int)$row['count'] > 1) {
143
+			if ((int) $row['count'] > 1) {
144 144
 				$this->removeApplicable($row['mount_id'], $applicableType, $applicableId);
145 145
 			} else {
146 146
 				$this->removeMount($row['mount_id']);
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 	 */
215 215
 	public function getAdminMountsForMultiple($type, array $values) {
216 216
 		$builder = $this->connection->getQueryBuilder();
217
-		$params = array_map(function ($value) use ($builder) {
217
+		$params = array_map(function($value) use ($builder) {
218 218
 			return $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR);
219 219
 		}, $values);
220 220
 
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
 		}
413 413
 		$uniqueMounts = array_values($uniqueMounts);
414 414
 
415
-		$mountIds = array_map(function ($mount) {
415
+		$mountIds = array_map(function($mount) {
416 416
 			return $mount['mount_id'];
417 417
 		}, $uniqueMounts);
418 418
 		$mountIds = array_values(array_unique($mountIds));
@@ -421,9 +421,9 @@  discard block
 block discarded – undo
421 421
 		$config = $this->getConfigForMounts($mountIds);
422 422
 		$options = $this->getOptionsForMounts($mountIds);
423 423
 
424
-		return array_map(function ($mount, $applicable, $config, $options) {
425
-			$mount['type'] = (int)$mount['type'];
426
-			$mount['priority'] = (int)$mount['priority'];
424
+		return array_map(function($mount, $applicable, $config, $options) {
425
+			$mount['type'] = (int) $mount['type'];
426
+			$mount['priority'] = (int) $mount['priority'];
427 427
 			$mount['applicable'] = $applicable;
428 428
 			$mount['config'] = $config;
429 429
 			$mount['options'] = $options;
@@ -445,7 +445,7 @@  discard block
 block discarded – undo
445 445
 		}
446 446
 		$builder = $this->connection->getQueryBuilder();
447 447
 		$fields[] = 'mount_id';
448
-		$placeHolders = array_map(function ($id) use ($builder) {
448
+		$placeHolders = array_map(function($id) use ($builder) {
449 449
 			return $builder->createPositionalParameter($id, IQueryBuilder::PARAM_INT);
450 450
 		}, $mountIds);
451 451
 		$query = $builder->select($fields)
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
 		}
463 463
 		foreach ($rows as $row) {
464 464
 			if (isset($row['type'])) {
465
-				$row['type'] = (int)$row['type'];
465
+				$row['type'] = (int) $row['type'];
466 466
 			}
467 467
 			$result[$row['mount_id']][] = $row;
468 468
 		}
@@ -493,8 +493,8 @@  discard block
 block discarded – undo
493 493
 	public function getOptionsForMounts($mountIds) {
494 494
 		$mountOptions = $this->selectForMounts('external_options', ['key', 'value'], $mountIds);
495 495
 		$optionsMap = array_map([$this, 'createKeyValueMap'], $mountOptions);
496
-		return array_map(function (array $options) {
497
-			return array_map(function ($option) {
496
+		return array_map(function(array $options) {
497
+			return array_map(function($option) {
498 498
 				return json_decode($option);
499 499
 			}, $options);
500 500
 		}, $optionsMap);
@@ -505,16 +505,16 @@  discard block
 block discarded – undo
505 505
 	 * @return array ['key1' => $value1, ...]
506 506
 	 */
507 507
 	private function createKeyValueMap(array $keyValuePairs) {
508
-		$decryptedPairts = array_map(function ($pair) {
508
+		$decryptedPairts = array_map(function($pair) {
509 509
 			if ($pair['key'] === 'password') {
510 510
 				$pair['value'] = $this->decryptValue($pair['value']);
511 511
 			}
512 512
 			return $pair;
513 513
 		}, $keyValuePairs);
514
-		$keys = array_map(function ($pair) {
514
+		$keys = array_map(function($pair) {
515 515
 			return $pair['key'];
516 516
 		}, $decryptedPairts);
517
-		$values = array_map(function ($pair) {
517
+		$values = array_map(function($pair) {
518 518
 			return $pair['value'];
519 519
 		}, $decryptedPairts);
520 520
 
Please login to merge, or discard this patch.
Indentation   +491 added lines, -491 removed lines patch added patch discarded remove patch
@@ -16,495 +16,495 @@
 block discarded – undo
16 16
  * Stores the mount config in the database
17 17
  */
18 18
 class DBConfigService {
19
-	public const MOUNT_TYPE_ADMIN = 1;
20
-	public const MOUNT_TYPE_PERSONAL = 2;
21
-	/** @deprecated use MOUNT_TYPE_PERSONAL (full uppercase) instead */
22
-	public const MOUNT_TYPE_PERSONAl = 2;
23
-
24
-	public const APPLICABLE_TYPE_GLOBAL = 1;
25
-	public const APPLICABLE_TYPE_GROUP = 2;
26
-	public const APPLICABLE_TYPE_USER = 3;
27
-
28
-	public function __construct(
29
-		private IDBConnection $connection,
30
-		private ICrypto $crypto,
31
-	) {
32
-	}
33
-
34
-	public function getMountById(int $mountId): ?array {
35
-		$builder = $this->connection->getQueryBuilder();
36
-		$query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type'])
37
-			->from('external_mounts', 'm')
38
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
39
-		$mounts = $this->getMountsFromQuery($query);
40
-		if (count($mounts) > 0) {
41
-			return $mounts[0];
42
-		} else {
43
-			return null;
44
-		}
45
-	}
46
-
47
-	/**
48
-	 * Get all configured mounts
49
-	 *
50
-	 * @return array
51
-	 */
52
-	public function getAllMounts() {
53
-		$builder = $this->connection->getQueryBuilder();
54
-		$query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type'])
55
-			->from('external_mounts');
56
-		return $this->getMountsFromQuery($query);
57
-	}
58
-
59
-	public function getMountsForUser($userId, $groupIds) {
60
-		$builder = $this->connection->getQueryBuilder();
61
-		$query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
62
-			->from('external_mounts', 'm')
63
-			->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id'))
64
-			->where($builder->expr()->orX(
65
-				$builder->expr()->andX( // global mounts
66
-					$builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GLOBAL, IQueryBuilder::PARAM_INT)),
67
-					$builder->expr()->isNull('a.value')
68
-				),
69
-				$builder->expr()->andX( // mounts for user
70
-					$builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_USER, IQueryBuilder::PARAM_INT)),
71
-					$builder->expr()->eq('a.value', $builder->createNamedParameter($userId))
72
-				),
73
-				$builder->expr()->andX( // mounts for group
74
-					$builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GROUP, IQueryBuilder::PARAM_INT)),
75
-					$builder->expr()->in('a.value', $builder->createNamedParameter($groupIds, IQueryBuilder::PARAM_STR_ARRAY))
76
-				)
77
-			));
78
-
79
-		return $this->getMountsFromQuery($query);
80
-	}
81
-
82
-	public function modifyMountsOnUserDelete(string $uid): void {
83
-		$this->modifyMountsOnDelete($uid, self::APPLICABLE_TYPE_USER);
84
-	}
85
-
86
-	public function modifyMountsOnGroupDelete(string $gid): void {
87
-		$this->modifyMountsOnDelete($gid, self::APPLICABLE_TYPE_GROUP);
88
-	}
89
-
90
-	protected function modifyMountsOnDelete(string $applicableId, int $applicableType): void {
91
-		$builder = $this->connection->getQueryBuilder();
92
-		$query = $builder->select(['a.mount_id', $builder->func()->count('a.mount_id', 'count')])
93
-			->from('external_applicable', 'a')
94
-			->leftJoin('a', 'external_applicable', 'b', $builder->expr()->eq('a.mount_id', 'b.mount_id'))
95
-			->where($builder->expr()->andX(
96
-				$builder->expr()->eq('b.type', $builder->createNamedParameter($applicableType, IQueryBuilder::PARAM_INT)),
97
-				$builder->expr()->eq('b.value', $builder->createNamedParameter($applicableId))
98
-			)
99
-			)
100
-			->groupBy(['a.mount_id']);
101
-		$stmt = $query->executeQuery();
102
-		$result = $stmt->fetchAll();
103
-		$stmt->closeCursor();
104
-
105
-		foreach ($result as $row) {
106
-			if ((int)$row['count'] > 1) {
107
-				$this->removeApplicable($row['mount_id'], $applicableType, $applicableId);
108
-			} else {
109
-				$this->removeMount($row['mount_id']);
110
-			}
111
-		}
112
-	}
113
-
114
-	/**
115
-	 * Get admin defined mounts
116
-	 *
117
-	 * @return array
118
-	 */
119
-	public function getAdminMounts() {
120
-		$builder = $this->connection->getQueryBuilder();
121
-		$query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type'])
122
-			->from('external_mounts')
123
-			->where($builder->expr()->eq('type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT)));
124
-		return $this->getMountsFromQuery($query);
125
-	}
126
-
127
-	protected function getForQuery(IQueryBuilder $builder, $type, $value) {
128
-		$query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
129
-			->from('external_mounts', 'm')
130
-			->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id'))
131
-			->where($builder->expr()->eq('a.type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)));
132
-
133
-		if (is_null($value)) {
134
-			$query = $query->andWhere($builder->expr()->isNull('a.value'));
135
-		} else {
136
-			$query = $query->andWhere($builder->expr()->eq('a.value', $builder->createNamedParameter($value)));
137
-		}
138
-
139
-		return $query;
140
-	}
141
-
142
-	/**
143
-	 * Get mounts by applicable
144
-	 *
145
-	 * @param int $type any of the self::APPLICABLE_TYPE_ constants
146
-	 * @param string|null $value user_id, group_id or null for global mounts
147
-	 * @return array
148
-	 */
149
-	public function getMountsFor($type, $value) {
150
-		$builder = $this->connection->getQueryBuilder();
151
-		$query = $this->getForQuery($builder, $type, $value);
152
-
153
-		return $this->getMountsFromQuery($query);
154
-	}
155
-
156
-	/**
157
-	 * Get admin defined mounts by applicable
158
-	 *
159
-	 * @param int $type any of the self::APPLICABLE_TYPE_ constants
160
-	 * @param string|null $value user_id, group_id or null for global mounts
161
-	 * @return array
162
-	 */
163
-	public function getAdminMountsFor($type, $value) {
164
-		$builder = $this->connection->getQueryBuilder();
165
-		$query = $this->getForQuery($builder, $type, $value);
166
-		$query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT)));
167
-
168
-		return $this->getMountsFromQuery($query);
169
-	}
170
-
171
-	/**
172
-	 * Get admin defined mounts for multiple applicable
173
-	 *
174
-	 * @param int $type any of the self::APPLICABLE_TYPE_ constants
175
-	 * @param string[] $values user_ids or group_ids
176
-	 * @return array
177
-	 */
178
-	public function getAdminMountsForMultiple($type, array $values) {
179
-		$builder = $this->connection->getQueryBuilder();
180
-		$params = array_map(function ($value) use ($builder) {
181
-			return $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR);
182
-		}, $values);
183
-
184
-		$query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
185
-			->from('external_mounts', 'm')
186
-			->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id'))
187
-			->where($builder->expr()->eq('a.type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)))
188
-			->andWhere($builder->expr()->in('a.value', $params));
189
-		$query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT)));
190
-
191
-		return $this->getMountsFromQuery($query);
192
-	}
193
-
194
-	/**
195
-	 * Get user defined mounts by applicable
196
-	 *
197
-	 * @param int $type any of the self::APPLICABLE_TYPE_ constants
198
-	 * @param string|null $value user_id, group_id or null for global mounts
199
-	 * @return array
200
-	 */
201
-	public function getUserMountsFor($type, $value) {
202
-		$builder = $this->connection->getQueryBuilder();
203
-		$query = $this->getForQuery($builder, $type, $value);
204
-		$query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_PERSONAL, IQueryBuilder::PARAM_INT)));
205
-
206
-		return $this->getMountsFromQuery($query);
207
-	}
208
-
209
-	/**
210
-	 * Add a mount to the database
211
-	 *
212
-	 * @param string $mountPoint
213
-	 * @param string $storageBackend
214
-	 * @param string $authBackend
215
-	 * @param int $priority
216
-	 * @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAL
217
-	 * @return int the id of the new mount
218
-	 */
219
-	public function addMount($mountPoint, $storageBackend, $authBackend, $priority, $type) {
220
-		if (!$priority) {
221
-			$priority = 100;
222
-		}
223
-		$builder = $this->connection->getQueryBuilder();
224
-		$query = $builder->insert('external_mounts')
225
-			->values([
226
-				'mount_point' => $builder->createNamedParameter($mountPoint, IQueryBuilder::PARAM_STR),
227
-				'storage_backend' => $builder->createNamedParameter($storageBackend, IQueryBuilder::PARAM_STR),
228
-				'auth_backend' => $builder->createNamedParameter($authBackend, IQueryBuilder::PARAM_STR),
229
-				'priority' => $builder->createNamedParameter($priority, IQueryBuilder::PARAM_INT),
230
-				'type' => $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)
231
-			]);
232
-		$query->executeStatement();
233
-		return $query->getLastInsertId();
234
-	}
235
-
236
-	/**
237
-	 * Remove a mount from the database
238
-	 *
239
-	 * @param int $mountId
240
-	 */
241
-	public function removeMount($mountId) {
242
-		$builder = $this->connection->getQueryBuilder();
243
-		$query = $builder->delete('external_mounts')
244
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
245
-		$query->executeStatement();
246
-
247
-		$builder = $this->connection->getQueryBuilder();
248
-		$query = $builder->delete('external_applicable')
249
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
250
-		$query->executeStatement();
251
-
252
-		$builder = $this->connection->getQueryBuilder();
253
-		$query = $builder->delete('external_config')
254
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
255
-		$query->executeStatement();
256
-
257
-		$builder = $this->connection->getQueryBuilder();
258
-		$query = $builder->delete('external_options')
259
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
260
-		$query->executeStatement();
261
-	}
262
-
263
-	/**
264
-	 * @param int $mountId
265
-	 * @param string $newMountPoint
266
-	 */
267
-	public function setMountPoint($mountId, $newMountPoint) {
268
-		$builder = $this->connection->getQueryBuilder();
269
-
270
-		$query = $builder->update('external_mounts')
271
-			->set('mount_point', $builder->createNamedParameter($newMountPoint))
272
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
273
-
274
-		$query->executeStatement();
275
-	}
276
-
277
-	/**
278
-	 * @param int $mountId
279
-	 * @param string $newAuthBackend
280
-	 */
281
-	public function setAuthBackend($mountId, $newAuthBackend) {
282
-		$builder = $this->connection->getQueryBuilder();
283
-
284
-		$query = $builder->update('external_mounts')
285
-			->set('auth_backend', $builder->createNamedParameter($newAuthBackend))
286
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
287
-
288
-		$query->executeStatement();
289
-	}
290
-
291
-	/**
292
-	 * @param int $mountId
293
-	 * @param string $key
294
-	 * @param string $value
295
-	 */
296
-	public function setConfig($mountId, $key, $value) {
297
-		if ($key === 'password') {
298
-			$value = $this->encryptValue($value);
299
-		}
300
-
301
-		try {
302
-			$builder = $this->connection->getQueryBuilder();
303
-			$builder->insert('external_config')
304
-				->setValue('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))
305
-				->setValue('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR))
306
-				->setValue('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR))
307
-				->executeStatement();
308
-		} catch (Exception $e) {
309
-			if ($e->getReason() !== Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
310
-				throw $e;
311
-			}
312
-			$builder = $this->connection->getQueryBuilder();
313
-			$query = $builder->update('external_config')
314
-				->set('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR))
315
-				->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
316
-				->andWhere($builder->expr()->eq('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR)));
317
-			$query->executeStatement();
318
-		}
319
-	}
320
-
321
-	/**
322
-	 * @param int $mountId
323
-	 * @param string $key
324
-	 * @param string $value
325
-	 */
326
-	public function setOption($mountId, $key, $value) {
327
-		try {
328
-			$builder = $this->connection->getQueryBuilder();
329
-			$builder->insert('external_options')
330
-				->setValue('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))
331
-				->setValue('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR))
332
-				->setValue('value', $builder->createNamedParameter(json_encode($value), IQueryBuilder::PARAM_STR))
333
-				->executeStatement();
334
-		} catch (Exception $e) {
335
-			if ($e->getReason() !== Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
336
-				throw $e;
337
-			}
338
-			$builder = $this->connection->getQueryBuilder();
339
-			$query = $builder->update('external_options')
340
-				->set('value', $builder->createNamedParameter(json_encode($value), IQueryBuilder::PARAM_STR))
341
-				->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
342
-				->andWhere($builder->expr()->eq('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR)));
343
-			$query->executeStatement();
344
-		}
345
-	}
346
-
347
-	public function addApplicable($mountId, $type, $value) {
348
-		try {
349
-			$builder = $this->connection->getQueryBuilder();
350
-			$builder->insert('external_applicable')
351
-				->setValue('mount_id', $builder->createNamedParameter($mountId))
352
-				->setValue('type', $builder->createNamedParameter($type))
353
-				->setValue('value', $builder->createNamedParameter($value))
354
-				->executeStatement();
355
-		} catch (Exception $e) {
356
-			// applicable exists already
357
-			if ($e->getReason() !== Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
358
-				throw $e;
359
-			}
360
-		}
361
-	}
362
-
363
-	public function removeApplicable($mountId, $type, $value) {
364
-		$builder = $this->connection->getQueryBuilder();
365
-		$query = $builder->delete('external_applicable')
366
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
367
-			->andWhere($builder->expr()->eq('type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)));
368
-
369
-		if (is_null($value)) {
370
-			$query = $query->andWhere($builder->expr()->isNull('value'));
371
-		} else {
372
-			$query = $query->andWhere($builder->expr()->eq('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR)));
373
-		}
374
-
375
-		$query->executeStatement();
376
-	}
377
-
378
-	private function getMountsFromQuery(IQueryBuilder $query) {
379
-		$result = $query->executeQuery();
380
-		$mounts = $result->fetchAll();
381
-		$uniqueMounts = [];
382
-		foreach ($mounts as $mount) {
383
-			$id = $mount['mount_id'];
384
-			if (!isset($uniqueMounts[$id])) {
385
-				$uniqueMounts[$id] = $mount;
386
-			}
387
-		}
388
-		$uniqueMounts = array_values($uniqueMounts);
389
-
390
-		$mountIds = array_map(function ($mount) {
391
-			return $mount['mount_id'];
392
-		}, $uniqueMounts);
393
-		$mountIds = array_values(array_unique($mountIds));
394
-
395
-		$applicable = $this->getApplicableForMounts($mountIds);
396
-		$config = $this->getConfigForMounts($mountIds);
397
-		$options = $this->getOptionsForMounts($mountIds);
398
-
399
-		return array_map(function ($mount, $applicable, $config, $options) {
400
-			$mount['type'] = (int)$mount['type'];
401
-			$mount['priority'] = (int)$mount['priority'];
402
-			$mount['applicable'] = $applicable;
403
-			$mount['config'] = $config;
404
-			$mount['options'] = $options;
405
-			return $mount;
406
-		}, $uniqueMounts, $applicable, $config, $options);
407
-	}
408
-
409
-	/**
410
-	 * Get mount options from a table grouped by mount id
411
-	 *
412
-	 * @param string $table
413
-	 * @param string[] $fields
414
-	 * @param int[] $mountIds
415
-	 * @return array [$mountId => [['field1' => $value1, ...], ...], ...]
416
-	 */
417
-	private function selectForMounts($table, array $fields, array $mountIds) {
418
-		if (count($mountIds) === 0) {
419
-			return [];
420
-		}
421
-		$builder = $this->connection->getQueryBuilder();
422
-		$fields[] = 'mount_id';
423
-		$placeHolders = array_map(function ($id) use ($builder) {
424
-			return $builder->createPositionalParameter($id, IQueryBuilder::PARAM_INT);
425
-		}, $mountIds);
426
-		$query = $builder->select($fields)
427
-			->from($table)
428
-			->where($builder->expr()->in('mount_id', $placeHolders));
429
-
430
-		$result = $query->executeQuery();
431
-		$rows = $result->fetchAll();
432
-		$result->closeCursor();
433
-
434
-		$result = [];
435
-		foreach ($mountIds as $mountId) {
436
-			$result[$mountId] = [];
437
-		}
438
-		foreach ($rows as $row) {
439
-			if (isset($row['type'])) {
440
-				$row['type'] = (int)$row['type'];
441
-			}
442
-			$result[$row['mount_id']][] = $row;
443
-		}
444
-		return $result;
445
-	}
446
-
447
-	/**
448
-	 * @param int[] $mountIds
449
-	 * @return array [$id => [['type' => $type, 'value' => $value], ...], ...]
450
-	 */
451
-	public function getApplicableForMounts($mountIds) {
452
-		return $this->selectForMounts('external_applicable', ['type', 'value'], $mountIds);
453
-	}
454
-
455
-	/**
456
-	 * @param int[] $mountIds
457
-	 * @return array [$id => ['key1' => $value1, ...], ...]
458
-	 */
459
-	public function getConfigForMounts($mountIds) {
460
-		$mountConfigs = $this->selectForMounts('external_config', ['key', 'value'], $mountIds);
461
-		return array_map([$this, 'createKeyValueMap'], $mountConfigs);
462
-	}
463
-
464
-	/**
465
-	 * @param int[] $mountIds
466
-	 * @return array [$id => ['key1' => $value1, ...], ...]
467
-	 */
468
-	public function getOptionsForMounts($mountIds) {
469
-		$mountOptions = $this->selectForMounts('external_options', ['key', 'value'], $mountIds);
470
-		$optionsMap = array_map([$this, 'createKeyValueMap'], $mountOptions);
471
-		return array_map(function (array $options) {
472
-			return array_map(function ($option) {
473
-				return json_decode($option);
474
-			}, $options);
475
-		}, $optionsMap);
476
-	}
477
-
478
-	/**
479
-	 * @param array $keyValuePairs [['key'=>$key, 'value=>$value], ...]
480
-	 * @return array ['key1' => $value1, ...]
481
-	 */
482
-	private function createKeyValueMap(array $keyValuePairs) {
483
-		$decryptedPairts = array_map(function ($pair) {
484
-			if ($pair['key'] === 'password') {
485
-				$pair['value'] = $this->decryptValue($pair['value']);
486
-			}
487
-			return $pair;
488
-		}, $keyValuePairs);
489
-		$keys = array_map(function ($pair) {
490
-			return $pair['key'];
491
-		}, $decryptedPairts);
492
-		$values = array_map(function ($pair) {
493
-			return $pair['value'];
494
-		}, $decryptedPairts);
495
-
496
-		return array_combine($keys, $values);
497
-	}
498
-
499
-	private function encryptValue($value) {
500
-		return $this->crypto->encrypt($value);
501
-	}
502
-
503
-	private function decryptValue($value) {
504
-		try {
505
-			return $this->crypto->decrypt($value);
506
-		} catch (\Exception $e) {
507
-			return $value;
508
-		}
509
-	}
19
+    public const MOUNT_TYPE_ADMIN = 1;
20
+    public const MOUNT_TYPE_PERSONAL = 2;
21
+    /** @deprecated use MOUNT_TYPE_PERSONAL (full uppercase) instead */
22
+    public const MOUNT_TYPE_PERSONAl = 2;
23
+
24
+    public const APPLICABLE_TYPE_GLOBAL = 1;
25
+    public const APPLICABLE_TYPE_GROUP = 2;
26
+    public const APPLICABLE_TYPE_USER = 3;
27
+
28
+    public function __construct(
29
+        private IDBConnection $connection,
30
+        private ICrypto $crypto,
31
+    ) {
32
+    }
33
+
34
+    public function getMountById(int $mountId): ?array {
35
+        $builder = $this->connection->getQueryBuilder();
36
+        $query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type'])
37
+            ->from('external_mounts', 'm')
38
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
39
+        $mounts = $this->getMountsFromQuery($query);
40
+        if (count($mounts) > 0) {
41
+            return $mounts[0];
42
+        } else {
43
+            return null;
44
+        }
45
+    }
46
+
47
+    /**
48
+     * Get all configured mounts
49
+     *
50
+     * @return array
51
+     */
52
+    public function getAllMounts() {
53
+        $builder = $this->connection->getQueryBuilder();
54
+        $query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type'])
55
+            ->from('external_mounts');
56
+        return $this->getMountsFromQuery($query);
57
+    }
58
+
59
+    public function getMountsForUser($userId, $groupIds) {
60
+        $builder = $this->connection->getQueryBuilder();
61
+        $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
62
+            ->from('external_mounts', 'm')
63
+            ->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id'))
64
+            ->where($builder->expr()->orX(
65
+                $builder->expr()->andX( // global mounts
66
+                    $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GLOBAL, IQueryBuilder::PARAM_INT)),
67
+                    $builder->expr()->isNull('a.value')
68
+                ),
69
+                $builder->expr()->andX( // mounts for user
70
+                    $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_USER, IQueryBuilder::PARAM_INT)),
71
+                    $builder->expr()->eq('a.value', $builder->createNamedParameter($userId))
72
+                ),
73
+                $builder->expr()->andX( // mounts for group
74
+                    $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GROUP, IQueryBuilder::PARAM_INT)),
75
+                    $builder->expr()->in('a.value', $builder->createNamedParameter($groupIds, IQueryBuilder::PARAM_STR_ARRAY))
76
+                )
77
+            ));
78
+
79
+        return $this->getMountsFromQuery($query);
80
+    }
81
+
82
+    public function modifyMountsOnUserDelete(string $uid): void {
83
+        $this->modifyMountsOnDelete($uid, self::APPLICABLE_TYPE_USER);
84
+    }
85
+
86
+    public function modifyMountsOnGroupDelete(string $gid): void {
87
+        $this->modifyMountsOnDelete($gid, self::APPLICABLE_TYPE_GROUP);
88
+    }
89
+
90
+    protected function modifyMountsOnDelete(string $applicableId, int $applicableType): void {
91
+        $builder = $this->connection->getQueryBuilder();
92
+        $query = $builder->select(['a.mount_id', $builder->func()->count('a.mount_id', 'count')])
93
+            ->from('external_applicable', 'a')
94
+            ->leftJoin('a', 'external_applicable', 'b', $builder->expr()->eq('a.mount_id', 'b.mount_id'))
95
+            ->where($builder->expr()->andX(
96
+                $builder->expr()->eq('b.type', $builder->createNamedParameter($applicableType, IQueryBuilder::PARAM_INT)),
97
+                $builder->expr()->eq('b.value', $builder->createNamedParameter($applicableId))
98
+            )
99
+            )
100
+            ->groupBy(['a.mount_id']);
101
+        $stmt = $query->executeQuery();
102
+        $result = $stmt->fetchAll();
103
+        $stmt->closeCursor();
104
+
105
+        foreach ($result as $row) {
106
+            if ((int)$row['count'] > 1) {
107
+                $this->removeApplicable($row['mount_id'], $applicableType, $applicableId);
108
+            } else {
109
+                $this->removeMount($row['mount_id']);
110
+            }
111
+        }
112
+    }
113
+
114
+    /**
115
+     * Get admin defined mounts
116
+     *
117
+     * @return array
118
+     */
119
+    public function getAdminMounts() {
120
+        $builder = $this->connection->getQueryBuilder();
121
+        $query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type'])
122
+            ->from('external_mounts')
123
+            ->where($builder->expr()->eq('type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT)));
124
+        return $this->getMountsFromQuery($query);
125
+    }
126
+
127
+    protected function getForQuery(IQueryBuilder $builder, $type, $value) {
128
+        $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
129
+            ->from('external_mounts', 'm')
130
+            ->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id'))
131
+            ->where($builder->expr()->eq('a.type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)));
132
+
133
+        if (is_null($value)) {
134
+            $query = $query->andWhere($builder->expr()->isNull('a.value'));
135
+        } else {
136
+            $query = $query->andWhere($builder->expr()->eq('a.value', $builder->createNamedParameter($value)));
137
+        }
138
+
139
+        return $query;
140
+    }
141
+
142
+    /**
143
+     * Get mounts by applicable
144
+     *
145
+     * @param int $type any of the self::APPLICABLE_TYPE_ constants
146
+     * @param string|null $value user_id, group_id or null for global mounts
147
+     * @return array
148
+     */
149
+    public function getMountsFor($type, $value) {
150
+        $builder = $this->connection->getQueryBuilder();
151
+        $query = $this->getForQuery($builder, $type, $value);
152
+
153
+        return $this->getMountsFromQuery($query);
154
+    }
155
+
156
+    /**
157
+     * Get admin defined mounts by applicable
158
+     *
159
+     * @param int $type any of the self::APPLICABLE_TYPE_ constants
160
+     * @param string|null $value user_id, group_id or null for global mounts
161
+     * @return array
162
+     */
163
+    public function getAdminMountsFor($type, $value) {
164
+        $builder = $this->connection->getQueryBuilder();
165
+        $query = $this->getForQuery($builder, $type, $value);
166
+        $query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT)));
167
+
168
+        return $this->getMountsFromQuery($query);
169
+    }
170
+
171
+    /**
172
+     * Get admin defined mounts for multiple applicable
173
+     *
174
+     * @param int $type any of the self::APPLICABLE_TYPE_ constants
175
+     * @param string[] $values user_ids or group_ids
176
+     * @return array
177
+     */
178
+    public function getAdminMountsForMultiple($type, array $values) {
179
+        $builder = $this->connection->getQueryBuilder();
180
+        $params = array_map(function ($value) use ($builder) {
181
+            return $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR);
182
+        }, $values);
183
+
184
+        $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
185
+            ->from('external_mounts', 'm')
186
+            ->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id'))
187
+            ->where($builder->expr()->eq('a.type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)))
188
+            ->andWhere($builder->expr()->in('a.value', $params));
189
+        $query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT)));
190
+
191
+        return $this->getMountsFromQuery($query);
192
+    }
193
+
194
+    /**
195
+     * Get user defined mounts by applicable
196
+     *
197
+     * @param int $type any of the self::APPLICABLE_TYPE_ constants
198
+     * @param string|null $value user_id, group_id or null for global mounts
199
+     * @return array
200
+     */
201
+    public function getUserMountsFor($type, $value) {
202
+        $builder = $this->connection->getQueryBuilder();
203
+        $query = $this->getForQuery($builder, $type, $value);
204
+        $query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_PERSONAL, IQueryBuilder::PARAM_INT)));
205
+
206
+        return $this->getMountsFromQuery($query);
207
+    }
208
+
209
+    /**
210
+     * Add a mount to the database
211
+     *
212
+     * @param string $mountPoint
213
+     * @param string $storageBackend
214
+     * @param string $authBackend
215
+     * @param int $priority
216
+     * @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAL
217
+     * @return int the id of the new mount
218
+     */
219
+    public function addMount($mountPoint, $storageBackend, $authBackend, $priority, $type) {
220
+        if (!$priority) {
221
+            $priority = 100;
222
+        }
223
+        $builder = $this->connection->getQueryBuilder();
224
+        $query = $builder->insert('external_mounts')
225
+            ->values([
226
+                'mount_point' => $builder->createNamedParameter($mountPoint, IQueryBuilder::PARAM_STR),
227
+                'storage_backend' => $builder->createNamedParameter($storageBackend, IQueryBuilder::PARAM_STR),
228
+                'auth_backend' => $builder->createNamedParameter($authBackend, IQueryBuilder::PARAM_STR),
229
+                'priority' => $builder->createNamedParameter($priority, IQueryBuilder::PARAM_INT),
230
+                'type' => $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)
231
+            ]);
232
+        $query->executeStatement();
233
+        return $query->getLastInsertId();
234
+    }
235
+
236
+    /**
237
+     * Remove a mount from the database
238
+     *
239
+     * @param int $mountId
240
+     */
241
+    public function removeMount($mountId) {
242
+        $builder = $this->connection->getQueryBuilder();
243
+        $query = $builder->delete('external_mounts')
244
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
245
+        $query->executeStatement();
246
+
247
+        $builder = $this->connection->getQueryBuilder();
248
+        $query = $builder->delete('external_applicable')
249
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
250
+        $query->executeStatement();
251
+
252
+        $builder = $this->connection->getQueryBuilder();
253
+        $query = $builder->delete('external_config')
254
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
255
+        $query->executeStatement();
256
+
257
+        $builder = $this->connection->getQueryBuilder();
258
+        $query = $builder->delete('external_options')
259
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
260
+        $query->executeStatement();
261
+    }
262
+
263
+    /**
264
+     * @param int $mountId
265
+     * @param string $newMountPoint
266
+     */
267
+    public function setMountPoint($mountId, $newMountPoint) {
268
+        $builder = $this->connection->getQueryBuilder();
269
+
270
+        $query = $builder->update('external_mounts')
271
+            ->set('mount_point', $builder->createNamedParameter($newMountPoint))
272
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
273
+
274
+        $query->executeStatement();
275
+    }
276
+
277
+    /**
278
+     * @param int $mountId
279
+     * @param string $newAuthBackend
280
+     */
281
+    public function setAuthBackend($mountId, $newAuthBackend) {
282
+        $builder = $this->connection->getQueryBuilder();
283
+
284
+        $query = $builder->update('external_mounts')
285
+            ->set('auth_backend', $builder->createNamedParameter($newAuthBackend))
286
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
287
+
288
+        $query->executeStatement();
289
+    }
290
+
291
+    /**
292
+     * @param int $mountId
293
+     * @param string $key
294
+     * @param string $value
295
+     */
296
+    public function setConfig($mountId, $key, $value) {
297
+        if ($key === 'password') {
298
+            $value = $this->encryptValue($value);
299
+        }
300
+
301
+        try {
302
+            $builder = $this->connection->getQueryBuilder();
303
+            $builder->insert('external_config')
304
+                ->setValue('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))
305
+                ->setValue('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR))
306
+                ->setValue('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR))
307
+                ->executeStatement();
308
+        } catch (Exception $e) {
309
+            if ($e->getReason() !== Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
310
+                throw $e;
311
+            }
312
+            $builder = $this->connection->getQueryBuilder();
313
+            $query = $builder->update('external_config')
314
+                ->set('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR))
315
+                ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
316
+                ->andWhere($builder->expr()->eq('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR)));
317
+            $query->executeStatement();
318
+        }
319
+    }
320
+
321
+    /**
322
+     * @param int $mountId
323
+     * @param string $key
324
+     * @param string $value
325
+     */
326
+    public function setOption($mountId, $key, $value) {
327
+        try {
328
+            $builder = $this->connection->getQueryBuilder();
329
+            $builder->insert('external_options')
330
+                ->setValue('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))
331
+                ->setValue('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR))
332
+                ->setValue('value', $builder->createNamedParameter(json_encode($value), IQueryBuilder::PARAM_STR))
333
+                ->executeStatement();
334
+        } catch (Exception $e) {
335
+            if ($e->getReason() !== Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
336
+                throw $e;
337
+            }
338
+            $builder = $this->connection->getQueryBuilder();
339
+            $query = $builder->update('external_options')
340
+                ->set('value', $builder->createNamedParameter(json_encode($value), IQueryBuilder::PARAM_STR))
341
+                ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
342
+                ->andWhere($builder->expr()->eq('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR)));
343
+            $query->executeStatement();
344
+        }
345
+    }
346
+
347
+    public function addApplicable($mountId, $type, $value) {
348
+        try {
349
+            $builder = $this->connection->getQueryBuilder();
350
+            $builder->insert('external_applicable')
351
+                ->setValue('mount_id', $builder->createNamedParameter($mountId))
352
+                ->setValue('type', $builder->createNamedParameter($type))
353
+                ->setValue('value', $builder->createNamedParameter($value))
354
+                ->executeStatement();
355
+        } catch (Exception $e) {
356
+            // applicable exists already
357
+            if ($e->getReason() !== Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
358
+                throw $e;
359
+            }
360
+        }
361
+    }
362
+
363
+    public function removeApplicable($mountId, $type, $value) {
364
+        $builder = $this->connection->getQueryBuilder();
365
+        $query = $builder->delete('external_applicable')
366
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
367
+            ->andWhere($builder->expr()->eq('type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)));
368
+
369
+        if (is_null($value)) {
370
+            $query = $query->andWhere($builder->expr()->isNull('value'));
371
+        } else {
372
+            $query = $query->andWhere($builder->expr()->eq('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR)));
373
+        }
374
+
375
+        $query->executeStatement();
376
+    }
377
+
378
+    private function getMountsFromQuery(IQueryBuilder $query) {
379
+        $result = $query->executeQuery();
380
+        $mounts = $result->fetchAll();
381
+        $uniqueMounts = [];
382
+        foreach ($mounts as $mount) {
383
+            $id = $mount['mount_id'];
384
+            if (!isset($uniqueMounts[$id])) {
385
+                $uniqueMounts[$id] = $mount;
386
+            }
387
+        }
388
+        $uniqueMounts = array_values($uniqueMounts);
389
+
390
+        $mountIds = array_map(function ($mount) {
391
+            return $mount['mount_id'];
392
+        }, $uniqueMounts);
393
+        $mountIds = array_values(array_unique($mountIds));
394
+
395
+        $applicable = $this->getApplicableForMounts($mountIds);
396
+        $config = $this->getConfigForMounts($mountIds);
397
+        $options = $this->getOptionsForMounts($mountIds);
398
+
399
+        return array_map(function ($mount, $applicable, $config, $options) {
400
+            $mount['type'] = (int)$mount['type'];
401
+            $mount['priority'] = (int)$mount['priority'];
402
+            $mount['applicable'] = $applicable;
403
+            $mount['config'] = $config;
404
+            $mount['options'] = $options;
405
+            return $mount;
406
+        }, $uniqueMounts, $applicable, $config, $options);
407
+    }
408
+
409
+    /**
410
+     * Get mount options from a table grouped by mount id
411
+     *
412
+     * @param string $table
413
+     * @param string[] $fields
414
+     * @param int[] $mountIds
415
+     * @return array [$mountId => [['field1' => $value1, ...], ...], ...]
416
+     */
417
+    private function selectForMounts($table, array $fields, array $mountIds) {
418
+        if (count($mountIds) === 0) {
419
+            return [];
420
+        }
421
+        $builder = $this->connection->getQueryBuilder();
422
+        $fields[] = 'mount_id';
423
+        $placeHolders = array_map(function ($id) use ($builder) {
424
+            return $builder->createPositionalParameter($id, IQueryBuilder::PARAM_INT);
425
+        }, $mountIds);
426
+        $query = $builder->select($fields)
427
+            ->from($table)
428
+            ->where($builder->expr()->in('mount_id', $placeHolders));
429
+
430
+        $result = $query->executeQuery();
431
+        $rows = $result->fetchAll();
432
+        $result->closeCursor();
433
+
434
+        $result = [];
435
+        foreach ($mountIds as $mountId) {
436
+            $result[$mountId] = [];
437
+        }
438
+        foreach ($rows as $row) {
439
+            if (isset($row['type'])) {
440
+                $row['type'] = (int)$row['type'];
441
+            }
442
+            $result[$row['mount_id']][] = $row;
443
+        }
444
+        return $result;
445
+    }
446
+
447
+    /**
448
+     * @param int[] $mountIds
449
+     * @return array [$id => [['type' => $type, 'value' => $value], ...], ...]
450
+     */
451
+    public function getApplicableForMounts($mountIds) {
452
+        return $this->selectForMounts('external_applicable', ['type', 'value'], $mountIds);
453
+    }
454
+
455
+    /**
456
+     * @param int[] $mountIds
457
+     * @return array [$id => ['key1' => $value1, ...], ...]
458
+     */
459
+    public function getConfigForMounts($mountIds) {
460
+        $mountConfigs = $this->selectForMounts('external_config', ['key', 'value'], $mountIds);
461
+        return array_map([$this, 'createKeyValueMap'], $mountConfigs);
462
+    }
463
+
464
+    /**
465
+     * @param int[] $mountIds
466
+     * @return array [$id => ['key1' => $value1, ...], ...]
467
+     */
468
+    public function getOptionsForMounts($mountIds) {
469
+        $mountOptions = $this->selectForMounts('external_options', ['key', 'value'], $mountIds);
470
+        $optionsMap = array_map([$this, 'createKeyValueMap'], $mountOptions);
471
+        return array_map(function (array $options) {
472
+            return array_map(function ($option) {
473
+                return json_decode($option);
474
+            }, $options);
475
+        }, $optionsMap);
476
+    }
477
+
478
+    /**
479
+     * @param array $keyValuePairs [['key'=>$key, 'value=>$value], ...]
480
+     * @return array ['key1' => $value1, ...]
481
+     */
482
+    private function createKeyValueMap(array $keyValuePairs) {
483
+        $decryptedPairts = array_map(function ($pair) {
484
+            if ($pair['key'] === 'password') {
485
+                $pair['value'] = $this->decryptValue($pair['value']);
486
+            }
487
+            return $pair;
488
+        }, $keyValuePairs);
489
+        $keys = array_map(function ($pair) {
490
+            return $pair['key'];
491
+        }, $decryptedPairts);
492
+        $values = array_map(function ($pair) {
493
+            return $pair['value'];
494
+        }, $decryptedPairts);
495
+
496
+        return array_combine($keys, $values);
497
+    }
498
+
499
+    private function encryptValue($value) {
500
+        return $this->crypto->encrypt($value);
501
+    }
502
+
503
+    private function decryptValue($value) {
504
+        try {
505
+            return $this->crypto->decrypt($value);
506
+        } catch (\Exception $e) {
507
+            return $value;
508
+        }
509
+    }
510 510
 }
Please login to merge, or discard this patch.
apps/workflowengine/lib/Settings/Personal.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -28,11 +28,11 @@
 block discarded – undo
28 28
 use OCP\WorkflowEngine\IManager;
29 29
 
30 30
 class Personal extends ASettings {
31
-	public function getScope(): int {
32
-		return IManager::SCOPE_USER;
33
-	}
31
+    public function getScope(): int {
32
+        return IManager::SCOPE_USER;
33
+    }
34 34
 
35
-	public function getSection(): ?string {
36
-		return $this->manager->isUserScopeEnabled() ? 'workflow' : null;
37
-	}
35
+    public function getSection(): ?string {
36
+        return $this->manager->isUserScopeEnabled() ? 'workflow' : null;
37
+    }
38 38
 }
Please login to merge, or discard this patch.
lib/public/DB/QueryBuilder/ICompositeExpression.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -29,39 +29,39 @@
 block discarded – undo
29 29
  * @since 8.2.0
30 30
  */
31 31
 interface ICompositeExpression {
32
-	/**
33
-	 * Adds multiple parts to composite expression.
34
-	 *
35
-	 * @param array $parts
36
-	 *
37
-	 * @return ICompositeExpression
38
-	 * @since 8.2.0
39
-	 */
40
-	public function addMultiple(array $parts = []): ICompositeExpression;
32
+    /**
33
+     * Adds multiple parts to composite expression.
34
+     *
35
+     * @param array $parts
36
+     *
37
+     * @return ICompositeExpression
38
+     * @since 8.2.0
39
+     */
40
+    public function addMultiple(array $parts = []): ICompositeExpression;
41 41
 
42
-	/**
43
-	 * Adds an expression to composite expression.
44
-	 *
45
-	 * @param mixed $part
46
-	 *
47
-	 * @return ICompositeExpression
48
-	 * @since 8.2.0
49
-	 */
50
-	public function add($part): ICompositeExpression;
42
+    /**
43
+     * Adds an expression to composite expression.
44
+     *
45
+     * @param mixed $part
46
+     *
47
+     * @return ICompositeExpression
48
+     * @since 8.2.0
49
+     */
50
+    public function add($part): ICompositeExpression;
51 51
 
52
-	/**
53
-	 * Retrieves the amount of expressions on composite expression.
54
-	 *
55
-	 * @return integer
56
-	 * @since 8.2.0
57
-	 */
58
-	public function count(): int;
52
+    /**
53
+     * Retrieves the amount of expressions on composite expression.
54
+     *
55
+     * @return integer
56
+     * @since 8.2.0
57
+     */
58
+    public function count(): int;
59 59
 
60
-	/**
61
-	 * Returns the type of this composite expression (AND/OR).
62
-	 *
63
-	 * @return string
64
-	 * @since 8.2.0
65
-	 */
66
-	public function getType(): string;
60
+    /**
61
+     * Returns the type of this composite expression (AND/OR).
62
+     *
63
+     * @return string
64
+     * @since 8.2.0
65
+     */
66
+    public function getType(): string;
67 67
 }
Please login to merge, or discard this patch.
core/Command/Group/Info.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@
 block discarded – undo
67 67
 		$gid = $input->getArgument('groupid');
68 68
 		$group = $this->groupManager->get($gid);
69 69
 		if (!$group instanceof IGroup) {
70
-			$output->writeln('<error>Group "' . $gid . '" does not exist.</error>');
70
+			$output->writeln('<error>Group "'.$gid.'" does not exist.</error>');
71 71
 			return 1;
72 72
 		} else {
73 73
 			$groupOutput = [
Please login to merge, or discard this patch.
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -35,56 +35,56 @@
 block discarded – undo
35 35
 use Symfony\Component\Console\Output\OutputInterface;
36 36
 
37 37
 class Info extends Base {
38
-	public function __construct(
39
-		protected IGroupManager $groupManager,
40
-	) {
41
-		parent::__construct();
42
-	}
38
+    public function __construct(
39
+        protected IGroupManager $groupManager,
40
+    ) {
41
+        parent::__construct();
42
+    }
43 43
 
44
-	protected function configure() {
45
-		$this
46
-			->setName('group:info')
47
-			->setDescription('Show information about a group')
48
-			->addArgument(
49
-				'groupid',
50
-				InputArgument::REQUIRED,
51
-				'Group id'
52
-			)->addOption(
53
-				'output',
54
-				null,
55
-				InputOption::VALUE_OPTIONAL,
56
-				'Output format (plain, json or json_pretty, default is plain)',
57
-				$this->defaultOutputFormat
58
-			);
59
-	}
44
+    protected function configure() {
45
+        $this
46
+            ->setName('group:info')
47
+            ->setDescription('Show information about a group')
48
+            ->addArgument(
49
+                'groupid',
50
+                InputArgument::REQUIRED,
51
+                'Group id'
52
+            )->addOption(
53
+                'output',
54
+                null,
55
+                InputOption::VALUE_OPTIONAL,
56
+                'Output format (plain, json or json_pretty, default is plain)',
57
+                $this->defaultOutputFormat
58
+            );
59
+    }
60 60
 
61
-	protected function execute(InputInterface $input, OutputInterface $output): int {
62
-		$gid = $input->getArgument('groupid');
63
-		$group = $this->groupManager->get($gid);
64
-		if (!$group instanceof IGroup) {
65
-			$output->writeln('<error>Group "' . $gid . '" does not exist.</error>');
66
-			return 1;
67
-		} else {
68
-			$groupOutput = [
69
-				'groupID' => $gid,
70
-				'displayName' => $group->getDisplayName(),
71
-				'backends' => $group->getBackendNames(),
72
-			];
61
+    protected function execute(InputInterface $input, OutputInterface $output): int {
62
+        $gid = $input->getArgument('groupid');
63
+        $group = $this->groupManager->get($gid);
64
+        if (!$group instanceof IGroup) {
65
+            $output->writeln('<error>Group "' . $gid . '" does not exist.</error>');
66
+            return 1;
67
+        } else {
68
+            $groupOutput = [
69
+                'groupID' => $gid,
70
+                'displayName' => $group->getDisplayName(),
71
+                'backends' => $group->getBackendNames(),
72
+            ];
73 73
 
74
-			$this->writeArrayInOutputFormat($input, $output, $groupOutput);
75
-			return 0;
76
-		}
77
-	}
74
+            $this->writeArrayInOutputFormat($input, $output, $groupOutput);
75
+            return 0;
76
+        }
77
+    }
78 78
 
79
-	/**
80
-	 * @param string $argumentName
81
-	 * @param CompletionContext $context
82
-	 * @return string[]
83
-	 */
84
-	public function completeArgumentValues($argumentName, CompletionContext $context) {
85
-		if ($argumentName === 'groupid') {
86
-			return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord()));
87
-		}
88
-		return [];
89
-	}
79
+    /**
80
+     * @param string $argumentName
81
+     * @param CompletionContext $context
82
+     * @return string[]
83
+     */
84
+    public function completeArgumentValues($argumentName, CompletionContext $context) {
85
+        if ($argumentName === 'groupid') {
86
+            return array_map(static fn (IGroup $group) => $group->getGID(), $this->groupManager->search($context->getCurrentWord()));
87
+        }
88
+        return [];
89
+    }
90 90
 }
Please login to merge, or discard this patch.
lib/private/Contacts/ContactsMenu/Entry.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 	 * sort the actions by priority and name
118 118
 	 */
119 119
 	private function sortActions(): void {
120
-		usort($this->actions, function (IAction $action1, IAction $action2) {
120
+		usort($this->actions, function(IAction $action1, IAction $action2) {
121 121
 			$prio1 = $action1->getPriority();
122 122
 			$prio2 = $action2->getPriority();
123 123
 
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
 	 */
155 155
 	public function jsonSerialize(): array {
156 156
 		$topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null;
157
-		$otherActions = array_map(function (IAction $action) {
157
+		$otherActions = array_map(function(IAction $action) {
158 158
 			return $action->jsonSerialize();
159 159
 		}, array_slice($this->actions, 1));
160 160
 
Please login to merge, or discard this patch.
Indentation   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -14,170 +14,170 @@
 block discarded – undo
14 14
 use function array_merge;
15 15
 
16 16
 class Entry implements IEntry {
17
-	public const PROPERTY_STATUS_MESSAGE_TIMESTAMP = 'statusMessageTimestamp';
18
-
19
-	/** @var string|int|null */
20
-	private $id = null;
21
-
22
-	private string $fullName = '';
23
-
24
-	/** @var string[] */
25
-	private array $emailAddresses = [];
26
-
27
-	private ?string $avatar = null;
28
-
29
-	private ?string $profileTitle = null;
30
-
31
-	private ?string $profileUrl = null;
32
-
33
-	/** @var IAction[] */
34
-	private array $actions = [];
35
-
36
-	private array $properties = [];
37
-
38
-	private ?string $status = null;
39
-	private ?string $statusMessage = null;
40
-	private ?int $statusMessageTimestamp = null;
41
-	private ?string $statusIcon = null;
42
-
43
-	public function setId(string $id): void {
44
-		$this->id = $id;
45
-	}
46
-
47
-	public function setFullName(string $displayName): void {
48
-		$this->fullName = $displayName;
49
-	}
50
-
51
-	public function getFullName(): string {
52
-		return $this->fullName;
53
-	}
54
-
55
-	public function addEMailAddress(string $address): void {
56
-		$this->emailAddresses[] = $address;
57
-	}
58
-
59
-	/**
60
-	 * @return string[]
61
-	 */
62
-	public function getEMailAddresses(): array {
63
-		return $this->emailAddresses;
64
-	}
65
-
66
-	public function setAvatar(string $avatar): void {
67
-		$this->avatar = $avatar;
68
-	}
69
-
70
-	public function getAvatar(): ?string {
71
-		return $this->avatar;
72
-	}
73
-
74
-	public function setProfileTitle(string $profileTitle): void {
75
-		$this->profileTitle = $profileTitle;
76
-	}
77
-
78
-	public function getProfileTitle(): ?string {
79
-		return $this->profileTitle;
80
-	}
81
-
82
-	public function setProfileUrl(string $profileUrl): void {
83
-		$this->profileUrl = $profileUrl;
84
-	}
85
-
86
-	public function getProfileUrl(): ?string {
87
-		return $this->profileUrl;
88
-	}
89
-
90
-	public function addAction(IAction $action): void {
91
-		$this->actions[] = $action;
92
-		$this->sortActions();
93
-	}
94
-
95
-	public function setStatus(string $status,
96
-		?string $statusMessage = null,
97
-		?int $statusMessageTimestamp = null,
98
-		?string $icon = null): void {
99
-		$this->status = $status;
100
-		$this->statusMessage = $statusMessage;
101
-		$this->statusMessageTimestamp = $statusMessageTimestamp;
102
-		$this->statusIcon = $icon;
103
-	}
104
-
105
-	/**
106
-	 * @return IAction[]
107
-	 */
108
-	public function getActions(): array {
109
-		return $this->actions;
110
-	}
111
-
112
-	/**
113
-	 * sort the actions by priority and name
114
-	 */
115
-	private function sortActions(): void {
116
-		usort($this->actions, function (IAction $action1, IAction $action2) {
117
-			$prio1 = $action1->getPriority();
118
-			$prio2 = $action2->getPriority();
119
-
120
-			if ($prio1 === $prio2) {
121
-				// Ascending order for same priority
122
-				return strcasecmp($action1->getName(), $action2->getName());
123
-			}
124
-
125
-			// Descending order when priority differs
126
-			return $prio2 - $prio1;
127
-		});
128
-	}
129
-
130
-	public function setProperty(string $propertyName, mixed $value) {
131
-		$this->properties[$propertyName] = $value;
132
-	}
133
-
134
-	/**
135
-	 * @param array $properties key-value array containing additional properties
136
-	 */
137
-	public function setProperties(array $properties): void {
138
-		$this->properties = array_merge($this->properties, $properties);
139
-	}
140
-
141
-	public function getProperty(string $key): mixed {
142
-		if (!isset($this->properties[$key])) {
143
-			return null;
144
-		}
145
-		return $this->properties[$key];
146
-	}
147
-
148
-	/**
149
-	 * @return array{id: int|string|null, fullName: string, avatar: string|null, topAction: mixed, actions: array, lastMessage: '', emailAddresses: string[], profileTitle: string|null, profileUrl: string|null, status: string|null, statusMessage: null|string, statusMessageTimestamp: null|int, statusIcon: null|string, isUser: bool, uid: mixed}
150
-	 */
151
-	public function jsonSerialize(): array {
152
-		$topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null;
153
-		$otherActions = array_map(function (IAction $action) {
154
-			return $action->jsonSerialize();
155
-		}, array_slice($this->actions, 1));
156
-
157
-		return [
158
-			'id' => $this->id,
159
-			'fullName' => $this->fullName,
160
-			'avatar' => $this->getAvatar(),
161
-			'topAction' => $topAction,
162
-			'actions' => $otherActions,
163
-			'lastMessage' => '',
164
-			'emailAddresses' => $this->getEMailAddresses(),
165
-			'profileTitle' => $this->profileTitle,
166
-			'profileUrl' => $this->profileUrl,
167
-			'status' => $this->status,
168
-			'statusMessage' => $this->statusMessage,
169
-			'statusMessageTimestamp' => $this->statusMessageTimestamp,
170
-			'statusIcon' => $this->statusIcon,
171
-			'isUser' => $this->getProperty('isUser') === true,
172
-			'uid' => $this->getProperty('UID'),
173
-		];
174
-	}
175
-
176
-	public function getStatusMessage(): ?string {
177
-		return $this->statusMessage;
178
-	}
179
-
180
-	public function getStatusMessageTimestamp(): ?int {
181
-		return $this->statusMessageTimestamp;
182
-	}
17
+    public const PROPERTY_STATUS_MESSAGE_TIMESTAMP = 'statusMessageTimestamp';
18
+
19
+    /** @var string|int|null */
20
+    private $id = null;
21
+
22
+    private string $fullName = '';
23
+
24
+    /** @var string[] */
25
+    private array $emailAddresses = [];
26
+
27
+    private ?string $avatar = null;
28
+
29
+    private ?string $profileTitle = null;
30
+
31
+    private ?string $profileUrl = null;
32
+
33
+    /** @var IAction[] */
34
+    private array $actions = [];
35
+
36
+    private array $properties = [];
37
+
38
+    private ?string $status = null;
39
+    private ?string $statusMessage = null;
40
+    private ?int $statusMessageTimestamp = null;
41
+    private ?string $statusIcon = null;
42
+
43
+    public function setId(string $id): void {
44
+        $this->id = $id;
45
+    }
46
+
47
+    public function setFullName(string $displayName): void {
48
+        $this->fullName = $displayName;
49
+    }
50
+
51
+    public function getFullName(): string {
52
+        return $this->fullName;
53
+    }
54
+
55
+    public function addEMailAddress(string $address): void {
56
+        $this->emailAddresses[] = $address;
57
+    }
58
+
59
+    /**
60
+     * @return string[]
61
+     */
62
+    public function getEMailAddresses(): array {
63
+        return $this->emailAddresses;
64
+    }
65
+
66
+    public function setAvatar(string $avatar): void {
67
+        $this->avatar = $avatar;
68
+    }
69
+
70
+    public function getAvatar(): ?string {
71
+        return $this->avatar;
72
+    }
73
+
74
+    public function setProfileTitle(string $profileTitle): void {
75
+        $this->profileTitle = $profileTitle;
76
+    }
77
+
78
+    public function getProfileTitle(): ?string {
79
+        return $this->profileTitle;
80
+    }
81
+
82
+    public function setProfileUrl(string $profileUrl): void {
83
+        $this->profileUrl = $profileUrl;
84
+    }
85
+
86
+    public function getProfileUrl(): ?string {
87
+        return $this->profileUrl;
88
+    }
89
+
90
+    public function addAction(IAction $action): void {
91
+        $this->actions[] = $action;
92
+        $this->sortActions();
93
+    }
94
+
95
+    public function setStatus(string $status,
96
+        ?string $statusMessage = null,
97
+        ?int $statusMessageTimestamp = null,
98
+        ?string $icon = null): void {
99
+        $this->status = $status;
100
+        $this->statusMessage = $statusMessage;
101
+        $this->statusMessageTimestamp = $statusMessageTimestamp;
102
+        $this->statusIcon = $icon;
103
+    }
104
+
105
+    /**
106
+     * @return IAction[]
107
+     */
108
+    public function getActions(): array {
109
+        return $this->actions;
110
+    }
111
+
112
+    /**
113
+     * sort the actions by priority and name
114
+     */
115
+    private function sortActions(): void {
116
+        usort($this->actions, function (IAction $action1, IAction $action2) {
117
+            $prio1 = $action1->getPriority();
118
+            $prio2 = $action2->getPriority();
119
+
120
+            if ($prio1 === $prio2) {
121
+                // Ascending order for same priority
122
+                return strcasecmp($action1->getName(), $action2->getName());
123
+            }
124
+
125
+            // Descending order when priority differs
126
+            return $prio2 - $prio1;
127
+        });
128
+    }
129
+
130
+    public function setProperty(string $propertyName, mixed $value) {
131
+        $this->properties[$propertyName] = $value;
132
+    }
133
+
134
+    /**
135
+     * @param array $properties key-value array containing additional properties
136
+     */
137
+    public function setProperties(array $properties): void {
138
+        $this->properties = array_merge($this->properties, $properties);
139
+    }
140
+
141
+    public function getProperty(string $key): mixed {
142
+        if (!isset($this->properties[$key])) {
143
+            return null;
144
+        }
145
+        return $this->properties[$key];
146
+    }
147
+
148
+    /**
149
+     * @return array{id: int|string|null, fullName: string, avatar: string|null, topAction: mixed, actions: array, lastMessage: '', emailAddresses: string[], profileTitle: string|null, profileUrl: string|null, status: string|null, statusMessage: null|string, statusMessageTimestamp: null|int, statusIcon: null|string, isUser: bool, uid: mixed}
150
+     */
151
+    public function jsonSerialize(): array {
152
+        $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null;
153
+        $otherActions = array_map(function (IAction $action) {
154
+            return $action->jsonSerialize();
155
+        }, array_slice($this->actions, 1));
156
+
157
+        return [
158
+            'id' => $this->id,
159
+            'fullName' => $this->fullName,
160
+            'avatar' => $this->getAvatar(),
161
+            'topAction' => $topAction,
162
+            'actions' => $otherActions,
163
+            'lastMessage' => '',
164
+            'emailAddresses' => $this->getEMailAddresses(),
165
+            'profileTitle' => $this->profileTitle,
166
+            'profileUrl' => $this->profileUrl,
167
+            'status' => $this->status,
168
+            'statusMessage' => $this->statusMessage,
169
+            'statusMessageTimestamp' => $this->statusMessageTimestamp,
170
+            'statusIcon' => $this->statusIcon,
171
+            'isUser' => $this->getProperty('isUser') === true,
172
+            'uid' => $this->getProperty('UID'),
173
+        ];
174
+    }
175
+
176
+    public function getStatusMessage(): ?string {
177
+        return $this->statusMessage;
178
+    }
179
+
180
+    public function getStatusMessageTimestamp(): ?int {
181
+        return $this->statusMessageTimestamp;
182
+    }
183 183
 }
Please login to merge, or discard this patch.
apps/admin_audit/lib/Actions/Trashbin.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -29,15 +29,15 @@
 block discarded – undo
29 29
 namespace OCA\AdminAudit\Actions;
30 30
 
31 31
 class Trashbin extends Action {
32
-	public function delete(array $params): void {
33
-		$this->log('File "%s" deleted from trash bin.',
34
-			['path' => $params['path']], ['path']
35
-		);
36
-	}
32
+    public function delete(array $params): void {
33
+        $this->log('File "%s" deleted from trash bin.',
34
+            ['path' => $params['path']], ['path']
35
+        );
36
+    }
37 37
 
38
-	public function restore(array $params): void {
39
-		$this->log('File "%s" restored from trash bin.',
40
-			['path' => $params['filePath']], ['path']
41
-		);
42
-	}
38
+    public function restore(array $params): void {
39
+        $this->log('File "%s" restored from trash bin.',
40
+            ['path' => $params['filePath']], ['path']
41
+        );
42
+    }
43 43
 }
Please login to merge, or discard this patch.
lib/public/Share/Exceptions/AlreadySharedException.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -29,22 +29,22 @@
 block discarded – undo
29 29
  * @since 22.0.0
30 30
  */
31 31
 class AlreadySharedException extends GenericShareException {
32
-	/** @var IShare */
33
-	private $existingShare;
32
+    /** @var IShare */
33
+    private $existingShare;
34 34
 
35
-	/**
36
-	 * @since 22.0.0
37
-	 */
38
-	public function __construct(string $message, IShare $existingShare) {
39
-		parent::__construct($message);
35
+    /**
36
+     * @since 22.0.0
37
+     */
38
+    public function __construct(string $message, IShare $existingShare) {
39
+        parent::__construct($message);
40 40
 
41
-		$this->existingShare = $existingShare;
42
-	}
41
+        $this->existingShare = $existingShare;
42
+    }
43 43
 
44
-	/**
45
-	 * @since 22.0.0
46
-	 */
47
-	public function getExistingShare(): IShare {
48
-		return $this->existingShare;
49
-	}
44
+    /**
45
+     * @since 22.0.0
46
+     */
47
+    public function getExistingShare(): IShare {
48
+        return $this->existingShare;
49
+    }
50 50
 }
Please login to merge, or discard this patch.