From a2aa537cab21e4d5173b02c564f287ff9afabdb4 Mon Sep 17 00:00:00 2001 From: liugang Date: Mon, 24 Nov 2025 16:15:03 +0800 Subject: [PATCH] * [refactor] Refactor SQL processing for database installation and upgrade - Extract SQL processing methods to install model for better reusability - Add replaceContantsInSQL() and appendMySQLTableOptions() public methods - Unify SQL constants replacement across installation and upgrade modules - Remove duplicate SQL processing code in extension and upgrade models - Fix __TABLE__ to __DATABASE__ in zentao.sql for consistency - Improve code maintainability and reduce duplication --- module/install/model.php | 5 ++--- module/upgrade/model.php | 13 ++----------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/module/install/model.php b/module/install/model.php index 7ecc152b44..db20fbbbd0 100644 --- a/module/install/model.php +++ b/module/install/model.php @@ -123,9 +123,8 @@ class installModel extends model { $this->dbh->useDB($this->config->db->name); - $dbCharset = $this->dbh->getDatabaseCharsetAndCollation($this->config->db->name); - $dbFile = $this->app->getAppRoot() . 'db' . DS . 'zentao.sql'; - $tables = explode(';', file_get_contents($dbFile)); + $dbFile = $this->app->getAppRoot() . 'db' . DS . 'zentao.sql'; + $tables = explode(';', file_get_contents($dbFile)); foreach($tables as $table) { diff --git a/module/upgrade/model.php b/module/upgrade/model.php index 9ef1376d53..86d24695a6 100644 --- a/module/upgrade/model.php +++ b/module/upgrade/model.php @@ -16,15 +16,6 @@ class upgradeModel extends model { static $errors = array(); - /** - * 数据库版本。 - * Database version. - * - * @var string - * access public - */ - public $databaseVersion = ''; - public $fromVersion = ''; public $fromEdition = ''; @@ -40,7 +31,6 @@ class upgradeModel extends model { parent::__construct(); $this->loadModel('setting'); - $this->databaseVersion = $this->loadModel('install')->getDatabaseVersion(); } /** @@ -10854,7 +10844,8 @@ class upgradeModel extends model { if($this->config->db->driver != 'mysql') return true; - if(version_compare($this->databaseVersion, '5.6', '<')) return true; + $dbVersion = $this->loadModel('install')->getDatabaseVersion(); + if(version_compare($dbVersion, '5.6', '<')) return true; /* 获取服务器的字符集和排序规则。Get server charset and collation. */ $result = $this->dbh->getServerCharsetAndCollation($this->config->db->name);