목록 조회 성능 축(깊은 OFFSET·정렬·색인)과 그 검증 계층에서 계획서 전수검수와 3회에 걸친 감사가 지적한 항목을 처리했다. 세부 경위는 의 각 회차 문서에 있다. 검증 계층 — 컨트롤러가 base Request 를 직접 주입받던 확장 13곳을 전용 FormRequest 로 옮겼다. 옮기면서 기존 동작 계약은 그대로 두었다: 상한 초과 limit 을 거부하지 않고 상한까지 반환하던 공개 API, per_page 를 범위로 조정하던 관리자 목록, 미지원 period 를 year 로 해석하던 인기글 목록 모두 종전과 같은 응답을 낸다. 상한/폴백을 rules 로 승격시키면 200 이던 응답이 422 가 되어 기존 링크가 깨지므로, 규칙은 타입만 닫고 클램프·폴백은 접근자가 맡는다. period 는 접근자가 닫힌 집합만 반환해 캐시 키 공간도 함께 닫힌다. ckeditor5 이미지 업로드만 ResponseHelper 봉투를 쓰지 않는다. 응답을 파싱하는 주체가 CDN 으로 로드되는 상위 CKEditor5 43.3.1 의 SimpleUploadAdapter 라 규약을 바꿀 수 없어, 각 응답 지점에 사유를 명시한 면제를 부착하고 근거를 API 문서에 남겼다. 하네스 — 룰 5개의 대상 경로 패턴이 매처와 맞지 않아 번들 확장 컨트롤러가 검사 대상에서 통째로 빠져 있었다. 패턴을 고치자 확장 위반 17건이 드러나 전건 처리했다. severity 오타가 요약 집계 양쪽에 안 잡혀 "0 error" 로 보고되던 문제도 런너 사전 검증으로 막았다. 정렬 게이트 대조 하네스는 관계 정렬 변형만 쓰는 저장소를 탐지하지 못한 채 통과시키고 있었다. 탐지·제외·인자 파싱을 함께 고치고 단위 테스트를 신설했다.
229 lines
9.0 KiB
PHP
229 lines
9.0 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands\Module;
|
|
|
|
use App\Console\Commands\Traits\HasProgressBar;
|
|
use App\Console\Commands\Traits\HasUnifiedConfirm;
|
|
use App\Console\Commands\Traits\RebuildsSearchIndex;
|
|
use App\Contracts\Repositories\ModuleRepositoryInterface;
|
|
use App\Enums\LayoutSourceType;
|
|
use App\Extension\ModuleManager;
|
|
use App\Extension\Vendor\VendorMode;
|
|
use App\Services\LayoutExtensionService;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class UpdateModuleCommand extends Command
|
|
{
|
|
use HasProgressBar;
|
|
use HasUnifiedConfirm;
|
|
use RebuildsSearchIndex;
|
|
|
|
/**
|
|
* The name and signature of the console command.
|
|
*/
|
|
protected $signature = 'module:update
|
|
{identifier : 업데이트할 모듈 식별자}
|
|
{--force : 버전 비교 없이 강제 업데이트}
|
|
{--vendor-mode=auto : Vendor 설치 모드 (auto|composer|bundled)}
|
|
{--layout-strategy=overwrite : 레이아웃 전략 (overwrite|keep)}
|
|
{--source=auto : 업데이트 소스 (auto|bundled|github) — bundled 는 _bundled 만 사용(GitHub 우회)}
|
|
{--zip= : 외부 ZIP 파일 경로 (지정 시 GitHub/번들 우회 + 버전은 module.json 기준)}
|
|
{--rebuild-search-index : 완료 후 색인이 누락된 검색 인덱스를 재생성 (인덱스가 잠기거나 재색인됩니다 — 운영 중에는 유지보수 시간에 수행하세요)}';
|
|
|
|
/**
|
|
* The console command description.
|
|
*/
|
|
protected $description = '모듈을 최신 버전으로 업데이트합니다';
|
|
|
|
/**
|
|
* 모듈 관리자 및 리포지토리
|
|
*/
|
|
public function __construct(
|
|
private ModuleManager $moduleManager,
|
|
private ModuleRepositoryInterface $moduleRepository,
|
|
private LayoutExtensionService $layoutExtensionService
|
|
) {
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*/
|
|
public function handle(): int
|
|
{
|
|
$identifier = $this->argument('identifier');
|
|
$force = $this->option('force');
|
|
$layoutStrategy = (string) $this->option('layout-strategy');
|
|
$sourceOption = (string) $this->option('source');
|
|
$zipPath = $this->option('zip');
|
|
|
|
if (! in_array($layoutStrategy, ['overwrite', 'keep'], true)) {
|
|
$this->error('❌ --layout-strategy 는 overwrite 또는 keep 이어야 합니다.');
|
|
|
|
return Command::FAILURE;
|
|
}
|
|
|
|
if (! in_array($sourceOption, ['auto', 'bundled', 'github'], true)) {
|
|
$this->error('❌ --source 는 auto, bundled, github 중 하나여야 합니다.');
|
|
|
|
return Command::FAILURE;
|
|
}
|
|
|
|
// --zip 과 --source 동시 지정 금지 (zip 이 우선 대상이므로)
|
|
if ($zipPath !== null && $sourceOption !== 'auto') {
|
|
$this->error('❌ --zip 은 --source 와 동시에 지정할 수 없습니다.');
|
|
|
|
return Command::FAILURE;
|
|
}
|
|
|
|
if ($zipPath !== null) {
|
|
$resolvedZip = realpath($zipPath);
|
|
if (! $resolvedZip || ! is_file($resolvedZip)) {
|
|
$this->error('❌ 지정된 ZIP 파일이 존재하지 않습니다: '.$zipPath);
|
|
|
|
return Command::FAILURE;
|
|
}
|
|
$zipPath = $resolvedZip;
|
|
}
|
|
|
|
$sourceOverride = $sourceOption === 'auto' ? null : $sourceOption;
|
|
|
|
try {
|
|
$this->moduleManager->loadModules();
|
|
|
|
// 모듈 존재 확인
|
|
$module = $this->moduleRepository->findByIdentifier($identifier);
|
|
|
|
if (! $module) {
|
|
$this->error('❌ '.__('modules.commands.update.not_installed', ['module' => $identifier]));
|
|
|
|
return Command::FAILURE;
|
|
}
|
|
|
|
// 업데이트 확인 (--zip 모드는 GitHub/번들 비교를 우회하므로 스킵)
|
|
if ($zipPath === null) {
|
|
$checkResult = $this->moduleManager->checkModuleUpdate($identifier);
|
|
|
|
if (! $checkResult['update_available'] && ! $force) {
|
|
$this->info('✅ '.__('modules.commands.update.no_update', ['module' => $identifier]));
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
|
|
// 업데이트 정보 표시
|
|
$this->info(__('modules.commands.update.current_version', ['version' => $checkResult['current_version']]));
|
|
|
|
if ($force && ! $checkResult['update_available']) {
|
|
$this->warn('⚠️ '.__('modules.commands.update.force_mode'));
|
|
} else {
|
|
$this->info(__('modules.commands.update.latest_version', ['version' => $checkResult['latest_version']]));
|
|
$this->info(__('modules.commands.update.update_source', ['source' => $checkResult['update_source']]));
|
|
}
|
|
} else {
|
|
$this->info(__('modules.commands.update.current_version', ['version' => $module->version]));
|
|
$this->info('업데이트 소스: ZIP ('.$zipPath.')');
|
|
$this->info('업데이트 버전: (module.json 추출 후 판별)');
|
|
}
|
|
|
|
$this->info(__('modules.commands.update.layout_strategy', ['strategy' => $layoutStrategy]));
|
|
|
|
// overwrite 전략일 때 관리자가 편집한 레이아웃 확장 경고
|
|
if ($layoutStrategy === 'overwrite') {
|
|
$modifiedExtensions = $this->layoutExtensionService->getModifiedExtensionsBySource(
|
|
LayoutSourceType::Module,
|
|
$identifier
|
|
);
|
|
|
|
if (! empty($modifiedExtensions)) {
|
|
$this->newLine();
|
|
$this->warn('⚠️ '.__('modules.commands.update.modified_extensions_warning', [
|
|
'count' => count($modifiedExtensions),
|
|
]));
|
|
|
|
foreach ($modifiedExtensions as $extension) {
|
|
$this->warn(__('modules.commands.update.modified_extension_item', [
|
|
'target' => $extension['target_name'],
|
|
'source' => $extension['source_identifier'],
|
|
]));
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->newLine();
|
|
|
|
// 확인 프롬프트 (--force 시 건너뜀)
|
|
if (! $force && ! $this->unifiedConfirm(__('modules.commands.update.confirm_question'), false)) {
|
|
$this->info(__('modules.commands.update.aborted'));
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
|
|
// 업데이트 실행
|
|
$vendorMode = VendorMode::fromStringOrAuto((string) $this->option('vendor-mode'));
|
|
$onProgress = $this->createProgressCallback(ModuleManager::UPDATE_STEPS);
|
|
|
|
// upgrade step 콘솔 출력 콜백: progress bar 를 잠시 지우고 별도 줄에 출력
|
|
$onUpgradeStep = function (string $version) use ($identifier): void {
|
|
if ($this->progressBar) {
|
|
$this->progressBar->clear();
|
|
}
|
|
$this->line(" • [{$identifier}] upgrade step 실행: {$version}");
|
|
if ($this->progressBar) {
|
|
$this->progressBar->display();
|
|
}
|
|
};
|
|
|
|
try {
|
|
$updateResult = $this->moduleManager->updateModule(
|
|
$identifier,
|
|
$force,
|
|
$onProgress,
|
|
$vendorMode,
|
|
$layoutStrategy,
|
|
$onUpgradeStep,
|
|
$sourceOverride,
|
|
$zipPath,
|
|
);
|
|
$this->finishProgress();
|
|
} catch (\Exception $e) {
|
|
$this->finishProgress();
|
|
throw $e;
|
|
}
|
|
|
|
if ($updateResult['success']) {
|
|
$this->newLine();
|
|
$this->info('✅ '.__('modules.commands.update.success', ['module' => $identifier]));
|
|
$this->info(' '.__('modules.commands.update.version_change', [
|
|
'from' => $updateResult['from_version'],
|
|
'to' => $updateResult['to_version'],
|
|
]));
|
|
|
|
Log::info('모듈 업데이트 완료', [
|
|
'module' => $identifier,
|
|
'from' => $updateResult['from_version'],
|
|
'to' => $updateResult['to_version'],
|
|
'layout_strategy' => $layoutStrategy,
|
|
]);
|
|
|
|
// 검색 인덱스 재생성은 운영자가 선택했을 때만 수행한다 (인덱스 잠금·재색인 비용)
|
|
$this->handleSearchIndexRebuild();
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
|
|
return Command::FAILURE;
|
|
} catch (\Exception $e) {
|
|
$this->error('❌ '.$e->getMessage());
|
|
$this->warn('💡 '.__('modules.commands.update.backup_restored'));
|
|
|
|
Log::error('모듈 업데이트 실패', [
|
|
'module' => $identifier,
|
|
'error' => $e->getMessage(),
|
|
]);
|
|
|
|
return Command::FAILURE;
|
|
}
|
|
}
|
|
}
|