mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 18:34:04 +00:00
convert batch class resolution to property level
This commit is contained in:
parent
df172ffc23
commit
8211ddb38a
1 changed files with 10 additions and 9 deletions
|
|
@ -19,23 +19,24 @@ class BatchTenancyBootstrapper implements TenancyBootstrapper
|
||||||
*/
|
*/
|
||||||
protected $previousConnection = null;
|
protected $previousConnection = null;
|
||||||
|
|
||||||
|
public function __construct(protected BatchRepository $batchRepository)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public function bootstrap(Tenant $tenant)
|
public function bootstrap(Tenant $tenant)
|
||||||
{
|
{
|
||||||
$batchRepository = app(BatchRepository::class);
|
if ($this->batchRepository instanceof DatabaseBatchRepository) {
|
||||||
|
// Update batch repository connection to use the tenant connection
|
||||||
if ($batchRepository instanceof DatabaseBatchRepository) {
|
$this->previousConnection = $this->batchRepository->getConnection();
|
||||||
// Access the resolved batch repository instance and update its connection to use the tenant connection
|
$this->batchRepository->setConnection(DB::connection('tenant'));
|
||||||
$this->previousConnection = $batchRepository->getConnection();
|
|
||||||
$batchRepository->setConnection(DB::connection('tenant'));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function revert()
|
public function revert()
|
||||||
{
|
{
|
||||||
if ($this->previousConnection) {
|
if ($this->previousConnection) {
|
||||||
// Access the resolved batch repository instance and replace its connection with the previously replaced one
|
// Replace batch repository connection with the previously replaced one
|
||||||
$batchRepository = app(BatchRepository::class);
|
$this->batchRepository->setConnection($this->previousConnection);
|
||||||
$batchRepository->setConnection($this->previousConnection);
|
|
||||||
$this->previousConnection = null;
|
$this->previousConnection = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue