Skip to content

Commit

Permalink
[TASK] Ensure to set a SchemaManagerFactory for lowlevel connection
Browse files Browse the repository at this point in the history
The doctrine team deprecated the instantiation of a connection
using `DriverManager::getConnection()` without a configuration
object [1].

This change ensures to set the default doctrine factory, but
sets the TYPO3 core implementation with TYPO3 v13.0 to provide
the custom SchemaManager for the different platforms.

[1] https://github.com/doctrine/dbal/blob/3.7.x/UPGRADE.md#deprecated-not-setting-a-schema-manager-factory

Releases: main
  • Loading branch information
sbuerk committed Nov 23, 2023
1 parent 3e9a846 commit a0ccebc
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Classes/Core/Testbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
* The TYPO3 project - inspiring people to share!
*/

use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Exception as DBALException;
use Doctrine\DBAL\Platforms\MariaDBPlatform as DoctrineMariaDBPlatform;
use Doctrine\DBAL\Platforms\MySQLPlatform as DoctrineMySQLPlatform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform as DoctrinePostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform as DoctrineSQLitePlatform;
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
use Doctrine\DBAL\Schema\SchemaManagerFactory;
use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use TYPO3\CMS\Core\Core\Bootstrap;
Expand Down Expand Up @@ -661,7 +664,16 @@ public function setUpTestDatabase(string $databaseName, string $originalDatabase
// @todo: This should by now work with using "our" ConnectionPool again, it does now, though.
$connectionParameters = $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default'];
unset($connectionParameters['dbname']);
$connection = DriverManager::getConnection($connectionParameters);
$configuration = (new Configuration())->setSchemaManagerFactory(GeneralUtility::makeInstance(DefaultSchemaManagerFactory::class));
// @todo Remove class exist check if supported minimal TYPO3 version is raised to v13+.
if (class_exists(\TYPO3\CMS\Core\Database\Schema\SchemaManager\CoreSchemaManagerFactory::class)) {
/** @var SchemaManagerFactory|\TYPO3\CMS\Core\Database\Schema\SchemaManager\CoreSchemaManagerFactory $coreSchemaFactory */
$coreSchemaFactory = GeneralUtility::makeInstance(
\TYPO3\CMS\Core\Database\Schema\SchemaManager\CoreSchemaManagerFactory::class
);
$configuration->setSchemaManagerFactory($coreSchemaFactory);
}
$connection = DriverManager::getConnection($connectionParameters, $configuration);
$schemaManager = $connection->createSchemaManager();
$platform = $connection->getDatabasePlatform();
$isSQLite = $platform instanceof DoctrineSQLitePlatform;
Expand Down

0 comments on commit a0ccebc

Please sign in to comment.