1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 17:14:03 +00:00

Remove withPending from runForMultiple

This commit is contained in:
lukinovec 2022-07-22 15:09:37 +02:00
parent c44a4c56d5
commit fd809bc81a
2 changed files with 3 additions and 33 deletions

View file

@ -9,7 +9,6 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Traits\Macroable; use Illuminate\Support\Traits\Macroable;
use Stancl\Tenancy\Contracts\TenancyBootstrapper; use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Contracts\Tenant; use Stancl\Tenancy\Contracts\Tenant;
use Stancl\Tenancy\Database\Concerns\PendingScope;
use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedById; use Stancl\Tenancy\Exceptions\TenantCouldNotBeIdentifiedById;
class Tenancy class Tenancy
@ -131,15 +130,10 @@ class Tenancy
* @param Tenant[]|\Traversable|string[]|null $tenants * @param Tenant[]|\Traversable|string[]|null $tenants
* @return void * @return void
*/ */
public function runForMultiple($tenants, callable $callback, bool $withPending = null) public function runForMultiple($tenants, callable $callback)
{ {
$query = $this->model()->newQuery();
if (is_bool($withPending) && $this->model()::hasGlobalScope(PendingScope::class)) {
$query->withPending($withPending);
}
// Convert null to all tenants // Convert null to all tenants
$tenants = is_null($tenants) ? $query->cursor() : $tenants; $tenants = is_null($tenants) ? $this->model()->cursor() : $tenants;
// Convert incrementing int ids to strings // Convert incrementing int ids to strings
$tenants = is_int($tenants) ? (string) $tenants : $tenants; $tenants = is_int($tenants) ? (string) $tenants : $tenants;
@ -148,7 +142,7 @@ class Tenancy
$tenants = is_string($tenants) ? [$tenants] : $tenants; $tenants = is_string($tenants) ? [$tenants] : $tenants;
// Use all tenants if $tenants is falsy // Use all tenants if $tenants is falsy
$tenants = $tenants ?: $query->cursor(); $tenants = $tenants ?: $this->model()->cursor();
$originalTenant = $this->tenant; $originalTenant = $this->tenant;

View file

@ -169,28 +169,4 @@ class PendingTenantsTest extends TestCase
Event::assertDispatched(PullingPendingTenant::class); Event::assertDispatched(PullingPendingTenant::class);
Event::assertDispatched(PendingTenantPulled::class); Event::assertDispatched(PendingTenantPulled::class);
} }
/** @test */
public function tenancy_run_for_multiple_can_scope_pending_tenants()
{
config(['tenancy.pending.include_in_queries' => false]);
Tenant::createPending();
Tenant::create();
$executedCount = 0;
tenancy()->runForMultiple([], function () use (&$executedCount){
$executedCount++;
}, false);
self::assertEquals(1, $executedCount);
$executedCount = 0;
tenancy()->runForMultiple([], function () use (&$executedCount){
$executedCount++;
}, true);
self::assertEquals(2, $executedCount);
}
} }