-
Notifications
You must be signed in to change notification settings - Fork 0
/
enantsMigrateRefresh.php
62 lines (50 loc) · 1.59 KB
/
enantsMigrateRefresh.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace App\Console\Commands;
use Illuminate\Database\Console\Migrations\RefreshCommand;
use Stancl\Tenancy\Concerns\DealsWithMigrations;
use Stancl\Tenancy\Concerns\HasATenantsOption;
class TenantsMigrateRefresh extends RefreshCommand
{
use HasATenantsOption, DealsWithMigrations;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'tenants:migrate-refresh {migrations?*}'; // {--f|files=?}
/**
* The console command description.
*
* @var string
*/
protected $description = 'Tenants: Reset and re-run all migrations';
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
foreach (config('tenancy.migration_parameters') as $parameter => $value) {
if (!$this->input->hasParameterOption($parameter)) {
$this->input->setOption(ltrim($parameter, '-'), $value);
}
}
if ($this->argument('migrations')) {
$dir = config('tenancy.migration_parameters.--path')[0];
$files = [];
foreach ($this->argument('migrations') as $key => $file) {
$files[$key] = $dir . '/' . $file;
}
$this->input->setOption('path', $files);
}
if (!$this->confirmToProceed()) {
return;
}
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
$this->line("Tenant: {$tenant->getTenantKey()}");
// Refresh
parent::handle();
});
}
}