Skip to content

Commit

Permalink
[BUGFIX] Ensure Comparator knows the current platform
Browse files Browse the repository at this point in the history
Doctrine DBAL 3.x has been introduced into TYPO3 v12
with #96287 and raised over the time, adding the one
or other deprecation and dual code branches and some
compat layers.

The `\Doctrine\DBAL\Schema\Comparator::compareSchemas()`
for example is still static and instantiaces itself,
and therefore not properly handing over the platform.
The missing platform does not execute the new way of
using `AbstractPlatform::columnsEqual()`, but renders
the platform specific handlings useless - specially
added for MySQL based platforms, for example the
datbase type `TEXT` length check and comparision.

This change passes the platform down to the inner
`Comparator` instance to ensure that the platform
specific handling can work. To avoid the new way
using the `AbstractPlatform::columnsEqual()` which
introduces incompatible checks for now, that method
is overriden and the `diffColumn()` check used.

That allows the proper TEXT sub-type handling with
MySQL and MariaDB while supressing noise for now.

Note: This is also done currently in TYPO3 v13.

Resolves: #103348
Related: #96287 (Doctrine DBAL 3.2)
Releases: 12.4
Change-Id: If130c73ff122d09a50158bc3ac53f28f9a4eb749
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/83457
Reviewed-by: Garvin Hicking <gh@faktor-e.de>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christophe Monard <contact@cmonard.fr>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: core-ci <typo3@b13.com>
Reviewed-by: Christophe Monard <contact@cmonard.fr>
Reviewed-by: Developer Archriss <typo3@archriss.com>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: Garvin Hicking <gh@faktor-e.de>
Tested-by: Developer Archriss <typo3@archriss.com>
  • Loading branch information
sbuerk committed Mar 19, 2024
1 parent 6707f50 commit dc392a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
17 changes: 14 additions & 3 deletions typo3/sysext/core/Classes/Database/Schema/Comparator.php
Expand Up @@ -18,6 +18,7 @@
namespace TYPO3\CMS\Core\Database\Schema;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MariaDBPlatform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
Expand Down Expand Up @@ -111,7 +112,7 @@ public function diffColumn(Column $column1, Column $column2)
$changedProperties = parent::diffColumn($column1, $column2);

// Only MySQL has variable length versions of TEXT/BLOB
if (!$this->databasePlatform instanceof MySQLPlatform) {
if (!($this->databasePlatform instanceof MariaDBPlatform || $this->databasePlatform instanceof MySQLPlatform)) {
return $changedProperties;
}

Expand All @@ -131,6 +132,15 @@ public function diffColumn(Column $column1, Column $column2)
return array_unique($changedProperties);
}

/**
* @todo TYPO3 v13 needs to properly handle the columnsEqual way, so we use the old column comparison here to
* avoid noisy and incorrect comparison for now leading to endless loop.
*/
public function columnsEqual(Column $column1, Column $column2): bool
{
return $this->diffColumn($column1, $column2) === [];
}

/**
* Returns a SchemaDiff object containing the differences between the schemas
* $fromSchema and $toSchema.
Expand All @@ -153,9 +163,10 @@ public function diffColumn(Column $column1, Column $column2)
*/
public static function compareSchemas(
Schema $fromSchema,
Schema $toSchema
Schema $toSchema,
AbstractPlatform $platform = null
) {
$comparator = new self();
$comparator = new self($platform);
$diff = new SchemaDiff();
$diff->fromSchema = $fromSchema;

Expand Down
Expand Up @@ -244,7 +244,7 @@ static function ($assetName) use ($tablesForConnection) {

// Build SchemaDiff and handle renames of tables and columns
$comparator = GeneralUtility::makeInstance(Comparator::class, $this->connection->getDatabasePlatform());
$schemaDiff = $comparator->compareSchemas($fromSchema, $toSchema);
$schemaDiff = $comparator->compareSchemas($fromSchema, $toSchema, $this->connection->getDatabasePlatform());
$schemaDiff = $this->migrateColumnRenamesToDistinctActions($schemaDiff);

if ($renameUnused) {
Expand Down

0 comments on commit dc392a4

Please sign in to comment.