|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Circles - Bring cloud-users closer together. |
|
6
|
|
|
* |
|
7
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
8
|
|
|
* later. See the COPYING file. |
|
9
|
|
|
* |
|
10
|
|
|
* @author Maxence Lange <[email protected]> |
|
11
|
|
|
* @copyright 2017 |
|
12
|
|
|
* @license GNU AGPL version 3 or any later version |
|
13
|
|
|
* |
|
14
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
15
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
16
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
17
|
|
|
* License, or (at your option) any later version. |
|
18
|
|
|
* |
|
19
|
|
|
* This program is distributed in the hope that it will be useful, |
|
20
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22
|
|
|
* GNU Affero General Public License for more details. |
|
23
|
|
|
* |
|
24
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
25
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
26
|
|
|
* |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
namespace OCA\Circles\Command; |
|
31
|
|
|
|
|
32
|
|
|
use OC\Core\Command\Base; |
|
33
|
|
|
use OCA\Circles\Db\CirclesRequest; |
|
34
|
|
|
use OCA\Circles\Db\MembersRequest; |
|
35
|
|
|
use OCA\Circles\Exceptions\CircleDoesNotExistException; |
|
36
|
|
|
use OCP\IL10N; |
|
37
|
|
|
use Symfony\Component\Console\Helper\Table; |
|
38
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
39
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
40
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
41
|
|
|
use Symfony\Component\Console\Output\ConsoleOutput; |
|
42
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Class MembersList |
|
47
|
|
|
* |
|
48
|
|
|
* @package OCA\Circles\Command |
|
49
|
|
|
*/ |
|
50
|
|
|
class MembersList extends Base { |
|
51
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
/** @var IL10N */ |
|
54
|
|
|
private $l10n; |
|
55
|
|
|
|
|
56
|
|
|
/** @var CirclesRequest */ |
|
57
|
|
|
private $circlesRequest; |
|
58
|
|
|
|
|
59
|
|
|
/** @var MembersRequest */ |
|
60
|
|
|
private $membersRequest; |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* MembersList constructor. |
|
65
|
|
|
* |
|
66
|
|
|
* @param IL10N $l10n |
|
67
|
|
|
* @param CirclesRequest $circlesRequest |
|
68
|
|
|
* @param MembersRequest $membersRequest |
|
69
|
|
|
*/ |
|
70
|
|
|
public function __construct(IL10N $l10n, CirclesRequest $circlesRequest, MembersRequest $membersRequest) { |
|
71
|
|
|
parent::__construct(); |
|
72
|
|
|
$this->l10n = $l10n; |
|
73
|
|
|
$this->circlesRequest = $circlesRequest; |
|
74
|
|
|
$this->membersRequest = $membersRequest; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
protected function configure() { |
|
79
|
|
|
parent::configure(); |
|
80
|
|
|
$this->setName('circles:members:list') |
|
81
|
|
|
->setDescription('listing members') |
|
82
|
|
|
->addArgument('circle_id', InputArgument::REQUIRED, 'ID of the circle') |
|
83
|
|
|
->addOption('json', '', InputOption::VALUE_NONE, 'returns result as JSON'); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @param InputInterface $input |
|
89
|
|
|
* @param OutputInterface $output |
|
90
|
|
|
* |
|
91
|
|
|
* @return int |
|
92
|
|
|
* @throws CircleDoesNotExistException |
|
93
|
|
|
*/ |
|
94
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int { |
|
95
|
|
|
$circleId = $input->getArgument('circle_id'); |
|
96
|
|
|
$json = $input->getOption('json'); |
|
97
|
|
|
|
|
98
|
|
|
$this->circlesRequest->forceGetCircle($circleId); |
|
99
|
|
|
|
|
100
|
|
|
$members = $this->membersRequest->forceGetMembers($circleId); |
|
101
|
|
|
|
|
102
|
|
|
if ($json) { |
|
103
|
|
|
echo json_encode($members, JSON_PRETTY_PRINT) . "\n"; |
|
104
|
|
|
|
|
105
|
|
|
return 0; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
$output = new ConsoleOutput(); |
|
109
|
|
|
$output = $output->section(); |
|
110
|
|
|
|
|
111
|
|
|
$table = new Table($output); |
|
112
|
|
|
$table->setHeaders(['ID', 'Name', 'Level']); |
|
113
|
|
|
$table->render(); |
|
114
|
|
|
$output->writeln(''); |
|
115
|
|
|
|
|
116
|
|
|
$c = 0; |
|
|
|
|
|
|
117
|
|
|
foreach ($members as $member) { |
|
118
|
|
|
$table->appendRow( |
|
119
|
|
|
[ |
|
120
|
|
|
$member->getMemberId(), |
|
121
|
|
|
$member->getUserId(), |
|
122
|
|
|
$member->getLevelString(), |
|
123
|
|
|
] |
|
124
|
|
|
); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
return 0; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.