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() |
32
|
|
|
{ |
33
|
|
|
$this->call('module:migrate-reset', [ |
34
|
|
|
'module' => $this->getModuleName(), |
35
|
|
|
'--database' => $this->option('database'), |
36
|
|
|
'--force' => $this->option('force'), |
37
|
|
|
]); |
38
|
|
|
|
39
|
|
|
$this->call('module:migrate', [ |
40
|
|
|
'module' => $this->getModuleName(), |
41
|
|
|
'--database' => $this->option('database'), |
42
|
|
|
'--force' => $this->option('force'), |
43
|
|
|
]); |
44
|
|
|
|
45
|
|
|
if ($this->option('seed')) { |
46
|
|
|
$this->call('module:seed', [ |
47
|
|
|
'module' => $this->getModuleName(), |
48
|
|
|
]); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Get the console command arguments. |
54
|
|
|
* |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
56 |
|
protected function getArguments() |
58
|
|
|
{ |
59
|
|
|
return array( |
60
|
56 |
|
array('module', InputArgument::OPTIONAL, 'The name of module will be used.'), |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Get the console command options. |
66
|
|
|
* |
67
|
|
|
* @return array |
68
|
|
|
*/ |
69
|
56 |
|
protected function getOptions() |
70
|
|
|
{ |
71
|
|
|
return array( |
72
|
56 |
|
array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'), |
73
|
|
|
array('force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'), |
74
|
|
|
array('seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run.'), |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function getModuleName() |
79
|
|
|
{ |
80
|
|
|
$module = $this->argument('module'); |
81
|
|
|
|
82
|
|
|
app('modules')->find($module); |
83
|
|
|
|
84
|
|
|
if ($module === null) { |
85
|
|
|
return $module; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $module->getStudlyName(); |
|
|
|
|
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.