1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Circles - Bring cloud-users closer together. |
8
|
|
|
* |
9
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
10
|
|
|
* later. See the COPYING file. |
11
|
|
|
* |
12
|
|
|
* @author Maxence Lange <[email protected]> |
13
|
|
|
* @copyright 2017 |
14
|
|
|
* @license GNU AGPL version 3 or any later version |
15
|
|
|
* |
16
|
|
|
* This program is free software: you can redistribute it and/or modify |
17
|
|
|
* it under the terms of the GNU Affero General Public License as |
18
|
|
|
* published by the Free Software Foundation, either version 3 of the |
19
|
|
|
* License, or (at your option) any later version. |
20
|
|
|
* |
21
|
|
|
* This program is distributed in the hope that it will be useful, |
22
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
23
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24
|
|
|
* GNU Affero General Public License for more details. |
25
|
|
|
* |
26
|
|
|
* You should have received a copy of the GNU Affero General Public License |
27
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
28
|
|
|
* |
29
|
|
|
*/ |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
namespace OCA\Circles\Command; |
33
|
|
|
|
34
|
|
|
use daita\MySmallPhpTools\Exceptions\InvalidItemException; |
35
|
|
|
use OC\Core\Command\Base; |
36
|
|
|
use OCA\Circles\Exceptions\CircleNotFoundException; |
37
|
|
|
use OCA\Circles\Exceptions\FederatedItemException; |
38
|
|
|
use OCA\Circles\Exceptions\FederatedUserException; |
39
|
|
|
use OCA\Circles\Exceptions\FederatedUserNotFoundException; |
40
|
|
|
use OCA\Circles\Exceptions\InitiatorNotFoundException; |
41
|
|
|
use OCA\Circles\Exceptions\InvalidIdException; |
42
|
|
|
use OCA\Circles\Exceptions\MemberNotFoundException; |
43
|
|
|
use OCA\Circles\Exceptions\OwnerNotFoundException; |
44
|
|
|
use OCA\Circles\Exceptions\RemoteInstanceException; |
45
|
|
|
use OCA\Circles\Exceptions\RemoteNotFoundException; |
46
|
|
|
use OCA\Circles\Exceptions\RemoteResourceNotFoundException; |
47
|
|
|
use OCA\Circles\Exceptions\RequestBuilderException; |
48
|
|
|
use OCA\Circles\Exceptions\SingleCircleNotFoundException; |
49
|
|
|
use OCA\Circles\Exceptions\UnknownRemoteException; |
50
|
|
|
use OCA\Circles\Exceptions\UserTypeNotFoundException; |
51
|
|
|
use OCA\Circles\Model\Member; |
52
|
|
|
use OCA\Circles\Service\CircleService; |
53
|
|
|
use OCA\Circles\Service\ConfigService; |
54
|
|
|
use OCA\Circles\Service\FederatedUserService; |
55
|
|
|
use OCA\Circles\Service\MemberService; |
56
|
|
|
use OCA\Circles\Service\RemoteService; |
57
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
58
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
59
|
|
|
use Symfony\Component\Console\Input\InputOption; |
60
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Class CirclesDetails |
65
|
|
|
* |
66
|
|
|
* @package OCA\Circles\Command |
67
|
|
|
*/ |
68
|
|
|
class CirclesDetails extends Base { |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
/** @var FederatedUserService */ |
72
|
|
|
private $federatedUserService; |
73
|
|
|
|
74
|
|
|
/** @var RemoteService */ |
75
|
|
|
private $remoteService; |
76
|
|
|
|
77
|
|
|
/** @var MemberService */ |
78
|
|
|
private $memberService; |
79
|
|
|
|
80
|
|
|
/** @var CircleService */ |
81
|
|
|
private $circleService; |
82
|
|
|
|
83
|
|
|
/** @var ConfigService */ |
84
|
|
|
private $configService; |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* CirclesDetails constructor. |
89
|
|
|
* |
90
|
|
|
* @param FederatedUserService $federatedUserService |
91
|
|
|
* @param RemoteService $remoteService |
92
|
|
|
* @param CircleService $circlesService |
93
|
|
|
* @param MemberService $membersService |
94
|
|
|
* @param ConfigService $configService |
95
|
|
|
*/ |
96
|
|
View Code Duplication |
public function __construct( |
|
|
|
|
97
|
|
|
FederatedUserService $federatedUserService, RemoteService $remoteService, |
98
|
|
|
CircleService $circlesService, MemberService $membersService, ConfigService $configService |
99
|
|
|
) { |
100
|
|
|
parent::__construct(); |
101
|
|
|
$this->federatedUserService = $federatedUserService; |
102
|
|
|
$this->remoteService = $remoteService; |
103
|
|
|
$this->circleService = $circlesService; |
104
|
|
|
$this->memberService = $membersService; |
105
|
|
|
$this->configService = $configService; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* |
111
|
|
|
*/ |
112
|
|
|
protected function configure() { |
113
|
|
|
parent::configure(); |
114
|
|
|
$this->setName('circles:manage:details') |
115
|
|
|
->setDescription('get details about a circle by its ID') |
116
|
|
|
->addArgument('circle_id', InputArgument::REQUIRED, 'ID of the circle') |
117
|
|
|
->addOption('instance', '', InputOption::VALUE_REQUIRED, 'Instance of the circle', '') |
118
|
|
|
->addOption('initiator', '', InputOption::VALUE_REQUIRED, 'set an initiator to the request', '') |
119
|
|
|
->addOption('initiator-type', '', InputOption::VALUE_REQUIRED, 'set initiator type', '0') |
120
|
|
|
->addOption('status-code', '', InputOption::VALUE_NONE, 'display status code on exception'); |
121
|
|
|
|
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param InputInterface $input |
127
|
|
|
* @param OutputInterface $output |
128
|
|
|
* |
129
|
|
|
* @return int |
130
|
|
|
* @throws CircleNotFoundException |
131
|
|
|
* @throws FederatedItemException |
132
|
|
|
* @throws FederatedUserException |
133
|
|
|
* @throws FederatedUserNotFoundException |
134
|
|
|
* @throws InitiatorNotFoundException |
135
|
|
|
* @throws InvalidItemException |
136
|
|
|
* @throws MemberNotFoundException |
137
|
|
|
* @throws OwnerNotFoundException |
138
|
|
|
* @throws RemoteInstanceException |
139
|
|
|
* @throws RemoteNotFoundException |
140
|
|
|
* @throws RemoteResourceNotFoundException |
141
|
|
|
* @throws UnknownRemoteException |
142
|
|
|
* @throws UserTypeNotFoundException |
143
|
|
|
* @throws InvalidIdException |
144
|
|
|
* @throws RequestBuilderException |
145
|
|
|
* @throws SingleCircleNotFoundException |
146
|
|
|
*/ |
147
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int { |
148
|
|
|
$circleId = (string)$input->getArgument('circle_id'); |
149
|
|
|
$instance = $input->getOption('instance'); |
150
|
|
|
|
151
|
|
|
try { |
152
|
|
|
if ($instance !== '') { |
153
|
|
|
$circle = $this->remoteService->getCircleFromInstance( |
154
|
|
|
$circleId, |
155
|
|
|
$instance, |
156
|
|
|
[ |
157
|
|
|
'initiator' => $input->getOption('initiator'), |
158
|
|
|
'initiatorType' => Member::parseTypeString($input->getOption('initiator-type')) |
159
|
|
|
] |
160
|
|
|
); |
161
|
|
|
} else { |
162
|
|
|
try { |
163
|
|
|
$this->federatedUserService->commandLineInitiator( |
164
|
|
|
$input->getOption('initiator'), |
165
|
|
|
Member::parseTypeString($input->getOption('initiator-type')), |
166
|
|
|
$circleId, |
167
|
|
|
true |
168
|
|
|
); |
169
|
|
|
|
170
|
|
|
$circle = $this->circleService->getCircle($circleId, 0); |
171
|
|
|
} catch (CircleNotFoundException $e) { |
172
|
|
|
throw new CircleNotFoundException( |
173
|
|
|
'unknown circle, use --instance to retrieve the data from a remote instance' |
174
|
|
|
); |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
} catch (FederatedItemException $e) { |
178
|
|
|
if ($input->getOption('status-code')) { |
179
|
|
|
throw new FederatedItemException( |
180
|
|
|
' [' . get_class($e) . ', ' . $e->getStatus() . ']' . "\n" . $e->getMessage() |
181
|
|
|
); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
throw $e; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
$output->writeln(json_encode($circle, JSON_PRETTY_PRINT)); |
188
|
|
|
|
189
|
|
|
return 0; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.