mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-13 23:34:03 +00:00
Rename bootstrappers (#40)
* SessionTenancyBootstrapper -> DatabaseSessionBootstrapper * FortifyRouteTenancyBootstrapper -> FortifyRouteBootstrapper * BatchTenancyBootstrapper -> JobBatchBootstrapper * ScoutTenancyBootstrapper -> ScoutPrefixBootstrapper, also fix logic and remove todo * MailTenancyBootstrapper -> MailConfigBootstrapper * PrefixCacheTenancyBootstrapper -> CacheTenancyBootstrapper * remove todo * improve config file
This commit is contained in:
parent
0c11f29c19
commit
9f94505cb4
16 changed files with 82 additions and 82 deletions
|
|
@ -1,42 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy\Bootstrappers;
|
||||
|
||||
use Illuminate\Bus\DatabaseBatchRepository;
|
||||
use Illuminate\Database\Connection;
|
||||
use Illuminate\Database\DatabaseManager;
|
||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||
use Stancl\Tenancy\Contracts\Tenant;
|
||||
|
||||
// todo add docblock
|
||||
class BatchTenancyBootstrapper implements TenancyBootstrapper
|
||||
{
|
||||
/**
|
||||
* The previous database connection instance.
|
||||
*/
|
||||
protected ?Connection $previousConnection = null;
|
||||
|
||||
public function __construct(
|
||||
protected DatabaseBatchRepository $batchRepository,
|
||||
protected DatabaseManager $databaseManager
|
||||
) {
|
||||
}
|
||||
|
||||
public function bootstrap(Tenant $tenant): void
|
||||
{
|
||||
// Update batch repository connection to use the tenant connection
|
||||
$this->previousConnection = $this->batchRepository->getConnection();
|
||||
$this->batchRepository->setConnection($this->databaseManager->connection('tenant'));
|
||||
}
|
||||
|
||||
public function revert(): void
|
||||
{
|
||||
if ($this->previousConnection) {
|
||||
// Replace batch repository connection with the previously replaced one
|
||||
$this->batchRepository->setConnection($this->previousConnection);
|
||||
$this->previousConnection = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue