1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 13:14:05 +00:00

convert batch class resolution to property level

This commit is contained in:
Abrar Ahmad 2022-09-13 11:24:59 +05:00
parent df172ffc23
commit 8211ddb38a

View file

@ -19,23 +19,24 @@ class BatchTenancyBootstrapper implements TenancyBootstrapper
*/
protected $previousConnection = null;
public function __construct(protected BatchRepository $batchRepository)
{
}
public function bootstrap(Tenant $tenant)
{
$batchRepository = app(BatchRepository::class);
if ($batchRepository instanceof DatabaseBatchRepository) {
// Access the resolved batch repository instance and update its connection to use the tenant connection
$this->previousConnection = $batchRepository->getConnection();
$batchRepository->setConnection(DB::connection('tenant'));
if ($this->batchRepository instanceof DatabaseBatchRepository) {
// Update batch repository connection to use the tenant connection
$this->previousConnection = $this->batchRepository->getConnection();
$this->batchRepository->setConnection(DB::connection('tenant'));
}
}
public function revert()
{
if ($this->previousConnection) {
// Access the resolved batch repository instance and replace its connection with the previously replaced one
$batchRepository = app(BatchRepository::class);
$batchRepository->setConnection($this->previousConnection);
// Replace batch repository connection with the previously replaced one
$this->batchRepository->setConnection($this->previousConnection);
$this->previousConnection = null;
}
}