Completed
Pull Request — master (#4369)
by Joas
17:44
created
apps/updatenotification/lib/Notification/Notifier.php 1 patch
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -36,141 +36,141 @@
 block discarded – undo
36 36
 
37 37
 class Notifier implements INotifier {
38 38
 
39
-	/** @var IURLGenerator */
40
-	protected $url;
41
-
42
-	/** @var IConfig */
43
-	protected $config;
44
-
45
-	/** @var IManager */
46
-	protected $notificationManager;
47
-
48
-	/** @var IFactory */
49
-	protected $l10NFactory;
50
-
51
-	/** @var IUserSession */
52
-	protected $userSession;
53
-
54
-	/** @var IGroupManager */
55
-	protected $groupManager;
56
-
57
-	/** @var string[] */
58
-	protected $appVersions;
59
-
60
-	/**
61
-	 * Notifier constructor.
62
-	 *
63
-	 * @param IURLGenerator $url
64
-	 * @param IConfig $config
65
-	 * @param IManager $notificationManager
66
-	 * @param IFactory $l10NFactory
67
-	 * @param IUserSession $userSession
68
-	 * @param IGroupManager $groupManager
69
-	 */
70
-	public function __construct(IURLGenerator $url, IConfig $config, IManager $notificationManager, IFactory $l10NFactory, IUserSession $userSession, IGroupManager $groupManager) {
71
-		$this->url = $url;
72
-		$this->notificationManager = $notificationManager;
73
-		$this->config = $config;
74
-		$this->l10NFactory = $l10NFactory;
75
-		$this->userSession = $userSession;
76
-		$this->groupManager = $groupManager;
77
-		$this->appVersions = $this->getAppVersions();
78
-	}
79
-
80
-	/**
81
-	 * @param INotification $notification
82
-	 * @param string $languageCode The code of the language that should be used to prepare the notification
83
-	 * @return INotification
84
-	 * @throws \InvalidArgumentException When the notification was not prepared by a notifier
85
-	 * @since 9.0.0
86
-	 */
87
-	public function prepare(INotification $notification, $languageCode) {
88
-		if ($notification->getApp() !== 'updatenotification') {
89
-			throw new \InvalidArgumentException();
90
-		}
91
-
92
-		$l = $this->l10NFactory->get('updatenotification', $languageCode);
93
-		if ($notification->getSubject() === 'connection_error') {
94
-			$errors = (int) $this->config->getAppValue('updatenotification', 'update_check_errors', 0);
95
-			if ($errors === 0) {
96
-				$this->notificationManager->markProcessed($notification);
97
-				throw new \InvalidArgumentException();
98
-			}
99
-
100
-			$notification->setParsedSubject($l->t('The update server could not be reached since %d days to check for new updates.', [$errors]))
101
-				->setParsedMessage($l->t('Please check the Nextcloud and server log files for errors.'));
102
-		} elseif ($notification->getObjectType() === 'core') {
103
-			$this->updateAlreadyInstalledCheck($notification, $this->getCoreVersions());
104
-
105
-			$parameters = $notification->getSubjectParameters();
106
-			$notification->setParsedSubject($l->t('Update to %1$s is available.', [$parameters['version']]));
107
-
108
-			if ($this->isAdmin()) {
109
-				$notification->setLink($this->url->linkToRouteAbsolute('settings.AdminSettings.index') . '#updater');
110
-			}
111
-		} else {
112
-			$appInfo = $this->getAppInfo($notification->getObjectType());
113
-			$appName = ($appInfo === null) ? $notification->getObjectType() : $appInfo['name'];
114
-
115
-			if (isset($this->appVersions[$notification->getObjectType()])) {
116
-				$this->updateAlreadyInstalledCheck($notification, $this->appVersions[$notification->getObjectType()]);
117
-			}
118
-
119
-			$notification->setParsedSubject($l->t('Update for %1$s to version %2$s is available.', [$appName, $notification->getObjectId()]))
120
-				->setRichSubject($l->t('Update for {app} to version %s is available.', $notification->getObjectId()), [
121
-					'app' => [
122
-						'type' => 'app',
123
-						'id' => $notification->getObjectType(),
124
-						'name' => $appName,
125
-					]
126
-				]);
127
-
128
-			if ($this->isAdmin()) {
129
-				$notification->setLink($this->url->linkToRouteAbsolute('settings.AppSettings.viewApps') . '#app-' . $notification->getObjectType());
130
-			}
131
-		}
132
-
133
-		$notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('updatenotification', 'notification.svg')));
134
-
135
-		return $notification;
136
-	}
137
-
138
-	/**
139
-	 * Remove the notification and prevent rendering, when the update is installed
140
-	 *
141
-	 * @param INotification $notification
142
-	 * @param string $installedVersion
143
-	 * @throws \InvalidArgumentException When the update is already installed
144
-	 */
145
-	protected function updateAlreadyInstalledCheck(INotification $notification, $installedVersion) {
146
-		if (version_compare($notification->getObjectId(), $installedVersion, '<=')) {
147
-			$this->notificationManager->markProcessed($notification);
148
-			throw new \InvalidArgumentException();
149
-		}
150
-	}
151
-
152
-	/**
153
-	 * @return bool
154
-	 */
155
-	protected function isAdmin() {
156
-		$user = $this->userSession->getUser();
157
-
158
-		if ($user instanceof IUser) {
159
-			return $this->groupManager->isAdmin($user->getUID());
160
-		}
161
-
162
-		return false;
163
-	}
164
-
165
-	protected function getCoreVersions() {
166
-		return implode('.', \OCP\Util::getVersion());
167
-	}
168
-
169
-	protected function getAppVersions() {
170
-		return \OC_App::getAppVersions();
171
-	}
172
-
173
-	protected function getAppInfo($appId) {
174
-		return \OC_App::getAppInfo($appId);
175
-	}
39
+    /** @var IURLGenerator */
40
+    protected $url;
41
+
42
+    /** @var IConfig */
43
+    protected $config;
44
+
45
+    /** @var IManager */
46
+    protected $notificationManager;
47
+
48
+    /** @var IFactory */
49
+    protected $l10NFactory;
50
+
51
+    /** @var IUserSession */
52
+    protected $userSession;
53
+
54
+    /** @var IGroupManager */
55
+    protected $groupManager;
56
+
57
+    /** @var string[] */
58
+    protected $appVersions;
59
+
60
+    /**
61
+     * Notifier constructor.
62
+     *
63
+     * @param IURLGenerator $url
64
+     * @param IConfig $config
65
+     * @param IManager $notificationManager
66
+     * @param IFactory $l10NFactory
67
+     * @param IUserSession $userSession
68
+     * @param IGroupManager $groupManager
69
+     */
70
+    public function __construct(IURLGenerator $url, IConfig $config, IManager $notificationManager, IFactory $l10NFactory, IUserSession $userSession, IGroupManager $groupManager) {
71
+        $this->url = $url;
72
+        $this->notificationManager = $notificationManager;
73
+        $this->config = $config;
74
+        $this->l10NFactory = $l10NFactory;
75
+        $this->userSession = $userSession;
76
+        $this->groupManager = $groupManager;
77
+        $this->appVersions = $this->getAppVersions();
78
+    }
79
+
80
+    /**
81
+     * @param INotification $notification
82
+     * @param string $languageCode The code of the language that should be used to prepare the notification
83
+     * @return INotification
84
+     * @throws \InvalidArgumentException When the notification was not prepared by a notifier
85
+     * @since 9.0.0
86
+     */
87
+    public function prepare(INotification $notification, $languageCode) {
88
+        if ($notification->getApp() !== 'updatenotification') {
89
+            throw new \InvalidArgumentException();
90
+        }
91
+
92
+        $l = $this->l10NFactory->get('updatenotification', $languageCode);
93
+        if ($notification->getSubject() === 'connection_error') {
94
+            $errors = (int) $this->config->getAppValue('updatenotification', 'update_check_errors', 0);
95
+            if ($errors === 0) {
96
+                $this->notificationManager->markProcessed($notification);
97
+                throw new \InvalidArgumentException();
98
+            }
99
+
100
+            $notification->setParsedSubject($l->t('The update server could not be reached since %d days to check for new updates.', [$errors]))
101
+                ->setParsedMessage($l->t('Please check the Nextcloud and server log files for errors.'));
102
+        } elseif ($notification->getObjectType() === 'core') {
103
+            $this->updateAlreadyInstalledCheck($notification, $this->getCoreVersions());
104
+
105
+            $parameters = $notification->getSubjectParameters();
106
+            $notification->setParsedSubject($l->t('Update to %1$s is available.', [$parameters['version']]));
107
+
108
+            if ($this->isAdmin()) {
109
+                $notification->setLink($this->url->linkToRouteAbsolute('settings.AdminSettings.index') . '#updater');
110
+            }
111
+        } else {
112
+            $appInfo = $this->getAppInfo($notification->getObjectType());
113
+            $appName = ($appInfo === null) ? $notification->getObjectType() : $appInfo['name'];
114
+
115
+            if (isset($this->appVersions[$notification->getObjectType()])) {
116
+                $this->updateAlreadyInstalledCheck($notification, $this->appVersions[$notification->getObjectType()]);
117
+            }
118
+
119
+            $notification->setParsedSubject($l->t('Update for %1$s to version %2$s is available.', [$appName, $notification->getObjectId()]))
120
+                ->setRichSubject($l->t('Update for {app} to version %s is available.', $notification->getObjectId()), [
121
+                    'app' => [
122
+                        'type' => 'app',
123
+                        'id' => $notification->getObjectType(),
124
+                        'name' => $appName,
125
+                    ]
126
+                ]);
127
+
128
+            if ($this->isAdmin()) {
129
+                $notification->setLink($this->url->linkToRouteAbsolute('settings.AppSettings.viewApps') . '#app-' . $notification->getObjectType());
130
+            }
131
+        }
132
+
133
+        $notification->setIcon($this->url->getAbsoluteURL($this->url->imagePath('updatenotification', 'notification.svg')));
134
+
135
+        return $notification;
136
+    }
137
+
138
+    /**
139
+     * Remove the notification and prevent rendering, when the update is installed
140
+     *
141
+     * @param INotification $notification
142
+     * @param string $installedVersion
143
+     * @throws \InvalidArgumentException When the update is already installed
144
+     */
145
+    protected function updateAlreadyInstalledCheck(INotification $notification, $installedVersion) {
146
+        if (version_compare($notification->getObjectId(), $installedVersion, '<=')) {
147
+            $this->notificationManager->markProcessed($notification);
148
+            throw new \InvalidArgumentException();
149
+        }
150
+    }
151
+
152
+    /**
153
+     * @return bool
154
+     */
155
+    protected function isAdmin() {
156
+        $user = $this->userSession->getUser();
157
+
158
+        if ($user instanceof IUser) {
159
+            return $this->groupManager->isAdmin($user->getUID());
160
+        }
161
+
162
+        return false;
163
+    }
164
+
165
+    protected function getCoreVersions() {
166
+        return implode('.', \OCP\Util::getVersion());
167
+    }
168
+
169
+    protected function getAppVersions() {
170
+        return \OC_App::getAppVersions();
171
+    }
172
+
173
+    protected function getAppInfo($appId) {
174
+        return \OC_App::getAppInfo($appId);
175
+    }
176 176
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Service/StoragesService.php 2 patches
Indentation   +486 added lines, -486 removed lines patch added patch discarded remove patch
@@ -41,490 +41,490 @@
 block discarded – undo
41 41
  */
42 42
 abstract class StoragesService {
43 43
 
44
-	/** @var BackendService */
45
-	protected $backendService;
46
-
47
-	/**
48
-	 * @var DBConfigService
49
-	 */
50
-	protected $dbConfig;
51
-
52
-	/**
53
-	 * @var IUserMountCache
54
-	 */
55
-	protected $userMountCache;
56
-
57
-	/**
58
-	 * @param BackendService $backendService
59
-	 * @param DBConfigService $dbConfigService
60
-	 * @param IUserMountCache $userMountCache
61
-	 */
62
-	public function __construct(BackendService $backendService, DBConfigService $dbConfigService, IUserMountCache $userMountCache) {
63
-		$this->backendService = $backendService;
64
-		$this->dbConfig = $dbConfigService;
65
-		$this->userMountCache = $userMountCache;
66
-	}
67
-
68
-	protected function readDBConfig() {
69
-		return $this->dbConfig->getAdminMounts();
70
-	}
71
-
72
-	protected function getStorageConfigFromDBMount(array $mount) {
73
-		$applicableUsers = array_filter($mount['applicable'], function ($applicable) {
74
-			return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_USER;
75
-		});
76
-		$applicableUsers = array_map(function ($applicable) {
77
-			return $applicable['value'];
78
-		}, $applicableUsers);
79
-
80
-		$applicableGroups = array_filter($mount['applicable'], function ($applicable) {
81
-			return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_GROUP;
82
-		});
83
-		$applicableGroups = array_map(function ($applicable) {
84
-			return $applicable['value'];
85
-		}, $applicableGroups);
86
-
87
-		try {
88
-			$config = $this->createStorage(
89
-				$mount['mount_point'],
90
-				$mount['storage_backend'],
91
-				$mount['auth_backend'],
92
-				$mount['config'],
93
-				$mount['options'],
94
-				array_values($applicableUsers),
95
-				array_values($applicableGroups),
96
-				$mount['priority']
97
-			);
98
-			$config->setType($mount['type']);
99
-			$config->setId((int)$mount['mount_id']);
100
-			return $config;
101
-		} catch (\UnexpectedValueException $e) {
102
-			// don't die if a storage backend doesn't exist
103
-			\OCP\Util::writeLog(
104
-				'files_external',
105
-				'Could not load storage: "' . $e->getMessage() . '"',
106
-				\OCP\Util::ERROR
107
-			);
108
-			return null;
109
-		} catch (\InvalidArgumentException $e) {
110
-			\OCP\Util::writeLog(
111
-				'files_external',
112
-				'Could not load storage: "' . $e->getMessage() . '"',
113
-				\OCP\Util::ERROR
114
-			);
115
-			return null;
116
-		}
117
-	}
118
-
119
-	/**
120
-	 * Read the external storages config
121
-	 *
122
-	 * @return array map of storage id to storage config
123
-	 */
124
-	protected function readConfig() {
125
-		$mounts = $this->readDBConfig();
126
-		$configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts);
127
-		$configs = array_filter($configs, function ($config) {
128
-			return $config instanceof StorageConfig;
129
-		});
130
-
131
-		$keys = array_map(function (StorageConfig $config) {
132
-			return $config->getId();
133
-		}, $configs);
134
-
135
-		return array_combine($keys, $configs);
136
-	}
137
-
138
-	/**
139
-	 * Get a storage with status
140
-	 *
141
-	 * @param int $id storage id
142
-	 *
143
-	 * @return StorageConfig
144
-	 * @throws NotFoundException if the storage with the given id was not found
145
-	 */
146
-	public function getStorage($id) {
147
-		$mount = $this->dbConfig->getMountById($id);
148
-
149
-		if (!is_array($mount)) {
150
-			throw new NotFoundException('Storage with ID "' . $id . '" not found');
151
-		}
152
-
153
-		$config = $this->getStorageConfigFromDBMount($mount);
154
-		if ($this->isApplicable($config)) {
155
-			return $config;
156
-		} else {
157
-			throw new NotFoundException('Storage with ID "' . $id . '" not found');
158
-		}
159
-	}
160
-
161
-	/**
162
-	 * Check whether this storage service should provide access to a storage
163
-	 *
164
-	 * @param StorageConfig $config
165
-	 * @return bool
166
-	 */
167
-	abstract protected function isApplicable(StorageConfig $config);
168
-
169
-	/**
170
-	 * Gets all storages, valid or not
171
-	 *
172
-	 * @return StorageConfig[] array of storage configs
173
-	 */
174
-	public function getAllStorages() {
175
-		return $this->readConfig();
176
-	}
177
-
178
-	/**
179
-	 * Gets all valid storages
180
-	 *
181
-	 * @return StorageConfig[]
182
-	 */
183
-	public function getStorages() {
184
-		return array_filter($this->getAllStorages(), [$this, 'validateStorage']);
185
-	}
186
-
187
-	/**
188
-	 * Validate storage
189
-	 * FIXME: De-duplicate with StoragesController::validate()
190
-	 *
191
-	 * @param StorageConfig $storage
192
-	 * @return bool
193
-	 */
194
-	protected function validateStorage(StorageConfig $storage) {
195
-		/** @var Backend */
196
-		$backend = $storage->getBackend();
197
-		/** @var AuthMechanism */
198
-		$authMechanism = $storage->getAuthMechanism();
199
-
200
-		if (!$backend->isVisibleFor($this->getVisibilityType())) {
201
-			// not permitted to use backend
202
-			return false;
203
-		}
204
-		if (!$authMechanism->isVisibleFor($this->getVisibilityType())) {
205
-			// not permitted to use auth mechanism
206
-			return false;
207
-		}
208
-
209
-		return true;
210
-	}
211
-
212
-	/**
213
-	 * Get the visibility type for this controller, used in validation
214
-	 *
215
-	 * @return string BackendService::VISIBILITY_* constants
216
-	 */
217
-	abstract public function getVisibilityType();
218
-
219
-	/**
220
-	 * @return integer
221
-	 */
222
-	protected function getType() {
223
-		return DBConfigService::MOUNT_TYPE_ADMIN;
224
-	}
225
-
226
-	/**
227
-	 * Add new storage to the configuration
228
-	 *
229
-	 * @param StorageConfig $newStorage storage attributes
230
-	 *
231
-	 * @return StorageConfig storage config, with added id
232
-	 */
233
-	public function addStorage(StorageConfig $newStorage) {
234
-		$allStorages = $this->readConfig();
235
-
236
-		$configId = $this->dbConfig->addMount(
237
-			$newStorage->getMountPoint(),
238
-			$newStorage->getBackend()->getIdentifier(),
239
-			$newStorage->getAuthMechanism()->getIdentifier(),
240
-			$newStorage->getPriority(),
241
-			$this->getType()
242
-		);
243
-
244
-		$newStorage->setId($configId);
245
-
246
-		foreach ($newStorage->getApplicableUsers() as $user) {
247
-			$this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_USER, $user);
248
-		}
249
-		foreach ($newStorage->getApplicableGroups() as $group) {
250
-			$this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
251
-		}
252
-		foreach ($newStorage->getBackendOptions() as $key => $value) {
253
-			$this->dbConfig->setConfig($configId, $key, $value);
254
-		}
255
-		foreach ($newStorage->getMountOptions() as $key => $value) {
256
-			$this->dbConfig->setOption($configId, $key, $value);
257
-		}
258
-
259
-		if (count($newStorage->getApplicableUsers()) === 0 && count($newStorage->getApplicableGroups()) === 0) {
260
-			$this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
261
-		}
262
-
263
-		// add new storage
264
-		$allStorages[$configId] = $newStorage;
265
-
266
-		$this->triggerHooks($newStorage, Filesystem::signal_create_mount);
267
-
268
-		$newStorage->setStatus(StorageNotAvailableException::STATUS_SUCCESS);
269
-		return $newStorage;
270
-	}
271
-
272
-	/**
273
-	 * Create a storage from its parameters
274
-	 *
275
-	 * @param string $mountPoint storage mount point
276
-	 * @param string $backendIdentifier backend identifier
277
-	 * @param string $authMechanismIdentifier authentication mechanism identifier
278
-	 * @param array $backendOptions backend-specific options
279
-	 * @param array|null $mountOptions mount-specific options
280
-	 * @param array|null $applicableUsers users for which to mount the storage
281
-	 * @param array|null $applicableGroups groups for which to mount the storage
282
-	 * @param int|null $priority priority
283
-	 *
284
-	 * @return StorageConfig
285
-	 */
286
-	public function createStorage(
287
-		$mountPoint,
288
-		$backendIdentifier,
289
-		$authMechanismIdentifier,
290
-		$backendOptions,
291
-		$mountOptions = null,
292
-		$applicableUsers = null,
293
-		$applicableGroups = null,
294
-		$priority = null
295
-	) {
296
-		$backend = $this->backendService->getBackend($backendIdentifier);
297
-		if (!$backend) {
298
-			throw new \InvalidArgumentException('Unable to get backend for ' . $backendIdentifier);
299
-		}
300
-		$authMechanism = $this->backendService->getAuthMechanism($authMechanismIdentifier);
301
-		if (!$authMechanism) {
302
-			throw new \InvalidArgumentException('Unable to get authentication mechanism for ' . $authMechanismIdentifier);
303
-		}
304
-		$newStorage = new StorageConfig();
305
-		$newStorage->setMountPoint($mountPoint);
306
-		$newStorage->setBackend($backend);
307
-		$newStorage->setAuthMechanism($authMechanism);
308
-		$newStorage->setBackendOptions($backendOptions);
309
-		if (isset($mountOptions)) {
310
-			$newStorage->setMountOptions($mountOptions);
311
-		}
312
-		if (isset($applicableUsers)) {
313
-			$newStorage->setApplicableUsers($applicableUsers);
314
-		}
315
-		if (isset($applicableGroups)) {
316
-			$newStorage->setApplicableGroups($applicableGroups);
317
-		}
318
-		if (isset($priority)) {
319
-			$newStorage->setPriority($priority);
320
-		}
321
-
322
-		return $newStorage;
323
-	}
324
-
325
-	/**
326
-	 * Triggers the given hook signal for all the applicables given
327
-	 *
328
-	 * @param string $signal signal
329
-	 * @param string $mountPoint hook mount pount param
330
-	 * @param string $mountType hook mount type param
331
-	 * @param array $applicableArray array of applicable users/groups for which to trigger the hook
332
-	 */
333
-	protected function triggerApplicableHooks($signal, $mountPoint, $mountType, $applicableArray) {
334
-		foreach ($applicableArray as $applicable) {
335
-			\OCP\Util::emitHook(
336
-				Filesystem::CLASSNAME,
337
-				$signal,
338
-				[
339
-					Filesystem::signal_param_path => $mountPoint,
340
-					Filesystem::signal_param_mount_type => $mountType,
341
-					Filesystem::signal_param_users => $applicable,
342
-				]
343
-			);
344
-		}
345
-	}
346
-
347
-	/**
348
-	 * Triggers $signal for all applicable users of the given
349
-	 * storage
350
-	 *
351
-	 * @param StorageConfig $storage storage data
352
-	 * @param string $signal signal to trigger
353
-	 */
354
-	abstract protected function triggerHooks(StorageConfig $storage, $signal);
355
-
356
-	/**
357
-	 * Triggers signal_create_mount or signal_delete_mount to
358
-	 * accommodate for additions/deletions in applicableUsers
359
-	 * and applicableGroups fields.
360
-	 *
361
-	 * @param StorageConfig $oldStorage old storage data
362
-	 * @param StorageConfig $newStorage new storage data
363
-	 */
364
-	abstract protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage);
365
-
366
-	/**
367
-	 * Update storage to the configuration
368
-	 *
369
-	 * @param StorageConfig $updatedStorage storage attributes
370
-	 *
371
-	 * @return StorageConfig storage config
372
-	 * @throws NotFoundException if the given storage does not exist in the config
373
-	 */
374
-	public function updateStorage(StorageConfig $updatedStorage) {
375
-		$id = $updatedStorage->getId();
376
-
377
-		$existingMount = $this->dbConfig->getMountById($id);
378
-
379
-		if (!is_array($existingMount)) {
380
-			throw new NotFoundException('Storage with ID "' . $id . '" not found while updating storage');
381
-		}
382
-
383
-		$oldStorage = $this->getStorageConfigFromDBMount($existingMount);
384
-
385
-		$removedUsers = array_diff($oldStorage->getApplicableUsers(), $updatedStorage->getApplicableUsers());
386
-		$removedGroups = array_diff($oldStorage->getApplicableGroups(), $updatedStorage->getApplicableGroups());
387
-		$addedUsers = array_diff($updatedStorage->getApplicableUsers(), $oldStorage->getApplicableUsers());
388
-		$addedGroups = array_diff($updatedStorage->getApplicableGroups(), $oldStorage->getApplicableGroups());
389
-
390
-		$oldUserCount = count($oldStorage->getApplicableUsers());
391
-		$oldGroupCount = count($oldStorage->getApplicableGroups());
392
-		$newUserCount = count($updatedStorage->getApplicableUsers());
393
-		$newGroupCount = count($updatedStorage->getApplicableGroups());
394
-		$wasGlobal = ($oldUserCount + $oldGroupCount) === 0;
395
-		$isGlobal = ($newUserCount + $newGroupCount) === 0;
396
-
397
-		foreach ($removedUsers as $user) {
398
-			$this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user);
399
-		}
400
-		foreach ($removedGroups as $group) {
401
-			$this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
402
-		}
403
-		foreach ($addedUsers as $user) {
404
-			$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user);
405
-		}
406
-		foreach ($addedGroups as $group) {
407
-			$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
408
-		}
409
-
410
-		if ($wasGlobal && !$isGlobal) {
411
-			$this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
412
-		} else if (!$wasGlobal && $isGlobal) {
413
-			$this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
414
-		}
415
-
416
-		$changedConfig = array_diff_assoc($updatedStorage->getBackendOptions(), $oldStorage->getBackendOptions());
417
-		$changedOptions = array_diff_assoc($updatedStorage->getMountOptions(), $oldStorage->getMountOptions());
418
-
419
-		foreach ($changedConfig as $key => $value) {
420
-			$this->dbConfig->setConfig($id, $key, $value);
421
-		}
422
-		foreach ($changedOptions as $key => $value) {
423
-			$this->dbConfig->setOption($id, $key, $value);
424
-		}
425
-
426
-		if ($updatedStorage->getMountPoint() !== $oldStorage->getMountPoint()) {
427
-			$this->dbConfig->setMountPoint($id, $updatedStorage->getMountPoint());
428
-		}
429
-
430
-		if ($updatedStorage->getAuthMechanism()->getIdentifier() !== $oldStorage->getAuthMechanism()->getIdentifier()) {
431
-			$this->dbConfig->setAuthBackend($id, $updatedStorage->getAuthMechanism()->getIdentifier());
432
-		}
433
-
434
-		$this->triggerChangeHooks($oldStorage, $updatedStorage);
435
-
436
-		if (($wasGlobal && !$isGlobal) || count($removedGroups) > 0) { // to expensive to properly handle these on the fly
437
-			$this->userMountCache->remoteStorageMounts($this->getStorageId($updatedStorage));
438
-		} else {
439
-			$storageId = $this->getStorageId($updatedStorage);
440
-			foreach ($removedUsers as $userId) {
441
-				$this->userMountCache->removeUserStorageMount($storageId, $userId);
442
-			}
443
-		}
444
-
445
-		return $this->getStorage($id);
446
-	}
447
-
448
-	/**
449
-	 * Delete the storage with the given id.
450
-	 *
451
-	 * @param int $id storage id
452
-	 *
453
-	 * @throws NotFoundException if no storage was found with the given id
454
-	 */
455
-	public function removeStorage($id) {
456
-		$existingMount = $this->dbConfig->getMountById($id);
457
-
458
-		if (!is_array($existingMount)) {
459
-			throw new NotFoundException('Storage with ID "' . $id . '" not found');
460
-		}
461
-
462
-		$this->dbConfig->removeMount($id);
463
-
464
-		$deletedStorage = $this->getStorageConfigFromDBMount($existingMount);
465
-		$this->triggerHooks($deletedStorage, Filesystem::signal_delete_mount);
466
-
467
-		// delete oc_storages entries and oc_filecache
468
-		try {
469
-			$rustyStorageId = $this->getRustyStorageIdFromConfig($deletedStorage);
470
-			\OC\Files\Cache\Storage::remove($rustyStorageId);
471
-		} catch (\Exception $e) {
472
-			// can happen either for invalid configs where the storage could not
473
-			// be instantiated or whenever $user vars where used, in which case
474
-			// the storage id could not be computed
475
-			\OCP\Util::writeLog(
476
-				'files_external',
477
-				'Exception: "' . $e->getMessage() . '"',
478
-				\OCP\Util::ERROR
479
-			);
480
-		}
481
-	}
482
-
483
-	/**
484
-	 * Returns the rusty storage id from oc_storages from the given storage config.
485
-	 *
486
-	 * @param StorageConfig $storageConfig
487
-	 * @return string rusty storage id
488
-	 */
489
-	private function getRustyStorageIdFromConfig(StorageConfig $storageConfig) {
490
-		// if any of the storage options contains $user, it is not possible
491
-		// to compute the possible storage id as we don't know which users
492
-		// mounted it already (and we certainly don't want to iterate over ALL users)
493
-		foreach ($storageConfig->getBackendOptions() as $value) {
494
-			if (strpos($value, '$user') !== false) {
495
-				throw new \Exception('Cannot compute storage id for deletion due to $user vars in the configuration');
496
-			}
497
-		}
498
-
499
-		// note: similar to ConfigAdapter->prepateStorageConfig()
500
-		$storageConfig->getAuthMechanism()->manipulateStorageConfig($storageConfig);
501
-		$storageConfig->getBackend()->manipulateStorageConfig($storageConfig);
502
-
503
-		$class = $storageConfig->getBackend()->getStorageClass();
504
-		$storageImpl = new $class($storageConfig->getBackendOptions());
505
-
506
-		return $storageImpl->getId();
507
-	}
508
-
509
-	/**
510
-	 * Construct the storage implementation
511
-	 *
512
-	 * @param StorageConfig $storageConfig
513
-	 * @return int
514
-	 */
515
-	private function getStorageId(StorageConfig $storageConfig) {
516
-		try {
517
-			$class = $storageConfig->getBackend()->getStorageClass();
518
-			/** @var \OC\Files\Storage\Storage $storage */
519
-			$storage = new $class($storageConfig->getBackendOptions());
520
-
521
-			// auth mechanism should fire first
522
-			$storage = $storageConfig->getBackend()->wrapStorage($storage);
523
-			$storage = $storageConfig->getAuthMechanism()->wrapStorage($storage);
524
-
525
-			return $storage->getStorageCache()->getNumericId();
526
-		} catch (\Exception $e) {
527
-			return -1;
528
-		}
529
-	}
44
+    /** @var BackendService */
45
+    protected $backendService;
46
+
47
+    /**
48
+     * @var DBConfigService
49
+     */
50
+    protected $dbConfig;
51
+
52
+    /**
53
+     * @var IUserMountCache
54
+     */
55
+    protected $userMountCache;
56
+
57
+    /**
58
+     * @param BackendService $backendService
59
+     * @param DBConfigService $dbConfigService
60
+     * @param IUserMountCache $userMountCache
61
+     */
62
+    public function __construct(BackendService $backendService, DBConfigService $dbConfigService, IUserMountCache $userMountCache) {
63
+        $this->backendService = $backendService;
64
+        $this->dbConfig = $dbConfigService;
65
+        $this->userMountCache = $userMountCache;
66
+    }
67
+
68
+    protected function readDBConfig() {
69
+        return $this->dbConfig->getAdminMounts();
70
+    }
71
+
72
+    protected function getStorageConfigFromDBMount(array $mount) {
73
+        $applicableUsers = array_filter($mount['applicable'], function ($applicable) {
74
+            return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_USER;
75
+        });
76
+        $applicableUsers = array_map(function ($applicable) {
77
+            return $applicable['value'];
78
+        }, $applicableUsers);
79
+
80
+        $applicableGroups = array_filter($mount['applicable'], function ($applicable) {
81
+            return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_GROUP;
82
+        });
83
+        $applicableGroups = array_map(function ($applicable) {
84
+            return $applicable['value'];
85
+        }, $applicableGroups);
86
+
87
+        try {
88
+            $config = $this->createStorage(
89
+                $mount['mount_point'],
90
+                $mount['storage_backend'],
91
+                $mount['auth_backend'],
92
+                $mount['config'],
93
+                $mount['options'],
94
+                array_values($applicableUsers),
95
+                array_values($applicableGroups),
96
+                $mount['priority']
97
+            );
98
+            $config->setType($mount['type']);
99
+            $config->setId((int)$mount['mount_id']);
100
+            return $config;
101
+        } catch (\UnexpectedValueException $e) {
102
+            // don't die if a storage backend doesn't exist
103
+            \OCP\Util::writeLog(
104
+                'files_external',
105
+                'Could not load storage: "' . $e->getMessage() . '"',
106
+                \OCP\Util::ERROR
107
+            );
108
+            return null;
109
+        } catch (\InvalidArgumentException $e) {
110
+            \OCP\Util::writeLog(
111
+                'files_external',
112
+                'Could not load storage: "' . $e->getMessage() . '"',
113
+                \OCP\Util::ERROR
114
+            );
115
+            return null;
116
+        }
117
+    }
118
+
119
+    /**
120
+     * Read the external storages config
121
+     *
122
+     * @return array map of storage id to storage config
123
+     */
124
+    protected function readConfig() {
125
+        $mounts = $this->readDBConfig();
126
+        $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts);
127
+        $configs = array_filter($configs, function ($config) {
128
+            return $config instanceof StorageConfig;
129
+        });
130
+
131
+        $keys = array_map(function (StorageConfig $config) {
132
+            return $config->getId();
133
+        }, $configs);
134
+
135
+        return array_combine($keys, $configs);
136
+    }
137
+
138
+    /**
139
+     * Get a storage with status
140
+     *
141
+     * @param int $id storage id
142
+     *
143
+     * @return StorageConfig
144
+     * @throws NotFoundException if the storage with the given id was not found
145
+     */
146
+    public function getStorage($id) {
147
+        $mount = $this->dbConfig->getMountById($id);
148
+
149
+        if (!is_array($mount)) {
150
+            throw new NotFoundException('Storage with ID "' . $id . '" not found');
151
+        }
152
+
153
+        $config = $this->getStorageConfigFromDBMount($mount);
154
+        if ($this->isApplicable($config)) {
155
+            return $config;
156
+        } else {
157
+            throw new NotFoundException('Storage with ID "' . $id . '" not found');
158
+        }
159
+    }
160
+
161
+    /**
162
+     * Check whether this storage service should provide access to a storage
163
+     *
164
+     * @param StorageConfig $config
165
+     * @return bool
166
+     */
167
+    abstract protected function isApplicable(StorageConfig $config);
168
+
169
+    /**
170
+     * Gets all storages, valid or not
171
+     *
172
+     * @return StorageConfig[] array of storage configs
173
+     */
174
+    public function getAllStorages() {
175
+        return $this->readConfig();
176
+    }
177
+
178
+    /**
179
+     * Gets all valid storages
180
+     *
181
+     * @return StorageConfig[]
182
+     */
183
+    public function getStorages() {
184
+        return array_filter($this->getAllStorages(), [$this, 'validateStorage']);
185
+    }
186
+
187
+    /**
188
+     * Validate storage
189
+     * FIXME: De-duplicate with StoragesController::validate()
190
+     *
191
+     * @param StorageConfig $storage
192
+     * @return bool
193
+     */
194
+    protected function validateStorage(StorageConfig $storage) {
195
+        /** @var Backend */
196
+        $backend = $storage->getBackend();
197
+        /** @var AuthMechanism */
198
+        $authMechanism = $storage->getAuthMechanism();
199
+
200
+        if (!$backend->isVisibleFor($this->getVisibilityType())) {
201
+            // not permitted to use backend
202
+            return false;
203
+        }
204
+        if (!$authMechanism->isVisibleFor($this->getVisibilityType())) {
205
+            // not permitted to use auth mechanism
206
+            return false;
207
+        }
208
+
209
+        return true;
210
+    }
211
+
212
+    /**
213
+     * Get the visibility type for this controller, used in validation
214
+     *
215
+     * @return string BackendService::VISIBILITY_* constants
216
+     */
217
+    abstract public function getVisibilityType();
218
+
219
+    /**
220
+     * @return integer
221
+     */
222
+    protected function getType() {
223
+        return DBConfigService::MOUNT_TYPE_ADMIN;
224
+    }
225
+
226
+    /**
227
+     * Add new storage to the configuration
228
+     *
229
+     * @param StorageConfig $newStorage storage attributes
230
+     *
231
+     * @return StorageConfig storage config, with added id
232
+     */
233
+    public function addStorage(StorageConfig $newStorage) {
234
+        $allStorages = $this->readConfig();
235
+
236
+        $configId = $this->dbConfig->addMount(
237
+            $newStorage->getMountPoint(),
238
+            $newStorage->getBackend()->getIdentifier(),
239
+            $newStorage->getAuthMechanism()->getIdentifier(),
240
+            $newStorage->getPriority(),
241
+            $this->getType()
242
+        );
243
+
244
+        $newStorage->setId($configId);
245
+
246
+        foreach ($newStorage->getApplicableUsers() as $user) {
247
+            $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_USER, $user);
248
+        }
249
+        foreach ($newStorage->getApplicableGroups() as $group) {
250
+            $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
251
+        }
252
+        foreach ($newStorage->getBackendOptions() as $key => $value) {
253
+            $this->dbConfig->setConfig($configId, $key, $value);
254
+        }
255
+        foreach ($newStorage->getMountOptions() as $key => $value) {
256
+            $this->dbConfig->setOption($configId, $key, $value);
257
+        }
258
+
259
+        if (count($newStorage->getApplicableUsers()) === 0 && count($newStorage->getApplicableGroups()) === 0) {
260
+            $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
261
+        }
262
+
263
+        // add new storage
264
+        $allStorages[$configId] = $newStorage;
265
+
266
+        $this->triggerHooks($newStorage, Filesystem::signal_create_mount);
267
+
268
+        $newStorage->setStatus(StorageNotAvailableException::STATUS_SUCCESS);
269
+        return $newStorage;
270
+    }
271
+
272
+    /**
273
+     * Create a storage from its parameters
274
+     *
275
+     * @param string $mountPoint storage mount point
276
+     * @param string $backendIdentifier backend identifier
277
+     * @param string $authMechanismIdentifier authentication mechanism identifier
278
+     * @param array $backendOptions backend-specific options
279
+     * @param array|null $mountOptions mount-specific options
280
+     * @param array|null $applicableUsers users for which to mount the storage
281
+     * @param array|null $applicableGroups groups for which to mount the storage
282
+     * @param int|null $priority priority
283
+     *
284
+     * @return StorageConfig
285
+     */
286
+    public function createStorage(
287
+        $mountPoint,
288
+        $backendIdentifier,
289
+        $authMechanismIdentifier,
290
+        $backendOptions,
291
+        $mountOptions = null,
292
+        $applicableUsers = null,
293
+        $applicableGroups = null,
294
+        $priority = null
295
+    ) {
296
+        $backend = $this->backendService->getBackend($backendIdentifier);
297
+        if (!$backend) {
298
+            throw new \InvalidArgumentException('Unable to get backend for ' . $backendIdentifier);
299
+        }
300
+        $authMechanism = $this->backendService->getAuthMechanism($authMechanismIdentifier);
301
+        if (!$authMechanism) {
302
+            throw new \InvalidArgumentException('Unable to get authentication mechanism for ' . $authMechanismIdentifier);
303
+        }
304
+        $newStorage = new StorageConfig();
305
+        $newStorage->setMountPoint($mountPoint);
306
+        $newStorage->setBackend($backend);
307
+        $newStorage->setAuthMechanism($authMechanism);
308
+        $newStorage->setBackendOptions($backendOptions);
309
+        if (isset($mountOptions)) {
310
+            $newStorage->setMountOptions($mountOptions);
311
+        }
312
+        if (isset($applicableUsers)) {
313
+            $newStorage->setApplicableUsers($applicableUsers);
314
+        }
315
+        if (isset($applicableGroups)) {
316
+            $newStorage->setApplicableGroups($applicableGroups);
317
+        }
318
+        if (isset($priority)) {
319
+            $newStorage->setPriority($priority);
320
+        }
321
+
322
+        return $newStorage;
323
+    }
324
+
325
+    /**
326
+     * Triggers the given hook signal for all the applicables given
327
+     *
328
+     * @param string $signal signal
329
+     * @param string $mountPoint hook mount pount param
330
+     * @param string $mountType hook mount type param
331
+     * @param array $applicableArray array of applicable users/groups for which to trigger the hook
332
+     */
333
+    protected function triggerApplicableHooks($signal, $mountPoint, $mountType, $applicableArray) {
334
+        foreach ($applicableArray as $applicable) {
335
+            \OCP\Util::emitHook(
336
+                Filesystem::CLASSNAME,
337
+                $signal,
338
+                [
339
+                    Filesystem::signal_param_path => $mountPoint,
340
+                    Filesystem::signal_param_mount_type => $mountType,
341
+                    Filesystem::signal_param_users => $applicable,
342
+                ]
343
+            );
344
+        }
345
+    }
346
+
347
+    /**
348
+     * Triggers $signal for all applicable users of the given
349
+     * storage
350
+     *
351
+     * @param StorageConfig $storage storage data
352
+     * @param string $signal signal to trigger
353
+     */
354
+    abstract protected function triggerHooks(StorageConfig $storage, $signal);
355
+
356
+    /**
357
+     * Triggers signal_create_mount or signal_delete_mount to
358
+     * accommodate for additions/deletions in applicableUsers
359
+     * and applicableGroups fields.
360
+     *
361
+     * @param StorageConfig $oldStorage old storage data
362
+     * @param StorageConfig $newStorage new storage data
363
+     */
364
+    abstract protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage);
365
+
366
+    /**
367
+     * Update storage to the configuration
368
+     *
369
+     * @param StorageConfig $updatedStorage storage attributes
370
+     *
371
+     * @return StorageConfig storage config
372
+     * @throws NotFoundException if the given storage does not exist in the config
373
+     */
374
+    public function updateStorage(StorageConfig $updatedStorage) {
375
+        $id = $updatedStorage->getId();
376
+
377
+        $existingMount = $this->dbConfig->getMountById($id);
378
+
379
+        if (!is_array($existingMount)) {
380
+            throw new NotFoundException('Storage with ID "' . $id . '" not found while updating storage');
381
+        }
382
+
383
+        $oldStorage = $this->getStorageConfigFromDBMount($existingMount);
384
+
385
+        $removedUsers = array_diff($oldStorage->getApplicableUsers(), $updatedStorage->getApplicableUsers());
386
+        $removedGroups = array_diff($oldStorage->getApplicableGroups(), $updatedStorage->getApplicableGroups());
387
+        $addedUsers = array_diff($updatedStorage->getApplicableUsers(), $oldStorage->getApplicableUsers());
388
+        $addedGroups = array_diff($updatedStorage->getApplicableGroups(), $oldStorage->getApplicableGroups());
389
+
390
+        $oldUserCount = count($oldStorage->getApplicableUsers());
391
+        $oldGroupCount = count($oldStorage->getApplicableGroups());
392
+        $newUserCount = count($updatedStorage->getApplicableUsers());
393
+        $newGroupCount = count($updatedStorage->getApplicableGroups());
394
+        $wasGlobal = ($oldUserCount + $oldGroupCount) === 0;
395
+        $isGlobal = ($newUserCount + $newGroupCount) === 0;
396
+
397
+        foreach ($removedUsers as $user) {
398
+            $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user);
399
+        }
400
+        foreach ($removedGroups as $group) {
401
+            $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
402
+        }
403
+        foreach ($addedUsers as $user) {
404
+            $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user);
405
+        }
406
+        foreach ($addedGroups as $group) {
407
+            $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
408
+        }
409
+
410
+        if ($wasGlobal && !$isGlobal) {
411
+            $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
412
+        } else if (!$wasGlobal && $isGlobal) {
413
+            $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
414
+        }
415
+
416
+        $changedConfig = array_diff_assoc($updatedStorage->getBackendOptions(), $oldStorage->getBackendOptions());
417
+        $changedOptions = array_diff_assoc($updatedStorage->getMountOptions(), $oldStorage->getMountOptions());
418
+
419
+        foreach ($changedConfig as $key => $value) {
420
+            $this->dbConfig->setConfig($id, $key, $value);
421
+        }
422
+        foreach ($changedOptions as $key => $value) {
423
+            $this->dbConfig->setOption($id, $key, $value);
424
+        }
425
+
426
+        if ($updatedStorage->getMountPoint() !== $oldStorage->getMountPoint()) {
427
+            $this->dbConfig->setMountPoint($id, $updatedStorage->getMountPoint());
428
+        }
429
+
430
+        if ($updatedStorage->getAuthMechanism()->getIdentifier() !== $oldStorage->getAuthMechanism()->getIdentifier()) {
431
+            $this->dbConfig->setAuthBackend($id, $updatedStorage->getAuthMechanism()->getIdentifier());
432
+        }
433
+
434
+        $this->triggerChangeHooks($oldStorage, $updatedStorage);
435
+
436
+        if (($wasGlobal && !$isGlobal) || count($removedGroups) > 0) { // to expensive to properly handle these on the fly
437
+            $this->userMountCache->remoteStorageMounts($this->getStorageId($updatedStorage));
438
+        } else {
439
+            $storageId = $this->getStorageId($updatedStorage);
440
+            foreach ($removedUsers as $userId) {
441
+                $this->userMountCache->removeUserStorageMount($storageId, $userId);
442
+            }
443
+        }
444
+
445
+        return $this->getStorage($id);
446
+    }
447
+
448
+    /**
449
+     * Delete the storage with the given id.
450
+     *
451
+     * @param int $id storage id
452
+     *
453
+     * @throws NotFoundException if no storage was found with the given id
454
+     */
455
+    public function removeStorage($id) {
456
+        $existingMount = $this->dbConfig->getMountById($id);
457
+
458
+        if (!is_array($existingMount)) {
459
+            throw new NotFoundException('Storage with ID "' . $id . '" not found');
460
+        }
461
+
462
+        $this->dbConfig->removeMount($id);
463
+
464
+        $deletedStorage = $this->getStorageConfigFromDBMount($existingMount);
465
+        $this->triggerHooks($deletedStorage, Filesystem::signal_delete_mount);
466
+
467
+        // delete oc_storages entries and oc_filecache
468
+        try {
469
+            $rustyStorageId = $this->getRustyStorageIdFromConfig($deletedStorage);
470
+            \OC\Files\Cache\Storage::remove($rustyStorageId);
471
+        } catch (\Exception $e) {
472
+            // can happen either for invalid configs where the storage could not
473
+            // be instantiated or whenever $user vars where used, in which case
474
+            // the storage id could not be computed
475
+            \OCP\Util::writeLog(
476
+                'files_external',
477
+                'Exception: "' . $e->getMessage() . '"',
478
+                \OCP\Util::ERROR
479
+            );
480
+        }
481
+    }
482
+
483
+    /**
484
+     * Returns the rusty storage id from oc_storages from the given storage config.
485
+     *
486
+     * @param StorageConfig $storageConfig
487
+     * @return string rusty storage id
488
+     */
489
+    private function getRustyStorageIdFromConfig(StorageConfig $storageConfig) {
490
+        // if any of the storage options contains $user, it is not possible
491
+        // to compute the possible storage id as we don't know which users
492
+        // mounted it already (and we certainly don't want to iterate over ALL users)
493
+        foreach ($storageConfig->getBackendOptions() as $value) {
494
+            if (strpos($value, '$user') !== false) {
495
+                throw new \Exception('Cannot compute storage id for deletion due to $user vars in the configuration');
496
+            }
497
+        }
498
+
499
+        // note: similar to ConfigAdapter->prepateStorageConfig()
500
+        $storageConfig->getAuthMechanism()->manipulateStorageConfig($storageConfig);
501
+        $storageConfig->getBackend()->manipulateStorageConfig($storageConfig);
502
+
503
+        $class = $storageConfig->getBackend()->getStorageClass();
504
+        $storageImpl = new $class($storageConfig->getBackendOptions());
505
+
506
+        return $storageImpl->getId();
507
+    }
508
+
509
+    /**
510
+     * Construct the storage implementation
511
+     *
512
+     * @param StorageConfig $storageConfig
513
+     * @return int
514
+     */
515
+    private function getStorageId(StorageConfig $storageConfig) {
516
+        try {
517
+            $class = $storageConfig->getBackend()->getStorageClass();
518
+            /** @var \OC\Files\Storage\Storage $storage */
519
+            $storage = new $class($storageConfig->getBackendOptions());
520
+
521
+            // auth mechanism should fire first
522
+            $storage = $storageConfig->getBackend()->wrapStorage($storage);
523
+            $storage = $storageConfig->getAuthMechanism()->wrapStorage($storage);
524
+
525
+            return $storage->getStorageCache()->getNumericId();
526
+        } catch (\Exception $e) {
527
+            return -1;
528
+        }
529
+    }
530 530
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -70,17 +70,17 @@  discard block
 block discarded – undo
70 70
 	}
71 71
 
72 72
 	protected function getStorageConfigFromDBMount(array $mount) {
73
-		$applicableUsers = array_filter($mount['applicable'], function ($applicable) {
73
+		$applicableUsers = array_filter($mount['applicable'], function($applicable) {
74 74
 			return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_USER;
75 75
 		});
76
-		$applicableUsers = array_map(function ($applicable) {
76
+		$applicableUsers = array_map(function($applicable) {
77 77
 			return $applicable['value'];
78 78
 		}, $applicableUsers);
79 79
 
80
-		$applicableGroups = array_filter($mount['applicable'], function ($applicable) {
80
+		$applicableGroups = array_filter($mount['applicable'], function($applicable) {
81 81
 			return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_GROUP;
82 82
 		});
83
-		$applicableGroups = array_map(function ($applicable) {
83
+		$applicableGroups = array_map(function($applicable) {
84 84
 			return $applicable['value'];
85 85
 		}, $applicableGroups);
86 86
 
@@ -96,20 +96,20 @@  discard block
 block discarded – undo
96 96
 				$mount['priority']
97 97
 			);
98 98
 			$config->setType($mount['type']);
99
-			$config->setId((int)$mount['mount_id']);
99
+			$config->setId((int) $mount['mount_id']);
100 100
 			return $config;
101 101
 		} catch (\UnexpectedValueException $e) {
102 102
 			// don't die if a storage backend doesn't exist
103 103
 			\OCP\Util::writeLog(
104 104
 				'files_external',
105
-				'Could not load storage: "' . $e->getMessage() . '"',
105
+				'Could not load storage: "'.$e->getMessage().'"',
106 106
 				\OCP\Util::ERROR
107 107
 			);
108 108
 			return null;
109 109
 		} catch (\InvalidArgumentException $e) {
110 110
 			\OCP\Util::writeLog(
111 111
 				'files_external',
112
-				'Could not load storage: "' . $e->getMessage() . '"',
112
+				'Could not load storage: "'.$e->getMessage().'"',
113 113
 				\OCP\Util::ERROR
114 114
 			);
115 115
 			return null;
@@ -124,11 +124,11 @@  discard block
 block discarded – undo
124 124
 	protected function readConfig() {
125 125
 		$mounts = $this->readDBConfig();
126 126
 		$configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts);
127
-		$configs = array_filter($configs, function ($config) {
127
+		$configs = array_filter($configs, function($config) {
128 128
 			return $config instanceof StorageConfig;
129 129
 		});
130 130
 
131
-		$keys = array_map(function (StorageConfig $config) {
131
+		$keys = array_map(function(StorageConfig $config) {
132 132
 			return $config->getId();
133 133
 		}, $configs);
134 134
 
@@ -147,14 +147,14 @@  discard block
 block discarded – undo
147 147
 		$mount = $this->dbConfig->getMountById($id);
148 148
 
149 149
 		if (!is_array($mount)) {
150
-			throw new NotFoundException('Storage with ID "' . $id . '" not found');
150
+			throw new NotFoundException('Storage with ID "'.$id.'" not found');
151 151
 		}
152 152
 
153 153
 		$config = $this->getStorageConfigFromDBMount($mount);
154 154
 		if ($this->isApplicable($config)) {
155 155
 			return $config;
156 156
 		} else {
157
-			throw new NotFoundException('Storage with ID "' . $id . '" not found');
157
+			throw new NotFoundException('Storage with ID "'.$id.'" not found');
158 158
 		}
159 159
 	}
160 160
 
@@ -295,11 +295,11 @@  discard block
 block discarded – undo
295 295
 	) {
296 296
 		$backend = $this->backendService->getBackend($backendIdentifier);
297 297
 		if (!$backend) {
298
-			throw new \InvalidArgumentException('Unable to get backend for ' . $backendIdentifier);
298
+			throw new \InvalidArgumentException('Unable to get backend for '.$backendIdentifier);
299 299
 		}
300 300
 		$authMechanism = $this->backendService->getAuthMechanism($authMechanismIdentifier);
301 301
 		if (!$authMechanism) {
302
-			throw new \InvalidArgumentException('Unable to get authentication mechanism for ' . $authMechanismIdentifier);
302
+			throw new \InvalidArgumentException('Unable to get authentication mechanism for '.$authMechanismIdentifier);
303 303
 		}
304 304
 		$newStorage = new StorageConfig();
305 305
 		$newStorage->setMountPoint($mountPoint);
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
 		$existingMount = $this->dbConfig->getMountById($id);
378 378
 
379 379
 		if (!is_array($existingMount)) {
380
-			throw new NotFoundException('Storage with ID "' . $id . '" not found while updating storage');
380
+			throw new NotFoundException('Storage with ID "'.$id.'" not found while updating storage');
381 381
 		}
382 382
 
383 383
 		$oldStorage = $this->getStorageConfigFromDBMount($existingMount);
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
 		$existingMount = $this->dbConfig->getMountById($id);
457 457
 
458 458
 		if (!is_array($existingMount)) {
459
-			throw new NotFoundException('Storage with ID "' . $id . '" not found');
459
+			throw new NotFoundException('Storage with ID "'.$id.'" not found');
460 460
 		}
461 461
 
462 462
 		$this->dbConfig->removeMount($id);
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
 			// the storage id could not be computed
475 475
 			\OCP\Util::writeLog(
476 476
 				'files_external',
477
-				'Exception: "' . $e->getMessage() . '"',
477
+				'Exception: "'.$e->getMessage().'"',
478 478
 				\OCP\Util::ERROR
479 479
 			);
480 480
 		}
Please login to merge, or discard this patch.
apps/files_external/lib/Controller/UserStoragesController.php 2 patches
Indentation   +180 added lines, -180 removed lines patch added patch discarded remove patch
@@ -43,185 +43,185 @@
 block discarded – undo
43 43
  * User storages controller
44 44
  */
45 45
 class UserStoragesController extends StoragesController {
46
-	/**
47
-	 * @var IUserSession
48
-	 */
49
-	private $userSession;
50
-
51
-	/**
52
-	 * Creates a new user storages controller.
53
-	 *
54
-	 * @param string $AppName application name
55
-	 * @param IRequest $request request object
56
-	 * @param IL10N $l10n l10n service
57
-	 * @param UserStoragesService $userStoragesService storage service
58
-	 * @param IUserSession $userSession
59
-	 * @param ILogger $logger
60
-	 */
61
-	public function __construct(
62
-		$AppName,
63
-		IRequest $request,
64
-		IL10N $l10n,
65
-		UserStoragesService $userStoragesService,
66
-		IUserSession $userSession,
67
-		ILogger $logger
68
-	) {
69
-		parent::__construct(
70
-			$AppName,
71
-			$request,
72
-			$l10n,
73
-			$userStoragesService,
74
-			$logger
75
-		);
76
-		$this->userSession = $userSession;
77
-	}
78
-
79
-	protected function manipulateStorageConfig(StorageConfig $storage) {
80
-		/** @var AuthMechanism */
81
-		$authMechanism = $storage->getAuthMechanism();
82
-		$authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser());
83
-		/** @var Backend */
84
-		$backend = $storage->getBackend();
85
-		$backend->manipulateStorageConfig($storage, $this->userSession->getUser());
86
-	}
87
-
88
-	/**
89
-	 * Get all storage entries
90
-	 *
91
-	 * @NoAdminRequired
92
-	 *
93
-	 * @return DataResponse
94
-	 */
95
-	public function index() {
96
-		return parent::index();
97
-	}
98
-
99
-	/**
100
-	 * Return storage
101
-	 *
102
-	 * @NoAdminRequired
103
-	 *
104
-	 * {@inheritdoc}
105
-	 */
106
-	public function show($id, $testOnly = true) {
107
-		return parent::show($id, $testOnly);
108
-	}
109
-
110
-	/**
111
-	 * Create an external storage entry.
112
-	 *
113
-	 * @param string $mountPoint storage mount point
114
-	 * @param string $backend backend identifier
115
-	 * @param string $authMechanism authentication mechanism identifier
116
-	 * @param array $backendOptions backend-specific options
117
-	 * @param array $mountOptions backend-specific mount options
118
-	 *
119
-	 * @return DataResponse
120
-	 *
121
-	 * @NoAdminRequired
122
-	 */
123
-	public function create(
124
-		$mountPoint,
125
-		$backend,
126
-		$authMechanism,
127
-		$backendOptions,
128
-		$mountOptions
129
-	) {
130
-		$newStorage = $this->createStorage(
131
-			$mountPoint,
132
-			$backend,
133
-			$authMechanism,
134
-			$backendOptions,
135
-			$mountOptions
136
-		);
137
-		if ($newStorage instanceOf DataResponse) {
138
-			return $newStorage;
139
-		}
140
-
141
-		$response = $this->validate($newStorage);
142
-		if (!empty($response)) {
143
-			return $response;
144
-		}
145
-
146
-		$newStorage = $this->service->addStorage($newStorage);
147
-		$this->updateStorageStatus($newStorage);
148
-
149
-		return new DataResponse(
150
-			$newStorage,
151
-			Http::STATUS_CREATED
152
-		);
153
-	}
154
-
155
-	/**
156
-	 * Update an external storage entry.
157
-	 *
158
-	 * @param int $id storage id
159
-	 * @param string $mountPoint storage mount point
160
-	 * @param string $backend backend identifier
161
-	 * @param string $authMechanism authentication mechanism identifier
162
-	 * @param array $backendOptions backend-specific options
163
-	 * @param array $mountOptions backend-specific mount options
164
-	 * @param bool $testOnly whether to storage should only test the connection or do more things
165
-	 *
166
-	 * @return DataResponse
167
-	 *
168
-	 * @NoAdminRequired
169
-	 */
170
-	public function update(
171
-		$id,
172
-		$mountPoint,
173
-		$backend,
174
-		$authMechanism,
175
-		$backendOptions,
176
-		$mountOptions,
177
-		$testOnly = true
178
-	) {
179
-		$storage = $this->createStorage(
180
-			$mountPoint,
181
-			$backend,
182
-			$authMechanism,
183
-			$backendOptions,
184
-			$mountOptions
185
-		);
186
-		if ($storage instanceOf DataResponse) {
187
-			return $storage;
188
-		}
189
-		$storage->setId($id);
190
-
191
-		$response = $this->validate($storage);
192
-		if (!empty($response)) {
193
-			return $response;
194
-		}
195
-
196
-		try {
197
-			$storage = $this->service->updateStorage($storage);
198
-		} catch (NotFoundException $e) {
199
-			return new DataResponse(
200
-				[
201
-					'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id))
202
-				],
203
-				Http::STATUS_NOT_FOUND
204
-			);
205
-		}
206
-
207
-		$this->updateStorageStatus($storage, $testOnly);
208
-
209
-		return new DataResponse(
210
-			$storage,
211
-			Http::STATUS_OK
212
-		);
213
-
214
-	}
215
-
216
-	/**
217
-	 * Delete storage
218
-	 *
219
-	 * @NoAdminRequired
220
-	 *
221
-	 * {@inheritdoc}
222
-	 */
223
-	public function destroy($id) {
224
-		return parent::destroy($id);
225
-	}
46
+    /**
47
+     * @var IUserSession
48
+     */
49
+    private $userSession;
50
+
51
+    /**
52
+     * Creates a new user storages controller.
53
+     *
54
+     * @param string $AppName application name
55
+     * @param IRequest $request request object
56
+     * @param IL10N $l10n l10n service
57
+     * @param UserStoragesService $userStoragesService storage service
58
+     * @param IUserSession $userSession
59
+     * @param ILogger $logger
60
+     */
61
+    public function __construct(
62
+        $AppName,
63
+        IRequest $request,
64
+        IL10N $l10n,
65
+        UserStoragesService $userStoragesService,
66
+        IUserSession $userSession,
67
+        ILogger $logger
68
+    ) {
69
+        parent::__construct(
70
+            $AppName,
71
+            $request,
72
+            $l10n,
73
+            $userStoragesService,
74
+            $logger
75
+        );
76
+        $this->userSession = $userSession;
77
+    }
78
+
79
+    protected function manipulateStorageConfig(StorageConfig $storage) {
80
+        /** @var AuthMechanism */
81
+        $authMechanism = $storage->getAuthMechanism();
82
+        $authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser());
83
+        /** @var Backend */
84
+        $backend = $storage->getBackend();
85
+        $backend->manipulateStorageConfig($storage, $this->userSession->getUser());
86
+    }
87
+
88
+    /**
89
+     * Get all storage entries
90
+     *
91
+     * @NoAdminRequired
92
+     *
93
+     * @return DataResponse
94
+     */
95
+    public function index() {
96
+        return parent::index();
97
+    }
98
+
99
+    /**
100
+     * Return storage
101
+     *
102
+     * @NoAdminRequired
103
+     *
104
+     * {@inheritdoc}
105
+     */
106
+    public function show($id, $testOnly = true) {
107
+        return parent::show($id, $testOnly);
108
+    }
109
+
110
+    /**
111
+     * Create an external storage entry.
112
+     *
113
+     * @param string $mountPoint storage mount point
114
+     * @param string $backend backend identifier
115
+     * @param string $authMechanism authentication mechanism identifier
116
+     * @param array $backendOptions backend-specific options
117
+     * @param array $mountOptions backend-specific mount options
118
+     *
119
+     * @return DataResponse
120
+     *
121
+     * @NoAdminRequired
122
+     */
123
+    public function create(
124
+        $mountPoint,
125
+        $backend,
126
+        $authMechanism,
127
+        $backendOptions,
128
+        $mountOptions
129
+    ) {
130
+        $newStorage = $this->createStorage(
131
+            $mountPoint,
132
+            $backend,
133
+            $authMechanism,
134
+            $backendOptions,
135
+            $mountOptions
136
+        );
137
+        if ($newStorage instanceOf DataResponse) {
138
+            return $newStorage;
139
+        }
140
+
141
+        $response = $this->validate($newStorage);
142
+        if (!empty($response)) {
143
+            return $response;
144
+        }
145
+
146
+        $newStorage = $this->service->addStorage($newStorage);
147
+        $this->updateStorageStatus($newStorage);
148
+
149
+        return new DataResponse(
150
+            $newStorage,
151
+            Http::STATUS_CREATED
152
+        );
153
+    }
154
+
155
+    /**
156
+     * Update an external storage entry.
157
+     *
158
+     * @param int $id storage id
159
+     * @param string $mountPoint storage mount point
160
+     * @param string $backend backend identifier
161
+     * @param string $authMechanism authentication mechanism identifier
162
+     * @param array $backendOptions backend-specific options
163
+     * @param array $mountOptions backend-specific mount options
164
+     * @param bool $testOnly whether to storage should only test the connection or do more things
165
+     *
166
+     * @return DataResponse
167
+     *
168
+     * @NoAdminRequired
169
+     */
170
+    public function update(
171
+        $id,
172
+        $mountPoint,
173
+        $backend,
174
+        $authMechanism,
175
+        $backendOptions,
176
+        $mountOptions,
177
+        $testOnly = true
178
+    ) {
179
+        $storage = $this->createStorage(
180
+            $mountPoint,
181
+            $backend,
182
+            $authMechanism,
183
+            $backendOptions,
184
+            $mountOptions
185
+        );
186
+        if ($storage instanceOf DataResponse) {
187
+            return $storage;
188
+        }
189
+        $storage->setId($id);
190
+
191
+        $response = $this->validate($storage);
192
+        if (!empty($response)) {
193
+            return $response;
194
+        }
195
+
196
+        try {
197
+            $storage = $this->service->updateStorage($storage);
198
+        } catch (NotFoundException $e) {
199
+            return new DataResponse(
200
+                [
201
+                    'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id))
202
+                ],
203
+                Http::STATUS_NOT_FOUND
204
+            );
205
+        }
206
+
207
+        $this->updateStorageStatus($storage, $testOnly);
208
+
209
+        return new DataResponse(
210
+            $storage,
211
+            Http::STATUS_OK
212
+        );
213
+
214
+    }
215
+
216
+    /**
217
+     * Delete storage
218
+     *
219
+     * @NoAdminRequired
220
+     *
221
+     * {@inheritdoc}
222
+     */
223
+    public function destroy($id) {
224
+        return parent::destroy($id);
225
+    }
226 226
 
227 227
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -198,7 +198,7 @@
 block discarded – undo
198 198
 		} catch (NotFoundException $e) {
199 199
 			return new DataResponse(
200 200
 				[
201
-					'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id))
201
+					'message' => (string) $this->l10n->t('Storage with ID "%d" not found', array($id))
202 202
 				],
203 203
 				Http::STATUS_NOT_FOUND
204 204
 			);
Please login to merge, or discard this patch.
apps/files_external/lib/Controller/UserGlobalStoragesController.php 2 patches
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -43,165 +43,165 @@
 block discarded – undo
43 43
  * User global storages controller
44 44
  */
45 45
 class UserGlobalStoragesController extends StoragesController {
46
-	/**
47
-	 * @var IUserSession
48
-	 */
49
-	private $userSession;
50
-
51
-	/**
52
-	 * Creates a new user global storages controller.
53
-	 *
54
-	 * @param string $AppName application name
55
-	 * @param IRequest $request request object
56
-	 * @param IL10N $l10n l10n service
57
-	 * @param UserGlobalStoragesService $userGlobalStoragesService storage service
58
-	 * @param IUserSession $userSession
59
-	 */
60
-	public function __construct(
61
-		$AppName,
62
-		IRequest $request,
63
-		IL10N $l10n,
64
-		UserGlobalStoragesService $userGlobalStoragesService,
65
-		IUserSession $userSession,
66
-		ILogger $logger
67
-	) {
68
-		parent::__construct(
69
-			$AppName,
70
-			$request,
71
-			$l10n,
72
-			$userGlobalStoragesService,
73
-			$logger
74
-		);
75
-		$this->userSession = $userSession;
76
-	}
77
-
78
-	/**
79
-	 * Get all storage entries
80
-	 *
81
-	 * @return DataResponse
82
-	 *
83
-	 * @NoAdminRequired
84
-	 */
85
-	public function index() {
86
-		$storages = $this->service->getUniqueStorages();
87
-
88
-		// remove configuration data, this must be kept private
89
-		foreach ($storages as $storage) {
90
-			$this->sanitizeStorage($storage);
91
-		}
92
-
93
-		return new DataResponse(
94
-			$storages,
95
-			Http::STATUS_OK
96
-		);
97
-	}
98
-
99
-	protected function manipulateStorageConfig(StorageConfig $storage) {
100
-		/** @var AuthMechanism */
101
-		$authMechanism = $storage->getAuthMechanism();
102
-		$authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser());
103
-		/** @var Backend */
104
-		$backend = $storage->getBackend();
105
-		$backend->manipulateStorageConfig($storage, $this->userSession->getUser());
106
-	}
107
-
108
-	/**
109
-	 * Get an external storage entry.
110
-	 *
111
-	 * @param int $id storage id
112
-	 * @param bool $testOnly whether to storage should only test the connection or do more things
113
-	 * @return DataResponse
114
-	 *
115
-	 * @NoAdminRequired
116
-	 */
117
-	public function show($id, $testOnly = true) {
118
-		try {
119
-			$storage = $this->service->getStorage($id);
120
-
121
-			$this->updateStorageStatus($storage, $testOnly);
122
-		} catch (NotFoundException $e) {
123
-			return new DataResponse(
124
-				[
125
-					'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id))
126
-				],
127
-				Http::STATUS_NOT_FOUND
128
-			);
129
-		}
130
-
131
-		$this->sanitizeStorage($storage);
132
-
133
-		return new DataResponse(
134
-			$storage,
135
-			Http::STATUS_OK
136
-		);
137
-	}
138
-
139
-	/**
140
-	 * Update an external storage entry.
141
-	 * Only allows setting user provided backend fields
142
-	 *
143
-	 * @param int $id storage id
144
-	 * @param array $backendOptions backend-specific options
145
-	 * @param bool $testOnly whether to storage should only test the connection or do more things
146
-	 *
147
-	 * @return DataResponse
148
-	 *
149
-	 * @NoAdminRequired
150
-	 */
151
-	public function update(
152
-		$id,
153
-		$backendOptions,
154
-		$testOnly = true
155
-	) {
156
-		try {
157
-			$storage = $this->service->getStorage($id);
158
-			$authMechanism = $storage->getAuthMechanism();
159
-			if ($authMechanism instanceof IUserProvided) {
160
-				$authMechanism->saveBackendOptions($this->userSession->getUser(), $id, $backendOptions);
161
-				$authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser());
162
-			} else {
163
-				return new DataResponse(
164
-					[
165
-						'message' => (string)$this->l10n->t('Storage with ID "%i" is not user editable', array($id))
166
-					],
167
-					Http::STATUS_FORBIDDEN
168
-				);
169
-			}
170
-		} catch (NotFoundException $e) {
171
-			return new DataResponse(
172
-				[
173
-					'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id))
174
-				],
175
-				Http::STATUS_NOT_FOUND
176
-			);
177
-		}
178
-
179
-		$this->updateStorageStatus($storage, $testOnly);
180
-		$this->sanitizeStorage($storage);
181
-
182
-		return new DataResponse(
183
-			$storage,
184
-			Http::STATUS_OK
185
-		);
186
-
187
-	}
188
-
189
-	/**
190
-	 * Remove sensitive data from a StorageConfig before returning it to the user
191
-	 *
192
-	 * @param StorageConfig $storage
193
-	 */
194
-	protected function sanitizeStorage(StorageConfig $storage) {
195
-		$storage->setBackendOptions([]);
196
-		$storage->setMountOptions([]);
197
-
198
-		if ($storage->getAuthMechanism() instanceof IUserProvided) {
199
-			try {
200
-				$storage->getAuthMechanism()->manipulateStorageConfig($storage, $this->userSession->getUser());
201
-			} catch (InsufficientDataForMeaningfulAnswerException $e) {
202
-				// not configured yet
203
-			}
204
-		}
205
-	}
46
+    /**
47
+     * @var IUserSession
48
+     */
49
+    private $userSession;
50
+
51
+    /**
52
+     * Creates a new user global storages controller.
53
+     *
54
+     * @param string $AppName application name
55
+     * @param IRequest $request request object
56
+     * @param IL10N $l10n l10n service
57
+     * @param UserGlobalStoragesService $userGlobalStoragesService storage service
58
+     * @param IUserSession $userSession
59
+     */
60
+    public function __construct(
61
+        $AppName,
62
+        IRequest $request,
63
+        IL10N $l10n,
64
+        UserGlobalStoragesService $userGlobalStoragesService,
65
+        IUserSession $userSession,
66
+        ILogger $logger
67
+    ) {
68
+        parent::__construct(
69
+            $AppName,
70
+            $request,
71
+            $l10n,
72
+            $userGlobalStoragesService,
73
+            $logger
74
+        );
75
+        $this->userSession = $userSession;
76
+    }
77
+
78
+    /**
79
+     * Get all storage entries
80
+     *
81
+     * @return DataResponse
82
+     *
83
+     * @NoAdminRequired
84
+     */
85
+    public function index() {
86
+        $storages = $this->service->getUniqueStorages();
87
+
88
+        // remove configuration data, this must be kept private
89
+        foreach ($storages as $storage) {
90
+            $this->sanitizeStorage($storage);
91
+        }
92
+
93
+        return new DataResponse(
94
+            $storages,
95
+            Http::STATUS_OK
96
+        );
97
+    }
98
+
99
+    protected function manipulateStorageConfig(StorageConfig $storage) {
100
+        /** @var AuthMechanism */
101
+        $authMechanism = $storage->getAuthMechanism();
102
+        $authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser());
103
+        /** @var Backend */
104
+        $backend = $storage->getBackend();
105
+        $backend->manipulateStorageConfig($storage, $this->userSession->getUser());
106
+    }
107
+
108
+    /**
109
+     * Get an external storage entry.
110
+     *
111
+     * @param int $id storage id
112
+     * @param bool $testOnly whether to storage should only test the connection or do more things
113
+     * @return DataResponse
114
+     *
115
+     * @NoAdminRequired
116
+     */
117
+    public function show($id, $testOnly = true) {
118
+        try {
119
+            $storage = $this->service->getStorage($id);
120
+
121
+            $this->updateStorageStatus($storage, $testOnly);
122
+        } catch (NotFoundException $e) {
123
+            return new DataResponse(
124
+                [
125
+                    'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id))
126
+                ],
127
+                Http::STATUS_NOT_FOUND
128
+            );
129
+        }
130
+
131
+        $this->sanitizeStorage($storage);
132
+
133
+        return new DataResponse(
134
+            $storage,
135
+            Http::STATUS_OK
136
+        );
137
+    }
138
+
139
+    /**
140
+     * Update an external storage entry.
141
+     * Only allows setting user provided backend fields
142
+     *
143
+     * @param int $id storage id
144
+     * @param array $backendOptions backend-specific options
145
+     * @param bool $testOnly whether to storage should only test the connection or do more things
146
+     *
147
+     * @return DataResponse
148
+     *
149
+     * @NoAdminRequired
150
+     */
151
+    public function update(
152
+        $id,
153
+        $backendOptions,
154
+        $testOnly = true
155
+    ) {
156
+        try {
157
+            $storage = $this->service->getStorage($id);
158
+            $authMechanism = $storage->getAuthMechanism();
159
+            if ($authMechanism instanceof IUserProvided) {
160
+                $authMechanism->saveBackendOptions($this->userSession->getUser(), $id, $backendOptions);
161
+                $authMechanism->manipulateStorageConfig($storage, $this->userSession->getUser());
162
+            } else {
163
+                return new DataResponse(
164
+                    [
165
+                        'message' => (string)$this->l10n->t('Storage with ID "%i" is not user editable', array($id))
166
+                    ],
167
+                    Http::STATUS_FORBIDDEN
168
+                );
169
+            }
170
+        } catch (NotFoundException $e) {
171
+            return new DataResponse(
172
+                [
173
+                    'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id))
174
+                ],
175
+                Http::STATUS_NOT_FOUND
176
+            );
177
+        }
178
+
179
+        $this->updateStorageStatus($storage, $testOnly);
180
+        $this->sanitizeStorage($storage);
181
+
182
+        return new DataResponse(
183
+            $storage,
184
+            Http::STATUS_OK
185
+        );
186
+
187
+    }
188
+
189
+    /**
190
+     * Remove sensitive data from a StorageConfig before returning it to the user
191
+     *
192
+     * @param StorageConfig $storage
193
+     */
194
+    protected function sanitizeStorage(StorageConfig $storage) {
195
+        $storage->setBackendOptions([]);
196
+        $storage->setMountOptions([]);
197
+
198
+        if ($storage->getAuthMechanism() instanceof IUserProvided) {
199
+            try {
200
+                $storage->getAuthMechanism()->manipulateStorageConfig($storage, $this->userSession->getUser());
201
+            } catch (InsufficientDataForMeaningfulAnswerException $e) {
202
+                // not configured yet
203
+            }
204
+        }
205
+    }
206 206
 
207 207
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 		} catch (NotFoundException $e) {
123 123
 			return new DataResponse(
124 124
 				[
125
-					'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id))
125
+					'message' => (string) $this->l10n->t('Storage with ID "%d" not found', array($id))
126 126
 				],
127 127
 				Http::STATUS_NOT_FOUND
128 128
 			);
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 			} else {
163 163
 				return new DataResponse(
164 164
 					[
165
-						'message' => (string)$this->l10n->t('Storage with ID "%i" is not user editable', array($id))
165
+						'message' => (string) $this->l10n->t('Storage with ID "%i" is not user editable', array($id))
166 166
 					],
167 167
 					Http::STATUS_FORBIDDEN
168 168
 				);
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 		} catch (NotFoundException $e) {
171 171
 			return new DataResponse(
172 172
 				[
173
-					'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id))
173
+					'message' => (string) $this->l10n->t('Storage with ID "%d" not found', array($id))
174 174
 				],
175 175
 				Http::STATUS_NOT_FOUND
176 176
 			);
Please login to merge, or discard this patch.
apps/files_external/lib/Controller/GlobalStoragesController.php 2 patches
Indentation   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -39,151 +39,151 @@
 block discarded – undo
39 39
  * Global storages controller
40 40
  */
41 41
 class GlobalStoragesController extends StoragesController {
42
-	/**
43
-	 * Creates a new global storages controller.
44
-	 *
45
-	 * @param string $AppName application name
46
-	 * @param IRequest $request request object
47
-	 * @param IL10N $l10n l10n service
48
-	 * @param GlobalStoragesService $globalStoragesService storage service
49
-	 * @param ILogger $logger
50
-	 */
51
-	public function __construct(
52
-		$AppName,
53
-		IRequest $request,
54
-		IL10N $l10n,
55
-		GlobalStoragesService $globalStoragesService,
56
-		ILogger $logger
57
-	) {
58
-		parent::__construct(
59
-			$AppName,
60
-			$request,
61
-			$l10n,
62
-			$globalStoragesService,
63
-			$logger
64
-		);
65
-	}
66
-
67
-	/**
68
-	 * Create an external storage entry.
69
-	 *
70
-	 * @param string $mountPoint storage mount point
71
-	 * @param string $backend backend identifier
72
-	 * @param string $authMechanism authentication mechanism identifier
73
-	 * @param array $backendOptions backend-specific options
74
-	 * @param array $mountOptions mount-specific options
75
-	 * @param array $applicableUsers users for which to mount the storage
76
-	 * @param array $applicableGroups groups for which to mount the storage
77
-	 * @param int $priority priority
78
-	 *
79
-	 * @return DataResponse
80
-	 */
81
-	public function create(
82
-		$mountPoint,
83
-		$backend,
84
-		$authMechanism,
85
-		$backendOptions,
86
-		$mountOptions,
87
-		$applicableUsers,
88
-		$applicableGroups,
89
-		$priority
90
-	) {
91
-		$newStorage = $this->createStorage(
92
-			$mountPoint,
93
-			$backend,
94
-			$authMechanism,
95
-			$backendOptions,
96
-			$mountOptions,
97
-			$applicableUsers,
98
-			$applicableGroups,
99
-			$priority
100
-		);
101
-		if ($newStorage instanceof DataResponse) {
102
-			return $newStorage;
103
-		}
104
-
105
-		$response = $this->validate($newStorage);
106
-		if (!empty($response)) {
107
-			return $response;
108
-		}
109
-
110
-		$newStorage = $this->service->addStorage($newStorage);
111
-
112
-		$this->updateStorageStatus($newStorage);
113
-
114
-		return new DataResponse(
115
-			$newStorage,
116
-			Http::STATUS_CREATED
117
-		);
118
-	}
119
-
120
-	/**
121
-	 * Update an external storage entry.
122
-	 *
123
-	 * @param int $id storage id
124
-	 * @param string $mountPoint storage mount point
125
-	 * @param string $backend backend identifier
126
-	 * @param string $authMechanism authentication mechansim identifier
127
-	 * @param array $backendOptions backend-specific options
128
-	 * @param array $mountOptions mount-specific options
129
-	 * @param array $applicableUsers users for which to mount the storage
130
-	 * @param array $applicableGroups groups for which to mount the storage
131
-	 * @param int $priority priority
132
-	 * @param bool $testOnly whether to storage should only test the connection or do more things
133
-	 *
134
-	 * @return DataResponse
135
-	 */
136
-	public function update(
137
-		$id,
138
-		$mountPoint,
139
-		$backend,
140
-		$authMechanism,
141
-		$backendOptions,
142
-		$mountOptions,
143
-		$applicableUsers,
144
-		$applicableGroups,
145
-		$priority,
146
-		$testOnly = true
147
-	) {
148
-		$storage = $this->createStorage(
149
-			$mountPoint,
150
-			$backend,
151
-			$authMechanism,
152
-			$backendOptions,
153
-			$mountOptions,
154
-			$applicableUsers,
155
-			$applicableGroups,
156
-			$priority
157
-		);
158
-		if ($storage instanceof DataResponse) {
159
-			return $storage;
160
-		}
161
-		$storage->setId($id);
162
-
163
-		$response = $this->validate($storage);
164
-		if (!empty($response)) {
165
-			return $response;
166
-		}
167
-
168
-		try {
169
-			$storage = $this->service->updateStorage($storage);
170
-		} catch (NotFoundException $e) {
171
-			return new DataResponse(
172
-				[
173
-					'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id))
174
-				],
175
-				Http::STATUS_NOT_FOUND
176
-			);
177
-		}
178
-
179
-		$this->updateStorageStatus($storage, $testOnly);
180
-
181
-		return new DataResponse(
182
-			$storage,
183
-			Http::STATUS_OK
184
-		);
185
-
186
-	}
42
+    /**
43
+     * Creates a new global storages controller.
44
+     *
45
+     * @param string $AppName application name
46
+     * @param IRequest $request request object
47
+     * @param IL10N $l10n l10n service
48
+     * @param GlobalStoragesService $globalStoragesService storage service
49
+     * @param ILogger $logger
50
+     */
51
+    public function __construct(
52
+        $AppName,
53
+        IRequest $request,
54
+        IL10N $l10n,
55
+        GlobalStoragesService $globalStoragesService,
56
+        ILogger $logger
57
+    ) {
58
+        parent::__construct(
59
+            $AppName,
60
+            $request,
61
+            $l10n,
62
+            $globalStoragesService,
63
+            $logger
64
+        );
65
+    }
66
+
67
+    /**
68
+     * Create an external storage entry.
69
+     *
70
+     * @param string $mountPoint storage mount point
71
+     * @param string $backend backend identifier
72
+     * @param string $authMechanism authentication mechanism identifier
73
+     * @param array $backendOptions backend-specific options
74
+     * @param array $mountOptions mount-specific options
75
+     * @param array $applicableUsers users for which to mount the storage
76
+     * @param array $applicableGroups groups for which to mount the storage
77
+     * @param int $priority priority
78
+     *
79
+     * @return DataResponse
80
+     */
81
+    public function create(
82
+        $mountPoint,
83
+        $backend,
84
+        $authMechanism,
85
+        $backendOptions,
86
+        $mountOptions,
87
+        $applicableUsers,
88
+        $applicableGroups,
89
+        $priority
90
+    ) {
91
+        $newStorage = $this->createStorage(
92
+            $mountPoint,
93
+            $backend,
94
+            $authMechanism,
95
+            $backendOptions,
96
+            $mountOptions,
97
+            $applicableUsers,
98
+            $applicableGroups,
99
+            $priority
100
+        );
101
+        if ($newStorage instanceof DataResponse) {
102
+            return $newStorage;
103
+        }
104
+
105
+        $response = $this->validate($newStorage);
106
+        if (!empty($response)) {
107
+            return $response;
108
+        }
109
+
110
+        $newStorage = $this->service->addStorage($newStorage);
111
+
112
+        $this->updateStorageStatus($newStorage);
113
+
114
+        return new DataResponse(
115
+            $newStorage,
116
+            Http::STATUS_CREATED
117
+        );
118
+    }
119
+
120
+    /**
121
+     * Update an external storage entry.
122
+     *
123
+     * @param int $id storage id
124
+     * @param string $mountPoint storage mount point
125
+     * @param string $backend backend identifier
126
+     * @param string $authMechanism authentication mechansim identifier
127
+     * @param array $backendOptions backend-specific options
128
+     * @param array $mountOptions mount-specific options
129
+     * @param array $applicableUsers users for which to mount the storage
130
+     * @param array $applicableGroups groups for which to mount the storage
131
+     * @param int $priority priority
132
+     * @param bool $testOnly whether to storage should only test the connection or do more things
133
+     *
134
+     * @return DataResponse
135
+     */
136
+    public function update(
137
+        $id,
138
+        $mountPoint,
139
+        $backend,
140
+        $authMechanism,
141
+        $backendOptions,
142
+        $mountOptions,
143
+        $applicableUsers,
144
+        $applicableGroups,
145
+        $priority,
146
+        $testOnly = true
147
+    ) {
148
+        $storage = $this->createStorage(
149
+            $mountPoint,
150
+            $backend,
151
+            $authMechanism,
152
+            $backendOptions,
153
+            $mountOptions,
154
+            $applicableUsers,
155
+            $applicableGroups,
156
+            $priority
157
+        );
158
+        if ($storage instanceof DataResponse) {
159
+            return $storage;
160
+        }
161
+        $storage->setId($id);
162
+
163
+        $response = $this->validate($storage);
164
+        if (!empty($response)) {
165
+            return $response;
166
+        }
167
+
168
+        try {
169
+            $storage = $this->service->updateStorage($storage);
170
+        } catch (NotFoundException $e) {
171
+            return new DataResponse(
172
+                [
173
+                    'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id))
174
+                ],
175
+                Http::STATUS_NOT_FOUND
176
+            );
177
+        }
178
+
179
+        $this->updateStorageStatus($storage, $testOnly);
180
+
181
+        return new DataResponse(
182
+            $storage,
183
+            Http::STATUS_OK
184
+        );
185
+
186
+    }
187 187
 
188 188
 
189 189
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -170,7 +170,7 @@
 block discarded – undo
170 170
 		} catch (NotFoundException $e) {
171 171
 			return new DataResponse(
172 172
 				[
173
-					'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id))
173
+					'message' => (string) $this->l10n->t('Storage with ID "%d" not found', array($id))
174 174
 				],
175 175
 				Http::STATUS_NOT_FOUND
176 176
 			);
Please login to merge, or discard this patch.
apps/files_external/lib/Controller/StoragesController.php 2 patches
Indentation   +272 added lines, -272 removed lines patch added patch discarded remove patch
@@ -47,298 +47,298 @@
 block discarded – undo
47 47
  */
48 48
 abstract class StoragesController extends Controller {
49 49
 
50
-	/**
51
-	 * L10N service
52
-	 *
53
-	 * @var IL10N
54
-	 */
55
-	protected $l10n;
50
+    /**
51
+     * L10N service
52
+     *
53
+     * @var IL10N
54
+     */
55
+    protected $l10n;
56 56
 
57
-	/**
58
-	 * Storages service
59
-	 *
60
-	 * @var StoragesService
61
-	 */
62
-	protected $service;
57
+    /**
58
+     * Storages service
59
+     *
60
+     * @var StoragesService
61
+     */
62
+    protected $service;
63 63
 
64
-	/**
65
-	 * @var ILogger
66
-	 */
67
-	protected $logger;
64
+    /**
65
+     * @var ILogger
66
+     */
67
+    protected $logger;
68 68
 
69
-	/**
70
-	 * Creates a new storages controller.
71
-	 *
72
-	 * @param string $AppName application name
73
-	 * @param IRequest $request request object
74
-	 * @param IL10N $l10n l10n service
75
-	 * @param StoragesService $storagesService storage service
76
-	 * @param ILogger $logger
77
-	 */
78
-	public function __construct(
79
-		$AppName,
80
-		IRequest $request,
81
-		IL10N $l10n,
82
-		StoragesService $storagesService,
83
-		ILogger $logger
84
-	) {
85
-		parent::__construct($AppName, $request);
86
-		$this->l10n = $l10n;
87
-		$this->service = $storagesService;
88
-		$this->logger = $logger;
89
-	}
69
+    /**
70
+     * Creates a new storages controller.
71
+     *
72
+     * @param string $AppName application name
73
+     * @param IRequest $request request object
74
+     * @param IL10N $l10n l10n service
75
+     * @param StoragesService $storagesService storage service
76
+     * @param ILogger $logger
77
+     */
78
+    public function __construct(
79
+        $AppName,
80
+        IRequest $request,
81
+        IL10N $l10n,
82
+        StoragesService $storagesService,
83
+        ILogger $logger
84
+    ) {
85
+        parent::__construct($AppName, $request);
86
+        $this->l10n = $l10n;
87
+        $this->service = $storagesService;
88
+        $this->logger = $logger;
89
+    }
90 90
 
91
-	/**
92
-	 * Create a storage from its parameters
93
-	 *
94
-	 * @param string $mountPoint storage mount point
95
-	 * @param string $backend backend identifier
96
-	 * @param string $authMechanism authentication mechanism identifier
97
-	 * @param array $backendOptions backend-specific options
98
-	 * @param array|null $mountOptions mount-specific options
99
-	 * @param array|null $applicableUsers users for which to mount the storage
100
-	 * @param array|null $applicableGroups groups for which to mount the storage
101
-	 * @param int|null $priority priority
102
-	 *
103
-	 * @return StorageConfig|DataResponse
104
-	 */
105
-	protected function createStorage(
106
-		$mountPoint,
107
-		$backend,
108
-		$authMechanism,
109
-		$backendOptions,
110
-		$mountOptions = null,
111
-		$applicableUsers = null,
112
-		$applicableGroups = null,
113
-		$priority = null
114
-	) {
115
-		try {
116
-			return $this->service->createStorage(
117
-				$mountPoint,
118
-				$backend,
119
-				$authMechanism,
120
-				$backendOptions,
121
-				$mountOptions,
122
-				$applicableUsers,
123
-				$applicableGroups,
124
-				$priority
125
-			);
126
-		} catch (\InvalidArgumentException $e) {
127
-			$this->logger->logException($e);
128
-			return new DataResponse(
129
-				[
130
-					'message' => (string)$this->l10n->t('Invalid backend or authentication mechanism class')
131
-				],
132
-				Http::STATUS_UNPROCESSABLE_ENTITY
133
-			);
134
-		}
135
-	}
91
+    /**
92
+     * Create a storage from its parameters
93
+     *
94
+     * @param string $mountPoint storage mount point
95
+     * @param string $backend backend identifier
96
+     * @param string $authMechanism authentication mechanism identifier
97
+     * @param array $backendOptions backend-specific options
98
+     * @param array|null $mountOptions mount-specific options
99
+     * @param array|null $applicableUsers users for which to mount the storage
100
+     * @param array|null $applicableGroups groups for which to mount the storage
101
+     * @param int|null $priority priority
102
+     *
103
+     * @return StorageConfig|DataResponse
104
+     */
105
+    protected function createStorage(
106
+        $mountPoint,
107
+        $backend,
108
+        $authMechanism,
109
+        $backendOptions,
110
+        $mountOptions = null,
111
+        $applicableUsers = null,
112
+        $applicableGroups = null,
113
+        $priority = null
114
+    ) {
115
+        try {
116
+            return $this->service->createStorage(
117
+                $mountPoint,
118
+                $backend,
119
+                $authMechanism,
120
+                $backendOptions,
121
+                $mountOptions,
122
+                $applicableUsers,
123
+                $applicableGroups,
124
+                $priority
125
+            );
126
+        } catch (\InvalidArgumentException $e) {
127
+            $this->logger->logException($e);
128
+            return new DataResponse(
129
+                [
130
+                    'message' => (string)$this->l10n->t('Invalid backend or authentication mechanism class')
131
+                ],
132
+                Http::STATUS_UNPROCESSABLE_ENTITY
133
+            );
134
+        }
135
+    }
136 136
 
137
-	/**
138
-	 * Validate storage config
139
-	 *
140
-	 * @param StorageConfig $storage storage config
141
-	 *1
142
-	 * @return DataResponse|null returns response in case of validation error
143
-	 */
144
-	protected function validate(StorageConfig $storage) {
145
-		$mountPoint = $storage->getMountPoint();
146
-		if ($mountPoint === '') {
147
-			return new DataResponse(
148
-				array(
149
-					'message' => (string)$this->l10n->t('Invalid mount point')
150
-				),
151
-				Http::STATUS_UNPROCESSABLE_ENTITY
152
-			);
153
-		}
137
+    /**
138
+     * Validate storage config
139
+     *
140
+     * @param StorageConfig $storage storage config
141
+     *1
142
+     * @return DataResponse|null returns response in case of validation error
143
+     */
144
+    protected function validate(StorageConfig $storage) {
145
+        $mountPoint = $storage->getMountPoint();
146
+        if ($mountPoint === '') {
147
+            return new DataResponse(
148
+                array(
149
+                    'message' => (string)$this->l10n->t('Invalid mount point')
150
+                ),
151
+                Http::STATUS_UNPROCESSABLE_ENTITY
152
+            );
153
+        }
154 154
 
155
-		if ($storage->getBackendOption('objectstore')) {
156
-			// objectstore must not be sent from client side
157
-			return new DataResponse(
158
-				array(
159
-					'message' => (string)$this->l10n->t('Objectstore forbidden')
160
-				),
161
-				Http::STATUS_UNPROCESSABLE_ENTITY
162
-			);
163
-		}
155
+        if ($storage->getBackendOption('objectstore')) {
156
+            // objectstore must not be sent from client side
157
+            return new DataResponse(
158
+                array(
159
+                    'message' => (string)$this->l10n->t('Objectstore forbidden')
160
+                ),
161
+                Http::STATUS_UNPROCESSABLE_ENTITY
162
+            );
163
+        }
164 164
 
165
-		/** @var Backend */
166
-		$backend = $storage->getBackend();
167
-		/** @var AuthMechanism */
168
-		$authMechanism = $storage->getAuthMechanism();
169
-		if ($backend->checkDependencies()) {
170
-			// invalid backend
171
-			return new DataResponse(
172
-				array(
173
-					'message' => (string)$this->l10n->t('Invalid storage backend "%s"', [
174
-						$backend->getIdentifier()
175
-					])
176
-				),
177
-				Http::STATUS_UNPROCESSABLE_ENTITY
178
-			);
179
-		}
165
+        /** @var Backend */
166
+        $backend = $storage->getBackend();
167
+        /** @var AuthMechanism */
168
+        $authMechanism = $storage->getAuthMechanism();
169
+        if ($backend->checkDependencies()) {
170
+            // invalid backend
171
+            return new DataResponse(
172
+                array(
173
+                    'message' => (string)$this->l10n->t('Invalid storage backend "%s"', [
174
+                        $backend->getIdentifier()
175
+                    ])
176
+                ),
177
+                Http::STATUS_UNPROCESSABLE_ENTITY
178
+            );
179
+        }
180 180
 
181
-		if (!$backend->isVisibleFor($this->service->getVisibilityType())) {
182
-			// not permitted to use backend
183
-			return new DataResponse(
184
-				array(
185
-					'message' => (string)$this->l10n->t('Not permitted to use backend "%s"', [
186
-						$backend->getIdentifier()
187
-					])
188
-				),
189
-				Http::STATUS_UNPROCESSABLE_ENTITY
190
-			);
191
-		}
192
-		if (!$authMechanism->isVisibleFor($this->service->getVisibilityType())) {
193
-			// not permitted to use auth mechanism
194
-			return new DataResponse(
195
-				array(
196
-					'message' => (string)$this->l10n->t('Not permitted to use authentication mechanism "%s"', [
197
-						$authMechanism->getIdentifier()
198
-					])
199
-				),
200
-				Http::STATUS_UNPROCESSABLE_ENTITY
201
-			);
202
-		}
181
+        if (!$backend->isVisibleFor($this->service->getVisibilityType())) {
182
+            // not permitted to use backend
183
+            return new DataResponse(
184
+                array(
185
+                    'message' => (string)$this->l10n->t('Not permitted to use backend "%s"', [
186
+                        $backend->getIdentifier()
187
+                    ])
188
+                ),
189
+                Http::STATUS_UNPROCESSABLE_ENTITY
190
+            );
191
+        }
192
+        if (!$authMechanism->isVisibleFor($this->service->getVisibilityType())) {
193
+            // not permitted to use auth mechanism
194
+            return new DataResponse(
195
+                array(
196
+                    'message' => (string)$this->l10n->t('Not permitted to use authentication mechanism "%s"', [
197
+                        $authMechanism->getIdentifier()
198
+                    ])
199
+                ),
200
+                Http::STATUS_UNPROCESSABLE_ENTITY
201
+            );
202
+        }
203 203
 
204
-		if (!$backend->validateStorage($storage)) {
205
-			// unsatisfied parameters
206
-			return new DataResponse(
207
-				array(
208
-					'message' => (string)$this->l10n->t('Unsatisfied backend parameters')
209
-				),
210
-				Http::STATUS_UNPROCESSABLE_ENTITY
211
-			);
212
-		}
213
-		if (!$authMechanism->validateStorage($storage)) {
214
-			// unsatisfied parameters
215
-			return new DataResponse(
216
-				[
217
-					'message' => (string)$this->l10n->t('Unsatisfied authentication mechanism parameters')
218
-				],
219
-				Http::STATUS_UNPROCESSABLE_ENTITY
220
-			);
221
-		}
204
+        if (!$backend->validateStorage($storage)) {
205
+            // unsatisfied parameters
206
+            return new DataResponse(
207
+                array(
208
+                    'message' => (string)$this->l10n->t('Unsatisfied backend parameters')
209
+                ),
210
+                Http::STATUS_UNPROCESSABLE_ENTITY
211
+            );
212
+        }
213
+        if (!$authMechanism->validateStorage($storage)) {
214
+            // unsatisfied parameters
215
+            return new DataResponse(
216
+                [
217
+                    'message' => (string)$this->l10n->t('Unsatisfied authentication mechanism parameters')
218
+                ],
219
+                Http::STATUS_UNPROCESSABLE_ENTITY
220
+            );
221
+        }
222 222
 
223
-		return null;
224
-	}
223
+        return null;
224
+    }
225 225
 
226
-	protected function manipulateStorageConfig(StorageConfig $storage) {
227
-		/** @var AuthMechanism */
228
-		$authMechanism = $storage->getAuthMechanism();
229
-		$authMechanism->manipulateStorageConfig($storage);
230
-		/** @var Backend */
231
-		$backend = $storage->getBackend();
232
-		$backend->manipulateStorageConfig($storage);
233
-	}
226
+    protected function manipulateStorageConfig(StorageConfig $storage) {
227
+        /** @var AuthMechanism */
228
+        $authMechanism = $storage->getAuthMechanism();
229
+        $authMechanism->manipulateStorageConfig($storage);
230
+        /** @var Backend */
231
+        $backend = $storage->getBackend();
232
+        $backend->manipulateStorageConfig($storage);
233
+    }
234 234
 
235
-	/**
236
-	 * Check whether the given storage is available / valid.
237
-	 *
238
-	 * Note that this operation can be time consuming depending
239
-	 * on whether the remote storage is available or not.
240
-	 *
241
-	 * @param StorageConfig $storage storage configuration
242
-	 * @param bool $testOnly whether to storage should only test the connection or do more things
243
-	 */
244
-	protected function updateStorageStatus(StorageConfig &$storage, $testOnly = true) {
245
-		try {
246
-			$this->manipulateStorageConfig($storage);
235
+    /**
236
+     * Check whether the given storage is available / valid.
237
+     *
238
+     * Note that this operation can be time consuming depending
239
+     * on whether the remote storage is available or not.
240
+     *
241
+     * @param StorageConfig $storage storage configuration
242
+     * @param bool $testOnly whether to storage should only test the connection or do more things
243
+     */
244
+    protected function updateStorageStatus(StorageConfig &$storage, $testOnly = true) {
245
+        try {
246
+            $this->manipulateStorageConfig($storage);
247 247
 
248
-			/** @var Backend */
249
-			$backend = $storage->getBackend();
250
-			// update status (can be time-consuming)
251
-			$storage->setStatus(
252
-				\OC_Mount_Config::getBackendStatus(
253
-					$backend->getStorageClass(),
254
-					$storage->getBackendOptions(),
255
-					false,
256
-					$testOnly
257
-				)
258
-			);
259
-		} catch (InsufficientDataForMeaningfulAnswerException $e) {
260
-			$status = $e->getCode() ? $e->getCode() : StorageNotAvailableException::STATUS_INDETERMINATE;
261
-			$storage->setStatus(
262
-				$status,
263
-				$this->l10n->t('Insufficient data: %s', [$e->getMessage()])
264
-			);
265
-		} catch (StorageNotAvailableException $e) {
266
-			$storage->setStatus(
267
-				$e->getCode(),
268
-				$this->l10n->t('%s', [$e->getMessage()])
269
-			);
270
-		} catch (\Exception $e) {
271
-			// FIXME: convert storage exceptions to StorageNotAvailableException
272
-			$storage->setStatus(
273
-				StorageNotAvailableException::STATUS_ERROR,
274
-				get_class($e).': '.$e->getMessage()
275
-			);
276
-		}
277
-	}
248
+            /** @var Backend */
249
+            $backend = $storage->getBackend();
250
+            // update status (can be time-consuming)
251
+            $storage->setStatus(
252
+                \OC_Mount_Config::getBackendStatus(
253
+                    $backend->getStorageClass(),
254
+                    $storage->getBackendOptions(),
255
+                    false,
256
+                    $testOnly
257
+                )
258
+            );
259
+        } catch (InsufficientDataForMeaningfulAnswerException $e) {
260
+            $status = $e->getCode() ? $e->getCode() : StorageNotAvailableException::STATUS_INDETERMINATE;
261
+            $storage->setStatus(
262
+                $status,
263
+                $this->l10n->t('Insufficient data: %s', [$e->getMessage()])
264
+            );
265
+        } catch (StorageNotAvailableException $e) {
266
+            $storage->setStatus(
267
+                $e->getCode(),
268
+                $this->l10n->t('%s', [$e->getMessage()])
269
+            );
270
+        } catch (\Exception $e) {
271
+            // FIXME: convert storage exceptions to StorageNotAvailableException
272
+            $storage->setStatus(
273
+                StorageNotAvailableException::STATUS_ERROR,
274
+                get_class($e).': '.$e->getMessage()
275
+            );
276
+        }
277
+    }
278 278
 
279
-	/**
280
-	 * Get all storage entries
281
-	 *
282
-	 * @return DataResponse
283
-	 */
284
-	public function index() {
285
-		$storages = $this->service->getStorages();
279
+    /**
280
+     * Get all storage entries
281
+     *
282
+     * @return DataResponse
283
+     */
284
+    public function index() {
285
+        $storages = $this->service->getStorages();
286 286
 
287
-		return new DataResponse(
288
-			$storages,
289
-			Http::STATUS_OK
290
-		);
291
-	}
287
+        return new DataResponse(
288
+            $storages,
289
+            Http::STATUS_OK
290
+        );
291
+    }
292 292
 
293
-	/**
294
-	 * Get an external storage entry.
295
-	 *
296
-	 * @param int $id storage id
297
-	 * @param bool $testOnly whether to storage should only test the connection or do more things
298
-	 *
299
-	 * @return DataResponse
300
-	 */
301
-	public function show($id, $testOnly = true) {
302
-		try {
303
-			$storage = $this->service->getStorage($id);
293
+    /**
294
+     * Get an external storage entry.
295
+     *
296
+     * @param int $id storage id
297
+     * @param bool $testOnly whether to storage should only test the connection or do more things
298
+     *
299
+     * @return DataResponse
300
+     */
301
+    public function show($id, $testOnly = true) {
302
+        try {
303
+            $storage = $this->service->getStorage($id);
304 304
 
305
-			$this->updateStorageStatus($storage, $testOnly);
306
-		} catch (NotFoundException $e) {
307
-			return new DataResponse(
308
-				[
309
-					'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id))
310
-				],
311
-				Http::STATUS_NOT_FOUND
312
-			);
313
-		}
305
+            $this->updateStorageStatus($storage, $testOnly);
306
+        } catch (NotFoundException $e) {
307
+            return new DataResponse(
308
+                [
309
+                    'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id))
310
+                ],
311
+                Http::STATUS_NOT_FOUND
312
+            );
313
+        }
314 314
 
315
-		return new DataResponse(
316
-			$storage,
317
-			Http::STATUS_OK
318
-		);
319
-	}
315
+        return new DataResponse(
316
+            $storage,
317
+            Http::STATUS_OK
318
+        );
319
+    }
320 320
 
321
-	/**
322
-	 * Deletes the storage with the given id.
323
-	 *
324
-	 * @param int $id storage id
325
-	 *
326
-	 * @return DataResponse
327
-	 */
328
-	public function destroy($id) {
329
-		try {
330
-			$this->service->removeStorage($id);
331
-		} catch (NotFoundException $e) {
332
-			return new DataResponse(
333
-				[
334
-					'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id))
335
-				],
336
-				Http::STATUS_NOT_FOUND
337
-			);
338
-		}
321
+    /**
322
+     * Deletes the storage with the given id.
323
+     *
324
+     * @param int $id storage id
325
+     *
326
+     * @return DataResponse
327
+     */
328
+    public function destroy($id) {
329
+        try {
330
+            $this->service->removeStorage($id);
331
+        } catch (NotFoundException $e) {
332
+            return new DataResponse(
333
+                [
334
+                    'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id))
335
+                ],
336
+                Http::STATUS_NOT_FOUND
337
+            );
338
+        }
339 339
 
340
-		return new DataResponse([], Http::STATUS_NO_CONTENT);
341
-	}
340
+        return new DataResponse([], Http::STATUS_NO_CONTENT);
341
+    }
342 342
 
343 343
 }
344 344
 
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 			$this->logger->logException($e);
128 128
 			return new DataResponse(
129 129
 				[
130
-					'message' => (string)$this->l10n->t('Invalid backend or authentication mechanism class')
130
+					'message' => (string) $this->l10n->t('Invalid backend or authentication mechanism class')
131 131
 				],
132 132
 				Http::STATUS_UNPROCESSABLE_ENTITY
133 133
 			);
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 		if ($mountPoint === '') {
147 147
 			return new DataResponse(
148 148
 				array(
149
-					'message' => (string)$this->l10n->t('Invalid mount point')
149
+					'message' => (string) $this->l10n->t('Invalid mount point')
150 150
 				),
151 151
 				Http::STATUS_UNPROCESSABLE_ENTITY
152 152
 			);
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 			// objectstore must not be sent from client side
157 157
 			return new DataResponse(
158 158
 				array(
159
-					'message' => (string)$this->l10n->t('Objectstore forbidden')
159
+					'message' => (string) $this->l10n->t('Objectstore forbidden')
160 160
 				),
161 161
 				Http::STATUS_UNPROCESSABLE_ENTITY
162 162
 			);
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 			// invalid backend
171 171
 			return new DataResponse(
172 172
 				array(
173
-					'message' => (string)$this->l10n->t('Invalid storage backend "%s"', [
173
+					'message' => (string) $this->l10n->t('Invalid storage backend "%s"', [
174 174
 						$backend->getIdentifier()
175 175
 					])
176 176
 				),
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 			// not permitted to use backend
183 183
 			return new DataResponse(
184 184
 				array(
185
-					'message' => (string)$this->l10n->t('Not permitted to use backend "%s"', [
185
+					'message' => (string) $this->l10n->t('Not permitted to use backend "%s"', [
186 186
 						$backend->getIdentifier()
187 187
 					])
188 188
 				),
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
 			// not permitted to use auth mechanism
194 194
 			return new DataResponse(
195 195
 				array(
196
-					'message' => (string)$this->l10n->t('Not permitted to use authentication mechanism "%s"', [
196
+					'message' => (string) $this->l10n->t('Not permitted to use authentication mechanism "%s"', [
197 197
 						$authMechanism->getIdentifier()
198 198
 					])
199 199
 				),
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 			// unsatisfied parameters
206 206
 			return new DataResponse(
207 207
 				array(
208
-					'message' => (string)$this->l10n->t('Unsatisfied backend parameters')
208
+					'message' => (string) $this->l10n->t('Unsatisfied backend parameters')
209 209
 				),
210 210
 				Http::STATUS_UNPROCESSABLE_ENTITY
211 211
 			);
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 			// unsatisfied parameters
215 215
 			return new DataResponse(
216 216
 				[
217
-					'message' => (string)$this->l10n->t('Unsatisfied authentication mechanism parameters')
217
+					'message' => (string) $this->l10n->t('Unsatisfied authentication mechanism parameters')
218 218
 				],
219 219
 				Http::STATUS_UNPROCESSABLE_ENTITY
220 220
 			);
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 	 * @param StorageConfig $storage storage configuration
242 242
 	 * @param bool $testOnly whether to storage should only test the connection or do more things
243 243
 	 */
244
-	protected function updateStorageStatus(StorageConfig &$storage, $testOnly = true) {
244
+	protected function updateStorageStatus(StorageConfig & $storage, $testOnly = true) {
245 245
 		try {
246 246
 			$this->manipulateStorageConfig($storage);
247 247
 
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
 		} catch (NotFoundException $e) {
307 307
 			return new DataResponse(
308 308
 				[
309
-					'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id))
309
+					'message' => (string) $this->l10n->t('Storage with ID "%d" not found', array($id))
310 310
 				],
311 311
 				Http::STATUS_NOT_FOUND
312 312
 			);
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 		} catch (NotFoundException $e) {
332 332
 			return new DataResponse(
333 333
 				[
334
-					'message' => (string)$this->l10n->t('Storage with ID "%d" not found', array($id))
334
+					'message' => (string) $this->l10n->t('Storage with ID "%d" not found', array($id))
335 335
 				],
336 336
 				Http::STATUS_NOT_FOUND
337 337
 			);
Please login to merge, or discard this patch.
apps/user_ldap/templates/part.wizard-loginfilter.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -1,29 +1,29 @@  discard block
 block discarded – undo
1 1
 <fieldset id="ldapWizard3">
2 2
 	<div>
3 3
 		<p>
4
-			<?php p($l->t('When logging in, %s will find the user based on the following attributes:', $theme->getName()));?>
4
+			<?php p($l->t('When logging in, %s will find the user based on the following attributes:', $theme->getName())); ?>
5 5
 		</p>
6 6
 		<p>
7 7
 			<label for="ldap_loginfilter_username">
8
-				<?php p($l->t('LDAP / AD Username:'));?>
8
+				<?php p($l->t('LDAP / AD Username:')); ?>
9 9
 			</label>
10 10
 
11 11
 			<input type="checkbox" id="ldap_loginfilter_username"
12
-				   title="<?php p($l->t('Allows login against the LDAP / AD username, which is either uid or sAMAccountName and will be detected.'));?>"
12
+				   title="<?php p($l->t('Allows login against the LDAP / AD username, which is either uid or sAMAccountName and will be detected.')); ?>"
13 13
 				   name="ldap_loginfilter_username" value="1" />
14 14
 		</p>
15 15
 		<p>
16 16
 			<label for="ldap_loginfilter_email">
17
-				<?php p($l->t('LDAP / AD Email Address:'));?>
17
+				<?php p($l->t('LDAP / AD Email Address:')); ?>
18 18
 			</label>
19 19
 
20 20
 			<input type="checkbox" id="ldap_loginfilter_email"
21
-				   title="<?php p($l->t('Allows login against an email attribute. Mail and mailPrimaryAddress will be allowed.'));?>"
21
+				   title="<?php p($l->t('Allows login against an email attribute. Mail and mailPrimaryAddress will be allowed.')); ?>"
22 22
 				   name="ldap_loginfilter_email" value="1" />
23 23
 		</p>
24 24
 		<p>
25 25
 			<label for="ldap_loginfilter_attributes">
26
-				<?php p($l->t('Other Attributes:'));?>
26
+				<?php p($l->t('Other Attributes:')); ?>
27 27
 			</label>
28 28
 
29 29
 			<select id="ldap_loginfilter_attributes" multiple="multiple"
@@ -31,17 +31,17 @@  discard block
 block discarded – undo
31 31
 			</select>
32 32
 		</p>
33 33
 		<p>
34
-			<label><a id='toggleRawLoginFilter' class='ldapToggle'>↓ <?php p($l->t('Edit LDAP Query'));?></a></label>
34
+			<label><a id='toggleRawLoginFilter' class='ldapToggle'>↓ <?php p($l->t('Edit LDAP Query')); ?></a></label>
35 35
 		</p>
36 36
 		<p id="ldapReadOnlyLoginFilterContainer" class="hidden ldapReadOnlyFilterContainer">
37
-			<label><?php p($l->t('LDAP Filter:'));?></label>
37
+			<label><?php p($l->t('LDAP Filter:')); ?></label>
38 38
 			<span class="ldapFilterReadOnlyElement ldapInputColElement"></span>
39 39
 		</p>
40 40
 		<p id="rawLoginFilterContainer" class="invisible">
41 41
 			<textarea type="text" id="ldap_login_filter" name="ldap_login_filter"
42 42
 				class="ldapFilterInputElement"
43
-				placeholder="<?php p($l->t('Edit LDAP Query'));?>"
44
-				title="<?php p($l->t('Defines the filter to apply, when login is attempted. %%uid replaces the username in the login action. Example: "uid=%%uid"'));?>">
43
+				placeholder="<?php p($l->t('Edit LDAP Query')); ?>"
44
+				title="<?php p($l->t('Defines the filter to apply, when login is attempted. %%uid replaces the username in the login action. Example: "uid=%%uid"')); ?>">
45 45
 			</textarea>
46 46
 		</p>
47 47
 		<p>
@@ -49,11 +49,11 @@  discard block
 block discarded – undo
49 49
 		</p>
50 50
 		<p class="ldap_verify">
51 51
 			<input type="text" id="ldap_test_loginname" name="ldap_test_loginname"
52
-				   placeholder="<?php p($l->t('Test Loginname'));?>"
52
+				   placeholder="<?php p($l->t('Test Loginname')); ?>"
53 53
 				   class="ldapVerifyInput"
54 54
 				   title="Attempts to receive a DN for the given loginname and the current login filter"/>
55 55
 			<button class="ldapVerifyLoginName" name="ldapTestLoginSettings" type="button" disabled="disabled">
56
-				<?php p($l->t('Verify settings'));?>
56
+				<?php p($l->t('Verify settings')); ?>
57 57
 			</button>
58 58
 		</p>
59 59
 		<?php print_unescaped($_['wizardControls']); ?>
Please login to merge, or discard this patch.
apps/user_ldap/templates/part.wizard-groupfilter.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -1,11 +1,11 @@  discard block
 block discarded – undo
1 1
 <fieldset id="ldapWizard4">
2 2
 	<div>
3 3
 		<p>
4
-			<?php p($l->t('Groups meeting these criteria are available in %s:', $theme->getName()));?>
4
+			<?php p($l->t('Groups meeting these criteria are available in %s:', $theme->getName())); ?>
5 5
 		</p>
6 6
 		<p>
7 7
 			<label for="ldap_groupfilter_objectclass">
8
-				<?php p($l->t('Only these object classes:'));?>
8
+				<?php p($l->t('Only these object classes:')); ?>
9 9
 			</label>
10 10
 
11 11
 			<select id="ldap_groupfilter_objectclass" multiple="multiple"
@@ -14,10 +14,10 @@  discard block
 block discarded – undo
14 14
 		</p>
15 15
 		<p>
16 16
 			<label for="ldap_groupfilter_groups">
17
-				<?php p($l->t('Only from these groups:'));?>
17
+				<?php p($l->t('Only from these groups:')); ?>
18 18
 			</label>
19 19
 
20
-			<input type="text" class="ldapManyGroupsSupport ldapManyGroupsSearch hidden" placeholder="<?php p($l->t('Search groups'));?>" />
20
+			<input type="text" class="ldapManyGroupsSupport ldapManyGroupsSearch hidden" placeholder="<?php p($l->t('Search groups')); ?>" />
21 21
 
22 22
 			<select id="ldap_groupfilter_groups" multiple="multiple"
23 23
 			 name="ldap_groupfilter_groups" class="multiSelectPlugin">
@@ -27,25 +27,25 @@  discard block
 block discarded – undo
27 27
 		<p class="ldapManyGroupsSupport hidden">
28 28
 			<label></label>
29 29
 			<select class="ldapGroupList ldapGroupListAvailable" multiple="multiple"
30
-					title="<?php p($l->t('Available groups'));?>"></select>
30
+					title="<?php p($l->t('Available groups')); ?>"></select>
31 31
 			<span class="buttonSpan">
32 32
 				<button class="ldapGroupListSelect" type="button">&gt;</button><br/>
33 33
 				<button class="ldapGroupListDeselect" type="button">&lt;</button>
34 34
 			</span>
35 35
 			<select class="ldapGroupList ldapGroupListSelected" multiple="multiple"
36
-					title="<?php p($l->t('Selected groups'));?>"></select>
36
+					title="<?php p($l->t('Selected groups')); ?>"></select>
37 37
 		</p>
38 38
 		<p>
39
-			<label><a id='toggleRawGroupFilter' class='ldapToggle'>↓ <?php p($l->t('Edit LDAP Query'));?></a></label>
39
+			<label><a id='toggleRawGroupFilter' class='ldapToggle'>↓ <?php p($l->t('Edit LDAP Query')); ?></a></label>
40 40
 		</p>
41 41
 		<p id="ldapReadOnlyGroupFilterContainer" class="hidden ldapReadOnlyFilterContainer">
42
-			<label><?php p($l->t('LDAP Filter:'));?></label>
42
+			<label><?php p($l->t('LDAP Filter:')); ?></label>
43 43
 			<span class="ldapFilterReadOnlyElement ldapInputColElement"></span>
44 44
 		</p>
45 45
 		<p id="rawGroupFilterContainer" class="invisible">
46 46
 			<textarea type="text" id="ldap_group_filter" name="ldap_group_filter"
47
-					  placeholder="<?php p($l->t('Edit LDAP Query'));?>"
48
-					  title="<?php p($l->t('The filter specifies which LDAP groups shall have access to the %s instance.', $theme->getName()));?>">
47
+					  placeholder="<?php p($l->t('Edit LDAP Query')); ?>"
48
+					  title="<?php p($l->t('The filter specifies which LDAP groups shall have access to the %s instance.', $theme->getName())); ?>">
49 49
 			</textarea>
50 50
 		</p>
51 51
 		<p>
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 		</p>
54 54
 		<p class="ldap_count">
55 55
 			<button class="ldapGetEntryCount ldapGetGroupCount" name="ldapGetEntryCount" type="button">
56
-				<?php p($l->t('Verify settings and count the groups'));?>
56
+				<?php p($l->t('Verify settings and count the groups')); ?>
57 57
 			</button>
58 58
 			<span id="ldap_group_count"></span>
59 59
 		</p>
Please login to merge, or discard this patch.
apps/user_ldap/templates/part.wizard-server.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -8,16 +8,16 @@  discard block
 block discarded – undo
8 8
 <fieldset id="ldapWizard1">
9 9
 		<p>
10 10
 		<select id="ldap_serverconfig_chooser" name="ldap_serverconfig_chooser">
11
-		<?php if(count($_['serverConfigurationPrefixes']) === 0 ) {
11
+		<?php if (count($_['serverConfigurationPrefixes']) === 0) {
12 12
 			?>
13
-				<option value="" selected><?php p($l->t('1. Server'));?></option>');
13
+				<option value="" selected><?php p($l->t('1. Server')); ?></option>');
14 14
 			<?php
15 15
 		} else {
16 16
 			$i = 1;
17 17
 			$sel = ' selected';
18
-			foreach($_['serverConfigurationPrefixes'] as $prefix) {
18
+			foreach ($_['serverConfigurationPrefixes'] as $prefix) {
19 19
 				?>
20
-				<option value="<?php p($prefix); ?>"<?php p($sel); $sel = ''; ?>><?php p($l->t('%s. Server:', array($i++)));?> <?php p(' '.$_['serverConfigurationHosts'][$prefix]); ?></option>
20
+				<option value="<?php p($prefix); ?>"<?php p($sel); $sel = ''; ?>><?php p($l->t('%s. Server:', array($i++))); ?> <?php p(' '.$_['serverConfigurationHosts'][$prefix]); ?></option>
21 21
 				<?php
22 22
 			}
23 23
 		}
@@ -25,14 +25,14 @@  discard block
 block discarded – undo
25 25
 		</select>
26 26
 		<button type="button" id="ldap_action_add_configuration"
27 27
 			name="ldap_action_add_configuration" class="icon-add icon-default-style"
28
-			title="<?php p($l->t('Add a new configuration'));?>">&nbsp;</button>
28
+			title="<?php p($l->t('Add a new configuration')); ?>">&nbsp;</button>
29 29
 		<button type="button" id="ldap_action_copy_configuration"
30 30
 			name="ldap_action_copy_configuration"
31 31
 			class="ldapIconCopy icon-default-style"
32
-			title="<?php p($l->t('Copy current configuration into new directory binding'));?>">&nbsp;</button>
32
+			title="<?php p($l->t('Copy current configuration into new directory binding')); ?>">&nbsp;</button>
33 33
 		<button type="button" id="ldap_action_delete_configuration"
34 34
 			name="ldap_action_delete_configuration" class="icon-delete icon-default-style"
35
-			title="<?php p($l->t('Delete the current configuration'));?>">&nbsp;</button>
35
+			title="<?php p($l->t('Delete the current configuration')); ?>">&nbsp;</button>
36 36
 		</p>
37 37
 
38 38
 		<div class="hostPortCombinator">
@@ -41,14 +41,14 @@  discard block
 block discarded – undo
41 41
 					<div class="table">
42 42
 						<input type="text" class="host" id="ldap_host"
43 43
 							name="ldap_host"
44
-							placeholder="<?php p($l->t('Host'));?>"
45
-							title="<?php p($l->t('You can omit the protocol, unless you require SSL. If so, start with ldaps://'));?>"
44
+							placeholder="<?php p($l->t('Host')); ?>"
45
+							title="<?php p($l->t('You can omit the protocol, unless you require SSL. If so, start with ldaps://')); ?>"
46 46
 							/>
47 47
 						<span class="hostPortCombinatorSpan">
48 48
 							<input type="number" id="ldap_port" name="ldap_port"
49
-								placeholder="<?php p($l->t('Port'));?>" />
49
+								placeholder="<?php p($l->t('Port')); ?>" />
50 50
 							<button class="ldapDetectPort" name="ldapDetectPort" type="button">
51
-								<?php p($l->t('Detect Port'));?>
51
+								<?php p($l->t('Detect Port')); ?>
52 52
 							</button>
53 53
 						</span>
54 54
 					</div>
@@ -57,40 +57,40 @@  discard block
 block discarded – undo
57 57
 			<div class="tablerow">
58 58
 				<input type="text" id="ldap_dn" name="ldap_dn"
59 59
 				class="tablecell"
60
-				placeholder="<?php p($l->t('User DN'));?>" autocomplete="off"
61
-				title="<?php p($l->t('The DN of the client user with which the bind shall be done, e.g. uid=agent,dc=example,dc=com. For anonymous access, leave DN and Password empty.'));?>"
60
+				placeholder="<?php p($l->t('User DN')); ?>" autocomplete="off"
61
+				title="<?php p($l->t('The DN of the client user with which the bind shall be done, e.g. uid=agent,dc=example,dc=com. For anonymous access, leave DN and Password empty.')); ?>"
62 62
 				/>
63 63
 			</div>
64 64
 
65 65
 			<div class="tablerow">
66 66
 				<input type="password" id="ldap_agent_password"
67 67
 				class="tablecell" name="ldap_agent_password"
68
-				placeholder="<?php p($l->t('Password'));?>" autocomplete="off"
69
-				title="<?php p($l->t('For anonymous access, leave DN and Password empty.'));?>"
68
+				placeholder="<?php p($l->t('Password')); ?>" autocomplete="off"
69
+				title="<?php p($l->t('For anonymous access, leave DN and Password empty.')); ?>"
70 70
 				/>
71 71
 			</div>
72 72
 
73 73
 			<div class="tablerow">
74 74
 				<textarea id="ldap_base" name="ldap_base"
75 75
 					class="tablecell"
76
-					placeholder="<?php p($l->t('One Base DN per line'));?>"
77
-					title="<?php p($l->t('You can specify Base DN for users and groups in the Advanced tab'));?>">
76
+					placeholder="<?php p($l->t('One Base DN per line')); ?>"
77
+					title="<?php p($l->t('You can specify Base DN for users and groups in the Advanced tab')); ?>">
78 78
 				</textarea>
79 79
 				<button class="ldapDetectBase" name="ldapDetectBase" type="button">
80
-					<?php p($l->t('Detect Base DN'));?>
80
+					<?php p($l->t('Detect Base DN')); ?>
81 81
 				</button>
82 82
 				<button class="ldapTestBase" name="ldapTestBase" type="button">
83
-					<?php p($l->t('Test Base DN'));?>
83
+					<?php p($l->t('Test Base DN')); ?>
84 84
 				</button>
85 85
 			</div>
86 86
 
87 87
 			<div class="tablerow left">
88 88
 				<input type="checkbox" id="ldap_experienced_admin" value="1"
89 89
 					name="ldap_experienced_admin" class="tablecell"
90
-					title="<?php p($l->t('Avoids automatic LDAP requests. Better for bigger setups, but requires some LDAP knowledge.'));?>"
90
+					title="<?php p($l->t('Avoids automatic LDAP requests. Better for bigger setups, but requires some LDAP knowledge.')); ?>"
91 91
 					/>
92 92
 				<label for="ldap_experienced_admin" class="tablecell">
93
-					<?php p($l->t('Manually enter LDAP filters (recommended for large directories)'));?>
93
+					<?php p($l->t('Manually enter LDAP filters (recommended for large directories)')); ?>
94 94
 				</label>
95 95
 			</div>
96 96
 
Please login to merge, or discard this patch.