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

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) {