@@ -29,28 +29,28 @@ |
||
29 | 29 | * Read user defined mounts from the legacy mount.json |
30 | 30 | */ |
31 | 31 | class UserLegacyStoragesService extends LegacyStoragesService { |
32 | - /** |
|
33 | - * @var IUserSession |
|
34 | - */ |
|
35 | - private $userSession; |
|
32 | + /** |
|
33 | + * @var IUserSession |
|
34 | + */ |
|
35 | + private $userSession; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param BackendService $backendService |
|
39 | - * @param IUserSession $userSession |
|
40 | - */ |
|
41 | - public function __construct(BackendService $backendService, IUserSession $userSession) { |
|
42 | - $this->backendService = $backendService; |
|
43 | - $this->userSession = $userSession; |
|
44 | - } |
|
37 | + /** |
|
38 | + * @param BackendService $backendService |
|
39 | + * @param IUserSession $userSession |
|
40 | + */ |
|
41 | + public function __construct(BackendService $backendService, IUserSession $userSession) { |
|
42 | + $this->backendService = $backendService; |
|
43 | + $this->userSession = $userSession; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Read legacy config data |
|
48 | - * |
|
49 | - * @return array list of storage configs |
|
50 | - */ |
|
51 | - protected function readLegacyConfig() { |
|
52 | - // read user config |
|
53 | - $user = $this->userSession->getUser()->getUID(); |
|
54 | - return \OC_Mount_Config::readData($user); |
|
55 | - } |
|
46 | + /** |
|
47 | + * Read legacy config data |
|
48 | + * |
|
49 | + * @return array list of storage configs |
|
50 | + */ |
|
51 | + protected function readLegacyConfig() { |
|
52 | + // read user config |
|
53 | + $user = $this->userSession->getUser()->getUID(); |
|
54 | + return \OC_Mount_Config::readData($user); |
|
55 | + } |
|
56 | 56 | } |
@@ -30,183 +30,183 @@ |
||
30 | 30 | * Read mount config from legacy mount.json |
31 | 31 | */ |
32 | 32 | abstract class LegacyStoragesService { |
33 | - /** @var BackendService */ |
|
34 | - protected $backendService; |
|
33 | + /** @var BackendService */ |
|
34 | + protected $backendService; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Read legacy config data |
|
38 | - * |
|
39 | - * @return array list of mount configs |
|
40 | - */ |
|
41 | - abstract protected function readLegacyConfig(); |
|
36 | + /** |
|
37 | + * Read legacy config data |
|
38 | + * |
|
39 | + * @return array list of mount configs |
|
40 | + */ |
|
41 | + abstract protected function readLegacyConfig(); |
|
42 | 42 | |
43 | - /** |
|
44 | - * Copy legacy storage options into the given storage config object. |
|
45 | - * |
|
46 | - * @param StorageConfig $storageConfig storage config to populate |
|
47 | - * @param string $mountType mount type |
|
48 | - * @param string $applicable applicable user or group |
|
49 | - * @param array $storageOptions legacy storage options |
|
50 | - * |
|
51 | - * @return StorageConfig populated storage config |
|
52 | - */ |
|
53 | - protected function populateStorageConfigWithLegacyOptions( |
|
54 | - &$storageConfig, |
|
55 | - $mountType, |
|
56 | - $applicable, |
|
57 | - $storageOptions |
|
58 | - ) { |
|
59 | - $backend = $this->backendService->getBackend($storageOptions['backend']); |
|
60 | - if (!$backend) { |
|
61 | - throw new \UnexpectedValueException('Invalid backend ' . $storageOptions['backend']); |
|
62 | - } |
|
63 | - $storageConfig->setBackend($backend); |
|
64 | - if (isset($storageOptions['authMechanism']) && $storageOptions['authMechanism'] !== 'builtin::builtin') { |
|
65 | - $authMechanism = $this->backendService->getAuthMechanism($storageOptions['authMechanism']); |
|
66 | - } else { |
|
67 | - $authMechanism = $backend->getLegacyAuthMechanism($storageOptions); |
|
68 | - $storageOptions['authMechanism'] = 'null'; // to make error handling easier |
|
69 | - } |
|
70 | - if (!$authMechanism) { |
|
71 | - throw new \UnexpectedValueException('Invalid authentication mechanism ' . $storageOptions['authMechanism']); |
|
72 | - } |
|
73 | - $storageConfig->setAuthMechanism($authMechanism); |
|
74 | - $storageConfig->setBackendOptions($storageOptions['options']); |
|
75 | - if (isset($storageOptions['mountOptions'])) { |
|
76 | - $storageConfig->setMountOptions($storageOptions['mountOptions']); |
|
77 | - } |
|
78 | - if (!isset($storageOptions['priority'])) { |
|
79 | - $storageOptions['priority'] = $backend->getPriority(); |
|
80 | - } |
|
81 | - $storageConfig->setPriority($storageOptions['priority']); |
|
82 | - if ($mountType === \OC_Mount_Config::MOUNT_TYPE_USER) { |
|
83 | - $applicableUsers = $storageConfig->getApplicableUsers(); |
|
84 | - if ($applicable !== 'all') { |
|
85 | - $applicableUsers[] = $applicable; |
|
86 | - $storageConfig->setApplicableUsers($applicableUsers); |
|
87 | - } |
|
88 | - } else if ($mountType === \OC_Mount_Config::MOUNT_TYPE_GROUP) { |
|
89 | - $applicableGroups = $storageConfig->getApplicableGroups(); |
|
90 | - $applicableGroups[] = $applicable; |
|
91 | - $storageConfig->setApplicableGroups($applicableGroups); |
|
92 | - } |
|
93 | - return $storageConfig; |
|
94 | - } |
|
43 | + /** |
|
44 | + * Copy legacy storage options into the given storage config object. |
|
45 | + * |
|
46 | + * @param StorageConfig $storageConfig storage config to populate |
|
47 | + * @param string $mountType mount type |
|
48 | + * @param string $applicable applicable user or group |
|
49 | + * @param array $storageOptions legacy storage options |
|
50 | + * |
|
51 | + * @return StorageConfig populated storage config |
|
52 | + */ |
|
53 | + protected function populateStorageConfigWithLegacyOptions( |
|
54 | + &$storageConfig, |
|
55 | + $mountType, |
|
56 | + $applicable, |
|
57 | + $storageOptions |
|
58 | + ) { |
|
59 | + $backend = $this->backendService->getBackend($storageOptions['backend']); |
|
60 | + if (!$backend) { |
|
61 | + throw new \UnexpectedValueException('Invalid backend ' . $storageOptions['backend']); |
|
62 | + } |
|
63 | + $storageConfig->setBackend($backend); |
|
64 | + if (isset($storageOptions['authMechanism']) && $storageOptions['authMechanism'] !== 'builtin::builtin') { |
|
65 | + $authMechanism = $this->backendService->getAuthMechanism($storageOptions['authMechanism']); |
|
66 | + } else { |
|
67 | + $authMechanism = $backend->getLegacyAuthMechanism($storageOptions); |
|
68 | + $storageOptions['authMechanism'] = 'null'; // to make error handling easier |
|
69 | + } |
|
70 | + if (!$authMechanism) { |
|
71 | + throw new \UnexpectedValueException('Invalid authentication mechanism ' . $storageOptions['authMechanism']); |
|
72 | + } |
|
73 | + $storageConfig->setAuthMechanism($authMechanism); |
|
74 | + $storageConfig->setBackendOptions($storageOptions['options']); |
|
75 | + if (isset($storageOptions['mountOptions'])) { |
|
76 | + $storageConfig->setMountOptions($storageOptions['mountOptions']); |
|
77 | + } |
|
78 | + if (!isset($storageOptions['priority'])) { |
|
79 | + $storageOptions['priority'] = $backend->getPriority(); |
|
80 | + } |
|
81 | + $storageConfig->setPriority($storageOptions['priority']); |
|
82 | + if ($mountType === \OC_Mount_Config::MOUNT_TYPE_USER) { |
|
83 | + $applicableUsers = $storageConfig->getApplicableUsers(); |
|
84 | + if ($applicable !== 'all') { |
|
85 | + $applicableUsers[] = $applicable; |
|
86 | + $storageConfig->setApplicableUsers($applicableUsers); |
|
87 | + } |
|
88 | + } else if ($mountType === \OC_Mount_Config::MOUNT_TYPE_GROUP) { |
|
89 | + $applicableGroups = $storageConfig->getApplicableGroups(); |
|
90 | + $applicableGroups[] = $applicable; |
|
91 | + $storageConfig->setApplicableGroups($applicableGroups); |
|
92 | + } |
|
93 | + return $storageConfig; |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Read the external storages config |
|
98 | - * |
|
99 | - * @return StorageConfig[] map of storage id to storage config |
|
100 | - */ |
|
101 | - public function getAllStorages() { |
|
102 | - $mountPoints = $this->readLegacyConfig(); |
|
103 | - /** |
|
104 | - * Here is the how the horribly messy mount point array looks like |
|
105 | - * from the mount.json file: |
|
106 | - * |
|
107 | - * $storageOptions = $mountPoints[$mountType][$applicable][$mountPath] |
|
108 | - * |
|
109 | - * - $mountType is either "user" or "group" |
|
110 | - * - $applicable is the name of a user or group (or the current user for personal mounts) |
|
111 | - * - $mountPath is the mount point path (where the storage must be mounted) |
|
112 | - * - $storageOptions is a map of storage options: |
|
113 | - * - "priority": storage priority |
|
114 | - * - "backend": backend identifier |
|
115 | - * - "class": LEGACY backend class name |
|
116 | - * - "options": backend-specific options |
|
117 | - * - "authMechanism": authentication mechanism identifier |
|
118 | - * - "mountOptions": mount-specific options (ex: disable previews, scanner, etc) |
|
119 | - */ |
|
120 | - // group by storage id |
|
121 | - /** @var StorageConfig[] $storages */ |
|
122 | - $storages = []; |
|
123 | - // for storages without id (legacy), group by config hash for |
|
124 | - // later processing |
|
125 | - $storagesWithConfigHash = []; |
|
126 | - foreach ($mountPoints as $mountType => $applicables) { |
|
127 | - foreach ($applicables as $applicable => $mountPaths) { |
|
128 | - foreach ($mountPaths as $rootMountPath => $storageOptions) { |
|
129 | - $currentStorage = null; |
|
130 | - /** |
|
131 | - * Flag whether the config that was read already has an id. |
|
132 | - * If not, it will use a config hash instead and generate |
|
133 | - * a proper id later |
|
134 | - * |
|
135 | - * @var boolean |
|
136 | - */ |
|
137 | - $hasId = false; |
|
138 | - // the root mount point is in the format "/$user/files/the/mount/point" |
|
139 | - // we remove the "/$user/files" prefix |
|
140 | - $parts = explode('/', ltrim($rootMountPath, '/'), 3); |
|
141 | - if (count($parts) < 3) { |
|
142 | - // something went wrong, skip |
|
143 | - \OCP\Util::writeLog( |
|
144 | - 'files_external', |
|
145 | - 'Could not parse mount point "' . $rootMountPath . '"', |
|
146 | - \OCP\Util::ERROR |
|
147 | - ); |
|
148 | - continue; |
|
149 | - } |
|
150 | - $relativeMountPath = rtrim($parts[2], '/'); |
|
151 | - // note: we cannot do this after the loop because the decrypted config |
|
152 | - // options might be needed for the config hash |
|
153 | - $storageOptions['options'] = \OC_Mount_Config::decryptPasswords($storageOptions['options']); |
|
154 | - if (!isset($storageOptions['backend'])) { |
|
155 | - $storageOptions['backend'] = $storageOptions['class']; // legacy compat |
|
156 | - } |
|
157 | - if (!isset($storageOptions['authMechanism'])) { |
|
158 | - $storageOptions['authMechanism'] = null; // ensure config hash works |
|
159 | - } |
|
160 | - if (isset($storageOptions['id'])) { |
|
161 | - $configId = (int)$storageOptions['id']; |
|
162 | - if (isset($storages[$configId])) { |
|
163 | - $currentStorage = $storages[$configId]; |
|
164 | - } |
|
165 | - $hasId = true; |
|
166 | - } else { |
|
167 | - // missing id in legacy config, need to generate |
|
168 | - // but at this point we don't know the max-id, so use |
|
169 | - // first group it by config hash |
|
170 | - $storageOptions['mountpoint'] = $rootMountPath; |
|
171 | - $configId = \OC_Mount_Config::makeConfigHash($storageOptions); |
|
172 | - if (isset($storagesWithConfigHash[$configId])) { |
|
173 | - $currentStorage = $storagesWithConfigHash[$configId]; |
|
174 | - } |
|
175 | - } |
|
176 | - if (is_null($currentStorage)) { |
|
177 | - // create new |
|
178 | - $currentStorage = new StorageConfig($configId); |
|
179 | - $currentStorage->setMountPoint($relativeMountPath); |
|
180 | - } |
|
181 | - try { |
|
182 | - $this->populateStorageConfigWithLegacyOptions( |
|
183 | - $currentStorage, |
|
184 | - $mountType, |
|
185 | - $applicable, |
|
186 | - $storageOptions |
|
187 | - ); |
|
188 | - if ($hasId) { |
|
189 | - $storages[$configId] = $currentStorage; |
|
190 | - } else { |
|
191 | - $storagesWithConfigHash[$configId] = $currentStorage; |
|
192 | - } |
|
193 | - } catch (\UnexpectedValueException $e) { |
|
194 | - // don't die if a storage backend doesn't exist |
|
195 | - \OCP\Util::writeLog( |
|
196 | - 'files_external', |
|
197 | - 'Could not load storage: "' . $e->getMessage() . '"', |
|
198 | - \OCP\Util::ERROR |
|
199 | - ); |
|
200 | - } |
|
201 | - } |
|
202 | - } |
|
203 | - } |
|
96 | + /** |
|
97 | + * Read the external storages config |
|
98 | + * |
|
99 | + * @return StorageConfig[] map of storage id to storage config |
|
100 | + */ |
|
101 | + public function getAllStorages() { |
|
102 | + $mountPoints = $this->readLegacyConfig(); |
|
103 | + /** |
|
104 | + * Here is the how the horribly messy mount point array looks like |
|
105 | + * from the mount.json file: |
|
106 | + * |
|
107 | + * $storageOptions = $mountPoints[$mountType][$applicable][$mountPath] |
|
108 | + * |
|
109 | + * - $mountType is either "user" or "group" |
|
110 | + * - $applicable is the name of a user or group (or the current user for personal mounts) |
|
111 | + * - $mountPath is the mount point path (where the storage must be mounted) |
|
112 | + * - $storageOptions is a map of storage options: |
|
113 | + * - "priority": storage priority |
|
114 | + * - "backend": backend identifier |
|
115 | + * - "class": LEGACY backend class name |
|
116 | + * - "options": backend-specific options |
|
117 | + * - "authMechanism": authentication mechanism identifier |
|
118 | + * - "mountOptions": mount-specific options (ex: disable previews, scanner, etc) |
|
119 | + */ |
|
120 | + // group by storage id |
|
121 | + /** @var StorageConfig[] $storages */ |
|
122 | + $storages = []; |
|
123 | + // for storages without id (legacy), group by config hash for |
|
124 | + // later processing |
|
125 | + $storagesWithConfigHash = []; |
|
126 | + foreach ($mountPoints as $mountType => $applicables) { |
|
127 | + foreach ($applicables as $applicable => $mountPaths) { |
|
128 | + foreach ($mountPaths as $rootMountPath => $storageOptions) { |
|
129 | + $currentStorage = null; |
|
130 | + /** |
|
131 | + * Flag whether the config that was read already has an id. |
|
132 | + * If not, it will use a config hash instead and generate |
|
133 | + * a proper id later |
|
134 | + * |
|
135 | + * @var boolean |
|
136 | + */ |
|
137 | + $hasId = false; |
|
138 | + // the root mount point is in the format "/$user/files/the/mount/point" |
|
139 | + // we remove the "/$user/files" prefix |
|
140 | + $parts = explode('/', ltrim($rootMountPath, '/'), 3); |
|
141 | + if (count($parts) < 3) { |
|
142 | + // something went wrong, skip |
|
143 | + \OCP\Util::writeLog( |
|
144 | + 'files_external', |
|
145 | + 'Could not parse mount point "' . $rootMountPath . '"', |
|
146 | + \OCP\Util::ERROR |
|
147 | + ); |
|
148 | + continue; |
|
149 | + } |
|
150 | + $relativeMountPath = rtrim($parts[2], '/'); |
|
151 | + // note: we cannot do this after the loop because the decrypted config |
|
152 | + // options might be needed for the config hash |
|
153 | + $storageOptions['options'] = \OC_Mount_Config::decryptPasswords($storageOptions['options']); |
|
154 | + if (!isset($storageOptions['backend'])) { |
|
155 | + $storageOptions['backend'] = $storageOptions['class']; // legacy compat |
|
156 | + } |
|
157 | + if (!isset($storageOptions['authMechanism'])) { |
|
158 | + $storageOptions['authMechanism'] = null; // ensure config hash works |
|
159 | + } |
|
160 | + if (isset($storageOptions['id'])) { |
|
161 | + $configId = (int)$storageOptions['id']; |
|
162 | + if (isset($storages[$configId])) { |
|
163 | + $currentStorage = $storages[$configId]; |
|
164 | + } |
|
165 | + $hasId = true; |
|
166 | + } else { |
|
167 | + // missing id in legacy config, need to generate |
|
168 | + // but at this point we don't know the max-id, so use |
|
169 | + // first group it by config hash |
|
170 | + $storageOptions['mountpoint'] = $rootMountPath; |
|
171 | + $configId = \OC_Mount_Config::makeConfigHash($storageOptions); |
|
172 | + if (isset($storagesWithConfigHash[$configId])) { |
|
173 | + $currentStorage = $storagesWithConfigHash[$configId]; |
|
174 | + } |
|
175 | + } |
|
176 | + if (is_null($currentStorage)) { |
|
177 | + // create new |
|
178 | + $currentStorage = new StorageConfig($configId); |
|
179 | + $currentStorage->setMountPoint($relativeMountPath); |
|
180 | + } |
|
181 | + try { |
|
182 | + $this->populateStorageConfigWithLegacyOptions( |
|
183 | + $currentStorage, |
|
184 | + $mountType, |
|
185 | + $applicable, |
|
186 | + $storageOptions |
|
187 | + ); |
|
188 | + if ($hasId) { |
|
189 | + $storages[$configId] = $currentStorage; |
|
190 | + } else { |
|
191 | + $storagesWithConfigHash[$configId] = $currentStorage; |
|
192 | + } |
|
193 | + } catch (\UnexpectedValueException $e) { |
|
194 | + // don't die if a storage backend doesn't exist |
|
195 | + \OCP\Util::writeLog( |
|
196 | + 'files_external', |
|
197 | + 'Could not load storage: "' . $e->getMessage() . '"', |
|
198 | + \OCP\Util::ERROR |
|
199 | + ); |
|
200 | + } |
|
201 | + } |
|
202 | + } |
|
203 | + } |
|
204 | 204 | |
205 | - // convert parameter values |
|
206 | - foreach ($storages as $storage) { |
|
207 | - $storage->getBackend()->validateStorageDefinition($storage); |
|
208 | - $storage->getAuthMechanism()->validateStorageDefinition($storage); |
|
209 | - } |
|
210 | - return $storages; |
|
211 | - } |
|
205 | + // convert parameter values |
|
206 | + foreach ($storages as $storage) { |
|
207 | + $storage->getBackend()->validateStorageDefinition($storage); |
|
208 | + $storage->getAuthMechanism()->validateStorageDefinition($storage); |
|
209 | + } |
|
210 | + return $storages; |
|
211 | + } |
|
212 | 212 | } |
@@ -30,46 +30,46 @@ |
||
30 | 30 | */ |
31 | 31 | trait UserTrait { |
32 | 32 | |
33 | - /** @var IUserSession */ |
|
34 | - protected $userSession; |
|
33 | + /** @var IUserSession */ |
|
34 | + protected $userSession; |
|
35 | 35 | |
36 | - /** |
|
37 | - * User override |
|
38 | - * |
|
39 | - * @var IUser|null |
|
40 | - */ |
|
41 | - private $user = null; |
|
36 | + /** |
|
37 | + * User override |
|
38 | + * |
|
39 | + * @var IUser|null |
|
40 | + */ |
|
41 | + private $user = null; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @return IUser|null |
|
45 | - */ |
|
46 | - protected function getUser() { |
|
47 | - if ($this->user) { |
|
48 | - return $this->user; |
|
49 | - } |
|
50 | - return $this->userSession->getUser(); |
|
51 | - } |
|
43 | + /** |
|
44 | + * @return IUser|null |
|
45 | + */ |
|
46 | + protected function getUser() { |
|
47 | + if ($this->user) { |
|
48 | + return $this->user; |
|
49 | + } |
|
50 | + return $this->userSession->getUser(); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Override the user from the session |
|
55 | - * Unset with ->resetUser() when finished! |
|
56 | - * |
|
57 | - * @param IUser |
|
58 | - * @return self |
|
59 | - */ |
|
60 | - public function setUser(IUser $user) { |
|
61 | - $this->user = $user; |
|
62 | - return $this; |
|
63 | - } |
|
53 | + /** |
|
54 | + * Override the user from the session |
|
55 | + * Unset with ->resetUser() when finished! |
|
56 | + * |
|
57 | + * @param IUser |
|
58 | + * @return self |
|
59 | + */ |
|
60 | + public function setUser(IUser $user) { |
|
61 | + $this->user = $user; |
|
62 | + return $this; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Reset the user override |
|
67 | - * |
|
68 | - * @return self |
|
69 | - */ |
|
70 | - public function resetUser() { |
|
71 | - $this->user = null; |
|
72 | - return $this; |
|
73 | - } |
|
65 | + /** |
|
66 | + * Reset the user override |
|
67 | + * |
|
68 | + * @return self |
|
69 | + */ |
|
70 | + public function resetUser() { |
|
71 | + $this->user = null; |
|
72 | + return $this; |
|
73 | + } |
|
74 | 74 | } |
75 | 75 |
@@ -40,105 +40,105 @@ |
||
40 | 40 | * (aka personal storages) |
41 | 41 | */ |
42 | 42 | class UserStoragesService extends StoragesService { |
43 | - use UserTrait; |
|
43 | + use UserTrait; |
|
44 | 44 | |
45 | - /** |
|
46 | - * Create a user storages service |
|
47 | - * |
|
48 | - * @param BackendService $backendService |
|
49 | - * @param DBConfigService $dbConfig |
|
50 | - * @param IUserSession $userSession user session |
|
51 | - * @param IUserMountCache $userMountCache |
|
52 | - */ |
|
53 | - public function __construct( |
|
54 | - BackendService $backendService, |
|
55 | - DBConfigService $dbConfig, |
|
56 | - IUserSession $userSession, |
|
57 | - IUserMountCache $userMountCache |
|
58 | - ) { |
|
59 | - $this->userSession = $userSession; |
|
60 | - parent::__construct($backendService, $dbConfig, $userMountCache); |
|
61 | - } |
|
45 | + /** |
|
46 | + * Create a user storages service |
|
47 | + * |
|
48 | + * @param BackendService $backendService |
|
49 | + * @param DBConfigService $dbConfig |
|
50 | + * @param IUserSession $userSession user session |
|
51 | + * @param IUserMountCache $userMountCache |
|
52 | + */ |
|
53 | + public function __construct( |
|
54 | + BackendService $backendService, |
|
55 | + DBConfigService $dbConfig, |
|
56 | + IUserSession $userSession, |
|
57 | + IUserMountCache $userMountCache |
|
58 | + ) { |
|
59 | + $this->userSession = $userSession; |
|
60 | + parent::__construct($backendService, $dbConfig, $userMountCache); |
|
61 | + } |
|
62 | 62 | |
63 | - protected function readDBConfig() { |
|
64 | - return $this->dbConfig->getUserMountsFor(DBConfigService::APPLICABLE_TYPE_USER, $this->getUser()->getUID()); |
|
65 | - } |
|
63 | + protected function readDBConfig() { |
|
64 | + return $this->dbConfig->getUserMountsFor(DBConfigService::APPLICABLE_TYPE_USER, $this->getUser()->getUID()); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Triggers $signal for all applicable users of the given |
|
69 | - * storage |
|
70 | - * |
|
71 | - * @param StorageConfig $storage storage data |
|
72 | - * @param string $signal signal to trigger |
|
73 | - */ |
|
74 | - protected function triggerHooks(StorageConfig $storage, $signal) { |
|
75 | - $user = $this->getUser()->getUID(); |
|
67 | + /** |
|
68 | + * Triggers $signal for all applicable users of the given |
|
69 | + * storage |
|
70 | + * |
|
71 | + * @param StorageConfig $storage storage data |
|
72 | + * @param string $signal signal to trigger |
|
73 | + */ |
|
74 | + protected function triggerHooks(StorageConfig $storage, $signal) { |
|
75 | + $user = $this->getUser()->getUID(); |
|
76 | 76 | |
77 | - // trigger hook for the current user |
|
78 | - $this->triggerApplicableHooks( |
|
79 | - $signal, |
|
80 | - $storage->getMountPoint(), |
|
81 | - \OC_Mount_Config::MOUNT_TYPE_USER, |
|
82 | - [$user] |
|
83 | - ); |
|
84 | - } |
|
77 | + // trigger hook for the current user |
|
78 | + $this->triggerApplicableHooks( |
|
79 | + $signal, |
|
80 | + $storage->getMountPoint(), |
|
81 | + \OC_Mount_Config::MOUNT_TYPE_USER, |
|
82 | + [$user] |
|
83 | + ); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Triggers signal_create_mount or signal_delete_mount to |
|
88 | - * accommodate for additions/deletions in applicableUsers |
|
89 | - * and applicableGroups fields. |
|
90 | - * |
|
91 | - * @param StorageConfig $oldStorage old storage data |
|
92 | - * @param StorageConfig $newStorage new storage data |
|
93 | - */ |
|
94 | - protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage) { |
|
95 | - // if mount point changed, it's like a deletion + creation |
|
96 | - if ($oldStorage->getMountPoint() !== $newStorage->getMountPoint()) { |
|
97 | - $this->triggerHooks($oldStorage, Filesystem::signal_delete_mount); |
|
98 | - $this->triggerHooks($newStorage, Filesystem::signal_create_mount); |
|
99 | - } |
|
100 | - } |
|
86 | + /** |
|
87 | + * Triggers signal_create_mount or signal_delete_mount to |
|
88 | + * accommodate for additions/deletions in applicableUsers |
|
89 | + * and applicableGroups fields. |
|
90 | + * |
|
91 | + * @param StorageConfig $oldStorage old storage data |
|
92 | + * @param StorageConfig $newStorage new storage data |
|
93 | + */ |
|
94 | + protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage) { |
|
95 | + // if mount point changed, it's like a deletion + creation |
|
96 | + if ($oldStorage->getMountPoint() !== $newStorage->getMountPoint()) { |
|
97 | + $this->triggerHooks($oldStorage, Filesystem::signal_delete_mount); |
|
98 | + $this->triggerHooks($newStorage, Filesystem::signal_create_mount); |
|
99 | + } |
|
100 | + } |
|
101 | 101 | |
102 | - protected function getType() { |
|
103 | - return DBConfigService::MOUNT_TYPE_PERSONAl; |
|
104 | - } |
|
102 | + protected function getType() { |
|
103 | + return DBConfigService::MOUNT_TYPE_PERSONAl; |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * Add new storage to the configuration |
|
108 | - * |
|
109 | - * @param StorageConfig $newStorage storage attributes |
|
110 | - * |
|
111 | - * @return StorageConfig storage config, with added id |
|
112 | - */ |
|
113 | - public function addStorage(StorageConfig $newStorage) { |
|
114 | - $newStorage->setApplicableUsers([$this->getUser()->getUID()]); |
|
115 | - $config = parent::addStorage($newStorage); |
|
116 | - return $config; |
|
117 | - } |
|
106 | + /** |
|
107 | + * Add new storage to the configuration |
|
108 | + * |
|
109 | + * @param StorageConfig $newStorage storage attributes |
|
110 | + * |
|
111 | + * @return StorageConfig storage config, with added id |
|
112 | + */ |
|
113 | + public function addStorage(StorageConfig $newStorage) { |
|
114 | + $newStorage->setApplicableUsers([$this->getUser()->getUID()]); |
|
115 | + $config = parent::addStorage($newStorage); |
|
116 | + return $config; |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * Update storage to the configuration |
|
121 | - * |
|
122 | - * @param StorageConfig $updatedStorage storage attributes |
|
123 | - * |
|
124 | - * @return StorageConfig storage config |
|
125 | - * @throws NotFoundException if the given storage does not exist in the config |
|
126 | - */ |
|
127 | - public function updateStorage(StorageConfig $updatedStorage) { |
|
128 | - $updatedStorage->setApplicableUsers([$this->getUser()->getUID()]); |
|
129 | - return parent::updateStorage($updatedStorage); |
|
130 | - } |
|
119 | + /** |
|
120 | + * Update storage to the configuration |
|
121 | + * |
|
122 | + * @param StorageConfig $updatedStorage storage attributes |
|
123 | + * |
|
124 | + * @return StorageConfig storage config |
|
125 | + * @throws NotFoundException if the given storage does not exist in the config |
|
126 | + */ |
|
127 | + public function updateStorage(StorageConfig $updatedStorage) { |
|
128 | + $updatedStorage->setApplicableUsers([$this->getUser()->getUID()]); |
|
129 | + return parent::updateStorage($updatedStorage); |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * Get the visibility type for this controller, used in validation |
|
134 | - * |
|
135 | - * @return string BackendService::VISIBILITY_* constants |
|
136 | - */ |
|
137 | - public function getVisibilityType() { |
|
138 | - return BackendService::VISIBILITY_PERSONAL; |
|
139 | - } |
|
132 | + /** |
|
133 | + * Get the visibility type for this controller, used in validation |
|
134 | + * |
|
135 | + * @return string BackendService::VISIBILITY_* constants |
|
136 | + */ |
|
137 | + public function getVisibilityType() { |
|
138 | + return BackendService::VISIBILITY_PERSONAL; |
|
139 | + } |
|
140 | 140 | |
141 | - protected function isApplicable(StorageConfig $config) { |
|
142 | - return ($config->getApplicableUsers() === [$this->getUser()->getUID()]) && $config->getType() === StorageConfig::MOUNT_TYPE_PERSONAl; |
|
143 | - } |
|
141 | + protected function isApplicable(StorageConfig $config) { |
|
142 | + return ($config->getApplicableUsers() === [$this->getUser()->getUID()]) && $config->getType() === StorageConfig::MOUNT_TYPE_PERSONAl; |
|
143 | + } |
|
144 | 144 | } |
@@ -45,143 +45,143 @@ |
||
45 | 45 | */ |
46 | 46 | class ConfigAdapter implements IMountProvider { |
47 | 47 | |
48 | - /** @var UserStoragesService */ |
|
49 | - private $userStoragesService; |
|
50 | - |
|
51 | - /** @var UserGlobalStoragesService */ |
|
52 | - private $userGlobalStoragesService; |
|
53 | - /** @var StorageMigrator */ |
|
54 | - private $migrator; |
|
55 | - |
|
56 | - /** |
|
57 | - * @param UserStoragesService $userStoragesService |
|
58 | - * @param UserGlobalStoragesService $userGlobalStoragesService |
|
59 | - * @param StorageMigrator $migrator |
|
60 | - */ |
|
61 | - public function __construct( |
|
62 | - UserStoragesService $userStoragesService, |
|
63 | - UserGlobalStoragesService $userGlobalStoragesService, |
|
64 | - StorageMigrator $migrator |
|
65 | - ) { |
|
66 | - $this->userStoragesService = $userStoragesService; |
|
67 | - $this->userGlobalStoragesService = $userGlobalStoragesService; |
|
68 | - $this->migrator = $migrator; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Process storage ready for mounting |
|
73 | - * |
|
74 | - * @param StorageConfig $storage |
|
75 | - * @param IUser $user |
|
76 | - */ |
|
77 | - private function prepareStorageConfig(StorageConfig &$storage, IUser $user) { |
|
78 | - foreach ($storage->getBackendOptions() as $option => $value) { |
|
79 | - $storage->setBackendOption($option, \OC_Mount_Config::setUserVars( |
|
80 | - $user->getUID(), $value |
|
81 | - )); |
|
82 | - } |
|
83 | - |
|
84 | - $objectStore = $storage->getBackendOption('objectstore'); |
|
85 | - if ($objectStore) { |
|
86 | - $objectClass = $objectStore['class']; |
|
87 | - if (!is_subclass_of($objectClass, '\OCP\Files\ObjectStore\IObjectStore')) { |
|
88 | - throw new \InvalidArgumentException('Invalid object store'); |
|
89 | - } |
|
90 | - $storage->setBackendOption('objectstore', new $objectClass($objectStore)); |
|
91 | - } |
|
92 | - |
|
93 | - $storage->getAuthMechanism()->manipulateStorageConfig($storage, $user); |
|
94 | - $storage->getBackend()->manipulateStorageConfig($storage, $user); |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Construct the storage implementation |
|
99 | - * |
|
100 | - * @param StorageConfig $storageConfig |
|
101 | - * @return Storage |
|
102 | - */ |
|
103 | - private function constructStorage(StorageConfig $storageConfig) { |
|
104 | - $class = $storageConfig->getBackend()->getStorageClass(); |
|
105 | - $storage = new $class($storageConfig->getBackendOptions()); |
|
106 | - |
|
107 | - // auth mechanism should fire first |
|
108 | - $storage = $storageConfig->getBackend()->wrapStorage($storage); |
|
109 | - $storage = $storageConfig->getAuthMechanism()->wrapStorage($storage); |
|
110 | - |
|
111 | - return $storage; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Get all mountpoints applicable for the user |
|
116 | - * |
|
117 | - * @param \OCP\IUser $user |
|
118 | - * @param \OCP\Files\Storage\IStorageFactory $loader |
|
119 | - * @return \OCP\Files\Mount\IMountPoint[] |
|
120 | - */ |
|
121 | - public function getMountsForUser(IUser $user, IStorageFactory $loader) { |
|
122 | - $this->migrator->migrateUser($user); |
|
123 | - |
|
124 | - $this->userStoragesService->setUser($user); |
|
125 | - $this->userGlobalStoragesService->setUser($user); |
|
126 | - |
|
127 | - $storageConfigs = $this->userGlobalStoragesService->getAllStoragesForUser(); |
|
128 | - |
|
129 | - $storages = array_map(function(StorageConfig $storageConfig) use ($user) { |
|
130 | - try { |
|
131 | - $this->prepareStorageConfig($storageConfig, $user); |
|
132 | - return $this->constructStorage($storageConfig); |
|
133 | - } catch (\Exception $e) { |
|
134 | - // propagate exception into filesystem |
|
135 | - return new FailedStorage(['exception' => $e]); |
|
136 | - } |
|
137 | - }, $storageConfigs); |
|
138 | - |
|
139 | - |
|
140 | - \OC\Files\Cache\Storage::getGlobalCache()->loadForStorageIds(array_map(function(Storage\IStorage $storage) { |
|
141 | - return $storage->getId(); |
|
142 | - }, $storages)); |
|
143 | - |
|
144 | - $availableStorages = array_map(function (Storage\IStorage $storage, StorageConfig $storageConfig) { |
|
145 | - try { |
|
146 | - $availability = $storage->getAvailability(); |
|
147 | - if (!$availability['available'] && !Availability::shouldRecheck($availability)) { |
|
148 | - $storage = new FailedStorage([ |
|
149 | - 'exception' => new StorageNotAvailableException('Storage with mount id ' . $storageConfig->getId() . ' is not available') |
|
150 | - ]); |
|
151 | - } |
|
152 | - } catch (\Exception $e) { |
|
153 | - // propagate exception into filesystem |
|
154 | - $storage = new FailedStorage(['exception' => $e]); |
|
155 | - } |
|
156 | - return $storage; |
|
157 | - }, $storages, $storageConfigs); |
|
158 | - |
|
159 | - $mounts = array_map(function(StorageConfig $storageConfig, Storage\IStorage $storage) use ($user, $loader) { |
|
160 | - if ($storageConfig->getType() === StorageConfig::MOUNT_TYPE_PERSONAl) { |
|
161 | - return new PersonalMount( |
|
162 | - $this->userStoragesService, |
|
163 | - $storageConfig->getId(), |
|
164 | - $storage, |
|
165 | - '/' . $user->getUID() . '/files' . $storageConfig->getMountPoint(), |
|
166 | - null, |
|
167 | - $loader, |
|
168 | - $storageConfig->getMountOptions() |
|
169 | - ); |
|
170 | - } else { |
|
171 | - return new MountPoint( |
|
172 | - $storage, |
|
173 | - '/' . $user->getUID() . '/files' . $storageConfig->getMountPoint(), |
|
174 | - null, |
|
175 | - $loader, |
|
176 | - $storageConfig->getMountOptions(), |
|
177 | - $storageConfig->getId() |
|
178 | - ); |
|
179 | - } |
|
180 | - }, $storageConfigs, $availableStorages); |
|
181 | - |
|
182 | - $this->userStoragesService->resetUser(); |
|
183 | - $this->userGlobalStoragesService->resetUser(); |
|
184 | - |
|
185 | - return $mounts; |
|
186 | - } |
|
48 | + /** @var UserStoragesService */ |
|
49 | + private $userStoragesService; |
|
50 | + |
|
51 | + /** @var UserGlobalStoragesService */ |
|
52 | + private $userGlobalStoragesService; |
|
53 | + /** @var StorageMigrator */ |
|
54 | + private $migrator; |
|
55 | + |
|
56 | + /** |
|
57 | + * @param UserStoragesService $userStoragesService |
|
58 | + * @param UserGlobalStoragesService $userGlobalStoragesService |
|
59 | + * @param StorageMigrator $migrator |
|
60 | + */ |
|
61 | + public function __construct( |
|
62 | + UserStoragesService $userStoragesService, |
|
63 | + UserGlobalStoragesService $userGlobalStoragesService, |
|
64 | + StorageMigrator $migrator |
|
65 | + ) { |
|
66 | + $this->userStoragesService = $userStoragesService; |
|
67 | + $this->userGlobalStoragesService = $userGlobalStoragesService; |
|
68 | + $this->migrator = $migrator; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Process storage ready for mounting |
|
73 | + * |
|
74 | + * @param StorageConfig $storage |
|
75 | + * @param IUser $user |
|
76 | + */ |
|
77 | + private function prepareStorageConfig(StorageConfig &$storage, IUser $user) { |
|
78 | + foreach ($storage->getBackendOptions() as $option => $value) { |
|
79 | + $storage->setBackendOption($option, \OC_Mount_Config::setUserVars( |
|
80 | + $user->getUID(), $value |
|
81 | + )); |
|
82 | + } |
|
83 | + |
|
84 | + $objectStore = $storage->getBackendOption('objectstore'); |
|
85 | + if ($objectStore) { |
|
86 | + $objectClass = $objectStore['class']; |
|
87 | + if (!is_subclass_of($objectClass, '\OCP\Files\ObjectStore\IObjectStore')) { |
|
88 | + throw new \InvalidArgumentException('Invalid object store'); |
|
89 | + } |
|
90 | + $storage->setBackendOption('objectstore', new $objectClass($objectStore)); |
|
91 | + } |
|
92 | + |
|
93 | + $storage->getAuthMechanism()->manipulateStorageConfig($storage, $user); |
|
94 | + $storage->getBackend()->manipulateStorageConfig($storage, $user); |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Construct the storage implementation |
|
99 | + * |
|
100 | + * @param StorageConfig $storageConfig |
|
101 | + * @return Storage |
|
102 | + */ |
|
103 | + private function constructStorage(StorageConfig $storageConfig) { |
|
104 | + $class = $storageConfig->getBackend()->getStorageClass(); |
|
105 | + $storage = new $class($storageConfig->getBackendOptions()); |
|
106 | + |
|
107 | + // auth mechanism should fire first |
|
108 | + $storage = $storageConfig->getBackend()->wrapStorage($storage); |
|
109 | + $storage = $storageConfig->getAuthMechanism()->wrapStorage($storage); |
|
110 | + |
|
111 | + return $storage; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Get all mountpoints applicable for the user |
|
116 | + * |
|
117 | + * @param \OCP\IUser $user |
|
118 | + * @param \OCP\Files\Storage\IStorageFactory $loader |
|
119 | + * @return \OCP\Files\Mount\IMountPoint[] |
|
120 | + */ |
|
121 | + public function getMountsForUser(IUser $user, IStorageFactory $loader) { |
|
122 | + $this->migrator->migrateUser($user); |
|
123 | + |
|
124 | + $this->userStoragesService->setUser($user); |
|
125 | + $this->userGlobalStoragesService->setUser($user); |
|
126 | + |
|
127 | + $storageConfigs = $this->userGlobalStoragesService->getAllStoragesForUser(); |
|
128 | + |
|
129 | + $storages = array_map(function(StorageConfig $storageConfig) use ($user) { |
|
130 | + try { |
|
131 | + $this->prepareStorageConfig($storageConfig, $user); |
|
132 | + return $this->constructStorage($storageConfig); |
|
133 | + } catch (\Exception $e) { |
|
134 | + // propagate exception into filesystem |
|
135 | + return new FailedStorage(['exception' => $e]); |
|
136 | + } |
|
137 | + }, $storageConfigs); |
|
138 | + |
|
139 | + |
|
140 | + \OC\Files\Cache\Storage::getGlobalCache()->loadForStorageIds(array_map(function(Storage\IStorage $storage) { |
|
141 | + return $storage->getId(); |
|
142 | + }, $storages)); |
|
143 | + |
|
144 | + $availableStorages = array_map(function (Storage\IStorage $storage, StorageConfig $storageConfig) { |
|
145 | + try { |
|
146 | + $availability = $storage->getAvailability(); |
|
147 | + if (!$availability['available'] && !Availability::shouldRecheck($availability)) { |
|
148 | + $storage = new FailedStorage([ |
|
149 | + 'exception' => new StorageNotAvailableException('Storage with mount id ' . $storageConfig->getId() . ' is not available') |
|
150 | + ]); |
|
151 | + } |
|
152 | + } catch (\Exception $e) { |
|
153 | + // propagate exception into filesystem |
|
154 | + $storage = new FailedStorage(['exception' => $e]); |
|
155 | + } |
|
156 | + return $storage; |
|
157 | + }, $storages, $storageConfigs); |
|
158 | + |
|
159 | + $mounts = array_map(function(StorageConfig $storageConfig, Storage\IStorage $storage) use ($user, $loader) { |
|
160 | + if ($storageConfig->getType() === StorageConfig::MOUNT_TYPE_PERSONAl) { |
|
161 | + return new PersonalMount( |
|
162 | + $this->userStoragesService, |
|
163 | + $storageConfig->getId(), |
|
164 | + $storage, |
|
165 | + '/' . $user->getUID() . '/files' . $storageConfig->getMountPoint(), |
|
166 | + null, |
|
167 | + $loader, |
|
168 | + $storageConfig->getMountOptions() |
|
169 | + ); |
|
170 | + } else { |
|
171 | + return new MountPoint( |
|
172 | + $storage, |
|
173 | + '/' . $user->getUID() . '/files' . $storageConfig->getMountPoint(), |
|
174 | + null, |
|
175 | + $loader, |
|
176 | + $storageConfig->getMountOptions(), |
|
177 | + $storageConfig->getId() |
|
178 | + ); |
|
179 | + } |
|
180 | + }, $storageConfigs, $availableStorages); |
|
181 | + |
|
182 | + $this->userStoragesService->resetUser(); |
|
183 | + $this->userGlobalStoragesService->resetUser(); |
|
184 | + |
|
185 | + return $mounts; |
|
186 | + } |
|
187 | 187 | } |
@@ -28,26 +28,26 @@ |
||
28 | 28 | |
29 | 29 | class DummyUserSession implements IUserSession { |
30 | 30 | |
31 | - /** |
|
32 | - * @var IUser |
|
33 | - */ |
|
34 | - private $user; |
|
31 | + /** |
|
32 | + * @var IUser |
|
33 | + */ |
|
34 | + private $user; |
|
35 | 35 | |
36 | - public function login($user, $password) { |
|
37 | - } |
|
36 | + public function login($user, $password) { |
|
37 | + } |
|
38 | 38 | |
39 | - public function logout() { |
|
40 | - } |
|
39 | + public function logout() { |
|
40 | + } |
|
41 | 41 | |
42 | - public function setUser($user) { |
|
43 | - $this->user = $user; |
|
44 | - } |
|
42 | + public function setUser($user) { |
|
43 | + $this->user = $user; |
|
44 | + } |
|
45 | 45 | |
46 | - public function getUser() { |
|
47 | - return $this->user; |
|
48 | - } |
|
46 | + public function getUser() { |
|
47 | + return $this->user; |
|
48 | + } |
|
49 | 49 | |
50 | - public function isLoggedIn() { |
|
51 | - return !is_null($this->user); |
|
52 | - } |
|
50 | + public function isLoggedIn() { |
|
51 | + return !is_null($this->user); |
|
52 | + } |
|
53 | 53 | } |
@@ -30,30 +30,30 @@ |
||
30 | 30 | |
31 | 31 | class Export extends ListCommand { |
32 | 32 | |
33 | - protected function configure() { |
|
34 | - $this |
|
35 | - ->setName('files_external:export') |
|
36 | - ->setDescription('Export mount configurations') |
|
37 | - ->addArgument( |
|
38 | - 'user_id', |
|
39 | - InputArgument::OPTIONAL, |
|
40 | - 'user id to export the personal mounts for, if no user is provided admin mounts will be exported' |
|
41 | - )->addOption( |
|
42 | - 'all', |
|
43 | - 'a', |
|
44 | - InputOption::VALUE_NONE, |
|
45 | - 'show both system wide mounts and all personal mounts' |
|
46 | - ); |
|
47 | - } |
|
33 | + protected function configure() { |
|
34 | + $this |
|
35 | + ->setName('files_external:export') |
|
36 | + ->setDescription('Export mount configurations') |
|
37 | + ->addArgument( |
|
38 | + 'user_id', |
|
39 | + InputArgument::OPTIONAL, |
|
40 | + 'user id to export the personal mounts for, if no user is provided admin mounts will be exported' |
|
41 | + )->addOption( |
|
42 | + 'all', |
|
43 | + 'a', |
|
44 | + InputOption::VALUE_NONE, |
|
45 | + 'show both system wide mounts and all personal mounts' |
|
46 | + ); |
|
47 | + } |
|
48 | 48 | |
49 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
50 | - $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager); |
|
51 | - $listInput = new ArrayInput([], $listCommand->getDefinition()); |
|
52 | - $listInput->setArgument('user_id', $input->getArgument('user_id')); |
|
53 | - $listInput->setOption('all', $input->getOption('all')); |
|
54 | - $listInput->setOption('output', 'json_pretty'); |
|
55 | - $listInput->setOption('show-password', true); |
|
56 | - $listInput->setOption('full', true); |
|
57 | - $listCommand->execute($listInput, $output); |
|
58 | - } |
|
49 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
50 | + $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager); |
|
51 | + $listInput = new ArrayInput([], $listCommand->getDefinition()); |
|
52 | + $listInput->setArgument('user_id', $input->getArgument('user_id')); |
|
53 | + $listInput->setOption('all', $input->getOption('all')); |
|
54 | + $listInput->setOption('output', 'json_pretty'); |
|
55 | + $listInput->setOption('show-password', true); |
|
56 | + $listInput->setOption('full', true); |
|
57 | + $listCommand->execute($listInput, $output); |
|
58 | + } |
|
59 | 59 | } |
@@ -37,108 +37,108 @@ |
||
37 | 37 | use Symfony\Component\Console\Output\OutputInterface; |
38 | 38 | |
39 | 39 | class Verify extends Base { |
40 | - /** |
|
41 | - * @var GlobalStoragesService |
|
42 | - */ |
|
43 | - protected $globalService; |
|
40 | + /** |
|
41 | + * @var GlobalStoragesService |
|
42 | + */ |
|
43 | + protected $globalService; |
|
44 | 44 | |
45 | - function __construct(GlobalStoragesService $globalService) { |
|
46 | - parent::__construct(); |
|
47 | - $this->globalService = $globalService; |
|
48 | - } |
|
45 | + function __construct(GlobalStoragesService $globalService) { |
|
46 | + parent::__construct(); |
|
47 | + $this->globalService = $globalService; |
|
48 | + } |
|
49 | 49 | |
50 | - protected function configure() { |
|
51 | - $this |
|
52 | - ->setName('files_external:verify') |
|
53 | - ->setDescription('Verify mount configuration') |
|
54 | - ->addArgument( |
|
55 | - 'mount_id', |
|
56 | - InputArgument::REQUIRED, |
|
57 | - 'The id of the mount to check' |
|
58 | - )->addOption( |
|
59 | - 'config', |
|
60 | - 'c', |
|
61 | - InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
|
62 | - 'Additional config option to set before checking in key=value pairs, required for certain auth backends such as login credentails' |
|
63 | - ); |
|
64 | - parent::configure(); |
|
65 | - } |
|
50 | + protected function configure() { |
|
51 | + $this |
|
52 | + ->setName('files_external:verify') |
|
53 | + ->setDescription('Verify mount configuration') |
|
54 | + ->addArgument( |
|
55 | + 'mount_id', |
|
56 | + InputArgument::REQUIRED, |
|
57 | + 'The id of the mount to check' |
|
58 | + )->addOption( |
|
59 | + 'config', |
|
60 | + 'c', |
|
61 | + InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
|
62 | + 'Additional config option to set before checking in key=value pairs, required for certain auth backends such as login credentails' |
|
63 | + ); |
|
64 | + parent::configure(); |
|
65 | + } |
|
66 | 66 | |
67 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
68 | - $mountId = $input->getArgument('mount_id'); |
|
69 | - $configInput = $input->getOption('config'); |
|
67 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
68 | + $mountId = $input->getArgument('mount_id'); |
|
69 | + $configInput = $input->getOption('config'); |
|
70 | 70 | |
71 | - try { |
|
72 | - $mount = $this->globalService->getStorage($mountId); |
|
73 | - } catch (NotFoundException $e) { |
|
74 | - $output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts"</error>'); |
|
75 | - return 404; |
|
76 | - } |
|
71 | + try { |
|
72 | + $mount = $this->globalService->getStorage($mountId); |
|
73 | + } catch (NotFoundException $e) { |
|
74 | + $output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts"</error>'); |
|
75 | + return 404; |
|
76 | + } |
|
77 | 77 | |
78 | - $this->updateStorageStatus($mount, $configInput, $output); |
|
78 | + $this->updateStorageStatus($mount, $configInput, $output); |
|
79 | 79 | |
80 | - $this->writeArrayInOutputFormat($input, $output, [ |
|
81 | - 'status' => StorageNotAvailableException::getStateCodeName($mount->getStatus()), |
|
82 | - 'code' => $mount->getStatus(), |
|
83 | - 'message' => $mount->getStatusMessage() |
|
84 | - ]); |
|
85 | - } |
|
80 | + $this->writeArrayInOutputFormat($input, $output, [ |
|
81 | + 'status' => StorageNotAvailableException::getStateCodeName($mount->getStatus()), |
|
82 | + 'code' => $mount->getStatus(), |
|
83 | + 'message' => $mount->getStatusMessage() |
|
84 | + ]); |
|
85 | + } |
|
86 | 86 | |
87 | - private function manipulateStorageConfig(StorageConfig $storage) { |
|
88 | - /** @var AuthMechanism */ |
|
89 | - $authMechanism = $storage->getAuthMechanism(); |
|
90 | - $authMechanism->manipulateStorageConfig($storage); |
|
91 | - /** @var Backend */ |
|
92 | - $backend = $storage->getBackend(); |
|
93 | - $backend->manipulateStorageConfig($storage); |
|
94 | - } |
|
87 | + private function manipulateStorageConfig(StorageConfig $storage) { |
|
88 | + /** @var AuthMechanism */ |
|
89 | + $authMechanism = $storage->getAuthMechanism(); |
|
90 | + $authMechanism->manipulateStorageConfig($storage); |
|
91 | + /** @var Backend */ |
|
92 | + $backend = $storage->getBackend(); |
|
93 | + $backend->manipulateStorageConfig($storage); |
|
94 | + } |
|
95 | 95 | |
96 | - private function updateStorageStatus(StorageConfig &$storage, $configInput, OutputInterface $output) { |
|
97 | - try { |
|
98 | - try { |
|
99 | - $this->manipulateStorageConfig($storage); |
|
100 | - } catch (InsufficientDataForMeaningfulAnswerException $e) { |
|
101 | - if (count($configInput) === 0) { // extra config options might solve the error |
|
102 | - throw $e; |
|
103 | - } |
|
104 | - } |
|
96 | + private function updateStorageStatus(StorageConfig &$storage, $configInput, OutputInterface $output) { |
|
97 | + try { |
|
98 | + try { |
|
99 | + $this->manipulateStorageConfig($storage); |
|
100 | + } catch (InsufficientDataForMeaningfulAnswerException $e) { |
|
101 | + if (count($configInput) === 0) { // extra config options might solve the error |
|
102 | + throw $e; |
|
103 | + } |
|
104 | + } |
|
105 | 105 | |
106 | - foreach ($configInput as $configOption) { |
|
107 | - if (!strpos($configOption, '=')) { |
|
108 | - $output->writeln('<error>Invalid mount configuration option "' . $configOption . '"</error>'); |
|
109 | - return; |
|
110 | - } |
|
111 | - list($key, $value) = explode('=', $configOption, 2); |
|
112 | - $storage->setBackendOption($key, $value); |
|
113 | - } |
|
106 | + foreach ($configInput as $configOption) { |
|
107 | + if (!strpos($configOption, '=')) { |
|
108 | + $output->writeln('<error>Invalid mount configuration option "' . $configOption . '"</error>'); |
|
109 | + return; |
|
110 | + } |
|
111 | + list($key, $value) = explode('=', $configOption, 2); |
|
112 | + $storage->setBackendOption($key, $value); |
|
113 | + } |
|
114 | 114 | |
115 | - /** @var Backend */ |
|
116 | - $backend = $storage->getBackend(); |
|
117 | - // update status (can be time-consuming) |
|
118 | - $storage->setStatus( |
|
119 | - \OC_Mount_Config::getBackendStatus( |
|
120 | - $backend->getStorageClass(), |
|
121 | - $storage->getBackendOptions(), |
|
122 | - false |
|
123 | - ) |
|
124 | - ); |
|
125 | - } catch (InsufficientDataForMeaningfulAnswerException $e) { |
|
126 | - $status = $e->getCode() ? $e->getCode() : StorageNotAvailableException::STATUS_INDETERMINATE; |
|
127 | - $storage->setStatus( |
|
128 | - $status, |
|
129 | - $e->getMessage() |
|
130 | - ); |
|
131 | - } catch (StorageNotAvailableException $e) { |
|
132 | - $storage->setStatus( |
|
133 | - $e->getCode(), |
|
134 | - $e->getMessage() |
|
135 | - ); |
|
136 | - } catch (\Exception $e) { |
|
137 | - // FIXME: convert storage exceptions to StorageNotAvailableException |
|
138 | - $storage->setStatus( |
|
139 | - StorageNotAvailableException::STATUS_ERROR, |
|
140 | - get_class($e) . ': ' . $e->getMessage() |
|
141 | - ); |
|
142 | - } |
|
143 | - } |
|
115 | + /** @var Backend */ |
|
116 | + $backend = $storage->getBackend(); |
|
117 | + // update status (can be time-consuming) |
|
118 | + $storage->setStatus( |
|
119 | + \OC_Mount_Config::getBackendStatus( |
|
120 | + $backend->getStorageClass(), |
|
121 | + $storage->getBackendOptions(), |
|
122 | + false |
|
123 | + ) |
|
124 | + ); |
|
125 | + } catch (InsufficientDataForMeaningfulAnswerException $e) { |
|
126 | + $status = $e->getCode() ? $e->getCode() : StorageNotAvailableException::STATUS_INDETERMINATE; |
|
127 | + $storage->setStatus( |
|
128 | + $status, |
|
129 | + $e->getMessage() |
|
130 | + ); |
|
131 | + } catch (StorageNotAvailableException $e) { |
|
132 | + $storage->setStatus( |
|
133 | + $e->getCode(), |
|
134 | + $e->getMessage() |
|
135 | + ); |
|
136 | + } catch (\Exception $e) { |
|
137 | + // FIXME: convert storage exceptions to StorageNotAvailableException |
|
138 | + $storage->setStatus( |
|
139 | + StorageNotAvailableException::STATUS_ERROR, |
|
140 | + get_class($e) . ': ' . $e->getMessage() |
|
141 | + ); |
|
142 | + } |
|
143 | + } |
|
144 | 144 | } |
@@ -28,50 +28,50 @@ |
||
28 | 28 | use Symfony\Component\Console\Output\OutputInterface; |
29 | 29 | |
30 | 30 | class Option extends Config { |
31 | - protected function configure() { |
|
32 | - $this |
|
33 | - ->setName('files_external:option') |
|
34 | - ->setDescription('Manage mount options for a mount') |
|
35 | - ->addArgument( |
|
36 | - 'mount_id', |
|
37 | - InputArgument::REQUIRED, |
|
38 | - 'The id of the mount to edit' |
|
39 | - )->addArgument( |
|
40 | - 'key', |
|
41 | - InputArgument::REQUIRED, |
|
42 | - 'key of the mount option to set/get' |
|
43 | - )->addArgument( |
|
44 | - 'value', |
|
45 | - InputArgument::OPTIONAL, |
|
46 | - 'value to set the mount option to, when no value is provided the existing value will be printed' |
|
47 | - ); |
|
48 | - } |
|
31 | + protected function configure() { |
|
32 | + $this |
|
33 | + ->setName('files_external:option') |
|
34 | + ->setDescription('Manage mount options for a mount') |
|
35 | + ->addArgument( |
|
36 | + 'mount_id', |
|
37 | + InputArgument::REQUIRED, |
|
38 | + 'The id of the mount to edit' |
|
39 | + )->addArgument( |
|
40 | + 'key', |
|
41 | + InputArgument::REQUIRED, |
|
42 | + 'key of the mount option to set/get' |
|
43 | + )->addArgument( |
|
44 | + 'value', |
|
45 | + InputArgument::OPTIONAL, |
|
46 | + 'value to set the mount option to, when no value is provided the existing value will be printed' |
|
47 | + ); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param StorageConfig $mount |
|
52 | - * @param string $key |
|
53 | - * @param OutputInterface $output |
|
54 | - */ |
|
55 | - protected function getOption(StorageConfig $mount, $key, OutputInterface $output) { |
|
56 | - $value = $mount->getMountOption($key); |
|
57 | - if (!is_string($value)) { // show bools and objects correctly |
|
58 | - $value = json_encode($value); |
|
59 | - } |
|
60 | - $output->writeln($value); |
|
61 | - } |
|
50 | + /** |
|
51 | + * @param StorageConfig $mount |
|
52 | + * @param string $key |
|
53 | + * @param OutputInterface $output |
|
54 | + */ |
|
55 | + protected function getOption(StorageConfig $mount, $key, OutputInterface $output) { |
|
56 | + $value = $mount->getMountOption($key); |
|
57 | + if (!is_string($value)) { // show bools and objects correctly |
|
58 | + $value = json_encode($value); |
|
59 | + } |
|
60 | + $output->writeln($value); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @param StorageConfig $mount |
|
65 | - * @param string $key |
|
66 | - * @param string $value |
|
67 | - * @param OutputInterface $output |
|
68 | - */ |
|
69 | - protected function setOption(StorageConfig $mount, $key, $value, OutputInterface $output) { |
|
70 | - $decoded = json_decode($value, true); |
|
71 | - if (!is_null($decoded)) { |
|
72 | - $value = $decoded; |
|
73 | - } |
|
74 | - $mount->setMountOption($key, $value); |
|
75 | - $this->globalService->updateStorage($mount); |
|
76 | - } |
|
63 | + /** |
|
64 | + * @param StorageConfig $mount |
|
65 | + * @param string $key |
|
66 | + * @param string $value |
|
67 | + * @param OutputInterface $output |
|
68 | + */ |
|
69 | + protected function setOption(StorageConfig $mount, $key, $value, OutputInterface $output) { |
|
70 | + $decoded = json_decode($value, true); |
|
71 | + if (!is_null($decoded)) { |
|
72 | + $value = $decoded; |
|
73 | + } |
|
74 | + $mount->setMountOption($key, $value); |
|
75 | + $this->globalService->updateStorage($mount); |
|
76 | + } |
|
77 | 77 | } |