Commit f425ae37 authored by Stephan Großberndt's avatar Stephan Großberndt Committed by Christian Kuhn
Browse files

[BUGFIX] Ignore unmapped tables on non-default connections

This patch changes the behaviour when building the SchemaDiff on a
non-default connection to only fetch tables which are mapped to that
connection instead of fetching table details of all tables and
discarding the information for unmapped tables later on.

This improves the performance and avoids errors for data types
unknown to doctrine/dbal in details of unmapped tables.

Resolves: #92959
Releases: main, 11.5
Change-Id: Ia4a62d861ea0748995eb0dec4f01e9e65eb3ed46
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/72765


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 61af3e74
......@@ -214,6 +214,35 @@ class ConnectionMigrator
*/
protected function buildSchemaDiff(bool $renameUnused = true): SchemaDiff
{
// Unmapped tables in a non-default connection are ignored by TYPO3
$tablesForConnection = [];
if ($this->connectionName !== ConnectionPool::DEFAULT_CONNECTION_NAME) {
// If there are no mapped tables return a SchemaDiff without any changes
// to avoid update suggestions for tables not related to TYPO3.
if (empty($GLOBALS['TYPO3_CONF_VARS']['DB']['TableMapping'] ?? null)) {
return new SchemaDiff();
}
// Collect the table names that have been mapped to this connection.
$connectionName = $this->connectionName;
/** @var string[] $tablesForConnection */
$tablesForConnection = array_keys(
array_filter(
$GLOBALS['TYPO3_CONF_VARS']['DB']['TableMapping'],
static function ($tableConnectionName) use ($connectionName) {
return $tableConnectionName === $connectionName;
}
)
);
// Ignore all tables without mapping if not in the default connection
$this->connection->getConfiguration()->setSchemaAssetsFilter(
static function ($assetName) use ($tablesForConnection) {
return in_array($assetName, $tablesForConnection, true);
}
);
}
// Build the schema definitions
$fromSchema = $this->connection->createSchemaManager()->createSchema();
$toSchema = $this->buildExpectedSchemaDefinitions($this->connectionName);
......@@ -245,24 +274,6 @@ class ConnectionMigrator
return $schemaDiff;
}
// If there are no mapped tables return a SchemaDiff without any changes
// to avoid update suggestions for tables not related to TYPO3.
if (empty($GLOBALS['TYPO3_CONF_VARS']['DB']['TableMapping'] ?? null)) {
return GeneralUtility::makeInstance(SchemaDiff::class, [], [], [], $fromSchema);
}
// Collect the table names that have been mapped to this connection.
$connectionName = $this->connectionName;
/** @var string[] $tablesForConnection */
$tablesForConnection = array_keys(
array_filter(
$GLOBALS['TYPO3_CONF_VARS']['DB']['TableMapping'],
static function ($tableConnectionName) use ($connectionName) {
return $tableConnectionName === $connectionName;
}
)
);
// Remove all tables that are not assigned to this connection from the diff
$schemaDiff->newTables = $this->removeUnrelatedTables($schemaDiff->newTables, $tablesForConnection);
$schemaDiff->changedTables = $this->removeUnrelatedTables($schemaDiff->changedTables, $tablesForConnection);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment