From be188136a2f353fcf76e52d91e93d1a18013feef Mon Sep 17 00:00:00 2001 From: Bizley Date: Wed, 10 Feb 2021 17:38:00 +0100 Subject: [PATCH] Fixed bug with multiple db connections for multiple updates --- src/Extractor.php | 2 +- src/controllers/BaseMigrationController.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Extractor.php b/src/Extractor.php index dd868819..b752e157 100644 --- a/src/Extractor.php +++ b/src/Extractor.php @@ -63,7 +63,7 @@ public function extract(string $migration, array $migrationPaths): void require_once $file; } - $this->subject = new $migration(['db' => clone $this->db, 'experimental' => $this->experimental]); + $this->subject = new $migration(['db' => $this->db, 'experimental' => $this->experimental]); if ($this->subject instanceof MigrationChangesInterface === false) { throw new ErrorException( "Class '{$migration}' must implement bizley\migration\dummy\MigrationChangesInterface." diff --git a/src/controllers/BaseMigrationController.php b/src/controllers/BaseMigrationController.php index 69eb4371..80f6db38 100644 --- a/src/controllers/BaseMigrationController.php +++ b/src/controllers/BaseMigrationController.php @@ -36,6 +36,7 @@ use yii\console\Controller; use yii\db\Connection; use yii\db\Query; +use yii\di\Instance; /** * This is the foundation of MigrationController. All services are registered here. @@ -278,7 +279,9 @@ public function getGenerator(): GeneratorInterface public function getExtractor(): ExtractorInterface { if ($this->extractor === null) { - $configuredObject = Yii::createObject($this->extractorClass, [$this->db, $this->experimental]); + $db = Instance::ensure($this->db, Connection::class); + // cloning connection here to not force reconnecting on each extraction + $configuredObject = Yii::createObject($this->extractorClass, [clone $db, $this->experimental]); if (!$configuredObject instanceof ExtractorInterface) { throw new InvalidConfigException('Extractor must implement bizley\migration\ExtractorInterface.'); }