From bb4dc196b0472a245f24eb06a33cfcd530c9cf46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Sat, 26 Oct 2019 21:17:28 +0200 Subject: [PATCH 1/3] [2.2.0] Make tenancy initialization in global MW stack optional (#203) * Make tenancy initialization in global MW stack optional * update config key --- assets/config.php | 1 + src/TenancyServiceProvider.php | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/assets/config.php b/assets/config.php index 8c504d63..9f0023c9 100644 --- a/assets/config.php +++ b/assets/config.php @@ -98,4 +98,5 @@ return [ 'queue_database_deletion' => false, 'delete_database_after_tenant_deletion' => false, // delete the tenant's database after deleting the tenant 'unique_id_generator' => Stancl\Tenancy\UniqueIDGenerators\UUIDGenerator::class, + 'push_initialization_middleware_to_global_stack' => true, ]; diff --git a/src/TenancyServiceProvider.php b/src/TenancyServiceProvider.php index 9687fed6..d475a081 100644 --- a/src/TenancyServiceProvider.php +++ b/src/TenancyServiceProvider.php @@ -78,7 +78,9 @@ class TenancyServiceProvider extends ServiceProvider __DIR__ . '/../assets/migrations/' => database_path('migrations'), ], 'migrations'); - $this->app->make(Kernel::class)->prependMiddleware(Middleware\InitializeTenancy::class); + if ($this->app['config']['tenancy.push_initialization_middleware_to_global_stack'] ?? true) { + $this->app->make(Kernel::class)->prependMiddleware(Middleware\InitializeTenancy::class); + } /* * Since tenancy is initialized in the global middleware stack, this From 77df4675676fca2391d8cb9a4fd948057dcfacc9 Mon Sep 17 00:00:00 2001 From: JapSeyz Date: Sat, 26 Oct 2019 21:18:03 +0200 Subject: [PATCH 2/3] Fixes an issue where tests wouldn't have tenants in the tearDown method (#198) * Fixes an issue where tests wouldn't have tenants in the tearDown method * Styling --- src/TenantManager.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/TenantManager.php b/src/TenantManager.php index 9144d2f4..5fe60e90 100644 --- a/src/TenantManager.php +++ b/src/TenantManager.php @@ -259,6 +259,10 @@ class TenantManager public function endTenancy(): self { + if (! $this->initialized) { + return $this; + } + $prevented = $this->event('ending'); foreach ($this->tenancyBootstrappers($prevented) as $bootstrapper) { From b4caaaed51f5adeccfae4f28546531c2f7b48895 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Sat, 26 Oct 2019 22:01:01 +0200 Subject: [PATCH 3/3] Add comments to config --- assets/config.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/config.php b/assets/config.php index 9f0023c9..e80edfb0 100644 --- a/assets/config.php +++ b/assets/config.php @@ -11,7 +11,7 @@ return [ 'custom_columns' => [ // 'plan', ], - 'connection' => null, + 'connection' => null, // Your central database connection. Set to null to use the default connection. 'table_names' => [ 'TenantModel' => 'tenants', 'DomainModel' => 'domains', @@ -27,7 +27,7 @@ return [ // 'localhost', ], 'database' => [ - 'based_on' => null, // The connection that will be used as a base for the dynamically created tenant connection. + 'based_on' => null, // The connection that will be used as a base for the dynamically created tenant connection. Set to null to use the default connection. 'prefix' => 'tenant', 'suffix' => '', ],