1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Slides\Saml2\Commands; |
4
|
|
|
|
5
|
|
|
use Slides\Saml2\Repositories\TenantRepository; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class DeleteTenant |
9
|
|
|
* |
10
|
|
|
* @package Slides\Saml2\Commands |
11
|
|
|
*/ |
12
|
|
|
class DeleteTenant extends \Illuminate\Console\Command |
13
|
|
|
{ |
14
|
|
|
use RendersTenants; |
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* The name and signature of the console command. |
18
|
|
|
* |
19
|
|
|
* @var string |
20
|
|
|
*/ |
21
|
|
|
protected $signature = 'saml2:delete-tenant {tenant} |
22
|
|
|
{ --safe : Safe deletion }'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The console command description. |
26
|
|
|
* |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $description = 'Delete a tenant by ID, key or UUID'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var TenantRepository |
33
|
|
|
*/ |
34
|
|
|
protected $tenants; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* DeleteTenant constructor. |
38
|
|
|
* |
39
|
|
|
* @param TenantRepository $tenants |
40
|
|
|
*/ |
41
|
|
|
public function __construct(TenantRepository $tenants) |
42
|
|
|
{ |
43
|
|
|
$this->tenants = $tenants; |
44
|
|
|
|
45
|
|
|
parent::__construct(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Execute the console command. |
50
|
|
|
* |
51
|
|
|
* @return void |
52
|
|
|
*/ |
53
|
|
|
public function handle() |
54
|
|
|
{ |
55
|
|
|
$tenants = $this->tenants->findByAnyIdentifier($this->argument('tenant'), false); |
|
|
|
|
56
|
|
|
|
57
|
|
|
if($tenants->isEmpty()) { |
58
|
|
|
$this->error('Cannot find a matching tenant by "' . $this->argument('tenant') . '" identifier'); |
|
|
|
|
59
|
|
|
return; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$this->renderTenants($tenants, 'Found tenant(s)'); |
63
|
|
|
|
64
|
|
|
if($tenants->count() > 1) { |
65
|
|
|
$deletingId = $this->ask('We have found several tenants, which one would you like to delete? (enter its ID)'); |
66
|
|
|
} |
67
|
|
|
else { |
68
|
|
|
$deletingId = $tenants->first()->id; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$tenant = $tenants->firstWhere('id', $deletingId); |
72
|
|
|
|
73
|
|
|
if($this->option('safe')) { |
74
|
|
|
$tenant->delete(); |
75
|
|
|
|
76
|
|
|
$this->info('The tenant #' . $deletingId . ' safely deleted. To restore it, run:'); |
77
|
|
|
$this->output->block('php artisan saml2:restore-tenant ' . $deletingId); |
78
|
|
|
|
79
|
|
|
return; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
if(!$this->confirm('Would you like to forcely delete the tenant #' . $deletingId . '? It cannot be reverted.')) { |
83
|
|
|
return; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$tenant->forceDelete(); |
87
|
|
|
|
88
|
|
|
$this->info('The tenant #' . $deletingId . ' safely deleted.'); |
89
|
|
|
} |
90
|
|
|
} |