These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * @author Joas Schilling <[email protected]> |
||
4 | * @author Robin Appelman <[email protected]> |
||
5 | * |
||
6 | * @copyright Copyright (c) 2016, ownCloud GmbH. |
||
7 | * @license AGPL-3.0 |
||
8 | * |
||
9 | * This code is free software: you can redistribute it and/or modify |
||
10 | * it under the terms of the GNU Affero General Public License, version 3, |
||
11 | * as published by the Free Software Foundation. |
||
12 | * |
||
13 | * This program is distributed in the hope that it will be useful, |
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
16 | * GNU Affero General Public License for more details. |
||
17 | * |
||
18 | * You should have received a copy of the GNU Affero General Public License, version 3, |
||
19 | * along with this program. If not, see <http://www.gnu.org/licenses/> |
||
20 | * |
||
21 | */ |
||
22 | |||
23 | namespace OCA\Files_External\Command; |
||
24 | |||
25 | use OC\Core\Command\Base; |
||
26 | use OCA\Files_External\NotFoundException; |
||
27 | use OCA\Files_External\Service\GlobalStoragesService; |
||
28 | use OCA\Files_External\Service\UserStoragesService; |
||
29 | use OCP\IUserManager; |
||
30 | use OCP\IUserSession; |
||
31 | use Symfony\Component\Console\Input\ArrayInput; |
||
32 | use Symfony\Component\Console\Input\InputArgument; |
||
33 | use Symfony\Component\Console\Input\InputInterface; |
||
34 | use Symfony\Component\Console\Input\InputOption; |
||
35 | use Symfony\Component\Console\Output\OutputInterface; |
||
36 | use Symfony\Component\Console\Question\ConfirmationQuestion; |
||
37 | |||
38 | class Delete extends Base { |
||
39 | /** |
||
40 | * @var GlobalStoragesService |
||
41 | */ |
||
42 | protected $globalService; |
||
43 | |||
44 | /** |
||
45 | * @var UserStoragesService |
||
46 | */ |
||
47 | protected $userService; |
||
48 | |||
49 | /** |
||
50 | * @var IUserSession |
||
51 | */ |
||
52 | protected $userSession; |
||
53 | |||
54 | /** |
||
55 | * @var IUserManager |
||
56 | */ |
||
57 | protected $userManager; |
||
58 | |||
59 | View Code Duplication | function __construct(GlobalStoragesService $globalService, UserStoragesService $userService, IUserSession $userSession, IUserManager $userManager) { |
|
60 | parent::__construct(); |
||
61 | $this->globalService = $globalService; |
||
62 | $this->userService = $userService; |
||
63 | $this->userSession = $userSession; |
||
64 | $this->userManager = $userManager; |
||
65 | } |
||
66 | |||
67 | protected function configure() { |
||
68 | $this |
||
69 | ->setName('files_external:delete') |
||
70 | ->setDescription('Delete an external mount') |
||
71 | ->addArgument( |
||
72 | 'mount_id', |
||
73 | InputArgument::REQUIRED, |
||
74 | 'The id of the mount to edit' |
||
75 | )->addOption( |
||
76 | 'yes', |
||
77 | 'y', |
||
78 | InputOption::VALUE_NONE, |
||
79 | 'Skip confirmation' |
||
80 | ); |
||
81 | parent::configure(); |
||
82 | } |
||
83 | |||
84 | protected function execute(InputInterface $input, OutputInterface $output) { |
||
85 | $mountId = $input->getArgument('mount_id'); |
||
86 | try { |
||
87 | $mount = $this->globalService->getStorage($mountId); |
||
88 | } catch (NotFoundException $e) { |
||
89 | $output->writeln('<error>Mount with id "' . $mountId . ' not found, check "occ files_external:list" to get available mounts"</error>'); |
||
90 | return 404; |
||
91 | } |
||
92 | |||
93 | $noConfirm = $input->getOption('yes'); |
||
94 | |||
95 | if (!$noConfirm) { |
||
96 | $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager); |
||
97 | $listInput = new ArrayInput([], $listCommand->getDefinition()); |
||
98 | $listInput->setOption('output', $input->getOption('output')); |
||
99 | $listCommand->listMounts(null, [$mount], $listInput, $output); |
||
0 ignored issues
–
show
|
|||
100 | |||
101 | $questionHelper = $this->getHelper('question'); |
||
102 | $question = new ConfirmationQuestion('Delete this mount? [y/N] ', false); |
||
103 | |||
104 | if (!$questionHelper->ask($input, $output, $question)) { |
||
105 | return; |
||
106 | } |
||
107 | } |
||
108 | |||
109 | $this->globalService->removeStorage($mountId); |
||
110 | } |
||
111 | } |
||
112 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: