feat(update): 冲突策略参数替代交互确认

This commit is contained in:
augushong
2026-05-25 22:44:34 +08:00
parent 2e3fac93f0
commit 67c613788f

View File

@@ -268,9 +268,32 @@ class AdminUpdateServiceBase
}
if (!empty($optional_update_waring_files)) {
$strategy = $this->optionalConflict ?: null; // empty string → null
if ($this->dryRun) {
$need_process_files = array_merge($need_process_files, $optional_update_waring_files);
if ($strategy === null) {
// 未传参数:保持现有 dry-run 行为(合并所有冲突文件)
$need_process_files = array_merge($need_process_files, $optional_update_waring_files);
} else {
// 显式传了策略:按策略决定
$effective = ($strategy === 'ask') ? 'skip' : $strategy;
if ($effective === 'overwrite') {
$need_process_files = array_merge($need_process_files, $optional_update_waring_files);
} else {
// skip: 记录被跳过的文件(供输出增强使用)
$this->skippedConflictFiles = array_merge(
$this->skippedConflictFiles,
array_map(fn($t) => ['type' => $t, 'category' => 'optional'], $optional_update_waring_files)
);
}
}
} elseif ($strategy !== null && $strategy !== 'ask') {
// 显式指定了非 ask 策略,静默处理
if ($strategy === 'overwrite') {
$need_process_files = array_merge($need_process_files, $optional_update_waring_files);
}
// skip: 不加入
} else {
// null 或 ask: 走原有交互确认(完全保持现有行为)
foreach ($optional_update_waring_files as $file_path => $type) {
$output->writeln($file_path . ' ' . $type);
}
@@ -287,9 +310,29 @@ class AdminUpdateServiceBase
}
if (!empty($force_update_waring_files)) {
$strategy = $this->forceConflict ?: null; // empty string → null
if ($this->dryRun) {
$need_process_files = array_merge($need_process_files, $force_update_waring_files);
if ($strategy === null) {
// 未传参数:保持现有 dry-run 行为(合并所有冲突文件)
$need_process_files = array_merge($need_process_files, $force_update_waring_files);
} else {
$effective = ($strategy === 'ask') ? 'overwrite' : $strategy;
if ($effective === 'overwrite') {
$need_process_files = array_merge($need_process_files, $force_update_waring_files);
} else {
// skip: 记录被跳过的文件
$this->skippedConflictFiles = array_merge(
$this->skippedConflictFiles,
array_map(fn($t) => ['type' => $t, 'category' => 'force'], $force_update_waring_files)
);
}
}
} elseif ($strategy !== null && $strategy !== 'ask') {
if ($strategy === 'overwrite') {
$need_process_files = array_merge($need_process_files, $force_update_waring_files);
}
} else {
// null 或 ask: 走原有交互确认
foreach ($force_update_waring_files as $file_path => $type) {
$output->writeln($file_path . ' ' . $type);
}