mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 14:14:04 +00:00
68 lines
1.6 KiB
PHP
68 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Stancl\Tenancy\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Database\Console\Migrations\RollbackCommand;
|
|
use Illuminate\Database\Migrations\Migrator;
|
|
use Stancl\Tenancy\Contracts\TenantWithDatabase;
|
|
use Stancl\Tenancy\DatabaseManager;
|
|
use Stancl\Tenancy\Traits\DealsWithMigrations;
|
|
use Stancl\Tenancy\Traits\HasATenantsOption;
|
|
|
|
class Rollback extends RollbackCommand
|
|
{
|
|
use HasATenantsOption, DealsWithMigrations;
|
|
|
|
protected $database;
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Rollback migrations for tenant(s).';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct(Migrator $migrator, DatabaseManager $database)
|
|
{
|
|
parent::__construct($migrator);
|
|
$this->database = $database;
|
|
|
|
$this->setName('tenants:rollback');
|
|
$this->specifyParameters();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
foreach (config('tenancy.migration_parameters') as $parameter => $value) {
|
|
if (! $this->input->hasParameterOption($parameter)) {
|
|
$this->input->setOption(ltrim($parameter, '-'), $value);
|
|
}
|
|
}
|
|
|
|
if (! $this->confirmToProceed()) {
|
|
return;
|
|
}
|
|
|
|
tenancy()->runForMultiple($this->option('tenants'), function ($tenant) {
|
|
$this->line("Tenant: {$tenant['id']}");
|
|
|
|
// Rollback
|
|
parent::handle();
|
|
|
|
// todo DatabaseRolledBack event
|
|
});
|
|
}
|
|
}
|