Issue Bug Closed

#81276Wrong constructor argument for TableDiff in TYPO3\CMS\Core\Database\Schema\ConnectionMigrator

Stephan Großberndt 05/19/17, 19:29 updated 10/02/18, 10:59

Description

On most places in TYPO3\CMS\Core\Database\Schema\ConnectionMigrator where an instance of TYPO3\CMS\Core\Database\Schema\TableDiff is created a wrong constructor is used:

class TableDiff extends \Doctrine\DBAL\Schema\TableDiff

and \Doctrine\DBAL\Schema\TableDiff defines $name as a string

class TableDiff
{
    /**
     * @var string
     */
    public $name = null;

but has a method getName() which returns an \Doctrine\DBAL\Schema\Identifier

    /**
     * @param AbstractPlatform $platform The platform to use for retrieving this table diff's name.
     *
     * @return \Doctrine\DBAL\Schema\Identifier
     */
    public function getName(AbstractPlatform $platform)
    {
        return new Identifier(
            $this->fromTable instanceof Table ? $this->fromTable->getQuotedName($platform) : $this->name
        );
    }

In TYPO3\CMS\Core\Database\Schema\ConnectionMigrator the first argument used in the constructor is $changedTable->getName($this->connection->getDatabasePlatform()) which returns the \Doctrine\DBAL\Schema\Identifier instead of a string

$changedTables[$index . ':tbl_' . $addedColumn->getName()] = GeneralUtility::makeInstance(
    TableDiff::class,
    $changedTable->getName($this->connection->getDatabasePlatform()),
    [$addedColumn],
    [],
    [],
    [],
    [],
    [],
    $schemaDiff->fromSchema->getTable($changedTable->name)
);

So TableDiff->name contains a \Doctrine\DBAL\Schema\Identifier instead of a string. If another Schema Migrator is added (like https://github.com/jsor/doctrine-postgis/blob/master/src/Event/DBALSchemaEventSubscriber.php) this leads to exceptions.

Reviews 2