-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Expand file tree
/
Copy pathDeleteClient.php
More file actions
58 lines (48 loc) · 1.47 KB
/
Copy pathDeleteClient.php
File metadata and controls
58 lines (48 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH
* SPDX-FileContributor: Carl Schwan
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\OAuth2\Command;
use OC\Core\Command\Base;
use OCA\OAuth2\Service\ClientService;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class DeleteClient extends Base {
private const ARGUMENT_CLIENT_ID = 'client-id';
public function __construct(
private readonly ClientService $clientService,
) {
parent::__construct();
}
#[\Override]
protected function configure(): void {
parent::configure();
$this->setName('oauth2:delete-client');
$this->setDescription('This command removes an existing oauth2 client.');
$this->addArgument(
self::ARGUMENT_CLIENT_ID,
InputArgument::REQUIRED,
'Id of the oauth2 client',
);
}
#[\Override]
protected function execute(InputInterface $input, OutputInterface $output): int {
$id = (int)$input->getArgument(self::ARGUMENT_CLIENT_ID);
if ($id === 0) {
$output->writeln('<error>The given id is not a valid positive integer.</error>');
return Command::FAILURE;
}
try {
$this->clientService->deleteClient($id);
} catch (\Exception $exception) {
$output->writeln('<error>' . $exception->getMessage() . '</error>');
return Command::FAILURE;
}
return Command::SUCCESS;
}
}