mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-01 15:32:48 +08:00
开始通过git升级版本
This commit is contained in:
@@ -152,6 +152,10 @@
|
||||
<td>ThinkPHP</td>
|
||||
<td>{:\\think\\App::VERSION}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>PHP</td>
|
||||
<td>{:PHP_VERSION}</td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
96
app/common/command/admin/Update.php
Normal file
96
app/common/command/admin/Update.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\common\command\admin;
|
||||
|
||||
use app\common\tools\PathTools;
|
||||
use CzProject\GitPhp\Git;
|
||||
use League\Flysystem\Filesystem;
|
||||
use League\Flysystem\Local\LocalFilesystemAdapter;
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\facade\App;
|
||||
|
||||
class Update extends Command
|
||||
{
|
||||
public const REPO = 'https://gitee.com/ulthon/ulthon_admin.git';
|
||||
|
||||
protected function configure()
|
||||
{
|
||||
// 指令配置
|
||||
$this->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);
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
composer.lock
generated
54
composer.lock
generated
@@ -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",
|
||||
|
||||
@@ -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
|
||||
],
|
||||
];
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user