1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
4
|
|
|
|
5
|
|
|
use App\Models\Tenant; |
6
|
|
|
use App\Services\TenantManager; |
7
|
|
|
use Illuminate\Console\Command; |
8
|
|
|
use Symfony\Component\Console\Exception\RuntimeException; |
9
|
|
|
|
10
|
|
|
class SeedDemoData extends Command |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* The name and signature of the console command. |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $signature = 'tenant:seeddemodata {tenantId}'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The console command description. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $description = 'Seed teenant database with example recruitments and fake candidates'; |
25
|
|
|
|
26
|
|
|
protected $tenantManager; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Create a new command instance. |
30
|
|
|
* |
31
|
|
|
* @return void |
32
|
|
|
*/ |
33
|
|
|
public function __construct(TenantManager $tenantManager) |
34
|
|
|
{ |
35
|
|
|
parent::__construct(); |
36
|
|
|
|
37
|
|
|
$this->tenantManager = $tenantManager; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Execute the console command. |
42
|
|
|
* |
43
|
|
|
* @return mixed |
44
|
|
|
*/ |
45
|
|
|
public function handle() |
46
|
|
|
{ |
47
|
|
|
$tenantId = $this->argument('tenantId'); |
48
|
|
|
$tenant = Tenant::find($tenantId); |
49
|
|
|
|
50
|
|
|
if (!$tenant) { |
51
|
|
|
throw new RuntimeException('Tenant with ID = '.$tenantId.' does not exist.'); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$this->tenantManager->setTenant($tenant); |
55
|
|
|
\DB::purge('tenant'); |
56
|
|
|
|
57
|
|
|
$seeder = new \ExampleRecruitments(); |
|
|
|
|
58
|
|
|
$seeder->setConnection('tenant'); |
59
|
|
|
$seeder->run(); |
60
|
|
|
|
61
|
|
|
$seeder = new \ExampleCandidates(); |
|
|
|
|
62
|
|
|
$seeder->setConnection('tenant'); |
63
|
|
|
$seeder->run(); |
64
|
|
|
|
65
|
|
|
$seeder = new \ExampleStages(); |
|
|
|
|
66
|
|
|
$seeder->setConnection('tenant'); |
67
|
|
|
$seeder->run(); |
68
|
|
|
|
69
|
|
|
$seeder = new \ExamplePredefinedMessages(); |
|
|
|
|
70
|
|
|
$seeder->setConnection('tenant'); |
71
|
|
|
$seeder->run(); |
72
|
|
|
|
73
|
|
|
$this->info('Demo data have been seeded for tenant with subdomain \''.$tenant->subdomain.'\'.'); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|