mirror of
https://github.com/archtechx/tenancy.git
synced 2026-03-22 01:04:04 +00:00
feat: option to skip tenant
This commit is contained in:
parent
37b2a91aa9
commit
f1e03fb921
2 changed files with 7 additions and 2 deletions
|
|
@ -17,7 +17,8 @@ class Run extends Command
|
||||||
protected $description = 'Run a command for tenant(s)';
|
protected $description = 'Run a command for tenant(s)';
|
||||||
|
|
||||||
protected $signature = 'tenants:run {commandname : The artisan command.}
|
protected $signature = 'tenants:run {commandname : The artisan command.}
|
||||||
{--tenants=* : The tenant(s) to run the command for. Default: all}';
|
{--tenants=* : The tenant(s) to run the command for. Default: all}
|
||||||
|
{--skip-tenants=* : The tenant(s) to skip}';
|
||||||
|
|
||||||
public function handle(): int
|
public function handle(): int
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ use Stancl\Tenancy\Database\Concerns\PendingScope;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds 'tenants' and 'with-pending' options.
|
* Adds 'tenants', 'skip-tenants', and 'with-pending' options.
|
||||||
*/
|
*/
|
||||||
trait HasTenantOptions
|
trait HasTenantOptions
|
||||||
{
|
{
|
||||||
|
|
@ -18,6 +18,7 @@ trait HasTenantOptions
|
||||||
{
|
{
|
||||||
return array_merge([
|
return array_merge([
|
||||||
['tenants', null, InputOption::VALUE_IS_ARRAY|InputOption::VALUE_OPTIONAL, 'The tenants to run this command for. Leave empty for all tenants', null],
|
['tenants', null, InputOption::VALUE_IS_ARRAY|InputOption::VALUE_OPTIONAL, 'The tenants to run this command for. Leave empty for all tenants', null],
|
||||||
|
['skip-tenants', null, InputOption::VALUE_IS_ARRAY|InputOption::VALUE_OPTIONAL, 'The tenants to skip when running this command', null],
|
||||||
['with-pending', null, InputOption::VALUE_NONE, 'Include pending tenants in query'], // todo@pending should we also offer without-pending? if we add this, mention in docs
|
['with-pending', null, InputOption::VALUE_NONE, 'Include pending tenants in query'], // todo@pending should we also offer without-pending? if we add this, mention in docs
|
||||||
], parent::getOptions());
|
], parent::getOptions());
|
||||||
}
|
}
|
||||||
|
|
@ -42,6 +43,9 @@ trait HasTenantOptions
|
||||||
->when($this->option('tenants'), function ($query) {
|
->when($this->option('tenants'), function ($query) {
|
||||||
$query->whereIn(tenancy()->model()->getTenantKeyName(), $this->option('tenants'));
|
$query->whereIn(tenancy()->model()->getTenantKeyName(), $this->option('tenants'));
|
||||||
})
|
})
|
||||||
|
->when($this->option('skip-tenants'), function ($query) {
|
||||||
|
$query->whereNotIn(tenancy()->model()->getTenantKeyName(), $this->option('skip-tenants'));
|
||||||
|
})
|
||||||
->when(tenancy()->model()::hasGlobalScope(PendingScope::class), function ($query) {
|
->when(tenancy()->model()::hasGlobalScope(PendingScope::class), function ($query) {
|
||||||
$query->withPending(config('tenancy.pending.include_in_queries') ?: $this->option('with-pending'));
|
$query->withPending(config('tenancy.pending.include_in_queries') ?: $this->option('with-pending'));
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue