Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump DBAL and remove compat code #1402

Merged
merged 1 commit into from
Sep 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions CacheWarmer/DoctrineMetadataCacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
use LogicException;
use Symfony\Bundle\FrameworkBundle\CacheWarmer\AbstractPhpFileCacheWarmer;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\DoctrineProvider;

use function is_file;
use function method_exists;

class DoctrineMetadataCacheWarmer extends AbstractPhpFileCacheWarmer
{
Expand Down Expand Up @@ -49,13 +47,7 @@ protected function doWarmUp($cacheDir, ArrayAdapter $arrayAdapter): bool
throw new LogicException('DoctrineMetadataCacheWarmer must load metadata first, check priority of your warmers.');
}

if (method_exists($metadataFactory, 'setCache')) {
$metadataFactory->setCache($arrayAdapter);
} elseif ($metadataFactory instanceof AbstractClassMetadataFactory) {
// BC with doctrine/persistence < 2.2
$metadataFactory->setCacheDriver(new DoctrineProvider($arrayAdapter));
}

$metadataFactory->setCache($arrayAdapter);
$metadataFactory->getAllMetadata();

return true;
Expand Down
15 changes: 3 additions & 12 deletions ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\AbstractMySQLDriver;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Exception as DBALException;
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;

use function array_merge;
use function class_exists;
use function is_subclass_of;
use function trigger_deprecation;

Expand Down Expand Up @@ -62,11 +60,7 @@ public function createConnection(array $params, ?Configuration $config = null, ?

if (isset($params['wrapperClass'])) {
if (! is_subclass_of($params['wrapperClass'], Connection::class)) {
if (class_exists(DBALException::class)) {
throw DBALException::invalidWrapperClass($params['wrapperClass']);
}

throw Exception::invalidWrapperClass($params['wrapperClass']);
throw DBALException::invalidWrapperClass($params['wrapperClass']);
}

$wrapperClass = $params['wrapperClass'];
Expand Down Expand Up @@ -122,16 +116,13 @@ public function createConnection(array $params, ?Configuration $config = null, ?
* For details have a look at DoctrineBundle issue #673.
*
* @throws DBALException
* @throws Exception
*/
private function getDatabasePlatform(Connection $connection): AbstractPlatform
{
try {
return $connection->getDatabasePlatform();
} catch (DriverException $driverException) {
$exceptionClass = class_exists(DBALException::class) ? DBALException::class : Exception::class;

throw new $exceptionClass(
throw new DBALException(
'An exception occurred while establishing a connection to figure out your platform version.' . PHP_EOL .
"You can circumvent this by setting a 'server_version' configuration value" . PHP_EOL . PHP_EOL .
'For further information have a look at:' . PHP_EOL .
Expand Down
24 changes: 5 additions & 19 deletions DependencyInjection/DoctrineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
use Doctrine\Bundle\DoctrineBundle\EventSubscriber\EventSubscriberInterface;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Connections\MasterSlaveConnection;
use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection;
use Doctrine\DBAL\Logging\LoggerChain;
use Doctrine\DBAL\SQLParserUtils;
use Doctrine\DBAL\Tools\Console\Command\ImportCommand;
use Doctrine\DBAL\Tools\Console\ConnectionProvider;
use Doctrine\ORM\EntityManagerInterface;
Expand Down Expand Up @@ -107,12 +105,7 @@ protected function dbalLoad(array $config, ContainerBuilder $container)
$loader->load('dbal.xml');
$chainLogger = $container->getDefinition('doctrine.dbal.logger.chain');
$logger = new Reference('doctrine.dbal.logger');
if (! method_exists(SQLParserUtils::class, 'getPositionalPlaceholderPositions') && method_exists(LoggerChain::class, 'addLogger')) {
// doctrine/dbal < 2.10.0
$chainLogger->addMethodCall('addLogger', [$logger]);
} else {
$chainLogger->addArgument([$logger]);
}
$chainLogger->addArgument([$logger]);

if (class_exists(ImportCommand::class)) {
$container->register('doctrine.database_import_command', ImportDoctrineCommand::class)
Expand Down Expand Up @@ -181,12 +174,7 @@ protected function loadDbalConnection($name, array $connection, ContainerBuilder
'doctrine.dbal.logger.chain',
LoggerChain::class
);
if (! method_exists(SQLParserUtils::class, 'getPositionalPlaceholderPositions') && method_exists(LoggerChain::class, 'addLogger')) {
// doctrine/dbal < 2.10.0
$chainLogger->addMethodCall('addLogger', [$profilingLogger]);
} else {
$chainLogger->addArgument([$logger, $profilingLogger]);
}
$chainLogger->addArgument([$logger, $profilingLogger]);

$loggerId = 'doctrine.dbal.logger.chain.' . $name;
$container->setDefinition($loggerId, $chainLogger);
Expand Down Expand Up @@ -315,7 +303,7 @@ protected function getConnectionOptions(array $connection): array
'options' => 'driverOptions',
'driver_class' => 'driverClass',
'wrapper_class' => 'wrapperClass',
'keep_slave' => class_exists(PrimaryReadReplicaConnection::class) ? 'keepReplica' : 'keepSlave',
'keep_slave' => 'keepReplica',
'keep_replica' => 'keepReplica',
'replicas' => 'replica',
'shard_choser' => 'shardChoser',
Expand Down Expand Up @@ -364,15 +352,13 @@ protected function getConnectionOptions(array $connection): array
continue;
}

$options[class_exists(PrimaryReadReplicaConnection::class) ? 'primary' : 'master'][$key] = $value;
$options['primary'][$key] = $value;
unset($options[$key]);
}

if (empty($options['wrapperClass'])) {
// Change the wrapper class only if user did not configure custom one.
$options['wrapperClass'] = class_exists(PrimaryReadReplicaConnection::class) ?
PrimaryReadReplicaConnection::class : // dbal >= 2.11
MasterSlaveConnection::class; // dbal < 2.11
$options['wrapperClass'] = PrimaryReadReplicaConnection::class;
}
} else {
unset($options['slaves'], $options['replica']);
Expand Down
10 changes: 2 additions & 8 deletions Tests/Command/DropDatabaseDoctrineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

use Doctrine\Bundle\DoctrineBundle\Command\DropDatabaseDoctrineCommand;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Exception as DBALException;
use Doctrine\Persistence\ManagerRegistry;
use Generator;
use PHPUnit\Framework\MockObject\MockObject;
Expand All @@ -16,7 +15,6 @@
use Symfony\Component\DependencyInjection\Container;

use function array_merge;
use function class_exists;
use function sprintf;
use function sys_get_temp_dir;

Expand Down Expand Up @@ -67,11 +65,7 @@ public function testExecute(array $options): void
*/
public function testItThrowsWhenUsingIfExistsWithAnIncompatibleDriver(array $options): void
{
if (class_exists(DBALException::class)) {
$this->expectException(DBALException::class);
} else {
$this->expectException(Exception::class);
}
$this->expectException(DBALException::class);

$this->testExecute($options);
}
Expand Down
8 changes: 2 additions & 6 deletions Tests/ConnectionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\API\ExceptionConverter;
use Doctrine\DBAL\Driver\Exception as InternalDriverException;
use Doctrine\DBAL\Exception as DBALException;
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
Expand Down Expand Up @@ -42,11 +42,7 @@ public function testContainer(): void
// put the mock into the fake driver
FakeDriver::$exception = $exception;

if (class_exists(DBALException::class)) {
$this->expectException(DBALException::class);
} else {
$this->expectException(\Doctrine\DBAL\Exception::class);
}
$this->expectException(DBALException::class);

try {
$factory->createConnection($params, $config, $eventManager, $mappingTypes);
Expand Down
9 changes: 1 addition & 8 deletions Tests/DependencyInjection/AbstractDoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Doctrine\Common\Cache\CacheProvider;
use Doctrine\Common\Cache\Psr6\DoctrineProvider;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connections\MasterSlaveConnection;
use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection;
use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\EntityManager;
Expand All @@ -35,7 +34,6 @@
use function array_keys;
use function array_values;
use function assert;
use function class_exists;
use function interface_exists;
use function method_exists;
use function sprintf;
Expand Down Expand Up @@ -185,12 +183,7 @@ public function testDbalLoadSingleMasterSlaveConnection(): void
$container = $this->loadContainer('dbal_service_single_master_slave_connection');
$param = $container->getDefinition('doctrine.dbal.default_connection')->getArgument(0);

$this->assertEquals(
class_exists(PrimaryReadReplicaConnection::class) ?
PrimaryReadReplicaConnection::class : // dbal >= 2.11
MasterSlaveConnection::class, // dbal < 2.11,x
$param['wrapperClass']
);
$this->assertEquals(PrimaryReadReplicaConnection::class, $param['wrapperClass']);
$this->assertTrue($param['keepReplica']);
$this->assertEquals(
[
Expand Down
4 changes: 0 additions & 4 deletions Tests/DependencyInjection/DoctrineExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -743,10 +743,6 @@ public function testAnnotationsBundleMappingDetection(): void

public function testAttributesBundleMappingDetection(): void
{
if (! class_exists(AttributeDriver::class)) {
self::markTestSkipped('This test requires ORM 2.9 with attribute driver.');
}

if (PHP_VERSION_ID < 70400) {
self::markTestSkipped('This test requires PHP 7.4.');
}
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"php": "^7.1 || ^8.0",
"doctrine/annotations": "^1",
"doctrine/cache": "^1.11 || ^2.0",
"doctrine/dbal": "^2.9.0|^3.0",
"doctrine/persistence": "^1.3.3|^2.0",
"doctrine/dbal": "^2.13.1|^3.1",
"doctrine/persistence": "^2.2",
"doctrine/sql-formatter": "^1.0.1",
"symfony/cache": "^4.3.3|^5.0|^6.0",
"symfony/config": "^4.4.3|^5.0|^6.0",
Expand Down