Skip to content

Commit

Permalink
Revert "chore: remove getPlatformName()"
Browse files Browse the repository at this point in the history
This reverts commit 1894de4.
  • Loading branch information
alexislefebvre committed Jul 2, 2024
1 parent 2f0ecae commit 2ca04d2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/Services/DatabaseTools/AbstractDatabaseTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,6 @@ protected function getCacheMetadataParameter()
return $this->container->hasParameter(self::CACHE_METADATA_PARAMETER_NAME)
&& false !== $this->container->getParameter(self::CACHE_METADATA_PARAMETER_NAME);
}

abstract protected function getPlatformName(): string;
}
47 changes: 47 additions & 0 deletions src/Services/DatabaseTools/AbstractDbalDatabaseTool.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Liip/TestFixturesBundle
*
* (c) Lukas Kahwe Smith <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace Liip\TestFixturesBundle\Services\DatabaseTools;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;

abstract class AbstractDbalDatabaseTool extends AbstractDatabaseTool
{
protected Connection $connection;

public function setObjectManagerName(?string $omName = null): void
{
parent::setObjectManagerName($omName);
$this->connection = $this->registry->getConnection($omName);
}

protected function getPlatformName(): string
{
$platform = $this->connection->getDatabasePlatform();

// AbstractMySQLPlatform was introduced in DBAL 3.3, keep the MySQLPlatform checks for compatibility with older versions
if ($platform instanceof AbstractMySQLPlatform || $platform instanceof MySqlPlatform) {
return 'mysql';
} elseif ($platform instanceof SqlitePlatform) {
return 'sqlite';
} elseif ($platform instanceof PostgreSQLPlatform) {
return 'pgsql';
}

return (new \ReflectionClass($platform))->getShortName();
}
}
11 changes: 1 addition & 10 deletions src/Services/DatabaseTools/ORMDatabaseTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Doctrine\Common\DataFixtures\Executor\ORMExecutor;
use Doctrine\Common\DataFixtures\ProxyReferenceRepository;
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\ORM\Configuration;
Expand All @@ -32,7 +31,7 @@
/**
* @author Aleksey Tupichenkov <[email protected]>
*/
class ORMDatabaseTool extends AbstractDatabaseTool
class ORMDatabaseTool extends AbstractDbalDatabaseTool
{
/**
* @var EntityManager
Expand All @@ -44,14 +43,6 @@ class ORMDatabaseTool extends AbstractDatabaseTool
*/
private $shouldEnableForeignKeyChecks = false;

protected Connection $connection;

public function setObjectManagerName(?string $omName = null): void
{
parent::setObjectManagerName($omName);
$this->connection = $this->registry->getConnection($omName);
}

public function getType(): string
{
return 'ORM';
Expand Down

0 comments on commit 2ca04d2

Please sign in to comment.