Skip to content

Commit

Permalink
Merge pull request #8 from BinarCode/command-interactions
Browse files Browse the repository at this point in the history
Asking for command and tenant
  • Loading branch information
freekmurze authored May 18, 2020
2 parents 888ddbe + 8dfb455 commit 27ad57e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/Commands/TenantsArtisanCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\Multitenancy\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Artisan;
use Spatie\Multitenancy\Models\Tenant;

Expand All @@ -14,11 +15,17 @@ public function handle()
{
$tenantQuery = Tenant::query();

if ($tenantIds = $this->option('tenant')) {
$tenantQuery = $tenantQuery->whereIn('id', $tenantIds);
if (!$artisanCommand = $this->argument('artisanCommand')) {
$artisanCommand = $this->ask('Command to run?');
}

$artisanCommand = $this->argument('artisanCommand');
if (!$tenantIds = $this->option('tenant')) {
$tenantIds = $this->ask('What tenant ID? Nothing for all tenants.');
}

if ($tenantIds) {
$tenantQuery->whereIn('id', Arr::wrap($tenantIds));
}

$tenantQuery
->cursor()
Expand Down
4 changes: 3 additions & 1 deletion tests/Feature/Commands/TenantsArtisanCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public function setUp(): void
/** @test */
public function it_can_migrate_all_tenant_databases()
{
$this->artisan('tenants:artisan migrate')->assertExitCode(0);
$this->artisan('tenants:artisan migrate')
->expectsQuestion('What tenant ID? Nothing for all tenants.', '')
->assertExitCode(0);

$this
->assertTenantDatabaseHasTable($this->tenant, 'migrations')
Expand Down

0 comments on commit 27ad57e

Please sign in to comment.