From bd13e711e09d60c6150055acb42cc87afe1ec13e Mon Sep 17 00:00:00 2001 From: liugang Date: Thu, 20 Nov 2025 16:18:26 +0800 Subject: [PATCH] * [refac] Improve charset handling consistency in upgrade module. --- module/upgrade/model.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/module/upgrade/model.php b/module/upgrade/model.php index cdf9f58fa3..6413bc560a 100644 --- a/module/upgrade/model.php +++ b/module/upgrade/model.php @@ -10857,11 +10857,15 @@ class upgradeModel extends model if(version_compare($dbVersion, '5.6', '<')) return true; /* 转换数据库的字符集。Convert database charset. */ - $this->dao->query("ALTER DATABASE `{$this->config->db->name}` CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci"); + $encoding = $this->config->db->encoding; + $result = $this->dbh->getServerCharsetAndCollation($this->config->db->name); + if($encoding != $result['charset']) return true; + + $this->dao->query("ALTER DATABASE `{$this->config->db->name}` CHARACTER SET {$result['charset']} COLLATE {$result['collation']}"); /* 转换自定义工作流表的字符集。Convert custom workflow tables charset. */ $flowTables = $this->dao->select('`table`')->from(TABLE_WORKFLOW)->where('buildin')->eq(0)->fetchPairs(); - foreach($flowTables as $flowTable) $this->dao->query("ALTER TABLE `$flowTable` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci"); + foreach($flowTables as $flowTable) $this->dao->query("ALTER TABLE `{$flowTable}` CONVERT TO CHARACTER SET {$result['charset']}LATE {$result['collation']}"); /* 获取数据库文件中的表名。Get table names from database file. */ $dbFile = $this->app->getBasePath() . 'db' . DS . 'zentao.sql'; @@ -10873,7 +10877,7 @@ class upgradeModel extends model foreach($matches[1] as $table) { $table = str_replace('zt_', $this->config->db->prefix, $table); - $this->dao->query("ALTER TABLE `$table` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci"); + $this->dao->query("ALTER TABLE `{$table}` CONVERT TO CHARACTER SET {$result['charset']}LATE {$result['collation']}"); } return true;