previousConnection = $this->batchRepository->getConnection(); $this->batchRepository->setConnection($this->databaseManager->connection('tenant')); } public function revert() { if ($this->previousConnection) { // Replace batch repository connection with the previously replaced one $this->batchRepository->setConnection($this->previousConnection); $this->previousConnection = null; } } }