From 65141c5c1a3c310fc4c4a8c1aa3d153609e73c10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20Gro=C3=9Fberndt?= <stephan.grossberndt@typo3.org> Date: Mon, 30 Nov 2020 18:36:53 +0100 Subject: [PATCH] [BUGFIX] Ignore unmapped tables on non-default connections MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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/+/66949 Tested-by: Stefan Bürk <stefan@buerk.tech> Tested-by: core-ci <typo3@b13.com> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Reviewed-by: Stefan Bürk <stefan@buerk.tech> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> --- .../Database/Schema/ConnectionMigrator.php | 47 ++++++++++++------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/typo3/sysext/core/Classes/Database/Schema/ConnectionMigrator.php b/typo3/sysext/core/Classes/Database/Schema/ConnectionMigrator.php index 15e560e07bcc..03a8e3f51e5e 100644 --- a/typo3/sysext/core/Classes/Database/Schema/ConnectionMigrator.php +++ b/typo3/sysext/core/Classes/Database/Schema/ConnectionMigrator.php @@ -213,6 +213,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); @@ -244,24 +273,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 new SchemaDiff([], [], [], $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); -- GitLab