diff --git a/app/admin/view/index/welcome.html b/app/admin/view/index/welcome.html
index c54656c..75441d9 100644
--- a/app/admin/view/index/welcome.html
+++ b/app/admin/view/index/welcome.html
@@ -152,6 +152,10 @@
ThinkPHP |
{:\\think\\App::VERSION} |
+
+ | PHP |
+ {:PHP_VERSION} |
+
diff --git a/app/common/command/admin/Update.php b/app/common/command/admin/Update.php
new file mode 100644
index 0000000..f163c15
--- /dev/null
+++ b/app/common/command/admin/Update.php
@@ -0,0 +1,96 @@
+setName('admin:update')
+ ->setDescription('the admin:update command');
+ }
+
+ protected function execute(Input $input, Output $output)
+ {
+ // 指令输出
+ $output->writeln('admin:update');
+
+ $this->cleanWorkpaceDir();
+
+ $current_version = Version::VERSION;
+
+ $current_version_dir = App::getRuntimePath() . '/update/' . $current_version;
+
+ $last_version_dir = App::getRuntimePath() . '/update/last';
+
+ $version_file_regx = "/\bconst VERSION\s*=\s*'[\d\.a-z]+'/";
+
+ $last_version_git = new Git();
+ $output->writeln('下载最新代码');
+ $last_version_repo = $last_version_git->cloneRepository(self::REPO, $last_version_dir);
+ $last_version_file = $last_version_dir . '/app/common/command/admin/Version.php';
+ $last_version_str = file_get_contents($last_version_file);
+ preg_match($version_file_regx, $last_version_str, $matches);
+
+ $matched_version_str = $matches[0];
+
+ $last_version = str_replace('const VERSION = ', '', $matched_version_str);
+ $last_version = str_replace('\'', '', $last_version);
+
+ // if ($last_version == $current_version) {
+ // $output->writeln('当前代码为最新版本,无需更新');
+ // $this->cleanWorkpaceDir();
+ // return;
+ // }
+
+ // 将最新代码切换到最新版本
+ $last_version_repo->checkout($last_version);
+
+ $current_version_git = new Git();
+ $output->writeln('获取当前版本代码');
+ $current_version_repo = $current_version_git->cloneRepository(self::REPO, $current_version_dir);
+ $output->writeln('切换版本' . $current_version);
+ $current_version_repo->checkout($current_version);
+
+ // 获取当前版本需要跳过的文件
+ $current_version_update_config = include $current_version_dir . '/config/update.php';
+ // 获取当前版本要替换的文件
+
+ $current_version_filesystem = new Filesystem(new LocalFilesystemAdapter($current_version_dir));
+ $list_files = $current_version_filesystem->listContents('/', Filesystem::LIST_DEEP);
+ // dump($list_files);
+
+ // 对比现在的代码,检查是否有定制修改
+ // 有定制修改则退出
+
+ // 获取最新版本需要跳过的文件
+ // 获取最新版本要替换的文件
+
+ // 删除当前版本要替换的文件
+ // 将最新版本要替换的文件替换到项目代码中
+
+ // 更新完成
+ }
+
+ protected function cleanWorkpaceDir()
+ {
+ $dir = App::getRuntimePath() . '/update/';
+
+ $this->output->writeln('清理目录 ' . $dir);
+ PathTools::removeDir($dir);
+ }
+}
diff --git a/app/common/command/admin/Version.php b/app/common/command/admin/Version.php
index 7228d4c..c5b81e8 100644
--- a/app/common/command/admin/Version.php
+++ b/app/common/command/admin/Version.php
@@ -14,12 +14,12 @@ use think\facade\App;
class Version extends Command
{
- public const VERSION = 'v2.0.29';
+ public const VERSION = 'v2.0.30-beta';
public const LAYUI_VERSION = '2.8.16';
public const COMMENT = [
- '新增拟物风格特效皮肤',
+ '修复文件',
];
protected function configure()
diff --git a/app/common/tools/PathTools.php b/app/common/tools/PathTools.php
index db146fc..1d941c8 100644
--- a/app/common/tools/PathTools.php
+++ b/app/common/tools/PathTools.php
@@ -53,6 +53,30 @@ class PathTools
return $file_path;
}
+ public static function removeDir($dir_name)
+ {
+ if (!is_dir($dir_name)) {
+ return false;
+ }
+
+ if (strpos(strtolower(PHP_OS), 'win') === 0) {
+ $dir_name = static::formatWinPath($dir_name);
+ exec("rd /s /q {$dir_name}", $output);
+
+ return;
+ }
+
+ $handle = opendir($dir_name);
+ while (false !== ($file = readdir($handle))) {
+ if ($file != '.' && $file != '..') {
+ is_dir("$dir_name/$file") ? self::removeDir("$dir_name/$file") : unlink("$dir_name/$file");
+ }
+ }
+ closedir($handle);
+
+ return rmdir($dir_name);
+ }
+
public static function mapDir($dir, $callback = null)
{
$result = [];
@@ -74,4 +98,9 @@ class PathTools
return $result;
}
+
+ public static function formatWinPath($content)
+ {
+ return str_replace('/', '\\', $content);
+ }
}
diff --git a/composer.json b/composer.json
index fbf35b0..84b200d 100644
--- a/composer.json
+++ b/composer.json
@@ -31,7 +31,8 @@
"league/flysystem": "^3.0",
"overtrue/flysystem-qiniu": "^3.0",
"overtrue/flysystem-cos": "^5.0",
- "iidestiny/flysystem-oss": "^4.0"
+ "iidestiny/flysystem-oss": "^4.0",
+ "czproject/git-php": "^4.2"
},
"require-dev": {
"symfony/var-dumper": "^4.2"
@@ -54,4 +55,4 @@
"@php think vendor:publish"
]
}
-}
\ No newline at end of file
+}
diff --git a/composer.lock b/composer.lock
index a237863..1fec4a5 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "07cbcad2506a74dbd4130f9597859332",
+ "content-hash": "431498e22ef6edab8343d1484636e6e0",
"packages": [
{
"name": "aliyuncs/oss-sdk-php",
@@ -51,6 +51,58 @@
},
"time": "2022-08-03T08:06:01+00:00"
},
+ {
+ "name": "czproject/git-php",
+ "version": "v4.2.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/czproject/git-php.git",
+ "reference": "e257f2c3b43fe8fef19ddb5727b604416b423107"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/czproject/git-php/zipball/e257f2c3b43fe8fef19ddb5727b604416b423107",
+ "reference": "e257f2c3b43fe8fef19ddb5727b604416b423107",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=5.6.0"
+ },
+ "require-dev": {
+ "nette/tester": "^2.0"
+ },
+ "type": "library",
+ "autoload": {
+ "classmap": [
+ "src/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "BSD-3-Clause"
+ ],
+ "authors": [
+ {
+ "name": "Jan Pecha",
+ "email": "janpecha@email.cz"
+ }
+ ],
+ "description": "Library for work with Git repository in PHP.",
+ "keywords": [
+ "git"
+ ],
+ "support": {
+ "issues": "https://github.com/czproject/git-php/issues",
+ "source": "https://github.com/czproject/git-php/tree/v4.2.0"
+ },
+ "funding": [
+ {
+ "url": "https://www.janpecha.cz/donate/git-php/",
+ "type": "other"
+ }
+ ],
+ "time": "2023-07-12T09:14:30+00:00"
+ },
{
"name": "doctrine/annotations",
"version": "1.14.3",
diff --git a/config/console.php b/config/console.php
index 0652cad..40bba3e 100644
--- a/config/console.php
+++ b/config/console.php
@@ -6,6 +6,7 @@
use app\common\command\admin\Clear;
use app\common\command\admin\Version;
use app\common\command\admin\ResetPassword;
+use app\common\command\admin\Update;
use app\common\command\curd\Migrate;
use app\common\command\Timer;
@@ -19,6 +20,7 @@ return [
Timer::class,
Version::class,
Migrate::class,
- Clear::class
+ Clear::class,
+ Update::class
],
];
diff --git a/config/update.php b/config/update.php
index 8a1b5ed..372b8ba 100644
--- a/config/update.php
+++ b/config/update.php
@@ -11,4 +11,10 @@ $skip_files[] = '/app/common/app/service.php';
$config['skip_files'] = $skip_files;
+$skip_dir = [];
+$skip_dir[] = '/runtime';
+$skip_dir[] = '/vendor';
+
+$config['skip_dir'] = $skip_dir;
+
return $config;