diff --git a/app/admin/controller/Login.php b/app/admin/controller/Login.php index 3bf8405..e2a26c3 100644 --- a/app/admin/controller/Login.php +++ b/app/admin/controller/Login.php @@ -7,12 +7,15 @@ use app\common\controller\AdminController; use think\captcha\facade\Captcha; use think\facade\Env; use think\facade\Event; +use trait\admin\controller\LoginTrait; /** * Class Login. */ class Login extends AdminController { + use LoginTrait; + /** * 初始化方法. */ @@ -33,7 +36,6 @@ class Login extends AdminController */ public function index() { - $captcha = Env::get('adminsystem.captcha', 1); if ($this->request->isPost()) { $post = $this->request->post(); diff --git a/app/common/command/admin/Update.php b/app/common/command/admin/Update.php index eaf6ed9..5672d49 100644 --- a/app/common/command/admin/Update.php +++ b/app/common/command/admin/Update.php @@ -210,6 +210,67 @@ class Update extends Command file_put_contents($now_file_path, $file_content); } + // 处理append的文件 + $last_version_list_skip_files = $last_version_filesystem->listContents('/', Filesystem::LIST_DEEP) + ->filter(function (StorageAttributes $attributes) use ($last_version_skip_config) { + if ($attributes->isDir()) { + return false; + } + + $path = $attributes->path(); + + if (str_starts_with($path, '.git')) { + return false; + } + + $skip_files = $last_version_skip_config['skip_files'] ?? []; + + if (in_array($path, $skip_files)) { + return true; + } + + $skip_dir = $last_version_skip_config['skip_dir'] ?? []; + + foreach ($skip_dir as $dir) { + if (str_starts_with($path, $dir)) { + return true; + } + } + + return true; + }) + ->map(fn (StorageAttributes $attributes) => $attributes->path()) + ->toArray(); + + $last_version_list_append_files = []; + + foreach ($last_version_list_skip_files as $file_path) { + if (in_array($file_path, $last_version_skip_config['append_files'])) { + $last_version_list_append_files[] = $file_path; + continue; + } + + foreach ($last_version_skip_config['append_dir'] as $dir) { + if(str_starts_with($file_path,$dir)){ + continue; + } + } + } + + foreach ($last_version_list_append_files as $file_path) { + $now_file_path = $now_dir. '/'. $file_path; + $last_file_path = $last_version_dir. '/'. $file_path; + + if(file_exists($now_file_path)){ + continue; + } + + $file_content = file_get_contents($last_file_path); + + PathTools::intiDir($now_file_path); + file_put_contents($now_file_path, $file_content); + } + // 检测now的composer依赖和最新的composer依赖 $last_composer_json = file_get_contents($last_version_dir . '/composer.json'); diff --git a/app/common/command/admin/Version.php b/app/common/command/admin/Version.php index 602a5e8..957364c 100644 --- a/app/common/command/admin/Version.php +++ b/app/common/command/admin/Version.php @@ -14,12 +14,13 @@ use think\facade\App; class Version extends Command { - public const VERSION = 'v2.0.33'; + public const VERSION = 'v2.0.34'; public const LAYUI_VERSION = '2.8.16'; public const COMMENT = [ - '调整更新的文件替换逻辑;', + '调整更新的append的逻辑', + '为login增加trait扩展机制', ]; protected function configure() diff --git a/composer.json b/composer.json index 74e1b39..7aecdff 100644 --- a/composer.json +++ b/composer.json @@ -40,6 +40,7 @@ "autoload": { "psr-4": { "app\\": "app", + "trait\\": "extend/trait", "Phinx\\": "extend/phinx" }, "psr-0": { diff --git a/config/update.php b/config/update.php index 0702741..b582157 100644 --- a/config/update.php +++ b/config/update.php @@ -18,7 +18,17 @@ $config['skip_files'] = $skip_files; $skip_dir = []; $skip_dir[] = 'runtime'; $skip_dir[] = 'vendor'; +$skip_dir[] = 'extend/trait'; $config['skip_dir'] = $skip_dir; + +// append 如果当前版本不存在,则追加,如果存在,则不应当覆盖 +// append 的文件应当在skip内部 +$config['append_files'] = []; + +$config['append_dir'] = [ + 'extend/trait', +]; + return $config; diff --git a/extend/trait/admin/controller/LoginTrait.php b/extend/trait/admin/controller/LoginTrait.php new file mode 100644 index 0000000..870b4dc --- /dev/null +++ b/extend/trait/admin/controller/LoginTrait.php @@ -0,0 +1,8 @@ +