From 713c7bc2be2626e76e571037caeb32747efcf5b5 Mon Sep 17 00:00:00 2001 From: Yuriy Bakhtin Date: Tue, 2 Nov 2021 15:42:58 +0300 Subject: [PATCH] Fix checking of foreign table index on install "contentcontainer_tag" (#5416) --- CHANGELOG.md | 1 + protected/humhub/components/Migration.php | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cba6f832f..f56bda5bf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ HumHub Changelog 1.9.3 (Unreleased) ------------------ - Fix #5372: Text shortening in Japanese broken - Fix truncating of multi-byte strings +- Fix #5398: Fix checking of foreign table index 1.9.2 (October 15, 2021) diff --git a/protected/humhub/components/Migration.php b/protected/humhub/components/Migration.php index 28d63162e0..b82ce55931 100644 --- a/protected/humhub/components/Migration.php +++ b/protected/humhub/components/Migration.php @@ -104,12 +104,12 @@ class Migration extends \yii\db\Migration * @param string $table * @return bool */ - protected function foreignIndexExists($index, $table): bool + protected function foreignIndexExists(string $index, string $table): bool { return (bool) $this->db->createCommand('SELECT * FROM information_schema.key_column_usage WHERE REFERENCED_TABLE_NAME IS NOT NULL AND TABLE_NAME = ' . $this->db->quoteValue($table) . ' - AND TABLE_SCHEMA = "humhub_develop" + AND TABLE_SCHEMA = ' . $this->db->quoteValue($this->getDsnAttribute('dbname')). ' AND CONSTRAINT_NAME = ' . $this->db->quoteValue($index)) ->queryOne(); } @@ -320,4 +320,18 @@ class Migration extends \yii\db\Migration { return (!Setting::isInstalled()); } + + /** + * Get data from database dsn config + * + * @since 1.9.3 + * @param string $name 'host', 'port', 'dbname' + * @return string|null + */ + private function getDsnAttribute(string $name): ?string + { + return preg_match('/' . preg_quote($name) . '=([^;]*)/', $this->db->dsn, $match) + ? $match[1] + : null; + } }