From 9f2d0898ec2d2ca900e37b92da21f86fe557ea37 Mon Sep 17 00:00:00 2001 From: augushong Date: Fri, 8 Dec 2023 14:09:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E5=B8=83=E6=96=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=EF=BC=9B=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=8A=A8=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/service/AdminUpdateCodeService.php | 9 ++ app/admin/view/index/_common.js | 13 +++ app/common/command/admin/UpdateCode.php | 11 ++ config/console.php | 4 +- .../service/AdminUpdateCodeServiceBase.php | 38 ++++++ .../service/adminUpdateCodeData/v2.0.74.php | 109 ++++++++++++++++++ .../admin/service/adminUpdateData/tips.php | 7 ++ .../common/command/admin/UpdateCodeBase.php | 41 +++++++ extend/base/helper.php | 2 +- 9 files changed, 232 insertions(+), 2 deletions(-) create mode 100644 app/admin/service/AdminUpdateCodeService.php create mode 100644 app/admin/view/index/_common.js create mode 100644 app/common/command/admin/UpdateCode.php create mode 100644 extend/base/admin/service/AdminUpdateCodeServiceBase.php create mode 100644 extend/base/admin/service/adminUpdateCodeData/v2.0.74.php create mode 100644 extend/base/common/command/admin/UpdateCodeBase.php diff --git a/app/admin/service/AdminUpdateCodeService.php b/app/admin/service/AdminUpdateCodeService.php new file mode 100644 index 0000000..ecede69 --- /dev/null +++ b/app/admin/service/AdminUpdateCodeService.php @@ -0,0 +1,9 @@ +output->error('指定版本无需特定更新'); + + return; + } + + require_once $class_function_path; + + $update_class = new UpdateFunction(); + $update_class->input = $this->input; + $update_class->output = $this->output; + $update_class->update(); + } +} diff --git a/extend/base/admin/service/adminUpdateCodeData/v2.0.74.php b/extend/base/admin/service/adminUpdateCodeData/v2.0.74.php new file mode 100644 index 0000000..1d902fa --- /dev/null +++ b/extend/base/admin/service/adminUpdateCodeData/v2.0.74.php @@ -0,0 +1,109 @@ + 'tableElem', + 'table_render_id' => 'tableRenderId', + 'index_url' => 'indexUrl', + 'add_url' => 'addUrl', + 'edit_url' => 'editUrl', + 'delete_url' => 'deleteUrl', + 'export_url' => 'exportUrl', + 'modify_url' => 'modifyUrl', + ]; + + public function update() + { + $this->output->writeln('更新代码'); + + $this->output->info('当前版本需要将js代码的init的属性从蛇形改为小驼峰'); + $this->output->info('您可以通过编辑器的全局搜索替换功能完成'); + $this->output->info('也可以使用当前命令替换'); + + $is_true = $this->output->confirm($this->input, '是否执行替换?'); + + if (!$is_true) { + $this->output->writeln('取消更新'); + + return; + } + + // 扫描app下的所有js文件 + $js_file_list = $this->scanJsFile(); + + // 将文件的内容替换 + foreach ($js_file_list as $file_path) { + $file_content = file_get_contents($file_path); + + foreach ($this->replaceMap as $search => $replace) { + $file_content = str_replace($search, $replace, $file_content); + } + + file_put_contents($file_path, $file_content); + } + + $this->output->writeln('更新代码完成'); + $this->output->writeln('请注意查看您的代码变动'); + } + + /** + * 扫描js文件. + * + * @return array + */ + public function scanJsFile() + { + $js_file_list = []; + + $app_path = App::getRootPath() . '/app'; + + $this->scanDir($app_path, $js_file_list); + + return $js_file_list; + } + + /** + * 扫描目录. + * + * @param string $dir + * @param array $js_file_list + * @return void + */ + public function scanDir($dir, &$js_file_list) + { + $dir_list = scandir($dir); + + foreach ($dir_list as $file) { + if ($file == '.' || $file == '..') { + continue; + } + + $file_path = $dir . DIRECTORY_SEPARATOR . $file; + + if (is_dir($file_path)) { + $this->scanDir($file_path, $js_file_list); + } else { + $file_ext = pathinfo($file_path, PATHINFO_EXTENSION); + + if ($file_ext == 'js') { + $js_file_list[] = $file_path; + } + } + } + } +} diff --git a/extend/base/admin/service/adminUpdateData/tips.php b/extend/base/admin/service/adminUpdateData/tips.php index 3b49efd..340e0af 100644 --- a/extend/base/admin/service/adminUpdateData/tips.php +++ b/extend/base/admin/service/adminUpdateData/tips.php @@ -23,4 +23,11 @@ return [ '本次更新修改了database/migrations/20220419030557_system_auth.php文件,修复了安装到sqlite的问题,如果你使用sqlite,需要有意识的解决这个问题', ], ], + [ + 'version' => 'v2.0.74', + 'desc' => [ + '本次更新修改了js中init的各项属性的大小写规范,你需要将蛇形命名全局替换为小驼峰命名,比如:table_elem改为tableElem', + '可以运行 php think admin:update:code --update-version v2.0.74 命令自动替换', + ], + ], ]; diff --git a/extend/base/common/command/admin/UpdateCodeBase.php b/extend/base/common/command/admin/UpdateCodeBase.php new file mode 100644 index 0000000..252e37f --- /dev/null +++ b/extend/base/common/command/admin/UpdateCodeBase.php @@ -0,0 +1,41 @@ +setName('admin:update:code') + ->addOption('update-version', null, Option::VALUE_REQUIRED, '按指定版本的规则更新现有代码') + ->setDescription('the admin:update:code command'); + } + + protected function execute(Input $input, Output $output) + { + // 指令输出 + + $update_version = $input->getOption('update-version'); + + if(is_null($update_version)){ + $output->error('请指定更新的版本号'); + return; + } + + $update_service = new AdminUpdateCodeService(); + $update_service->input = $input; + $update_service->output = $output; + $update_service->update($update_version); + + + } +} diff --git a/extend/base/helper.php b/extend/base/helper.php index e122216..0af9d0c 100644 --- a/extend/base/helper.php +++ b/extend/base/helper.php @@ -309,7 +309,7 @@ function event_response($name, $params = []) /** * 以扩展的架构定位app下的文件位置. * - * @param string $file_path 文件路径,不要以/开头,不需要以app开头,会自动定位app或extend/base。 + * @param string $file_path 文件路径,不要以/开头,不需要以app开头,会自动定位 app 或 extend/base。 * @return string */ function app_file_path($file_path)