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

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 REPO = 'https://gitee.com/ulthon/ulthon_admin.git';
public const PRODUCT_REPO = '';
public $useRepo = null;
public $useVersion = null;
public $type = 'ulthon_admin';
/** /**
* @var Input * @var Input
*/ */
@@ -27,8 +35,15 @@ class AdminUpdateServiceBase
*/ */
public $output; 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() public function update()
@@ -38,7 +53,7 @@ class AdminUpdateServiceBase
$this->cleanWorkpaceDir(); $this->cleanWorkpaceDir();
$current_version = Version::VERSION; $current_version = $this->useVersion;
$current_version_dir = App::getRuntimePath() . '/update/' . $current_version; $current_version_dir = App::getRuntimePath() . '/update/' . $current_version;
$last_version_dir = App::getRuntimePath() . '/update/last'; $last_version_dir = App::getRuntimePath() . '/update/last';
@@ -47,7 +62,7 @@ class AdminUpdateServiceBase
$output->writeln('获取最新代码'); $output->writeln('获取最新代码');
$last_version_git = new Git(); $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(); $tags = $last_version_repo->getTags();
@@ -87,7 +102,7 @@ class AdminUpdateServiceBase
$current_version_git = new Git(); $current_version_git = new Git();
$output->writeln('获取当前版本代码'); $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); $output->writeln('切换版本' . $current_version);
$current_version_repo->checkout($current_version); $current_version_repo->checkout($current_version);
@@ -228,7 +243,6 @@ class AdminUpdateServiceBase
// 如果现存版本和当前版本一致,则直接处理 // 如果现存版本和当前版本一致,则直接处理
if (PathTools::compareFiles($now_file_path, $current_file_path)) { 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; continue;
@@ -348,7 +362,7 @@ class AdminUpdateServiceBase
'app', 'app',
'config', 'config',
'route', 'route',
'docker' 'docker',
]; ];
foreach ($optional_files_prefix as $prefix) { foreach ($optional_files_prefix as $prefix) {

View File

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

View File

@@ -14,6 +14,8 @@ class VersionBase extends Command
{ {
public const VERSION = 'v2.0.103'; public const VERSION = 'v2.0.103';
public const PRODUCT_VERSION = '';
public const LAYUI_VERSION = '2.8.17'; public const LAYUI_VERSION = '2.8.17';
public const COMMENT = [ public const COMMENT = [
@@ -32,7 +34,10 @@ class VersionBase extends Command
protected function execute(Input $input, Output $output) 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('当前Layui版本号为' . $this::LAYUI_VERSION);
$output->info('当前ThinkPHP版本号为' . ThinkApp::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')) { if (!function_exists('get_site_version_key')) {
function 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;
} }
} }