Passed
Push — master ( bed972...c9ea23 )
by Joas
15:02 queued 16s
created
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   +454 added lines, -454 removed lines patch added patch discarded remove patch
@@ -49,458 +49,458 @@
 block discarded – undo
49 49
  */
50 50
 abstract class StoragesService {
51 51
 
52
-	/** @var BackendService */
53
-	protected $backendService;
54
-
55
-	/**
56
-	 * @var DBConfigService
57
-	 */
58
-	protected $dbConfig;
59
-
60
-	/**
61
-	 * @var IUserMountCache
62
-	 */
63
-	protected $userMountCache;
64
-
65
-	/**
66
-	 * @param BackendService $backendService
67
-	 * @param DBConfigService $dbConfigService
68
-	 * @param IUserMountCache $userMountCache
69
-	 */
70
-	public function __construct(BackendService $backendService, DBConfigService $dbConfigService, IUserMountCache $userMountCache) {
71
-		$this->backendService = $backendService;
72
-		$this->dbConfig = $dbConfigService;
73
-		$this->userMountCache = $userMountCache;
74
-	}
75
-
76
-	protected function readDBConfig() {
77
-		return $this->dbConfig->getAdminMounts();
78
-	}
79
-
80
-	protected function getStorageConfigFromDBMount(array $mount) {
81
-		$applicableUsers = array_filter($mount['applicable'], function ($applicable) {
82
-			return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_USER;
83
-		});
84
-		$applicableUsers = array_map(function ($applicable) {
85
-			return $applicable['value'];
86
-		}, $applicableUsers);
87
-
88
-		$applicableGroups = array_filter($mount['applicable'], function ($applicable) {
89
-			return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_GROUP;
90
-		});
91
-		$applicableGroups = array_map(function ($applicable) {
92
-			return $applicable['value'];
93
-		}, $applicableGroups);
94
-
95
-		try {
96
-			$config = $this->createStorage(
97
-				$mount['mount_point'],
98
-				$mount['storage_backend'],
99
-				$mount['auth_backend'],
100
-				$mount['config'],
101
-				$mount['options'],
102
-				array_values($applicableUsers),
103
-				array_values($applicableGroups),
104
-				$mount['priority']
105
-			);
106
-			$config->setType($mount['type']);
107
-			$config->setId((int)$mount['mount_id']);
108
-			return $config;
109
-		} catch (\UnexpectedValueException $e) {
110
-			// don't die if a storage backend doesn't exist
111
-			\OC::$server->getLogger()->logException($e, [
112
-				'message' => 'Could not load storage.',
113
-				'level' => ILogger::ERROR,
114
-				'app' => 'files_external',
115
-			]);
116
-			return null;
117
-		} catch (\InvalidArgumentException $e) {
118
-			\OC::$server->getLogger()->logException($e, [
119
-				'message' => 'Could not load storage.',
120
-				'level' => ILogger::ERROR,
121
-				'app' => 'files_external',
122
-			]);
123
-			return null;
124
-		}
125
-	}
126
-
127
-	/**
128
-	 * Read the external storage config
129
-	 *
130
-	 * @return array map of storage id to storage config
131
-	 */
132
-	protected function readConfig() {
133
-		$mounts = $this->readDBConfig();
134
-		$configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts);
135
-		$configs = array_filter($configs, function ($config) {
136
-			return $config instanceof StorageConfig;
137
-		});
138
-
139
-		$keys = array_map(function (StorageConfig $config) {
140
-			return $config->getId();
141
-		}, $configs);
142
-
143
-		return array_combine($keys, $configs);
144
-	}
145
-
146
-	/**
147
-	 * Get a storage with status
148
-	 *
149
-	 * @param int $id storage id
150
-	 *
151
-	 * @return StorageConfig
152
-	 * @throws NotFoundException if the storage with the given id was not found
153
-	 */
154
-	public function getStorage($id) {
155
-		$mount = $this->dbConfig->getMountById($id);
156
-
157
-		if (!is_array($mount)) {
158
-			throw new NotFoundException('Storage with ID "' . $id . '" not found');
159
-		}
160
-
161
-		$config = $this->getStorageConfigFromDBMount($mount);
162
-		if ($this->isApplicable($config)) {
163
-			return $config;
164
-		} else {
165
-			throw new NotFoundException('Storage with ID "' . $id . '" not found');
166
-		}
167
-	}
168
-
169
-	/**
170
-	 * Check whether this storage service should provide access to a storage
171
-	 *
172
-	 * @param StorageConfig $config
173
-	 * @return bool
174
-	 */
175
-	abstract protected function isApplicable(StorageConfig $config);
176
-
177
-	/**
178
-	 * Gets all storages, valid or not
179
-	 *
180
-	 * @return StorageConfig[] array of storage configs
181
-	 */
182
-	public function getAllStorages() {
183
-		return $this->readConfig();
184
-	}
185
-
186
-	/**
187
-	 * Gets all valid storages
188
-	 *
189
-	 * @return StorageConfig[]
190
-	 */
191
-	public function getStorages() {
192
-		return array_filter($this->getAllStorages(), [$this, 'validateStorage']);
193
-	}
194
-
195
-	/**
196
-	 * Validate storage
197
-	 * FIXME: De-duplicate with StoragesController::validate()
198
-	 *
199
-	 * @param StorageConfig $storage
200
-	 * @return bool
201
-	 */
202
-	protected function validateStorage(StorageConfig $storage) {
203
-		/** @var Backend */
204
-		$backend = $storage->getBackend();
205
-		/** @var AuthMechanism */
206
-		$authMechanism = $storage->getAuthMechanism();
207
-
208
-		if (!$backend->isVisibleFor($this->getVisibilityType())) {
209
-			// not permitted to use backend
210
-			return false;
211
-		}
212
-		if (!$authMechanism->isVisibleFor($this->getVisibilityType())) {
213
-			// not permitted to use auth mechanism
214
-			return false;
215
-		}
216
-
217
-		return true;
218
-	}
219
-
220
-	/**
221
-	 * Get the visibility type for this controller, used in validation
222
-	 *
223
-	 * @return string BackendService::VISIBILITY_* constants
224
-	 */
225
-	abstract public function getVisibilityType();
226
-
227
-	/**
228
-	 * @return integer
229
-	 */
230
-	protected function getType() {
231
-		return DBConfigService::MOUNT_TYPE_ADMIN;
232
-	}
233
-
234
-	/**
235
-	 * Add new storage to the configuration
236
-	 *
237
-	 * @param StorageConfig $newStorage storage attributes
238
-	 *
239
-	 * @return StorageConfig storage config, with added id
240
-	 */
241
-	public function addStorage(StorageConfig $newStorage) {
242
-		$allStorages = $this->readConfig();
243
-
244
-		$configId = $this->dbConfig->addMount(
245
-			$newStorage->getMountPoint(),
246
-			$newStorage->getBackend()->getIdentifier(),
247
-			$newStorage->getAuthMechanism()->getIdentifier(),
248
-			$newStorage->getPriority(),
249
-			$this->getType()
250
-		);
251
-
252
-		$newStorage->setId($configId);
253
-
254
-		foreach ($newStorage->getApplicableUsers() as $user) {
255
-			$this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_USER, $user);
256
-		}
257
-		foreach ($newStorage->getApplicableGroups() as $group) {
258
-			$this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
259
-		}
260
-		foreach ($newStorage->getBackendOptions() as $key => $value) {
261
-			$this->dbConfig->setConfig($configId, $key, $value);
262
-		}
263
-		foreach ($newStorage->getMountOptions() as $key => $value) {
264
-			$this->dbConfig->setOption($configId, $key, $value);
265
-		}
266
-
267
-		if (count($newStorage->getApplicableUsers()) === 0 && count($newStorage->getApplicableGroups()) === 0) {
268
-			$this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
269
-		}
270
-
271
-		// add new storage
272
-		$allStorages[$configId] = $newStorage;
273
-
274
-		$this->triggerHooks($newStorage, Filesystem::signal_create_mount);
275
-
276
-		$newStorage->setStatus(StorageNotAvailableException::STATUS_SUCCESS);
277
-		return $newStorage;
278
-	}
279
-
280
-	/**
281
-	 * Create a storage from its parameters
282
-	 *
283
-	 * @param string $mountPoint storage mount point
284
-	 * @param string $backendIdentifier backend identifier
285
-	 * @param string $authMechanismIdentifier authentication mechanism identifier
286
-	 * @param array $backendOptions backend-specific options
287
-	 * @param array|null $mountOptions mount-specific options
288
-	 * @param array|null $applicableUsers users for which to mount the storage
289
-	 * @param array|null $applicableGroups groups for which to mount the storage
290
-	 * @param int|null $priority priority
291
-	 *
292
-	 * @return StorageConfig
293
-	 */
294
-	public function createStorage(
295
-		$mountPoint,
296
-		$backendIdentifier,
297
-		$authMechanismIdentifier,
298
-		$backendOptions,
299
-		$mountOptions = null,
300
-		$applicableUsers = null,
301
-		$applicableGroups = null,
302
-		$priority = null
303
-	) {
304
-		$backend = $this->backendService->getBackend($backendIdentifier);
305
-		if (!$backend) {
306
-			$backend = new InvalidBackend($backendIdentifier);
307
-		}
308
-		$authMechanism = $this->backendService->getAuthMechanism($authMechanismIdentifier);
309
-		if (!$authMechanism) {
310
-			$authMechanism = new InvalidAuth($authMechanismIdentifier);
311
-		}
312
-		$newStorage = new StorageConfig();
313
-		$newStorage->setMountPoint($mountPoint);
314
-		$newStorage->setBackend($backend);
315
-		$newStorage->setAuthMechanism($authMechanism);
316
-		$newStorage->setBackendOptions($backendOptions);
317
-		if (isset($mountOptions)) {
318
-			$newStorage->setMountOptions($mountOptions);
319
-		}
320
-		if (isset($applicableUsers)) {
321
-			$newStorage->setApplicableUsers($applicableUsers);
322
-		}
323
-		if (isset($applicableGroups)) {
324
-			$newStorage->setApplicableGroups($applicableGroups);
325
-		}
326
-		if (isset($priority)) {
327
-			$newStorage->setPriority($priority);
328
-		}
329
-
330
-		return $newStorage;
331
-	}
332
-
333
-	/**
334
-	 * Triggers the given hook signal for all the applicables given
335
-	 *
336
-	 * @param string $signal signal
337
-	 * @param string $mountPoint hook mount pount param
338
-	 * @param string $mountType hook mount type param
339
-	 * @param array $applicableArray array of applicable users/groups for which to trigger the hook
340
-	 */
341
-	protected function triggerApplicableHooks($signal, $mountPoint, $mountType, $applicableArray) {
342
-		foreach ($applicableArray as $applicable) {
343
-			\OCP\Util::emitHook(
344
-				Filesystem::CLASSNAME,
345
-				$signal,
346
-				[
347
-					Filesystem::signal_param_path => $mountPoint,
348
-					Filesystem::signal_param_mount_type => $mountType,
349
-					Filesystem::signal_param_users => $applicable,
350
-				]
351
-			);
352
-		}
353
-	}
354
-
355
-	/**
356
-	 * Triggers $signal for all applicable users of the given
357
-	 * storage
358
-	 *
359
-	 * @param StorageConfig $storage storage data
360
-	 * @param string $signal signal to trigger
361
-	 */
362
-	abstract protected function triggerHooks(StorageConfig $storage, $signal);
363
-
364
-	/**
365
-	 * Triggers signal_create_mount or signal_delete_mount to
366
-	 * accommodate for additions/deletions in applicableUsers
367
-	 * and applicableGroups fields.
368
-	 *
369
-	 * @param StorageConfig $oldStorage old storage data
370
-	 * @param StorageConfig $newStorage new storage data
371
-	 */
372
-	abstract protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage);
373
-
374
-	/**
375
-	 * Update storage to the configuration
376
-	 *
377
-	 * @param StorageConfig $updatedStorage storage attributes
378
-	 *
379
-	 * @return StorageConfig storage config
380
-	 * @throws NotFoundException if the given storage does not exist in the config
381
-	 */
382
-	public function updateStorage(StorageConfig $updatedStorage) {
383
-		$id = $updatedStorage->getId();
384
-
385
-		$existingMount = $this->dbConfig->getMountById($id);
386
-
387
-		if (!is_array($existingMount)) {
388
-			throw new NotFoundException('Storage with ID "' . $id . '" not found while updating storage');
389
-		}
390
-
391
-		$oldStorage = $this->getStorageConfigFromDBMount($existingMount);
392
-
393
-		if ($oldStorage->getBackend() instanceof InvalidBackend) {
394
-			throw new NotFoundException('Storage with id "' . $id . '" cannot be edited due to missing backend');
395
-		}
396
-
397
-		$removedUsers = array_diff($oldStorage->getApplicableUsers(), $updatedStorage->getApplicableUsers());
398
-		$removedGroups = array_diff($oldStorage->getApplicableGroups(), $updatedStorage->getApplicableGroups());
399
-		$addedUsers = array_diff($updatedStorage->getApplicableUsers(), $oldStorage->getApplicableUsers());
400
-		$addedGroups = array_diff($updatedStorage->getApplicableGroups(), $oldStorage->getApplicableGroups());
401
-
402
-		$oldUserCount = count($oldStorage->getApplicableUsers());
403
-		$oldGroupCount = count($oldStorage->getApplicableGroups());
404
-		$newUserCount = count($updatedStorage->getApplicableUsers());
405
-		$newGroupCount = count($updatedStorage->getApplicableGroups());
406
-		$wasGlobal = ($oldUserCount + $oldGroupCount) === 0;
407
-		$isGlobal = ($newUserCount + $newGroupCount) === 0;
408
-
409
-		foreach ($removedUsers as $user) {
410
-			$this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user);
411
-		}
412
-		foreach ($removedGroups as $group) {
413
-			$this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
414
-		}
415
-		foreach ($addedUsers as $user) {
416
-			$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user);
417
-		}
418
-		foreach ($addedGroups as $group) {
419
-			$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
420
-		}
421
-
422
-		if ($wasGlobal && !$isGlobal) {
423
-			$this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
424
-		} elseif (!$wasGlobal && $isGlobal) {
425
-			$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
426
-		}
427
-
428
-		$changedConfig = array_diff_assoc($updatedStorage->getBackendOptions(), $oldStorage->getBackendOptions());
429
-		$changedOptions = array_diff_assoc($updatedStorage->getMountOptions(), $oldStorage->getMountOptions());
430
-
431
-		foreach ($changedConfig as $key => $value) {
432
-			if ($value !== DefinitionParameter::UNMODIFIED_PLACEHOLDER) {
433
-				$this->dbConfig->setConfig($id, $key, $value);
434
-			}
435
-		}
436
-		foreach ($changedOptions as $key => $value) {
437
-			$this->dbConfig->setOption($id, $key, $value);
438
-		}
439
-
440
-		if ($updatedStorage->getMountPoint() !== $oldStorage->getMountPoint()) {
441
-			$this->dbConfig->setMountPoint($id, $updatedStorage->getMountPoint());
442
-		}
443
-
444
-		if ($updatedStorage->getAuthMechanism()->getIdentifier() !== $oldStorage->getAuthMechanism()->getIdentifier()) {
445
-			$this->dbConfig->setAuthBackend($id, $updatedStorage->getAuthMechanism()->getIdentifier());
446
-		}
447
-
448
-		$this->triggerChangeHooks($oldStorage, $updatedStorage);
449
-
450
-		if (($wasGlobal && !$isGlobal) || count($removedGroups) > 0) { // to expensive to properly handle these on the fly
451
-			$this->userMountCache->remoteStorageMounts($this->getStorageId($updatedStorage));
452
-		} else {
453
-			$storageId = $this->getStorageId($updatedStorage);
454
-			foreach ($removedUsers as $userId) {
455
-				$this->userMountCache->removeUserStorageMount($storageId, $userId);
456
-			}
457
-		}
458
-
459
-		return $this->getStorage($id);
460
-	}
461
-
462
-	/**
463
-	 * Delete the storage with the given id.
464
-	 *
465
-	 * @param int $id storage id
466
-	 *
467
-	 * @throws NotFoundException if no storage was found with the given id
468
-	 */
469
-	public function removeStorage($id) {
470
-		$existingMount = $this->dbConfig->getMountById($id);
471
-
472
-		if (!is_array($existingMount)) {
473
-			throw new NotFoundException('Storage with ID "' . $id . '" not found');
474
-		}
475
-
476
-		$this->dbConfig->removeMount($id);
477
-
478
-		$deletedStorage = $this->getStorageConfigFromDBMount($existingMount);
479
-		$this->triggerHooks($deletedStorage, Filesystem::signal_delete_mount);
480
-
481
-		// delete oc_storages entries and oc_filecache
482
-		\OC\Files\Cache\Storage::cleanByMountId($id);
483
-	}
484
-
485
-	/**
486
-	 * Construct the storage implementation
487
-	 *
488
-	 * @param StorageConfig $storageConfig
489
-	 * @return int
490
-	 */
491
-	private function getStorageId(StorageConfig $storageConfig) {
492
-		try {
493
-			$class = $storageConfig->getBackend()->getStorageClass();
494
-			/** @var \OC\Files\Storage\Storage $storage */
495
-			$storage = new $class($storageConfig->getBackendOptions());
496
-
497
-			// auth mechanism should fire first
498
-			$storage = $storageConfig->getBackend()->wrapStorage($storage);
499
-			$storage = $storageConfig->getAuthMechanism()->wrapStorage($storage);
500
-
501
-			return $storage->getStorageCache()->getNumericId();
502
-		} catch (\Exception $e) {
503
-			return -1;
504
-		}
505
-	}
52
+    /** @var BackendService */
53
+    protected $backendService;
54
+
55
+    /**
56
+     * @var DBConfigService
57
+     */
58
+    protected $dbConfig;
59
+
60
+    /**
61
+     * @var IUserMountCache
62
+     */
63
+    protected $userMountCache;
64
+
65
+    /**
66
+     * @param BackendService $backendService
67
+     * @param DBConfigService $dbConfigService
68
+     * @param IUserMountCache $userMountCache
69
+     */
70
+    public function __construct(BackendService $backendService, DBConfigService $dbConfigService, IUserMountCache $userMountCache) {
71
+        $this->backendService = $backendService;
72
+        $this->dbConfig = $dbConfigService;
73
+        $this->userMountCache = $userMountCache;
74
+    }
75
+
76
+    protected function readDBConfig() {
77
+        return $this->dbConfig->getAdminMounts();
78
+    }
79
+
80
+    protected function getStorageConfigFromDBMount(array $mount) {
81
+        $applicableUsers = array_filter($mount['applicable'], function ($applicable) {
82
+            return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_USER;
83
+        });
84
+        $applicableUsers = array_map(function ($applicable) {
85
+            return $applicable['value'];
86
+        }, $applicableUsers);
87
+
88
+        $applicableGroups = array_filter($mount['applicable'], function ($applicable) {
89
+            return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_GROUP;
90
+        });
91
+        $applicableGroups = array_map(function ($applicable) {
92
+            return $applicable['value'];
93
+        }, $applicableGroups);
94
+
95
+        try {
96
+            $config = $this->createStorage(
97
+                $mount['mount_point'],
98
+                $mount['storage_backend'],
99
+                $mount['auth_backend'],
100
+                $mount['config'],
101
+                $mount['options'],
102
+                array_values($applicableUsers),
103
+                array_values($applicableGroups),
104
+                $mount['priority']
105
+            );
106
+            $config->setType($mount['type']);
107
+            $config->setId((int)$mount['mount_id']);
108
+            return $config;
109
+        } catch (\UnexpectedValueException $e) {
110
+            // don't die if a storage backend doesn't exist
111
+            \OC::$server->getLogger()->logException($e, [
112
+                'message' => 'Could not load storage.',
113
+                'level' => ILogger::ERROR,
114
+                'app' => 'files_external',
115
+            ]);
116
+            return null;
117
+        } catch (\InvalidArgumentException $e) {
118
+            \OC::$server->getLogger()->logException($e, [
119
+                'message' => 'Could not load storage.',
120
+                'level' => ILogger::ERROR,
121
+                'app' => 'files_external',
122
+            ]);
123
+            return null;
124
+        }
125
+    }
126
+
127
+    /**
128
+     * Read the external storage config
129
+     *
130
+     * @return array map of storage id to storage config
131
+     */
132
+    protected function readConfig() {
133
+        $mounts = $this->readDBConfig();
134
+        $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts);
135
+        $configs = array_filter($configs, function ($config) {
136
+            return $config instanceof StorageConfig;
137
+        });
138
+
139
+        $keys = array_map(function (StorageConfig $config) {
140
+            return $config->getId();
141
+        }, $configs);
142
+
143
+        return array_combine($keys, $configs);
144
+    }
145
+
146
+    /**
147
+     * Get a storage with status
148
+     *
149
+     * @param int $id storage id
150
+     *
151
+     * @return StorageConfig
152
+     * @throws NotFoundException if the storage with the given id was not found
153
+     */
154
+    public function getStorage($id) {
155
+        $mount = $this->dbConfig->getMountById($id);
156
+
157
+        if (!is_array($mount)) {
158
+            throw new NotFoundException('Storage with ID "' . $id . '" not found');
159
+        }
160
+
161
+        $config = $this->getStorageConfigFromDBMount($mount);
162
+        if ($this->isApplicable($config)) {
163
+            return $config;
164
+        } else {
165
+            throw new NotFoundException('Storage with ID "' . $id . '" not found');
166
+        }
167
+    }
168
+
169
+    /**
170
+     * Check whether this storage service should provide access to a storage
171
+     *
172
+     * @param StorageConfig $config
173
+     * @return bool
174
+     */
175
+    abstract protected function isApplicable(StorageConfig $config);
176
+
177
+    /**
178
+     * Gets all storages, valid or not
179
+     *
180
+     * @return StorageConfig[] array of storage configs
181
+     */
182
+    public function getAllStorages() {
183
+        return $this->readConfig();
184
+    }
185
+
186
+    /**
187
+     * Gets all valid storages
188
+     *
189
+     * @return StorageConfig[]
190
+     */
191
+    public function getStorages() {
192
+        return array_filter($this->getAllStorages(), [$this, 'validateStorage']);
193
+    }
194
+
195
+    /**
196
+     * Validate storage
197
+     * FIXME: De-duplicate with StoragesController::validate()
198
+     *
199
+     * @param StorageConfig $storage
200
+     * @return bool
201
+     */
202
+    protected function validateStorage(StorageConfig $storage) {
203
+        /** @var Backend */
204
+        $backend = $storage->getBackend();
205
+        /** @var AuthMechanism */
206
+        $authMechanism = $storage->getAuthMechanism();
207
+
208
+        if (!$backend->isVisibleFor($this->getVisibilityType())) {
209
+            // not permitted to use backend
210
+            return false;
211
+        }
212
+        if (!$authMechanism->isVisibleFor($this->getVisibilityType())) {
213
+            // not permitted to use auth mechanism
214
+            return false;
215
+        }
216
+
217
+        return true;
218
+    }
219
+
220
+    /**
221
+     * Get the visibility type for this controller, used in validation
222
+     *
223
+     * @return string BackendService::VISIBILITY_* constants
224
+     */
225
+    abstract public function getVisibilityType();
226
+
227
+    /**
228
+     * @return integer
229
+     */
230
+    protected function getType() {
231
+        return DBConfigService::MOUNT_TYPE_ADMIN;
232
+    }
233
+
234
+    /**
235
+     * Add new storage to the configuration
236
+     *
237
+     * @param StorageConfig $newStorage storage attributes
238
+     *
239
+     * @return StorageConfig storage config, with added id
240
+     */
241
+    public function addStorage(StorageConfig $newStorage) {
242
+        $allStorages = $this->readConfig();
243
+
244
+        $configId = $this->dbConfig->addMount(
245
+            $newStorage->getMountPoint(),
246
+            $newStorage->getBackend()->getIdentifier(),
247
+            $newStorage->getAuthMechanism()->getIdentifier(),
248
+            $newStorage->getPriority(),
249
+            $this->getType()
250
+        );
251
+
252
+        $newStorage->setId($configId);
253
+
254
+        foreach ($newStorage->getApplicableUsers() as $user) {
255
+            $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_USER, $user);
256
+        }
257
+        foreach ($newStorage->getApplicableGroups() as $group) {
258
+            $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
259
+        }
260
+        foreach ($newStorage->getBackendOptions() as $key => $value) {
261
+            $this->dbConfig->setConfig($configId, $key, $value);
262
+        }
263
+        foreach ($newStorage->getMountOptions() as $key => $value) {
264
+            $this->dbConfig->setOption($configId, $key, $value);
265
+        }
266
+
267
+        if (count($newStorage->getApplicableUsers()) === 0 && count($newStorage->getApplicableGroups()) === 0) {
268
+            $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
269
+        }
270
+
271
+        // add new storage
272
+        $allStorages[$configId] = $newStorage;
273
+
274
+        $this->triggerHooks($newStorage, Filesystem::signal_create_mount);
275
+
276
+        $newStorage->setStatus(StorageNotAvailableException::STATUS_SUCCESS);
277
+        return $newStorage;
278
+    }
279
+
280
+    /**
281
+     * Create a storage from its parameters
282
+     *
283
+     * @param string $mountPoint storage mount point
284
+     * @param string $backendIdentifier backend identifier
285
+     * @param string $authMechanismIdentifier authentication mechanism identifier
286
+     * @param array $backendOptions backend-specific options
287
+     * @param array|null $mountOptions mount-specific options
288
+     * @param array|null $applicableUsers users for which to mount the storage
289
+     * @param array|null $applicableGroups groups for which to mount the storage
290
+     * @param int|null $priority priority
291
+     *
292
+     * @return StorageConfig
293
+     */
294
+    public function createStorage(
295
+        $mountPoint,
296
+        $backendIdentifier,
297
+        $authMechanismIdentifier,
298
+        $backendOptions,
299
+        $mountOptions = null,
300
+        $applicableUsers = null,
301
+        $applicableGroups = null,
302
+        $priority = null
303
+    ) {
304
+        $backend = $this->backendService->getBackend($backendIdentifier);
305
+        if (!$backend) {
306
+            $backend = new InvalidBackend($backendIdentifier);
307
+        }
308
+        $authMechanism = $this->backendService->getAuthMechanism($authMechanismIdentifier);
309
+        if (!$authMechanism) {
310
+            $authMechanism = new InvalidAuth($authMechanismIdentifier);
311
+        }
312
+        $newStorage = new StorageConfig();
313
+        $newStorage->setMountPoint($mountPoint);
314
+        $newStorage->setBackend($backend);
315
+        $newStorage->setAuthMechanism($authMechanism);
316
+        $newStorage->setBackendOptions($backendOptions);
317
+        if (isset($mountOptions)) {
318
+            $newStorage->setMountOptions($mountOptions);
319
+        }
320
+        if (isset($applicableUsers)) {
321
+            $newStorage->setApplicableUsers($applicableUsers);
322
+        }
323
+        if (isset($applicableGroups)) {
324
+            $newStorage->setApplicableGroups($applicableGroups);
325
+        }
326
+        if (isset($priority)) {
327
+            $newStorage->setPriority($priority);
328
+        }
329
+
330
+        return $newStorage;
331
+    }
332
+
333
+    /**
334
+     * Triggers the given hook signal for all the applicables given
335
+     *
336
+     * @param string $signal signal
337
+     * @param string $mountPoint hook mount pount param
338
+     * @param string $mountType hook mount type param
339
+     * @param array $applicableArray array of applicable users/groups for which to trigger the hook
340
+     */
341
+    protected function triggerApplicableHooks($signal, $mountPoint, $mountType, $applicableArray) {
342
+        foreach ($applicableArray as $applicable) {
343
+            \OCP\Util::emitHook(
344
+                Filesystem::CLASSNAME,
345
+                $signal,
346
+                [
347
+                    Filesystem::signal_param_path => $mountPoint,
348
+                    Filesystem::signal_param_mount_type => $mountType,
349
+                    Filesystem::signal_param_users => $applicable,
350
+                ]
351
+            );
352
+        }
353
+    }
354
+
355
+    /**
356
+     * Triggers $signal for all applicable users of the given
357
+     * storage
358
+     *
359
+     * @param StorageConfig $storage storage data
360
+     * @param string $signal signal to trigger
361
+     */
362
+    abstract protected function triggerHooks(StorageConfig $storage, $signal);
363
+
364
+    /**
365
+     * Triggers signal_create_mount or signal_delete_mount to
366
+     * accommodate for additions/deletions in applicableUsers
367
+     * and applicableGroups fields.
368
+     *
369
+     * @param StorageConfig $oldStorage old storage data
370
+     * @param StorageConfig $newStorage new storage data
371
+     */
372
+    abstract protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage);
373
+
374
+    /**
375
+     * Update storage to the configuration
376
+     *
377
+     * @param StorageConfig $updatedStorage storage attributes
378
+     *
379
+     * @return StorageConfig storage config
380
+     * @throws NotFoundException if the given storage does not exist in the config
381
+     */
382
+    public function updateStorage(StorageConfig $updatedStorage) {
383
+        $id = $updatedStorage->getId();
384
+
385
+        $existingMount = $this->dbConfig->getMountById($id);
386
+
387
+        if (!is_array($existingMount)) {
388
+            throw new NotFoundException('Storage with ID "' . $id . '" not found while updating storage');
389
+        }
390
+
391
+        $oldStorage = $this->getStorageConfigFromDBMount($existingMount);
392
+
393
+        if ($oldStorage->getBackend() instanceof InvalidBackend) {
394
+            throw new NotFoundException('Storage with id "' . $id . '" cannot be edited due to missing backend');
395
+        }
396
+
397
+        $removedUsers = array_diff($oldStorage->getApplicableUsers(), $updatedStorage->getApplicableUsers());
398
+        $removedGroups = array_diff($oldStorage->getApplicableGroups(), $updatedStorage->getApplicableGroups());
399
+        $addedUsers = array_diff($updatedStorage->getApplicableUsers(), $oldStorage->getApplicableUsers());
400
+        $addedGroups = array_diff($updatedStorage->getApplicableGroups(), $oldStorage->getApplicableGroups());
401
+
402
+        $oldUserCount = count($oldStorage->getApplicableUsers());
403
+        $oldGroupCount = count($oldStorage->getApplicableGroups());
404
+        $newUserCount = count($updatedStorage->getApplicableUsers());
405
+        $newGroupCount = count($updatedStorage->getApplicableGroups());
406
+        $wasGlobal = ($oldUserCount + $oldGroupCount) === 0;
407
+        $isGlobal = ($newUserCount + $newGroupCount) === 0;
408
+
409
+        foreach ($removedUsers as $user) {
410
+            $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user);
411
+        }
412
+        foreach ($removedGroups as $group) {
413
+            $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
414
+        }
415
+        foreach ($addedUsers as $user) {
416
+            $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user);
417
+        }
418
+        foreach ($addedGroups as $group) {
419
+            $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
420
+        }
421
+
422
+        if ($wasGlobal && !$isGlobal) {
423
+            $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
424
+        } elseif (!$wasGlobal && $isGlobal) {
425
+            $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
426
+        }
427
+
428
+        $changedConfig = array_diff_assoc($updatedStorage->getBackendOptions(), $oldStorage->getBackendOptions());
429
+        $changedOptions = array_diff_assoc($updatedStorage->getMountOptions(), $oldStorage->getMountOptions());
430
+
431
+        foreach ($changedConfig as $key => $value) {
432
+            if ($value !== DefinitionParameter::UNMODIFIED_PLACEHOLDER) {
433
+                $this->dbConfig->setConfig($id, $key, $value);
434
+            }
435
+        }
436
+        foreach ($changedOptions as $key => $value) {
437
+            $this->dbConfig->setOption($id, $key, $value);
438
+        }
439
+
440
+        if ($updatedStorage->getMountPoint() !== $oldStorage->getMountPoint()) {
441
+            $this->dbConfig->setMountPoint($id, $updatedStorage->getMountPoint());
442
+        }
443
+
444
+        if ($updatedStorage->getAuthMechanism()->getIdentifier() !== $oldStorage->getAuthMechanism()->getIdentifier()) {
445
+            $this->dbConfig->setAuthBackend($id, $updatedStorage->getAuthMechanism()->getIdentifier());
446
+        }
447
+
448
+        $this->triggerChangeHooks($oldStorage, $updatedStorage);
449
+
450
+        if (($wasGlobal && !$isGlobal) || count($removedGroups) > 0) { // to expensive to properly handle these on the fly
451
+            $this->userMountCache->remoteStorageMounts($this->getStorageId($updatedStorage));
452
+        } else {
453
+            $storageId = $this->getStorageId($updatedStorage);
454
+            foreach ($removedUsers as $userId) {
455
+                $this->userMountCache->removeUserStorageMount($storageId, $userId);
456
+            }
457
+        }
458
+
459
+        return $this->getStorage($id);
460
+    }
461
+
462
+    /**
463
+     * Delete the storage with the given id.
464
+     *
465
+     * @param int $id storage id
466
+     *
467
+     * @throws NotFoundException if no storage was found with the given id
468
+     */
469
+    public function removeStorage($id) {
470
+        $existingMount = $this->dbConfig->getMountById($id);
471
+
472
+        if (!is_array($existingMount)) {
473
+            throw new NotFoundException('Storage with ID "' . $id . '" not found');
474
+        }
475
+
476
+        $this->dbConfig->removeMount($id);
477
+
478
+        $deletedStorage = $this->getStorageConfigFromDBMount($existingMount);
479
+        $this->triggerHooks($deletedStorage, Filesystem::signal_delete_mount);
480
+
481
+        // delete oc_storages entries and oc_filecache
482
+        \OC\Files\Cache\Storage::cleanByMountId($id);
483
+    }
484
+
485
+    /**
486
+     * Construct the storage implementation
487
+     *
488
+     * @param StorageConfig $storageConfig
489
+     * @return int
490
+     */
491
+    private function getStorageId(StorageConfig $storageConfig) {
492
+        try {
493
+            $class = $storageConfig->getBackend()->getStorageClass();
494
+            /** @var \OC\Files\Storage\Storage $storage */
495
+            $storage = new $class($storageConfig->getBackendOptions());
496
+
497
+            // auth mechanism should fire first
498
+            $storage = $storageConfig->getBackend()->wrapStorage($storage);
499
+            $storage = $storageConfig->getAuthMechanism()->wrapStorage($storage);
500
+
501
+            return $storage->getStorageCache()->getNumericId();
502
+        } catch (\Exception $e) {
503
+            return -1;
504
+        }
505
+    }
506 506
 }
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.
apps/files/lib/App.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -28,40 +28,40 @@
 block discarded – undo
28 28
 namespace OCA\Files;
29 29
 
30 30
 class App {
31
-	/**
32
-	 * @var \OCP\INavigationManager
33
-	 */
34
-	private static $navigationManager;
31
+    /**
32
+     * @var \OCP\INavigationManager
33
+     */
34
+    private static $navigationManager;
35 35
 
36
-	/**
37
-	 * Returns the app's navigation manager
38
-	 *
39
-	 * @return \OCP\INavigationManager
40
-	 */
41
-	public static function getNavigationManager() {
42
-		// TODO: move this into a service in the Application class
43
-		if (self::$navigationManager === null) {
44
-			self::$navigationManager = new \OC\NavigationManager(
45
-				\OC::$server->getAppManager(),
46
-				\OC::$server->getURLGenerator(),
47
-				\OC::$server->getL10NFactory(),
48
-				\OC::$server->getUserSession(),
49
-				\OC::$server->getGroupManager(),
50
-				\OC::$server->getConfig()
51
-			);
52
-			self::$navigationManager->clear(false);
53
-		}
54
-		return self::$navigationManager;
55
-	}
36
+    /**
37
+     * Returns the app's navigation manager
38
+     *
39
+     * @return \OCP\INavigationManager
40
+     */
41
+    public static function getNavigationManager() {
42
+        // TODO: move this into a service in the Application class
43
+        if (self::$navigationManager === null) {
44
+            self::$navigationManager = new \OC\NavigationManager(
45
+                \OC::$server->getAppManager(),
46
+                \OC::$server->getURLGenerator(),
47
+                \OC::$server->getL10NFactory(),
48
+                \OC::$server->getUserSession(),
49
+                \OC::$server->getGroupManager(),
50
+                \OC::$server->getConfig()
51
+            );
52
+            self::$navigationManager->clear(false);
53
+        }
54
+        return self::$navigationManager;
55
+    }
56 56
 
57
-	public static function extendJsConfig($settings) {
58
-		$appConfig = json_decode($settings['array']['oc_appconfig'], true);
57
+    public static function extendJsConfig($settings) {
58
+        $appConfig = json_decode($settings['array']['oc_appconfig'], true);
59 59
 
60
-		$maxChunkSize = (int)\OC::$server->getConfig()->getAppValue('files', 'max_chunk_size', 10 * 1024 * 1024);
61
-		$appConfig['files'] = [
62
-			'max_chunk_size' => $maxChunkSize
63
-		];
60
+        $maxChunkSize = (int)\OC::$server->getConfig()->getAppValue('files', 'max_chunk_size', 10 * 1024 * 1024);
61
+        $appConfig['files'] = [
62
+            'max_chunk_size' => $maxChunkSize
63
+        ];
64 64
 
65
-		$settings['array']['oc_appconfig'] = json_encode($appConfig);
66
-	}
65
+        $settings['array']['oc_appconfig'] = json_encode($appConfig);
66
+    }
67 67
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@
 block discarded – undo
57 57
 	public static function extendJsConfig($settings) {
58 58
 		$appConfig = json_decode($settings['array']['oc_appconfig'], true);
59 59
 
60
-		$maxChunkSize = (int)\OC::$server->getConfig()->getAppValue('files', 'max_chunk_size', 10 * 1024 * 1024);
60
+		$maxChunkSize = (int) \OC::$server->getConfig()->getAppValue('files', 'max_chunk_size', 10 * 1024 * 1024);
61 61
 		$appConfig['files'] = [
62 62
 			'max_chunk_size' => $maxChunkSize
63 63
 		];
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/Auth/PublicKey/RSA.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -36,51 +36,51 @@
 block discarded – undo
36 36
  */
37 37
 class RSA extends AuthMechanism {
38 38
 
39
-	/** @var IConfig */
40
-	private $config;
39
+    /** @var IConfig */
40
+    private $config;
41 41
 
42
-	public function __construct(IL10N $l, IConfig $config) {
43
-		$this->config = $config;
42
+    public function __construct(IL10N $l, IConfig $config) {
43
+        $this->config = $config;
44 44
 
45
-		$this
46
-			->setIdentifier('publickey::rsa')
47
-			->setScheme(self::SCHEME_PUBLICKEY)
48
-			->setText($l->t('RSA public key'))
49
-			->addParameters([
50
-				new DefinitionParameter('user', $l->t('Username')),
51
-				new DefinitionParameter('public_key', $l->t('Public key')),
52
-				(new DefinitionParameter('private_key', 'private_key'))
53
-					->setType(DefinitionParameter::VALUE_HIDDEN),
54
-			])
55
-			->addCustomJs('public_key')
56
-		;
57
-	}
45
+        $this
46
+            ->setIdentifier('publickey::rsa')
47
+            ->setScheme(self::SCHEME_PUBLICKEY)
48
+            ->setText($l->t('RSA public key'))
49
+            ->addParameters([
50
+                new DefinitionParameter('user', $l->t('Username')),
51
+                new DefinitionParameter('public_key', $l->t('Public key')),
52
+                (new DefinitionParameter('private_key', 'private_key'))
53
+                    ->setType(DefinitionParameter::VALUE_HIDDEN),
54
+            ])
55
+            ->addCustomJs('public_key')
56
+        ;
57
+    }
58 58
 
59
-	public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
60
-		$auth = new RSACrypt();
61
-		$auth->setPassword($this->config->getSystemValue('secret', ''));
62
-		if (!$auth->loadKey($storage->getBackendOption('private_key'))) {
63
-			throw new \RuntimeException('unable to load private key');
64
-		}
65
-		$storage->setBackendOption('public_key_auth', $auth);
66
-	}
59
+    public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
60
+        $auth = new RSACrypt();
61
+        $auth->setPassword($this->config->getSystemValue('secret', ''));
62
+        if (!$auth->loadKey($storage->getBackendOption('private_key'))) {
63
+            throw new \RuntimeException('unable to load private key');
64
+        }
65
+        $storage->setBackendOption('public_key_auth', $auth);
66
+    }
67 67
 
68
-	/**
69
-	 * Generate a keypair
70
-	 *
71
-	 * @param int $keyLenth
72
-	 * @return array ['privatekey' => $privateKey, 'publickey' => $publicKey]
73
-	 */
74
-	public function createKey($keyLength) {
75
-		$rsa = new RSACrypt();
76
-		$rsa->setPublicKeyFormat(RSACrypt::PUBLIC_FORMAT_OPENSSH);
77
-		$rsa->setPassword($this->config->getSystemValue('secret', ''));
68
+    /**
69
+     * Generate a keypair
70
+     *
71
+     * @param int $keyLenth
72
+     * @return array ['privatekey' => $privateKey, 'publickey' => $publicKey]
73
+     */
74
+    public function createKey($keyLength) {
75
+        $rsa = new RSACrypt();
76
+        $rsa->setPublicKeyFormat(RSACrypt::PUBLIC_FORMAT_OPENSSH);
77
+        $rsa->setPassword($this->config->getSystemValue('secret', ''));
78 78
 
79
-		if ($keyLength !== 1024 && $keyLength !== 2048 && $keyLength !== 4096) {
80
-			$keyLength = 1024;
81
-		}
79
+        if ($keyLength !== 1024 && $keyLength !== 2048 && $keyLength !== 4096) {
80
+            $keyLength = 1024;
81
+        }
82 82
 
83
-		return $rsa->createKey($keyLength);
84
-	}
83
+        return $rsa->createKey($keyLength);
84
+    }
85 85
 
86 86
 }
Please login to merge, or discard this patch.
lib/private/Repair/ClearFrontendCaches.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -31,40 +31,40 @@
 block discarded – undo
31 31
 
32 32
 class ClearFrontendCaches implements IRepairStep {
33 33
 
34
-	/** @var ICacheFactory */
35
-	protected $cacheFactory;
34
+    /** @var ICacheFactory */
35
+    protected $cacheFactory;
36 36
 
37
-	/** @var SCSSCacher */
38
-	protected $scssCacher;
37
+    /** @var SCSSCacher */
38
+    protected $scssCacher;
39 39
 
40
-	/** @var JSCombiner */
41
-	protected $jsCombiner;
40
+    /** @var JSCombiner */
41
+    protected $jsCombiner;
42 42
 
43
-	public function __construct(ICacheFactory $cacheFactory,
44
-								SCSSCacher $SCSSCacher,
45
-								JSCombiner $JSCombiner) {
46
-		$this->cacheFactory = $cacheFactory;
47
-		$this->scssCacher = $SCSSCacher;
48
-		$this->jsCombiner = $JSCombiner;
49
-	}
43
+    public function __construct(ICacheFactory $cacheFactory,
44
+                                SCSSCacher $SCSSCacher,
45
+                                JSCombiner $JSCombiner) {
46
+        $this->cacheFactory = $cacheFactory;
47
+        $this->scssCacher = $SCSSCacher;
48
+        $this->jsCombiner = $JSCombiner;
49
+    }
50 50
 
51
-	public function getName() {
52
-		return 'Clear frontend caches';
53
-	}
51
+    public function getName() {
52
+        return 'Clear frontend caches';
53
+    }
54 54
 
55
-	public function run(IOutput $output) {
56
-		try {
57
-			$c = $this->cacheFactory->createDistributed('imagePath');
58
-			$c->clear();
59
-			$output->info('Image cache cleared');
55
+    public function run(IOutput $output) {
56
+        try {
57
+            $c = $this->cacheFactory->createDistributed('imagePath');
58
+            $c->clear();
59
+            $output->info('Image cache cleared');
60 60
 
61
-			$this->scssCacher->resetCache();
62
-			$output->info('SCSS cache cleared');
61
+            $this->scssCacher->resetCache();
62
+            $output->info('SCSS cache cleared');
63 63
 
64
-			$this->jsCombiner->resetCache();
65
-			$output->info('JS cache cleared');
66
-		} catch (\Exception $e) {
67
-			$output->warning('Unable to clear the frontend cache');
68
-		}
69
-	}
64
+            $this->jsCombiner->resetCache();
65
+            $output->info('JS cache cleared');
66
+        } catch (\Exception $e) {
67
+            $output->warning('Unable to clear the frontend cache');
68
+        }
69
+    }
70 70
 }
Please login to merge, or discard this patch.
lib/public/Files/SimpleFS/ISimpleRoot.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -34,35 +34,35 @@
 block discarded – undo
34 34
  * @since 11.0.0
35 35
  */
36 36
 interface ISimpleRoot {
37
-	/**
38
-	 * Get the folder with name $name
39
-	 *
40
-	 * @param string $name
41
-	 * @return ISimpleFolder
42
-	 * @throws NotFoundException
43
-	 * @throws \RuntimeException
44
-	 * @since 11.0.0
45
-	 */
46
-	public function getFolder(string $name): ISimpleFolder;
37
+    /**
38
+     * Get the folder with name $name
39
+     *
40
+     * @param string $name
41
+     * @return ISimpleFolder
42
+     * @throws NotFoundException
43
+     * @throws \RuntimeException
44
+     * @since 11.0.0
45
+     */
46
+    public function getFolder(string $name): ISimpleFolder;
47 47
 
48
-	/**
49
-	 * Get all the Folders
50
-	 *
51
-	 * @return ISimpleFolder[]
52
-	 * @throws NotFoundException
53
-	 * @throws \RuntimeException
54
-	 * @since 11.0.0
55
-	 */
56
-	public function getDirectoryListing(): array;
48
+    /**
49
+     * Get all the Folders
50
+     *
51
+     * @return ISimpleFolder[]
52
+     * @throws NotFoundException
53
+     * @throws \RuntimeException
54
+     * @since 11.0.0
55
+     */
56
+    public function getDirectoryListing(): array;
57 57
 
58
-	/**
59
-	 * Create a new folder named $name
60
-	 *
61
-	 * @param string $name
62
-	 * @return ISimpleFolder
63
-	 * @throws NotPermittedException
64
-	 * @throws \RuntimeException
65
-	 * @since 11.0.0
66
-	 */
67
-	public function newFolder(string $name): ISimpleFolder;
58
+    /**
59
+     * Create a new folder named $name
60
+     *
61
+     * @param string $name
62
+     * @return ISimpleFolder
63
+     * @throws NotPermittedException
64
+     * @throws \RuntimeException
65
+     * @since 11.0.0
66
+     */
67
+    public function newFolder(string $name): ISimpleFolder;
68 68
 }
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
@@ -32,93 +32,93 @@
 block discarded – undo
32 32
  */
33 33
 class SimpleMenuAction implements IMenuAction {
34 34
 
35
-	/** @var string */
36
-	private $id;
35
+    /** @var string */
36
+    private $id;
37 37
 
38
-	/** @var string */
39
-	private $label;
38
+    /** @var string */
39
+    private $label;
40 40
 
41
-	/** @var string */
42
-	private $icon;
41
+    /** @var string */
42
+    private $icon;
43 43
 
44
-	/** @var string */
45
-	private $link;
44
+    /** @var string */
45
+    private $link;
46 46
 
47
-	/** @var int */
48
-	private $priority;
47
+    /** @var int */
48
+    private $priority;
49 49
 
50
-	/** @var string */
51
-	private $detail;
50
+    /** @var string */
51
+    private $detail;
52 52
 
53
-	/**
54
-	 * SimpleMenuAction constructor.
55
-	 *
56
-	 * @param string $id
57
-	 * @param string $label
58
-	 * @param string $icon
59
-	 * @param string $link
60
-	 * @param int $priority
61
-	 * @param string $detail
62
-	 * @since 14.0.0
63
-	 */
64
-	public function __construct(string $id, string $label, string $icon, string $link = '', int $priority = 100, string $detail = '') {
65
-		$this->id = $id;
66
-		$this->label = $label;
67
-		$this->icon = $icon;
68
-		$this->link = $link;
69
-		$this->priority = $priority;
70
-		$this->detail = $detail;
71
-	}
53
+    /**
54
+     * SimpleMenuAction constructor.
55
+     *
56
+     * @param string $id
57
+     * @param string $label
58
+     * @param string $icon
59
+     * @param string $link
60
+     * @param int $priority
61
+     * @param string $detail
62
+     * @since 14.0.0
63
+     */
64
+    public function __construct(string $id, string $label, string $icon, string $link = '', int $priority = 100, string $detail = '') {
65
+        $this->id = $id;
66
+        $this->label = $label;
67
+        $this->icon = $icon;
68
+        $this->link = $link;
69
+        $this->priority = $priority;
70
+        $this->detail = $detail;
71
+    }
72 72
 
73
-	/**
74
-	 * @return string
75
-	 * @since 14.0.0
76
-	 */
77
-	public function getId(): string {
78
-		return $this->id;
79
-	}
73
+    /**
74
+     * @return string
75
+     * @since 14.0.0
76
+     */
77
+    public function getId(): string {
78
+        return $this->id;
79
+    }
80 80
 
81
-	/**
82
-	 * @return string
83
-	 * @since 14.0.0
84
-	 */
85
-	public function getLabel(): string {
86
-		return $this->label;
87
-	}
81
+    /**
82
+     * @return string
83
+     * @since 14.0.0
84
+     */
85
+    public function getLabel(): string {
86
+        return $this->label;
87
+    }
88 88
 
89
-	/**
90
-	 * @return string
91
-	 * @since 14.0.0
92
-	 */
93
-	public function getIcon(): string {
94
-		return $this->icon;
95
-	}
89
+    /**
90
+     * @return string
91
+     * @since 14.0.0
92
+     */
93
+    public function getIcon(): string {
94
+        return $this->icon;
95
+    }
96 96
 
97
-	/**
98
-	 * @return string
99
-	 * @since 14.0.0
100
-	 */
101
-	public function getLink(): string {
102
-		return $this->link;
103
-	}
97
+    /**
98
+     * @return string
99
+     * @since 14.0.0
100
+     */
101
+    public function getLink(): string {
102
+        return $this->link;
103
+    }
104 104
 
105
-	/**
106
-	 * @return int
107
-	 * @since 14.0.0
108
-	 */
109
-	public function getPriority(): int {
110
-		return $this->priority;
111
-	}
105
+    /**
106
+     * @return int
107
+     * @since 14.0.0
108
+     */
109
+    public function getPriority(): int {
110
+        return $this->priority;
111
+    }
112 112
 
113
-	/**
114
-	 * @return string
115
-	 * @since 14.0.0
116
-	 */
117
-	public function render(): string {
118
-		$detailContent = ($this->detail !== '') ? '&nbsp;<span class="download-size">(' . Util::sanitizeHTML($this->detail) . ')</span>' : '';
119
-		return sprintf(
120
-			'<li id="%s"><a href="%s"><span class="icon %s"></span>%s %s</a></li>',
121
-			Util::sanitizeHTML($this->id), Util::sanitizeHTML($this->link), Util::sanitizeHTML($this->icon), Util::sanitizeHTML($this->label), $detailContent
122
-		);
123
-	}
113
+    /**
114
+     * @return string
115
+     * @since 14.0.0
116
+     */
117
+    public function render(): string {
118
+        $detailContent = ($this->detail !== '') ? '&nbsp;<span class="download-size">(' . Util::sanitizeHTML($this->detail) . ')</span>' : '';
119
+        return sprintf(
120
+            '<li id="%s"><a href="%s"><span class="icon %s"></span>%s %s</a></li>',
121
+            Util::sanitizeHTML($this->id), Util::sanitizeHTML($this->link), Util::sanitizeHTML($this->icon), Util::sanitizeHTML($this->label), $detailContent
122
+        );
123
+    }
124 124
 }
Please login to merge, or discard this patch.