-
Notifications
You must be signed in to change notification settings - Fork 190
/
DeleteCommand.php
50 lines (41 loc) · 1.68 KB
/
DeleteCommand.php
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
<?php
namespace Pantheon\Terminus\Commands\MachineToken;
use Pantheon\Terminus\Commands\TerminusCommand;
use Terminus\Exceptions\TerminusException;
class DeleteCommand extends TerminusCommand
{
/**
* @var boolean True if the command requires the user to be logged in
*/
protected $authorized = true;
/**
* Removes a machine token from the logged-in user's account
*
* @name machine-token:delete
* @param string $machine_token_id The ID of the machine token to be deleted
* @throws \Terminus\Exceptions\TerminusException
* @aliases mt:delete
*
* @usage terminus machine-token:delete <machine_token_id>
* Removes the given machine token from the user's account
*/
public function delete($machine_token_id) {
$user = $this->session()->getUser();
// Find the token. Will throw an exception if it doesn't exist.
$machine_token = $user->machine_tokens->get($machine_token_id);
if (empty($machine_token)) {
throw new TerminusException('There are no machine tokens with the id {id}.', compact($machine_token_id));
}
$name = $machine_token->get('device_name');
// Confirm the delete.
if ($this->confirm(sprintf('Are you sure you want to delete "%s"?', $name))) {
$this->log()->notice('Deleting {token} ...', ['token' => $name]);
$response = $machine_token->delete();
if ($response['status_code'] == 200) {
$this->log()->notice('Deleted {token}!', ['token' => $name]);
} else {
throw new TerminusException('There was an problem deleting the machine token.');
}
}
}
}