Files
Gnuboard7/app/Console/Commands/Module/InstallModuleCommand.php
T
HeuJung b10e89bef0 fix(core,board,ecommerce,page,gdpr,ckeditor5,kginicis,admin_basic,basic): 목록 조회·검증 계층 정비 및 감사 지적 전건 처리
목록 조회 성능 축(깊은 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" 로 보고되던 문제도 런너 사전 검증으로 막았다.

정렬 게이트 대조 하네스는 관계 정렬 변형만 쓰는 저장소를 탐지하지 못한 채 통과시키고 있었다.
탐지·제외·인자 파싱을 함께 고치고 단위 테스트를 신설했다.
2026-08-02 15:29:29 +09:00

138 lines
5.3 KiB
PHP

<?php
namespace App\Console\Commands\Module;
use App\Console\Commands\Traits\HasProgressBar;
use App\Console\Commands\Traits\RebuildsSearchIndex;
use App\Contracts\Repositories\ModuleRepositoryInterface;
use App\Enums\ExtensionOwnerType;
use App\Extension\ModuleManager;
use App\Extension\Vendor\VendorMode;
use App\Models\Menu;
use App\Models\Permission;
use App\Rules\ValidExtensionIdentifier;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
class InstallModuleCommand extends Command
{
use HasProgressBar;
use RebuildsSearchIndex;
/**
* The name and signature of the console command.
*/
protected $signature = 'module:install
{identifier : 설치할 모듈 식별자}
{--vendor-mode=auto : Vendor 설치 모드 (auto|composer|bundled)}
{--force : 이미 설치된 경우에도 _bundled/_pending 원본으로 활성 디렉토리를 덮어쓰고 재설치 (불완전 설치 복구)}
{--rebuild-search-index : 완료 후 색인이 누락된 검색 인덱스를 재생성 (인덱스가 잠기거나 재색인됩니다 — 운영 중에는 유지보수 시간에 수행하세요)}';
/**
* The console command description.
*/
protected $description = '모듈을 설치합니다';
/**
* 모듈 관리자 및 리포지토리
*/
public function __construct(
private ModuleManager $moduleManager,
private ModuleRepositoryInterface $moduleRepository
) {
parent::__construct();
}
/**
* Execute the console command.
*/
public function handle(): int
{
$identifier = $this->argument('identifier');
// 식별자 형식 검증
$validator = Validator::make(
['identifier' => $identifier],
['identifier' => [new ValidExtensionIdentifier]]
);
if ($validator->fails()) {
$this->error('❌ '.$validator->errors()->first('identifier'));
return Command::FAILURE;
}
$force = (bool) $this->option('force');
try {
// 모듈 디렉토리 스캔 및 로드
$this->moduleManager->loadModules();
// 이미 설치된 모듈인지 확인 (force 시 스킵하여 재설치/복구 허용)
$existingModule = $this->moduleRepository->findByIdentifier($identifier);
if ($existingModule && ! $force) {
$this->warn('⚠️ '.__('modules.commands.install.already_installed', ['module' => $identifier]));
return Command::FAILURE;
}
if ($existingModule && $force) {
$this->warn('⚠️ '.__('modules.commands.install.force_reinstall', ['module' => $identifier]));
}
// 모듈 설치
$vendorMode = VendorMode::fromStringOrAuto((string) $this->option('vendor-mode'));
$onProgress = $this->createProgressCallback(ModuleManager::INSTALL_STEPS);
try {
$result = $this->moduleManager->installModule($identifier, $onProgress, $vendorMode, $force);
$this->finishProgress();
} catch (\Exception $e) {
$this->finishProgress();
throw $e;
}
if ($result) {
// 설치된 모듈 정보 조회
$module = $this->moduleRepository->findByIdentifier($identifier);
// 모듈 인스턴스에서 생성된 role 개수 조회
$moduleInstance = $this->moduleManager->getModule($identifier);
$rolesCount = 0;
if ($moduleInstance && method_exists($moduleInstance, 'getRoles')) {
$rolesCount = count($moduleInstance->getRoles());
}
// 권한 및 메뉴 개수 조회
$permissionsCount = Permission::byExtension(ExtensionOwnerType::Module, $identifier)->count();
$menusCount = Menu::byExtension(ExtensionOwnerType::Module, $identifier)->count();
// 성공 메시지
$this->info('✅ '.__('modules.commands.install.success', ['module' => $identifier]));
$this->info(' - '.__('modules.commands.install.vendor', ['vendor' => $module->vendor]));
$this->info(' - '.__('modules.commands.install.version', ['version' => $module->version]));
$this->info(' - '.__('modules.commands.install.roles_created', ['count' => $rolesCount]));
$this->info(' - '.__('modules.commands.install.permissions_created', ['count' => $permissionsCount]));
$this->info(' - '.__('modules.commands.install.menus_created', ['count' => $menusCount]));
Log::info(__('modules.commands.install.success', ['module' => $identifier]));
// 검색 인덱스 재생성은 운영자가 선택했을 때만 수행한다 (인덱스 잠금·재색인 비용)
$this->handleSearchIndexRebuild();
return Command::SUCCESS;
}
return Command::FAILURE;
} catch (\Exception $e) {
$this->error('❌ '.$e->getMessage());
Log::error('모듈 설치 실패', [
'module' => $identifier,
'error' => $e->getMessage(),
]);
return Command::FAILURE;
}
}
}