diff --git a/src/Synchronization/Executor/DataTransfer.php b/src/Synchronization/Executor/DataTransfer.php index bd3361d..a26afcd 100644 --- a/src/Synchronization/Executor/DataTransfer.php +++ b/src/Synchronization/Executor/DataTransfer.php @@ -34,17 +34,21 @@ class DataTransfer implements DataTransferInterface * where ids are those already inserted for the given table. */ protected array $tableIdInserted = []; + protected PDOConnectionInterface $distantPDOConnection; + protected PDOConnectionInterface $localPDOConnection; public function __construct(ConfigurationProviderInterface $configurationProvider, PDOConnectionInterface $distantPDOConnection, PDOConnectionInterface $localPDOConnection, SqlBuilder $sqlBuilder) { - $this->dbDistant = $distantPDOConnection->getPDO(); - $this->dbLocale = $localPDOConnection->getPDO(); $this->configurationProvider = $configurationProvider; $this->sqlBuilder = $sqlBuilder; + $this->distantPDOConnection = $distantPDOConnection; + $this->localPDOConnection = $localPDOConnection; } public function fromDistantToLocal(array $tableModels): void { + $this->dbLocale = $this->localPDOConnection->getPDO(); + $this->dbDistant = $this->distantPDOConnection->getPDO(); $this->tableModels = $tableModels; $this->removeDisabledTables(); $this->fillCurrentTableReferenced(); diff --git a/src/Synchronization/Executor/SqlBuilder.php b/src/Synchronization/Executor/SqlBuilder.php index 9c49201..8790240 100644 --- a/src/Synchronization/Executor/SqlBuilder.php +++ b/src/Synchronization/Executor/SqlBuilder.php @@ -13,15 +13,17 @@ class SqlBuilder protected ConfigurationProviderInterface $configurationProvider; protected \PDO $dbLocale; protected array $tableModels = []; + protected PDOConnectionInterface $localPDOConnection; public function __construct(ConfigurationProviderInterface $configurationProvider, PDOConnectionInterface $localPDOConnection) { $this->configurationProvider = $configurationProvider; - $this->dbLocale = $localPDOConnection->getPDO(); + $this->localPDOConnection = $localPDOConnection; } public function selectQuery(array $tableModels, string $tableName, array $columns, array $forceIds = [], array $exceptsIds = []): string { + $this->dbLocale = $this->localPDOConnection->getPDO(); $this->tableModels = $tableModels; $andWhere = $this->getWhere($tableName, $forceIds); diff --git a/src/Synchronization/Provider/TableModelProvider.php b/src/Synchronization/Provider/TableModelProvider.php index acbad60..750a1f7 100644 --- a/src/Synchronization/Provider/TableModelProvider.php +++ b/src/Synchronization/Provider/TableModelProvider.php @@ -21,16 +21,20 @@ class TableModelProvider implements TableModelProviderInterface, OutputAwareInte protected \PDO $dbLocale; protected \PDO $dbDistant; protected ConfigurationProviderInterface $configurationProvider; + protected PDOConnectionInterface $distantPDOConnection; + protected PDOConnectionInterface $localPDOConnection; public function __construct(ConfigurationProviderInterface $configurationProvider, PDOConnectionInterface $distantPDOConnection, PDOConnectionInterface $localPDOConnection) { $this->configurationProvider = $configurationProvider; - $this->dbLocale = $localPDOConnection->getPDO(); - $this->dbDistant = $distantPDOConnection->getPDO(); + $this->distantPDOConnection = $distantPDOConnection; + $this->localPDOConnection = $localPDOConnection; } public function provideAll(): array { + $this->dbLocale = $this->localPDOConnection->getPDO(); + $this->dbDistant = $this->distantPDOConnection->getPDO(); $this->writeln("-----------------------------------"); $this->writeln("Generation of Tables Models started"); $this->writeln("-----------------------------------");