From: Joshua Rüsweg Date: Mon, 29 Jul 2019 17:04:43 +0000 (+0200) Subject: Add foreign key system check X-Git-Tag: 5.2.0_Alpha_4~19^2~4 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=c65817a89f132129d9cca3d7a9cdcd5bb500f7c6;p=GitHub%2FWoltLab%2FWCF.git Add foreign key system check See #2977 --- diff --git a/wcfsetup/install/files/acp/templates/systemCheck.tpl b/wcfsetup/install/files/acp/templates/systemCheck.tpl index 4a2109d46d..f72c9e7454 100644 --- a/wcfsetup/install/files/acp/templates/systemCheck.tpl +++ b/wcfsetup/install/files/acp/templates/systemCheck.tpl @@ -129,6 +129,18 @@ {lang}wcf.acp.systemCheck.mysql.innodb.description{/lang} + + +
{lang}wcf.acp.systemCheck.mysql.foreignKeys{/lang}
+
+ {if $results[mysql][foreignKeys]} + {@$statusOk} {lang}wcf.acp.systemCheck.pass{/lang} + {else} + {@$statusInsufficient} {lang}wcf.acp.systemCheck.notSupported{/lang} + {/if} + {lang}wcf.acp.systemCheck.mysql.foreignKeys.description{/lang} +
+
diff --git a/wcfsetup/install/files/lib/acp/page/SystemCheckPage.class.php b/wcfsetup/install/files/lib/acp/page/SystemCheckPage.class.php index a66275191c..3a14e3ef2a 100644 --- a/wcfsetup/install/files/lib/acp/page/SystemCheckPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/SystemCheckPage.class.php @@ -3,6 +3,7 @@ namespace wcf\acp\page; use wcf\data\application\Application; use wcf\page\AbstractPage; use wcf\system\exception\SystemException; +use wcf\system\Regex; use wcf\system\WCF; use wcf\util\FileUtil; @@ -79,6 +80,39 @@ class SystemCheckPage extends AbstractPage { 'recommended' => ['7.1', '7.2', '7.3'], ]; + public $foreignKeys = [ + 'wcf'. WCF_N .'_user' => [ + 'avatarID' => [ + 'referenceTable' => 'wcf'. WCF_N .'_user_avatar', + 'referenceColumn' => 'avatarID' + ] + ], + 'wcf'. WCF_N .'_comment' => [ + 'userID' => [ + 'referenceTable' => 'wcf'. WCF_N .'_user', + 'referenceColumn' => 'userID' + ], + 'objectTypeID' => [ + 'referenceTable' => 'wcf'. WCF_N .'_object_type', + 'referenceColumn' => 'objectTypeID' + ] + ], + 'wcf'. WCF_N .'_moderation_queue' => [ + 'objectTypeID' => [ + 'referenceTable' => 'wcf'. WCF_N .'_object_type', + 'referenceColumn' => 'objectTypeID' + ], + 'assignedUserID' => [ + 'referenceTable' => 'wcf'. WCF_N .'_user', + 'referenceColumn' => 'userID' + ], + 'userID' => [ + 'referenceTable' => 'wcf'. WCF_N .'_user', + 'referenceColumn' => 'userID' + ] + ] + ]; + public $results = [ 'directories' => [], 'mysql' => [ @@ -86,6 +120,7 @@ class SystemCheckPage extends AbstractPage { 'mariadb' => false, 'result' => false, 'version' => '0.0.0', + 'foreignKeys' => false, ], 'php' => [ 'extension' => [], @@ -184,7 +219,23 @@ class SystemCheckPage extends AbstractPage { } } - if ($this->results['mysql']['result'] && $this->results['mysql']['innodb']) { + // validate foreign keys + $this->results['mysql']['foreignKeys'] = true; + foreach ($this->foreignKeys as $table => $keys) { + $sql = "SHOW CREATE TABLE ". $table; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute(); + + $command = $statement->fetchSingleColumn(1); + foreach ($keys as $column => $reference) { + if (!Regex::compile('CONSTRAINT [`"]?(.)*[`"]? FOREIGN KEY \([`"]?'. $column .'[`"]?\) REFERENCES [`"]?'. $reference['referenceTable'] .'[`"]? \([`"]?'. $reference['referenceColumn'] .'[`"]?\)')->match($command)) { + $this->results['mysql']['foreignKeys'] = false; + break 2; + } + } + } + + if ($this->results['mysql']['result'] && $this->results['mysql']['innodb'] && $this->results['mysql']['foreignKeys']) { $this->results['status']['mysql'] = true; } } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index cf05a4951f..4950ba8a99 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -2704,6 +2704,8 @@ Kein Abschnitt darf leer sein und alle Abschnitten dürfen nur folgende Zeichen + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index fc9484e4bc..566be37cc2 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -2632,6 +2632,8 @@ If you have already bought the licenses for the listed apps, th + +