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

Drop support for DBAL 2 #1570

Merged
merged 8 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
9 changes: 3 additions & 6 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ jobs:
fail-fast: false
matrix:
php-version:
- "7.1"
- "7.2"
- "7.3"
- "7.4"
dmaicher marked this conversation as resolved.
Show resolved Hide resolved
dependencies:
- "highest"
Expand All @@ -37,7 +34,7 @@ jobs:
# Tests the lowest set of dependencies
- dependencies: "lowest"
stability: "stable"
php-version: "7.1"
php-version: "7.4"
symfony-deprecations-helper: "weak"

# Test legacy LTS
Expand Down Expand Up @@ -72,7 +69,7 @@ jobs:

- name: "Install PHP with XDebug"
uses: "shivammathur/setup-php@v2"
if: "${{ matrix.php-version == '7.1' }}"
if: "${{ matrix.php-version == '7.4' }}"
with:
php-version: "${{ matrix.php-version }}"
coverage: "xdebug"
Expand All @@ -81,7 +78,7 @@ jobs:

- name: "Install PHP with PCOV"
uses: "shivammathur/setup-php@v2"
if: "${{ matrix.php-version != '7.1' }}"
dmaicher marked this conversation as resolved.
Show resolved Hide resolved
if: "${{ matrix.php-version != '7.4' }}"
dmaicher marked this conversation as resolved.
Show resolved Hide resolved
with:
php-version: "${{ matrix.php-version }}"
coverage: "pcov"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
php-version:
- "7.1"
- "7.4"

steps:
- name: "Checkout code"
Expand Down
40 changes: 1 addition & 39 deletions Command/CreateDatabaseDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
namespace Doctrine\Bundle\DoctrineBundle\Command;

use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Sharding\PoolingShardConnection;
use InvalidArgumentException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Throwable;

use function array_merge;
use function in_array;
use function method_exists;
use function sprintf;
use function trigger_deprecation;

/**
* Database tool allows you to easily create your configured databases.
Expand All @@ -28,7 +25,6 @@ protected function configure(): void
$this
->setName('doctrine:database:create')
->setDescription('Creates the configured database')
->addOption('shard', 's', InputOption::VALUE_REQUIRED, 'The shard connection to use for this command')
->addOption('connection', 'c', InputOption::VALUE_OPTIONAL, 'The connection to use for this command')
->addOption('if-not-exists', null, InputOption::VALUE_NONE, 'Don\'t trigger an error, when the database already exists')
->setHelp(<<<EOT
Expand Down Expand Up @@ -60,51 +56,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$params = $params['primary'];
}

// Cannot inject `shard` option in parent::getDoctrineConnection
// cause it will try to connect to a non-existing database
if (isset($params['shards'])) {
$shards = $params['shards'];
// Default select global
$params = array_merge($params, $params['global'] ?? []);
unset($params['global']['dbname'], $params['global']['path'], $params['global']['url']);
if ($input->getOption('shard')) {
trigger_deprecation(
'doctrine/doctrine-bundle',
'2.7',
'Passing a "shard" option for "%s" is deprecated. DBAL 3 does not support shards anymore.',
self::class
);

foreach ($shards as $i => $shard) {
if ($shard['id'] === (int) $input->getOption('shard')) {
// Select sharded database
$params = array_merge($params, $shard);
unset($params['shards'][$i]['dbname'], $params['shards'][$i]['path'], $params['shards'][$i]['url'], $params['id']);
break;
}
}
}
}

$hasPath = isset($params['path']);
$name = $hasPath ? $params['path'] : ($params['dbname'] ?? false);
if (! $name) {
throw new InvalidArgumentException("Connection does not contain a 'path' or 'dbname' parameter and cannot be created.");
}

// Need to get rid of _every_ occurrence of dbname from connection configuration and we have already extracted all relevant info from url
/** @psalm-suppress InvalidArrayOffset */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the error here? Does it complain about url key? Because that looks correct to me, $connection->getParams() cannot really return url key, can it? Same in DropDatabaseDoctrineCommand

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes exactly. The error was about the url key.

$connection->getParams() cannot really return url key, can it?

Actually it can 😢 I tested it. If I configure a DBAL connection using url in the bundle config then that key is also present in connection params.

unset($params['dbname'], $params['path'], $params['url']);

$tmpConnection = DriverManager::getConnection($params);
if ($tmpConnection instanceof PoolingShardConnection) {
$tmpConnection->connect($input->getOption('shard'));
trigger_deprecation(
'doctrine/doctrine-bundle',
'2.7',
'Using a DBAL connection of type "%s" is deprecated. DBAL 3 does not support shards anymore.',
PoolingShardConnection::class
);
}

$schemaManager = method_exists($tmpConnection, 'createSchemaManager')
? $tmpConnection->createSchemaManager()
Expand Down
27 changes: 3 additions & 24 deletions Command/DoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@
namespace Doctrine\Bundle\DoctrineBundle\Command;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Sharding\PoolingShardConnection;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Tools\EntityGenerator;
use Doctrine\Persistence\ManagerRegistry;
use LogicException;
use InvalidArgumentException;
use Symfony\Component\Console\Command\Command;

use function sprintf;
use function trigger_deprecation;

/**
* Base class for Doctrine console commands to extend from.
*
Expand Down Expand Up @@ -61,24 +56,8 @@ protected function getEntityManager($name, $shardId = null)
{
$manager = $this->getDoctrine()->getManager($name);

if ($shardId) {
trigger_deprecation(
'doctrine/doctrine-bundle',
'2.7',
'Passing a "shardId" argument to "%s" is deprecated. DBAL 3 does not support shards anymore.',
__METHOD__
);

if (! $manager instanceof EntityManagerInterface) {
throw new LogicException(sprintf('Sharding is supported only in EntityManager of instance "%s".', EntityManagerInterface::class));
}

$connection = $manager->getConnection();
if (! $connection instanceof PoolingShardConnection) {
throw new LogicException(sprintf("Connection of EntityManager '%s' must implement shards configuration.", $name));
}

$connection->connect($shardId);
if ($shardId !== null) {
ostrolucky marked this conversation as resolved.
Show resolved Hide resolved
throw new InvalidArgumentException('Shards are not supported anymore using doctrine/dbal >= 3');
}

return $manager;
Expand Down
27 changes: 1 addition & 26 deletions Command/DropDatabaseDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
use Symfony\Component\Console\Output\OutputInterface;
use Throwable;

use function array_merge;
use function in_array;
use function method_exists;
use function sprintf;
use function trigger_deprecation;

/**
* Database tool allows you to easily drop your configured databases.
Expand All @@ -34,7 +32,6 @@ protected function configure()
$this
->setName('doctrine:database:drop')
->setDescription('Drops the configured database')
->addOption('shard', 's', InputOption::VALUE_REQUIRED, 'The shard connection to use for this command')
->addOption('connection', 'c', InputOption::VALUE_OPTIONAL, 'The connection to use for this command')
->addOption('if-exists', null, InputOption::VALUE_NONE, 'Don\'t trigger an error, when the database doesn\'t exist')
->addOption('force', 'f', InputOption::VALUE_NONE, 'Set this parameter to execute this action')
Expand Down Expand Up @@ -71,34 +68,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$params = $params['primary'];
}

if (isset($params['shards'])) {
$shards = $params['shards'];
// Default select global
$params = array_merge($params, $params['global'] ?? []);
if ($input->getOption('shard')) {
trigger_deprecation(
'doctrine/doctrine-bundle',
'2.7',
'Passing a "shard" option for "%s" is deprecated. DBAL 3 does not support shards anymore.',
self::class
);

foreach ($shards as $shard) {
if ($shard['id'] === (int) $input->getOption('shard')) {
// Select sharded database
$params = array_merge($params, $shard);
unset($params['id']);
break;
}
}
}
}

$name = $params['path'] ?? ($params['dbname'] ?? false);
if (! $name) {
throw new InvalidArgumentException("Connection does not contain a 'path' or 'dbname' parameter and cannot be dropped.");
}

/** @psalm-suppress InvalidArrayOffset */
unset($params['dbname'], $params['url']);

if (! $input->getOption('force')) {
Expand Down
13 changes: 1 addition & 12 deletions Command/ImportMappingDoctrineCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use function mkdir;
use function sprintf;
use function str_replace;
use function trigger_deprecation;

/**
* Import Doctrine ORM metadata mapping information from an existing database.
Expand Down Expand Up @@ -49,7 +48,6 @@ protected function configure(): void
->addArgument('name', InputArgument::REQUIRED, 'The bundle or namespace to import the mapping information to')
->addArgument('mapping-type', InputArgument::OPTIONAL, 'The mapping type to export the imported mapping information to')
->addOption('em', null, InputOption::VALUE_OPTIONAL, 'The entity manager to use for this command')
->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command')
->addOption('filter', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'A string pattern used to match entities that should be mapped.')
->addOption('force', null, InputOption::VALUE_NONE, 'Force to overwrite existing mapping files.')
->addOption('path', null, InputOption::VALUE_REQUIRED, 'The path where the files would be generated (not used when a bundle is passed).')
Expand Down Expand Up @@ -121,16 +119,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$exporter->setEntityGenerator($entityGenerator);
}

if ($input->getOption('shard')) {
trigger_deprecation(
'doctrine/doctrine-bundle',
'2.7',
'Passing a "shard" option for "%s" is deprecated. DBAL 3 does not support shards anymore.',
self::class
);
}

$em = $this->getEntityManager($input->getOption('em'), $input->getOption('shard'));
$em = $this->getEntityManager($input->getOption('em'));

$databaseDriver = new DatabaseDriver($em->getConnection()->getSchemaManager());
$em->getConfiguration()->setMetadataDriverImpl($databaseDriver);
Expand Down
18 changes: 0 additions & 18 deletions Command/Proxy/DoctrineCommandHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

namespace Doctrine\Bundle\DoctrineBundle\Command\Proxy;

use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Tools\Console\EntityManagerProvider;
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
use Symfony\Bundle\FrameworkBundle\Console\Application;

use function assert;
use function class_exists;
use function trigger_deprecation;

/**
Expand All @@ -30,10 +28,6 @@ public static function setApplicationEntityManager(Application $application, $em
$em = $application->getKernel()->getContainer()->get('doctrine')->getManager($emName);
assert($em instanceof EntityManagerInterface);
$helperSet = $application->getHelperSet();
if (class_exists(ConnectionHelper::class)) {
$helperSet->set(new ConnectionHelper($em->getConnection()), 'db');
}

$helperSet->set(new EntityManagerHelper($em), 'em');

trigger_deprecation(
Expand All @@ -44,16 +38,4 @@ public static function setApplicationEntityManager(Application $application, $em
EntityManagerProvider::class
);
}

/**
* Convenience method to push the helper sets of a given connection into the application.
*
* @param string $connName
*/
public static function setApplicationConnection(Application $application, $connName)
{
$connection = $application->getKernel()->getContainer()->get('doctrine')->getConnection($connName);
$helperSet = $application->getHelperSet();
$helperSet->set(new ConnectionHelper($connection), 'db');
}
}
44 changes: 0 additions & 44 deletions Command/Proxy/ImportDoctrineCommand.php

This file was deleted.

Loading