Fix checking of foreign table index on install "contentcontainer_tag" (#5416)

This commit is contained in:
Yuriy Bakhtin 2021-11-02 15:42:58 +03:00 committed by GitHub
parent 7327b375fe
commit 713c7bc2be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -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)

View File

@ -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;
}
}