mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 16:14:03 +00:00
* Using laravel components * Ensure commands returns success * update tests * clean * bump EndBug version * Update ci.yml * Update ci.yml * Update ci.yml * revert CI changes * Update ci.yml * Update ci.yml * Update ci.yml * revert CI changes to it's original state * fix typos, improve code * improve Install & TenantList commands * php-cs-fixer * type GitHub properly Co-authored-by: Abrar Ahmad <abrar.dev99@gmail.com> Co-authored-by: Samuel Štancl <samuel@archte.ch> Co-authored-by: Samuel Štancl <samuel.stancl@gmail.com>
57 lines
1.5 KiB
PHP
57 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Stancl\Tenancy\Commands;
|
|
|
|
use Illuminate\Database\Console\Migrations\RollbackCommand;
|
|
use Illuminate\Database\Migrations\Migrator;
|
|
use Stancl\Tenancy\Concerns\ExtendsLaravelCommand;
|
|
use Stancl\Tenancy\Concerns\HasATenantsOption;
|
|
use Stancl\Tenancy\Events\DatabaseRolledBack;
|
|
use Stancl\Tenancy\Events\RollingBackDatabase;
|
|
|
|
class Rollback extends RollbackCommand
|
|
{
|
|
use HasATenantsOption, ExtendsLaravelCommand;
|
|
|
|
protected $description = 'Rollback migrations for tenant(s).';
|
|
|
|
public function __construct(Migrator $migrator)
|
|
{
|
|
parent::__construct($migrator);
|
|
|
|
$this->specifyTenantSignature();
|
|
}
|
|
|
|
public function handle(): int
|
|
{
|
|
foreach (config('tenancy.migration_parameters') as $parameter => $value) {
|
|
if (! $this->input->hasParameterOption($parameter)) {
|
|
$this->input->setOption(ltrim($parameter, '-'), $value);
|
|
}
|
|
}
|
|
|
|
if (! $this->confirmToProceed()) {
|
|
return 1;
|
|
}
|
|
|
|
tenancy()->runForMultiple($this->getTenants(), function ($tenant) {
|
|
$this->components->info("Tenant: {$tenant->getTenantKey()}");
|
|
|
|
event(new RollingBackDatabase($tenant));
|
|
|
|
// Rollback
|
|
parent::handle();
|
|
|
|
event(new DatabaseRolledBack($tenant));
|
|
});
|
|
|
|
return 0;
|
|
}
|
|
|
|
protected static function getTenantCommandName(): string
|
|
{
|
|
return 'tenants:rollback';
|
|
}
|
|
}
|