为基于框架的产品预留更新机制;

This commit is contained in:
augushong
2024-10-14 18:01:10 +08:00
parent 090ab096c0
commit 40a00be9d6
4 changed files with 48 additions and 19 deletions

View File

@@ -17,6 +17,14 @@ class AdminUpdateServiceBase
{
public const REPO = 'https://gitee.com/ulthon/ulthon_admin.git';
public const PRODUCT_REPO = '';
public $useRepo = null;
public $useVersion = null;
public $type = 'ulthon_admin';
/**
* @var Input
*/
@@ -27,8 +35,15 @@ class AdminUpdateServiceBase
*/
public $output;
public function __construct()
public function __construct($type = 'ulthon_admin')
{
if ($type == 'ulthon_admin') {
$this->useRepo = self::REPO;
$this->useVersion = Version::VERSION;
} else {
$this->useRepo = static::PRODUCT_REPO;
$this->useVersion = Version::PRODUCT_VERSION;
}
}
public function update()
@@ -38,7 +53,7 @@ class AdminUpdateServiceBase
$this->cleanWorkpaceDir();
$current_version = Version::VERSION;
$current_version = $this->useVersion;
$current_version_dir = App::getRuntimePath() . '/update/' . $current_version;
$last_version_dir = App::getRuntimePath() . '/update/last';
@@ -47,7 +62,7 @@ class AdminUpdateServiceBase
$output->writeln('获取最新代码');
$last_version_git = new Git();
$last_version_repo = $last_version_git->cloneRepository(self::REPO, $last_version_dir);
$last_version_repo = $last_version_git->cloneRepository($this->useRepo, $last_version_dir);
$tags = $last_version_repo->getTags();
@@ -87,7 +102,7 @@ class AdminUpdateServiceBase
$current_version_git = new Git();
$output->writeln('获取当前版本代码');
$current_version_repo = $current_version_git->cloneRepository(self::REPO, $current_version_dir);
$current_version_repo = $current_version_git->cloneRepository($this->useRepo, $current_version_dir);
$output->writeln('切换版本' . $current_version);
$current_version_repo->checkout($current_version);
@@ -127,21 +142,21 @@ class AdminUpdateServiceBase
// 当前版本的应该被处理所有文件
$current_version_files = $current_version_filesystem->listContents('/', true)
->filter($filter_files_function)
->map(fn (StorageAttributes $attributes) => $attributes->path())
->toArray();
->filter($filter_files_function)
->map(fn (StorageAttributes $attributes) => $attributes->path())
->toArray();
// 最新版本的所有文件
$last_version_files = $last_version_filesystem->listContents('/', true)
->filter($filter_files_function)
->map(fn (StorageAttributes $attributes) => $attributes->path())
->toArray();
->filter($filter_files_function)
->map(fn (StorageAttributes $attributes) => $attributes->path())
->toArray();
// 本身的所有文件
$now_files = $now_filesystem->listContents('/', true)
->filter($filter_files_function)
->map(fn (StorageAttributes $attributes) => $attributes->path())
->toArray();
->filter($filter_files_function)
->map(fn (StorageAttributes $attributes) => $attributes->path())
->toArray();
$changed_files = [];
@@ -228,8 +243,7 @@ class AdminUpdateServiceBase
// 如果现存版本和当前版本一致,则直接处理
if (PathTools::compareFiles($now_file_path, $current_file_path)) {
if(PathTools::compareFiles($current_file_path,$last_file_path)){
if (PathTools::compareFiles($current_file_path, $last_file_path)) {
// 如果当前版本和新版本一致,则无需处理
continue;
}
@@ -348,7 +362,7 @@ class AdminUpdateServiceBase
'app',
'config',
'route',
'docker'
'docker',
];
foreach ($optional_files_prefix as $prefix) {

View File

@@ -12,11 +12,15 @@ use think\console\Output;
class UpdateBase extends Command
{
public const REPO = null;
protected function configure()
{
// 指令配置
$this->setName('admin:update')
->addOption('reinstall', null, Option::VALUE_NONE, '重装版本')
->addOption('update-ulthon', null, Option::VALUE_NONE, '重装版本')
->setDescription('the admin:update command');
}
@@ -25,7 +29,13 @@ class UpdateBase extends Command
// 指令输出
$output->writeln('admin:update');
$update_service = new AdminUpdateService();
$repo = static::REPO;
if($input->hasOption('update-ulthon')){
$repo = null;
}
$update_service = new AdminUpdateService($repo);
$update_service->input = $input;
$update_service->output = $output;
$update_service->update();

View File

@@ -14,6 +14,8 @@ class VersionBase extends Command
{
public const VERSION = 'v2.0.103';
public const PRODUCT_VERSION = '';
public const LAYUI_VERSION = '2.8.17';
public const COMMENT = [
@@ -32,7 +34,10 @@ class VersionBase extends Command
protected function execute(Input $input, Output $output)
{
// 指令输出
$output->info('当前版本号为:' . $this::VERSION);
if (!empty(static::PRODUCT_VERSION)) {
$output->info('当前版本号为:' . $this::PRODUCT_VERSION);
}
$output->info('当前ulthon_admin版本号为' . $this::VERSION);
$output->info('当前Layui版本号为' . $this::LAYUI_VERSION);
$output->info('当前ThinkPHP版本号为' . ThinkApp::VERSION);

View File

@@ -364,6 +364,6 @@ function set_store_value($key, $value)
if (!function_exists('get_site_version_key')) {
function get_site_version_key()
{
return sysconfig('site', 'site_version') . '-' . Version::VERSION . '-' . Version::LAYUI_VERSION;
return sysconfig('site', 'site_version') . '-' . Version::VERSION . '-' . Version::PRODUCT_VERSION . '-' . Version::LAYUI_VERSION;
}
}