From 52bc50ea4fd84048f811d26ab7dccc17223b9ea4 Mon Sep 17 00:00:00 2001 From: liugang Date: Tue, 18 Nov 2025 17:41:37 +0800 Subject: [PATCH] * [refac] Improve upgrade module file deletion and copy command features - Optimize file deletion logic with unified deletion script - Add copy command button for better user experience - Complete Chinese and English language support - Standardize error message formatting --- module/upgrade/control.php | 7 ++++++- module/upgrade/js/execute.ui.js | 12 +++++++++++ module/upgrade/lang/en.php | 7 +++++-- module/upgrade/lang/zh-cn.php | 7 +++++-- module/upgrade/model.php | 17 ++++++++++++---- module/upgrade/ui/execute.html.php | 32 ++++++++++++++++++++++++------ 6 files changed, 67 insertions(+), 15 deletions(-) diff --git a/module/upgrade/control.php b/module/upgrade/control.php index ee4694013a..72acca6db3 100644 --- a/module/upgrade/control.php +++ b/module/upgrade/control.php @@ -151,7 +151,8 @@ class upgrade extends control /* 手动删除无法自动删除的文件。*/ /* Remove files that can not be deleted automatically. */ - $result = $this->upgrade->deleteFiles(); + $script = $this->app->getTmpRoot() . 'deleteFiles.sh'; + $result = $this->upgrade->deleteFiles($script); if($result) { $this->view->result = 'fail'; @@ -159,6 +160,10 @@ class upgrade extends control return $this->display(); } + elseif(is_file($script)) + { + unlink($script); + } $rawFromVersion = isset($_POST['fromVersion']) ? $this->post->fromVersion : $fromVersion; if(strpos($fromVersion, 'lite') !== false) $rawFromVersion = $this->config->upgrade->liteVersion[$fromVersion]; diff --git a/module/upgrade/js/execute.ui.js b/module/upgrade/js/execute.ui.js index ae6bcf6ab7..ab97e97c27 100644 --- a/module/upgrade/js/execute.ui.js +++ b/module/upgrade/js/execute.ui.js @@ -7,6 +7,18 @@ window.submitConfirm = function(event) updateProgress(); } +window.copyCommand = function() +{ + const command = $('#command').text(); + navigator.clipboard.writeText(command).then(function() + { + zui.Messager.show({type: 'success', message: copySuccess, timeout: 1000}); + }, function() + { + zui.Messager.show({type: 'danger', message: copyFail, timeout: 1000}); + }); +} + $(document).ready(function() { if(typeof result != 'undefined' && result == 'duckdbFail') diff --git a/module/upgrade/lang/en.php b/module/upgrade/lang/en.php index 446e7ad432..792fb56fca 100644 --- a/module/upgrade/lang/en.php +++ b/module/upgrade/lang/en.php @@ -59,6 +59,9 @@ $lang->upgrade->setStatusFile = '

Please complete the following actions<

I have read and done as instructed above. Continue upgrading.

'; $lang->upgrade->selectVersion = 'Version'; +$lang->upgrade->copyCommand = 'Copy'; +$lang->upgrade->copySuccess = 'Copied to clipboard'; +$lang->upgrade->copyFail = 'Copy failed, please copy it manually.'; $lang->upgrade->continue = 'Continue'; $lang->upgrade->noteVersion = "Select the compatible version, or it might cause data loss."; $lang->upgrade->fromVersion = 'From'; @@ -70,8 +73,8 @@ $lang->upgrade->forbiddenExt = 'The extension is incompatible with the version. $lang->upgrade->updateFile = 'File information has to be updated.'; $lang->upgrade->showSQLLog = 'Your database is inconsistent with the standard and try fix it.'; $lang->upgrade->noticeErrSQL = 'Your database is inconsistent with the standard and it failed to fix it. Please run the following SQL and refresh.'; -$lang->upgrade->afterDeleted = 'Please execute commands to delete the files. Please refresh after you delete them.'; -$lang->upgrade->afterExec = 'Please modify the database manually according to the above error information, and refresh after the modification!'; +$lang->upgrade->afterDeleted = 'Please execute the above command on the server to delete the file, and then refresh the page.'; +$lang->upgrade->afterExec = 'Please manually modify the database based on the above error message, and then refresh the page.'; $lang->upgrade->afterDuckdb = 'Please wait for Duckdb engine to install.'; $lang->upgrade->mergeProgram = 'Data Merge'; $lang->upgrade->mergeTips = 'Data Migration Tips'; diff --git a/module/upgrade/lang/zh-cn.php b/module/upgrade/lang/zh-cn.php index d3f57ce379..290458172e 100644 --- a/module/upgrade/lang/zh-cn.php +++ b/module/upgrade/lang/zh-cn.php @@ -59,6 +59,9 @@ $lang->upgrade->setStatusFile = '

升级之前请先完成下面的操

我已经仔细阅读上面提示且完成上述工作,继续更新

'; $lang->upgrade->selectVersion = '选择版本'; +$lang->upgrade->copyCommand = '复制命令'; +$lang->upgrade->copySuccess = '复制成功'; +$lang->upgrade->copyFail = '复制失败,请手动复制'; $lang->upgrade->continue = '继续'; $lang->upgrade->noteVersion = "务必选择正确的版本,否则会造成数据丢失。"; $lang->upgrade->fromVersion = '原来的版本'; @@ -70,8 +73,8 @@ $lang->upgrade->forbiddenExt = '以下插件与新版本不兼容,已经自 $lang->upgrade->updateFile = '需要更新附件信息。'; $lang->upgrade->showSQLLog = '检查到你的数据库跟标准不一致,正在尝试修复。以下是修复SQL语句。'; $lang->upgrade->noticeErrSQL = '检查到你的数据库跟标准不一致,尝试修复失败。请手动执行以下SQL语句,再刷新页面检查。'; -$lang->upgrade->afterDeleted = '请执行上面命令删除文件, 删除后刷新!'; -$lang->upgrade->afterExec = '请根据以上报错信息手动修改数据库,修改后刷新!'; +$lang->upgrade->afterDeleted = '请在服务器上执行上面命令删除文件,删除后刷新页面。'; +$lang->upgrade->afterExec = '请根据以上报错信息手动修改数据库,修改后刷新页面。'; $lang->upgrade->afterDuckdb = '请等待安装Duckdb引擎。'; $lang->upgrade->mergeProgram = '数据迁移'; $lang->upgrade->mergeTips = '数据迁移提示'; diff --git a/module/upgrade/model.php b/module/upgrade/model.php index 2dced2354b..278abfd059 100644 --- a/module/upgrade/model.php +++ b/module/upgrade/model.php @@ -657,10 +657,11 @@ class upgradeModel extends model * 删除无用的文件。 * Delete Useless Files. * + * @param string $script * @access public * @return array */ - public function deleteFiles(): array + public function deleteFiles(string $script): array { $result = array(); $zfile = $this->app->loadClass('zfile'); @@ -681,7 +682,7 @@ class upgradeModel extends model if(!is_writable($fullPath) || ($isDir && !$zfile->removeDir($fullPath)) || (!$isDir && !$zfile->removeFile($fullPath))) { - $result[] = 'rm -f ' . ($isDir ? '-r ' : '') . $fullPath; + $result[] = 'rm -fr ' . $fullPath; } } } @@ -696,11 +697,19 @@ class upgradeModel extends model if(!is_writable($patchPath) || ($isDir && !$zfile->removeDir($patchPath)) || (!$isDir && !$zfile->removeDir($patchPath))) { - $result[] = 'rm -f ' . ($isDir ? '-r ' : '') . $patchPath; + $result[] = 'rm -fr ' . $patchPath; } } - return $result; + if(empty($result)) return $result; + + asort($result); + + $content = "#!/bin/bash\n"; + foreach($result as $cmd) $content .= "$cmd\n"; + file_put_contents($script, $content); + + return ["/bin/bash $script"]; } /** diff --git a/module/upgrade/ui/execute.html.php b/module/upgrade/ui/execute.html.php index 3e8960af6d..4f351db8b7 100644 --- a/module/upgrade/ui/execute.html.php +++ b/module/upgrade/ui/execute.html.php @@ -13,6 +13,9 @@ namespace zin; set::zui(true); jsVar('result', $result); +jsVar('copySuccess', $lang->upgrade->copySuccess); +jsVar('copyFail', $lang->upgrade->copyFail); + div ( setID('main'), @@ -40,6 +43,7 @@ div h::textarea ( setClass('form-control w-full'), + set::id('command'), set::name('errors'), set::rows(10), set::readonly('readonly'), @@ -50,19 +54,35 @@ div ( on::click('button[type=submit]', "submitConfirm"), on::click('button[type=button]', "loadCurrentPage"), + on::click('#copyBtn', "copyCommand"), set::target('_self'), set::actions(false), formHidden('fromVersion', $fromVersion), div ( setClass('mt-4'), - $result == 'sqlFail' ? $lang->upgrade->afterExec : null, - $result == 'fail' ? $lang->upgrade->afterDeleted : null, - btn + div ( - setID('refreshBtn'), - set::btnType($this->app->rawMethod == 'execute' ? 'submit' : 'button'), - $lang->refresh + setClass('text-important'), + $result == 'sqlFail' ? $lang->upgrade->afterExec : null, + $result == 'fail' ? $lang->upgrade->afterDeleted : null, + ), + div + ( + setClass('text-center'), + $result == 'fail' ? a + ( + setID('copyBtn'), + setClass('btn wide important mr-2'), + $lang->upgrade->copyCommand + ) : null, + btn + ( + setID('refreshBtn'), + setClass('btn-wide primary'), + set::btnType($this->app->rawMethod == 'execute' ? 'submit' : 'button'), + $lang->refresh + ) ) ) )