1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 06:44:04 +00:00

pending tenants: minor cleanup

This commit is contained in:
Samuel Štancl 2025-10-29 19:24:06 +01:00
parent 0dc187510b
commit d274d8c902
No known key found for this signature in database
GPG key ID: BA146259A1E16C57
4 changed files with 13 additions and 33 deletions

View file

@ -19,9 +19,9 @@ You won't have to change a thing in your application's code.
- :heavy_check_mark: No replacing of Laravel classes (`Cache`, `Storage`, ...) with tenancy-aware classes
- :heavy_check_mark: Built-in tenant identification based on hostname (including second level domains)
### [Documentation](https://tenancy-v4.pages.dev/)
### [Documentation](https://v4.tenancyforlaravel.com)
Documentation can be found here: https://tenancy-v4.pages.dev/
Documentation can be found here: https://v4.tenancyforlaravel.com
### [Need help?](https://github.com/stancl/tenancy/blob/3.x/SUPPORT.md)

View file

@ -444,7 +444,6 @@ return [
/**
* Pending tenants config.
* This is useful if you're looking for a way to always have a tenant ready to be used.
*/
'pending' => [
/**
@ -453,6 +452,7 @@ return [
* Note: when disabled, this will also ignore pending tenants when running the tenant commands (migration, seed, etc.)
*/
'include_in_queries' => true,
/**
* Defines how many pending tenants you want to have ready in the pending tenant pool.
* This depends on the volume of tenants you're creating.

View file

@ -18,7 +18,7 @@ trait HasTenantOptions
{
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],
['with-pending', null, InputOption::VALUE_NONE, 'Include pending tenants in query'],
['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());
}

View file

@ -10,13 +10,6 @@ use Illuminate\Database\Eloquent\Scope;
class PendingScope implements Scope
{
/**
* All of the extensions to be added to the builder.
*
* @var string[]
*/
protected $extensions = ['WithPending', 'WithoutPending', 'OnlyPending'];
/**
* Apply the scope to a given Eloquent query builder.
*
@ -32,26 +25,21 @@ class PendingScope implements Scope
}
/**
* Extend the query builder with the needed functions.
* Add methods to the query builder.
*
* @param Builder<\Stancl\Tenancy\Contracts\Tenant&Model> $builder
*
* @return void
*/
public function extend(Builder $builder)
public function extend(Builder $builder): void
{
foreach ($this->extensions as $extension) {
$this->{"add{$extension}"}($builder);
}
$this->addWithPending($builder);
$this->addWithoutPending($builder);
$this->addOnlyPending($builder);
}
/**
* Add the with-pending extension to the builder.
*
* @param Builder<\Stancl\Tenancy\Contracts\Tenant&Model> $builder
*
* @return void
*/
protected function addWithPending(Builder $builder)
protected function addWithPending(Builder $builder): void
{
$builder->macro('withPending', function (Builder $builder, $withPending = true) {
if (! $withPending) {
@ -63,13 +51,9 @@ class PendingScope implements Scope
}
/**
* Add the without-pending extension to the builder.
*
* @param Builder<\Stancl\Tenancy\Contracts\Tenant&Model> $builder
*
* @return void
*/
protected function addWithoutPending(Builder $builder)
protected function addWithoutPending(Builder $builder): void
{
$builder->macro('withoutPending', function (Builder $builder) {
$builder->withoutGlobalScope(static::class)
@ -81,13 +65,9 @@ class PendingScope implements Scope
}
/**
* Add the only-pending extension to the builder.
*
* @param Builder<\Stancl\Tenancy\Contracts\Tenant&Model> $builder
*
* @return void
*/
protected function addOnlyPending(Builder $builder)
protected function addOnlyPending(Builder $builder): void
{
$builder->macro('onlyPending', function (Builder $builder) {
$builder->withoutGlobalScope(static::class)->whereNotNull($builder->getModel()->getColumnForQuery('pending_since'));