1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Itstructure\Mult\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class DatabaseCommand |
9
|
|
|
* |
10
|
|
|
* @package Itstructure\Mult\Commands |
11
|
|
|
* |
12
|
|
|
* @author Andrey Girnik <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class DatabaseCommand extends Command |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* The name and signature of the console command. |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $signature = 'mult:database '. |
21
|
|
|
'{--force : Overwrite existing views by default. This option can not be used.}'. |
22
|
|
|
'{--only= : Run only specific process. Available values: migrate, seed. This option can not be used.}'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* The console command description. |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $description = 'Fill database - migrate and seed.'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Execute the console command. |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
|
|
public function handle() |
35
|
|
|
{ |
36
|
|
|
try { |
37
|
|
|
$this->info('Start fill database...'); |
38
|
|
|
|
39
|
|
|
$callArguments = []; |
40
|
|
|
|
41
|
|
|
if ($this->option('force')) { |
42
|
|
|
$this->warn('Force process.'); |
43
|
|
|
$callArguments['--force'] = true; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
if ($this->option('only')) { |
47
|
|
|
switch ($this->option('only')) { |
48
|
|
|
case 'migrate': |
49
|
|
|
$this->info('Migration process...'); |
50
|
|
|
$this->call('migrate', $callArguments); |
51
|
|
|
break; |
52
|
|
|
|
53
|
|
|
case 'seed': |
54
|
|
|
$this->info('Seeding process...'); |
55
|
|
|
$this->call('db:seed', array_merge([ |
56
|
|
|
'--class' => 'MultSeeder', |
57
|
|
|
], $callArguments) |
58
|
|
|
); |
59
|
|
|
break; |
60
|
|
|
|
61
|
|
|
default: |
62
|
|
|
$this->error('Invalid "only" argument value!'); |
63
|
|
|
return; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
} else { |
67
|
|
|
$this->info('Run all processes: migration and seeding.'); |
68
|
|
|
$this->call('migrate', $callArguments); |
69
|
|
|
$this->call('db:seed', array_merge([ |
70
|
|
|
'--class' => 'MultSeeder', |
71
|
|
|
], $callArguments) |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$this->info('Filling database is completed successfully.'); |
76
|
|
|
|
77
|
|
|
} catch (\Exception $e) { |
78
|
|
|
$this->error('Failed!'); |
79
|
|
|
$this->error($e->getMessage()); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|