@@ -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 null; |
|
107 | - } |
|
108 | - } |
|
105 | + if (!$questionHelper->ask($input, $output, $question)) { |
|
106 | + return null; |
|
107 | + } |
|
108 | + } |
|
109 | 109 | |
110 | - $this->globalService->removeStorage($mountId); |
|
111 | - } |
|
110 | + $this->globalService->removeStorage($mountId); |
|
111 | + } |
|
112 | 112 | } |
@@ -34,318 +34,318 @@ |
||
34 | 34 | |
35 | 35 | class Manager implements IManager { |
36 | 36 | |
37 | - /** @var IStorage */ |
|
38 | - protected $storage; |
|
39 | - |
|
40 | - /** @var string */ |
|
41 | - protected $path; |
|
42 | - |
|
43 | - /** @var array[] */ |
|
44 | - protected $operations = []; |
|
45 | - |
|
46 | - /** @var array[] */ |
|
47 | - protected $checks = []; |
|
48 | - |
|
49 | - /** @var IDBConnection */ |
|
50 | - protected $connection; |
|
51 | - |
|
52 | - /** @var IServerContainer|\OC\Server */ |
|
53 | - protected $container; |
|
54 | - |
|
55 | - /** @var IL10N */ |
|
56 | - protected $l; |
|
57 | - |
|
58 | - /** |
|
59 | - * @param IDBConnection $connection |
|
60 | - * @param IServerContainer $container |
|
61 | - * @param IL10N $l |
|
62 | - */ |
|
63 | - public function __construct(IDBConnection $connection, IServerContainer $container, IL10N $l) { |
|
64 | - $this->connection = $connection; |
|
65 | - $this->container = $container; |
|
66 | - $this->l = $l; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * @inheritdoc |
|
71 | - */ |
|
72 | - public function setFileInfo(IStorage $storage, $path) { |
|
73 | - $this->storage = $storage; |
|
74 | - $this->path = $path; |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * @inheritdoc |
|
79 | - */ |
|
80 | - public function getMatchingOperations($class, $returnFirstMatchingOperationOnly = true) { |
|
81 | - $operations = $this->getOperations($class); |
|
82 | - |
|
83 | - $matches = []; |
|
84 | - foreach ($operations as $operation) { |
|
85 | - $checkIds = json_decode($operation['checks'], true); |
|
86 | - $checks = $this->getChecks($checkIds); |
|
87 | - |
|
88 | - foreach ($checks as $check) { |
|
89 | - if (!$this->check($check)) { |
|
90 | - // Check did not match, continue with the next operation |
|
91 | - continue 2; |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - if ($returnFirstMatchingOperationOnly) { |
|
96 | - return $operation; |
|
97 | - } |
|
98 | - $matches[] = $operation; |
|
99 | - } |
|
100 | - |
|
101 | - return $matches; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * @param array $check |
|
106 | - * @return bool |
|
107 | - */ |
|
108 | - protected function check(array $check) { |
|
109 | - try { |
|
110 | - $checkInstance = $this->container->query($check['class']); |
|
111 | - } catch (QueryException $e) { |
|
112 | - // Check does not exist, assume it matches. |
|
113 | - return true; |
|
114 | - } |
|
115 | - |
|
116 | - if ($checkInstance instanceof ICheck) { |
|
117 | - $checkInstance->setFileInfo($this->storage, $this->path); |
|
118 | - return $checkInstance->executeCheck($check['operator'], $check['value']); |
|
119 | - } else { |
|
120 | - // Check is invalid |
|
121 | - throw new \UnexpectedValueException($this->l->t('Check %s is invalid or does not exist', $check['class'])); |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @param string $class |
|
127 | - * @return array[] |
|
128 | - */ |
|
129 | - public function getOperations($class) { |
|
130 | - if (isset($this->operations[$class])) { |
|
131 | - return $this->operations[$class]; |
|
132 | - } |
|
133 | - |
|
134 | - $query = $this->connection->getQueryBuilder(); |
|
135 | - |
|
136 | - $query->select('*') |
|
137 | - ->from('flow_operations') |
|
138 | - ->where($query->expr()->eq('class', $query->createNamedParameter($class))); |
|
139 | - $result = $query->execute(); |
|
140 | - |
|
141 | - $this->operations[$class] = []; |
|
142 | - while ($row = $result->fetch()) { |
|
143 | - $this->operations[$class][] = $row; |
|
144 | - } |
|
145 | - $result->closeCursor(); |
|
146 | - |
|
147 | - return $this->operations[$class]; |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * @param int $id |
|
152 | - * @return array |
|
153 | - * @throws \UnexpectedValueException |
|
154 | - */ |
|
155 | - protected function getOperation($id) { |
|
156 | - $query = $this->connection->getQueryBuilder(); |
|
157 | - $query->select('*') |
|
158 | - ->from('flow_operations') |
|
159 | - ->where($query->expr()->eq('id', $query->createNamedParameter($id))); |
|
160 | - $result = $query->execute(); |
|
161 | - $row = $result->fetch(); |
|
162 | - $result->closeCursor(); |
|
163 | - |
|
164 | - if ($row) { |
|
165 | - return $row; |
|
166 | - } |
|
167 | - |
|
168 | - throw new \UnexpectedValueException($this->l->t('Operation #%s does not exist', [$id])); |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * @param string $class |
|
173 | - * @param string $name |
|
174 | - * @param array[] $checks |
|
175 | - * @param string $operation |
|
176 | - * @return array The added operation |
|
177 | - * @throws \UnexpectedValueException |
|
178 | - */ |
|
179 | - public function addOperation($class, $name, array $checks, $operation) { |
|
180 | - $this->validateOperation($class, $name, $checks, $operation); |
|
181 | - |
|
182 | - $checkIds = []; |
|
183 | - foreach ($checks as $check) { |
|
184 | - $checkIds[] = $this->addCheck($check['class'], $check['operator'], $check['value']); |
|
185 | - } |
|
186 | - |
|
187 | - $query = $this->connection->getQueryBuilder(); |
|
188 | - $query->insert('flow_operations') |
|
189 | - ->values([ |
|
190 | - 'class' => $query->createNamedParameter($class), |
|
191 | - 'name' => $query->createNamedParameter($name), |
|
192 | - 'checks' => $query->createNamedParameter(json_encode(array_unique($checkIds))), |
|
193 | - 'operation' => $query->createNamedParameter($operation), |
|
194 | - ]); |
|
195 | - $query->execute(); |
|
196 | - |
|
197 | - $id = $query->getLastInsertId(); |
|
198 | - return $this->getOperation($id); |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * @param int $id |
|
203 | - * @param string $name |
|
204 | - * @param array[] $checks |
|
205 | - * @param string $operation |
|
206 | - * @return array The updated operation |
|
207 | - * @throws \UnexpectedValueException |
|
208 | - */ |
|
209 | - public function updateOperation($id, $name, array $checks, $operation) { |
|
210 | - $row = $this->getOperation($id); |
|
211 | - $this->validateOperation($row['class'], $name, $checks, $operation); |
|
212 | - |
|
213 | - $checkIds = []; |
|
214 | - foreach ($checks as $check) { |
|
215 | - $checkIds[] = $this->addCheck($check['class'], $check['operator'], $check['value']); |
|
216 | - } |
|
217 | - |
|
218 | - $query = $this->connection->getQueryBuilder(); |
|
219 | - $query->update('flow_operations') |
|
220 | - ->set('name', $query->createNamedParameter($name)) |
|
221 | - ->set('checks', $query->createNamedParameter(json_encode(array_unique($checkIds)))) |
|
222 | - ->set('operation', $query->createNamedParameter($operation)) |
|
223 | - ->where($query->expr()->eq('id', $query->createNamedParameter($id))); |
|
224 | - $query->execute(); |
|
225 | - |
|
226 | - return $this->getOperation($id); |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * @param int $id |
|
231 | - * @return bool |
|
232 | - * @throws \UnexpectedValueException |
|
233 | - */ |
|
234 | - public function deleteOperation($id) { |
|
235 | - $query = $this->connection->getQueryBuilder(); |
|
236 | - $query->delete('flow_operations') |
|
237 | - ->where($query->expr()->eq('id', $query->createNamedParameter($id))); |
|
238 | - return (bool) $query->execute(); |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * @param string $class |
|
243 | - * @param string $name |
|
244 | - * @param array[] $checks |
|
245 | - * @param string $operation |
|
246 | - * @throws \UnexpectedValueException |
|
247 | - */ |
|
248 | - protected function validateOperation($class, $name, array $checks, $operation) { |
|
249 | - try { |
|
250 | - /** @var IOperation $instance */ |
|
251 | - $instance = $this->container->query($class); |
|
252 | - } catch (QueryException $e) { |
|
253 | - throw new \UnexpectedValueException($this->l->t('Operation %s does not exist', [$class])); |
|
254 | - } |
|
255 | - |
|
256 | - if (!($instance instanceof IOperation)) { |
|
257 | - throw new \UnexpectedValueException($this->l->t('Operation %s is invalid', [$class])); |
|
258 | - } |
|
259 | - |
|
260 | - $instance->validateOperation($name, $checks, $operation); |
|
261 | - |
|
262 | - foreach ($checks as $check) { |
|
263 | - try { |
|
264 | - /** @var ICheck $instance */ |
|
265 | - $instance = $this->container->query($check['class']); |
|
266 | - } catch (QueryException $e) { |
|
267 | - throw new \UnexpectedValueException($this->l->t('Check %s does not exist', [$class])); |
|
268 | - } |
|
269 | - |
|
270 | - if (!($instance instanceof ICheck)) { |
|
271 | - throw new \UnexpectedValueException($this->l->t('Check %s is invalid', [$class])); |
|
272 | - } |
|
273 | - |
|
274 | - $instance->validateCheck($check['operator'], $check['value']); |
|
275 | - } |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * @param int[] $checkIds |
|
280 | - * @return array[] |
|
281 | - */ |
|
282 | - public function getChecks(array $checkIds) { |
|
283 | - $checkIds = array_map('intval', $checkIds); |
|
284 | - |
|
285 | - $checks = []; |
|
286 | - foreach ($checkIds as $i => $checkId) { |
|
287 | - if (isset($this->checks[$checkId])) { |
|
288 | - $checks[$checkId] = $this->checks[$checkId]; |
|
289 | - unset($checkIds[$i]); |
|
290 | - } |
|
291 | - } |
|
292 | - |
|
293 | - if (empty($checkIds)) { |
|
294 | - return $checks; |
|
295 | - } |
|
296 | - |
|
297 | - $query = $this->connection->getQueryBuilder(); |
|
298 | - $query->select('*') |
|
299 | - ->from('flow_checks') |
|
300 | - ->where($query->expr()->in('id', $query->createNamedParameter($checkIds, IQueryBuilder::PARAM_INT_ARRAY))); |
|
301 | - $result = $query->execute(); |
|
302 | - |
|
303 | - while ($row = $result->fetch()) { |
|
304 | - $this->checks[(int) $row['id']] = $row; |
|
305 | - $checks[(int) $row['id']] = $row; |
|
306 | - } |
|
307 | - $result->closeCursor(); |
|
308 | - |
|
309 | - $checkIds = array_diff($checkIds, array_keys($checks)); |
|
310 | - |
|
311 | - if (!empty($checkIds)) { |
|
312 | - $missingCheck = array_pop($checkIds); |
|
313 | - throw new \UnexpectedValueException($this->l->t('Check #%s does not exist', $missingCheck)); |
|
314 | - } |
|
315 | - |
|
316 | - return $checks; |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * @param string $class |
|
321 | - * @param string $operator |
|
322 | - * @param string $value |
|
323 | - * @return int Check unique ID |
|
324 | - */ |
|
325 | - protected function addCheck($class, $operator, $value) { |
|
326 | - $hash = md5($class . '::' . $operator . '::' . $value); |
|
327 | - |
|
328 | - $query = $this->connection->getQueryBuilder(); |
|
329 | - $query->select('id') |
|
330 | - ->from('flow_checks') |
|
331 | - ->where($query->expr()->eq('hash', $query->createNamedParameter($hash))); |
|
332 | - $result = $query->execute(); |
|
333 | - |
|
334 | - if ($row = $result->fetch()) { |
|
335 | - $result->closeCursor(); |
|
336 | - return (int) $row['id']; |
|
337 | - } |
|
338 | - |
|
339 | - $query = $this->connection->getQueryBuilder(); |
|
340 | - $query->insert('flow_checks') |
|
341 | - ->values([ |
|
342 | - 'class' => $query->createNamedParameter($class), |
|
343 | - 'operator' => $query->createNamedParameter($operator), |
|
344 | - 'value' => $query->createNamedParameter($value), |
|
345 | - 'hash' => $query->createNamedParameter($hash), |
|
346 | - ]); |
|
347 | - $query->execute(); |
|
348 | - |
|
349 | - return $query->getLastInsertId(); |
|
350 | - } |
|
37 | + /** @var IStorage */ |
|
38 | + protected $storage; |
|
39 | + |
|
40 | + /** @var string */ |
|
41 | + protected $path; |
|
42 | + |
|
43 | + /** @var array[] */ |
|
44 | + protected $operations = []; |
|
45 | + |
|
46 | + /** @var array[] */ |
|
47 | + protected $checks = []; |
|
48 | + |
|
49 | + /** @var IDBConnection */ |
|
50 | + protected $connection; |
|
51 | + |
|
52 | + /** @var IServerContainer|\OC\Server */ |
|
53 | + protected $container; |
|
54 | + |
|
55 | + /** @var IL10N */ |
|
56 | + protected $l; |
|
57 | + |
|
58 | + /** |
|
59 | + * @param IDBConnection $connection |
|
60 | + * @param IServerContainer $container |
|
61 | + * @param IL10N $l |
|
62 | + */ |
|
63 | + public function __construct(IDBConnection $connection, IServerContainer $container, IL10N $l) { |
|
64 | + $this->connection = $connection; |
|
65 | + $this->container = $container; |
|
66 | + $this->l = $l; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * @inheritdoc |
|
71 | + */ |
|
72 | + public function setFileInfo(IStorage $storage, $path) { |
|
73 | + $this->storage = $storage; |
|
74 | + $this->path = $path; |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * @inheritdoc |
|
79 | + */ |
|
80 | + public function getMatchingOperations($class, $returnFirstMatchingOperationOnly = true) { |
|
81 | + $operations = $this->getOperations($class); |
|
82 | + |
|
83 | + $matches = []; |
|
84 | + foreach ($operations as $operation) { |
|
85 | + $checkIds = json_decode($operation['checks'], true); |
|
86 | + $checks = $this->getChecks($checkIds); |
|
87 | + |
|
88 | + foreach ($checks as $check) { |
|
89 | + if (!$this->check($check)) { |
|
90 | + // Check did not match, continue with the next operation |
|
91 | + continue 2; |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + if ($returnFirstMatchingOperationOnly) { |
|
96 | + return $operation; |
|
97 | + } |
|
98 | + $matches[] = $operation; |
|
99 | + } |
|
100 | + |
|
101 | + return $matches; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * @param array $check |
|
106 | + * @return bool |
|
107 | + */ |
|
108 | + protected function check(array $check) { |
|
109 | + try { |
|
110 | + $checkInstance = $this->container->query($check['class']); |
|
111 | + } catch (QueryException $e) { |
|
112 | + // Check does not exist, assume it matches. |
|
113 | + return true; |
|
114 | + } |
|
115 | + |
|
116 | + if ($checkInstance instanceof ICheck) { |
|
117 | + $checkInstance->setFileInfo($this->storage, $this->path); |
|
118 | + return $checkInstance->executeCheck($check['operator'], $check['value']); |
|
119 | + } else { |
|
120 | + // Check is invalid |
|
121 | + throw new \UnexpectedValueException($this->l->t('Check %s is invalid or does not exist', $check['class'])); |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @param string $class |
|
127 | + * @return array[] |
|
128 | + */ |
|
129 | + public function getOperations($class) { |
|
130 | + if (isset($this->operations[$class])) { |
|
131 | + return $this->operations[$class]; |
|
132 | + } |
|
133 | + |
|
134 | + $query = $this->connection->getQueryBuilder(); |
|
135 | + |
|
136 | + $query->select('*') |
|
137 | + ->from('flow_operations') |
|
138 | + ->where($query->expr()->eq('class', $query->createNamedParameter($class))); |
|
139 | + $result = $query->execute(); |
|
140 | + |
|
141 | + $this->operations[$class] = []; |
|
142 | + while ($row = $result->fetch()) { |
|
143 | + $this->operations[$class][] = $row; |
|
144 | + } |
|
145 | + $result->closeCursor(); |
|
146 | + |
|
147 | + return $this->operations[$class]; |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * @param int $id |
|
152 | + * @return array |
|
153 | + * @throws \UnexpectedValueException |
|
154 | + */ |
|
155 | + protected function getOperation($id) { |
|
156 | + $query = $this->connection->getQueryBuilder(); |
|
157 | + $query->select('*') |
|
158 | + ->from('flow_operations') |
|
159 | + ->where($query->expr()->eq('id', $query->createNamedParameter($id))); |
|
160 | + $result = $query->execute(); |
|
161 | + $row = $result->fetch(); |
|
162 | + $result->closeCursor(); |
|
163 | + |
|
164 | + if ($row) { |
|
165 | + return $row; |
|
166 | + } |
|
167 | + |
|
168 | + throw new \UnexpectedValueException($this->l->t('Operation #%s does not exist', [$id])); |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * @param string $class |
|
173 | + * @param string $name |
|
174 | + * @param array[] $checks |
|
175 | + * @param string $operation |
|
176 | + * @return array The added operation |
|
177 | + * @throws \UnexpectedValueException |
|
178 | + */ |
|
179 | + public function addOperation($class, $name, array $checks, $operation) { |
|
180 | + $this->validateOperation($class, $name, $checks, $operation); |
|
181 | + |
|
182 | + $checkIds = []; |
|
183 | + foreach ($checks as $check) { |
|
184 | + $checkIds[] = $this->addCheck($check['class'], $check['operator'], $check['value']); |
|
185 | + } |
|
186 | + |
|
187 | + $query = $this->connection->getQueryBuilder(); |
|
188 | + $query->insert('flow_operations') |
|
189 | + ->values([ |
|
190 | + 'class' => $query->createNamedParameter($class), |
|
191 | + 'name' => $query->createNamedParameter($name), |
|
192 | + 'checks' => $query->createNamedParameter(json_encode(array_unique($checkIds))), |
|
193 | + 'operation' => $query->createNamedParameter($operation), |
|
194 | + ]); |
|
195 | + $query->execute(); |
|
196 | + |
|
197 | + $id = $query->getLastInsertId(); |
|
198 | + return $this->getOperation($id); |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * @param int $id |
|
203 | + * @param string $name |
|
204 | + * @param array[] $checks |
|
205 | + * @param string $operation |
|
206 | + * @return array The updated operation |
|
207 | + * @throws \UnexpectedValueException |
|
208 | + */ |
|
209 | + public function updateOperation($id, $name, array $checks, $operation) { |
|
210 | + $row = $this->getOperation($id); |
|
211 | + $this->validateOperation($row['class'], $name, $checks, $operation); |
|
212 | + |
|
213 | + $checkIds = []; |
|
214 | + foreach ($checks as $check) { |
|
215 | + $checkIds[] = $this->addCheck($check['class'], $check['operator'], $check['value']); |
|
216 | + } |
|
217 | + |
|
218 | + $query = $this->connection->getQueryBuilder(); |
|
219 | + $query->update('flow_operations') |
|
220 | + ->set('name', $query->createNamedParameter($name)) |
|
221 | + ->set('checks', $query->createNamedParameter(json_encode(array_unique($checkIds)))) |
|
222 | + ->set('operation', $query->createNamedParameter($operation)) |
|
223 | + ->where($query->expr()->eq('id', $query->createNamedParameter($id))); |
|
224 | + $query->execute(); |
|
225 | + |
|
226 | + return $this->getOperation($id); |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * @param int $id |
|
231 | + * @return bool |
|
232 | + * @throws \UnexpectedValueException |
|
233 | + */ |
|
234 | + public function deleteOperation($id) { |
|
235 | + $query = $this->connection->getQueryBuilder(); |
|
236 | + $query->delete('flow_operations') |
|
237 | + ->where($query->expr()->eq('id', $query->createNamedParameter($id))); |
|
238 | + return (bool) $query->execute(); |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * @param string $class |
|
243 | + * @param string $name |
|
244 | + * @param array[] $checks |
|
245 | + * @param string $operation |
|
246 | + * @throws \UnexpectedValueException |
|
247 | + */ |
|
248 | + protected function validateOperation($class, $name, array $checks, $operation) { |
|
249 | + try { |
|
250 | + /** @var IOperation $instance */ |
|
251 | + $instance = $this->container->query($class); |
|
252 | + } catch (QueryException $e) { |
|
253 | + throw new \UnexpectedValueException($this->l->t('Operation %s does not exist', [$class])); |
|
254 | + } |
|
255 | + |
|
256 | + if (!($instance instanceof IOperation)) { |
|
257 | + throw new \UnexpectedValueException($this->l->t('Operation %s is invalid', [$class])); |
|
258 | + } |
|
259 | + |
|
260 | + $instance->validateOperation($name, $checks, $operation); |
|
261 | + |
|
262 | + foreach ($checks as $check) { |
|
263 | + try { |
|
264 | + /** @var ICheck $instance */ |
|
265 | + $instance = $this->container->query($check['class']); |
|
266 | + } catch (QueryException $e) { |
|
267 | + throw new \UnexpectedValueException($this->l->t('Check %s does not exist', [$class])); |
|
268 | + } |
|
269 | + |
|
270 | + if (!($instance instanceof ICheck)) { |
|
271 | + throw new \UnexpectedValueException($this->l->t('Check %s is invalid', [$class])); |
|
272 | + } |
|
273 | + |
|
274 | + $instance->validateCheck($check['operator'], $check['value']); |
|
275 | + } |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * @param int[] $checkIds |
|
280 | + * @return array[] |
|
281 | + */ |
|
282 | + public function getChecks(array $checkIds) { |
|
283 | + $checkIds = array_map('intval', $checkIds); |
|
284 | + |
|
285 | + $checks = []; |
|
286 | + foreach ($checkIds as $i => $checkId) { |
|
287 | + if (isset($this->checks[$checkId])) { |
|
288 | + $checks[$checkId] = $this->checks[$checkId]; |
|
289 | + unset($checkIds[$i]); |
|
290 | + } |
|
291 | + } |
|
292 | + |
|
293 | + if (empty($checkIds)) { |
|
294 | + return $checks; |
|
295 | + } |
|
296 | + |
|
297 | + $query = $this->connection->getQueryBuilder(); |
|
298 | + $query->select('*') |
|
299 | + ->from('flow_checks') |
|
300 | + ->where($query->expr()->in('id', $query->createNamedParameter($checkIds, IQueryBuilder::PARAM_INT_ARRAY))); |
|
301 | + $result = $query->execute(); |
|
302 | + |
|
303 | + while ($row = $result->fetch()) { |
|
304 | + $this->checks[(int) $row['id']] = $row; |
|
305 | + $checks[(int) $row['id']] = $row; |
|
306 | + } |
|
307 | + $result->closeCursor(); |
|
308 | + |
|
309 | + $checkIds = array_diff($checkIds, array_keys($checks)); |
|
310 | + |
|
311 | + if (!empty($checkIds)) { |
|
312 | + $missingCheck = array_pop($checkIds); |
|
313 | + throw new \UnexpectedValueException($this->l->t('Check #%s does not exist', $missingCheck)); |
|
314 | + } |
|
315 | + |
|
316 | + return $checks; |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * @param string $class |
|
321 | + * @param string $operator |
|
322 | + * @param string $value |
|
323 | + * @return int Check unique ID |
|
324 | + */ |
|
325 | + protected function addCheck($class, $operator, $value) { |
|
326 | + $hash = md5($class . '::' . $operator . '::' . $value); |
|
327 | + |
|
328 | + $query = $this->connection->getQueryBuilder(); |
|
329 | + $query->select('id') |
|
330 | + ->from('flow_checks') |
|
331 | + ->where($query->expr()->eq('hash', $query->createNamedParameter($hash))); |
|
332 | + $result = $query->execute(); |
|
333 | + |
|
334 | + if ($row = $result->fetch()) { |
|
335 | + $result->closeCursor(); |
|
336 | + return (int) $row['id']; |
|
337 | + } |
|
338 | + |
|
339 | + $query = $this->connection->getQueryBuilder(); |
|
340 | + $query->insert('flow_checks') |
|
341 | + ->values([ |
|
342 | + 'class' => $query->createNamedParameter($class), |
|
343 | + 'operator' => $query->createNamedParameter($operator), |
|
344 | + 'value' => $query->createNamedParameter($value), |
|
345 | + 'hash' => $query->createNamedParameter($hash), |
|
346 | + ]); |
|
347 | + $query->execute(); |
|
348 | + |
|
349 | + return $query->getLastInsertId(); |
|
350 | + } |
|
351 | 351 | } |
@@ -21,62 +21,62 @@ |
||
21 | 21 | */ |
22 | 22 | |
23 | 23 | return [ |
24 | - 'routes' => [ |
|
25 | - [ |
|
26 | - 'name' => 'RateLimitTest#userAndAnonProtected', |
|
27 | - 'url' => '/userAndAnonProtected', |
|
28 | - 'verb' => 'GET', |
|
29 | - ], |
|
30 | - [ |
|
31 | - 'name' => 'RateLimitTest#onlyAnonProtected', |
|
32 | - 'url' => '/anonProtected', |
|
33 | - 'verb' => 'GET', |
|
34 | - ], |
|
35 | - ], |
|
24 | + 'routes' => [ |
|
25 | + [ |
|
26 | + 'name' => 'RateLimitTest#userAndAnonProtected', |
|
27 | + 'url' => '/userAndAnonProtected', |
|
28 | + 'verb' => 'GET', |
|
29 | + ], |
|
30 | + [ |
|
31 | + 'name' => 'RateLimitTest#onlyAnonProtected', |
|
32 | + 'url' => '/anonProtected', |
|
33 | + 'verb' => 'GET', |
|
34 | + ], |
|
35 | + ], |
|
36 | 36 | |
37 | - 'ocs' => [ |
|
38 | - [ |
|
39 | - 'name' => 'Config#setAppValue', |
|
40 | - 'url' => '/api/v1/app/{appid}/{configkey}', |
|
41 | - 'verb' => 'POST', |
|
42 | - ], |
|
43 | - [ |
|
44 | - 'name' => 'Config#deleteAppValue', |
|
45 | - 'url' => '/api/v1/app/{appid}/{configkey}', |
|
46 | - 'verb' => 'DELETE', |
|
47 | - ], |
|
48 | - [ |
|
49 | - 'name' => 'Locking#isLockingEnabled', |
|
50 | - 'url' => '/api/v1/lockprovisioning', |
|
51 | - 'verb' => 'GET', |
|
52 | - ], |
|
53 | - [ |
|
54 | - 'name' => 'Locking#isLocked', |
|
55 | - 'url' => '/api/v1/lockprovisioning/{type}/{user}', |
|
56 | - 'verb' => 'GET', |
|
57 | - ], |
|
58 | - [ |
|
59 | - 'name' => 'Locking#acquireLock', |
|
60 | - 'url' => '/api/v1/lockprovisioning/{type}/{user}', |
|
61 | - 'verb' => 'POST', |
|
62 | - ], |
|
63 | - [ |
|
64 | - 'name' => 'Locking#changeLock', |
|
65 | - 'url' => '/api/v1/lockprovisioning/{type}/{user}', |
|
66 | - 'verb' => 'PUT', |
|
67 | - ], |
|
68 | - [ |
|
69 | - 'name' => 'Locking#releaseLock', |
|
70 | - 'url' => '/api/v1/lockprovisioning/{type}/{user}', |
|
71 | - 'verb' => 'DELETE', |
|
72 | - ], |
|
73 | - [ |
|
74 | - 'name' => 'Locking#releaseAll', |
|
75 | - 'url' => '/api/v1/lockprovisioning/{type}', |
|
76 | - 'verb' => 'DELETE', |
|
77 | - 'defaults' => [ |
|
78 | - 'type' => null |
|
79 | - ] |
|
80 | - ], |
|
81 | - ], |
|
37 | + 'ocs' => [ |
|
38 | + [ |
|
39 | + 'name' => 'Config#setAppValue', |
|
40 | + 'url' => '/api/v1/app/{appid}/{configkey}', |
|
41 | + 'verb' => 'POST', |
|
42 | + ], |
|
43 | + [ |
|
44 | + 'name' => 'Config#deleteAppValue', |
|
45 | + 'url' => '/api/v1/app/{appid}/{configkey}', |
|
46 | + 'verb' => 'DELETE', |
|
47 | + ], |
|
48 | + [ |
|
49 | + 'name' => 'Locking#isLockingEnabled', |
|
50 | + 'url' => '/api/v1/lockprovisioning', |
|
51 | + 'verb' => 'GET', |
|
52 | + ], |
|
53 | + [ |
|
54 | + 'name' => 'Locking#isLocked', |
|
55 | + 'url' => '/api/v1/lockprovisioning/{type}/{user}', |
|
56 | + 'verb' => 'GET', |
|
57 | + ], |
|
58 | + [ |
|
59 | + 'name' => 'Locking#acquireLock', |
|
60 | + 'url' => '/api/v1/lockprovisioning/{type}/{user}', |
|
61 | + 'verb' => 'POST', |
|
62 | + ], |
|
63 | + [ |
|
64 | + 'name' => 'Locking#changeLock', |
|
65 | + 'url' => '/api/v1/lockprovisioning/{type}/{user}', |
|
66 | + 'verb' => 'PUT', |
|
67 | + ], |
|
68 | + [ |
|
69 | + 'name' => 'Locking#releaseLock', |
|
70 | + 'url' => '/api/v1/lockprovisioning/{type}/{user}', |
|
71 | + 'verb' => 'DELETE', |
|
72 | + ], |
|
73 | + [ |
|
74 | + 'name' => 'Locking#releaseAll', |
|
75 | + 'url' => '/api/v1/lockprovisioning/{type}', |
|
76 | + 'verb' => 'DELETE', |
|
77 | + 'defaults' => [ |
|
78 | + 'type' => null |
|
79 | + ] |
|
80 | + ], |
|
81 | + ], |
|
82 | 82 | ]; |
@@ -32,14 +32,14 @@ |
||
32 | 32 | * @since 9.1.0 |
33 | 33 | */ |
34 | 34 | class OCSNotFoundException extends OCSException { |
35 | - /** |
|
36 | - * OCSNotFoundException constructor. |
|
37 | - * |
|
38 | - * @param string $message |
|
39 | - * @param Exception|null $previous |
|
40 | - * @since 9.1.0 |
|
41 | - */ |
|
42 | - public function __construct($message = '', Exception $previous = null) { |
|
43 | - parent::__construct($message, Http::STATUS_NOT_FOUND, $previous); |
|
44 | - } |
|
35 | + /** |
|
36 | + * OCSNotFoundException constructor. |
|
37 | + * |
|
38 | + * @param string $message |
|
39 | + * @param Exception|null $previous |
|
40 | + * @since 9.1.0 |
|
41 | + */ |
|
42 | + public function __construct($message = '', Exception $previous = null) { |
|
43 | + parent::__construct($message, Http::STATUS_NOT_FOUND, $previous); |
|
44 | + } |
|
45 | 45 | } |
@@ -32,14 +32,14 @@ |
||
32 | 32 | * @since 9.1.0 |
33 | 33 | */ |
34 | 34 | class OCSForbiddenException extends OCSException { |
35 | - /** |
|
36 | - * OCSForbiddenException constructor. |
|
37 | - * |
|
38 | - * @param string $message |
|
39 | - * @param Exception|null $previous |
|
40 | - * @since 9.1.0 |
|
41 | - */ |
|
42 | - public function __construct($message = '', Exception $previous = null) { |
|
43 | - parent::__construct($message, Http::STATUS_FORBIDDEN, $previous); |
|
44 | - } |
|
35 | + /** |
|
36 | + * OCSForbiddenException constructor. |
|
37 | + * |
|
38 | + * @param string $message |
|
39 | + * @param Exception|null $previous |
|
40 | + * @since 9.1.0 |
|
41 | + */ |
|
42 | + public function __construct($message = '', Exception $previous = null) { |
|
43 | + parent::__construct($message, Http::STATUS_FORBIDDEN, $previous); |
|
44 | + } |
|
45 | 45 | } |
@@ -32,14 +32,14 @@ |
||
32 | 32 | * @since 9.1.0 |
33 | 33 | */ |
34 | 34 | class OCSBadRequestException extends OCSException { |
35 | - /** |
|
36 | - * OCSBadRequestException constructor. |
|
37 | - * |
|
38 | - * @param string $message |
|
39 | - * @param Exception|null $previous |
|
40 | - * @since 9.1.0 |
|
41 | - */ |
|
42 | - public function __construct($message = '', Exception $previous = null) { |
|
43 | - parent::__construct($message, Http::STATUS_BAD_REQUEST, $previous); |
|
44 | - } |
|
35 | + /** |
|
36 | + * OCSBadRequestException constructor. |
|
37 | + * |
|
38 | + * @param string $message |
|
39 | + * @param Exception|null $previous |
|
40 | + * @since 9.1.0 |
|
41 | + */ |
|
42 | + public function __construct($message = '', Exception $previous = null) { |
|
43 | + parent::__construct($message, Http::STATUS_BAD_REQUEST, $previous); |
|
44 | + } |
|
45 | 45 | } |
@@ -31,33 +31,33 @@ |
||
31 | 31 | |
32 | 32 | class EMailProvider implements IProvider { |
33 | 33 | |
34 | - /** @var IActionFactory */ |
|
35 | - private $actionFactory; |
|
36 | - |
|
37 | - /** @var IURLGenerator */ |
|
38 | - private $urlGenerator; |
|
39 | - |
|
40 | - /** |
|
41 | - * @param IActionFactory $actionFactory |
|
42 | - * @param IURLGenerator $urlGenerator |
|
43 | - */ |
|
44 | - public function __construct(IActionFactory $actionFactory, IURLGenerator $urlGenerator) { |
|
45 | - $this->actionFactory = $actionFactory; |
|
46 | - $this->urlGenerator = $urlGenerator; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * @param IEntry $entry |
|
51 | - */ |
|
52 | - public function process(IEntry $entry) { |
|
53 | - $iconUrl = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/mail.svg')); |
|
54 | - foreach ($entry->getEMailAddresses() as $address) { |
|
55 | - if (empty($address)) { |
|
56 | - // Skip |
|
57 | - continue; |
|
58 | - } |
|
59 | - $action = $this->actionFactory->newEMailAction($iconUrl, $address, $address); |
|
60 | - $entry->addAction($action); |
|
61 | - } |
|
62 | - } |
|
34 | + /** @var IActionFactory */ |
|
35 | + private $actionFactory; |
|
36 | + |
|
37 | + /** @var IURLGenerator */ |
|
38 | + private $urlGenerator; |
|
39 | + |
|
40 | + /** |
|
41 | + * @param IActionFactory $actionFactory |
|
42 | + * @param IURLGenerator $urlGenerator |
|
43 | + */ |
|
44 | + public function __construct(IActionFactory $actionFactory, IURLGenerator $urlGenerator) { |
|
45 | + $this->actionFactory = $actionFactory; |
|
46 | + $this->urlGenerator = $urlGenerator; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * @param IEntry $entry |
|
51 | + */ |
|
52 | + public function process(IEntry $entry) { |
|
53 | + $iconUrl = $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/mail.svg')); |
|
54 | + foreach ($entry->getEMailAddresses() as $address) { |
|
55 | + if (empty($address)) { |
|
56 | + // Skip |
|
57 | + continue; |
|
58 | + } |
|
59 | + $action = $this->actionFactory->newEMailAction($iconUrl, $address, $address); |
|
60 | + $entry->addAction($action); |
|
61 | + } |
|
62 | + } |
|
63 | 63 | } |
@@ -32,7 +32,7 @@ |
||
32 | 32 | * @package OC\AppFramework\Middleware\Security\Exceptions |
33 | 33 | */ |
34 | 34 | class StrictCookieMissingException extends SecurityException { |
35 | - public function __construct() { |
|
36 | - parent::__construct('Strict Cookie has not been found in request.', Http::STATUS_PRECONDITION_FAILED); |
|
37 | - } |
|
35 | + public function __construct() { |
|
36 | + parent::__construct('Strict Cookie has not been found in request.', Http::STATUS_PRECONDITION_FAILED); |
|
37 | + } |
|
38 | 38 | } |
@@ -29,40 +29,40 @@ |
||
29 | 29 | |
30 | 30 | class FedAuth extends AbstractBasic { |
31 | 31 | |
32 | - /** @var DbHandler */ |
|
33 | - private $db; |
|
32 | + /** @var DbHandler */ |
|
33 | + private $db; |
|
34 | 34 | |
35 | - /** |
|
36 | - * FedAuth constructor. |
|
37 | - * |
|
38 | - * @param DbHandler $db |
|
39 | - */ |
|
40 | - public function __construct(DbHandler $db) { |
|
41 | - $this->db = $db; |
|
42 | - $this->principalPrefix = 'principals/system/'; |
|
35 | + /** |
|
36 | + * FedAuth constructor. |
|
37 | + * |
|
38 | + * @param DbHandler $db |
|
39 | + */ |
|
40 | + public function __construct(DbHandler $db) { |
|
41 | + $this->db = $db; |
|
42 | + $this->principalPrefix = 'principals/system/'; |
|
43 | 43 | |
44 | - // setup realm |
|
45 | - $defaults = new \OCP\Defaults(); |
|
46 | - $this->realm = $defaults->getName(); |
|
47 | - } |
|
44 | + // setup realm |
|
45 | + $defaults = new \OCP\Defaults(); |
|
46 | + $this->realm = $defaults->getName(); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Validates a username and password |
|
51 | - * |
|
52 | - * This method should return true or false depending on if login |
|
53 | - * succeeded. |
|
54 | - * |
|
55 | - * @param string $username |
|
56 | - * @param string $password |
|
57 | - * @return bool |
|
58 | - */ |
|
59 | - protected function validateUserPass($username, $password) { |
|
60 | - return $this->db->auth($username, $password); |
|
61 | - } |
|
49 | + /** |
|
50 | + * Validates a username and password |
|
51 | + * |
|
52 | + * This method should return true or false depending on if login |
|
53 | + * succeeded. |
|
54 | + * |
|
55 | + * @param string $username |
|
56 | + * @param string $password |
|
57 | + * @return bool |
|
58 | + */ |
|
59 | + protected function validateUserPass($username, $password) { |
|
60 | + return $this->db->auth($username, $password); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @inheritdoc |
|
65 | - */ |
|
66 | - public function challenge(RequestInterface $request, ResponseInterface $response) { |
|
67 | - } |
|
63 | + /** |
|
64 | + * @inheritdoc |
|
65 | + */ |
|
66 | + public function challenge(RequestInterface $request, ResponseInterface $response) { |
|
67 | + } |
|
68 | 68 | } |