1 | <?php |
||
11 | class MigrateCommand extends Command |
||
12 | { |
||
13 | /** |
||
14 | * The console command name. |
||
15 | * |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $name = 'module:migrate'; |
||
19 | |||
20 | /** |
||
21 | * The console command description. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $description = 'Migrate the migrations from the specified module or from all modules.'; |
||
26 | |||
27 | /** |
||
28 | * @var \Nwidart\Modules\Repository |
||
29 | */ |
||
30 | protected $module; |
||
31 | |||
32 | /** |
||
33 | * Execute the console command. |
||
34 | * |
||
35 | * @return mixed |
||
36 | */ |
||
37 | public function handle() |
||
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 | return $this->migrate($module); |
||
47 | } |
||
48 | |||
49 | foreach ($this->module->getOrdered($this->option('direction')) as $module) { |
||
50 | $this->line('Running for module: <info>' . $module->getName() . '</info>'); |
||
51 | |||
52 | $this->migrate($module); |
||
53 | } |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Run the migration from the specified module. |
||
58 | * |
||
59 | * @param Module $module |
||
60 | */ |
||
61 | protected function migrate(Module $module) |
||
62 | { |
||
63 | $path = str_replace(base_path(), '', (new Migrator($module))->getPath()); |
||
64 | |||
65 | if ($this->option('subpath')) { |
||
66 | $path = $path . "/" . $this->option("subpath"); |
||
67 | } |
||
68 | |||
69 | $this->call('migrate', [ |
||
70 | '--path' => $path, |
||
71 | '--database' => $this->option('database'), |
||
72 | '--pretend' => $this->option('pretend'), |
||
73 | '--force' => $this->option('force'), |
||
74 | ]); |
||
75 | |||
76 | if ($this->option('seed')) { |
||
77 | $this->call('module:seed', ['module' => $module->getName()]); |
||
78 | } |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * Get the console command arguments. |
||
83 | * |
||
84 | * @return array |
||
85 | */ |
||
86 | 56 | protected function getArguments() |
|
92 | |||
93 | /** |
||
94 | * Get the console command options. |
||
95 | * |
||
96 | * @return array |
||
97 | */ |
||
98 | 56 | protected function getOptions() |
|
109 | } |
||
110 |