mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 21:14:03 +00:00
Finalize GlobalCache-related changes
This commit is contained in:
parent
a760c52ef2
commit
4129b2d956
3 changed files with 12 additions and 8 deletions
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
|
|
@ -16,7 +16,7 @@ jobs:
|
|||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- laravel: "12.x-dev" # todo0 revert
|
||||
- laravel: "^12.0"
|
||||
php: "8.4"
|
||||
|
||||
steps:
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ namespace Stancl\Tenancy\Bootstrappers;
|
|||
|
||||
use Exception;
|
||||
use Illuminate\Cache\CacheManager;
|
||||
use Illuminate\Cache\DatabaseStore;
|
||||
use Illuminate\Config\Repository;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||
|
|
@ -13,10 +14,10 @@ use Stancl\Tenancy\Contracts\Tenant;
|
|||
use Stancl\Tenancy\TenancyServiceProvider;
|
||||
|
||||
/**
|
||||
* This bootstrapper allows cache to be stored in the tenant databases by switching
|
||||
* the database cache store's (and cache locks) connection.
|
||||
* This bootstrapper allows cache to be stored in tenant databases by switching the database
|
||||
* connection used by cache stores that use the database driver.
|
||||
*
|
||||
* Intended to be used with database driver-based cache stores, instead of CacheTenancyBootstrapper.
|
||||
* Can be used instead of CacheTenancyBootstrapper.
|
||||
*
|
||||
* On bootstrap(), all database cache stores' connections are set to 'tenant'
|
||||
* and the database cache stores are purged from the CacheManager's resolved stores.
|
||||
|
|
@ -69,11 +70,11 @@ class DatabaseCacheBootstrapper implements TenancyBootstrapper
|
|||
|
||||
TenancyServiceProvider::$adjustCacheManagerUsing = static function (CacheManager $manager) use ($originalConnections) {
|
||||
foreach ($originalConnections as $storeName => $connections) {
|
||||
// @phpstan-ignore-next-line method.notFound
|
||||
$manager->store($storeName)->getStore()->setConnection(DB::connection($connections['connection']));
|
||||
/** @var DatabaseStore $store */
|
||||
$store = $manager->store($storeName)->getStore();
|
||||
|
||||
// @phpstan-ignore-next-line method.notFound
|
||||
$manager->store($storeName)->getStore()->setLockConnection(DB::connection($connections['lockConnection']));
|
||||
$store->setConnection(DB::connection($connections['connection']));
|
||||
$store->setLockConnection(DB::connection($connections['lockConnection']));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,6 +97,9 @@ class TenancyServiceProvider extends ServiceProvider
|
|||
// When we use the DatabaseTenancyBootstrapper, it changes the default connection,
|
||||
// and therefore the connection of the database store that will be created when
|
||||
// this new CacheManager is instantiated again.
|
||||
//
|
||||
// For that reason, we also adjust the relevant stores on this new CacheManager
|
||||
// using the callback below. It is set by DatabaseCacheBootstrapper.
|
||||
$manager = new CacheManager($app);
|
||||
|
||||
if (static::$adjustCacheManagerUsing !== null) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue