|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AtlassianConnectCore\Console; |
|
4
|
|
|
|
|
5
|
|
|
use AtlassianConnectCore\Models\Tenant; |
|
6
|
|
|
use AtlassianConnectCore\Services\TenantService; |
|
7
|
|
|
use Illuminate\Console\Command; |
|
8
|
|
|
use Illuminate\Support\Facades\Validator; |
|
9
|
|
|
use Illuminate\Validation\Rule; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class DummyCommand |
|
13
|
|
|
* |
|
14
|
|
|
* @package AtlassianConnectCore\Console |
|
15
|
|
|
*/ |
|
16
|
|
|
class DummyCommand extends Command |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* The name and signature of the console command. |
|
20
|
|
|
* |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $signature = 'plugin:dummy'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* The console command description. |
|
27
|
|
|
* |
|
28
|
|
|
* @var string |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $description = 'Make your tenant dummy'; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var TenantService |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $tenantService; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* InstallCommand constructor. |
|
39
|
|
|
* |
|
40
|
|
|
* @param TenantService $tenantService |
|
41
|
|
|
*/ |
|
42
|
|
|
public function __construct(TenantService $tenantService) |
|
43
|
|
|
{ |
|
44
|
|
|
parent::__construct(); |
|
45
|
|
|
|
|
46
|
|
|
$this->tenantService = $tenantService; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Execute the console command. |
|
51
|
|
|
* |
|
52
|
|
|
* @return mixed |
|
53
|
|
|
*/ |
|
54
|
|
|
public function handle() |
|
55
|
|
|
{ |
|
56
|
|
|
$tenants = $this->tenantService->findReals(); |
|
57
|
|
|
|
|
58
|
|
|
$this->table( |
|
59
|
|
|
['ID', 'Client Key (last 22 chars)', 'Product', 'Status', 'Created At'], |
|
60
|
|
|
$this->formatTenants($tenants, [ |
|
|
|
|
|
|
61
|
|
|
'id', 'client_key', 'product_type', 'event_type', 'created_at' |
|
62
|
|
|
]) |
|
63
|
|
|
); |
|
64
|
|
|
|
|
65
|
|
|
// Make the list of choices |
|
66
|
|
|
$choices = $tenants |
|
67
|
|
|
->pluck('id') |
|
68
|
|
|
->toArray(); |
|
69
|
|
|
|
|
70
|
|
|
$id = $this->ask('Which the tenant should be dummy? (Pass ID)'); |
|
71
|
|
|
|
|
72
|
|
|
$validator = Validator::make(['value' => $id], ['value' => Rule::in($choices)]); |
|
73
|
|
|
|
|
74
|
|
|
if($validator->fails()) { |
|
75
|
|
|
return $this->error('Invalid ID provided'); |
|
|
|
|
|
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$this->tenantService->makeDummy($id); |
|
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
$this->comment('Tenant <info>' . $id . '</info> has been set as dummy'); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Format given tenants to columns with specific attributes |
|
85
|
|
|
* |
|
86
|
|
|
* @param \Illuminate\Database\Eloquent\Collection|Tenant[] $tenants |
|
87
|
|
|
* @param array $attributes Attributes need to be returned |
|
88
|
|
|
* |
|
89
|
|
|
* @return array |
|
90
|
|
|
*/ |
|
91
|
|
|
protected function formatTenants($tenants, array $attributes) |
|
92
|
|
|
{ |
|
93
|
|
|
$tenants = collect($tenants->toArray()); |
|
94
|
|
|
|
|
95
|
|
|
return $tenants->map(function ($tenant) use ($attributes) { |
|
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
// Make the client key shorter for displaying |
|
98
|
|
|
$tenant['client_key'] = substr($tenant['client_key'], -22); |
|
99
|
|
|
|
|
100
|
|
|
return array_only($tenant, $attributes); |
|
101
|
|
|
}); |
|
102
|
|
|
} |
|
103
|
|
|
} |