From f4233e751e22bf94cb6c91d3568e047e4a983c04 Mon Sep 17 00:00:00 2001 From: zhenhui <1276357500@qq.com> Date: Sat, 21 Mar 2026 15:48:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=89=E8=A3=85=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/Install.php | 18 ++++++ .../migrations/20230620180908_install.php | 2 + .../20231111000000_add_config_timestamps.php | 55 +++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 database/migrations/20231111000000_add_config_timestamps.php diff --git a/app/api/controller/Install.php b/app/api/controller/Install.php index 6a9031d..39fd2e2 100644 --- a/app/api/controller/Install.php +++ b/app/api/controller/Install.php @@ -12,6 +12,7 @@ use ba\Filesystem; use app\common\controller\Api; use app\admin\model\Admin as AdminModel; use app\admin\model\User as UserModel; +use app\process\Monitor; use support\Response; use Webman\Http\Request; use Phinx\Config\Config as PhinxConfig; @@ -428,6 +429,20 @@ class Install extends Api ]); } + // Windows 下 php windows.php 会每秒检测监控目录;写入 config/.env 等会触发 taskkill 整进程,导致 POST 被中断(ERR_CONNECTION_RESET) + Monitor::pause(); + try { + return $this->baseConfigPost($request, $envOk, $rootPath, $migrateCommand); + } finally { + Monitor::resume(); + } + } + + /** + * 系统基础配置 POST:写入配置并执行迁移 + */ + private function baseConfigPost(Request $request, bool $envOk, string $rootPath, string $migrateCommand): Response + { $connectData = $databaseParam = $request->only(['hostname', 'username', 'password', 'hostport', 'database', 'prefix']); // 数据库配置测试 @@ -455,6 +470,9 @@ class Install extends Api return "\$env('database.{$key}', '" . addslashes($value) . "')"; }; $dbConfigText = preg_replace_callback("/\\\$env\('database\.(hostname|database|username|password|hostport|prefix)',\s*'[^']*'\)/", $callback, $dbConfigContent); + if ($dbConfigText === null) { + return $this->error(__('Failed to update database config file:%s', ['config/' . self::$dbConfigFileName])); + } $result = @file_put_contents($dbConfigFile, $dbConfigText); if (!$result) { return $this->error(__('File has no write permission:%s', ['config/' . self::$dbConfigFileName])); diff --git a/database/migrations/20230620180908_install.php b/database/migrations/20230620180908_install.php index 0441455..a45794c 100644 --- a/database/migrations/20230620180908_install.php +++ b/database/migrations/20230620180908_install.php @@ -227,6 +227,8 @@ class Install extends AbstractMigration ->addColumn('extend', 'string', ['limit' => 255, 'default' => '', 'comment' => '扩展属性', 'null' => false]) ->addColumn('allow_del', 'integer', ['signed' => false, 'limit' => MysqlAdapter::INT_TINY, 'default' => 0, 'comment' => '允许删除:0=否,1=是', 'null' => false]) ->addColumn('weigh', 'integer', ['comment' => '权重', 'default' => 0, 'null' => false]) + ->addColumn('update_time', 'biginteger', ['limit' => 16, 'signed' => false, 'null' => true, 'default' => null, 'comment' => '更新时间']) + ->addColumn('create_time', 'biginteger', ['limit' => 16, 'signed' => false, 'null' => true, 'default' => null, 'comment' => '创建时间']) ->addIndex(['name'], [ 'unique' => true, ]) diff --git a/database/migrations/20231111000000_add_config_timestamps.php b/database/migrations/20231111000000_add_config_timestamps.php new file mode 100644 index 0000000..6ddf989 --- /dev/null +++ b/database/migrations/20231111000000_add_config_timestamps.php @@ -0,0 +1,55 @@ +hasTable('config')) { + return; + } + $config = $this->table('config'); + if (!$config->hasColumn('update_time')) { + $config->addColumn('update_time', 'biginteger', [ + 'limit' => 16, + 'signed' => false, + 'null' => true, + 'default' => null, + 'comment' => '更新时间', + 'after' => 'weigh', + ])->save(); + } + $config = $this->table('config'); + if (!$config->hasColumn('create_time')) { + $config->addColumn('create_time', 'biginteger', [ + 'limit' => 16, + 'signed' => false, + 'null' => true, + 'default' => null, + 'comment' => '创建时间', + 'after' => 'update_time', + ])->save(); + } + } + + public function down(): void + { + if (!$this->hasTable('config')) { + return; + } + $config = $this->table('config'); + if ($config->hasColumn('create_time')) { + $config->removeColumn('create_time')->save(); + } + $config = $this->table('config'); + if ($config->hasColumn('update_time')) { + $config->removeColumn('update_time')->save(); + } + } +}