Files
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

115 lines
3.9 KiB
PHP

<?php
namespace App\Console\Commands\Traits;
use App\Search\DTO\SearchIndexHealth;
use App\Search\DTO\SearchIndexRepairReport;
use App\Search\SearchIndexMaintenanceManager;
/**
* 설치·업데이트 커맨드에 "검색 인덱스 재생성" 선택 옵션을 제공하는 트레이트.
*
* 재생성 비용은 엔진마다 다르지만(테이블 잠금 / 전체 재색인) 어느 쪽이든 운영 중인
* 사이트에 영향을 줍니다. 그래서 **기본값은 재생성하지 않음**이고, 운영자가
* `--rebuild-search-index` 로 명시했을 때만 수행합니다.
*
* 옵션을 주지 않아도 점검 결과는 안내합니다 — 색인이 누락되면 검색이 오류 없이 0건을
* 돌려주므로, 알려주지 않으면 운영자가 알 방법이 없습니다.
*/
trait RebuildsSearchIndex
{
/**
* 커맨드 `$signature` 에 붙일 옵션 정의.
*
* @return string 옵션 시그니처 조각
*/
public static function rebuildSearchIndexOption(): string
{
return '{--rebuild-search-index : 완료 후 색인이 누락된 검색 인덱스를 재생성 (인덱스가 잠기거나 재색인됩니다 — 운영 중에는 점검 결과만 확인하고 유지보수 시간에 수행하세요)}';
}
/**
* 작업 완료 후 검색 인덱스를 점검하고, 요청이 있었으면 재생성합니다.
*
* @param bool|null $requested 재생성 요청 여부 (null 이면 커맨드 옵션에서 읽음)
* @return SearchIndexRepairReport|null 재생성 보고 (재생성을 하지 않았으면 null)
*/
protected function handleSearchIndexRebuild(?bool $requested = null): ?SearchIndexRepairReport
{
$manager = app(SearchIndexMaintenanceManager::class);
// 점검을 제공하지 않는 엔진에서는 조용히 넘어간다 (검색 자체는 정상 동작)
if (! $manager->hasMaintainer() || $manager->unavailableReason() !== null) {
return null;
}
$requested ??= (bool) $this->option('rebuild-search-index');
if ($requested) {
$report = $manager->repairStale();
$this->reportRebuild($report);
return $report;
}
$this->warnStale($manager->inspect());
return null;
}
/**
* 재생성하지 않은 경우, 색인 누락 사실만 안내합니다.
*
* @param array<int, SearchIndexHealth> $results 점검 결과
* @return void
*/
private function warnStale(array $results): void
{
$stale = array_values(array_filter($results, fn (SearchIndexHealth $h) => $h->needsRebuild()));
if ($stale === []) {
return;
}
$this->newLine();
$this->warn('⚠️ '.__('search.index.stale_after_update', ['count' => count($stale)]));
foreach ($stale as $health) {
$this->line(' - '.$health->identifier);
}
$this->line(' '.__('search.index.stale_hint'));
}
/**
* 재생성 보고를 콘솔에 출력합니다.
*
* @param SearchIndexRepairReport $report 재생성 보고
* @return void
*/
private function reportRebuild(SearchIndexRepairReport $report): void
{
$this->newLine();
if (! $report->didRebuild()) {
$this->info('✅ '.$report->summary());
return;
}
$this->info('✅ '.$report->summary());
foreach ($report->repaired as $identifier) {
$this->line(' '.__('search.index.rebuilt_item', ['index' => $identifier]));
}
foreach ($report->failed as $identifier => $message) {
$this->error(' '.__('search.index.rebuild_failed_item', ['index' => $identifier, 'error' => $message]));
}
foreach ($report->remaining as $identifier) {
$this->warn(' '.__('search.index.still_stale_item', ['index' => $identifier]));
}
}
}