Skip to content

Commit

Permalink
Deprecated Doctrine\DBAL\Driver::getName() (#152)
Browse files Browse the repository at this point in the history
* Deprecated Doctrine\DBAL\Driver::getName()

Use driver's class name since Driver::getName() has been removed in Doctrine DBAL 3.

* Fix coding standard

* Use Connection::fetchOne() when Doctrine DBAL 3 is used

* Fix coding standard

* Limit doctrine/dbal to >= 2.13
  • Loading branch information
gjuric authored Oct 20, 2021
1 parent 54d797a commit aabf34d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
"symfony/phpunit-bridge": "^4.4 || ^5.0",
"theofidry/alice-data-fixtures": "^1.0.1"
},
"conflict": {
"doctrine/dbal": "<2.13"
},
"suggest": {
"doctrine/dbal": "Required when using the fixture loading functionality with an ORM and SQLite",
"doctrine/doctrine-fixtures-bundle": "Required when using the fixture loading functionality",
Expand Down
2 changes: 1 addition & 1 deletion src/Services/DatabaseToolCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function get($omName = null, $registryName = 'doctrine', int $purgeMode =
{
/** @var ManagerRegistry $registry */
$registry = $this->container->get($registryName);
$driverName = ('ORM' === $registry->getName()) ? $registry->getConnection()->getDriver()->getName() : 'default';
$driverName = ('ORM' === $registry->getName()) ? \get_class($registry->getConnection()->getDriver()) : 'default';

$databaseTool = isset($this->items[$registry->getName()][$driverName])
? $this->items[$registry->getName()][$driverName]
Expand Down
8 changes: 7 additions & 1 deletion src/Services/DatabaseTools/ORMDatabaseTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,13 @@ protected function disableForeignKeyChecksIfApplicable(): void
return;
}

$currentValue = $this->connection->fetchColumn('SELECT @@SESSION.foreign_key_checks');
// Doctrine DBAL 2.x deprecated fetchColumn() in favor of fetchOne()
if (method_exists($this->connection, 'fetchColumn')) {
$currentValue = $this->connection->fetchColumn('SELECT @@SESSION.foreign_key_checks');
} else {
$currentValue = $this->connection->fetchOne('SELECT @@SESSION.foreign_key_checks');
}

if ('0' === $currentValue) {
return;
}
Expand Down
11 changes: 9 additions & 2 deletions src/Services/DatabaseTools/ORMSqliteDatabaseTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

use Doctrine\Common\DataFixtures\Executor\AbstractExecutor;
use Doctrine\Common\DataFixtures\ProxyReferenceRepository;
use Doctrine\DBAL\Driver\PDO\SQLite\Driver;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\ORM\Tools\SchemaTool;
use Liip\TestFixturesBundle\Event\FixtureEvent;
Expand All @@ -35,7 +36,7 @@ class ORMSqliteDatabaseTool extends ORMDatabaseTool

public function getDriverName(): string
{
return 'pdo_sqlite';
return Driver::class;
}

public function loadFixtures(array $classNames = [], bool $append = false): AbstractExecutor
Expand Down Expand Up @@ -112,7 +113,13 @@ protected function disableForeignKeyChecksIfApplicable(): void
return;
}

$currentValue = $this->connection->fetchColumn('PRAGMA foreign_keys');
// Doctrine DBAL 2.x deprecated fetchColumn() in favor of fetchOne()
if (method_exists($this->connection, 'fetchColumn')) {
$currentValue = $this->connection->fetchColumn('PRAGMA foreign_keys');
} else {
$currentValue = $this->connection->fetchOne('PRAGMA foreign_keys');
}

if ('0' === $currentValue) {
return;
}
Expand Down

0 comments on commit aabf34d

Please sign in to comment.