Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / auth / management / PhabricatorAuthManagementTrustOAuthClientWorkflow.php
blob8455b5697f965d75734b31ae3f7dee779b9575de
1 <?php
3 final class PhabricatorAuthManagementTrustOAuthClientWorkflow
4 extends PhabricatorAuthManagementWorkflow {
6 protected function didConstruct() {
7 $this
8 ->setName('trust-oauth-client')
9 ->setExamples('**trust-oauth-client** [--id client_id]')
10 ->setSynopsis(
11 pht(
12 'Mark an OAuth client as trusted. Trusted OAuth clients may be '.
13 'reauthorized without requiring users to manually confirm the '.
14 'action.'))
15 ->setArguments(
16 array(
17 array(
18 'name' => 'id',
19 'param' => 'id',
20 'help' => pht('The id of the OAuth client.'),
22 ));
25 public function execute(PhutilArgumentParser $args) {
26 $id = $args->getArg('id');
28 if (!$id) {
29 throw new PhutilArgumentUsageException(
30 pht(
31 'Specify an OAuth client id with "--id".'));
34 $client = id(new PhabricatorOAuthServerClientQuery())
35 ->setViewer($this->getViewer())
36 ->withIDs(array($id))
37 ->executeOne();
39 if (!$client) {
40 throw new PhutilArgumentUsageException(
41 pht(
42 'Failed to find an OAuth client with id %s.', $id));
45 if ($client->getIsTrusted()) {
46 throw new PhutilArgumentUsageException(
47 pht(
48 'OAuth client "%s" is already trusted.',
49 $client->getName()));
52 $client->setIsTrusted(1);
53 $client->save();
55 $console = PhutilConsole::getConsole();
56 $console->writeOut(
57 "%s\n",
58 pht(
59 'OAuth client "%s" is now trusted.',
60 $client->getName()));