Passed
Push — master ( ff6610...e81fdf )
by Robin
14:53 queued 15s
created
lib/public/Http/Client/IClientService.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -31,9 +31,9 @@
 block discarded – undo
31 31
  * @since 8.1.0
32 32
  */
33 33
 interface IClientService {
34
-	/**
35
-	 * @return IClient
36
-	 * @since 8.1.0
37
-	 */
38
-	public function newClient(): IClient;
34
+    /**
35
+     * @return IClient
36
+     * @since 8.1.0
37
+     */
38
+    public function newClient(): IClient;
39 39
 }
Please login to merge, or discard this patch.
lib/public/Http/Client/IResponse.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -32,28 +32,28 @@
 block discarded – undo
32 32
  * @since 8.1.0
33 33
  */
34 34
 interface IResponse {
35
-	/**
36
-	 * @return string|resource
37
-	 * @since 8.1.0
38
-	 */
39
-	public function getBody();
35
+    /**
36
+     * @return string|resource
37
+     * @since 8.1.0
38
+     */
39
+    public function getBody();
40 40
 
41
-	/**
42
-	 * @return int
43
-	 * @since 8.1.0
44
-	 */
45
-	public function getStatusCode(): int;
41
+    /**
42
+     * @return int
43
+     * @since 8.1.0
44
+     */
45
+    public function getStatusCode(): int;
46 46
 
47
-	/**
48
-	 * @param string $key
49
-	 * @return string
50
-	 * @since 8.1.0
51
-	 */
52
-	public function getHeader(string $key): string;
47
+    /**
48
+     * @param string $key
49
+     * @return string
50
+     * @since 8.1.0
51
+     */
52
+    public function getHeader(string $key): string;
53 53
 
54
-	/**
55
-	 * @return array
56
-	 * @since 8.1.0
57
-	 */
58
-	public function getHeaders(): array;
54
+    /**
55
+     * @return array
56
+     * @since 8.1.0
57
+     */
58
+    public function getHeaders(): array;
59 59
 }
Please login to merge, or discard this patch.
lib/public/Security/IHasher.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -45,23 +45,23 @@
 block discarded – undo
45 45
  * @since 8.0.0
46 46
  */
47 47
 interface IHasher {
48
-	/**
49
-	 * Hashes a message using PHP's `password_hash` functionality.
50
-	 * Please note that the size of the returned string is not guaranteed
51
-	 * and can be up to 255 characters.
52
-	 *
53
-	 * @param string $message Message to generate hash from
54
-	 * @return string Hash of the message with appended version parameter
55
-	 * @since 8.0.0
56
-	 */
57
-	public function hash(string $message): string;
48
+    /**
49
+     * Hashes a message using PHP's `password_hash` functionality.
50
+     * Please note that the size of the returned string is not guaranteed
51
+     * and can be up to 255 characters.
52
+     *
53
+     * @param string $message Message to generate hash from
54
+     * @return string Hash of the message with appended version parameter
55
+     * @since 8.0.0
56
+     */
57
+    public function hash(string $message): string;
58 58
 
59
-	/**
60
-	 * @param string $message Message to verify
61
-	 * @param string $hash Assumed hash of the message
62
-	 * @param null|string &$newHash Reference will contain the updated hash if necessary. Update the existing hash with this one.
63
-	 * @return bool Whether $hash is a valid hash of $message
64
-	 * @since 8.0.0
65
-	 */
66
-	public function verify(string $message, string $hash, &$newHash = null): bool ;
59
+    /**
60
+     * @param string $message Message to verify
61
+     * @param string $hash Assumed hash of the message
62
+     * @param null|string &$newHash Reference will contain the updated hash if necessary. Update the existing hash with this one.
63
+     * @return bool Whether $hash is a valid hash of $message
64
+     * @since 8.0.0
65
+     */
66
+    public function verify(string $message, string $hash, &$newHash = null): bool ;
67 67
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -63,5 +63,5 @@
 block discarded – undo
63 63
 	 * @return bool Whether $hash is a valid hash of $message
64 64
 	 * @since 8.0.0
65 65
 	 */
66
-	public function verify(string $message, string $hash, &$newHash = null): bool ;
66
+	public function verify(string $message, string $hash, &$newHash = null): bool;
67 67
 }
Please login to merge, or discard this patch.
apps/twofactor_backupcodes/lib/Migration/Version1002Date20170607113030.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -31,75 +31,75 @@
 block discarded – undo
31 31
 
32 32
 class Version1002Date20170607113030 extends SimpleMigrationStep {
33 33
 
34
-	/** @var IDBConnection */
35
-	protected $connection;
34
+    /** @var IDBConnection */
35
+    protected $connection;
36 36
 
37
-	/**
38
-	 * @param IDBConnection $connection
39
-	 */
40
-	public function __construct(IDBConnection $connection) {
41
-		$this->connection = $connection;
42
-	}
37
+    /**
38
+     * @param IDBConnection $connection
39
+     */
40
+    public function __construct(IDBConnection $connection) {
41
+        $this->connection = $connection;
42
+    }
43 43
 
44
-	/**
45
-	 * @param IOutput $output
46
-	 * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
47
-	 * @param array $options
48
-	 * @since 13.0.0
49
-	 */
50
-	public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
51
-		/** @var ISchemaWrapper $schema */
52
-		$schema = $schemaClosure();
44
+    /**
45
+     * @param IOutput $output
46
+     * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
47
+     * @param array $options
48
+     * @since 13.0.0
49
+     */
50
+    public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
51
+        /** @var ISchemaWrapper $schema */
52
+        $schema = $schemaClosure();
53 53
 
54
-		if (!$schema->hasTable('twofactor_backup_codes')) {
55
-			// Legacy table does not exist
56
-			return;
57
-		}
54
+        if (!$schema->hasTable('twofactor_backup_codes')) {
55
+            // Legacy table does not exist
56
+            return;
57
+        }
58 58
 
59
-		$insert = $this->connection->getQueryBuilder();
60
-		$insert->insert('twofactor_backupcodes')
61
-			->values([
62
-				// Inserting with id might fail: 'id' => $insert->createParameter('id'),
63
-				'user_id' => $insert->createParameter('user_id'),
64
-				'code' => $insert->createParameter('code'),
65
-				'used' => $insert->createParameter('used'),
66
-			]);
59
+        $insert = $this->connection->getQueryBuilder();
60
+        $insert->insert('twofactor_backupcodes')
61
+            ->values([
62
+                // Inserting with id might fail: 'id' => $insert->createParameter('id'),
63
+                'user_id' => $insert->createParameter('user_id'),
64
+                'code' => $insert->createParameter('code'),
65
+                'used' => $insert->createParameter('used'),
66
+            ]);
67 67
 
68
-		$query = $this->connection->getQueryBuilder();
69
-		$query->select('*')
70
-			->from('twofactor_backup_codes')
71
-			->orderBy('id', 'ASC');
72
-		$result = $query->execute();
68
+        $query = $this->connection->getQueryBuilder();
69
+        $query->select('*')
70
+            ->from('twofactor_backup_codes')
71
+            ->orderBy('id', 'ASC');
72
+        $result = $query->execute();
73 73
 
74
-		$output->startProgress();
75
-		while ($row = $result->fetch()) {
76
-			$output->advance();
74
+        $output->startProgress();
75
+        while ($row = $result->fetch()) {
76
+            $output->advance();
77 77
 
78
-			$insert
79
-				// Inserting with id might fail: ->setParameter('id', $row['id'], IQueryBuilder::PARAM_INT)
80
-				->setParameter('user_id', $row['user_id'], IQueryBuilder::PARAM_STR)
81
-				->setParameter('code', $row['code'], IQueryBuilder::PARAM_STR)
82
-				->setParameter('used', $row['used'], IQueryBuilder::PARAM_INT)
83
-				->execute();
84
-		}
85
-		$output->finishProgress();
86
-	}
78
+            $insert
79
+                // Inserting with id might fail: ->setParameter('id', $row['id'], IQueryBuilder::PARAM_INT)
80
+                ->setParameter('user_id', $row['user_id'], IQueryBuilder::PARAM_STR)
81
+                ->setParameter('code', $row['code'], IQueryBuilder::PARAM_STR)
82
+                ->setParameter('used', $row['used'], IQueryBuilder::PARAM_INT)
83
+                ->execute();
84
+        }
85
+        $output->finishProgress();
86
+    }
87 87
 
88
-	/**
89
-	 * @param IOutput $output
90
-	 * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
91
-	 * @param array $options
92
-	 * @return null|ISchemaWrapper
93
-	 * @since 13.0.0
94
-	 */
95
-	public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
96
-		/** @var ISchemaWrapper $schema */
97
-		$schema = $schemaClosure();
88
+    /**
89
+     * @param IOutput $output
90
+     * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
91
+     * @param array $options
92
+     * @return null|ISchemaWrapper
93
+     * @since 13.0.0
94
+     */
95
+    public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
96
+        /** @var ISchemaWrapper $schema */
97
+        $schema = $schemaClosure();
98 98
 
99
-		if ($schema->hasTable('twofactor_backup_codes')) {
100
-			$schema->dropTable('twofactor_backup_codes');
101
-			return $schema;
102
-		}
103
-		return null;
104
-	}
99
+        if ($schema->hasTable('twofactor_backup_codes')) {
100
+            $schema->dropTable('twofactor_backup_codes');
101
+            return $schema;
102
+        }
103
+        return null;
104
+    }
105 105
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Service/StoragesService.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -72,17 +72,17 @@  discard block
 block discarded – undo
72 72
 	}
73 73
 
74 74
 	protected function getStorageConfigFromDBMount(array $mount) {
75
-		$applicableUsers = array_filter($mount['applicable'], function ($applicable) {
75
+		$applicableUsers = array_filter($mount['applicable'], function($applicable) {
76 76
 			return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_USER;
77 77
 		});
78
-		$applicableUsers = array_map(function ($applicable) {
78
+		$applicableUsers = array_map(function($applicable) {
79 79
 			return $applicable['value'];
80 80
 		}, $applicableUsers);
81 81
 
82
-		$applicableGroups = array_filter($mount['applicable'], function ($applicable) {
82
+		$applicableGroups = array_filter($mount['applicable'], function($applicable) {
83 83
 			return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_GROUP;
84 84
 		});
85
-		$applicableGroups = array_map(function ($applicable) {
85
+		$applicableGroups = array_map(function($applicable) {
86 86
 			return $applicable['value'];
87 87
 		}, $applicableGroups);
88 88
 
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 				$mount['priority']
99 99
 			);
100 100
 			$config->setType($mount['type']);
101
-			$config->setId((int)$mount['mount_id']);
101
+			$config->setId((int) $mount['mount_id']);
102 102
 			return $config;
103 103
 		} catch (\UnexpectedValueException $e) {
104 104
 			// don't die if a storage backend doesn't exist
@@ -126,11 +126,11 @@  discard block
 block discarded – undo
126 126
 	protected function readConfig() {
127 127
 		$mounts = $this->readDBConfig();
128 128
 		$configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts);
129
-		$configs = array_filter($configs, function ($config) {
129
+		$configs = array_filter($configs, function($config) {
130 130
 			return $config instanceof StorageConfig;
131 131
 		});
132 132
 
133
-		$keys = array_map(function (StorageConfig $config) {
133
+		$keys = array_map(function(StorageConfig $config) {
134 134
 			return $config->getId();
135 135
 		}, $configs);
136 136
 
@@ -149,14 +149,14 @@  discard block
 block discarded – undo
149 149
 		$mount = $this->dbConfig->getMountById($id);
150 150
 
151 151
 		if (!is_array($mount)) {
152
-			throw new NotFoundException('Storage with ID "' . $id . '" not found');
152
+			throw new NotFoundException('Storage with ID "'.$id.'" not found');
153 153
 		}
154 154
 
155 155
 		$config = $this->getStorageConfigFromDBMount($mount);
156 156
 		if ($this->isApplicable($config)) {
157 157
 			return $config;
158 158
 		} else {
159
-			throw new NotFoundException('Storage with ID "' . $id . '" not found');
159
+			throw new NotFoundException('Storage with ID "'.$id.'" not found');
160 160
 		}
161 161
 	}
162 162
 
@@ -379,13 +379,13 @@  discard block
 block discarded – undo
379 379
 		$existingMount = $this->dbConfig->getMountById($id);
380 380
 
381 381
 		if (!is_array($existingMount)) {
382
-			throw new NotFoundException('Storage with ID "' . $id . '" not found while updating storage');
382
+			throw new NotFoundException('Storage with ID "'.$id.'" not found while updating storage');
383 383
 		}
384 384
 
385 385
 		$oldStorage = $this->getStorageConfigFromDBMount($existingMount);
386 386
 
387 387
 		if ($oldStorage->getBackend() instanceof InvalidBackend) {
388
-			throw new NotFoundException('Storage with id "' . $id . '" cannot be edited due to missing backend');
388
+			throw new NotFoundException('Storage with id "'.$id.'" cannot be edited due to missing backend');
389 389
 		}
390 390
 
391 391
 		$removedUsers = array_diff($oldStorage->getApplicableUsers(), $updatedStorage->getApplicableUsers());
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
 		$existingMount = $this->dbConfig->getMountById($id);
463 463
 
464 464
 		if (!is_array($existingMount)) {
465
-			throw new NotFoundException('Storage with ID "' . $id . '" not found');
465
+			throw new NotFoundException('Storage with ID "'.$id.'" not found');
466 466
 		}
467 467
 
468 468
 		$this->dbConfig->removeMount($id);
Please login to merge, or discard this patch.
Indentation   +465 added lines, -465 removed lines patch added patch discarded remove patch
@@ -51,469 +51,469 @@
 block discarded – undo
51 51
  */
52 52
 abstract class StoragesService {
53 53
 
54
-	/** @var BackendService */
55
-	protected $backendService;
56
-
57
-	/**
58
-	 * @var DBConfigService
59
-	 */
60
-	protected $dbConfig;
61
-
62
-	/**
63
-	 * @var IUserMountCache
64
-	 */
65
-	protected $userMountCache;
66
-
67
-	protected IEventDispatcher $eventDispatcher;
68
-
69
-	/**
70
-	 * @param BackendService $backendService
71
-	 * @param DBConfigService $dbConfigService
72
-	 * @param IUserMountCache $userMountCache
73
-	 * @param IEventDispatcher $eventDispatcher
74
-	 */
75
-	public function __construct(
76
-		BackendService $backendService,
77
-		DBConfigService $dbConfigService,
78
-		IUserMountCache $userMountCache,
79
-		IEventDispatcher $eventDispatcher
80
-	) {
81
-		$this->backendService = $backendService;
82
-		$this->dbConfig = $dbConfigService;
83
-		$this->userMountCache = $userMountCache;
84
-		$this->eventDispatcher = $eventDispatcher;
85
-	}
86
-
87
-	protected function readDBConfig() {
88
-		return $this->dbConfig->getAdminMounts();
89
-	}
90
-
91
-	protected function getStorageConfigFromDBMount(array $mount) {
92
-		$applicableUsers = array_filter($mount['applicable'], function ($applicable) {
93
-			return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_USER;
94
-		});
95
-		$applicableUsers = array_map(function ($applicable) {
96
-			return $applicable['value'];
97
-		}, $applicableUsers);
98
-
99
-		$applicableGroups = array_filter($mount['applicable'], function ($applicable) {
100
-			return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_GROUP;
101
-		});
102
-		$applicableGroups = array_map(function ($applicable) {
103
-			return $applicable['value'];
104
-		}, $applicableGroups);
105
-
106
-		try {
107
-			$config = $this->createStorage(
108
-				$mount['mount_point'],
109
-				$mount['storage_backend'],
110
-				$mount['auth_backend'],
111
-				$mount['config'],
112
-				$mount['options'],
113
-				array_values($applicableUsers),
114
-				array_values($applicableGroups),
115
-				$mount['priority']
116
-			);
117
-			$config->setType($mount['type']);
118
-			$config->setId((int)$mount['mount_id']);
119
-			return $config;
120
-		} catch (\UnexpectedValueException $e) {
121
-			// don't die if a storage backend doesn't exist
122
-			\OC::$server->getLogger()->logException($e, [
123
-				'message' => 'Could not load storage.',
124
-				'level' => ILogger::ERROR,
125
-				'app' => 'files_external',
126
-			]);
127
-			return null;
128
-		} catch (\InvalidArgumentException $e) {
129
-			\OC::$server->getLogger()->logException($e, [
130
-				'message' => 'Could not load storage.',
131
-				'level' => ILogger::ERROR,
132
-				'app' => 'files_external',
133
-			]);
134
-			return null;
135
-		}
136
-	}
137
-
138
-	/**
139
-	 * Read the external storage config
140
-	 *
141
-	 * @return array map of storage id to storage config
142
-	 */
143
-	protected function readConfig() {
144
-		$mounts = $this->readDBConfig();
145
-		$configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts);
146
-		$configs = array_filter($configs, function ($config) {
147
-			return $config instanceof StorageConfig;
148
-		});
149
-
150
-		$keys = array_map(function (StorageConfig $config) {
151
-			return $config->getId();
152
-		}, $configs);
153
-
154
-		return array_combine($keys, $configs);
155
-	}
156
-
157
-	/**
158
-	 * Get a storage with status
159
-	 *
160
-	 * @param int $id storage id
161
-	 *
162
-	 * @return StorageConfig
163
-	 * @throws NotFoundException if the storage with the given id was not found
164
-	 */
165
-	public function getStorage($id) {
166
-		$mount = $this->dbConfig->getMountById($id);
167
-
168
-		if (!is_array($mount)) {
169
-			throw new NotFoundException('Storage with ID "' . $id . '" not found');
170
-		}
171
-
172
-		$config = $this->getStorageConfigFromDBMount($mount);
173
-		if ($this->isApplicable($config)) {
174
-			return $config;
175
-		} else {
176
-			throw new NotFoundException('Storage with ID "' . $id . '" not found');
177
-		}
178
-	}
179
-
180
-	/**
181
-	 * Check whether this storage service should provide access to a storage
182
-	 *
183
-	 * @param StorageConfig $config
184
-	 * @return bool
185
-	 */
186
-	abstract protected function isApplicable(StorageConfig $config);
187
-
188
-	/**
189
-	 * Gets all storages, valid or not
190
-	 *
191
-	 * @return StorageConfig[] array of storage configs
192
-	 */
193
-	public function getAllStorages() {
194
-		return $this->readConfig();
195
-	}
196
-
197
-	/**
198
-	 * Gets all valid storages
199
-	 *
200
-	 * @return StorageConfig[]
201
-	 */
202
-	public function getStorages() {
203
-		return array_filter($this->getAllStorages(), [$this, 'validateStorage']);
204
-	}
205
-
206
-	/**
207
-	 * Validate storage
208
-	 * FIXME: De-duplicate with StoragesController::validate()
209
-	 *
210
-	 * @param StorageConfig $storage
211
-	 * @return bool
212
-	 */
213
-	protected function validateStorage(StorageConfig $storage) {
214
-		/** @var Backend */
215
-		$backend = $storage->getBackend();
216
-		/** @var AuthMechanism */
217
-		$authMechanism = $storage->getAuthMechanism();
218
-
219
-		if (!$backend->isVisibleFor($this->getVisibilityType())) {
220
-			// not permitted to use backend
221
-			return false;
222
-		}
223
-		if (!$authMechanism->isVisibleFor($this->getVisibilityType())) {
224
-			// not permitted to use auth mechanism
225
-			return false;
226
-		}
227
-
228
-		return true;
229
-	}
230
-
231
-	/**
232
-	 * Get the visibility type for this controller, used in validation
233
-	 *
234
-	 * @return int BackendService::VISIBILITY_* constants
235
-	 */
236
-	abstract public function getVisibilityType();
237
-
238
-	/**
239
-	 * @return integer
240
-	 */
241
-	protected function getType() {
242
-		return DBConfigService::MOUNT_TYPE_ADMIN;
243
-	}
244
-
245
-	/**
246
-	 * Add new storage to the configuration
247
-	 *
248
-	 * @param StorageConfig $newStorage storage attributes
249
-	 *
250
-	 * @return StorageConfig storage config, with added id
251
-	 */
252
-	public function addStorage(StorageConfig $newStorage) {
253
-		$allStorages = $this->readConfig();
254
-
255
-		$configId = $this->dbConfig->addMount(
256
-			$newStorage->getMountPoint(),
257
-			$newStorage->getBackend()->getIdentifier(),
258
-			$newStorage->getAuthMechanism()->getIdentifier(),
259
-			$newStorage->getPriority(),
260
-			$this->getType()
261
-		);
262
-
263
-		$newStorage->setId($configId);
264
-
265
-		foreach ($newStorage->getApplicableUsers() as $user) {
266
-			$this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_USER, $user);
267
-		}
268
-		foreach ($newStorage->getApplicableGroups() as $group) {
269
-			$this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
270
-		}
271
-		foreach ($newStorage->getBackendOptions() as $key => $value) {
272
-			$this->dbConfig->setConfig($configId, $key, $value);
273
-		}
274
-		foreach ($newStorage->getMountOptions() as $key => $value) {
275
-			$this->dbConfig->setOption($configId, $key, $value);
276
-		}
277
-
278
-		if (count($newStorage->getApplicableUsers()) === 0 && count($newStorage->getApplicableGroups()) === 0) {
279
-			$this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
280
-		}
281
-
282
-		// add new storage
283
-		$allStorages[$configId] = $newStorage;
284
-
285
-		$this->triggerHooks($newStorage, Filesystem::signal_create_mount);
286
-
287
-		$newStorage->setStatus(StorageNotAvailableException::STATUS_SUCCESS);
288
-		return $newStorage;
289
-	}
290
-
291
-	/**
292
-	 * Create a storage from its parameters
293
-	 *
294
-	 * @param string $mountPoint storage mount point
295
-	 * @param string $backendIdentifier backend identifier
296
-	 * @param string $authMechanismIdentifier authentication mechanism identifier
297
-	 * @param array $backendOptions backend-specific options
298
-	 * @param array|null $mountOptions mount-specific options
299
-	 * @param array|null $applicableUsers users for which to mount the storage
300
-	 * @param array|null $applicableGroups groups for which to mount the storage
301
-	 * @param int|null $priority priority
302
-	 *
303
-	 * @return StorageConfig
304
-	 */
305
-	public function createStorage(
306
-		$mountPoint,
307
-		$backendIdentifier,
308
-		$authMechanismIdentifier,
309
-		$backendOptions,
310
-		$mountOptions = null,
311
-		$applicableUsers = null,
312
-		$applicableGroups = null,
313
-		$priority = null
314
-	) {
315
-		$backend = $this->backendService->getBackend($backendIdentifier);
316
-		if (!$backend) {
317
-			$backend = new InvalidBackend($backendIdentifier);
318
-		}
319
-		$authMechanism = $this->backendService->getAuthMechanism($authMechanismIdentifier);
320
-		if (!$authMechanism) {
321
-			$authMechanism = new InvalidAuth($authMechanismIdentifier);
322
-		}
323
-		$newStorage = new StorageConfig();
324
-		$newStorage->setMountPoint($mountPoint);
325
-		$newStorage->setBackend($backend);
326
-		$newStorage->setAuthMechanism($authMechanism);
327
-		$newStorage->setBackendOptions($backendOptions);
328
-		if (isset($mountOptions)) {
329
-			$newStorage->setMountOptions($mountOptions);
330
-		}
331
-		if (isset($applicableUsers)) {
332
-			$newStorage->setApplicableUsers($applicableUsers);
333
-		}
334
-		if (isset($applicableGroups)) {
335
-			$newStorage->setApplicableGroups($applicableGroups);
336
-		}
337
-		if (isset($priority)) {
338
-			$newStorage->setPriority($priority);
339
-		}
340
-
341
-		return $newStorage;
342
-	}
343
-
344
-	/**
345
-	 * Triggers the given hook signal for all the applicables given
346
-	 *
347
-	 * @param string $signal signal
348
-	 * @param string $mountPoint hook mount point param
349
-	 * @param string $mountType hook mount type param
350
-	 * @param array $applicableArray array of applicable users/groups for which to trigger the hook
351
-	 */
352
-	protected function triggerApplicableHooks($signal, $mountPoint, $mountType, $applicableArray): void {
353
-		$this->eventDispatcher->dispatchTyped(new InvalidateMountCacheEvent(null));
354
-		foreach ($applicableArray as $applicable) {
355
-			\OCP\Util::emitHook(
356
-				Filesystem::CLASSNAME,
357
-				$signal,
358
-				[
359
-					Filesystem::signal_param_path => $mountPoint,
360
-					Filesystem::signal_param_mount_type => $mountType,
361
-					Filesystem::signal_param_users => $applicable,
362
-				]
363
-			);
364
-		}
365
-	}
366
-
367
-	/**
368
-	 * Triggers $signal for all applicable users of the given
369
-	 * storage
370
-	 *
371
-	 * @param StorageConfig $storage storage data
372
-	 * @param string $signal signal to trigger
373
-	 */
374
-	abstract protected function triggerHooks(StorageConfig $storage, $signal);
375
-
376
-	/**
377
-	 * Triggers signal_create_mount or signal_delete_mount to
378
-	 * accommodate for additions/deletions in applicableUsers
379
-	 * and applicableGroups fields.
380
-	 *
381
-	 * @param StorageConfig $oldStorage old storage data
382
-	 * @param StorageConfig $newStorage new storage data
383
-	 */
384
-	abstract protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage);
385
-
386
-	/**
387
-	 * Update storage to the configuration
388
-	 *
389
-	 * @param StorageConfig $updatedStorage storage attributes
390
-	 *
391
-	 * @return StorageConfig storage config
392
-	 * @throws NotFoundException if the given storage does not exist in the config
393
-	 */
394
-	public function updateStorage(StorageConfig $updatedStorage) {
395
-		$id = $updatedStorage->getId();
396
-
397
-		$existingMount = $this->dbConfig->getMountById($id);
398
-
399
-		if (!is_array($existingMount)) {
400
-			throw new NotFoundException('Storage with ID "' . $id . '" not found while updating storage');
401
-		}
402
-
403
-		$oldStorage = $this->getStorageConfigFromDBMount($existingMount);
404
-
405
-		if ($oldStorage->getBackend() instanceof InvalidBackend) {
406
-			throw new NotFoundException('Storage with id "' . $id . '" cannot be edited due to missing backend');
407
-		}
408
-
409
-		$removedUsers = array_diff($oldStorage->getApplicableUsers(), $updatedStorage->getApplicableUsers());
410
-		$removedGroups = array_diff($oldStorage->getApplicableGroups(), $updatedStorage->getApplicableGroups());
411
-		$addedUsers = array_diff($updatedStorage->getApplicableUsers(), $oldStorage->getApplicableUsers());
412
-		$addedGroups = array_diff($updatedStorage->getApplicableGroups(), $oldStorage->getApplicableGroups());
413
-
414
-		$oldUserCount = count($oldStorage->getApplicableUsers());
415
-		$oldGroupCount = count($oldStorage->getApplicableGroups());
416
-		$newUserCount = count($updatedStorage->getApplicableUsers());
417
-		$newGroupCount = count($updatedStorage->getApplicableGroups());
418
-		$wasGlobal = ($oldUserCount + $oldGroupCount) === 0;
419
-		$isGlobal = ($newUserCount + $newGroupCount) === 0;
420
-
421
-		foreach ($removedUsers as $user) {
422
-			$this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user);
423
-		}
424
-		foreach ($removedGroups as $group) {
425
-			$this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
426
-		}
427
-		foreach ($addedUsers as $user) {
428
-			$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user);
429
-		}
430
-		foreach ($addedGroups as $group) {
431
-			$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
432
-		}
433
-
434
-		if ($wasGlobal && !$isGlobal) {
435
-			$this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
436
-		} elseif (!$wasGlobal && $isGlobal) {
437
-			$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
438
-		}
439
-
440
-		$changedConfig = array_diff_assoc($updatedStorage->getBackendOptions(), $oldStorage->getBackendOptions());
441
-		$changedOptions = array_diff_assoc($updatedStorage->getMountOptions(), $oldStorage->getMountOptions());
442
-
443
-		foreach ($changedConfig as $key => $value) {
444
-			if ($value !== DefinitionParameter::UNMODIFIED_PLACEHOLDER) {
445
-				$this->dbConfig->setConfig($id, $key, $value);
446
-			}
447
-		}
448
-		foreach ($changedOptions as $key => $value) {
449
-			$this->dbConfig->setOption($id, $key, $value);
450
-		}
451
-
452
-		if ($updatedStorage->getMountPoint() !== $oldStorage->getMountPoint()) {
453
-			$this->dbConfig->setMountPoint($id, $updatedStorage->getMountPoint());
454
-		}
455
-
456
-		if ($updatedStorage->getAuthMechanism()->getIdentifier() !== $oldStorage->getAuthMechanism()->getIdentifier()) {
457
-			$this->dbConfig->setAuthBackend($id, $updatedStorage->getAuthMechanism()->getIdentifier());
458
-		}
459
-
460
-		$this->triggerChangeHooks($oldStorage, $updatedStorage);
461
-
462
-		if (($wasGlobal && !$isGlobal) || count($removedGroups) > 0) { // to expensive to properly handle these on the fly
463
-			$this->userMountCache->remoteStorageMounts($this->getStorageId($updatedStorage));
464
-		} else {
465
-			$storageId = $this->getStorageId($updatedStorage);
466
-			foreach ($removedUsers as $userId) {
467
-				$this->userMountCache->removeUserStorageMount($storageId, $userId);
468
-			}
469
-		}
470
-
471
-		return $this->getStorage($id);
472
-	}
473
-
474
-	/**
475
-	 * Delete the storage with the given id.
476
-	 *
477
-	 * @param int $id storage id
478
-	 *
479
-	 * @throws NotFoundException if no storage was found with the given id
480
-	 */
481
-	public function removeStorage($id) {
482
-		$existingMount = $this->dbConfig->getMountById($id);
483
-
484
-		if (!is_array($existingMount)) {
485
-			throw new NotFoundException('Storage with ID "' . $id . '" not found');
486
-		}
487
-
488
-		$this->dbConfig->removeMount($id);
489
-
490
-		$deletedStorage = $this->getStorageConfigFromDBMount($existingMount);
491
-		$this->triggerHooks($deletedStorage, Filesystem::signal_delete_mount);
492
-
493
-		// delete oc_storages entries and oc_filecache
494
-		\OC\Files\Cache\Storage::cleanByMountId($id);
495
-	}
496
-
497
-	/**
498
-	 * Construct the storage implementation
499
-	 *
500
-	 * @param StorageConfig $storageConfig
501
-	 * @return int
502
-	 */
503
-	private function getStorageId(StorageConfig $storageConfig) {
504
-		try {
505
-			$class = $storageConfig->getBackend()->getStorageClass();
506
-			/** @var \OC\Files\Storage\Storage $storage */
507
-			$storage = new $class($storageConfig->getBackendOptions());
508
-
509
-			// auth mechanism should fire first
510
-			$storage = $storageConfig->getBackend()->wrapStorage($storage);
511
-			$storage = $storageConfig->getAuthMechanism()->wrapStorage($storage);
512
-
513
-			/** @var \OC\Files\Storage\Storage $storage */
514
-			return $storage->getStorageCache()->getNumericId();
515
-		} catch (\Exception $e) {
516
-			return -1;
517
-		}
518
-	}
54
+    /** @var BackendService */
55
+    protected $backendService;
56
+
57
+    /**
58
+     * @var DBConfigService
59
+     */
60
+    protected $dbConfig;
61
+
62
+    /**
63
+     * @var IUserMountCache
64
+     */
65
+    protected $userMountCache;
66
+
67
+    protected IEventDispatcher $eventDispatcher;
68
+
69
+    /**
70
+     * @param BackendService $backendService
71
+     * @param DBConfigService $dbConfigService
72
+     * @param IUserMountCache $userMountCache
73
+     * @param IEventDispatcher $eventDispatcher
74
+     */
75
+    public function __construct(
76
+        BackendService $backendService,
77
+        DBConfigService $dbConfigService,
78
+        IUserMountCache $userMountCache,
79
+        IEventDispatcher $eventDispatcher
80
+    ) {
81
+        $this->backendService = $backendService;
82
+        $this->dbConfig = $dbConfigService;
83
+        $this->userMountCache = $userMountCache;
84
+        $this->eventDispatcher = $eventDispatcher;
85
+    }
86
+
87
+    protected function readDBConfig() {
88
+        return $this->dbConfig->getAdminMounts();
89
+    }
90
+
91
+    protected function getStorageConfigFromDBMount(array $mount) {
92
+        $applicableUsers = array_filter($mount['applicable'], function ($applicable) {
93
+            return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_USER;
94
+        });
95
+        $applicableUsers = array_map(function ($applicable) {
96
+            return $applicable['value'];
97
+        }, $applicableUsers);
98
+
99
+        $applicableGroups = array_filter($mount['applicable'], function ($applicable) {
100
+            return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_GROUP;
101
+        });
102
+        $applicableGroups = array_map(function ($applicable) {
103
+            return $applicable['value'];
104
+        }, $applicableGroups);
105
+
106
+        try {
107
+            $config = $this->createStorage(
108
+                $mount['mount_point'],
109
+                $mount['storage_backend'],
110
+                $mount['auth_backend'],
111
+                $mount['config'],
112
+                $mount['options'],
113
+                array_values($applicableUsers),
114
+                array_values($applicableGroups),
115
+                $mount['priority']
116
+            );
117
+            $config->setType($mount['type']);
118
+            $config->setId((int)$mount['mount_id']);
119
+            return $config;
120
+        } catch (\UnexpectedValueException $e) {
121
+            // don't die if a storage backend doesn't exist
122
+            \OC::$server->getLogger()->logException($e, [
123
+                'message' => 'Could not load storage.',
124
+                'level' => ILogger::ERROR,
125
+                'app' => 'files_external',
126
+            ]);
127
+            return null;
128
+        } catch (\InvalidArgumentException $e) {
129
+            \OC::$server->getLogger()->logException($e, [
130
+                'message' => 'Could not load storage.',
131
+                'level' => ILogger::ERROR,
132
+                'app' => 'files_external',
133
+            ]);
134
+            return null;
135
+        }
136
+    }
137
+
138
+    /**
139
+     * Read the external storage config
140
+     *
141
+     * @return array map of storage id to storage config
142
+     */
143
+    protected function readConfig() {
144
+        $mounts = $this->readDBConfig();
145
+        $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts);
146
+        $configs = array_filter($configs, function ($config) {
147
+            return $config instanceof StorageConfig;
148
+        });
149
+
150
+        $keys = array_map(function (StorageConfig $config) {
151
+            return $config->getId();
152
+        }, $configs);
153
+
154
+        return array_combine($keys, $configs);
155
+    }
156
+
157
+    /**
158
+     * Get a storage with status
159
+     *
160
+     * @param int $id storage id
161
+     *
162
+     * @return StorageConfig
163
+     * @throws NotFoundException if the storage with the given id was not found
164
+     */
165
+    public function getStorage($id) {
166
+        $mount = $this->dbConfig->getMountById($id);
167
+
168
+        if (!is_array($mount)) {
169
+            throw new NotFoundException('Storage with ID "' . $id . '" not found');
170
+        }
171
+
172
+        $config = $this->getStorageConfigFromDBMount($mount);
173
+        if ($this->isApplicable($config)) {
174
+            return $config;
175
+        } else {
176
+            throw new NotFoundException('Storage with ID "' . $id . '" not found');
177
+        }
178
+    }
179
+
180
+    /**
181
+     * Check whether this storage service should provide access to a storage
182
+     *
183
+     * @param StorageConfig $config
184
+     * @return bool
185
+     */
186
+    abstract protected function isApplicable(StorageConfig $config);
187
+
188
+    /**
189
+     * Gets all storages, valid or not
190
+     *
191
+     * @return StorageConfig[] array of storage configs
192
+     */
193
+    public function getAllStorages() {
194
+        return $this->readConfig();
195
+    }
196
+
197
+    /**
198
+     * Gets all valid storages
199
+     *
200
+     * @return StorageConfig[]
201
+     */
202
+    public function getStorages() {
203
+        return array_filter($this->getAllStorages(), [$this, 'validateStorage']);
204
+    }
205
+
206
+    /**
207
+     * Validate storage
208
+     * FIXME: De-duplicate with StoragesController::validate()
209
+     *
210
+     * @param StorageConfig $storage
211
+     * @return bool
212
+     */
213
+    protected function validateStorage(StorageConfig $storage) {
214
+        /** @var Backend */
215
+        $backend = $storage->getBackend();
216
+        /** @var AuthMechanism */
217
+        $authMechanism = $storage->getAuthMechanism();
218
+
219
+        if (!$backend->isVisibleFor($this->getVisibilityType())) {
220
+            // not permitted to use backend
221
+            return false;
222
+        }
223
+        if (!$authMechanism->isVisibleFor($this->getVisibilityType())) {
224
+            // not permitted to use auth mechanism
225
+            return false;
226
+        }
227
+
228
+        return true;
229
+    }
230
+
231
+    /**
232
+     * Get the visibility type for this controller, used in validation
233
+     *
234
+     * @return int BackendService::VISIBILITY_* constants
235
+     */
236
+    abstract public function getVisibilityType();
237
+
238
+    /**
239
+     * @return integer
240
+     */
241
+    protected function getType() {
242
+        return DBConfigService::MOUNT_TYPE_ADMIN;
243
+    }
244
+
245
+    /**
246
+     * Add new storage to the configuration
247
+     *
248
+     * @param StorageConfig $newStorage storage attributes
249
+     *
250
+     * @return StorageConfig storage config, with added id
251
+     */
252
+    public function addStorage(StorageConfig $newStorage) {
253
+        $allStorages = $this->readConfig();
254
+
255
+        $configId = $this->dbConfig->addMount(
256
+            $newStorage->getMountPoint(),
257
+            $newStorage->getBackend()->getIdentifier(),
258
+            $newStorage->getAuthMechanism()->getIdentifier(),
259
+            $newStorage->getPriority(),
260
+            $this->getType()
261
+        );
262
+
263
+        $newStorage->setId($configId);
264
+
265
+        foreach ($newStorage->getApplicableUsers() as $user) {
266
+            $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_USER, $user);
267
+        }
268
+        foreach ($newStorage->getApplicableGroups() as $group) {
269
+            $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
270
+        }
271
+        foreach ($newStorage->getBackendOptions() as $key => $value) {
272
+            $this->dbConfig->setConfig($configId, $key, $value);
273
+        }
274
+        foreach ($newStorage->getMountOptions() as $key => $value) {
275
+            $this->dbConfig->setOption($configId, $key, $value);
276
+        }
277
+
278
+        if (count($newStorage->getApplicableUsers()) === 0 && count($newStorage->getApplicableGroups()) === 0) {
279
+            $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
280
+        }
281
+
282
+        // add new storage
283
+        $allStorages[$configId] = $newStorage;
284
+
285
+        $this->triggerHooks($newStorage, Filesystem::signal_create_mount);
286
+
287
+        $newStorage->setStatus(StorageNotAvailableException::STATUS_SUCCESS);
288
+        return $newStorage;
289
+    }
290
+
291
+    /**
292
+     * Create a storage from its parameters
293
+     *
294
+     * @param string $mountPoint storage mount point
295
+     * @param string $backendIdentifier backend identifier
296
+     * @param string $authMechanismIdentifier authentication mechanism identifier
297
+     * @param array $backendOptions backend-specific options
298
+     * @param array|null $mountOptions mount-specific options
299
+     * @param array|null $applicableUsers users for which to mount the storage
300
+     * @param array|null $applicableGroups groups for which to mount the storage
301
+     * @param int|null $priority priority
302
+     *
303
+     * @return StorageConfig
304
+     */
305
+    public function createStorage(
306
+        $mountPoint,
307
+        $backendIdentifier,
308
+        $authMechanismIdentifier,
309
+        $backendOptions,
310
+        $mountOptions = null,
311
+        $applicableUsers = null,
312
+        $applicableGroups = null,
313
+        $priority = null
314
+    ) {
315
+        $backend = $this->backendService->getBackend($backendIdentifier);
316
+        if (!$backend) {
317
+            $backend = new InvalidBackend($backendIdentifier);
318
+        }
319
+        $authMechanism = $this->backendService->getAuthMechanism($authMechanismIdentifier);
320
+        if (!$authMechanism) {
321
+            $authMechanism = new InvalidAuth($authMechanismIdentifier);
322
+        }
323
+        $newStorage = new StorageConfig();
324
+        $newStorage->setMountPoint($mountPoint);
325
+        $newStorage->setBackend($backend);
326
+        $newStorage->setAuthMechanism($authMechanism);
327
+        $newStorage->setBackendOptions($backendOptions);
328
+        if (isset($mountOptions)) {
329
+            $newStorage->setMountOptions($mountOptions);
330
+        }
331
+        if (isset($applicableUsers)) {
332
+            $newStorage->setApplicableUsers($applicableUsers);
333
+        }
334
+        if (isset($applicableGroups)) {
335
+            $newStorage->setApplicableGroups($applicableGroups);
336
+        }
337
+        if (isset($priority)) {
338
+            $newStorage->setPriority($priority);
339
+        }
340
+
341
+        return $newStorage;
342
+    }
343
+
344
+    /**
345
+     * Triggers the given hook signal for all the applicables given
346
+     *
347
+     * @param string $signal signal
348
+     * @param string $mountPoint hook mount point param
349
+     * @param string $mountType hook mount type param
350
+     * @param array $applicableArray array of applicable users/groups for which to trigger the hook
351
+     */
352
+    protected function triggerApplicableHooks($signal, $mountPoint, $mountType, $applicableArray): void {
353
+        $this->eventDispatcher->dispatchTyped(new InvalidateMountCacheEvent(null));
354
+        foreach ($applicableArray as $applicable) {
355
+            \OCP\Util::emitHook(
356
+                Filesystem::CLASSNAME,
357
+                $signal,
358
+                [
359
+                    Filesystem::signal_param_path => $mountPoint,
360
+                    Filesystem::signal_param_mount_type => $mountType,
361
+                    Filesystem::signal_param_users => $applicable,
362
+                ]
363
+            );
364
+        }
365
+    }
366
+
367
+    /**
368
+     * Triggers $signal for all applicable users of the given
369
+     * storage
370
+     *
371
+     * @param StorageConfig $storage storage data
372
+     * @param string $signal signal to trigger
373
+     */
374
+    abstract protected function triggerHooks(StorageConfig $storage, $signal);
375
+
376
+    /**
377
+     * Triggers signal_create_mount or signal_delete_mount to
378
+     * accommodate for additions/deletions in applicableUsers
379
+     * and applicableGroups fields.
380
+     *
381
+     * @param StorageConfig $oldStorage old storage data
382
+     * @param StorageConfig $newStorage new storage data
383
+     */
384
+    abstract protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage);
385
+
386
+    /**
387
+     * Update storage to the configuration
388
+     *
389
+     * @param StorageConfig $updatedStorage storage attributes
390
+     *
391
+     * @return StorageConfig storage config
392
+     * @throws NotFoundException if the given storage does not exist in the config
393
+     */
394
+    public function updateStorage(StorageConfig $updatedStorage) {
395
+        $id = $updatedStorage->getId();
396
+
397
+        $existingMount = $this->dbConfig->getMountById($id);
398
+
399
+        if (!is_array($existingMount)) {
400
+            throw new NotFoundException('Storage with ID "' . $id . '" not found while updating storage');
401
+        }
402
+
403
+        $oldStorage = $this->getStorageConfigFromDBMount($existingMount);
404
+
405
+        if ($oldStorage->getBackend() instanceof InvalidBackend) {
406
+            throw new NotFoundException('Storage with id "' . $id . '" cannot be edited due to missing backend');
407
+        }
408
+
409
+        $removedUsers = array_diff($oldStorage->getApplicableUsers(), $updatedStorage->getApplicableUsers());
410
+        $removedGroups = array_diff($oldStorage->getApplicableGroups(), $updatedStorage->getApplicableGroups());
411
+        $addedUsers = array_diff($updatedStorage->getApplicableUsers(), $oldStorage->getApplicableUsers());
412
+        $addedGroups = array_diff($updatedStorage->getApplicableGroups(), $oldStorage->getApplicableGroups());
413
+
414
+        $oldUserCount = count($oldStorage->getApplicableUsers());
415
+        $oldGroupCount = count($oldStorage->getApplicableGroups());
416
+        $newUserCount = count($updatedStorage->getApplicableUsers());
417
+        $newGroupCount = count($updatedStorage->getApplicableGroups());
418
+        $wasGlobal = ($oldUserCount + $oldGroupCount) === 0;
419
+        $isGlobal = ($newUserCount + $newGroupCount) === 0;
420
+
421
+        foreach ($removedUsers as $user) {
422
+            $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user);
423
+        }
424
+        foreach ($removedGroups as $group) {
425
+            $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
426
+        }
427
+        foreach ($addedUsers as $user) {
428
+            $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user);
429
+        }
430
+        foreach ($addedGroups as $group) {
431
+            $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
432
+        }
433
+
434
+        if ($wasGlobal && !$isGlobal) {
435
+            $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
436
+        } elseif (!$wasGlobal && $isGlobal) {
437
+            $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
438
+        }
439
+
440
+        $changedConfig = array_diff_assoc($updatedStorage->getBackendOptions(), $oldStorage->getBackendOptions());
441
+        $changedOptions = array_diff_assoc($updatedStorage->getMountOptions(), $oldStorage->getMountOptions());
442
+
443
+        foreach ($changedConfig as $key => $value) {
444
+            if ($value !== DefinitionParameter::UNMODIFIED_PLACEHOLDER) {
445
+                $this->dbConfig->setConfig($id, $key, $value);
446
+            }
447
+        }
448
+        foreach ($changedOptions as $key => $value) {
449
+            $this->dbConfig->setOption($id, $key, $value);
450
+        }
451
+
452
+        if ($updatedStorage->getMountPoint() !== $oldStorage->getMountPoint()) {
453
+            $this->dbConfig->setMountPoint($id, $updatedStorage->getMountPoint());
454
+        }
455
+
456
+        if ($updatedStorage->getAuthMechanism()->getIdentifier() !== $oldStorage->getAuthMechanism()->getIdentifier()) {
457
+            $this->dbConfig->setAuthBackend($id, $updatedStorage->getAuthMechanism()->getIdentifier());
458
+        }
459
+
460
+        $this->triggerChangeHooks($oldStorage, $updatedStorage);
461
+
462
+        if (($wasGlobal && !$isGlobal) || count($removedGroups) > 0) { // to expensive to properly handle these on the fly
463
+            $this->userMountCache->remoteStorageMounts($this->getStorageId($updatedStorage));
464
+        } else {
465
+            $storageId = $this->getStorageId($updatedStorage);
466
+            foreach ($removedUsers as $userId) {
467
+                $this->userMountCache->removeUserStorageMount($storageId, $userId);
468
+            }
469
+        }
470
+
471
+        return $this->getStorage($id);
472
+    }
473
+
474
+    /**
475
+     * Delete the storage with the given id.
476
+     *
477
+     * @param int $id storage id
478
+     *
479
+     * @throws NotFoundException if no storage was found with the given id
480
+     */
481
+    public function removeStorage($id) {
482
+        $existingMount = $this->dbConfig->getMountById($id);
483
+
484
+        if (!is_array($existingMount)) {
485
+            throw new NotFoundException('Storage with ID "' . $id . '" not found');
486
+        }
487
+
488
+        $this->dbConfig->removeMount($id);
489
+
490
+        $deletedStorage = $this->getStorageConfigFromDBMount($existingMount);
491
+        $this->triggerHooks($deletedStorage, Filesystem::signal_delete_mount);
492
+
493
+        // delete oc_storages entries and oc_filecache
494
+        \OC\Files\Cache\Storage::cleanByMountId($id);
495
+    }
496
+
497
+    /**
498
+     * Construct the storage implementation
499
+     *
500
+     * @param StorageConfig $storageConfig
501
+     * @return int
502
+     */
503
+    private function getStorageId(StorageConfig $storageConfig) {
504
+        try {
505
+            $class = $storageConfig->getBackend()->getStorageClass();
506
+            /** @var \OC\Files\Storage\Storage $storage */
507
+            $storage = new $class($storageConfig->getBackendOptions());
508
+
509
+            // auth mechanism should fire first
510
+            $storage = $storageConfig->getBackend()->wrapStorage($storage);
511
+            $storage = $storageConfig->getAuthMechanism()->wrapStorage($storage);
512
+
513
+            /** @var \OC\Files\Storage\Storage $storage */
514
+            return $storage->getStorageCache()->getNumericId();
515
+        } catch (\Exception $e) {
516
+            return -1;
517
+        }
518
+    }
519 519
 }
Please login to merge, or discard this patch.
lib/public/IAppConfig.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -31,41 +31,41 @@
 block discarded – undo
31 31
  * @since 7.0.0
32 32
  */
33 33
 interface IAppConfig {
34
-	/**
35
-	 * check if a key is set in the appconfig
36
-	 * @param string $app
37
-	 * @param string $key
38
-	 * @return bool
39
-	 * @since 7.0.0
40
-	 */
41
-	public function hasKey($app, $key);
34
+    /**
35
+     * check if a key is set in the appconfig
36
+     * @param string $app
37
+     * @param string $key
38
+     * @return bool
39
+     * @since 7.0.0
40
+     */
41
+    public function hasKey($app, $key);
42 42
 
43
-	/**
44
-	 * get multiply values, either the app or key can be used as wildcard by setting it to false
45
-	 *
46
-	 * @param string|false $key
47
-	 * @param string|false $app
48
-	 * @return array|false
49
-	 * @since 7.0.0
50
-	 */
51
-	public function getValues($app, $key);
43
+    /**
44
+     * get multiply values, either the app or key can be used as wildcard by setting it to false
45
+     *
46
+     * @param string|false $key
47
+     * @param string|false $app
48
+     * @return array|false
49
+     * @since 7.0.0
50
+     */
51
+    public function getValues($app, $key);
52 52
 
53
-	/**
54
-	 * get all values of the app or and filters out sensitive data
55
-	 *
56
-	 * @param string $app
57
-	 * @return array
58
-	 * @since 12.0.0
59
-	 */
60
-	public function getFilteredValues($app);
53
+    /**
54
+     * get all values of the app or and filters out sensitive data
55
+     *
56
+     * @param string $app
57
+     * @return array
58
+     * @since 12.0.0
59
+     */
60
+    public function getFilteredValues($app);
61 61
 
62
-	/**
63
-	 * Get all apps using the config
64
-	 * @return array an array of app ids
65
-	 *
66
-	 * This function returns a list of all apps that have at least one
67
-	 * entry in the appconfig table.
68
-	 * @since 7.0.0
69
-	 */
70
-	public function getApps();
62
+    /**
63
+     * Get all apps using the config
64
+     * @return array an array of app ids
65
+     *
66
+     * This function returns a list of all apps that have at least one
67
+     * entry in the appconfig table.
68
+     * @since 7.0.0
69
+     */
70
+    public function getApps();
71 71
 }
Please login to merge, or discard this patch.
apps/workflowengine/lib/Controller/RequestTime.php 2 patches
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -26,27 +26,27 @@
 block discarded – undo
26 26
 
27 27
 class RequestTime extends Controller {
28 28
 
29
-	/**
30
-	 * @NoAdminRequired
31
-	 *
32
-	 * @param string $search
33
-	 * @return JSONResponse
34
-	 */
35
-	public function getTimezones($search = '') {
36
-		$timezones = \DateTimeZone::listIdentifiers();
29
+    /**
30
+     * @NoAdminRequired
31
+     *
32
+     * @param string $search
33
+     * @return JSONResponse
34
+     */
35
+    public function getTimezones($search = '') {
36
+        $timezones = \DateTimeZone::listIdentifiers();
37 37
 
38
-		if ($search !== '') {
39
-			$timezones = array_filter($timezones, function ($timezone) use ($search) {
40
-				return stripos($timezone, $search) !== false;
41
-			});
42
-		}
38
+        if ($search !== '') {
39
+            $timezones = array_filter($timezones, function ($timezone) use ($search) {
40
+                return stripos($timezone, $search) !== false;
41
+            });
42
+        }
43 43
 
44
-		$timezones = array_slice($timezones, 0, 10);
44
+        $timezones = array_slice($timezones, 0, 10);
45 45
 
46
-		$response = [];
47
-		foreach ($timezones as $timezone) {
48
-			$response[$timezone] = $timezone;
49
-		}
50
-		return new JSONResponse($response);
51
-	}
46
+        $response = [];
47
+        foreach ($timezones as $timezone) {
48
+            $response[$timezone] = $timezone;
49
+        }
50
+        return new JSONResponse($response);
51
+    }
52 52
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@
 block discarded – undo
36 36
 		$timezones = \DateTimeZone::listIdentifiers();
37 37
 
38 38
 		if ($search !== '') {
39
-			$timezones = array_filter($timezones, function ($timezone) use ($search) {
39
+			$timezones = array_filter($timezones, function($timezone) use ($search) {
40 40
 				return stripos($timezone, $search) !== false;
41 41
 			});
42 42
 		}
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/Template/SimpleMenuAction.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -164,7 +164,7 @@
 block discarded – undo
164 164
 	 * @since 14.0.0
165 165
 	 */
166 166
 	public function render(): string {
167
-		$detailContent = ($this->detail !== '') ? '&nbsp;<span class="download-size">(' . Util::sanitizeHTML($this->detail) . ')</span>' : '';
167
+		$detailContent = ($this->detail !== '') ? '&nbsp;<span class="download-size">('.Util::sanitizeHTML($this->detail).')</span>' : '';
168 168
 		return sprintf(
169 169
 			'<li id="%s"><a href="%s"><span class="icon %s"></span>%s %s</a></li>',
170 170
 			Util::sanitizeHTML($this->id), Util::sanitizeHTML($this->link), Util::sanitizeHTML($this->icon), Util::sanitizeHTML($this->label), $detailContent
Please login to merge, or discard this patch.
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -31,93 +31,93 @@
 block discarded – undo
31 31
  * @since 14.0.0
32 32
  */
33 33
 class SimpleMenuAction implements IMenuAction {
34
-	/** @var string */
35
-	private $id;
34
+    /** @var string */
35
+    private $id;
36 36
 
37
-	/** @var string */
38
-	private $label;
37
+    /** @var string */
38
+    private $label;
39 39
 
40
-	/** @var string */
41
-	private $icon;
40
+    /** @var string */
41
+    private $icon;
42 42
 
43
-	/** @var string */
44
-	private $link;
43
+    /** @var string */
44
+    private $link;
45 45
 
46
-	/** @var int */
47
-	private $priority;
46
+    /** @var int */
47
+    private $priority;
48 48
 
49
-	/** @var string */
50
-	private $detail;
49
+    /** @var string */
50
+    private $detail;
51 51
 
52
-	/**
53
-	 * SimpleMenuAction constructor.
54
-	 *
55
-	 * @param string $id
56
-	 * @param string $label
57
-	 * @param string $icon
58
-	 * @param string $link
59
-	 * @param int $priority
60
-	 * @param string $detail
61
-	 * @since 14.0.0
62
-	 */
63
-	public function __construct(string $id, string $label, string $icon, string $link = '', int $priority = 100, string $detail = '') {
64
-		$this->id = $id;
65
-		$this->label = $label;
66
-		$this->icon = $icon;
67
-		$this->link = $link;
68
-		$this->priority = $priority;
69
-		$this->detail = $detail;
70
-	}
52
+    /**
53
+     * SimpleMenuAction constructor.
54
+     *
55
+     * @param string $id
56
+     * @param string $label
57
+     * @param string $icon
58
+     * @param string $link
59
+     * @param int $priority
60
+     * @param string $detail
61
+     * @since 14.0.0
62
+     */
63
+    public function __construct(string $id, string $label, string $icon, string $link = '', int $priority = 100, string $detail = '') {
64
+        $this->id = $id;
65
+        $this->label = $label;
66
+        $this->icon = $icon;
67
+        $this->link = $link;
68
+        $this->priority = $priority;
69
+        $this->detail = $detail;
70
+    }
71 71
 
72
-	/**
73
-	 * @return string
74
-	 * @since 14.0.0
75
-	 */
76
-	public function getId(): string {
77
-		return $this->id;
78
-	}
72
+    /**
73
+     * @return string
74
+     * @since 14.0.0
75
+     */
76
+    public function getId(): string {
77
+        return $this->id;
78
+    }
79 79
 
80
-	/**
81
-	 * @return string
82
-	 * @since 14.0.0
83
-	 */
84
-	public function getLabel(): string {
85
-		return $this->label;
86
-	}
80
+    /**
81
+     * @return string
82
+     * @since 14.0.0
83
+     */
84
+    public function getLabel(): string {
85
+        return $this->label;
86
+    }
87 87
 
88
-	/**
89
-	 * @return string
90
-	 * @since 14.0.0
91
-	 */
92
-	public function getIcon(): string {
93
-		return $this->icon;
94
-	}
88
+    /**
89
+     * @return string
90
+     * @since 14.0.0
91
+     */
92
+    public function getIcon(): string {
93
+        return $this->icon;
94
+    }
95 95
 
96
-	/**
97
-	 * @return string
98
-	 * @since 14.0.0
99
-	 */
100
-	public function getLink(): string {
101
-		return $this->link;
102
-	}
96
+    /**
97
+     * @return string
98
+     * @since 14.0.0
99
+     */
100
+    public function getLink(): string {
101
+        return $this->link;
102
+    }
103 103
 
104
-	/**
105
-	 * @return int
106
-	 * @since 14.0.0
107
-	 */
108
-	public function getPriority(): int {
109
-		return $this->priority;
110
-	}
104
+    /**
105
+     * @return int
106
+     * @since 14.0.0
107
+     */
108
+    public function getPriority(): int {
109
+        return $this->priority;
110
+    }
111 111
 
112
-	/**
113
-	 * @return string
114
-	 * @since 14.0.0
115
-	 */
116
-	public function render(): string {
117
-		$detailContent = ($this->detail !== '') ? '&nbsp;<span class="download-size">(' . Util::sanitizeHTML($this->detail) . ')</span>' : '';
118
-		return sprintf(
119
-			'<li id="%s"><a href="%s"><span class="icon %s"></span>%s %s</a></li>',
120
-			Util::sanitizeHTML($this->id), Util::sanitizeHTML($this->link), Util::sanitizeHTML($this->icon), Util::sanitizeHTML($this->label), $detailContent
121
-		);
122
-	}
112
+    /**
113
+     * @return string
114
+     * @since 14.0.0
115
+     */
116
+    public function render(): string {
117
+        $detailContent = ($this->detail !== '') ? '&nbsp;<span class="download-size">(' . Util::sanitizeHTML($this->detail) . ')</span>' : '';
118
+        return sprintf(
119
+            '<li id="%s"><a href="%s"><span class="icon %s"></span>%s %s</a></li>',
120
+            Util::sanitizeHTML($this->id), Util::sanitizeHTML($this->link), Util::sanitizeHTML($this->icon), Util::sanitizeHTML($this->label), $detailContent
121
+        );
122
+    }
123 123
 }
Please login to merge, or discard this patch.
apps/comments/lib/Activity/Listener.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 
85 85
 		// Get all mount point owners
86 86
 		$cache = $this->mountCollection->getMountCache();
87
-		$mounts = $cache->getMountsForFileId((int)$event->getComment()->getObjectId());
87
+		$mounts = $cache->getMountsForFileId((int) $event->getComment()->getObjectId());
88 88
 		if (empty($mounts)) {
89 89
 			return;
90 90
 		}
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 		foreach ($mounts as $mount) {
94 94
 			$owner = $mount->getUser()->getUID();
95 95
 			$ownerFolder = $this->rootFolder->getUserFolder($owner);
96
-			$nodes = $ownerFolder->getById((int)$event->getComment()->getObjectId());
96
+			$nodes = $ownerFolder->getById((int) $event->getComment()->getObjectId());
97 97
 			if (!empty($nodes)) {
98 98
 				/** @var Node $node */
99 99
 				$node = array_shift($nodes);
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 		foreach ($users as $user => $path) {
122 122
 			// numerical user ids end up as integers from array keys, but string
123 123
 			// is required
124
-			$activity->setAffectedUser((string)$user);
124
+			$activity->setAffectedUser((string) $user);
125 125
 
126 126
 			$activity->setSubject('add_comment_subject', [
127 127
 				'actor' => $actor,
Please login to merge, or discard this patch.
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -35,88 +35,88 @@
 block discarded – undo
35 35
 use OCP\Share\IShareHelper;
36 36
 
37 37
 class Listener {
38
-	protected IManager $activityManager;
39
-	protected IUserSession $session;
40
-	protected IAppManager $appManager;
41
-	protected IMountProviderCollection $mountCollection;
42
-	protected IRootFolder $rootFolder;
43
-	protected IShareHelper $shareHelper;
38
+    protected IManager $activityManager;
39
+    protected IUserSession $session;
40
+    protected IAppManager $appManager;
41
+    protected IMountProviderCollection $mountCollection;
42
+    protected IRootFolder $rootFolder;
43
+    protected IShareHelper $shareHelper;
44 44
 
45
-	/**
46
-	 * Listener constructor.
47
-	 */
48
-	public function __construct(IManager $activityManager,
49
-								IUserSession $session,
50
-								IAppManager $appManager,
51
-								IMountProviderCollection $mountCollection,
52
-								IRootFolder $rootFolder,
53
-								IShareHelper $shareHelper) {
54
-		$this->activityManager = $activityManager;
55
-		$this->session = $session;
56
-		$this->appManager = $appManager;
57
-		$this->mountCollection = $mountCollection;
58
-		$this->rootFolder = $rootFolder;
59
-		$this->shareHelper = $shareHelper;
60
-	}
45
+    /**
46
+     * Listener constructor.
47
+     */
48
+    public function __construct(IManager $activityManager,
49
+                                IUserSession $session,
50
+                                IAppManager $appManager,
51
+                                IMountProviderCollection $mountCollection,
52
+                                IRootFolder $rootFolder,
53
+                                IShareHelper $shareHelper) {
54
+        $this->activityManager = $activityManager;
55
+        $this->session = $session;
56
+        $this->appManager = $appManager;
57
+        $this->mountCollection = $mountCollection;
58
+        $this->rootFolder = $rootFolder;
59
+        $this->shareHelper = $shareHelper;
60
+    }
61 61
 
62
-	/**
63
-	 * @param CommentsEvent $event
64
-	 */
65
-	public function commentEvent(CommentsEvent $event) {
66
-		if ($event->getComment()->getObjectType() !== 'files'
67
-			|| $event->getEvent() !== CommentsEvent::EVENT_ADD
68
-			|| !$this->appManager->isInstalled('activity')) {
69
-			// Comment not for file, not adding a comment or no activity-app enabled (save the energy)
70
-			return;
71
-		}
62
+    /**
63
+     * @param CommentsEvent $event
64
+     */
65
+    public function commentEvent(CommentsEvent $event) {
66
+        if ($event->getComment()->getObjectType() !== 'files'
67
+            || $event->getEvent() !== CommentsEvent::EVENT_ADD
68
+            || !$this->appManager->isInstalled('activity')) {
69
+            // Comment not for file, not adding a comment or no activity-app enabled (save the energy)
70
+            return;
71
+        }
72 72
 
73
-		// Get all mount point owners
74
-		$cache = $this->mountCollection->getMountCache();
75
-		$mounts = $cache->getMountsForFileId((int)$event->getComment()->getObjectId());
76
-		if (empty($mounts)) {
77
-			return;
78
-		}
73
+        // Get all mount point owners
74
+        $cache = $this->mountCollection->getMountCache();
75
+        $mounts = $cache->getMountsForFileId((int)$event->getComment()->getObjectId());
76
+        if (empty($mounts)) {
77
+            return;
78
+        }
79 79
 
80
-		$users = [];
81
-		foreach ($mounts as $mount) {
82
-			$owner = $mount->getUser()->getUID();
83
-			$ownerFolder = $this->rootFolder->getUserFolder($owner);
84
-			$nodes = $ownerFolder->getById((int)$event->getComment()->getObjectId());
85
-			if (!empty($nodes)) {
86
-				/** @var Node $node */
87
-				$node = array_shift($nodes);
88
-				$al = $this->shareHelper->getPathsForAccessList($node);
89
-				$users += $al['users'];
90
-			}
91
-		}
80
+        $users = [];
81
+        foreach ($mounts as $mount) {
82
+            $owner = $mount->getUser()->getUID();
83
+            $ownerFolder = $this->rootFolder->getUserFolder($owner);
84
+            $nodes = $ownerFolder->getById((int)$event->getComment()->getObjectId());
85
+            if (!empty($nodes)) {
86
+                /** @var Node $node */
87
+                $node = array_shift($nodes);
88
+                $al = $this->shareHelper->getPathsForAccessList($node);
89
+                $users += $al['users'];
90
+            }
91
+        }
92 92
 
93
-		$actor = $this->session->getUser();
94
-		if ($actor instanceof IUser) {
95
-			$actor = $actor->getUID();
96
-		} else {
97
-			$actor = '';
98
-		}
93
+        $actor = $this->session->getUser();
94
+        if ($actor instanceof IUser) {
95
+            $actor = $actor->getUID();
96
+        } else {
97
+            $actor = '';
98
+        }
99 99
 
100
-		$activity = $this->activityManager->generateEvent();
101
-		$activity->setApp('comments')
102
-			->setType('comments')
103
-			->setAuthor($actor)
104
-			->setObject($event->getComment()->getObjectType(), (int) $event->getComment()->getObjectId())
105
-			->setMessage('add_comment_message', [
106
-				'commentId' => $event->getComment()->getId(),
107
-			]);
100
+        $activity = $this->activityManager->generateEvent();
101
+        $activity->setApp('comments')
102
+            ->setType('comments')
103
+            ->setAuthor($actor)
104
+            ->setObject($event->getComment()->getObjectType(), (int) $event->getComment()->getObjectId())
105
+            ->setMessage('add_comment_message', [
106
+                'commentId' => $event->getComment()->getId(),
107
+            ]);
108 108
 
109
-		foreach ($users as $user => $path) {
110
-			// numerical user ids end up as integers from array keys, but string
111
-			// is required
112
-			$activity->setAffectedUser((string)$user);
109
+        foreach ($users as $user => $path) {
110
+            // numerical user ids end up as integers from array keys, but string
111
+            // is required
112
+            $activity->setAffectedUser((string)$user);
113 113
 
114
-			$activity->setSubject('add_comment_subject', [
115
-				'actor' => $actor,
116
-				'fileId' => (int) $event->getComment()->getObjectId(),
117
-				'filePath' => trim($path, '/'),
118
-			]);
119
-			$this->activityManager->publish($activity);
120
-		}
121
-	}
114
+            $activity->setSubject('add_comment_subject', [
115
+                'actor' => $actor,
116
+                'fileId' => (int) $event->getComment()->getObjectId(),
117
+                'filePath' => trim($path, '/'),
118
+            ]);
119
+            $this->activityManager->publish($activity);
120
+        }
121
+    }
122 122
 }
Please login to merge, or discard this patch.