1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 21:54:03 +00:00

[2.2.4] [WIP] Respect custom connections when creating database (#244)

* Add TenantDatabaseManager::setConnection()

* Apply fixes from StyleCI
This commit is contained in:
Samuel Štancl 2019-12-11 22:16:25 +01:00 committed by GitHub
parent 5145b1f13e
commit fed8c0f9d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 5 deletions

View file

@ -8,6 +8,7 @@ use Closure;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Database\DatabaseManager as BaseDatabaseManager;
use Illuminate\Foundation\Application;
use Stancl\Tenancy\Contracts\Future\CanSetConnection;
use Stancl\Tenancy\Contracts\TenantDatabaseManager;
use Stancl\Tenancy\Exceptions\DatabaseManagerNotRegisteredException;
use Stancl\Tenancy\Exceptions\TenantDatabaseAlreadyExistsException;
@ -226,7 +227,7 @@ class DatabaseManager
*/
public function getTenantDatabaseManager(Tenant $tenant): TenantDatabaseManager
{
$driver = $this->getDriver($this->getBaseConnection($tenant->getConnectionName()));
$driver = $this->getDriver($this->getBaseConnection($connectionName = $tenant->getConnectionName()));
$databaseManagers = $this->app['config']['tenancy.database_managers'];
@ -234,6 +235,12 @@ class DatabaseManager
throw new DatabaseManagerNotRegisteredException($driver);
}
return $this->app[$databaseManagers[$driver]];
$databaseManager = $this->app[$databaseManagers[$driver]];
if ($connectionName !== 'tenant' && $databaseManager instanceof CanSetConnection) {
$databaseManager->setConnection($this->database->connection($connectionName));
}
return $databaseManager;
}
}