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

Get rid of TenantDatabaseDoesNotExist exception

This commit is contained in:
Samuel Štancl 2020-06-29 09:58:37 +02:00
parent 1e18dc3a74
commit fe52a3c4ea
6 changed files with 3 additions and 27 deletions

View file

@ -8,7 +8,6 @@ use Stancl\Tenancy\Contracts\TenancyBootstrapper;
use Stancl\Tenancy\Contracts\Tenant; use Stancl\Tenancy\Contracts\Tenant;
use Stancl\Tenancy\Contracts\TenantWithDatabase; use Stancl\Tenancy\Contracts\TenantWithDatabase;
use Stancl\Tenancy\Database\DatabaseManager; use Stancl\Tenancy\Database\DatabaseManager;
use Stancl\Tenancy\Exceptions\TenantDatabaseDoesNotExistException;
class DatabaseTenancyBootstrapper implements TenancyBootstrapper class DatabaseTenancyBootstrapper implements TenancyBootstrapper
{ {
@ -22,12 +21,6 @@ class DatabaseTenancyBootstrapper implements TenancyBootstrapper
public function bootstrap(Tenant $tenant) public function bootstrap(Tenant $tenant)
{ {
/** @var TenantWithDatabase $tenant */
$database = $tenant->database()->getName();
if (! $tenant->database()->manager()->databaseExists($database)) {
throw new TenantDatabaseDoesNotExistException($database);
}
$this->database->connectToTenant($tenant); $this->database->connectToTenant($tenant);
} }

View file

@ -21,7 +21,7 @@ class TenantCouldNotBeIdentifiedByPathException extends TenantCouldNotBeIdentifi
return BaseSolution::create('Tenant could not be identified on this path') return BaseSolution::create('Tenant could not be identified on this path')
->setSolutionDescription('Did you forget to create a tenant for this path?') ->setSolutionDescription('Did you forget to create a tenant for this path?')
->setDocumentationLinks([ ->setDocumentationLinks([
'Creating Tenants' => 'https://tenancyforlaravel.com/docs/v2/creating-tenants/', // todo update link for v3 'Creating Tenants' => 'https://tenancyforlaravel.com/docs/v3/tenants/',
]); ]);
} }
} }

View file

@ -21,7 +21,7 @@ class TenantCouldNotBeIdentifiedByRequestDataException extends TenantCouldNotBeI
return BaseSolution::create('Tenant could not be identified with this request data') return BaseSolution::create('Tenant could not be identified with this request data')
->setSolutionDescription('Did you forget to create a tenant with this id?') ->setSolutionDescription('Did you forget to create a tenant with this id?')
->setDocumentationLinks([ ->setDocumentationLinks([
'Creating Tenants' => 'https://tenancyforlaravel.com/docs/v2/creating-tenants/', // todo update link for v3 'Creating Tenants' => 'https://tenancyforlaravel.com/docs/v3/tenants/',
]); ]);
} }
} }

View file

@ -21,7 +21,7 @@ class TenantCouldNotBeIdentifiedOnDomainException extends TenantCouldNotBeIdenti
return BaseSolution::create('Tenant could not be identified on this domain') return BaseSolution::create('Tenant could not be identified on this domain')
->setSolutionDescription('Did you forget to create a tenant for this domain?') ->setSolutionDescription('Did you forget to create a tenant for this domain?')
->setDocumentationLinks([ ->setDocumentationLinks([
'Creating Tenants' => 'https://tenancyforlaravel.com/docs/v2/creating-tenants/', // todo update link for v3 'Creating Tenants' => 'https://tenancyforlaravel.com/docs/v3/tenants/',
]); ]);
} }
} }

View file

@ -1,15 +0,0 @@
<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Exceptions;
use Exception;
class TenantDatabaseDoesNotExistException extends Exception
{
public function __construct($database)
{
parent::__construct("Database $database does not exist.");
}
}

View file

@ -109,6 +109,4 @@ class CachedTenantResolverTest extends TestCase
$this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('bar'))); $this->assertTrue($tenant->is(app(DomainTenantResolver::class)->resolve('bar')));
$this->assertNotEmpty(DB::getQueryLog()); // not empty $this->assertNotEmpty(DB::getQueryLog()); // not empty
} }
// todo2 at some point in the future, we could write invalidation tests for the other resolvers too
} }