|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Nwidart\Modules\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
6
|
|
|
use Nwidart\Modules\Traits\ModuleCommandTrait; |
|
7
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
9
|
|
|
|
|
10
|
|
|
class MigrateRefreshCommand extends Command |
|
11
|
|
|
{ |
|
12
|
|
|
use ModuleCommandTrait; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* The console command name. |
|
16
|
|
|
* |
|
17
|
|
|
* @var string |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $name = 'module:migrate-refresh'; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* The console command description. |
|
23
|
|
|
* |
|
24
|
|
|
* @var string |
|
25
|
|
|
*/ |
|
26
|
|
|
protected $description = 'Rollback & re-migrate the modules migrations.'; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Execute the console command. |
|
30
|
|
|
*/ |
|
31
|
|
|
public function handle() : int |
|
32
|
|
|
{ |
|
33
|
|
|
$module = $this->argument('module'); |
|
34
|
|
|
|
|
35
|
|
|
if ($module && !$this->getModuleName()) { |
|
36
|
|
|
$this->error("Module [$module] does not exists."); |
|
37
|
|
|
|
|
38
|
|
|
return E_ERROR; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
$this->call('module:migrate-reset', [ |
|
42
|
|
|
'module' => $this->getModuleName(), |
|
43
|
|
|
'--database' => $this->option('database'), |
|
44
|
|
|
'--force' => $this->option('force'), |
|
45
|
|
|
]); |
|
46
|
|
|
|
|
47
|
|
|
$this->call('module:migrate', [ |
|
48
|
|
|
'module' => $this->getModuleName(), |
|
49
|
|
|
'--database' => $this->option('database'), |
|
50
|
|
|
'--force' => $this->option('force'), |
|
51
|
|
|
]); |
|
52
|
|
|
|
|
53
|
|
|
if ($this->option('seed')) { |
|
54
|
|
|
$this->call('module:seed', [ |
|
55
|
|
|
'module' => $this->getModuleName(), |
|
56
|
|
|
]); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return 0; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Get the console command arguments. |
|
64
|
|
|
* |
|
65
|
|
|
* @return array |
|
66
|
|
|
*/ |
|
67
|
128 |
|
protected function getArguments() |
|
68
|
|
|
{ |
|
69
|
|
|
return [ |
|
70
|
128 |
|
['module', InputArgument::OPTIONAL, 'The name of module will be used.'], |
|
71
|
|
|
]; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Get the console command options. |
|
76
|
|
|
* |
|
77
|
|
|
* @return array |
|
78
|
|
|
*/ |
|
79
|
128 |
View Code Duplication |
protected function getOptions() |
|
80
|
|
|
{ |
|
81
|
|
|
return [ |
|
82
|
128 |
|
['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'], |
|
83
|
|
|
['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'], |
|
84
|
|
|
['seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'], |
|
85
|
|
|
]; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function getModuleName() |
|
89
|
|
|
{ |
|
90
|
|
|
$module = $this->argument('module'); |
|
91
|
|
|
|
|
92
|
|
|
if (!$module) { |
|
93
|
|
|
return null; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
$module = app('modules')->find($module); |
|
97
|
|
|
|
|
98
|
|
|
return $module ? $module->getStudlyName() : null; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|