mirror of
https://gitee.com/zoujingli/ThinkAdmin.git
synced 2026-06-07 20:48:09 +08:00
fix(command): 修复迁移打包选项与发布清理逻辑
This commit is contained in:
parent
27568cecfa
commit
a58b8c0b29
@ -80,11 +80,13 @@ class Package extends Command
|
|||||||
*/
|
*/
|
||||||
private function createScheme(): bool
|
private function createScheme(): bool
|
||||||
{
|
{
|
||||||
$force = $this->input->hasOption('force');
|
$force = boolval($this->input->getOption('force'));
|
||||||
|
$table = trim((string)$this->input->getOption('table'));
|
||||||
|
$all = boolval($this->input->getOption('all'));
|
||||||
// 接收指定打包数据表
|
// 接收指定打包数据表
|
||||||
if ($this->input->hasOption('table')) {
|
if ($table !== '') {
|
||||||
$tables = str2arr(strtr($this->input->getOption('table'), '|', ','));
|
$tables = str2arr(strtr($table, '|', ','));
|
||||||
} elseif ($this->input->hasOption('all')) {
|
} elseif ($all) {
|
||||||
[$tables] = SystemService::getTables();
|
[$tables] = SystemService::getTables();
|
||||||
} else {
|
} else {
|
||||||
$tables = Library::$sapp->config->get('phinx.tables', []);
|
$tables = Library::$sapp->config->get('phinx.tables', []);
|
||||||
@ -134,10 +136,12 @@ class Package extends Command
|
|||||||
*/
|
*/
|
||||||
private function createBackup(): bool
|
private function createBackup(): bool
|
||||||
{
|
{
|
||||||
|
$backup = trim((string)$this->input->getOption('backup'));
|
||||||
|
$all = boolval($this->input->getOption('all'));
|
||||||
// 接收指定打包数据表
|
// 接收指定打包数据表
|
||||||
if ($this->input->hasOption('backup')) {
|
if ($backup !== '') {
|
||||||
$tables = str2arr(strtr($this->input->getOption('backup'), '|', ','));
|
$tables = str2arr(strtr($backup, '|', ','));
|
||||||
} elseif ($this->input->hasOption('all')) {
|
} elseif ($all) {
|
||||||
[$tables] = SystemService::getTables();
|
[$tables] = SystemService::getTables();
|
||||||
} else {
|
} else {
|
||||||
[$tables] = SystemService::getTables();
|
[$tables] = SystemService::getTables();
|
||||||
|
|||||||
@ -91,9 +91,50 @@ class Publish extends Command
|
|||||||
|
|
||||||
// 复制数据库脚本
|
// 复制数据库脚本
|
||||||
$frdir = rtrim($copy, '\/') . DIRECTORY_SEPARATOR . 'database';
|
$frdir = rtrim($copy, '\/') . DIRECTORY_SEPARATOR . 'database';
|
||||||
|
$this->cleanupPublishedMigrations($frdir, syspath('database/migrations'));
|
||||||
ToolsExtend::copy($frdir, syspath('database/migrations'), [], $force, false);
|
ToolsExtend::copy($frdir, syspath('database/migrations'), [], $force, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清理已改名但仍残留在根目录的旧迁移脚本.
|
||||||
|
*/
|
||||||
|
private function cleanupPublishedMigrations(string $source, string $target): void
|
||||||
|
{
|
||||||
|
if (!is_dir($source) || !is_dir($target)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sourceMigrations = [];
|
||||||
|
foreach (ToolsExtend::find($source, 1, function (\SplFileInfo $info) {
|
||||||
|
return $info->isFile() && strtolower($info->getExtension()) === 'php';
|
||||||
|
}) as $file) {
|
||||||
|
$name = basename($file);
|
||||||
|
if (preg_match('/^\d{14}_(.+\.php)$/', $name, $match)) {
|
||||||
|
$sourceMigrations[$match[1]] = $name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (empty($sourceMigrations)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (ToolsExtend::find($target, 1, function (\SplFileInfo $info) {
|
||||||
|
return $info->isFile() && strtolower($info->getExtension()) === 'php';
|
||||||
|
}) as $file) {
|
||||||
|
$name = basename($file);
|
||||||
|
if (!preg_match('/^(\d{14})_(.+\.php)$/', $name, $match)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
[$version, $suffix] = [$match[1], $match[2]];
|
||||||
|
if (($sourceMigrations[$suffix] ?? $name) === $name) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
@unlink(rtrim($target, '\/') . DIRECTORY_SEPARATOR . $name);
|
||||||
|
if (is_dir($dataPath = rtrim($target, '\/') . DIRECTORY_SEPARATOR . $version)) {
|
||||||
|
ToolsExtend::remove($dataPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 解析 json 包.
|
* 解析 json 包.
|
||||||
* @return $this
|
* @return $this
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user