From: Matthias Schmidt Date: Tue, 13 Apr 2021 14:01:45 +0000 (+0200) Subject: Check if foreign key references unknown database table X-Git-Tag: 5.3.6~6^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=998e92246df310530c9370bb112b6b5de2e40ff3;p=GitHub%2FWoltLab%2FWCF.git Check if foreign key references unknown database table --- diff --git a/wcfsetup/install/files/lib/system/database/table/DatabaseTableChangeProcessor.class.php b/wcfsetup/install/files/lib/system/database/table/DatabaseTableChangeProcessor.class.php index 87fc5051e4..202065ff00 100644 --- a/wcfsetup/install/files/lib/system/database/table/DatabaseTableChangeProcessor.class.php +++ b/wcfsetup/install/files/lib/system/database/table/DatabaseTableChangeProcessor.class.php @@ -1149,6 +1149,24 @@ class DatabaseTableChangeProcessor { } } } + + foreach ($table->getForeignKeys() as $foreignKey) { + $referencedTableExists = in_array($foreignKey->getReferencedTable(), $this->existingTableNames); + foreach ($this->tables as $processedTable) { + if ($processedTable->getName() === $foreignKey->getReferencedTable()) { + $referencedTableExists = !$processedTable->willBeDropped(); + } + } + + if (!$referencedTableExists) { + $errors[] = [ + 'columnNames' => implode(',', $foreignKey->getColumns()), + 'referencedTableName' => $foreignKey->getReferencedTable(), + 'tableName' => $table->getName(), + 'type' => 'unknownTableInForeignKey', + ]; + } + } } } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index bf17f297e5..31f1a66b1a 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -1984,6 +1984,8 @@ Die Datenbestände werden sorgfältig gepflegt, aber es ist nicht ausgeschlossen Der Primärindex {$error[tableName]} ({$error[columnNames]}) enthält die Spalte {$error[columnName]}, deren Werte NULL sein können. {else if $error[type] === 'foreignForeignKeyDrop'} Der Fremdschlüssel {$error[tableName]} ({$error[columnNames]}) gehört zu einem anderen Paket und kann deshalb nicht gelöscht werden. + {else if $error[type] === 'unknownTableInForeignKey'} + Der Fremdschlüssel {$error[tableName]} ({$error[columnNames]}) referenziert eine unbekannte Tabelle {$error[referencedTableName]}. {else} Unbekannter Fehler. {/if} diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index d3a1c9d506..c30f3cfb9c 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -1968,6 +1968,8 @@ If you have already bought the licenses for the listed apps, th The primary index {$error[tableName]} ({$error[columnNames]}) contains the column {$error[columnName]} whose values can be NULL. {else if $error[type] === 'foreignForeignKeyDrop'} The foreign key {$error[tableName]} ({$error[columnNames]}) belongs to a different package and thus cannot be dropped. + {else if $error[type] === 'unknownTableInForeignKey'} + The foreign key {$error[tableName]} ({$error[columnNames]}) references an unknown table {$error[referencedTableName]}. {else} Unknown error. {/if}