1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nwidart\Modules\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Nwidart\Modules\Migrations\Migrator; |
7
|
|
|
use Nwidart\Modules\Module; |
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
10
|
|
|
|
11
|
|
|
class MigrateStatusCommand extends Command |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* The console command name. |
15
|
|
|
* |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $name = 'module:migrate-status'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The console command description. |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $description = 'Status for all module migrations'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var \Nwidart\Modules\Contracts\RepositoryInterface |
29
|
|
|
*/ |
30
|
|
|
protected $module; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Execute the console command. |
34
|
|
|
* |
35
|
|
|
* @return mixed |
36
|
|
|
*/ |
37
|
|
View Code Duplication |
public function handle() : int |
38
|
|
|
{ |
39
|
|
|
$this->module = $this->laravel['modules']; |
40
|
|
|
|
41
|
|
|
$name = $this->argument('module'); |
42
|
|
|
|
43
|
|
|
if ($name) { |
44
|
|
|
$module = $this->module->findOrFail($name); |
45
|
|
|
|
46
|
|
|
$this->migrateStatus($module); |
47
|
|
|
|
48
|
|
|
return 0; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
foreach ($this->module->getOrdered($this->option('direction')) as $module) { |
52
|
|
|
$this->line('Running for module: <info>' . $module->getName() . '</info>'); |
53
|
|
|
$this->migrateStatus($module); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return 0; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Run the migration from the specified module. |
61
|
|
|
* |
62
|
|
|
* @param Module $module |
63
|
|
|
*/ |
64
|
|
|
protected function migrateStatus(Module $module) |
65
|
|
|
{ |
66
|
|
|
$path = str_replace(base_path(), '', (new Migrator($module, $this->getLaravel()))->getPath()); |
67
|
|
|
|
68
|
|
|
$this->call('migrate:status', [ |
69
|
|
|
'--path' => $path, |
70
|
|
|
'--database' => $this->option('database'), |
71
|
|
|
]); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Get the console command arguments. |
76
|
|
|
* |
77
|
|
|
* @return array |
78
|
|
|
*/ |
79
|
128 |
|
protected function getArguments() |
80
|
|
|
{ |
81
|
|
|
return [ |
82
|
128 |
|
['module', InputArgument::OPTIONAL, 'The name of module will be used.'], |
83
|
|
|
]; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Get the console command options. |
88
|
|
|
* |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
128 |
View Code Duplication |
protected function getOptions() |
92
|
|
|
{ |
93
|
|
|
return [ |
94
|
128 |
|
['direction', 'd', InputOption::VALUE_OPTIONAL, 'The direction of ordering.', 'asc'], |
95
|
|
|
['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'], |
96
|
|
|
]; |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|