Passed
Push — master ( 4deff3...82cc9c )
by Roeland
11:32
created
apps/files_external/lib/Config/ConfigAdapter.php 2 patches
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -47,143 +47,143 @@
 block discarded – undo
47 47
  */
48 48
 class ConfigAdapter implements IMountProvider {
49 49
 
50
-	/** @var UserStoragesService */
51
-	private $userStoragesService;
52
-
53
-	/** @var UserGlobalStoragesService */
54
-	private $userGlobalStoragesService;
55
-	/** @var StorageMigrator  */
56
-	private $migrator;
57
-
58
-	/**
59
-	 * @param UserStoragesService $userStoragesService
60
-	 * @param UserGlobalStoragesService $userGlobalStoragesService
61
-	 * @param StorageMigrator $migrator
62
-	 */
63
-	public function __construct(
64
-		UserStoragesService $userStoragesService,
65
-		UserGlobalStoragesService $userGlobalStoragesService,
66
-		StorageMigrator $migrator
67
-	) {
68
-		$this->userStoragesService = $userStoragesService;
69
-		$this->userGlobalStoragesService = $userGlobalStoragesService;
70
-		$this->migrator = $migrator;
71
-	}
72
-
73
-	/**
74
-	 * Process storage ready for mounting
75
-	 *
76
-	 * @param StorageConfig $storage
77
-	 * @param IUser $user
78
-	 * @throws \OCP\AppFramework\QueryException
79
-	 */
80
-	private function prepareStorageConfig(StorageConfig &$storage, IUser $user) {
81
-		foreach ($storage->getBackendOptions() as $option => $value) {
82
-			$storage->setBackendOption($option, \OCA\Files_External\MountConfig::substitutePlaceholdersInConfig($value, $user->getUID()));
83
-		}
84
-
85
-		$objectStore = $storage->getBackendOption('objectstore');
86
-		if ($objectStore) {
87
-			$objectClass = $objectStore['class'];
88
-			if (!is_subclass_of($objectClass, '\OCP\Files\ObjectStore\IObjectStore')) {
89
-				throw new \InvalidArgumentException('Invalid object store');
90
-			}
91
-			$storage->setBackendOption('objectstore', new $objectClass($objectStore));
92
-		}
93
-
94
-		$storage->getAuthMechanism()->manipulateStorageConfig($storage, $user);
95
-		$storage->getBackend()->manipulateStorageConfig($storage, $user);
96
-	}
97
-
98
-	/**
99
-	 * Construct the storage implementation
100
-	 *
101
-	 * @param StorageConfig $storageConfig
102
-	 * @return Storage
103
-	 */
104
-	private function constructStorage(StorageConfig $storageConfig) {
105
-		$class = $storageConfig->getBackend()->getStorageClass();
106
-		$storage = new $class($storageConfig->getBackendOptions());
107
-
108
-		// auth mechanism should fire first
109
-		$storage = $storageConfig->getBackend()->wrapStorage($storage);
110
-		$storage = $storageConfig->getAuthMechanism()->wrapStorage($storage);
111
-
112
-		return $storage;
113
-	}
114
-
115
-	/**
116
-	 * Get all mountpoints applicable for the user
117
-	 *
118
-	 * @param \OCP\IUser $user
119
-	 * @param \OCP\Files\Storage\IStorageFactory $loader
120
-	 * @return \OCP\Files\Mount\IMountPoint[]
121
-	 */
122
-	public function getMountsForUser(IUser $user, IStorageFactory $loader) {
123
-		$this->migrator->migrateUser($user);
124
-
125
-		$this->userStoragesService->setUser($user);
126
-		$this->userGlobalStoragesService->setUser($user);
127
-
128
-		$storageConfigs = $this->userGlobalStoragesService->getAllStoragesForUser();
129
-
130
-		$storages = array_map(function (StorageConfig $storageConfig) use ($user) {
131
-			try {
132
-				$this->prepareStorageConfig($storageConfig, $user);
133
-				return $this->constructStorage($storageConfig);
134
-			} catch (\Exception $e) {
135
-				// propagate exception into filesystem
136
-				return new FailedStorage(['exception' => $e]);
137
-			}
138
-		}, $storageConfigs);
139
-
140
-
141
-		\OC\Files\Cache\Storage::getGlobalCache()->loadForStorageIds(array_map(function (Storage\IStorage $storage) {
142
-			return $storage->getId();
143
-		}, $storages));
144
-
145
-		$availableStorages = array_map(function (Storage\IStorage $storage, StorageConfig $storageConfig) {
146
-			try {
147
-				$availability = $storage->getAvailability();
148
-				if (!$availability['available'] && !Availability::shouldRecheck($availability)) {
149
-					$storage = new FailedStorage([
150
-						'exception' => new StorageNotAvailableException('Storage with mount id ' . $storageConfig->getId() . ' is not available')
151
-					]);
152
-				}
153
-			} catch (\Exception $e) {
154
-				// propagate exception into filesystem
155
-				$storage = new FailedStorage(['exception' => $e]);
156
-			}
157
-			return $storage;
158
-		}, $storages, $storageConfigs);
159
-
160
-		$mounts = array_map(function (StorageConfig $storageConfig, Storage\IStorage $storage) use ($user, $loader) {
161
-			if ($storageConfig->getType() === StorageConfig::MOUNT_TYPE_PERSONAl) {
162
-				return new PersonalMount(
163
-					$this->userStoragesService,
164
-					$storageConfig->getId(),
165
-					$storage,
166
-					'/' . $user->getUID() . '/files' . $storageConfig->getMountPoint(),
167
-					null,
168
-					$loader,
169
-					$storageConfig->getMountOptions(),
170
-					$storageConfig->getId()
171
-				);
172
-			} else {
173
-				return new ExternalMountPoint(
174
-					$storage,
175
-					'/' . $user->getUID() . '/files' . $storageConfig->getMountPoint(),
176
-					null,
177
-					$loader,
178
-					$storageConfig->getMountOptions(),
179
-					$storageConfig->getId()
180
-				);
181
-			}
182
-		}, $storageConfigs, $availableStorages);
183
-
184
-		$this->userStoragesService->resetUser();
185
-		$this->userGlobalStoragesService->resetUser();
186
-
187
-		return $mounts;
188
-	}
50
+    /** @var UserStoragesService */
51
+    private $userStoragesService;
52
+
53
+    /** @var UserGlobalStoragesService */
54
+    private $userGlobalStoragesService;
55
+    /** @var StorageMigrator  */
56
+    private $migrator;
57
+
58
+    /**
59
+     * @param UserStoragesService $userStoragesService
60
+     * @param UserGlobalStoragesService $userGlobalStoragesService
61
+     * @param StorageMigrator $migrator
62
+     */
63
+    public function __construct(
64
+        UserStoragesService $userStoragesService,
65
+        UserGlobalStoragesService $userGlobalStoragesService,
66
+        StorageMigrator $migrator
67
+    ) {
68
+        $this->userStoragesService = $userStoragesService;
69
+        $this->userGlobalStoragesService = $userGlobalStoragesService;
70
+        $this->migrator = $migrator;
71
+    }
72
+
73
+    /**
74
+     * Process storage ready for mounting
75
+     *
76
+     * @param StorageConfig $storage
77
+     * @param IUser $user
78
+     * @throws \OCP\AppFramework\QueryException
79
+     */
80
+    private function prepareStorageConfig(StorageConfig &$storage, IUser $user) {
81
+        foreach ($storage->getBackendOptions() as $option => $value) {
82
+            $storage->setBackendOption($option, \OCA\Files_External\MountConfig::substitutePlaceholdersInConfig($value, $user->getUID()));
83
+        }
84
+
85
+        $objectStore = $storage->getBackendOption('objectstore');
86
+        if ($objectStore) {
87
+            $objectClass = $objectStore['class'];
88
+            if (!is_subclass_of($objectClass, '\OCP\Files\ObjectStore\IObjectStore')) {
89
+                throw new \InvalidArgumentException('Invalid object store');
90
+            }
91
+            $storage->setBackendOption('objectstore', new $objectClass($objectStore));
92
+        }
93
+
94
+        $storage->getAuthMechanism()->manipulateStorageConfig($storage, $user);
95
+        $storage->getBackend()->manipulateStorageConfig($storage, $user);
96
+    }
97
+
98
+    /**
99
+     * Construct the storage implementation
100
+     *
101
+     * @param StorageConfig $storageConfig
102
+     * @return Storage
103
+     */
104
+    private function constructStorage(StorageConfig $storageConfig) {
105
+        $class = $storageConfig->getBackend()->getStorageClass();
106
+        $storage = new $class($storageConfig->getBackendOptions());
107
+
108
+        // auth mechanism should fire first
109
+        $storage = $storageConfig->getBackend()->wrapStorage($storage);
110
+        $storage = $storageConfig->getAuthMechanism()->wrapStorage($storage);
111
+
112
+        return $storage;
113
+    }
114
+
115
+    /**
116
+     * Get all mountpoints applicable for the user
117
+     *
118
+     * @param \OCP\IUser $user
119
+     * @param \OCP\Files\Storage\IStorageFactory $loader
120
+     * @return \OCP\Files\Mount\IMountPoint[]
121
+     */
122
+    public function getMountsForUser(IUser $user, IStorageFactory $loader) {
123
+        $this->migrator->migrateUser($user);
124
+
125
+        $this->userStoragesService->setUser($user);
126
+        $this->userGlobalStoragesService->setUser($user);
127
+
128
+        $storageConfigs = $this->userGlobalStoragesService->getAllStoragesForUser();
129
+
130
+        $storages = array_map(function (StorageConfig $storageConfig) use ($user) {
131
+            try {
132
+                $this->prepareStorageConfig($storageConfig, $user);
133
+                return $this->constructStorage($storageConfig);
134
+            } catch (\Exception $e) {
135
+                // propagate exception into filesystem
136
+                return new FailedStorage(['exception' => $e]);
137
+            }
138
+        }, $storageConfigs);
139
+
140
+
141
+        \OC\Files\Cache\Storage::getGlobalCache()->loadForStorageIds(array_map(function (Storage\IStorage $storage) {
142
+            return $storage->getId();
143
+        }, $storages));
144
+
145
+        $availableStorages = array_map(function (Storage\IStorage $storage, StorageConfig $storageConfig) {
146
+            try {
147
+                $availability = $storage->getAvailability();
148
+                if (!$availability['available'] && !Availability::shouldRecheck($availability)) {
149
+                    $storage = new FailedStorage([
150
+                        'exception' => new StorageNotAvailableException('Storage with mount id ' . $storageConfig->getId() . ' is not available')
151
+                    ]);
152
+                }
153
+            } catch (\Exception $e) {
154
+                // propagate exception into filesystem
155
+                $storage = new FailedStorage(['exception' => $e]);
156
+            }
157
+            return $storage;
158
+        }, $storages, $storageConfigs);
159
+
160
+        $mounts = array_map(function (StorageConfig $storageConfig, Storage\IStorage $storage) use ($user, $loader) {
161
+            if ($storageConfig->getType() === StorageConfig::MOUNT_TYPE_PERSONAl) {
162
+                return new PersonalMount(
163
+                    $this->userStoragesService,
164
+                    $storageConfig->getId(),
165
+                    $storage,
166
+                    '/' . $user->getUID() . '/files' . $storageConfig->getMountPoint(),
167
+                    null,
168
+                    $loader,
169
+                    $storageConfig->getMountOptions(),
170
+                    $storageConfig->getId()
171
+                );
172
+            } else {
173
+                return new ExternalMountPoint(
174
+                    $storage,
175
+                    '/' . $user->getUID() . '/files' . $storageConfig->getMountPoint(),
176
+                    null,
177
+                    $loader,
178
+                    $storageConfig->getMountOptions(),
179
+                    $storageConfig->getId()
180
+                );
181
+            }
182
+        }, $storageConfigs, $availableStorages);
183
+
184
+        $this->userStoragesService->resetUser();
185
+        $this->userGlobalStoragesService->resetUser();
186
+
187
+        return $mounts;
188
+    }
189 189
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 
128 128
 		$storageConfigs = $this->userGlobalStoragesService->getAllStoragesForUser();
129 129
 
130
-		$storages = array_map(function (StorageConfig $storageConfig) use ($user) {
130
+		$storages = array_map(function(StorageConfig $storageConfig) use ($user) {
131 131
 			try {
132 132
 				$this->prepareStorageConfig($storageConfig, $user);
133 133
 				return $this->constructStorage($storageConfig);
@@ -138,16 +138,16 @@  discard block
 block discarded – undo
138 138
 		}, $storageConfigs);
139 139
 
140 140
 
141
-		\OC\Files\Cache\Storage::getGlobalCache()->loadForStorageIds(array_map(function (Storage\IStorage $storage) {
141
+		\OC\Files\Cache\Storage::getGlobalCache()->loadForStorageIds(array_map(function(Storage\IStorage $storage) {
142 142
 			return $storage->getId();
143 143
 		}, $storages));
144 144
 
145
-		$availableStorages = array_map(function (Storage\IStorage $storage, StorageConfig $storageConfig) {
145
+		$availableStorages = array_map(function(Storage\IStorage $storage, StorageConfig $storageConfig) {
146 146
 			try {
147 147
 				$availability = $storage->getAvailability();
148 148
 				if (!$availability['available'] && !Availability::shouldRecheck($availability)) {
149 149
 					$storage = new FailedStorage([
150
-						'exception' => new StorageNotAvailableException('Storage with mount id ' . $storageConfig->getId() . ' is not available')
150
+						'exception' => new StorageNotAvailableException('Storage with mount id '.$storageConfig->getId().' is not available')
151 151
 					]);
152 152
 				}
153 153
 			} catch (\Exception $e) {
@@ -157,13 +157,13 @@  discard block
 block discarded – undo
157 157
 			return $storage;
158 158
 		}, $storages, $storageConfigs);
159 159
 
160
-		$mounts = array_map(function (StorageConfig $storageConfig, Storage\IStorage $storage) use ($user, $loader) {
160
+		$mounts = array_map(function(StorageConfig $storageConfig, Storage\IStorage $storage) use ($user, $loader) {
161 161
 			if ($storageConfig->getType() === StorageConfig::MOUNT_TYPE_PERSONAl) {
162 162
 				return new PersonalMount(
163 163
 					$this->userStoragesService,
164 164
 					$storageConfig->getId(),
165 165
 					$storage,
166
-					'/' . $user->getUID() . '/files' . $storageConfig->getMountPoint(),
166
+					'/'.$user->getUID().'/files'.$storageConfig->getMountPoint(),
167 167
 					null,
168 168
 					$loader,
169 169
 					$storageConfig->getMountOptions(),
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 			} else {
173 173
 				return new ExternalMountPoint(
174 174
 					$storage,
175
-					'/' . $user->getUID() . '/files' . $storageConfig->getMountPoint(),
175
+					'/'.$user->getUID().'/files'.$storageConfig->getMountPoint(),
176 176
 					null,
177 177
 					$loader,
178 178
 					$storageConfig->getMountOptions(),
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/PersonalMount.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -33,59 +33,59 @@
 block discarded – undo
33 33
  * Person mount points can be moved by the user
34 34
  */
35 35
 class PersonalMount extends ExternalMountPoint implements MoveableMount {
36
-	/** @var UserStoragesService */
37
-	protected $storagesService;
36
+    /** @var UserStoragesService */
37
+    protected $storagesService;
38 38
 
39
-	/** @var int */
40
-	protected $numericStorageId;
39
+    /** @var int */
40
+    protected $numericStorageId;
41 41
 
42
-	/**
43
-	 * @param UserStoragesService $storagesService
44
-	 * @param int $storageId
45
-	 * @param \OCP\Files\Storage $storage
46
-	 * @param string $mountpoint
47
-	 * @param array $arguments (optional) configuration for the storage backend
48
-	 * @param \OCP\Files\Storage\IStorageFactory $loader
49
-	 * @param array $mountOptions mount specific options
50
-	 */
51
-	public function __construct(
52
-		UserStoragesService $storagesService,
53
-		$storageId,
54
-		$storage,
55
-		$mountpoint,
56
-		$arguments = null,
57
-		$loader = null,
58
-		$mountOptions = null,
59
-		$mountId = null
60
-	) {
61
-		parent::__construct($storage, $mountpoint, $arguments, $loader, $mountOptions, $mountId);
62
-		$this->storagesService = $storagesService;
63
-		$this->numericStorageId = $storageId;
64
-	}
42
+    /**
43
+     * @param UserStoragesService $storagesService
44
+     * @param int $storageId
45
+     * @param \OCP\Files\Storage $storage
46
+     * @param string $mountpoint
47
+     * @param array $arguments (optional) configuration for the storage backend
48
+     * @param \OCP\Files\Storage\IStorageFactory $loader
49
+     * @param array $mountOptions mount specific options
50
+     */
51
+    public function __construct(
52
+        UserStoragesService $storagesService,
53
+        $storageId,
54
+        $storage,
55
+        $mountpoint,
56
+        $arguments = null,
57
+        $loader = null,
58
+        $mountOptions = null,
59
+        $mountId = null
60
+    ) {
61
+        parent::__construct($storage, $mountpoint, $arguments, $loader, $mountOptions, $mountId);
62
+        $this->storagesService = $storagesService;
63
+        $this->numericStorageId = $storageId;
64
+    }
65 65
 
66
-	/**
67
-	 * Move the mount point to $target
68
-	 *
69
-	 * @param string $target the target mount point
70
-	 * @return bool
71
-	 */
72
-	public function moveMount($target) {
73
-		$storage = $this->storagesService->getStorage($this->numericStorageId);
74
-		// remove "/$user/files" prefix
75
-		$targetParts = explode('/', trim($target, '/'), 3);
76
-		$storage->setMountPoint($targetParts[2]);
77
-		$this->storagesService->updateStorage($storage);
78
-		$this->setMountPoint($target);
79
-		return true;
80
-	}
66
+    /**
67
+     * Move the mount point to $target
68
+     *
69
+     * @param string $target the target mount point
70
+     * @return bool
71
+     */
72
+    public function moveMount($target) {
73
+        $storage = $this->storagesService->getStorage($this->numericStorageId);
74
+        // remove "/$user/files" prefix
75
+        $targetParts = explode('/', trim($target, '/'), 3);
76
+        $storage->setMountPoint($targetParts[2]);
77
+        $this->storagesService->updateStorage($storage);
78
+        $this->setMountPoint($target);
79
+        return true;
80
+    }
81 81
 
82
-	/**
83
-	 * Remove the mount points
84
-	 *
85
-	 * @return bool
86
-	 */
87
-	public function removeMount() {
88
-		$this->storagesService->removeStorage($this->numericStorageId);
89
-		return true;
90
-	}
82
+    /**
83
+     * Remove the mount points
84
+     *
85
+     * @return bool
86
+     */
87
+    public function removeMount() {
88
+        $this->storagesService->removeStorage($this->numericStorageId);
89
+        return true;
90
+    }
91 91
 }
Please login to merge, or discard this patch.