|
5 | 5 | use Doctrine\DBAL\Connection; |
6 | 6 | use Doctrine\DBAL\Driver\PDO\MySQL\Driver as PDOMySqlDriver; |
7 | 7 | use Doctrine\DBAL\DriverManager; |
| 8 | +use Doctrine\DBAL\Tools\DsnParser; |
8 | 9 | use RuntimeException; |
9 | 10 | use Symfony\Component\Console\Command\Command; |
10 | 11 | use Symfony\Component\Console\Input\InputArgument; |
@@ -69,7 +70,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int |
69 | 70 | $progressOutput = $this->createProgressOutput($input, $output); |
70 | 71 |
|
71 | 72 | $connection = $this->createConnection($input); |
72 | | - $connection->getEventManager()->addEventSubscriber(new DummyTypeRegistrationEventSubscriber($connection->getSchemaManager())); |
| 73 | + |
| 74 | + // In DBAL 3, the SchemaManager parses DC2Type column comments and throws when encountering |
| 75 | + // unknown types. We register a DummyType for any unknown type to work around this. |
| 76 | + // In DBAL 4, the DC2Type comment mechanism was removed entirely, so this is no longer needed. |
| 77 | + if (class_exists(\Doctrine\DBAL\Events::class)) { |
| 78 | + $connection->getEventManager()->addEventSubscriber(new DummyTypeRegistrationEventSubscriber($connection->createSchemaManager())); |
| 79 | + } |
| 80 | + |
73 | 81 | $this->setMaxExecutionTimeUnlimited($connection, $progressOutput); |
74 | 82 |
|
75 | 83 | $config = ConfigBuilder::createConfigurationFromConsecutiveFiles($input->getArgument('config')); |
@@ -146,8 +154,16 @@ private function createConnection(InputInterface $input): Connection |
146 | 154 | } |
147 | 155 |
|
148 | 156 | $mysqliIndependentDsn = preg_replace('_^mysqli:_', 'mysql:', $dsn); |
| 157 | + |
| 158 | + if (class_exists(DsnParser::class)) { |
| 159 | + // DBAL 4: the 'url' connection parameter was removed in favour of DsnParser |
| 160 | + $params = (new DsnParser(['mysql' => 'pdo_mysql']))->parse($mysqliIndependentDsn); |
| 161 | + } else { |
| 162 | + $params = ['url' => $mysqliIndependentDsn]; |
| 163 | + } |
| 164 | + |
149 | 165 | $connection = DriverManager::getConnection( |
150 | | - ['url' => $mysqliIndependentDsn, 'charset' => 'utf8', 'driverClass' => PDOMySqlDriver::class] |
| 166 | + array_merge($params, ['charset' => 'utf8', 'driverClass' => PDOMySqlDriver::class]) |
151 | 167 | ); |
152 | 168 |
|
153 | 169 | return $connection; |
|
0 commit comments