@@ -6,5 +6,5 @@ |
||
6 | 6 | $baseDir = $vendorDir; |
7 | 7 | |
8 | 8 | return array( |
9 | - 'OCA\\Files_Versions\\' => array($baseDir . '/../lib'), |
|
9 | + 'OCA\\Files_Versions\\' => array($baseDir.'/../lib'), |
|
10 | 10 | ); |
@@ -26,61 +26,61 @@ |
||
26 | 26 | |
27 | 27 | interface ILDAPGroupPlugin { |
28 | 28 | |
29 | - /** |
|
30 | - * Check if plugin implements actions |
|
31 | - * @return int |
|
32 | - * |
|
33 | - * Returns the supported actions as int to be |
|
34 | - * compared with OC_GROUP_BACKEND_CREATE_GROUP etc. |
|
35 | - */ |
|
36 | - public function respondToActions(); |
|
29 | + /** |
|
30 | + * Check if plugin implements actions |
|
31 | + * @return int |
|
32 | + * |
|
33 | + * Returns the supported actions as int to be |
|
34 | + * compared with OC_GROUP_BACKEND_CREATE_GROUP etc. |
|
35 | + */ |
|
36 | + public function respondToActions(); |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param string $gid |
|
40 | - * @return string|null The group DN if group creation was successful. |
|
41 | - */ |
|
42 | - public function createGroup($gid); |
|
38 | + /** |
|
39 | + * @param string $gid |
|
40 | + * @return string|null The group DN if group creation was successful. |
|
41 | + */ |
|
42 | + public function createGroup($gid); |
|
43 | 43 | |
44 | - /** |
|
45 | - * delete a group |
|
46 | - * @param string $gid gid of the group to delete |
|
47 | - * @return bool |
|
48 | - */ |
|
49 | - public function deleteGroup($gid); |
|
44 | + /** |
|
45 | + * delete a group |
|
46 | + * @param string $gid gid of the group to delete |
|
47 | + * @return bool |
|
48 | + */ |
|
49 | + public function deleteGroup($gid); |
|
50 | 50 | |
51 | - /** |
|
52 | - * Add a user to a group |
|
53 | - * @param string $uid Name of the user to add to group |
|
54 | - * @param string $gid Name of the group in which add the user |
|
55 | - * @return bool |
|
56 | - * |
|
57 | - * Adds a user to a group. |
|
58 | - */ |
|
59 | - public function addToGroup($uid, $gid); |
|
51 | + /** |
|
52 | + * Add a user to a group |
|
53 | + * @param string $uid Name of the user to add to group |
|
54 | + * @param string $gid Name of the group in which add the user |
|
55 | + * @return bool |
|
56 | + * |
|
57 | + * Adds a user to a group. |
|
58 | + */ |
|
59 | + public function addToGroup($uid, $gid); |
|
60 | 60 | |
61 | - /** |
|
62 | - * Removes a user from a group |
|
63 | - * @param string $uid Name of the user to remove from group |
|
64 | - * @param string $gid Name of the group from which remove the user |
|
65 | - * @return bool |
|
66 | - * |
|
67 | - * removes the user from a group. |
|
68 | - */ |
|
69 | - public function removeFromGroup($uid, $gid); |
|
61 | + /** |
|
62 | + * Removes a user from a group |
|
63 | + * @param string $uid Name of the user to remove from group |
|
64 | + * @param string $gid Name of the group from which remove the user |
|
65 | + * @return bool |
|
66 | + * |
|
67 | + * removes the user from a group. |
|
68 | + */ |
|
69 | + public function removeFromGroup($uid, $gid); |
|
70 | 70 | |
71 | - /** |
|
72 | - * get the number of all users matching the search string in a group |
|
73 | - * @param string $gid |
|
74 | - * @param string $search |
|
75 | - * @return int|false |
|
76 | - */ |
|
77 | - public function countUsersInGroup($gid, $search = ''); |
|
71 | + /** |
|
72 | + * get the number of all users matching the search string in a group |
|
73 | + * @param string $gid |
|
74 | + * @param string $search |
|
75 | + * @return int|false |
|
76 | + */ |
|
77 | + public function countUsersInGroup($gid, $search = ''); |
|
78 | 78 | |
79 | - /** |
|
80 | - * get an array with group details |
|
81 | - * @param string $gid |
|
82 | - * @return array|false |
|
83 | - */ |
|
84 | - public function getGroupDetails($gid); |
|
79 | + /** |
|
80 | + * get an array with group details |
|
81 | + * @param string $gid |
|
82 | + * @return array|false |
|
83 | + */ |
|
84 | + public function getGroupDetails($gid); |
|
85 | 85 | |
86 | 86 | } |
@@ -30,35 +30,35 @@ |
||
30 | 30 | * @since 12.0.0 |
31 | 31 | */ |
32 | 32 | interface ICloudId { |
33 | - /** |
|
34 | - * The remote cloud id |
|
35 | - * |
|
36 | - * @return string |
|
37 | - * @since 12.0.0 |
|
38 | - */ |
|
39 | - public function getId(): string; |
|
33 | + /** |
|
34 | + * The remote cloud id |
|
35 | + * |
|
36 | + * @return string |
|
37 | + * @since 12.0.0 |
|
38 | + */ |
|
39 | + public function getId(): string; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Get a clean representation of the cloud id for display |
|
43 | - * |
|
44 | - * @return string |
|
45 | - * @since 12.0.0 |
|
46 | - */ |
|
47 | - public function getDisplayId(): string; |
|
41 | + /** |
|
42 | + * Get a clean representation of the cloud id for display |
|
43 | + * |
|
44 | + * @return string |
|
45 | + * @since 12.0.0 |
|
46 | + */ |
|
47 | + public function getDisplayId(): string; |
|
48 | 48 | |
49 | - /** |
|
50 | - * The username on the remote server |
|
51 | - * |
|
52 | - * @return string |
|
53 | - * @since 12.0.0 |
|
54 | - */ |
|
55 | - public function getUser(): string; |
|
49 | + /** |
|
50 | + * The username on the remote server |
|
51 | + * |
|
52 | + * @return string |
|
53 | + * @since 12.0.0 |
|
54 | + */ |
|
55 | + public function getUser(): string; |
|
56 | 56 | |
57 | - /** |
|
58 | - * The base address of the remote server |
|
59 | - * |
|
60 | - * @return string |
|
61 | - * @since 12.0.0 |
|
62 | - */ |
|
63 | - public function getRemote(): string; |
|
57 | + /** |
|
58 | + * The base address of the remote server |
|
59 | + * |
|
60 | + * @return string |
|
61 | + * @since 12.0.0 |
|
62 | + */ |
|
63 | + public function getRemote(): string; |
|
64 | 64 | } |
@@ -31,9 +31,9 @@ |
||
31 | 31 | * @since 8.1.0 |
32 | 32 | */ |
33 | 33 | interface IClientService { |
34 | - /** |
|
35 | - * @return IClient |
|
36 | - * @since 8.1.0 |
|
37 | - */ |
|
38 | - public function newClient(): IClient; |
|
34 | + /** |
|
35 | + * @return IClient |
|
36 | + * @since 8.1.0 |
|
37 | + */ |
|
38 | + public function newClient(): IClient; |
|
39 | 39 | } |
@@ -29,30 +29,30 @@ |
||
29 | 29 | |
30 | 30 | class Version1004Date20170919104507 extends SimpleMigrationStep { |
31 | 31 | |
32 | - /** |
|
33 | - * @param IOutput $output |
|
34 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
35 | - * @param array $options |
|
36 | - * @return null|ISchemaWrapper |
|
37 | - * @since 13.0.0 |
|
38 | - */ |
|
39 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
40 | - /** @var ISchemaWrapper $schema */ |
|
41 | - $schema = $schemaClosure(); |
|
42 | - |
|
43 | - $table = $schema->getTable('addressbooks'); |
|
44 | - $column = $table->getColumn('id'); |
|
45 | - $column->setUnsigned(true); |
|
46 | - |
|
47 | - $table = $schema->getTable('calendarobjects'); |
|
48 | - $column = $table->getColumn('id'); |
|
49 | - $column->setUnsigned(true); |
|
50 | - |
|
51 | - $table = $schema->getTable('calendarchanges'); |
|
52 | - $column = $table->getColumn('id'); |
|
53 | - $column->setUnsigned(true); |
|
54 | - |
|
55 | - return $schema; |
|
56 | - } |
|
32 | + /** |
|
33 | + * @param IOutput $output |
|
34 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
35 | + * @param array $options |
|
36 | + * @return null|ISchemaWrapper |
|
37 | + * @since 13.0.0 |
|
38 | + */ |
|
39 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
40 | + /** @var ISchemaWrapper $schema */ |
|
41 | + $schema = $schemaClosure(); |
|
42 | + |
|
43 | + $table = $schema->getTable('addressbooks'); |
|
44 | + $column = $table->getColumn('id'); |
|
45 | + $column->setUnsigned(true); |
|
46 | + |
|
47 | + $table = $schema->getTable('calendarobjects'); |
|
48 | + $column = $table->getColumn('id'); |
|
49 | + $column->setUnsigned(true); |
|
50 | + |
|
51 | + $table = $schema->getTable('calendarchanges'); |
|
52 | + $column = $table->getColumn('id'); |
|
53 | + $column->setUnsigned(true); |
|
54 | + |
|
55 | + return $schema; |
|
56 | + } |
|
57 | 57 | |
58 | 58 | } |
@@ -72,17 +72,17 @@ discard block |
||
72 | 72 | } |
73 | 73 | |
74 | 74 | protected function getStorageConfigFromDBMount(array $mount) { |
75 | - $applicableUsers = array_filter($mount['applicable'], function ($applicable) { |
|
75 | + $applicableUsers = array_filter($mount['applicable'], function($applicable) { |
|
76 | 76 | return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_USER; |
77 | 77 | }); |
78 | - $applicableUsers = array_map(function ($applicable) { |
|
78 | + $applicableUsers = array_map(function($applicable) { |
|
79 | 79 | return $applicable['value']; |
80 | 80 | }, $applicableUsers); |
81 | 81 | |
82 | - $applicableGroups = array_filter($mount['applicable'], function ($applicable) { |
|
82 | + $applicableGroups = array_filter($mount['applicable'], function($applicable) { |
|
83 | 83 | return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_GROUP; |
84 | 84 | }); |
85 | - $applicableGroups = array_map(function ($applicable) { |
|
85 | + $applicableGroups = array_map(function($applicable) { |
|
86 | 86 | return $applicable['value']; |
87 | 87 | }, $applicableGroups); |
88 | 88 | |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | $mount['priority'] |
99 | 99 | ); |
100 | 100 | $config->setType($mount['type']); |
101 | - $config->setId((int)$mount['mount_id']); |
|
101 | + $config->setId((int) $mount['mount_id']); |
|
102 | 102 | return $config; |
103 | 103 | } catch (\UnexpectedValueException $e) { |
104 | 104 | // don't die if a storage backend doesn't exist |
@@ -126,11 +126,11 @@ discard block |
||
126 | 126 | protected function readConfig() { |
127 | 127 | $mounts = $this->readDBConfig(); |
128 | 128 | $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); |
129 | - $configs = array_filter($configs, function ($config) { |
|
129 | + $configs = array_filter($configs, function($config) { |
|
130 | 130 | return $config instanceof StorageConfig; |
131 | 131 | }); |
132 | 132 | |
133 | - $keys = array_map(function (StorageConfig $config) { |
|
133 | + $keys = array_map(function(StorageConfig $config) { |
|
134 | 134 | return $config->getId(); |
135 | 135 | }, $configs); |
136 | 136 | |
@@ -149,14 +149,14 @@ discard block |
||
149 | 149 | $mount = $this->dbConfig->getMountById($id); |
150 | 150 | |
151 | 151 | if (!is_array($mount)) { |
152 | - throw new NotFoundException('Storage with ID "' . $id . '" not found'); |
|
152 | + throw new NotFoundException('Storage with ID "'.$id.'" not found'); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | $config = $this->getStorageConfigFromDBMount($mount); |
156 | 156 | if ($this->isApplicable($config)) { |
157 | 157 | return $config; |
158 | 158 | } else { |
159 | - throw new NotFoundException('Storage with ID "' . $id . '" not found'); |
|
159 | + throw new NotFoundException('Storage with ID "'.$id.'" not found'); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
@@ -379,13 +379,13 @@ discard block |
||
379 | 379 | $existingMount = $this->dbConfig->getMountById($id); |
380 | 380 | |
381 | 381 | if (!is_array($existingMount)) { |
382 | - throw new NotFoundException('Storage with ID "' . $id . '" not found while updating storage'); |
|
382 | + throw new NotFoundException('Storage with ID "'.$id.'" not found while updating storage'); |
|
383 | 383 | } |
384 | 384 | |
385 | 385 | $oldStorage = $this->getStorageConfigFromDBMount($existingMount); |
386 | 386 | |
387 | 387 | if ($oldStorage->getBackend() instanceof InvalidBackend) { |
388 | - throw new NotFoundException('Storage with id "' . $id . '" cannot be edited due to missing backend'); |
|
388 | + throw new NotFoundException('Storage with id "'.$id.'" cannot be edited due to missing backend'); |
|
389 | 389 | } |
390 | 390 | |
391 | 391 | $removedUsers = array_diff($oldStorage->getApplicableUsers(), $updatedStorage->getApplicableUsers()); |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | $existingMount = $this->dbConfig->getMountById($id); |
463 | 463 | |
464 | 464 | if (!is_array($existingMount)) { |
465 | - throw new NotFoundException('Storage with ID "' . $id . '" not found'); |
|
465 | + throw new NotFoundException('Storage with ID "'.$id.'" not found'); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | $this->dbConfig->removeMount($id); |
@@ -33,472 +33,472 @@ |
||
33 | 33 | */ |
34 | 34 | abstract class StoragesService { |
35 | 35 | |
36 | - /** |
|
37 | - * @param BackendService $backendService |
|
38 | - * @param DBConfigService $dbConfig |
|
39 | - * @param IUserMountCache $userMountCache |
|
40 | - * @param IEventDispatcher $eventDispatcher |
|
41 | - */ |
|
42 | - public function __construct( |
|
43 | - protected BackendService $backendService, |
|
44 | - protected DBConfigService $dbConfig, |
|
45 | - protected IUserMountCache $userMountCache, |
|
46 | - protected IEventDispatcher $eventDispatcher, |
|
47 | - protected IAppConfig $appConfig, |
|
48 | - ) { |
|
49 | - } |
|
50 | - |
|
51 | - protected function readDBConfig() { |
|
52 | - return $this->dbConfig->getAdminMounts(); |
|
53 | - } |
|
54 | - |
|
55 | - protected function getStorageConfigFromDBMount(array $mount) { |
|
56 | - $applicableUsers = array_filter($mount['applicable'], function ($applicable) { |
|
57 | - return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_USER; |
|
58 | - }); |
|
59 | - $applicableUsers = array_map(function ($applicable) { |
|
60 | - return $applicable['value']; |
|
61 | - }, $applicableUsers); |
|
62 | - |
|
63 | - $applicableGroups = array_filter($mount['applicable'], function ($applicable) { |
|
64 | - return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_GROUP; |
|
65 | - }); |
|
66 | - $applicableGroups = array_map(function ($applicable) { |
|
67 | - return $applicable['value']; |
|
68 | - }, $applicableGroups); |
|
69 | - |
|
70 | - try { |
|
71 | - $config = $this->createStorage( |
|
72 | - $mount['mount_point'], |
|
73 | - $mount['storage_backend'], |
|
74 | - $mount['auth_backend'], |
|
75 | - $mount['config'], |
|
76 | - $mount['options'], |
|
77 | - array_values($applicableUsers), |
|
78 | - array_values($applicableGroups), |
|
79 | - $mount['priority'] |
|
80 | - ); |
|
81 | - $config->setType($mount['type']); |
|
82 | - $config->setId((int)$mount['mount_id']); |
|
83 | - return $config; |
|
84 | - } catch (\UnexpectedValueException $e) { |
|
85 | - // don't die if a storage backend doesn't exist |
|
86 | - Server::get(LoggerInterface::class)->error('Could not load storage.', [ |
|
87 | - 'app' => 'files_external', |
|
88 | - 'exception' => $e, |
|
89 | - ]); |
|
90 | - return null; |
|
91 | - } catch (\InvalidArgumentException $e) { |
|
92 | - Server::get(LoggerInterface::class)->error('Could not load storage.', [ |
|
93 | - 'app' => 'files_external', |
|
94 | - 'exception' => $e, |
|
95 | - ]); |
|
96 | - return null; |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Read the external storage config |
|
102 | - * |
|
103 | - * @return array map of storage id to storage config |
|
104 | - */ |
|
105 | - protected function readConfig() { |
|
106 | - $mounts = $this->readDBConfig(); |
|
107 | - $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); |
|
108 | - $configs = array_filter($configs, function ($config) { |
|
109 | - return $config instanceof StorageConfig; |
|
110 | - }); |
|
111 | - |
|
112 | - $keys = array_map(function (StorageConfig $config) { |
|
113 | - return $config->getId(); |
|
114 | - }, $configs); |
|
115 | - |
|
116 | - return array_combine($keys, $configs); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Get a storage with status |
|
121 | - * |
|
122 | - * @param int $id storage id |
|
123 | - * |
|
124 | - * @return StorageConfig |
|
125 | - * @throws NotFoundException if the storage with the given id was not found |
|
126 | - */ |
|
127 | - public function getStorage(int $id) { |
|
128 | - $mount = $this->dbConfig->getMountById($id); |
|
129 | - |
|
130 | - if (!is_array($mount)) { |
|
131 | - throw new NotFoundException('Storage with ID "' . $id . '" not found'); |
|
132 | - } |
|
133 | - |
|
134 | - $config = $this->getStorageConfigFromDBMount($mount); |
|
135 | - if ($this->isApplicable($config)) { |
|
136 | - return $config; |
|
137 | - } else { |
|
138 | - throw new NotFoundException('Storage with ID "' . $id . '" not found'); |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Check whether this storage service should provide access to a storage |
|
144 | - * |
|
145 | - * @param StorageConfig $config |
|
146 | - * @return bool |
|
147 | - */ |
|
148 | - abstract protected function isApplicable(StorageConfig $config); |
|
149 | - |
|
150 | - /** |
|
151 | - * Gets all storages, valid or not |
|
152 | - * |
|
153 | - * @return StorageConfig[] array of storage configs |
|
154 | - */ |
|
155 | - public function getAllStorages() { |
|
156 | - return $this->readConfig(); |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Gets all valid storages |
|
161 | - * |
|
162 | - * @return StorageConfig[] |
|
163 | - */ |
|
164 | - public function getStorages() { |
|
165 | - return array_filter($this->getAllStorages(), [$this, 'validateStorage']); |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Validate storage |
|
170 | - * FIXME: De-duplicate with StoragesController::validate() |
|
171 | - * |
|
172 | - * @param StorageConfig $storage |
|
173 | - * @return bool |
|
174 | - */ |
|
175 | - protected function validateStorage(StorageConfig $storage) { |
|
176 | - /** @var Backend */ |
|
177 | - $backend = $storage->getBackend(); |
|
178 | - /** @var AuthMechanism */ |
|
179 | - $authMechanism = $storage->getAuthMechanism(); |
|
180 | - |
|
181 | - if (!$backend->isVisibleFor($this->getVisibilityType())) { |
|
182 | - // not permitted to use backend |
|
183 | - return false; |
|
184 | - } |
|
185 | - if (!$authMechanism->isVisibleFor($this->getVisibilityType())) { |
|
186 | - // not permitted to use auth mechanism |
|
187 | - return false; |
|
188 | - } |
|
189 | - |
|
190 | - return true; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Get the visibility type for this controller, used in validation |
|
195 | - * |
|
196 | - * @return int BackendService::VISIBILITY_* constants |
|
197 | - */ |
|
198 | - abstract public function getVisibilityType(); |
|
199 | - |
|
200 | - /** |
|
201 | - * @return integer |
|
202 | - */ |
|
203 | - protected function getType() { |
|
204 | - return DBConfigService::MOUNT_TYPE_ADMIN; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Add new storage to the configuration |
|
209 | - * |
|
210 | - * @param StorageConfig $newStorage storage attributes |
|
211 | - * |
|
212 | - * @return StorageConfig storage config, with added id |
|
213 | - */ |
|
214 | - public function addStorage(StorageConfig $newStorage) { |
|
215 | - $allStorages = $this->readConfig(); |
|
216 | - |
|
217 | - $configId = $this->dbConfig->addMount( |
|
218 | - $newStorage->getMountPoint(), |
|
219 | - $newStorage->getBackend()->getIdentifier(), |
|
220 | - $newStorage->getAuthMechanism()->getIdentifier(), |
|
221 | - $newStorage->getPriority(), |
|
222 | - $this->getType() |
|
223 | - ); |
|
224 | - |
|
225 | - $newStorage->setId($configId); |
|
226 | - |
|
227 | - foreach ($newStorage->getApplicableUsers() as $user) { |
|
228 | - $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_USER, $user); |
|
229 | - } |
|
230 | - foreach ($newStorage->getApplicableGroups() as $group) { |
|
231 | - $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GROUP, $group); |
|
232 | - } |
|
233 | - foreach ($newStorage->getBackendOptions() as $key => $value) { |
|
234 | - $this->dbConfig->setConfig($configId, $key, $value); |
|
235 | - } |
|
236 | - foreach ($newStorage->getMountOptions() as $key => $value) { |
|
237 | - $this->dbConfig->setOption($configId, $key, $value); |
|
238 | - } |
|
239 | - |
|
240 | - if (count($newStorage->getApplicableUsers()) === 0 && count($newStorage->getApplicableGroups()) === 0) { |
|
241 | - $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
242 | - } |
|
243 | - |
|
244 | - // add new storage |
|
245 | - $allStorages[$configId] = $newStorage; |
|
246 | - |
|
247 | - $this->triggerHooks($newStorage, Filesystem::signal_create_mount); |
|
248 | - |
|
249 | - $newStorage->setStatus(StorageNotAvailableException::STATUS_SUCCESS); |
|
250 | - |
|
251 | - $this->updateOverwriteHomeFolders(); |
|
252 | - |
|
253 | - return $newStorage; |
|
254 | - } |
|
255 | - |
|
256 | - /** |
|
257 | - * Create a storage from its parameters |
|
258 | - * |
|
259 | - * @param string $mountPoint storage mount point |
|
260 | - * @param string $backendIdentifier backend identifier |
|
261 | - * @param string $authMechanismIdentifier authentication mechanism identifier |
|
262 | - * @param array $backendOptions backend-specific options |
|
263 | - * @param array|null $mountOptions mount-specific options |
|
264 | - * @param array|null $applicableUsers users for which to mount the storage |
|
265 | - * @param array|null $applicableGroups groups for which to mount the storage |
|
266 | - * @param int|null $priority priority |
|
267 | - * |
|
268 | - * @return StorageConfig |
|
269 | - */ |
|
270 | - public function createStorage( |
|
271 | - $mountPoint, |
|
272 | - $backendIdentifier, |
|
273 | - $authMechanismIdentifier, |
|
274 | - $backendOptions, |
|
275 | - $mountOptions = null, |
|
276 | - $applicableUsers = null, |
|
277 | - $applicableGroups = null, |
|
278 | - $priority = null, |
|
279 | - ) { |
|
280 | - $backend = $this->backendService->getBackend($backendIdentifier); |
|
281 | - if (!$backend) { |
|
282 | - $backend = new InvalidBackend($backendIdentifier); |
|
283 | - } |
|
284 | - $authMechanism = $this->backendService->getAuthMechanism($authMechanismIdentifier); |
|
285 | - if (!$authMechanism) { |
|
286 | - $authMechanism = new InvalidAuth($authMechanismIdentifier); |
|
287 | - } |
|
288 | - $newStorage = new StorageConfig(); |
|
289 | - $newStorage->setMountPoint($mountPoint); |
|
290 | - $newStorage->setBackend($backend); |
|
291 | - $newStorage->setAuthMechanism($authMechanism); |
|
292 | - $newStorage->setBackendOptions($backendOptions); |
|
293 | - if (isset($mountOptions)) { |
|
294 | - $newStorage->setMountOptions($mountOptions); |
|
295 | - } |
|
296 | - if (isset($applicableUsers)) { |
|
297 | - $newStorage->setApplicableUsers($applicableUsers); |
|
298 | - } |
|
299 | - if (isset($applicableGroups)) { |
|
300 | - $newStorage->setApplicableGroups($applicableGroups); |
|
301 | - } |
|
302 | - if (isset($priority)) { |
|
303 | - $newStorage->setPriority($priority); |
|
304 | - } |
|
305 | - |
|
306 | - return $newStorage; |
|
307 | - } |
|
308 | - |
|
309 | - /** |
|
310 | - * Triggers the given hook signal for all the applicables given |
|
311 | - * |
|
312 | - * @param string $signal signal |
|
313 | - * @param string $mountPoint hook mount point param |
|
314 | - * @param string $mountType hook mount type param |
|
315 | - * @param array $applicableArray array of applicable users/groups for which to trigger the hook |
|
316 | - */ |
|
317 | - protected function triggerApplicableHooks($signal, $mountPoint, $mountType, $applicableArray): void { |
|
318 | - $this->eventDispatcher->dispatchTyped(new InvalidateMountCacheEvent(null)); |
|
319 | - foreach ($applicableArray as $applicable) { |
|
320 | - Util::emitHook( |
|
321 | - Filesystem::CLASSNAME, |
|
322 | - $signal, |
|
323 | - [ |
|
324 | - Filesystem::signal_param_path => $mountPoint, |
|
325 | - Filesystem::signal_param_mount_type => $mountType, |
|
326 | - Filesystem::signal_param_users => $applicable, |
|
327 | - ] |
|
328 | - ); |
|
329 | - } |
|
330 | - } |
|
331 | - |
|
332 | - /** |
|
333 | - * Triggers $signal for all applicable users of the given |
|
334 | - * storage |
|
335 | - * |
|
336 | - * @param StorageConfig $storage storage data |
|
337 | - * @param string $signal signal to trigger |
|
338 | - */ |
|
339 | - abstract protected function triggerHooks(StorageConfig $storage, $signal); |
|
340 | - |
|
341 | - /** |
|
342 | - * Triggers signal_create_mount or signal_delete_mount to |
|
343 | - * accommodate for additions/deletions in applicableUsers |
|
344 | - * and applicableGroups fields. |
|
345 | - * |
|
346 | - * @param StorageConfig $oldStorage old storage data |
|
347 | - * @param StorageConfig $newStorage new storage data |
|
348 | - */ |
|
349 | - abstract protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage); |
|
350 | - |
|
351 | - /** |
|
352 | - * Update storage to the configuration |
|
353 | - * |
|
354 | - * @param StorageConfig $updatedStorage storage attributes |
|
355 | - * |
|
356 | - * @return StorageConfig storage config |
|
357 | - * @throws NotFoundException if the given storage does not exist in the config |
|
358 | - */ |
|
359 | - public function updateStorage(StorageConfig $updatedStorage) { |
|
360 | - $id = $updatedStorage->getId(); |
|
361 | - |
|
362 | - $existingMount = $this->dbConfig->getMountById($id); |
|
363 | - |
|
364 | - if (!is_array($existingMount)) { |
|
365 | - throw new NotFoundException('Storage with ID "' . $id . '" not found while updating storage'); |
|
366 | - } |
|
367 | - |
|
368 | - $oldStorage = $this->getStorageConfigFromDBMount($existingMount); |
|
369 | - |
|
370 | - if ($oldStorage->getBackend() instanceof InvalidBackend) { |
|
371 | - throw new NotFoundException('Storage with id "' . $id . '" cannot be edited due to missing backend'); |
|
372 | - } |
|
373 | - |
|
374 | - $removedUsers = array_diff($oldStorage->getApplicableUsers(), $updatedStorage->getApplicableUsers()); |
|
375 | - $removedGroups = array_diff($oldStorage->getApplicableGroups(), $updatedStorage->getApplicableGroups()); |
|
376 | - $addedUsers = array_diff($updatedStorage->getApplicableUsers(), $oldStorage->getApplicableUsers()); |
|
377 | - $addedGroups = array_diff($updatedStorage->getApplicableGroups(), $oldStorage->getApplicableGroups()); |
|
378 | - |
|
379 | - $oldUserCount = count($oldStorage->getApplicableUsers()); |
|
380 | - $oldGroupCount = count($oldStorage->getApplicableGroups()); |
|
381 | - $newUserCount = count($updatedStorage->getApplicableUsers()); |
|
382 | - $newGroupCount = count($updatedStorage->getApplicableGroups()); |
|
383 | - $wasGlobal = ($oldUserCount + $oldGroupCount) === 0; |
|
384 | - $isGlobal = ($newUserCount + $newGroupCount) === 0; |
|
385 | - |
|
386 | - foreach ($removedUsers as $user) { |
|
387 | - $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user); |
|
388 | - } |
|
389 | - foreach ($removedGroups as $group) { |
|
390 | - $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group); |
|
391 | - } |
|
392 | - foreach ($addedUsers as $user) { |
|
393 | - $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user); |
|
394 | - } |
|
395 | - foreach ($addedGroups as $group) { |
|
396 | - $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group); |
|
397 | - } |
|
398 | - |
|
399 | - if ($wasGlobal && !$isGlobal) { |
|
400 | - $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
401 | - } elseif (!$wasGlobal && $isGlobal) { |
|
402 | - $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
403 | - } |
|
404 | - |
|
405 | - $changedConfig = array_diff_assoc($updatedStorage->getBackendOptions(), $oldStorage->getBackendOptions()); |
|
406 | - $changedOptions = array_diff_assoc($updatedStorage->getMountOptions(), $oldStorage->getMountOptions()); |
|
407 | - |
|
408 | - foreach ($changedConfig as $key => $value) { |
|
409 | - if ($value !== DefinitionParameter::UNMODIFIED_PLACEHOLDER) { |
|
410 | - $this->dbConfig->setConfig($id, $key, $value); |
|
411 | - } |
|
412 | - } |
|
413 | - foreach ($changedOptions as $key => $value) { |
|
414 | - $this->dbConfig->setOption($id, $key, $value); |
|
415 | - } |
|
416 | - |
|
417 | - if ($updatedStorage->getMountPoint() !== $oldStorage->getMountPoint()) { |
|
418 | - $this->dbConfig->setMountPoint($id, $updatedStorage->getMountPoint()); |
|
419 | - } |
|
420 | - |
|
421 | - if ($updatedStorage->getAuthMechanism()->getIdentifier() !== $oldStorage->getAuthMechanism()->getIdentifier()) { |
|
422 | - $this->dbConfig->setAuthBackend($id, $updatedStorage->getAuthMechanism()->getIdentifier()); |
|
423 | - } |
|
424 | - |
|
425 | - $this->triggerChangeHooks($oldStorage, $updatedStorage); |
|
426 | - |
|
427 | - if (($wasGlobal && !$isGlobal) || count($removedGroups) > 0) { // to expensive to properly handle these on the fly |
|
428 | - $this->userMountCache->remoteStorageMounts($this->getStorageId($updatedStorage)); |
|
429 | - } else { |
|
430 | - $storageId = $this->getStorageId($updatedStorage); |
|
431 | - foreach ($removedUsers as $userId) { |
|
432 | - $this->userMountCache->removeUserStorageMount($storageId, $userId); |
|
433 | - } |
|
434 | - } |
|
435 | - |
|
436 | - $this->updateOverwriteHomeFolders(); |
|
437 | - |
|
438 | - return $this->getStorage($id); |
|
439 | - } |
|
440 | - |
|
441 | - /** |
|
442 | - * Delete the storage with the given id. |
|
443 | - * |
|
444 | - * @param int $id storage id |
|
445 | - * |
|
446 | - * @throws NotFoundException if no storage was found with the given id |
|
447 | - */ |
|
448 | - public function removeStorage(int $id) { |
|
449 | - $existingMount = $this->dbConfig->getMountById($id); |
|
450 | - |
|
451 | - if (!is_array($existingMount)) { |
|
452 | - throw new NotFoundException('Storage with ID "' . $id . '" not found'); |
|
453 | - } |
|
454 | - |
|
455 | - $this->dbConfig->removeMount($id); |
|
456 | - |
|
457 | - $deletedStorage = $this->getStorageConfigFromDBMount($existingMount); |
|
458 | - $this->triggerHooks($deletedStorage, Filesystem::signal_delete_mount); |
|
459 | - |
|
460 | - // delete oc_storages entries and oc_filecache |
|
461 | - Storage::cleanByMountId($id); |
|
462 | - |
|
463 | - $this->updateOverwriteHomeFolders(); |
|
464 | - } |
|
465 | - |
|
466 | - /** |
|
467 | - * Construct the storage implementation |
|
468 | - * |
|
469 | - * @param StorageConfig $storageConfig |
|
470 | - * @return int |
|
471 | - */ |
|
472 | - private function getStorageId(StorageConfig $storageConfig) { |
|
473 | - try { |
|
474 | - $class = $storageConfig->getBackend()->getStorageClass(); |
|
475 | - /** @var \OC\Files\Storage\Storage $storage */ |
|
476 | - $storage = new $class($storageConfig->getBackendOptions()); |
|
477 | - |
|
478 | - // auth mechanism should fire first |
|
479 | - $storage = $storageConfig->getBackend()->wrapStorage($storage); |
|
480 | - $storage = $storageConfig->getAuthMechanism()->wrapStorage($storage); |
|
481 | - |
|
482 | - /** @var \OC\Files\Storage\Storage $storage */ |
|
483 | - return $storage->getStorageCache()->getNumericId(); |
|
484 | - } catch (\Exception $e) { |
|
485 | - return -1; |
|
486 | - } |
|
487 | - } |
|
488 | - |
|
489 | - public function updateOverwriteHomeFolders(): void { |
|
490 | - $appIdsList = $this->appConfig->getValueArray(FilesApplication::APP_ID, ConfigLexicon::OVERWRITES_HOME_FOLDERS); |
|
491 | - |
|
492 | - if ($this->dbConfig->hasHomeFolderOverwriteMount()) { |
|
493 | - if (!in_array(Application::APP_ID, $appIdsList)) { |
|
494 | - $appIdsList[] = Application::APP_ID; |
|
495 | - $this->appConfig->setValueArray(FilesApplication::APP_ID, ConfigLexicon::OVERWRITES_HOME_FOLDERS, $appIdsList); |
|
496 | - } |
|
497 | - } else { |
|
498 | - if (in_array(Application::APP_ID, $appIdsList)) { |
|
499 | - $appIdsList = array_values(array_filter($appIdsList, fn ($v) => $v !== Application::APP_ID)); |
|
500 | - $this->appConfig->setValueArray(FilesApplication::APP_ID, ConfigLexicon::OVERWRITES_HOME_FOLDERS, $appIdsList); |
|
501 | - } |
|
502 | - } |
|
503 | - } |
|
36 | + /** |
|
37 | + * @param BackendService $backendService |
|
38 | + * @param DBConfigService $dbConfig |
|
39 | + * @param IUserMountCache $userMountCache |
|
40 | + * @param IEventDispatcher $eventDispatcher |
|
41 | + */ |
|
42 | + public function __construct( |
|
43 | + protected BackendService $backendService, |
|
44 | + protected DBConfigService $dbConfig, |
|
45 | + protected IUserMountCache $userMountCache, |
|
46 | + protected IEventDispatcher $eventDispatcher, |
|
47 | + protected IAppConfig $appConfig, |
|
48 | + ) { |
|
49 | + } |
|
50 | + |
|
51 | + protected function readDBConfig() { |
|
52 | + return $this->dbConfig->getAdminMounts(); |
|
53 | + } |
|
54 | + |
|
55 | + protected function getStorageConfigFromDBMount(array $mount) { |
|
56 | + $applicableUsers = array_filter($mount['applicable'], function ($applicable) { |
|
57 | + return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_USER; |
|
58 | + }); |
|
59 | + $applicableUsers = array_map(function ($applicable) { |
|
60 | + return $applicable['value']; |
|
61 | + }, $applicableUsers); |
|
62 | + |
|
63 | + $applicableGroups = array_filter($mount['applicable'], function ($applicable) { |
|
64 | + return $applicable['type'] === DBConfigService::APPLICABLE_TYPE_GROUP; |
|
65 | + }); |
|
66 | + $applicableGroups = array_map(function ($applicable) { |
|
67 | + return $applicable['value']; |
|
68 | + }, $applicableGroups); |
|
69 | + |
|
70 | + try { |
|
71 | + $config = $this->createStorage( |
|
72 | + $mount['mount_point'], |
|
73 | + $mount['storage_backend'], |
|
74 | + $mount['auth_backend'], |
|
75 | + $mount['config'], |
|
76 | + $mount['options'], |
|
77 | + array_values($applicableUsers), |
|
78 | + array_values($applicableGroups), |
|
79 | + $mount['priority'] |
|
80 | + ); |
|
81 | + $config->setType($mount['type']); |
|
82 | + $config->setId((int)$mount['mount_id']); |
|
83 | + return $config; |
|
84 | + } catch (\UnexpectedValueException $e) { |
|
85 | + // don't die if a storage backend doesn't exist |
|
86 | + Server::get(LoggerInterface::class)->error('Could not load storage.', [ |
|
87 | + 'app' => 'files_external', |
|
88 | + 'exception' => $e, |
|
89 | + ]); |
|
90 | + return null; |
|
91 | + } catch (\InvalidArgumentException $e) { |
|
92 | + Server::get(LoggerInterface::class)->error('Could not load storage.', [ |
|
93 | + 'app' => 'files_external', |
|
94 | + 'exception' => $e, |
|
95 | + ]); |
|
96 | + return null; |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Read the external storage config |
|
102 | + * |
|
103 | + * @return array map of storage id to storage config |
|
104 | + */ |
|
105 | + protected function readConfig() { |
|
106 | + $mounts = $this->readDBConfig(); |
|
107 | + $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); |
|
108 | + $configs = array_filter($configs, function ($config) { |
|
109 | + return $config instanceof StorageConfig; |
|
110 | + }); |
|
111 | + |
|
112 | + $keys = array_map(function (StorageConfig $config) { |
|
113 | + return $config->getId(); |
|
114 | + }, $configs); |
|
115 | + |
|
116 | + return array_combine($keys, $configs); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Get a storage with status |
|
121 | + * |
|
122 | + * @param int $id storage id |
|
123 | + * |
|
124 | + * @return StorageConfig |
|
125 | + * @throws NotFoundException if the storage with the given id was not found |
|
126 | + */ |
|
127 | + public function getStorage(int $id) { |
|
128 | + $mount = $this->dbConfig->getMountById($id); |
|
129 | + |
|
130 | + if (!is_array($mount)) { |
|
131 | + throw new NotFoundException('Storage with ID "' . $id . '" not found'); |
|
132 | + } |
|
133 | + |
|
134 | + $config = $this->getStorageConfigFromDBMount($mount); |
|
135 | + if ($this->isApplicable($config)) { |
|
136 | + return $config; |
|
137 | + } else { |
|
138 | + throw new NotFoundException('Storage with ID "' . $id . '" not found'); |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Check whether this storage service should provide access to a storage |
|
144 | + * |
|
145 | + * @param StorageConfig $config |
|
146 | + * @return bool |
|
147 | + */ |
|
148 | + abstract protected function isApplicable(StorageConfig $config); |
|
149 | + |
|
150 | + /** |
|
151 | + * Gets all storages, valid or not |
|
152 | + * |
|
153 | + * @return StorageConfig[] array of storage configs |
|
154 | + */ |
|
155 | + public function getAllStorages() { |
|
156 | + return $this->readConfig(); |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Gets all valid storages |
|
161 | + * |
|
162 | + * @return StorageConfig[] |
|
163 | + */ |
|
164 | + public function getStorages() { |
|
165 | + return array_filter($this->getAllStorages(), [$this, 'validateStorage']); |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Validate storage |
|
170 | + * FIXME: De-duplicate with StoragesController::validate() |
|
171 | + * |
|
172 | + * @param StorageConfig $storage |
|
173 | + * @return bool |
|
174 | + */ |
|
175 | + protected function validateStorage(StorageConfig $storage) { |
|
176 | + /** @var Backend */ |
|
177 | + $backend = $storage->getBackend(); |
|
178 | + /** @var AuthMechanism */ |
|
179 | + $authMechanism = $storage->getAuthMechanism(); |
|
180 | + |
|
181 | + if (!$backend->isVisibleFor($this->getVisibilityType())) { |
|
182 | + // not permitted to use backend |
|
183 | + return false; |
|
184 | + } |
|
185 | + if (!$authMechanism->isVisibleFor($this->getVisibilityType())) { |
|
186 | + // not permitted to use auth mechanism |
|
187 | + return false; |
|
188 | + } |
|
189 | + |
|
190 | + return true; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Get the visibility type for this controller, used in validation |
|
195 | + * |
|
196 | + * @return int BackendService::VISIBILITY_* constants |
|
197 | + */ |
|
198 | + abstract public function getVisibilityType(); |
|
199 | + |
|
200 | + /** |
|
201 | + * @return integer |
|
202 | + */ |
|
203 | + protected function getType() { |
|
204 | + return DBConfigService::MOUNT_TYPE_ADMIN; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Add new storage to the configuration |
|
209 | + * |
|
210 | + * @param StorageConfig $newStorage storage attributes |
|
211 | + * |
|
212 | + * @return StorageConfig storage config, with added id |
|
213 | + */ |
|
214 | + public function addStorage(StorageConfig $newStorage) { |
|
215 | + $allStorages = $this->readConfig(); |
|
216 | + |
|
217 | + $configId = $this->dbConfig->addMount( |
|
218 | + $newStorage->getMountPoint(), |
|
219 | + $newStorage->getBackend()->getIdentifier(), |
|
220 | + $newStorage->getAuthMechanism()->getIdentifier(), |
|
221 | + $newStorage->getPriority(), |
|
222 | + $this->getType() |
|
223 | + ); |
|
224 | + |
|
225 | + $newStorage->setId($configId); |
|
226 | + |
|
227 | + foreach ($newStorage->getApplicableUsers() as $user) { |
|
228 | + $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_USER, $user); |
|
229 | + } |
|
230 | + foreach ($newStorage->getApplicableGroups() as $group) { |
|
231 | + $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GROUP, $group); |
|
232 | + } |
|
233 | + foreach ($newStorage->getBackendOptions() as $key => $value) { |
|
234 | + $this->dbConfig->setConfig($configId, $key, $value); |
|
235 | + } |
|
236 | + foreach ($newStorage->getMountOptions() as $key => $value) { |
|
237 | + $this->dbConfig->setOption($configId, $key, $value); |
|
238 | + } |
|
239 | + |
|
240 | + if (count($newStorage->getApplicableUsers()) === 0 && count($newStorage->getApplicableGroups()) === 0) { |
|
241 | + $this->dbConfig->addApplicable($configId, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
242 | + } |
|
243 | + |
|
244 | + // add new storage |
|
245 | + $allStorages[$configId] = $newStorage; |
|
246 | + |
|
247 | + $this->triggerHooks($newStorage, Filesystem::signal_create_mount); |
|
248 | + |
|
249 | + $newStorage->setStatus(StorageNotAvailableException::STATUS_SUCCESS); |
|
250 | + |
|
251 | + $this->updateOverwriteHomeFolders(); |
|
252 | + |
|
253 | + return $newStorage; |
|
254 | + } |
|
255 | + |
|
256 | + /** |
|
257 | + * Create a storage from its parameters |
|
258 | + * |
|
259 | + * @param string $mountPoint storage mount point |
|
260 | + * @param string $backendIdentifier backend identifier |
|
261 | + * @param string $authMechanismIdentifier authentication mechanism identifier |
|
262 | + * @param array $backendOptions backend-specific options |
|
263 | + * @param array|null $mountOptions mount-specific options |
|
264 | + * @param array|null $applicableUsers users for which to mount the storage |
|
265 | + * @param array|null $applicableGroups groups for which to mount the storage |
|
266 | + * @param int|null $priority priority |
|
267 | + * |
|
268 | + * @return StorageConfig |
|
269 | + */ |
|
270 | + public function createStorage( |
|
271 | + $mountPoint, |
|
272 | + $backendIdentifier, |
|
273 | + $authMechanismIdentifier, |
|
274 | + $backendOptions, |
|
275 | + $mountOptions = null, |
|
276 | + $applicableUsers = null, |
|
277 | + $applicableGroups = null, |
|
278 | + $priority = null, |
|
279 | + ) { |
|
280 | + $backend = $this->backendService->getBackend($backendIdentifier); |
|
281 | + if (!$backend) { |
|
282 | + $backend = new InvalidBackend($backendIdentifier); |
|
283 | + } |
|
284 | + $authMechanism = $this->backendService->getAuthMechanism($authMechanismIdentifier); |
|
285 | + if (!$authMechanism) { |
|
286 | + $authMechanism = new InvalidAuth($authMechanismIdentifier); |
|
287 | + } |
|
288 | + $newStorage = new StorageConfig(); |
|
289 | + $newStorage->setMountPoint($mountPoint); |
|
290 | + $newStorage->setBackend($backend); |
|
291 | + $newStorage->setAuthMechanism($authMechanism); |
|
292 | + $newStorage->setBackendOptions($backendOptions); |
|
293 | + if (isset($mountOptions)) { |
|
294 | + $newStorage->setMountOptions($mountOptions); |
|
295 | + } |
|
296 | + if (isset($applicableUsers)) { |
|
297 | + $newStorage->setApplicableUsers($applicableUsers); |
|
298 | + } |
|
299 | + if (isset($applicableGroups)) { |
|
300 | + $newStorage->setApplicableGroups($applicableGroups); |
|
301 | + } |
|
302 | + if (isset($priority)) { |
|
303 | + $newStorage->setPriority($priority); |
|
304 | + } |
|
305 | + |
|
306 | + return $newStorage; |
|
307 | + } |
|
308 | + |
|
309 | + /** |
|
310 | + * Triggers the given hook signal for all the applicables given |
|
311 | + * |
|
312 | + * @param string $signal signal |
|
313 | + * @param string $mountPoint hook mount point param |
|
314 | + * @param string $mountType hook mount type param |
|
315 | + * @param array $applicableArray array of applicable users/groups for which to trigger the hook |
|
316 | + */ |
|
317 | + protected function triggerApplicableHooks($signal, $mountPoint, $mountType, $applicableArray): void { |
|
318 | + $this->eventDispatcher->dispatchTyped(new InvalidateMountCacheEvent(null)); |
|
319 | + foreach ($applicableArray as $applicable) { |
|
320 | + Util::emitHook( |
|
321 | + Filesystem::CLASSNAME, |
|
322 | + $signal, |
|
323 | + [ |
|
324 | + Filesystem::signal_param_path => $mountPoint, |
|
325 | + Filesystem::signal_param_mount_type => $mountType, |
|
326 | + Filesystem::signal_param_users => $applicable, |
|
327 | + ] |
|
328 | + ); |
|
329 | + } |
|
330 | + } |
|
331 | + |
|
332 | + /** |
|
333 | + * Triggers $signal for all applicable users of the given |
|
334 | + * storage |
|
335 | + * |
|
336 | + * @param StorageConfig $storage storage data |
|
337 | + * @param string $signal signal to trigger |
|
338 | + */ |
|
339 | + abstract protected function triggerHooks(StorageConfig $storage, $signal); |
|
340 | + |
|
341 | + /** |
|
342 | + * Triggers signal_create_mount or signal_delete_mount to |
|
343 | + * accommodate for additions/deletions in applicableUsers |
|
344 | + * and applicableGroups fields. |
|
345 | + * |
|
346 | + * @param StorageConfig $oldStorage old storage data |
|
347 | + * @param StorageConfig $newStorage new storage data |
|
348 | + */ |
|
349 | + abstract protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage); |
|
350 | + |
|
351 | + /** |
|
352 | + * Update storage to the configuration |
|
353 | + * |
|
354 | + * @param StorageConfig $updatedStorage storage attributes |
|
355 | + * |
|
356 | + * @return StorageConfig storage config |
|
357 | + * @throws NotFoundException if the given storage does not exist in the config |
|
358 | + */ |
|
359 | + public function updateStorage(StorageConfig $updatedStorage) { |
|
360 | + $id = $updatedStorage->getId(); |
|
361 | + |
|
362 | + $existingMount = $this->dbConfig->getMountById($id); |
|
363 | + |
|
364 | + if (!is_array($existingMount)) { |
|
365 | + throw new NotFoundException('Storage with ID "' . $id . '" not found while updating storage'); |
|
366 | + } |
|
367 | + |
|
368 | + $oldStorage = $this->getStorageConfigFromDBMount($existingMount); |
|
369 | + |
|
370 | + if ($oldStorage->getBackend() instanceof InvalidBackend) { |
|
371 | + throw new NotFoundException('Storage with id "' . $id . '" cannot be edited due to missing backend'); |
|
372 | + } |
|
373 | + |
|
374 | + $removedUsers = array_diff($oldStorage->getApplicableUsers(), $updatedStorage->getApplicableUsers()); |
|
375 | + $removedGroups = array_diff($oldStorage->getApplicableGroups(), $updatedStorage->getApplicableGroups()); |
|
376 | + $addedUsers = array_diff($updatedStorage->getApplicableUsers(), $oldStorage->getApplicableUsers()); |
|
377 | + $addedGroups = array_diff($updatedStorage->getApplicableGroups(), $oldStorage->getApplicableGroups()); |
|
378 | + |
|
379 | + $oldUserCount = count($oldStorage->getApplicableUsers()); |
|
380 | + $oldGroupCount = count($oldStorage->getApplicableGroups()); |
|
381 | + $newUserCount = count($updatedStorage->getApplicableUsers()); |
|
382 | + $newGroupCount = count($updatedStorage->getApplicableGroups()); |
|
383 | + $wasGlobal = ($oldUserCount + $oldGroupCount) === 0; |
|
384 | + $isGlobal = ($newUserCount + $newGroupCount) === 0; |
|
385 | + |
|
386 | + foreach ($removedUsers as $user) { |
|
387 | + $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user); |
|
388 | + } |
|
389 | + foreach ($removedGroups as $group) { |
|
390 | + $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group); |
|
391 | + } |
|
392 | + foreach ($addedUsers as $user) { |
|
393 | + $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user); |
|
394 | + } |
|
395 | + foreach ($addedGroups as $group) { |
|
396 | + $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group); |
|
397 | + } |
|
398 | + |
|
399 | + if ($wasGlobal && !$isGlobal) { |
|
400 | + $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
401 | + } elseif (!$wasGlobal && $isGlobal) { |
|
402 | + $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
403 | + } |
|
404 | + |
|
405 | + $changedConfig = array_diff_assoc($updatedStorage->getBackendOptions(), $oldStorage->getBackendOptions()); |
|
406 | + $changedOptions = array_diff_assoc($updatedStorage->getMountOptions(), $oldStorage->getMountOptions()); |
|
407 | + |
|
408 | + foreach ($changedConfig as $key => $value) { |
|
409 | + if ($value !== DefinitionParameter::UNMODIFIED_PLACEHOLDER) { |
|
410 | + $this->dbConfig->setConfig($id, $key, $value); |
|
411 | + } |
|
412 | + } |
|
413 | + foreach ($changedOptions as $key => $value) { |
|
414 | + $this->dbConfig->setOption($id, $key, $value); |
|
415 | + } |
|
416 | + |
|
417 | + if ($updatedStorage->getMountPoint() !== $oldStorage->getMountPoint()) { |
|
418 | + $this->dbConfig->setMountPoint($id, $updatedStorage->getMountPoint()); |
|
419 | + } |
|
420 | + |
|
421 | + if ($updatedStorage->getAuthMechanism()->getIdentifier() !== $oldStorage->getAuthMechanism()->getIdentifier()) { |
|
422 | + $this->dbConfig->setAuthBackend($id, $updatedStorage->getAuthMechanism()->getIdentifier()); |
|
423 | + } |
|
424 | + |
|
425 | + $this->triggerChangeHooks($oldStorage, $updatedStorage); |
|
426 | + |
|
427 | + if (($wasGlobal && !$isGlobal) || count($removedGroups) > 0) { // to expensive to properly handle these on the fly |
|
428 | + $this->userMountCache->remoteStorageMounts($this->getStorageId($updatedStorage)); |
|
429 | + } else { |
|
430 | + $storageId = $this->getStorageId($updatedStorage); |
|
431 | + foreach ($removedUsers as $userId) { |
|
432 | + $this->userMountCache->removeUserStorageMount($storageId, $userId); |
|
433 | + } |
|
434 | + } |
|
435 | + |
|
436 | + $this->updateOverwriteHomeFolders(); |
|
437 | + |
|
438 | + return $this->getStorage($id); |
|
439 | + } |
|
440 | + |
|
441 | + /** |
|
442 | + * Delete the storage with the given id. |
|
443 | + * |
|
444 | + * @param int $id storage id |
|
445 | + * |
|
446 | + * @throws NotFoundException if no storage was found with the given id |
|
447 | + */ |
|
448 | + public function removeStorage(int $id) { |
|
449 | + $existingMount = $this->dbConfig->getMountById($id); |
|
450 | + |
|
451 | + if (!is_array($existingMount)) { |
|
452 | + throw new NotFoundException('Storage with ID "' . $id . '" not found'); |
|
453 | + } |
|
454 | + |
|
455 | + $this->dbConfig->removeMount($id); |
|
456 | + |
|
457 | + $deletedStorage = $this->getStorageConfigFromDBMount($existingMount); |
|
458 | + $this->triggerHooks($deletedStorage, Filesystem::signal_delete_mount); |
|
459 | + |
|
460 | + // delete oc_storages entries and oc_filecache |
|
461 | + Storage::cleanByMountId($id); |
|
462 | + |
|
463 | + $this->updateOverwriteHomeFolders(); |
|
464 | + } |
|
465 | + |
|
466 | + /** |
|
467 | + * Construct the storage implementation |
|
468 | + * |
|
469 | + * @param StorageConfig $storageConfig |
|
470 | + * @return int |
|
471 | + */ |
|
472 | + private function getStorageId(StorageConfig $storageConfig) { |
|
473 | + try { |
|
474 | + $class = $storageConfig->getBackend()->getStorageClass(); |
|
475 | + /** @var \OC\Files\Storage\Storage $storage */ |
|
476 | + $storage = new $class($storageConfig->getBackendOptions()); |
|
477 | + |
|
478 | + // auth mechanism should fire first |
|
479 | + $storage = $storageConfig->getBackend()->wrapStorage($storage); |
|
480 | + $storage = $storageConfig->getAuthMechanism()->wrapStorage($storage); |
|
481 | + |
|
482 | + /** @var \OC\Files\Storage\Storage $storage */ |
|
483 | + return $storage->getStorageCache()->getNumericId(); |
|
484 | + } catch (\Exception $e) { |
|
485 | + return -1; |
|
486 | + } |
|
487 | + } |
|
488 | + |
|
489 | + public function updateOverwriteHomeFolders(): void { |
|
490 | + $appIdsList = $this->appConfig->getValueArray(FilesApplication::APP_ID, ConfigLexicon::OVERWRITES_HOME_FOLDERS); |
|
491 | + |
|
492 | + if ($this->dbConfig->hasHomeFolderOverwriteMount()) { |
|
493 | + if (!in_array(Application::APP_ID, $appIdsList)) { |
|
494 | + $appIdsList[] = Application::APP_ID; |
|
495 | + $this->appConfig->setValueArray(FilesApplication::APP_ID, ConfigLexicon::OVERWRITES_HOME_FOLDERS, $appIdsList); |
|
496 | + } |
|
497 | + } else { |
|
498 | + if (in_array(Application::APP_ID, $appIdsList)) { |
|
499 | + $appIdsList = array_values(array_filter($appIdsList, fn ($v) => $v !== Application::APP_ID)); |
|
500 | + $this->appConfig->setValueArray(FilesApplication::APP_ID, ConfigLexicon::OVERWRITES_HOME_FOLDERS, $appIdsList); |
|
501 | + } |
|
502 | + } |
|
503 | + } |
|
504 | 504 | } |
@@ -36,7 +36,7 @@ |
||
36 | 36 | * @package OC\AppFramework\Middleware\Security\Exceptions |
37 | 37 | */ |
38 | 38 | class NotAdminException extends SecurityException { |
39 | - public function __construct(string $message) { |
|
40 | - parent::__construct($message, Http::STATUS_FORBIDDEN); |
|
41 | - } |
|
39 | + public function __construct(string $message) { |
|
40 | + parent::__construct($message, Http::STATUS_FORBIDDEN); |
|
41 | + } |
|
42 | 42 | } |
@@ -100,7 +100,7 @@ |
||
100 | 100 | |
101 | 101 | // casted to string because cast to float cause equality for non equal numbers |
102 | 102 | // and integer has the problem of limited size on 32 bit systems |
103 | - if ((string)$expectedSize !== (string)$actualSize) { |
|
103 | + if ((string) $expectedSize !== (string) $actualSize) { |
|
104 | 104 | throw new BadRequest("Chunks on server do not sum up to $expectedSize but to $actualSize bytes"); |
105 | 105 | } |
106 | 106 | } |
@@ -18,97 +18,97 @@ |
||
18 | 18 | |
19 | 19 | class ChunkingPlugin extends ServerPlugin { |
20 | 20 | |
21 | - /** @var Server */ |
|
22 | - private $server; |
|
23 | - /** @var FutureFile */ |
|
24 | - private $sourceNode; |
|
21 | + /** @var Server */ |
|
22 | + private $server; |
|
23 | + /** @var FutureFile */ |
|
24 | + private $sourceNode; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @inheritdoc |
|
28 | - */ |
|
29 | - public function initialize(Server $server) { |
|
30 | - $server->on('beforeMove', [$this, 'beforeMove']); |
|
31 | - $this->server = $server; |
|
32 | - } |
|
26 | + /** |
|
27 | + * @inheritdoc |
|
28 | + */ |
|
29 | + public function initialize(Server $server) { |
|
30 | + $server->on('beforeMove', [$this, 'beforeMove']); |
|
31 | + $this->server = $server; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param string $sourcePath source path |
|
36 | - * @param string $destination destination path |
|
37 | - * @return bool|void |
|
38 | - * @throws BadRequest |
|
39 | - * @throws NotFound |
|
40 | - */ |
|
41 | - public function beforeMove($sourcePath, $destination) { |
|
42 | - $this->sourceNode = $this->server->tree->getNodeForPath($sourcePath); |
|
43 | - if (!$this->sourceNode instanceof FutureFile) { |
|
44 | - // skip handling as the source is not a chunked FutureFile |
|
45 | - return; |
|
46 | - } |
|
34 | + /** |
|
35 | + * @param string $sourcePath source path |
|
36 | + * @param string $destination destination path |
|
37 | + * @return bool|void |
|
38 | + * @throws BadRequest |
|
39 | + * @throws NotFound |
|
40 | + */ |
|
41 | + public function beforeMove($sourcePath, $destination) { |
|
42 | + $this->sourceNode = $this->server->tree->getNodeForPath($sourcePath); |
|
43 | + if (!$this->sourceNode instanceof FutureFile) { |
|
44 | + // skip handling as the source is not a chunked FutureFile |
|
45 | + return; |
|
46 | + } |
|
47 | 47 | |
48 | - try { |
|
49 | - /** @var INode $destinationNode */ |
|
50 | - $destinationNode = $this->server->tree->getNodeForPath($destination); |
|
51 | - if ($destinationNode instanceof Directory) { |
|
52 | - throw new BadRequest("The given destination $destination is a directory."); |
|
53 | - } |
|
54 | - } catch (NotFound $e) { |
|
55 | - // If the destination does not exist yet it's not a directory either ;) |
|
56 | - } |
|
48 | + try { |
|
49 | + /** @var INode $destinationNode */ |
|
50 | + $destinationNode = $this->server->tree->getNodeForPath($destination); |
|
51 | + if ($destinationNode instanceof Directory) { |
|
52 | + throw new BadRequest("The given destination $destination is a directory."); |
|
53 | + } |
|
54 | + } catch (NotFound $e) { |
|
55 | + // If the destination does not exist yet it's not a directory either ;) |
|
56 | + } |
|
57 | 57 | |
58 | - $this->verifySize(); |
|
59 | - return $this->performMove($sourcePath, $destination); |
|
60 | - } |
|
58 | + $this->verifySize(); |
|
59 | + return $this->performMove($sourcePath, $destination); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Move handler for future file. |
|
64 | - * |
|
65 | - * This overrides the default move behavior to prevent Sabre |
|
66 | - * to delete the target file before moving. Because deleting would |
|
67 | - * lose the file id and metadata. |
|
68 | - * |
|
69 | - * @param string $path source path |
|
70 | - * @param string $destination destination path |
|
71 | - * @return bool|void false to stop handling, void to skip this handler |
|
72 | - */ |
|
73 | - public function performMove($path, $destination) { |
|
74 | - $fileExists = $this->server->tree->nodeExists($destination); |
|
75 | - // do a move manually, skipping Sabre's default "delete" for existing nodes |
|
76 | - try { |
|
77 | - $this->server->tree->move($path, $destination); |
|
78 | - } catch (Forbidden $e) { |
|
79 | - $sourceNode = $this->server->tree->getNodeForPath($path); |
|
80 | - if ($sourceNode instanceof FutureFile) { |
|
81 | - $sourceNode->delete(); |
|
82 | - } |
|
83 | - throw $e; |
|
84 | - } |
|
62 | + /** |
|
63 | + * Move handler for future file. |
|
64 | + * |
|
65 | + * This overrides the default move behavior to prevent Sabre |
|
66 | + * to delete the target file before moving. Because deleting would |
|
67 | + * lose the file id and metadata. |
|
68 | + * |
|
69 | + * @param string $path source path |
|
70 | + * @param string $destination destination path |
|
71 | + * @return bool|void false to stop handling, void to skip this handler |
|
72 | + */ |
|
73 | + public function performMove($path, $destination) { |
|
74 | + $fileExists = $this->server->tree->nodeExists($destination); |
|
75 | + // do a move manually, skipping Sabre's default "delete" for existing nodes |
|
76 | + try { |
|
77 | + $this->server->tree->move($path, $destination); |
|
78 | + } catch (Forbidden $e) { |
|
79 | + $sourceNode = $this->server->tree->getNodeForPath($path); |
|
80 | + if ($sourceNode instanceof FutureFile) { |
|
81 | + $sourceNode->delete(); |
|
82 | + } |
|
83 | + throw $e; |
|
84 | + } |
|
85 | 85 | |
86 | - // trigger all default events (copied from CorePlugin::move) |
|
87 | - $this->server->emit('afterMove', [$path, $destination]); |
|
88 | - $this->server->emit('afterUnbind', [$path]); |
|
89 | - $this->server->emit('afterBind', [$destination]); |
|
86 | + // trigger all default events (copied from CorePlugin::move) |
|
87 | + $this->server->emit('afterMove', [$path, $destination]); |
|
88 | + $this->server->emit('afterUnbind', [$path]); |
|
89 | + $this->server->emit('afterBind', [$destination]); |
|
90 | 90 | |
91 | - $response = $this->server->httpResponse; |
|
92 | - $response->setHeader('Content-Length', '0'); |
|
93 | - $response->setStatus($fileExists ? Http::STATUS_NO_CONTENT : Http::STATUS_CREATED); |
|
91 | + $response = $this->server->httpResponse; |
|
92 | + $response->setHeader('Content-Length', '0'); |
|
93 | + $response->setStatus($fileExists ? Http::STATUS_NO_CONTENT : Http::STATUS_CREATED); |
|
94 | 94 | |
95 | - return false; |
|
96 | - } |
|
95 | + return false; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * @throws BadRequest |
|
100 | - */ |
|
101 | - private function verifySize() { |
|
102 | - $expectedSize = $this->server->httpRequest->getHeader('OC-Total-Length'); |
|
103 | - if ($expectedSize === null) { |
|
104 | - return; |
|
105 | - } |
|
106 | - $actualSize = $this->sourceNode->getSize(); |
|
98 | + /** |
|
99 | + * @throws BadRequest |
|
100 | + */ |
|
101 | + private function verifySize() { |
|
102 | + $expectedSize = $this->server->httpRequest->getHeader('OC-Total-Length'); |
|
103 | + if ($expectedSize === null) { |
|
104 | + return; |
|
105 | + } |
|
106 | + $actualSize = $this->sourceNode->getSize(); |
|
107 | 107 | |
108 | - // casted to string because cast to float cause equality for non equal numbers |
|
109 | - // and integer has the problem of limited size on 32 bit systems |
|
110 | - if ((string)$expectedSize !== (string)$actualSize) { |
|
111 | - throw new BadRequest("Chunks on server do not sum up to $expectedSize but to $actualSize bytes"); |
|
112 | - } |
|
113 | - } |
|
108 | + // casted to string because cast to float cause equality for non equal numbers |
|
109 | + // and integer has the problem of limited size on 32 bit systems |
|
110 | + if ((string)$expectedSize !== (string)$actualSize) { |
|
111 | + throw new BadRequest("Chunks on server do not sum up to $expectedSize but to $actualSize bytes"); |
|
112 | + } |
|
113 | + } |
|
114 | 114 | } |
@@ -30,30 +30,30 @@ |
||
30 | 30 | * Delete the admin|personal sections and settings tables |
31 | 31 | */ |
32 | 32 | class Version14000Date20180129121024 extends SimpleMigrationStep { |
33 | - public function name(): string { |
|
34 | - return 'Drop obsolete settings tables'; |
|
35 | - } |
|
33 | + public function name(): string { |
|
34 | + return 'Drop obsolete settings tables'; |
|
35 | + } |
|
36 | 36 | |
37 | - public function description(): string { |
|
38 | - return 'Drops the following obsolete tables: "admin_sections", "admin_settings", "personal_sections" and "personal_settings"'; |
|
39 | - } |
|
37 | + public function description(): string { |
|
38 | + return 'Drops the following obsolete tables: "admin_sections", "admin_settings", "personal_sections" and "personal_settings"'; |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param IOutput $output |
|
43 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
44 | - * @param array $options |
|
45 | - * @return null|ISchemaWrapper |
|
46 | - * @since 13.0.0 |
|
47 | - */ |
|
48 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
49 | - /** @var ISchemaWrapper $schema */ |
|
50 | - $schema = $schemaClosure(); |
|
41 | + /** |
|
42 | + * @param IOutput $output |
|
43 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
44 | + * @param array $options |
|
45 | + * @return null|ISchemaWrapper |
|
46 | + * @since 13.0.0 |
|
47 | + */ |
|
48 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
49 | + /** @var ISchemaWrapper $schema */ |
|
50 | + $schema = $schemaClosure(); |
|
51 | 51 | |
52 | - $schema->dropTable('admin_sections'); |
|
53 | - $schema->dropTable('admin_settings'); |
|
54 | - $schema->dropTable('personal_sections'); |
|
55 | - $schema->dropTable('personal_settings'); |
|
52 | + $schema->dropTable('admin_sections'); |
|
53 | + $schema->dropTable('admin_settings'); |
|
54 | + $schema->dropTable('personal_sections'); |
|
55 | + $schema->dropTable('personal_settings'); |
|
56 | 56 | |
57 | - return $schema; |
|
58 | - } |
|
57 | + return $schema; |
|
58 | + } |
|
59 | 59 | } |