@@ -37,239 +37,239 @@ |
||
37 | 37 | use Symfony\Component\Console\Output\OutputInterface; |
38 | 38 | |
39 | 39 | class ListCommand extends Base { |
40 | - /** |
|
41 | - * @var GlobalStoragesService |
|
42 | - */ |
|
43 | - protected $globalService; |
|
40 | + /** |
|
41 | + * @var GlobalStoragesService |
|
42 | + */ |
|
43 | + protected $globalService; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @var UserStoragesService |
|
47 | - */ |
|
48 | - protected $userService; |
|
45 | + /** |
|
46 | + * @var UserStoragesService |
|
47 | + */ |
|
48 | + protected $userService; |
|
49 | 49 | |
50 | - /** |
|
51 | - * @var IUserSession |
|
52 | - */ |
|
53 | - protected $userSession; |
|
50 | + /** |
|
51 | + * @var IUserSession |
|
52 | + */ |
|
53 | + protected $userSession; |
|
54 | 54 | |
55 | - /** |
|
56 | - * @var IUserManager |
|
57 | - */ |
|
58 | - protected $userManager; |
|
55 | + /** |
|
56 | + * @var IUserManager |
|
57 | + */ |
|
58 | + protected $userManager; |
|
59 | 59 | |
60 | - const ALL = -1; |
|
60 | + const ALL = -1; |
|
61 | 61 | |
62 | - function __construct(GlobalStoragesService $globalService, UserStoragesService $userService, IUserSession $userSession, IUserManager $userManager) { |
|
63 | - parent::__construct(); |
|
64 | - $this->globalService = $globalService; |
|
65 | - $this->userService = $userService; |
|
66 | - $this->userSession = $userSession; |
|
67 | - $this->userManager = $userManager; |
|
68 | - } |
|
62 | + function __construct(GlobalStoragesService $globalService, UserStoragesService $userService, IUserSession $userSession, IUserManager $userManager) { |
|
63 | + parent::__construct(); |
|
64 | + $this->globalService = $globalService; |
|
65 | + $this->userService = $userService; |
|
66 | + $this->userSession = $userSession; |
|
67 | + $this->userManager = $userManager; |
|
68 | + } |
|
69 | 69 | |
70 | - protected function configure() { |
|
71 | - $this |
|
72 | - ->setName('files_external:list') |
|
73 | - ->setDescription('List configured admin or personal mounts') |
|
74 | - ->addArgument( |
|
75 | - 'user_id', |
|
76 | - InputArgument::OPTIONAL, |
|
77 | - 'user id to list the personal mounts for, if no user is provided admin mounts will be listed' |
|
78 | - )->addOption( |
|
79 | - 'show-password', |
|
80 | - null, |
|
81 | - InputOption::VALUE_NONE, |
|
82 | - 'show passwords and secrets' |
|
83 | - )->addOption( |
|
84 | - 'full', |
|
85 | - null, |
|
86 | - InputOption::VALUE_NONE, |
|
87 | - 'don\'t truncate long values in table output' |
|
88 | - )->addOption( |
|
89 | - 'all', |
|
90 | - 'a', |
|
91 | - InputOption::VALUE_NONE, |
|
92 | - 'show both system wide mounts and all personal mounts' |
|
93 | - ); |
|
94 | - parent::configure(); |
|
95 | - } |
|
70 | + protected function configure() { |
|
71 | + $this |
|
72 | + ->setName('files_external:list') |
|
73 | + ->setDescription('List configured admin or personal mounts') |
|
74 | + ->addArgument( |
|
75 | + 'user_id', |
|
76 | + InputArgument::OPTIONAL, |
|
77 | + 'user id to list the personal mounts for, if no user is provided admin mounts will be listed' |
|
78 | + )->addOption( |
|
79 | + 'show-password', |
|
80 | + null, |
|
81 | + InputOption::VALUE_NONE, |
|
82 | + 'show passwords and secrets' |
|
83 | + )->addOption( |
|
84 | + 'full', |
|
85 | + null, |
|
86 | + InputOption::VALUE_NONE, |
|
87 | + 'don\'t truncate long values in table output' |
|
88 | + )->addOption( |
|
89 | + 'all', |
|
90 | + 'a', |
|
91 | + InputOption::VALUE_NONE, |
|
92 | + 'show both system wide mounts and all personal mounts' |
|
93 | + ); |
|
94 | + parent::configure(); |
|
95 | + } |
|
96 | 96 | |
97 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
98 | - if ($input->getOption('all')) { |
|
99 | - /** @var $mounts StorageConfig[] */ |
|
100 | - $mounts = $this->globalService->getStorageForAllUsers(); |
|
101 | - $userId = self::ALL; |
|
102 | - } else { |
|
103 | - $userId = $input->getArgument('user_id'); |
|
104 | - $storageService = $this->getStorageService($userId); |
|
97 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
98 | + if ($input->getOption('all')) { |
|
99 | + /** @var $mounts StorageConfig[] */ |
|
100 | + $mounts = $this->globalService->getStorageForAllUsers(); |
|
101 | + $userId = self::ALL; |
|
102 | + } else { |
|
103 | + $userId = $input->getArgument('user_id'); |
|
104 | + $storageService = $this->getStorageService($userId); |
|
105 | 105 | |
106 | - /** @var $mounts StorageConfig[] */ |
|
107 | - $mounts = $storageService->getAllStorages(); |
|
108 | - } |
|
106 | + /** @var $mounts StorageConfig[] */ |
|
107 | + $mounts = $storageService->getAllStorages(); |
|
108 | + } |
|
109 | 109 | |
110 | - $this->listMounts($userId, $mounts, $input, $output); |
|
111 | - } |
|
110 | + $this->listMounts($userId, $mounts, $input, $output); |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * @param $userId $userId |
|
115 | - * @param StorageConfig[] $mounts |
|
116 | - * @param InputInterface $input |
|
117 | - * @param OutputInterface $output |
|
118 | - */ |
|
119 | - public function listMounts($userId, array $mounts, InputInterface $input, OutputInterface $output) { |
|
120 | - $outputType = $input->getOption('output'); |
|
121 | - if (count($mounts) === 0) { |
|
122 | - if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) { |
|
123 | - $output->writeln('[]'); |
|
124 | - } else { |
|
125 | - if ($userId === self::ALL) { |
|
126 | - $output->writeln("<info>No mounts configured</info>"); |
|
127 | - } else if ($userId) { |
|
128 | - $output->writeln("<info>No mounts configured by $userId</info>"); |
|
129 | - } else { |
|
130 | - $output->writeln("<info>No admin mounts configured</info>"); |
|
131 | - } |
|
132 | - } |
|
133 | - return; |
|
134 | - } |
|
113 | + /** |
|
114 | + * @param $userId $userId |
|
115 | + * @param StorageConfig[] $mounts |
|
116 | + * @param InputInterface $input |
|
117 | + * @param OutputInterface $output |
|
118 | + */ |
|
119 | + public function listMounts($userId, array $mounts, InputInterface $input, OutputInterface $output) { |
|
120 | + $outputType = $input->getOption('output'); |
|
121 | + if (count($mounts) === 0) { |
|
122 | + if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) { |
|
123 | + $output->writeln('[]'); |
|
124 | + } else { |
|
125 | + if ($userId === self::ALL) { |
|
126 | + $output->writeln("<info>No mounts configured</info>"); |
|
127 | + } else if ($userId) { |
|
128 | + $output->writeln("<info>No mounts configured by $userId</info>"); |
|
129 | + } else { |
|
130 | + $output->writeln("<info>No admin mounts configured</info>"); |
|
131 | + } |
|
132 | + } |
|
133 | + return; |
|
134 | + } |
|
135 | 135 | |
136 | - $headers = ['Mount ID', 'Mount Point', 'Storage', 'Authentication Type', 'Configuration', 'Options']; |
|
136 | + $headers = ['Mount ID', 'Mount Point', 'Storage', 'Authentication Type', 'Configuration', 'Options']; |
|
137 | 137 | |
138 | - if (!$userId || $userId === self::ALL) { |
|
139 | - $headers[] = 'Applicable Users'; |
|
140 | - $headers[] = 'Applicable Groups'; |
|
141 | - } |
|
142 | - if ($userId === self::ALL) { |
|
143 | - $headers[] = 'Type'; |
|
144 | - } |
|
138 | + if (!$userId || $userId === self::ALL) { |
|
139 | + $headers[] = 'Applicable Users'; |
|
140 | + $headers[] = 'Applicable Groups'; |
|
141 | + } |
|
142 | + if ($userId === self::ALL) { |
|
143 | + $headers[] = 'Type'; |
|
144 | + } |
|
145 | 145 | |
146 | - if (!$input->getOption('show-password')) { |
|
147 | - $hideKeys = ['password', 'refresh_token', 'token', 'client_secret', 'public_key', 'private_key']; |
|
148 | - foreach ($mounts as $mount) { |
|
149 | - $config = $mount->getBackendOptions(); |
|
150 | - foreach ($config as $key => $value) { |
|
151 | - if (in_array($key, $hideKeys)) { |
|
152 | - $mount->setBackendOption($key, '***'); |
|
153 | - } |
|
154 | - } |
|
155 | - } |
|
156 | - } |
|
146 | + if (!$input->getOption('show-password')) { |
|
147 | + $hideKeys = ['password', 'refresh_token', 'token', 'client_secret', 'public_key', 'private_key']; |
|
148 | + foreach ($mounts as $mount) { |
|
149 | + $config = $mount->getBackendOptions(); |
|
150 | + foreach ($config as $key => $value) { |
|
151 | + if (in_array($key, $hideKeys)) { |
|
152 | + $mount->setBackendOption($key, '***'); |
|
153 | + } |
|
154 | + } |
|
155 | + } |
|
156 | + } |
|
157 | 157 | |
158 | - if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) { |
|
159 | - $keys = array_map(function ($header) { |
|
160 | - return strtolower(str_replace(' ', '_', $header)); |
|
161 | - }, $headers); |
|
158 | + if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) { |
|
159 | + $keys = array_map(function ($header) { |
|
160 | + return strtolower(str_replace(' ', '_', $header)); |
|
161 | + }, $headers); |
|
162 | 162 | |
163 | - $pairs = array_map(function (StorageConfig $config) use ($keys, $userId) { |
|
164 | - $values = [ |
|
165 | - $config->getId(), |
|
166 | - $config->getMountPoint(), |
|
167 | - $config->getBackend()->getStorageClass(), |
|
168 | - $config->getAuthMechanism()->getIdentifier(), |
|
169 | - $config->getBackendOptions(), |
|
170 | - $config->getMountOptions() |
|
171 | - ]; |
|
172 | - if (!$userId || $userId === self::ALL) { |
|
173 | - $values[] = $config->getApplicableUsers(); |
|
174 | - $values[] = $config->getApplicableGroups(); |
|
175 | - } |
|
176 | - if ($userId === self::ALL) { |
|
177 | - $values[] = $config->getType() === StorageConfig::MOUNT_TYPE_ADMIN ? 'admin' : 'personal'; |
|
178 | - } |
|
163 | + $pairs = array_map(function (StorageConfig $config) use ($keys, $userId) { |
|
164 | + $values = [ |
|
165 | + $config->getId(), |
|
166 | + $config->getMountPoint(), |
|
167 | + $config->getBackend()->getStorageClass(), |
|
168 | + $config->getAuthMechanism()->getIdentifier(), |
|
169 | + $config->getBackendOptions(), |
|
170 | + $config->getMountOptions() |
|
171 | + ]; |
|
172 | + if (!$userId || $userId === self::ALL) { |
|
173 | + $values[] = $config->getApplicableUsers(); |
|
174 | + $values[] = $config->getApplicableGroups(); |
|
175 | + } |
|
176 | + if ($userId === self::ALL) { |
|
177 | + $values[] = $config->getType() === StorageConfig::MOUNT_TYPE_ADMIN ? 'admin' : 'personal'; |
|
178 | + } |
|
179 | 179 | |
180 | - return array_combine($keys, $values); |
|
181 | - }, $mounts); |
|
182 | - if ($outputType === self::OUTPUT_FORMAT_JSON) { |
|
183 | - $output->writeln(json_encode(array_values($pairs))); |
|
184 | - } else { |
|
185 | - $output->writeln(json_encode(array_values($pairs), JSON_PRETTY_PRINT)); |
|
186 | - } |
|
187 | - } else { |
|
188 | - $full = $input->getOption('full'); |
|
189 | - $defaultMountOptions = [ |
|
190 | - 'encrypt' => true, |
|
191 | - 'previews' => true, |
|
192 | - 'filesystem_check_changes' => 1, |
|
193 | - 'enable_sharing' => false, |
|
194 | - 'encoding_compatibility' => false |
|
195 | - ]; |
|
196 | - $rows = array_map(function (StorageConfig $config) use ($userId, $defaultMountOptions, $full) { |
|
197 | - $storageConfig = $config->getBackendOptions(); |
|
198 | - $keys = array_keys($storageConfig); |
|
199 | - $values = array_values($storageConfig); |
|
180 | + return array_combine($keys, $values); |
|
181 | + }, $mounts); |
|
182 | + if ($outputType === self::OUTPUT_FORMAT_JSON) { |
|
183 | + $output->writeln(json_encode(array_values($pairs))); |
|
184 | + } else { |
|
185 | + $output->writeln(json_encode(array_values($pairs), JSON_PRETTY_PRINT)); |
|
186 | + } |
|
187 | + } else { |
|
188 | + $full = $input->getOption('full'); |
|
189 | + $defaultMountOptions = [ |
|
190 | + 'encrypt' => true, |
|
191 | + 'previews' => true, |
|
192 | + 'filesystem_check_changes' => 1, |
|
193 | + 'enable_sharing' => false, |
|
194 | + 'encoding_compatibility' => false |
|
195 | + ]; |
|
196 | + $rows = array_map(function (StorageConfig $config) use ($userId, $defaultMountOptions, $full) { |
|
197 | + $storageConfig = $config->getBackendOptions(); |
|
198 | + $keys = array_keys($storageConfig); |
|
199 | + $values = array_values($storageConfig); |
|
200 | 200 | |
201 | - if (!$full) { |
|
202 | - $values = array_map(function ($value) { |
|
203 | - if (is_string($value) && strlen($value) > 32) { |
|
204 | - return substr($value, 0, 6) . '...' . substr($value, -6, 6); |
|
205 | - } else { |
|
206 | - return $value; |
|
207 | - } |
|
208 | - }, $values); |
|
209 | - } |
|
201 | + if (!$full) { |
|
202 | + $values = array_map(function ($value) { |
|
203 | + if (is_string($value) && strlen($value) > 32) { |
|
204 | + return substr($value, 0, 6) . '...' . substr($value, -6, 6); |
|
205 | + } else { |
|
206 | + return $value; |
|
207 | + } |
|
208 | + }, $values); |
|
209 | + } |
|
210 | 210 | |
211 | - $configStrings = array_map(function ($key, $value) { |
|
212 | - return $key . ': ' . json_encode($value); |
|
213 | - }, $keys, $values); |
|
214 | - $configString = implode(', ', $configStrings); |
|
211 | + $configStrings = array_map(function ($key, $value) { |
|
212 | + return $key . ': ' . json_encode($value); |
|
213 | + }, $keys, $values); |
|
214 | + $configString = implode(', ', $configStrings); |
|
215 | 215 | |
216 | - $mountOptions = $config->getMountOptions(); |
|
217 | - // hide defaults |
|
218 | - foreach ($mountOptions as $key => $value) { |
|
219 | - if ($value === $defaultMountOptions[$key]) { |
|
220 | - unset($mountOptions[$key]); |
|
221 | - } |
|
222 | - } |
|
223 | - $keys = array_keys($mountOptions); |
|
224 | - $values = array_values($mountOptions); |
|
216 | + $mountOptions = $config->getMountOptions(); |
|
217 | + // hide defaults |
|
218 | + foreach ($mountOptions as $key => $value) { |
|
219 | + if ($value === $defaultMountOptions[$key]) { |
|
220 | + unset($mountOptions[$key]); |
|
221 | + } |
|
222 | + } |
|
223 | + $keys = array_keys($mountOptions); |
|
224 | + $values = array_values($mountOptions); |
|
225 | 225 | |
226 | - $optionsStrings = array_map(function ($key, $value) { |
|
227 | - return $key . ': ' . json_encode($value); |
|
228 | - }, $keys, $values); |
|
229 | - $optionsString = implode(', ', $optionsStrings); |
|
226 | + $optionsStrings = array_map(function ($key, $value) { |
|
227 | + return $key . ': ' . json_encode($value); |
|
228 | + }, $keys, $values); |
|
229 | + $optionsString = implode(', ', $optionsStrings); |
|
230 | 230 | |
231 | - $values = [ |
|
232 | - $config->getId(), |
|
233 | - $config->getMountPoint(), |
|
234 | - $config->getBackend()->getText(), |
|
235 | - $config->getAuthMechanism()->getText(), |
|
236 | - $configString, |
|
237 | - $optionsString |
|
238 | - ]; |
|
231 | + $values = [ |
|
232 | + $config->getId(), |
|
233 | + $config->getMountPoint(), |
|
234 | + $config->getBackend()->getText(), |
|
235 | + $config->getAuthMechanism()->getText(), |
|
236 | + $configString, |
|
237 | + $optionsString |
|
238 | + ]; |
|
239 | 239 | |
240 | - if (!$userId || $userId === self::ALL) { |
|
241 | - $applicableUsers = implode(', ', $config->getApplicableUsers()); |
|
242 | - $applicableGroups = implode(', ', $config->getApplicableGroups()); |
|
243 | - if ($applicableUsers === '' && $applicableGroups === '') { |
|
244 | - $applicableUsers = 'All'; |
|
245 | - } |
|
246 | - $values[] = $applicableUsers; |
|
247 | - $values[] = $applicableGroups; |
|
248 | - } |
|
249 | - if ($userId === self::ALL) { |
|
250 | - $values[] = $config->getType() === StorageConfig::MOUNT_TYPE_ADMIN ? 'Admin' : 'Personal'; |
|
251 | - } |
|
240 | + if (!$userId || $userId === self::ALL) { |
|
241 | + $applicableUsers = implode(', ', $config->getApplicableUsers()); |
|
242 | + $applicableGroups = implode(', ', $config->getApplicableGroups()); |
|
243 | + if ($applicableUsers === '' && $applicableGroups === '') { |
|
244 | + $applicableUsers = 'All'; |
|
245 | + } |
|
246 | + $values[] = $applicableUsers; |
|
247 | + $values[] = $applicableGroups; |
|
248 | + } |
|
249 | + if ($userId === self::ALL) { |
|
250 | + $values[] = $config->getType() === StorageConfig::MOUNT_TYPE_ADMIN ? 'Admin' : 'Personal'; |
|
251 | + } |
|
252 | 252 | |
253 | - return $values; |
|
254 | - }, $mounts); |
|
253 | + return $values; |
|
254 | + }, $mounts); |
|
255 | 255 | |
256 | - $table = new Table($output); |
|
257 | - $table->setHeaders($headers); |
|
258 | - $table->setRows($rows); |
|
259 | - $table->render(); |
|
260 | - } |
|
261 | - } |
|
256 | + $table = new Table($output); |
|
257 | + $table->setHeaders($headers); |
|
258 | + $table->setRows($rows); |
|
259 | + $table->render(); |
|
260 | + } |
|
261 | + } |
|
262 | 262 | |
263 | - protected function getStorageService($userId) { |
|
264 | - if (!empty($userId)) { |
|
265 | - $user = $this->userManager->get($userId); |
|
266 | - if (is_null($user)) { |
|
267 | - throw new NoUserException("user $userId not found"); |
|
268 | - } |
|
269 | - $this->userSession->setUser($user); |
|
270 | - return $this->userService; |
|
271 | - } else { |
|
272 | - return $this->globalService; |
|
273 | - } |
|
274 | - } |
|
263 | + protected function getStorageService($userId) { |
|
264 | + if (!empty($userId)) { |
|
265 | + $user = $this->userManager->get($userId); |
|
266 | + if (is_null($user)) { |
|
267 | + throw new NoUserException("user $userId not found"); |
|
268 | + } |
|
269 | + $this->userSession->setUser($user); |
|
270 | + return $this->userService; |
|
271 | + } else { |
|
272 | + return $this->globalService; |
|
273 | + } |
|
274 | + } |
|
275 | 275 | } |
@@ -156,11 +156,11 @@ discard block |
||
156 | 156 | } |
157 | 157 | |
158 | 158 | if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) { |
159 | - $keys = array_map(function ($header) { |
|
159 | + $keys = array_map(function($header) { |
|
160 | 160 | return strtolower(str_replace(' ', '_', $header)); |
161 | 161 | }, $headers); |
162 | 162 | |
163 | - $pairs = array_map(function (StorageConfig $config) use ($keys, $userId) { |
|
163 | + $pairs = array_map(function(StorageConfig $config) use ($keys, $userId) { |
|
164 | 164 | $values = [ |
165 | 165 | $config->getId(), |
166 | 166 | $config->getMountPoint(), |
@@ -193,23 +193,23 @@ discard block |
||
193 | 193 | 'enable_sharing' => false, |
194 | 194 | 'encoding_compatibility' => false |
195 | 195 | ]; |
196 | - $rows = array_map(function (StorageConfig $config) use ($userId, $defaultMountOptions, $full) { |
|
196 | + $rows = array_map(function(StorageConfig $config) use ($userId, $defaultMountOptions, $full) { |
|
197 | 197 | $storageConfig = $config->getBackendOptions(); |
198 | 198 | $keys = array_keys($storageConfig); |
199 | 199 | $values = array_values($storageConfig); |
200 | 200 | |
201 | 201 | if (!$full) { |
202 | - $values = array_map(function ($value) { |
|
202 | + $values = array_map(function($value) { |
|
203 | 203 | if (is_string($value) && strlen($value) > 32) { |
204 | - return substr($value, 0, 6) . '...' . substr($value, -6, 6); |
|
204 | + return substr($value, 0, 6).'...'.substr($value, -6, 6); |
|
205 | 205 | } else { |
206 | 206 | return $value; |
207 | 207 | } |
208 | 208 | }, $values); |
209 | 209 | } |
210 | 210 | |
211 | - $configStrings = array_map(function ($key, $value) { |
|
212 | - return $key . ': ' . json_encode($value); |
|
211 | + $configStrings = array_map(function($key, $value) { |
|
212 | + return $key.': '.json_encode($value); |
|
213 | 213 | }, $keys, $values); |
214 | 214 | $configString = implode(', ', $configStrings); |
215 | 215 | |
@@ -223,8 +223,8 @@ discard block |
||
223 | 223 | $keys = array_keys($mountOptions); |
224 | 224 | $values = array_values($mountOptions); |
225 | 225 | |
226 | - $optionsStrings = array_map(function ($key, $value) { |
|
227 | - return $key . ': ' . json_encode($value); |
|
226 | + $optionsStrings = array_map(function($key, $value) { |
|
227 | + return $key.': '.json_encode($value); |
|
228 | 228 | }, $keys, $values); |
229 | 229 | $optionsString = implode(', ', $optionsStrings); |
230 | 230 |
@@ -68,7 +68,7 @@ |
||
68 | 68 | try { |
69 | 69 | $mount = $this->globalService->getStorage($mountId); |
70 | 70 | } catch (NotFoundException $e) { |
71 | - $output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts"</error>'); |
|
71 | + $output->writeln('<error>Mount with id "'.$mountId.' not found, check "occ files_external:list" to get available mounts"</error>'); |
|
72 | 72 | return 404; |
73 | 73 | } |
74 | 74 |
@@ -32,87 +32,87 @@ |
||
32 | 32 | use Symfony\Component\Console\Output\OutputInterface; |
33 | 33 | |
34 | 34 | class Config extends Base { |
35 | - /** |
|
36 | - * @var GlobalStoragesService |
|
37 | - */ |
|
38 | - protected $globalService; |
|
35 | + /** |
|
36 | + * @var GlobalStoragesService |
|
37 | + */ |
|
38 | + protected $globalService; |
|
39 | 39 | |
40 | - function __construct(GlobalStoragesService $globalService) { |
|
41 | - parent::__construct(); |
|
42 | - $this->globalService = $globalService; |
|
43 | - } |
|
40 | + function __construct(GlobalStoragesService $globalService) { |
|
41 | + parent::__construct(); |
|
42 | + $this->globalService = $globalService; |
|
43 | + } |
|
44 | 44 | |
45 | - protected function configure() { |
|
46 | - $this |
|
47 | - ->setName('files_external:config') |
|
48 | - ->setDescription('Manage backend configuration for a mount') |
|
49 | - ->addArgument( |
|
50 | - 'mount_id', |
|
51 | - InputArgument::REQUIRED, |
|
52 | - 'The id of the mount to edit' |
|
53 | - )->addArgument( |
|
54 | - 'key', |
|
55 | - InputArgument::REQUIRED, |
|
56 | - 'key of the config option to set/get' |
|
57 | - )->addArgument( |
|
58 | - 'value', |
|
59 | - InputArgument::OPTIONAL, |
|
60 | - 'value to set the config option to, when no value is provided the existing value will be printed' |
|
61 | - ); |
|
62 | - parent::configure(); |
|
63 | - } |
|
45 | + protected function configure() { |
|
46 | + $this |
|
47 | + ->setName('files_external:config') |
|
48 | + ->setDescription('Manage backend configuration for a mount') |
|
49 | + ->addArgument( |
|
50 | + 'mount_id', |
|
51 | + InputArgument::REQUIRED, |
|
52 | + 'The id of the mount to edit' |
|
53 | + )->addArgument( |
|
54 | + 'key', |
|
55 | + InputArgument::REQUIRED, |
|
56 | + 'key of the config option to set/get' |
|
57 | + )->addArgument( |
|
58 | + 'value', |
|
59 | + InputArgument::OPTIONAL, |
|
60 | + 'value to set the config option to, when no value is provided the existing value will be printed' |
|
61 | + ); |
|
62 | + parent::configure(); |
|
63 | + } |
|
64 | 64 | |
65 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
66 | - $mountId = $input->getArgument('mount_id'); |
|
67 | - $key = $input->getArgument('key'); |
|
68 | - try { |
|
69 | - $mount = $this->globalService->getStorage($mountId); |
|
70 | - } catch (NotFoundException $e) { |
|
71 | - $output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts"</error>'); |
|
72 | - return 404; |
|
73 | - } |
|
65 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
66 | + $mountId = $input->getArgument('mount_id'); |
|
67 | + $key = $input->getArgument('key'); |
|
68 | + try { |
|
69 | + $mount = $this->globalService->getStorage($mountId); |
|
70 | + } catch (NotFoundException $e) { |
|
71 | + $output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts"</error>'); |
|
72 | + return 404; |
|
73 | + } |
|
74 | 74 | |
75 | - $value = $input->getArgument('value'); |
|
76 | - if ($value) { |
|
77 | - $this->setOption($mount, $key, $value, $output); |
|
78 | - } else { |
|
79 | - $this->getOption($mount, $key, $output); |
|
80 | - } |
|
81 | - } |
|
75 | + $value = $input->getArgument('value'); |
|
76 | + if ($value) { |
|
77 | + $this->setOption($mount, $key, $value, $output); |
|
78 | + } else { |
|
79 | + $this->getOption($mount, $key, $output); |
|
80 | + } |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @param StorageConfig $mount |
|
85 | - * @param string $key |
|
86 | - * @param OutputInterface $output |
|
87 | - */ |
|
88 | - protected function getOption(StorageConfig $mount, $key, OutputInterface $output) { |
|
89 | - if ($key === 'mountpoint' || $key === 'mount_point') { |
|
90 | - $value = $mount->getMountPoint(); |
|
91 | - } else { |
|
92 | - $value = $mount->getBackendOption($key); |
|
93 | - } |
|
94 | - if (!is_string($value) && json_decode(json_encode($value)) === $value) { // show bools and objects correctly |
|
95 | - $value = json_encode($value); |
|
96 | - } |
|
97 | - $output->writeln($value); |
|
98 | - } |
|
83 | + /** |
|
84 | + * @param StorageConfig $mount |
|
85 | + * @param string $key |
|
86 | + * @param OutputInterface $output |
|
87 | + */ |
|
88 | + protected function getOption(StorageConfig $mount, $key, OutputInterface $output) { |
|
89 | + if ($key === 'mountpoint' || $key === 'mount_point') { |
|
90 | + $value = $mount->getMountPoint(); |
|
91 | + } else { |
|
92 | + $value = $mount->getBackendOption($key); |
|
93 | + } |
|
94 | + if (!is_string($value) && json_decode(json_encode($value)) === $value) { // show bools and objects correctly |
|
95 | + $value = json_encode($value); |
|
96 | + } |
|
97 | + $output->writeln($value); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @param StorageConfig $mount |
|
102 | - * @param string $key |
|
103 | - * @param string $value |
|
104 | - * @param OutputInterface $output |
|
105 | - */ |
|
106 | - protected function setOption(StorageConfig $mount, $key, $value, OutputInterface $output) { |
|
107 | - $decoded = json_decode($value, true); |
|
108 | - if (!is_null($decoded) && json_encode($decoded) === $value) { |
|
109 | - $value = $decoded; |
|
110 | - } |
|
111 | - if ($key === 'mountpoint' || $key === 'mount_point') { |
|
112 | - $mount->setMountPoint($value); |
|
113 | - } else { |
|
114 | - $mount->setBackendOption($key, $value); |
|
115 | - } |
|
116 | - $this->globalService->updateStorage($mount); |
|
117 | - } |
|
100 | + /** |
|
101 | + * @param StorageConfig $mount |
|
102 | + * @param string $key |
|
103 | + * @param string $value |
|
104 | + * @param OutputInterface $output |
|
105 | + */ |
|
106 | + protected function setOption(StorageConfig $mount, $key, $value, OutputInterface $output) { |
|
107 | + $decoded = json_decode($value, true); |
|
108 | + if (!is_null($decoded) && json_encode($decoded) === $value) { |
|
109 | + $value = $decoded; |
|
110 | + } |
|
111 | + if ($key === 'mountpoint' || $key === 'mount_point') { |
|
112 | + $mount->setMountPoint($value); |
|
113 | + } else { |
|
114 | + $mount->setBackendOption($key, $value); |
|
115 | + } |
|
116 | + $this->globalService->updateStorage($mount); |
|
117 | + } |
|
118 | 118 | } |
@@ -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 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | try { |
72 | 72 | $mount = $this->globalService->getStorage($mountId); |
73 | 73 | } catch (NotFoundException $e) { |
74 | - $output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts"</error>'); |
|
74 | + $output->writeln('<error>Mount with id "'.$mountId.' not found, check "occ files_external:list" to get available mounts"</error>'); |
|
75 | 75 | return 404; |
76 | 76 | } |
77 | 77 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | $backend->manipulateStorageConfig($storage); |
94 | 94 | } |
95 | 95 | |
96 | - private function updateStorageStatus(StorageConfig &$storage, $configInput, OutputInterface $output) { |
|
96 | + private function updateStorageStatus(StorageConfig & $storage, $configInput, OutputInterface $output) { |
|
97 | 97 | try { |
98 | 98 | try { |
99 | 99 | $this->manipulateStorageConfig($storage); |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | |
106 | 106 | foreach ($configInput as $configOption) { |
107 | 107 | if (!strpos($configOption, '=')) { |
108 | - $output->writeln('<error>Invalid mount configuration option "' . $configOption . '"</error>'); |
|
108 | + $output->writeln('<error>Invalid mount configuration option "'.$configOption.'"</error>'); |
|
109 | 109 | return; |
110 | 110 | } |
111 | 111 | list($key, $value) = explode('=', $configOption, 2); |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | // FIXME: convert storage exceptions to StorageNotAvailableException |
138 | 138 | $storage->setStatus( |
139 | 139 | StorageNotAvailableException::STATUS_ERROR, |
140 | - get_class($e) . ': ' . $e->getMessage() |
|
140 | + get_class($e).': '.$e->getMessage() |
|
141 | 141 | ); |
142 | 142 | } |
143 | 143 | } |
@@ -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 | } |
@@ -40,178 +40,178 @@ |
||
40 | 40 | use Symfony\Component\Console\Output\OutputInterface; |
41 | 41 | |
42 | 42 | class Notify extends Base { |
43 | - /** @var GlobalStoragesService */ |
|
44 | - private $globalService; |
|
45 | - /** @var IDBConnection */ |
|
46 | - private $connection; |
|
47 | - /** @var \OCP\DB\QueryBuilder\IQueryBuilder */ |
|
48 | - private $updateQuery; |
|
49 | - |
|
50 | - function __construct(GlobalStoragesService $globalService, IDBConnection $connection) { |
|
51 | - parent::__construct(); |
|
52 | - $this->globalService = $globalService; |
|
53 | - $this->connection = $connection; |
|
54 | - // the query builder doesn't really like subqueries with parameters |
|
55 | - $this->updateQuery = $this->connection->prepare( |
|
56 | - 'UPDATE *PREFIX*filecache SET size = -1 |
|
43 | + /** @var GlobalStoragesService */ |
|
44 | + private $globalService; |
|
45 | + /** @var IDBConnection */ |
|
46 | + private $connection; |
|
47 | + /** @var \OCP\DB\QueryBuilder\IQueryBuilder */ |
|
48 | + private $updateQuery; |
|
49 | + |
|
50 | + function __construct(GlobalStoragesService $globalService, IDBConnection $connection) { |
|
51 | + parent::__construct(); |
|
52 | + $this->globalService = $globalService; |
|
53 | + $this->connection = $connection; |
|
54 | + // the query builder doesn't really like subqueries with parameters |
|
55 | + $this->updateQuery = $this->connection->prepare( |
|
56 | + 'UPDATE *PREFIX*filecache SET size = -1 |
|
57 | 57 | WHERE `path` = ? |
58 | 58 | AND `storage` IN (SELECT storage_id FROM *PREFIX*mounts WHERE mount_id = ?)' |
59 | - ); |
|
60 | - } |
|
61 | - |
|
62 | - protected function configure() { |
|
63 | - $this |
|
64 | - ->setName('files_external:notify') |
|
65 | - ->setDescription('Listen for active update notifications for a configured external mount') |
|
66 | - ->addArgument( |
|
67 | - 'mount_id', |
|
68 | - InputArgument::REQUIRED, |
|
69 | - 'the mount id of the mount to listen to' |
|
70 | - )->addOption( |
|
71 | - 'user', |
|
72 | - 'u', |
|
73 | - InputOption::VALUE_REQUIRED, |
|
74 | - 'The username for the remote mount (required only for some mount configuration that don\'t store credentials)' |
|
75 | - )->addOption( |
|
76 | - 'password', |
|
77 | - 'p', |
|
78 | - InputOption::VALUE_REQUIRED, |
|
79 | - 'The password for the remote mount (required only for some mount configuration that don\'t store credentials)' |
|
80 | - )->addOption( |
|
81 | - 'path', |
|
82 | - null, |
|
83 | - InputOption::VALUE_REQUIRED, |
|
84 | - 'The directory in the storage to listen for updates in', |
|
85 | - '/' |
|
86 | - ); |
|
87 | - parent::configure(); |
|
88 | - } |
|
89 | - |
|
90 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
91 | - $mount = $this->globalService->getStorage($input->getArgument('mount_id')); |
|
92 | - if (is_null($mount)) { |
|
93 | - $output->writeln('<error>Mount not found</error>'); |
|
94 | - return 1; |
|
95 | - } |
|
96 | - $noAuth = false; |
|
97 | - try { |
|
98 | - $authBackend = $mount->getAuthMechanism(); |
|
99 | - $authBackend->manipulateStorageConfig($mount); |
|
100 | - } catch (InsufficientDataForMeaningfulAnswerException $e) { |
|
101 | - $noAuth = true; |
|
102 | - } catch (StorageNotAvailableException $e) { |
|
103 | - $noAuth = true; |
|
104 | - } |
|
105 | - |
|
106 | - if ($input->getOption('user')) { |
|
107 | - $mount->setBackendOption('user', $input->getOption('user')); |
|
108 | - } |
|
109 | - if ($input->getOption('password')) { |
|
110 | - $mount->setBackendOption('password', $input->getOption('password')); |
|
111 | - } |
|
112 | - |
|
113 | - try { |
|
114 | - $storage = $this->createStorage($mount); |
|
115 | - } catch (\Exception $e) { |
|
116 | - $output->writeln('<error>Error while trying to create storage</error>'); |
|
117 | - if ($noAuth) { |
|
118 | - $output->writeln('<error>Username and/or password required</error>'); |
|
119 | - } |
|
120 | - return 1; |
|
121 | - } |
|
122 | - if (!$storage instanceof INotifyStorage) { |
|
123 | - $output->writeln('<error>Mount of type "' . $mount->getBackend()->getText() . '" does not support active update notifications</error>'); |
|
124 | - return 1; |
|
125 | - } |
|
126 | - |
|
127 | - $verbose = $input->getOption('verbose'); |
|
128 | - |
|
129 | - $path = trim($input->getOption('path'), '/'); |
|
130 | - $notifyHandler = $storage->notify($path); |
|
131 | - $this->selfTest($storage, $notifyHandler, $verbose, $output); |
|
132 | - $notifyHandler->listen(function (IChange $change) use ($mount, $verbose, $output) { |
|
133 | - if ($verbose) { |
|
134 | - $this->logUpdate($change, $output); |
|
135 | - } |
|
136 | - if ($change instanceof IRenameChange) { |
|
137 | - $this->markParentAsOutdated($mount->getId(), $change->getTargetPath()); |
|
138 | - } |
|
139 | - $this->markParentAsOutdated($mount->getId(), $change->getPath()); |
|
140 | - }); |
|
141 | - } |
|
142 | - |
|
143 | - private function createStorage(StorageConfig $mount) { |
|
144 | - $class = $mount->getBackend()->getStorageClass(); |
|
145 | - return new $class($mount->getBackendOptions()); |
|
146 | - } |
|
147 | - |
|
148 | - private function markParentAsOutdated($mountId, $path) { |
|
149 | - $parent = dirname($path); |
|
150 | - if ($parent === '.') { |
|
151 | - $parent = ''; |
|
152 | - } |
|
153 | - $this->updateQuery->execute([$parent, $mountId]); |
|
154 | - } |
|
155 | - |
|
156 | - private function logUpdate(IChange $change, OutputInterface $output) { |
|
157 | - switch ($change->getType()) { |
|
158 | - case INotifyStorage::NOTIFY_ADDED: |
|
159 | - $text = 'added'; |
|
160 | - break; |
|
161 | - case INotifyStorage::NOTIFY_MODIFIED: |
|
162 | - $text = 'modified'; |
|
163 | - break; |
|
164 | - case INotifyStorage::NOTIFY_REMOVED: |
|
165 | - $text = 'removed'; |
|
166 | - break; |
|
167 | - case INotifyStorage::NOTIFY_RENAMED: |
|
168 | - $text = 'renamed'; |
|
169 | - break; |
|
170 | - default: |
|
171 | - return; |
|
172 | - } |
|
173 | - |
|
174 | - $text .= ' ' . $change->getPath(); |
|
175 | - if ($change instanceof IRenameChange) { |
|
176 | - $text .= ' to ' . $change->getTargetPath(); |
|
177 | - } |
|
178 | - |
|
179 | - $output->writeln($text); |
|
180 | - } |
|
181 | - |
|
182 | - private function selfTest(IStorage $storage, INotifyHandler $notifyHandler, $verbose, OutputInterface $output) { |
|
183 | - usleep(100 * 1000); //give time for the notify to start |
|
184 | - $storage->file_put_contents('/.nc_test_file.txt', 'test content'); |
|
185 | - $storage->mkdir('/.nc_test_folder'); |
|
186 | - $storage->file_put_contents('/.nc_test_folder/subfile.txt', 'test content'); |
|
187 | - |
|
188 | - usleep(100 * 1000); //time for all changes to be processed |
|
189 | - $changes = $notifyHandler->getChanges(); |
|
190 | - |
|
191 | - $storage->unlink('/.nc_test_file.txt'); |
|
192 | - $storage->unlink('/.nc_test_folder/subfile.txt'); |
|
193 | - $storage->rmdir('/.nc_test_folder'); |
|
194 | - |
|
195 | - usleep(100 * 1000); //time for all changes to be processed |
|
196 | - $notifyHandler->getChanges(); // flush |
|
197 | - |
|
198 | - $foundRootChange = false; |
|
199 | - $foundSubfolderChange = false; |
|
200 | - |
|
201 | - foreach ($changes as $change) { |
|
202 | - if ($change->getPath() === '/.nc_test_file.txt' || $change->getPath() === '.nc_test_file.txt') { |
|
203 | - $foundRootChange = true; |
|
204 | - } else if ($change->getPath() === '/.nc_test_folder/subfile.txt' || $change->getPath() === '.nc_test_folder/subfile.txt') { |
|
205 | - $foundSubfolderChange = true; |
|
206 | - } |
|
207 | - } |
|
208 | - |
|
209 | - if ($foundRootChange && $foundSubfolderChange && $verbose) { |
|
210 | - $output->writeln('<info>Self-test successful</info>'); |
|
211 | - } else if ($foundRootChange && !$foundSubfolderChange) { |
|
212 | - $output->writeln('<error>Error while running self-test, change is subfolder not detected</error>'); |
|
213 | - } else if (!$foundRootChange) { |
|
214 | - $output->writeln('<error>Error while running self-test, no changes detected</error>'); |
|
215 | - } |
|
216 | - } |
|
59 | + ); |
|
60 | + } |
|
61 | + |
|
62 | + protected function configure() { |
|
63 | + $this |
|
64 | + ->setName('files_external:notify') |
|
65 | + ->setDescription('Listen for active update notifications for a configured external mount') |
|
66 | + ->addArgument( |
|
67 | + 'mount_id', |
|
68 | + InputArgument::REQUIRED, |
|
69 | + 'the mount id of the mount to listen to' |
|
70 | + )->addOption( |
|
71 | + 'user', |
|
72 | + 'u', |
|
73 | + InputOption::VALUE_REQUIRED, |
|
74 | + 'The username for the remote mount (required only for some mount configuration that don\'t store credentials)' |
|
75 | + )->addOption( |
|
76 | + 'password', |
|
77 | + 'p', |
|
78 | + InputOption::VALUE_REQUIRED, |
|
79 | + 'The password for the remote mount (required only for some mount configuration that don\'t store credentials)' |
|
80 | + )->addOption( |
|
81 | + 'path', |
|
82 | + null, |
|
83 | + InputOption::VALUE_REQUIRED, |
|
84 | + 'The directory in the storage to listen for updates in', |
|
85 | + '/' |
|
86 | + ); |
|
87 | + parent::configure(); |
|
88 | + } |
|
89 | + |
|
90 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
91 | + $mount = $this->globalService->getStorage($input->getArgument('mount_id')); |
|
92 | + if (is_null($mount)) { |
|
93 | + $output->writeln('<error>Mount not found</error>'); |
|
94 | + return 1; |
|
95 | + } |
|
96 | + $noAuth = false; |
|
97 | + try { |
|
98 | + $authBackend = $mount->getAuthMechanism(); |
|
99 | + $authBackend->manipulateStorageConfig($mount); |
|
100 | + } catch (InsufficientDataForMeaningfulAnswerException $e) { |
|
101 | + $noAuth = true; |
|
102 | + } catch (StorageNotAvailableException $e) { |
|
103 | + $noAuth = true; |
|
104 | + } |
|
105 | + |
|
106 | + if ($input->getOption('user')) { |
|
107 | + $mount->setBackendOption('user', $input->getOption('user')); |
|
108 | + } |
|
109 | + if ($input->getOption('password')) { |
|
110 | + $mount->setBackendOption('password', $input->getOption('password')); |
|
111 | + } |
|
112 | + |
|
113 | + try { |
|
114 | + $storage = $this->createStorage($mount); |
|
115 | + } catch (\Exception $e) { |
|
116 | + $output->writeln('<error>Error while trying to create storage</error>'); |
|
117 | + if ($noAuth) { |
|
118 | + $output->writeln('<error>Username and/or password required</error>'); |
|
119 | + } |
|
120 | + return 1; |
|
121 | + } |
|
122 | + if (!$storage instanceof INotifyStorage) { |
|
123 | + $output->writeln('<error>Mount of type "' . $mount->getBackend()->getText() . '" does not support active update notifications</error>'); |
|
124 | + return 1; |
|
125 | + } |
|
126 | + |
|
127 | + $verbose = $input->getOption('verbose'); |
|
128 | + |
|
129 | + $path = trim($input->getOption('path'), '/'); |
|
130 | + $notifyHandler = $storage->notify($path); |
|
131 | + $this->selfTest($storage, $notifyHandler, $verbose, $output); |
|
132 | + $notifyHandler->listen(function (IChange $change) use ($mount, $verbose, $output) { |
|
133 | + if ($verbose) { |
|
134 | + $this->logUpdate($change, $output); |
|
135 | + } |
|
136 | + if ($change instanceof IRenameChange) { |
|
137 | + $this->markParentAsOutdated($mount->getId(), $change->getTargetPath()); |
|
138 | + } |
|
139 | + $this->markParentAsOutdated($mount->getId(), $change->getPath()); |
|
140 | + }); |
|
141 | + } |
|
142 | + |
|
143 | + private function createStorage(StorageConfig $mount) { |
|
144 | + $class = $mount->getBackend()->getStorageClass(); |
|
145 | + return new $class($mount->getBackendOptions()); |
|
146 | + } |
|
147 | + |
|
148 | + private function markParentAsOutdated($mountId, $path) { |
|
149 | + $parent = dirname($path); |
|
150 | + if ($parent === '.') { |
|
151 | + $parent = ''; |
|
152 | + } |
|
153 | + $this->updateQuery->execute([$parent, $mountId]); |
|
154 | + } |
|
155 | + |
|
156 | + private function logUpdate(IChange $change, OutputInterface $output) { |
|
157 | + switch ($change->getType()) { |
|
158 | + case INotifyStorage::NOTIFY_ADDED: |
|
159 | + $text = 'added'; |
|
160 | + break; |
|
161 | + case INotifyStorage::NOTIFY_MODIFIED: |
|
162 | + $text = 'modified'; |
|
163 | + break; |
|
164 | + case INotifyStorage::NOTIFY_REMOVED: |
|
165 | + $text = 'removed'; |
|
166 | + break; |
|
167 | + case INotifyStorage::NOTIFY_RENAMED: |
|
168 | + $text = 'renamed'; |
|
169 | + break; |
|
170 | + default: |
|
171 | + return; |
|
172 | + } |
|
173 | + |
|
174 | + $text .= ' ' . $change->getPath(); |
|
175 | + if ($change instanceof IRenameChange) { |
|
176 | + $text .= ' to ' . $change->getTargetPath(); |
|
177 | + } |
|
178 | + |
|
179 | + $output->writeln($text); |
|
180 | + } |
|
181 | + |
|
182 | + private function selfTest(IStorage $storage, INotifyHandler $notifyHandler, $verbose, OutputInterface $output) { |
|
183 | + usleep(100 * 1000); //give time for the notify to start |
|
184 | + $storage->file_put_contents('/.nc_test_file.txt', 'test content'); |
|
185 | + $storage->mkdir('/.nc_test_folder'); |
|
186 | + $storage->file_put_contents('/.nc_test_folder/subfile.txt', 'test content'); |
|
187 | + |
|
188 | + usleep(100 * 1000); //time for all changes to be processed |
|
189 | + $changes = $notifyHandler->getChanges(); |
|
190 | + |
|
191 | + $storage->unlink('/.nc_test_file.txt'); |
|
192 | + $storage->unlink('/.nc_test_folder/subfile.txt'); |
|
193 | + $storage->rmdir('/.nc_test_folder'); |
|
194 | + |
|
195 | + usleep(100 * 1000); //time for all changes to be processed |
|
196 | + $notifyHandler->getChanges(); // flush |
|
197 | + |
|
198 | + $foundRootChange = false; |
|
199 | + $foundSubfolderChange = false; |
|
200 | + |
|
201 | + foreach ($changes as $change) { |
|
202 | + if ($change->getPath() === '/.nc_test_file.txt' || $change->getPath() === '.nc_test_file.txt') { |
|
203 | + $foundRootChange = true; |
|
204 | + } else if ($change->getPath() === '/.nc_test_folder/subfile.txt' || $change->getPath() === '.nc_test_folder/subfile.txt') { |
|
205 | + $foundSubfolderChange = true; |
|
206 | + } |
|
207 | + } |
|
208 | + |
|
209 | + if ($foundRootChange && $foundSubfolderChange && $verbose) { |
|
210 | + $output->writeln('<info>Self-test successful</info>'); |
|
211 | + } else if ($foundRootChange && !$foundSubfolderChange) { |
|
212 | + $output->writeln('<error>Error while running self-test, change is subfolder not detected</error>'); |
|
213 | + } else if (!$foundRootChange) { |
|
214 | + $output->writeln('<error>Error while running self-test, no changes detected</error>'); |
|
215 | + } |
|
216 | + } |
|
217 | 217 | } |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | return 1; |
121 | 121 | } |
122 | 122 | if (!$storage instanceof INotifyStorage) { |
123 | - $output->writeln('<error>Mount of type "' . $mount->getBackend()->getText() . '" does not support active update notifications</error>'); |
|
123 | + $output->writeln('<error>Mount of type "'.$mount->getBackend()->getText().'" does not support active update notifications</error>'); |
|
124 | 124 | return 1; |
125 | 125 | } |
126 | 126 | |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | $path = trim($input->getOption('path'), '/'); |
130 | 130 | $notifyHandler = $storage->notify($path); |
131 | 131 | $this->selfTest($storage, $notifyHandler, $verbose, $output); |
132 | - $notifyHandler->listen(function (IChange $change) use ($mount, $verbose, $output) { |
|
132 | + $notifyHandler->listen(function(IChange $change) use ($mount, $verbose, $output) { |
|
133 | 133 | if ($verbose) { |
134 | 134 | $this->logUpdate($change, $output); |
135 | 135 | } |
@@ -171,9 +171,9 @@ discard block |
||
171 | 171 | return; |
172 | 172 | } |
173 | 173 | |
174 | - $text .= ' ' . $change->getPath(); |
|
174 | + $text .= ' '.$change->getPath(); |
|
175 | 175 | if ($change instanceof IRenameChange) { |
176 | - $text .= ' to ' . $change->getTargetPath(); |
|
176 | + $text .= ' to '.$change->getTargetPath(); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | $output->writeln($text); |
@@ -42,182 +42,182 @@ |
||
42 | 42 | use Symfony\Component\Console\Output\OutputInterface; |
43 | 43 | |
44 | 44 | class Create extends Base { |
45 | - /** |
|
46 | - * @var GlobalStoragesService |
|
47 | - */ |
|
48 | - private $globalService; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var UserStoragesService |
|
52 | - */ |
|
53 | - private $userService; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var IUserManager |
|
57 | - */ |
|
58 | - private $userManager; |
|
59 | - |
|
60 | - /** @var BackendService */ |
|
61 | - private $backendService; |
|
62 | - |
|
63 | - /** @var IUserSession */ |
|
64 | - private $userSession; |
|
65 | - |
|
66 | - function __construct(GlobalStoragesService $globalService, |
|
67 | - UserStoragesService $userService, |
|
68 | - IUserManager $userManager, |
|
69 | - IUserSession $userSession, |
|
70 | - BackendService $backendService |
|
71 | - ) { |
|
72 | - parent::__construct(); |
|
73 | - $this->globalService = $globalService; |
|
74 | - $this->userService = $userService; |
|
75 | - $this->userManager = $userManager; |
|
76 | - $this->userSession = $userSession; |
|
77 | - $this->backendService = $backendService; |
|
78 | - } |
|
79 | - |
|
80 | - protected function configure() { |
|
81 | - $this |
|
82 | - ->setName('files_external:create') |
|
83 | - ->setDescription('Create a new mount configuration') |
|
84 | - ->addOption( |
|
85 | - 'user', |
|
86 | - null, |
|
87 | - InputOption::VALUE_OPTIONAL, |
|
88 | - 'user to add the mount configuration for, if not set the mount will be added as system mount' |
|
89 | - ) |
|
90 | - ->addArgument( |
|
91 | - 'mount_point', |
|
92 | - InputArgument::REQUIRED, |
|
93 | - 'mount point for the new mount' |
|
94 | - ) |
|
95 | - ->addArgument( |
|
96 | - 'storage_backend', |
|
97 | - InputArgument::REQUIRED, |
|
98 | - 'storage backend identifier for the new mount, see `occ files_external:backends` for possible values' |
|
99 | - ) |
|
100 | - ->addArgument( |
|
101 | - 'authentication_backend', |
|
102 | - InputArgument::REQUIRED, |
|
103 | - 'authentication backend identifier for the new mount, see `occ files_external:backends` for possible values' |
|
104 | - ) |
|
105 | - ->addOption( |
|
106 | - 'config', |
|
107 | - 'c', |
|
108 | - InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
|
109 | - 'Mount configuration option in key=value format' |
|
110 | - ) |
|
111 | - ->addOption( |
|
112 | - 'dry', |
|
113 | - null, |
|
114 | - InputOption::VALUE_NONE, |
|
115 | - 'Don\'t save the created mount, only list the new mount' |
|
116 | - ); |
|
117 | - parent::configure(); |
|
118 | - } |
|
119 | - |
|
120 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
121 | - $user = $input->getOption('user'); |
|
122 | - $mountPoint = $input->getArgument('mount_point'); |
|
123 | - $storageIdentifier = $input->getArgument('storage_backend'); |
|
124 | - $authIdentifier = $input->getArgument('authentication_backend'); |
|
125 | - $configInput = $input->getOption('config'); |
|
126 | - |
|
127 | - $storageBackend = $this->backendService->getBackend($storageIdentifier); |
|
128 | - $authBackend = $this->backendService->getAuthMechanism($authIdentifier); |
|
129 | - |
|
130 | - if (!Filesystem::isValidPath($mountPoint)) { |
|
131 | - $output->writeln('<error>Invalid mountpoint "' . $mountPoint . '"</error>'); |
|
132 | - return 1; |
|
133 | - } |
|
134 | - if (is_null($storageBackend)) { |
|
135 | - $output->writeln('<error>Storage backend with identifier "' . $storageIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>'); |
|
136 | - return 404; |
|
137 | - } |
|
138 | - if (is_null($authBackend)) { |
|
139 | - $output->writeln('<error>Authentication backend with identifier "' . $authIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>'); |
|
140 | - return 404; |
|
141 | - } |
|
142 | - $supportedSchemes = array_keys($storageBackend->getAuthSchemes()); |
|
143 | - if (!in_array($authBackend->getScheme(), $supportedSchemes)) { |
|
144 | - $output->writeln('<error>Authentication backend "' . $authIdentifier . '" not valid for storage backend "' . $storageIdentifier . '" (see `occ files_external:backends storage ' . $storageIdentifier . '` for possible values)</error>'); |
|
145 | - return 1; |
|
146 | - } |
|
147 | - |
|
148 | - $config = []; |
|
149 | - foreach ($configInput as $configOption) { |
|
150 | - if (!strpos($configOption, '=')) { |
|
151 | - $output->writeln('<error>Invalid mount configuration option "' . $configOption . '"</error>'); |
|
152 | - return 1; |
|
153 | - } |
|
154 | - list($key, $value) = explode('=', $configOption, 2); |
|
155 | - if (!$this->validateParam($key, $value, $storageBackend, $authBackend)) { |
|
156 | - $output->writeln('<error>Unknown configuration for backends "' . $key . '"</error>'); |
|
157 | - return 1; |
|
158 | - } |
|
159 | - $config[$key] = $value; |
|
160 | - } |
|
161 | - |
|
162 | - $mount = new StorageConfig(); |
|
163 | - $mount->setMountPoint($mountPoint); |
|
164 | - $mount->setBackend($storageBackend); |
|
165 | - $mount->setAuthMechanism($authBackend); |
|
166 | - $mount->setBackendOptions($config); |
|
167 | - |
|
168 | - if ($user) { |
|
169 | - if (!$this->userManager->userExists($user)) { |
|
170 | - $output->writeln('<error>User "' . $user . '" not found</error>'); |
|
171 | - return 1; |
|
172 | - } |
|
173 | - $mount->setApplicableUsers([$user]); |
|
174 | - } |
|
175 | - |
|
176 | - if ($input->getOption('dry')) { |
|
177 | - $this->showMount($user, $mount, $input, $output); |
|
178 | - } else { |
|
179 | - $this->getStorageService($user)->addStorage($mount); |
|
180 | - if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) { |
|
181 | - $output->writeln('<info>Storage created with id ' . $mount->getId() . '</info>'); |
|
182 | - } else { |
|
183 | - $output->writeln($mount->getId()); |
|
184 | - } |
|
185 | - } |
|
186 | - return 0; |
|
187 | - } |
|
188 | - |
|
189 | - private function validateParam($key, &$value, Backend $storageBackend, AuthMechanism $authBackend) { |
|
190 | - $params = array_merge($storageBackend->getParameters(), $authBackend->getParameters()); |
|
191 | - foreach ($params as $param) { |
|
192 | - /** @var DefinitionParameter $param */ |
|
193 | - if ($param->getName() === $key) { |
|
194 | - if ($param->getType() === DefinitionParameter::VALUE_BOOLEAN) { |
|
195 | - $value = ($value === 'true'); |
|
196 | - } |
|
197 | - return true; |
|
198 | - } |
|
199 | - } |
|
200 | - return false; |
|
201 | - } |
|
202 | - |
|
203 | - private function showMount($user, StorageConfig $mount, InputInterface $input, OutputInterface $output) { |
|
204 | - $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager); |
|
205 | - $listInput = new ArrayInput([], $listCommand->getDefinition()); |
|
206 | - $listInput->setOption('output', $input->getOption('output')); |
|
207 | - $listInput->setOption('show-password', true); |
|
208 | - $listCommand->listMounts($user, [$mount], $listInput, $output); |
|
209 | - } |
|
210 | - |
|
211 | - protected function getStorageService($userId) { |
|
212 | - if (!empty($userId)) { |
|
213 | - $user = $this->userManager->get($userId); |
|
214 | - if (is_null($user)) { |
|
215 | - throw new NoUserException("user $userId not found"); |
|
216 | - } |
|
217 | - $this->userSession->setUser($user); |
|
218 | - return $this->userService; |
|
219 | - } else { |
|
220 | - return $this->globalService; |
|
221 | - } |
|
222 | - } |
|
45 | + /** |
|
46 | + * @var GlobalStoragesService |
|
47 | + */ |
|
48 | + private $globalService; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var UserStoragesService |
|
52 | + */ |
|
53 | + private $userService; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var IUserManager |
|
57 | + */ |
|
58 | + private $userManager; |
|
59 | + |
|
60 | + /** @var BackendService */ |
|
61 | + private $backendService; |
|
62 | + |
|
63 | + /** @var IUserSession */ |
|
64 | + private $userSession; |
|
65 | + |
|
66 | + function __construct(GlobalStoragesService $globalService, |
|
67 | + UserStoragesService $userService, |
|
68 | + IUserManager $userManager, |
|
69 | + IUserSession $userSession, |
|
70 | + BackendService $backendService |
|
71 | + ) { |
|
72 | + parent::__construct(); |
|
73 | + $this->globalService = $globalService; |
|
74 | + $this->userService = $userService; |
|
75 | + $this->userManager = $userManager; |
|
76 | + $this->userSession = $userSession; |
|
77 | + $this->backendService = $backendService; |
|
78 | + } |
|
79 | + |
|
80 | + protected function configure() { |
|
81 | + $this |
|
82 | + ->setName('files_external:create') |
|
83 | + ->setDescription('Create a new mount configuration') |
|
84 | + ->addOption( |
|
85 | + 'user', |
|
86 | + null, |
|
87 | + InputOption::VALUE_OPTIONAL, |
|
88 | + 'user to add the mount configuration for, if not set the mount will be added as system mount' |
|
89 | + ) |
|
90 | + ->addArgument( |
|
91 | + 'mount_point', |
|
92 | + InputArgument::REQUIRED, |
|
93 | + 'mount point for the new mount' |
|
94 | + ) |
|
95 | + ->addArgument( |
|
96 | + 'storage_backend', |
|
97 | + InputArgument::REQUIRED, |
|
98 | + 'storage backend identifier for the new mount, see `occ files_external:backends` for possible values' |
|
99 | + ) |
|
100 | + ->addArgument( |
|
101 | + 'authentication_backend', |
|
102 | + InputArgument::REQUIRED, |
|
103 | + 'authentication backend identifier for the new mount, see `occ files_external:backends` for possible values' |
|
104 | + ) |
|
105 | + ->addOption( |
|
106 | + 'config', |
|
107 | + 'c', |
|
108 | + InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
|
109 | + 'Mount configuration option in key=value format' |
|
110 | + ) |
|
111 | + ->addOption( |
|
112 | + 'dry', |
|
113 | + null, |
|
114 | + InputOption::VALUE_NONE, |
|
115 | + 'Don\'t save the created mount, only list the new mount' |
|
116 | + ); |
|
117 | + parent::configure(); |
|
118 | + } |
|
119 | + |
|
120 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
121 | + $user = $input->getOption('user'); |
|
122 | + $mountPoint = $input->getArgument('mount_point'); |
|
123 | + $storageIdentifier = $input->getArgument('storage_backend'); |
|
124 | + $authIdentifier = $input->getArgument('authentication_backend'); |
|
125 | + $configInput = $input->getOption('config'); |
|
126 | + |
|
127 | + $storageBackend = $this->backendService->getBackend($storageIdentifier); |
|
128 | + $authBackend = $this->backendService->getAuthMechanism($authIdentifier); |
|
129 | + |
|
130 | + if (!Filesystem::isValidPath($mountPoint)) { |
|
131 | + $output->writeln('<error>Invalid mountpoint "' . $mountPoint . '"</error>'); |
|
132 | + return 1; |
|
133 | + } |
|
134 | + if (is_null($storageBackend)) { |
|
135 | + $output->writeln('<error>Storage backend with identifier "' . $storageIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>'); |
|
136 | + return 404; |
|
137 | + } |
|
138 | + if (is_null($authBackend)) { |
|
139 | + $output->writeln('<error>Authentication backend with identifier "' . $authIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>'); |
|
140 | + return 404; |
|
141 | + } |
|
142 | + $supportedSchemes = array_keys($storageBackend->getAuthSchemes()); |
|
143 | + if (!in_array($authBackend->getScheme(), $supportedSchemes)) { |
|
144 | + $output->writeln('<error>Authentication backend "' . $authIdentifier . '" not valid for storage backend "' . $storageIdentifier . '" (see `occ files_external:backends storage ' . $storageIdentifier . '` for possible values)</error>'); |
|
145 | + return 1; |
|
146 | + } |
|
147 | + |
|
148 | + $config = []; |
|
149 | + foreach ($configInput as $configOption) { |
|
150 | + if (!strpos($configOption, '=')) { |
|
151 | + $output->writeln('<error>Invalid mount configuration option "' . $configOption . '"</error>'); |
|
152 | + return 1; |
|
153 | + } |
|
154 | + list($key, $value) = explode('=', $configOption, 2); |
|
155 | + if (!$this->validateParam($key, $value, $storageBackend, $authBackend)) { |
|
156 | + $output->writeln('<error>Unknown configuration for backends "' . $key . '"</error>'); |
|
157 | + return 1; |
|
158 | + } |
|
159 | + $config[$key] = $value; |
|
160 | + } |
|
161 | + |
|
162 | + $mount = new StorageConfig(); |
|
163 | + $mount->setMountPoint($mountPoint); |
|
164 | + $mount->setBackend($storageBackend); |
|
165 | + $mount->setAuthMechanism($authBackend); |
|
166 | + $mount->setBackendOptions($config); |
|
167 | + |
|
168 | + if ($user) { |
|
169 | + if (!$this->userManager->userExists($user)) { |
|
170 | + $output->writeln('<error>User "' . $user . '" not found</error>'); |
|
171 | + return 1; |
|
172 | + } |
|
173 | + $mount->setApplicableUsers([$user]); |
|
174 | + } |
|
175 | + |
|
176 | + if ($input->getOption('dry')) { |
|
177 | + $this->showMount($user, $mount, $input, $output); |
|
178 | + } else { |
|
179 | + $this->getStorageService($user)->addStorage($mount); |
|
180 | + if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) { |
|
181 | + $output->writeln('<info>Storage created with id ' . $mount->getId() . '</info>'); |
|
182 | + } else { |
|
183 | + $output->writeln($mount->getId()); |
|
184 | + } |
|
185 | + } |
|
186 | + return 0; |
|
187 | + } |
|
188 | + |
|
189 | + private function validateParam($key, &$value, Backend $storageBackend, AuthMechanism $authBackend) { |
|
190 | + $params = array_merge($storageBackend->getParameters(), $authBackend->getParameters()); |
|
191 | + foreach ($params as $param) { |
|
192 | + /** @var DefinitionParameter $param */ |
|
193 | + if ($param->getName() === $key) { |
|
194 | + if ($param->getType() === DefinitionParameter::VALUE_BOOLEAN) { |
|
195 | + $value = ($value === 'true'); |
|
196 | + } |
|
197 | + return true; |
|
198 | + } |
|
199 | + } |
|
200 | + return false; |
|
201 | + } |
|
202 | + |
|
203 | + private function showMount($user, StorageConfig $mount, InputInterface $input, OutputInterface $output) { |
|
204 | + $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager); |
|
205 | + $listInput = new ArrayInput([], $listCommand->getDefinition()); |
|
206 | + $listInput->setOption('output', $input->getOption('output')); |
|
207 | + $listInput->setOption('show-password', true); |
|
208 | + $listCommand->listMounts($user, [$mount], $listInput, $output); |
|
209 | + } |
|
210 | + |
|
211 | + protected function getStorageService($userId) { |
|
212 | + if (!empty($userId)) { |
|
213 | + $user = $this->userManager->get($userId); |
|
214 | + if (is_null($user)) { |
|
215 | + throw new NoUserException("user $userId not found"); |
|
216 | + } |
|
217 | + $this->userSession->setUser($user); |
|
218 | + return $this->userService; |
|
219 | + } else { |
|
220 | + return $this->globalService; |
|
221 | + } |
|
222 | + } |
|
223 | 223 | } |
@@ -128,32 +128,32 @@ discard block |
||
128 | 128 | $authBackend = $this->backendService->getAuthMechanism($authIdentifier); |
129 | 129 | |
130 | 130 | if (!Filesystem::isValidPath($mountPoint)) { |
131 | - $output->writeln('<error>Invalid mountpoint "' . $mountPoint . '"</error>'); |
|
131 | + $output->writeln('<error>Invalid mountpoint "'.$mountPoint.'"</error>'); |
|
132 | 132 | return 1; |
133 | 133 | } |
134 | 134 | if (is_null($storageBackend)) { |
135 | - $output->writeln('<error>Storage backend with identifier "' . $storageIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>'); |
|
135 | + $output->writeln('<error>Storage backend with identifier "'.$storageIdentifier.'" not found (see `occ files_external:backends` for possible values)</error>'); |
|
136 | 136 | return 404; |
137 | 137 | } |
138 | 138 | if (is_null($authBackend)) { |
139 | - $output->writeln('<error>Authentication backend with identifier "' . $authIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>'); |
|
139 | + $output->writeln('<error>Authentication backend with identifier "'.$authIdentifier.'" not found (see `occ files_external:backends` for possible values)</error>'); |
|
140 | 140 | return 404; |
141 | 141 | } |
142 | 142 | $supportedSchemes = array_keys($storageBackend->getAuthSchemes()); |
143 | 143 | if (!in_array($authBackend->getScheme(), $supportedSchemes)) { |
144 | - $output->writeln('<error>Authentication backend "' . $authIdentifier . '" not valid for storage backend "' . $storageIdentifier . '" (see `occ files_external:backends storage ' . $storageIdentifier . '` for possible values)</error>'); |
|
144 | + $output->writeln('<error>Authentication backend "'.$authIdentifier.'" not valid for storage backend "'.$storageIdentifier.'" (see `occ files_external:backends storage '.$storageIdentifier.'` for possible values)</error>'); |
|
145 | 145 | return 1; |
146 | 146 | } |
147 | 147 | |
148 | 148 | $config = []; |
149 | 149 | foreach ($configInput as $configOption) { |
150 | 150 | if (!strpos($configOption, '=')) { |
151 | - $output->writeln('<error>Invalid mount configuration option "' . $configOption . '"</error>'); |
|
151 | + $output->writeln('<error>Invalid mount configuration option "'.$configOption.'"</error>'); |
|
152 | 152 | return 1; |
153 | 153 | } |
154 | 154 | list($key, $value) = explode('=', $configOption, 2); |
155 | 155 | if (!$this->validateParam($key, $value, $storageBackend, $authBackend)) { |
156 | - $output->writeln('<error>Unknown configuration for backends "' . $key . '"</error>'); |
|
156 | + $output->writeln('<error>Unknown configuration for backends "'.$key.'"</error>'); |
|
157 | 157 | return 1; |
158 | 158 | } |
159 | 159 | $config[$key] = $value; |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | |
168 | 168 | if ($user) { |
169 | 169 | if (!$this->userManager->userExists($user)) { |
170 | - $output->writeln('<error>User "' . $user . '" not found</error>'); |
|
170 | + $output->writeln('<error>User "'.$user.'" not found</error>'); |
|
171 | 171 | return 1; |
172 | 172 | } |
173 | 173 | $mount->setApplicableUsers([$user]); |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | } else { |
179 | 179 | $this->getStorageService($user)->addStorage($mount); |
180 | 180 | if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) { |
181 | - $output->writeln('<info>Storage created with id ' . $mount->getId() . '</info>'); |
|
181 | + $output->writeln('<info>Storage created with id '.$mount->getId().'</info>'); |
|
182 | 182 | } else { |
183 | 183 | $output->writeln($mount->getId()); |
184 | 184 | } |
@@ -32,91 +32,91 @@ |
||
32 | 32 | use Symfony\Component\Console\Output\OutputInterface; |
33 | 33 | |
34 | 34 | class Backends extends Base { |
35 | - /** @var BackendService */ |
|
36 | - private $backendService; |
|
35 | + /** @var BackendService */ |
|
36 | + private $backendService; |
|
37 | 37 | |
38 | - function __construct(BackendService $backendService |
|
39 | - ) { |
|
40 | - parent::__construct(); |
|
38 | + function __construct(BackendService $backendService |
|
39 | + ) { |
|
40 | + parent::__construct(); |
|
41 | 41 | |
42 | - $this->backendService = $backendService; |
|
43 | - } |
|
42 | + $this->backendService = $backendService; |
|
43 | + } |
|
44 | 44 | |
45 | - protected function configure() { |
|
46 | - $this |
|
47 | - ->setName('files_external:backends') |
|
48 | - ->setDescription('Show available authentication and storage backends') |
|
49 | - ->addArgument( |
|
50 | - 'type', |
|
51 | - InputArgument::OPTIONAL, |
|
52 | - 'only show backends of a certain type. Possible values are "authentication" or "storage"' |
|
53 | - )->addArgument( |
|
54 | - 'backend', |
|
55 | - InputArgument::OPTIONAL, |
|
56 | - 'only show information of a specific backend' |
|
57 | - ); |
|
58 | - parent::configure(); |
|
59 | - } |
|
45 | + protected function configure() { |
|
46 | + $this |
|
47 | + ->setName('files_external:backends') |
|
48 | + ->setDescription('Show available authentication and storage backends') |
|
49 | + ->addArgument( |
|
50 | + 'type', |
|
51 | + InputArgument::OPTIONAL, |
|
52 | + 'only show backends of a certain type. Possible values are "authentication" or "storage"' |
|
53 | + )->addArgument( |
|
54 | + 'backend', |
|
55 | + InputArgument::OPTIONAL, |
|
56 | + 'only show information of a specific backend' |
|
57 | + ); |
|
58 | + parent::configure(); |
|
59 | + } |
|
60 | 60 | |
61 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
62 | - $authBackends = $this->backendService->getAuthMechanisms(); |
|
63 | - $storageBackends = $this->backendService->getBackends(); |
|
61 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
62 | + $authBackends = $this->backendService->getAuthMechanisms(); |
|
63 | + $storageBackends = $this->backendService->getBackends(); |
|
64 | 64 | |
65 | - $data = [ |
|
66 | - 'authentication' => array_map([$this, 'serializeAuthBackend'], $authBackends), |
|
67 | - 'storage' => array_map([$this, 'serializeAuthBackend'], $storageBackends) |
|
68 | - ]; |
|
65 | + $data = [ |
|
66 | + 'authentication' => array_map([$this, 'serializeAuthBackend'], $authBackends), |
|
67 | + 'storage' => array_map([$this, 'serializeAuthBackend'], $storageBackends) |
|
68 | + ]; |
|
69 | 69 | |
70 | - $type = $input->getArgument('type'); |
|
71 | - $backend = $input->getArgument('backend'); |
|
72 | - if ($type) { |
|
73 | - if (!isset($data[$type])) { |
|
74 | - $output->writeln('<error>Invalid type "' . $type . '". Possible values are "authentication" or "storage"</error>'); |
|
75 | - return 1; |
|
76 | - } |
|
77 | - $data = $data[$type]; |
|
70 | + $type = $input->getArgument('type'); |
|
71 | + $backend = $input->getArgument('backend'); |
|
72 | + if ($type) { |
|
73 | + if (!isset($data[$type])) { |
|
74 | + $output->writeln('<error>Invalid type "' . $type . '". Possible values are "authentication" or "storage"</error>'); |
|
75 | + return 1; |
|
76 | + } |
|
77 | + $data = $data[$type]; |
|
78 | 78 | |
79 | - if ($backend) { |
|
80 | - if (!isset($data[$backend])) { |
|
81 | - $output->writeln('<error>Unknown backend "' . $backend . '" of type "' . $type . '"</error>'); |
|
82 | - return 1; |
|
83 | - } |
|
84 | - $data = $data[$backend]; |
|
85 | - } |
|
86 | - } |
|
79 | + if ($backend) { |
|
80 | + if (!isset($data[$backend])) { |
|
81 | + $output->writeln('<error>Unknown backend "' . $backend . '" of type "' . $type . '"</error>'); |
|
82 | + return 1; |
|
83 | + } |
|
84 | + $data = $data[$backend]; |
|
85 | + } |
|
86 | + } |
|
87 | 87 | |
88 | - $this->writeArrayInOutputFormat($input, $output, $data); |
|
89 | - } |
|
88 | + $this->writeArrayInOutputFormat($input, $output, $data); |
|
89 | + } |
|
90 | 90 | |
91 | - private function serializeAuthBackend(\JsonSerializable $backend) { |
|
92 | - $data = $backend->jsonSerialize(); |
|
93 | - $result = [ |
|
94 | - 'name' => $data['name'], |
|
95 | - 'identifier' => $data['identifier'], |
|
96 | - 'configuration' => $this->formatConfiguration($data['configuration']) |
|
97 | - ]; |
|
98 | - if ($backend instanceof Backend) { |
|
99 | - $result['storage_class'] = $backend->getStorageClass(); |
|
100 | - $authBackends = $this->backendService->getAuthMechanismsByScheme(array_keys($backend->getAuthSchemes())); |
|
101 | - $result['supported_authentication_backends'] = array_keys($authBackends); |
|
102 | - $authConfig = array_map(function (AuthMechanism $auth) { |
|
103 | - return $this->serializeAuthBackend($auth)['configuration']; |
|
104 | - }, $authBackends); |
|
105 | - $result['authentication_configuration'] = array_combine(array_keys($authBackends), $authConfig); |
|
106 | - } |
|
107 | - return $result; |
|
108 | - } |
|
91 | + private function serializeAuthBackend(\JsonSerializable $backend) { |
|
92 | + $data = $backend->jsonSerialize(); |
|
93 | + $result = [ |
|
94 | + 'name' => $data['name'], |
|
95 | + 'identifier' => $data['identifier'], |
|
96 | + 'configuration' => $this->formatConfiguration($data['configuration']) |
|
97 | + ]; |
|
98 | + if ($backend instanceof Backend) { |
|
99 | + $result['storage_class'] = $backend->getStorageClass(); |
|
100 | + $authBackends = $this->backendService->getAuthMechanismsByScheme(array_keys($backend->getAuthSchemes())); |
|
101 | + $result['supported_authentication_backends'] = array_keys($authBackends); |
|
102 | + $authConfig = array_map(function (AuthMechanism $auth) { |
|
103 | + return $this->serializeAuthBackend($auth)['configuration']; |
|
104 | + }, $authBackends); |
|
105 | + $result['authentication_configuration'] = array_combine(array_keys($authBackends), $authConfig); |
|
106 | + } |
|
107 | + return $result; |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * @param DefinitionParameter[] $parameters |
|
112 | - * @return string[] |
|
113 | - */ |
|
114 | - private function formatConfiguration(array $parameters) { |
|
115 | - $configuration = array_filter($parameters, function (DefinitionParameter $parameter) { |
|
116 | - return $parameter->getType() !== DefinitionParameter::VALUE_HIDDEN; |
|
117 | - }); |
|
118 | - return array_map(function (DefinitionParameter $parameter) { |
|
119 | - return $parameter->getTypeName(); |
|
120 | - }, $configuration); |
|
121 | - } |
|
110 | + /** |
|
111 | + * @param DefinitionParameter[] $parameters |
|
112 | + * @return string[] |
|
113 | + */ |
|
114 | + private function formatConfiguration(array $parameters) { |
|
115 | + $configuration = array_filter($parameters, function (DefinitionParameter $parameter) { |
|
116 | + return $parameter->getType() !== DefinitionParameter::VALUE_HIDDEN; |
|
117 | + }); |
|
118 | + return array_map(function (DefinitionParameter $parameter) { |
|
119 | + return $parameter->getTypeName(); |
|
120 | + }, $configuration); |
|
121 | + } |
|
122 | 122 | } |
@@ -71,14 +71,14 @@ discard block |
||
71 | 71 | $backend = $input->getArgument('backend'); |
72 | 72 | if ($type) { |
73 | 73 | if (!isset($data[$type])) { |
74 | - $output->writeln('<error>Invalid type "' . $type . '". Possible values are "authentication" or "storage"</error>'); |
|
74 | + $output->writeln('<error>Invalid type "'.$type.'". Possible values are "authentication" or "storage"</error>'); |
|
75 | 75 | return 1; |
76 | 76 | } |
77 | 77 | $data = $data[$type]; |
78 | 78 | |
79 | 79 | if ($backend) { |
80 | 80 | if (!isset($data[$backend])) { |
81 | - $output->writeln('<error>Unknown backend "' . $backend . '" of type "' . $type . '"</error>'); |
|
81 | + $output->writeln('<error>Unknown backend "'.$backend.'" of type "'.$type.'"</error>'); |
|
82 | 82 | return 1; |
83 | 83 | } |
84 | 84 | $data = $data[$backend]; |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | $result['storage_class'] = $backend->getStorageClass(); |
100 | 100 | $authBackends = $this->backendService->getAuthMechanismsByScheme(array_keys($backend->getAuthSchemes())); |
101 | 101 | $result['supported_authentication_backends'] = array_keys($authBackends); |
102 | - $authConfig = array_map(function (AuthMechanism $auth) { |
|
102 | + $authConfig = array_map(function(AuthMechanism $auth) { |
|
103 | 103 | return $this->serializeAuthBackend($auth)['configuration']; |
104 | 104 | }, $authBackends); |
105 | 105 | $result['authentication_configuration'] = array_combine(array_keys($authBackends), $authConfig); |
@@ -112,10 +112,10 @@ discard block |
||
112 | 112 | * @return string[] |
113 | 113 | */ |
114 | 114 | private function formatConfiguration(array $parameters) { |
115 | - $configuration = array_filter($parameters, function (DefinitionParameter $parameter) { |
|
115 | + $configuration = array_filter($parameters, function(DefinitionParameter $parameter) { |
|
116 | 116 | return $parameter->getType() !== DefinitionParameter::VALUE_HIDDEN; |
117 | 117 | }); |
118 | - return array_map(function (DefinitionParameter $parameter) { |
|
118 | + return array_map(function(DefinitionParameter $parameter) { |
|
119 | 119 | return $parameter->getTypeName(); |
120 | 120 | }, $configuration); |
121 | 121 | } |
@@ -37,76 +37,76 @@ |
||
37 | 37 | use Symfony\Component\Console\Question\ConfirmationQuestion; |
38 | 38 | |
39 | 39 | class Delete extends Base { |
40 | - /** |
|
41 | - * @var GlobalStoragesService |
|
42 | - */ |
|
43 | - protected $globalService; |
|
40 | + /** |
|
41 | + * @var GlobalStoragesService |
|
42 | + */ |
|
43 | + protected $globalService; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @var UserStoragesService |
|
47 | - */ |
|
48 | - protected $userService; |
|
45 | + /** |
|
46 | + * @var UserStoragesService |
|
47 | + */ |
|
48 | + protected $userService; |
|
49 | 49 | |
50 | - /** |
|
51 | - * @var IUserSession |
|
52 | - */ |
|
53 | - protected $userSession; |
|
50 | + /** |
|
51 | + * @var IUserSession |
|
52 | + */ |
|
53 | + protected $userSession; |
|
54 | 54 | |
55 | - /** |
|
56 | - * @var IUserManager |
|
57 | - */ |
|
58 | - protected $userManager; |
|
55 | + /** |
|
56 | + * @var IUserManager |
|
57 | + */ |
|
58 | + protected $userManager; |
|
59 | 59 | |
60 | - function __construct(GlobalStoragesService $globalService, UserStoragesService $userService, IUserSession $userSession, IUserManager $userManager) { |
|
61 | - parent::__construct(); |
|
62 | - $this->globalService = $globalService; |
|
63 | - $this->userService = $userService; |
|
64 | - $this->userSession = $userSession; |
|
65 | - $this->userManager = $userManager; |
|
66 | - } |
|
60 | + function __construct(GlobalStoragesService $globalService, UserStoragesService $userService, IUserSession $userSession, IUserManager $userManager) { |
|
61 | + parent::__construct(); |
|
62 | + $this->globalService = $globalService; |
|
63 | + $this->userService = $userService; |
|
64 | + $this->userSession = $userSession; |
|
65 | + $this->userManager = $userManager; |
|
66 | + } |
|
67 | 67 | |
68 | - protected function configure() { |
|
69 | - $this |
|
70 | - ->setName('files_external:delete') |
|
71 | - ->setDescription('Delete an external mount') |
|
72 | - ->addArgument( |
|
73 | - 'mount_id', |
|
74 | - InputArgument::REQUIRED, |
|
75 | - 'The id of the mount to edit' |
|
76 | - )->addOption( |
|
77 | - 'yes', |
|
78 | - 'y', |
|
79 | - InputOption::VALUE_NONE, |
|
80 | - 'Skip confirmation' |
|
81 | - ); |
|
82 | - parent::configure(); |
|
83 | - } |
|
68 | + protected function configure() { |
|
69 | + $this |
|
70 | + ->setName('files_external:delete') |
|
71 | + ->setDescription('Delete an external mount') |
|
72 | + ->addArgument( |
|
73 | + 'mount_id', |
|
74 | + InputArgument::REQUIRED, |
|
75 | + 'The id of the mount to edit' |
|
76 | + )->addOption( |
|
77 | + 'yes', |
|
78 | + 'y', |
|
79 | + InputOption::VALUE_NONE, |
|
80 | + 'Skip confirmation' |
|
81 | + ); |
|
82 | + parent::configure(); |
|
83 | + } |
|
84 | 84 | |
85 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
86 | - $mountId = $input->getArgument('mount_id'); |
|
87 | - try { |
|
88 | - $mount = $this->globalService->getStorage($mountId); |
|
89 | - } catch (NotFoundException $e) { |
|
90 | - $output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts"</error>'); |
|
91 | - return 404; |
|
92 | - } |
|
85 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
86 | + $mountId = $input->getArgument('mount_id'); |
|
87 | + try { |
|
88 | + $mount = $this->globalService->getStorage($mountId); |
|
89 | + } catch (NotFoundException $e) { |
|
90 | + $output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts"</error>'); |
|
91 | + return 404; |
|
92 | + } |
|
93 | 93 | |
94 | - $noConfirm = $input->getOption('yes'); |
|
94 | + $noConfirm = $input->getOption('yes'); |
|
95 | 95 | |
96 | - if (!$noConfirm) { |
|
97 | - $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager); |
|
98 | - $listInput = new ArrayInput([], $listCommand->getDefinition()); |
|
99 | - $listInput->setOption('output', $input->getOption('output')); |
|
100 | - $listCommand->listMounts(null, [$mount], $listInput, $output); |
|
96 | + if (!$noConfirm) { |
|
97 | + $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager); |
|
98 | + $listInput = new ArrayInput([], $listCommand->getDefinition()); |
|
99 | + $listInput->setOption('output', $input->getOption('output')); |
|
100 | + $listCommand->listMounts(null, [$mount], $listInput, $output); |
|
101 | 101 | |
102 | - $questionHelper = $this->getHelper('question'); |
|
103 | - $question = new ConfirmationQuestion('Delete this mount? [y/N] ', false); |
|
102 | + $questionHelper = $this->getHelper('question'); |
|
103 | + $question = new ConfirmationQuestion('Delete this mount? [y/N] ', false); |
|
104 | 104 | |
105 | - if (!$questionHelper->ask($input, $output, $question)) { |
|
106 | - return; |
|
107 | - } |
|
108 | - } |
|
105 | + if (!$questionHelper->ask($input, $output, $question)) { |
|
106 | + return; |
|
107 | + } |
|
108 | + } |
|
109 | 109 | |
110 | - $this->globalService->removeStorage($mountId); |
|
111 | - } |
|
110 | + $this->globalService->removeStorage($mountId); |
|
111 | + } |
|
112 | 112 | } |
@@ -68,7 +68,7 @@ |
||
68 | 68 | try { |
69 | 69 | $mount = $this->globalService->getStorage($mountId); |
70 | 70 | } catch (NotFoundException $e) { |
71 | - $output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts"</error>'); |
|
71 | + $output->writeln('<error>Mount with id "'.$mountId.' not found, check "occ files_external:list" to get available mounts"</error>'); |
|
72 | 72 | return 404; |
73 | 73 | } |
74 | 74 |
@@ -39,187 +39,187 @@ |
||
39 | 39 | use Symfony\Component\Console\Output\OutputInterface; |
40 | 40 | |
41 | 41 | class Import extends Base { |
42 | - /** |
|
43 | - * @var GlobalStoragesService |
|
44 | - */ |
|
45 | - private $globalService; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var UserStoragesService |
|
49 | - */ |
|
50 | - private $userService; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var IUserSession |
|
54 | - */ |
|
55 | - private $userSession; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var IUserManager |
|
59 | - */ |
|
60 | - private $userManager; |
|
61 | - |
|
62 | - /** @var ImportLegacyStoragesService */ |
|
63 | - private $importLegacyStorageService; |
|
64 | - |
|
65 | - /** @var BackendService */ |
|
66 | - private $backendService; |
|
67 | - |
|
68 | - function __construct(GlobalStoragesService $globalService, |
|
69 | - UserStoragesService $userService, |
|
70 | - IUserSession $userSession, |
|
71 | - IUserManager $userManager, |
|
72 | - ImportLegacyStoragesService $importLegacyStorageService, |
|
73 | - BackendService $backendService |
|
74 | - ) { |
|
75 | - parent::__construct(); |
|
76 | - $this->globalService = $globalService; |
|
77 | - $this->userService = $userService; |
|
78 | - $this->userSession = $userSession; |
|
79 | - $this->userManager = $userManager; |
|
80 | - $this->importLegacyStorageService = $importLegacyStorageService; |
|
81 | - $this->backendService = $backendService; |
|
82 | - } |
|
83 | - |
|
84 | - protected function configure() { |
|
85 | - $this |
|
86 | - ->setName('files_external:import') |
|
87 | - ->setDescription('Import mount configurations') |
|
88 | - ->addOption( |
|
89 | - 'user', |
|
90 | - null, |
|
91 | - InputOption::VALUE_OPTIONAL, |
|
92 | - 'user to add the mount configurations for, if not set the mount will be added as system mount' |
|
93 | - ) |
|
94 | - ->addArgument( |
|
95 | - 'path', |
|
96 | - InputArgument::REQUIRED, |
|
97 | - 'path to a json file containing the mounts to import, use "-" to read from stdin' |
|
98 | - ) |
|
99 | - ->addOption( |
|
100 | - 'dry', |
|
101 | - null, |
|
102 | - InputOption::VALUE_NONE, |
|
103 | - 'Don\'t save the imported mounts, only list the new mounts' |
|
104 | - ); |
|
105 | - parent::configure(); |
|
106 | - } |
|
107 | - |
|
108 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
109 | - $user = $input->getOption('user'); |
|
110 | - $path = $input->getArgument('path'); |
|
111 | - if ($path === '-') { |
|
112 | - $json = file_get_contents('php://stdin'); |
|
113 | - } else { |
|
114 | - if (!file_exists($path)) { |
|
115 | - $output->writeln('<error>File not found: ' . $path . '</error>'); |
|
116 | - return 1; |
|
117 | - } |
|
118 | - $json = file_get_contents($path); |
|
119 | - } |
|
120 | - if (!is_string($json) || strlen($json) < 2) { |
|
121 | - $output->writeln('<error>Error while reading json</error>'); |
|
122 | - return 1; |
|
123 | - } |
|
124 | - $data = json_decode($json, true); |
|
125 | - if (!is_array($data)) { |
|
126 | - $output->writeln('<error>Error while parsing json</error>'); |
|
127 | - return 1; |
|
128 | - } |
|
129 | - |
|
130 | - $isLegacy = isset($data['user']) || isset($data['group']); |
|
131 | - if ($isLegacy) { |
|
132 | - $this->importLegacyStorageService->setData($data); |
|
133 | - $mounts = $this->importLegacyStorageService->getAllStorages(); |
|
134 | - foreach ($mounts as $mount) { |
|
135 | - if ($mount->getBackendOption('password') === false) { |
|
136 | - $output->writeln('<error>Failed to decrypt password</error>'); |
|
137 | - return 1; |
|
138 | - } |
|
139 | - } |
|
140 | - } else { |
|
141 | - if (!isset($data[0])) { //normalize to an array of mounts |
|
142 | - $data = [$data]; |
|
143 | - } |
|
144 | - $mounts = array_map([$this, 'parseData'], $data); |
|
145 | - } |
|
146 | - |
|
147 | - if ($user) { |
|
148 | - // ensure applicables are correct for personal mounts |
|
149 | - foreach ($mounts as $mount) { |
|
150 | - $mount->setApplicableGroups([]); |
|
151 | - $mount->setApplicableUsers([$user]); |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - $storageService = $this->getStorageService($user); |
|
156 | - |
|
157 | - $existingMounts = $storageService->getAllStorages(); |
|
158 | - |
|
159 | - foreach ($mounts as $mount) { |
|
160 | - foreach ($existingMounts as $existingMount) { |
|
161 | - if ( |
|
162 | - $existingMount->getMountPoint() === $mount->getMountPoint() && |
|
163 | - $existingMount->getApplicableGroups() === $mount->getApplicableGroups() && |
|
164 | - $existingMount->getApplicableUsers() == $mount->getApplicableUsers() && |
|
165 | - $existingMount->getBackendOptions() == $mount->getBackendOptions() |
|
166 | - ) { |
|
167 | - $output->writeln("<error>Duplicate mount (" . $mount->getMountPoint() . ")</error>"); |
|
168 | - return 1; |
|
169 | - } |
|
170 | - } |
|
171 | - } |
|
172 | - |
|
173 | - if ($input->getOption('dry')) { |
|
174 | - if (count($mounts) === 0) { |
|
175 | - $output->writeln('<error>No mounts to be imported</error>'); |
|
176 | - return 1; |
|
177 | - } |
|
178 | - $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager); |
|
179 | - $listInput = new ArrayInput([], $listCommand->getDefinition()); |
|
180 | - $listInput->setOption('output', $input->getOption('output')); |
|
181 | - $listInput->setOption('show-password', true); |
|
182 | - $listCommand->listMounts($user, $mounts, $listInput, $output); |
|
183 | - } else { |
|
184 | - foreach ($mounts as $mount) { |
|
185 | - $storageService->addStorage($mount); |
|
186 | - } |
|
187 | - } |
|
188 | - return 0; |
|
189 | - } |
|
190 | - |
|
191 | - private function parseData(array $data) { |
|
192 | - $mount = new StorageConfig($data['mount_id']); |
|
193 | - $mount->setMountPoint($data['mount_point']); |
|
194 | - $mount->setBackend($this->getBackendByClass($data['storage'])); |
|
195 | - $authBackend = $this->backendService->getAuthMechanism($data['authentication_type']); |
|
196 | - $mount->setAuthMechanism($authBackend); |
|
197 | - $mount->setBackendOptions($data['configuration']); |
|
198 | - $mount->setMountOptions($data['options']); |
|
199 | - $mount->setApplicableUsers(isset($data['applicable_users']) ? $data['applicable_users'] : []); |
|
200 | - $mount->setApplicableGroups(isset($data['applicable_groups']) ? $data['applicable_groups'] : []); |
|
201 | - return $mount; |
|
202 | - } |
|
203 | - |
|
204 | - private function getBackendByClass($className) { |
|
205 | - $backends = $this->backendService->getBackends(); |
|
206 | - foreach ($backends as $backend) { |
|
207 | - if ($backend->getStorageClass() === $className) { |
|
208 | - return $backend; |
|
209 | - } |
|
210 | - } |
|
211 | - } |
|
212 | - |
|
213 | - protected function getStorageService($userId) { |
|
214 | - if (!empty($userId)) { |
|
215 | - $user = $this->userManager->get($userId); |
|
216 | - if (is_null($user)) { |
|
217 | - throw new NoUserException("user $userId not found"); |
|
218 | - } |
|
219 | - $this->userSession->setUser($user); |
|
220 | - return $this->userService; |
|
221 | - } else { |
|
222 | - return $this->globalService; |
|
223 | - } |
|
224 | - } |
|
42 | + /** |
|
43 | + * @var GlobalStoragesService |
|
44 | + */ |
|
45 | + private $globalService; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var UserStoragesService |
|
49 | + */ |
|
50 | + private $userService; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var IUserSession |
|
54 | + */ |
|
55 | + private $userSession; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var IUserManager |
|
59 | + */ |
|
60 | + private $userManager; |
|
61 | + |
|
62 | + /** @var ImportLegacyStoragesService */ |
|
63 | + private $importLegacyStorageService; |
|
64 | + |
|
65 | + /** @var BackendService */ |
|
66 | + private $backendService; |
|
67 | + |
|
68 | + function __construct(GlobalStoragesService $globalService, |
|
69 | + UserStoragesService $userService, |
|
70 | + IUserSession $userSession, |
|
71 | + IUserManager $userManager, |
|
72 | + ImportLegacyStoragesService $importLegacyStorageService, |
|
73 | + BackendService $backendService |
|
74 | + ) { |
|
75 | + parent::__construct(); |
|
76 | + $this->globalService = $globalService; |
|
77 | + $this->userService = $userService; |
|
78 | + $this->userSession = $userSession; |
|
79 | + $this->userManager = $userManager; |
|
80 | + $this->importLegacyStorageService = $importLegacyStorageService; |
|
81 | + $this->backendService = $backendService; |
|
82 | + } |
|
83 | + |
|
84 | + protected function configure() { |
|
85 | + $this |
|
86 | + ->setName('files_external:import') |
|
87 | + ->setDescription('Import mount configurations') |
|
88 | + ->addOption( |
|
89 | + 'user', |
|
90 | + null, |
|
91 | + InputOption::VALUE_OPTIONAL, |
|
92 | + 'user to add the mount configurations for, if not set the mount will be added as system mount' |
|
93 | + ) |
|
94 | + ->addArgument( |
|
95 | + 'path', |
|
96 | + InputArgument::REQUIRED, |
|
97 | + 'path to a json file containing the mounts to import, use "-" to read from stdin' |
|
98 | + ) |
|
99 | + ->addOption( |
|
100 | + 'dry', |
|
101 | + null, |
|
102 | + InputOption::VALUE_NONE, |
|
103 | + 'Don\'t save the imported mounts, only list the new mounts' |
|
104 | + ); |
|
105 | + parent::configure(); |
|
106 | + } |
|
107 | + |
|
108 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
109 | + $user = $input->getOption('user'); |
|
110 | + $path = $input->getArgument('path'); |
|
111 | + if ($path === '-') { |
|
112 | + $json = file_get_contents('php://stdin'); |
|
113 | + } else { |
|
114 | + if (!file_exists($path)) { |
|
115 | + $output->writeln('<error>File not found: ' . $path . '</error>'); |
|
116 | + return 1; |
|
117 | + } |
|
118 | + $json = file_get_contents($path); |
|
119 | + } |
|
120 | + if (!is_string($json) || strlen($json) < 2) { |
|
121 | + $output->writeln('<error>Error while reading json</error>'); |
|
122 | + return 1; |
|
123 | + } |
|
124 | + $data = json_decode($json, true); |
|
125 | + if (!is_array($data)) { |
|
126 | + $output->writeln('<error>Error while parsing json</error>'); |
|
127 | + return 1; |
|
128 | + } |
|
129 | + |
|
130 | + $isLegacy = isset($data['user']) || isset($data['group']); |
|
131 | + if ($isLegacy) { |
|
132 | + $this->importLegacyStorageService->setData($data); |
|
133 | + $mounts = $this->importLegacyStorageService->getAllStorages(); |
|
134 | + foreach ($mounts as $mount) { |
|
135 | + if ($mount->getBackendOption('password') === false) { |
|
136 | + $output->writeln('<error>Failed to decrypt password</error>'); |
|
137 | + return 1; |
|
138 | + } |
|
139 | + } |
|
140 | + } else { |
|
141 | + if (!isset($data[0])) { //normalize to an array of mounts |
|
142 | + $data = [$data]; |
|
143 | + } |
|
144 | + $mounts = array_map([$this, 'parseData'], $data); |
|
145 | + } |
|
146 | + |
|
147 | + if ($user) { |
|
148 | + // ensure applicables are correct for personal mounts |
|
149 | + foreach ($mounts as $mount) { |
|
150 | + $mount->setApplicableGroups([]); |
|
151 | + $mount->setApplicableUsers([$user]); |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + $storageService = $this->getStorageService($user); |
|
156 | + |
|
157 | + $existingMounts = $storageService->getAllStorages(); |
|
158 | + |
|
159 | + foreach ($mounts as $mount) { |
|
160 | + foreach ($existingMounts as $existingMount) { |
|
161 | + if ( |
|
162 | + $existingMount->getMountPoint() === $mount->getMountPoint() && |
|
163 | + $existingMount->getApplicableGroups() === $mount->getApplicableGroups() && |
|
164 | + $existingMount->getApplicableUsers() == $mount->getApplicableUsers() && |
|
165 | + $existingMount->getBackendOptions() == $mount->getBackendOptions() |
|
166 | + ) { |
|
167 | + $output->writeln("<error>Duplicate mount (" . $mount->getMountPoint() . ")</error>"); |
|
168 | + return 1; |
|
169 | + } |
|
170 | + } |
|
171 | + } |
|
172 | + |
|
173 | + if ($input->getOption('dry')) { |
|
174 | + if (count($mounts) === 0) { |
|
175 | + $output->writeln('<error>No mounts to be imported</error>'); |
|
176 | + return 1; |
|
177 | + } |
|
178 | + $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager); |
|
179 | + $listInput = new ArrayInput([], $listCommand->getDefinition()); |
|
180 | + $listInput->setOption('output', $input->getOption('output')); |
|
181 | + $listInput->setOption('show-password', true); |
|
182 | + $listCommand->listMounts($user, $mounts, $listInput, $output); |
|
183 | + } else { |
|
184 | + foreach ($mounts as $mount) { |
|
185 | + $storageService->addStorage($mount); |
|
186 | + } |
|
187 | + } |
|
188 | + return 0; |
|
189 | + } |
|
190 | + |
|
191 | + private function parseData(array $data) { |
|
192 | + $mount = new StorageConfig($data['mount_id']); |
|
193 | + $mount->setMountPoint($data['mount_point']); |
|
194 | + $mount->setBackend($this->getBackendByClass($data['storage'])); |
|
195 | + $authBackend = $this->backendService->getAuthMechanism($data['authentication_type']); |
|
196 | + $mount->setAuthMechanism($authBackend); |
|
197 | + $mount->setBackendOptions($data['configuration']); |
|
198 | + $mount->setMountOptions($data['options']); |
|
199 | + $mount->setApplicableUsers(isset($data['applicable_users']) ? $data['applicable_users'] : []); |
|
200 | + $mount->setApplicableGroups(isset($data['applicable_groups']) ? $data['applicable_groups'] : []); |
|
201 | + return $mount; |
|
202 | + } |
|
203 | + |
|
204 | + private function getBackendByClass($className) { |
|
205 | + $backends = $this->backendService->getBackends(); |
|
206 | + foreach ($backends as $backend) { |
|
207 | + if ($backend->getStorageClass() === $className) { |
|
208 | + return $backend; |
|
209 | + } |
|
210 | + } |
|
211 | + } |
|
212 | + |
|
213 | + protected function getStorageService($userId) { |
|
214 | + if (!empty($userId)) { |
|
215 | + $user = $this->userManager->get($userId); |
|
216 | + if (is_null($user)) { |
|
217 | + throw new NoUserException("user $userId not found"); |
|
218 | + } |
|
219 | + $this->userSession->setUser($user); |
|
220 | + return $this->userService; |
|
221 | + } else { |
|
222 | + return $this->globalService; |
|
223 | + } |
|
224 | + } |
|
225 | 225 | } |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | $json = file_get_contents('php://stdin'); |
113 | 113 | } else { |
114 | 114 | if (!file_exists($path)) { |
115 | - $output->writeln('<error>File not found: ' . $path . '</error>'); |
|
115 | + $output->writeln('<error>File not found: '.$path.'</error>'); |
|
116 | 116 | return 1; |
117 | 117 | } |
118 | 118 | $json = file_get_contents($path); |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | $existingMount->getApplicableUsers() == $mount->getApplicableUsers() && |
165 | 165 | $existingMount->getBackendOptions() == $mount->getBackendOptions() |
166 | 166 | ) { |
167 | - $output->writeln("<error>Duplicate mount (" . $mount->getMountPoint() . ")</error>"); |
|
167 | + $output->writeln("<error>Duplicate mount (".$mount->getMountPoint().")</error>"); |
|
168 | 168 | return 1; |
169 | 169 | } |
170 | 170 | } |