mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-06 04:44:04 +00:00
* install PHP CS Fixer * Fix styling * remove StyleCI config * use config from archtechx/template * Fix styling * added `php-cs-fixer` * Update .php-cs-fixer.php * added GitHub token * Update ci.yml * Update ci.yml * Update ci.yml * php-cs-fixer workflow same as template Co-authored-by: Erik Gaal <me@erikgaal.nl> Co-authored-by: erikgaal <erikgaal@users.noreply.github.com>
53 lines
1.4 KiB
PHP
53 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Stancl\Tenancy\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Contracts\Events\Dispatcher;
|
|
use Illuminate\Database\ConnectionResolverInterface;
|
|
use Illuminate\Database\Console\DumpCommand;
|
|
use Stancl\Tenancy\Contracts\Tenant;
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
class TenantDump extends DumpCommand
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
$this->setName('tenants:dump');
|
|
$this->specifyParameters();
|
|
}
|
|
|
|
public function handle(ConnectionResolverInterface $connections, Dispatcher $dispatcher): int
|
|
{
|
|
$this->tenant()->run(fn () => parent::handle($connections, $dispatcher));
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
|
|
public function tenant(): Tenant
|
|
{
|
|
$tenant = $this->option('tenant')
|
|
?? tenant()
|
|
?? $this->ask('What tenant do you want to dump the schema for?')
|
|
?? tenancy()->query()->first();
|
|
|
|
if (! $tenant instanceof Tenant) {
|
|
$tenant = tenancy()->find($tenant);
|
|
}
|
|
|
|
throw_if(! $tenant, 'Could not identify the tenant to use for dumping the schema.');
|
|
|
|
return $tenant;
|
|
}
|
|
|
|
protected function getOptions(): array
|
|
{
|
|
return array_merge([
|
|
['tenant', null, InputOption::VALUE_OPTIONAL, '', null],
|
|
], parent::getOptions());
|
|
}
|
|
}
|