1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Rawilk\LaravelModules\Commands\Other; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Rawilk\LaravelModules\Traits\ModuleCommands; |
7
|
|
|
|
8
|
|
|
class MigrateRefreshCommand extends Command |
9
|
|
|
{ |
10
|
|
|
use ModuleCommands; |
11
|
|
|
|
12
|
|
|
/** @var string */ |
13
|
|
|
protected $signature = 'module:migrate-refresh |
14
|
|
|
{module? : The name of the module to refresh migrations for} |
15
|
|
|
{--database= : The database connection to use} |
16
|
|
|
{--force : Force the operation to run when in production} |
17
|
|
|
{--seed : Indicates if the seed task should be re-run}'; |
18
|
|
|
|
19
|
|
|
/** @var string */ |
20
|
|
|
protected $description = 'Rollback & re-migrate the migrations for the specified module.'; |
21
|
|
|
|
22
|
|
|
public function handle(): void |
23
|
|
|
{ |
24
|
|
|
$this->call('module:migrate-reset', [ |
25
|
|
|
'module' => $this->getModuleName(), |
26
|
|
|
'--database' => $this->option('database'), |
27
|
|
|
'--force' => $this->option('force') |
28
|
|
|
]); |
29
|
|
|
|
30
|
|
|
$this->call('module:migrate', [ |
31
|
|
|
'module' => $this->getModuleName(), |
32
|
|
|
'--database' => $this->option('database'), |
33
|
|
|
'--force' => $this->option('force') |
34
|
|
|
]); |
35
|
|
|
|
36
|
|
|
if ($this->option('seed')) { |
37
|
|
|
$this->call('module:seed', [ |
38
|
|
|
'module' => $this->getModuleName() |
39
|
|
|
]); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
private function getModuleName(): ?string |
44
|
|
|
{ |
45
|
|
|
$module = $this->argument('module'); |
46
|
|
|
|
47
|
|
|
/** @var \Rawilk\LaravelModules\Module $module */ |
48
|
|
|
$module = $this->laravel['modules']->find($module); |
49
|
|
|
|
50
|
|
|
if ($module === null) { |
51
|
|
|
return $module; |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $module->getStudlyName(); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|