feat(ckeditor5,board,ecommerce,page,core,admin_basic): 미참조 에디터 업로드 이미지 정리 신설 + 업로드 고아 동종 결함 7건 전수 해소

공개 (@Tuwasduliebst 제보) 대응.

- ckeditor5: 미참조 이미지 정리 엔진 신설 — 참조 판정(hash + 파일명 2토큰,
 filter_reference_sources 훅으로 확장 콘텐츠 등록) + 정리 커맨드(기본 꺼짐 옵트인,
 3중 게이트) + 업로드 관리 화면(권한 분리·참조 배지·개별/선택 삭제) + 기설치본
 설정 백필 upgrade step
- board: 임시 첨부 GC(상시) + 소프트삭제 첨부 영구 정리(옵트인) + 설정 UI,
 저장 payload 누락(F4)·빈 temp 디렉토리 잔존(F5) 수정
- ecommerce: 임시 상품 이미지 GC + 카테고리 삭제 시 이미지 파일 미삭제(S4) 수정
- page: 임시 첨부 GC
- 코어: 고아 첨부 정리 커맨드(옵트인, site_logo 보호) + 사이트 로고 교체 시
 구 로고 재편입 차단(S6) + DB 백업 미구현 501 정직화(B3) + 플러그인 관리자
 메뉴 설치·업데이트 자동 동기화(F1·F7)
- 동반: 플러그인 설정 검증 오류 필드명 라벨화(F3), Toggle 노드 type 정정
 수평 전개(marketing 1.0.2 bump·gdpr·ecommerce), ja 언어팩 4종, API 문서,
 hooks.md, 시나리오 매니페스트 8종, Playwright E2E 4종
This commit is contained in:
HeuJung committed 2026-08-17 02:44:54 +09:00
1 parent 1d895a6428
commit cfc2caba1b
170 files changed
+11142 -209

No files matched your search

@@ -0,0 +1,92 @@
<?php
namespace Modules\Sirsoft\Ecommerce\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use Modules\Sirsoft\Ecommerce\Services\ProductImageService;
/**
* 미연결 임시 상품 이미지 정리 커맨드
*
* 상품 등록 폼에서 업로드만 하고 저장 없이 이탈해 남은 임시 이미지(파일 + 기록)를 정리합니다.
* 연결 시점에 본경로로 옮겨지므로 `temp_key` 가 남아 있다는 것은 "끝내 연결되지 않았다" 는
* 뜻이고, 그래서 별도 운영자 토글 없이 상시 동작합니다 (운영 데이터가 아닌 폼 세션 부산물).
*
* @example php artisan sirsoft-ecommerce:prune-temp-product-images --dry-run
* @example php artisan sirsoft-ecommerce:prune-temp-product-images --days=1
*/
class PruneTempProductImagesCommand extends Command
{
/**
* 커맨드 이름 및 시그니처
*
* @var string
*/
protected $signature = 'sirsoft-ecommerce:prune-temp-product-images
{--dry-run : 실제 삭제 없이 대상 건수만 확인}
{--limit=500 : 한 번에 처리할 최대 건수}
{--days=2 : 임시 이미지 보존기간(일)}';
/**
* 커맨드 설명
*
* @var string
*/
protected $description = '상품에 연결되지 않은 채 방치된 임시 상품 이미지를 정리합니다.';
/**
* @param ProductImageService $productImageService 상품 이미지 서비스
*/
public function __construct(
protected ProductImageService $productImageService
) {
parent::__construct();
}
/**
* 커맨드 실행
*
* @return int 종료 코드
*/
public function handle(): int
{
$days = (int) $this->option('days');
// 보존기간 0 이하 = 방금 올린 임시 이미지까지 지우게 되므로 차단한다.
if ($days < 1) {
$this->info('임시 이미지 보존기간이 1일 미만이어서 정리를 수행하지 않았습니다.');
return Command::SUCCESS;
}
$limit = max(1, (int) $this->option('limit'));
$isDryRun = (bool) $this->option('dry-run');
$result = $this->productImageService->pruneTempUploads($days, $limit, $isDryRun);
if ($isDryRun) {
$this->info("[DRY RUN] 보존기간({$days}일) 경과 미연결 임시 상품 이미지: {$result['scanned']}건");
return Command::SUCCESS;
}
$this->info(sprintf(
'보존기간(%d일) 경과 임시 상품 이미지 %d건 중 %d건을 삭제했습니다. (실패 %d건)',
$days,
$result['scanned'],
$result['deleted'],
$result['failed'],
));
Log::info('PruneTempProductImagesCommand: 임시 상품 이미지 정리 완료', [
'days' => $days,
'limit' => $limit,
'scanned' => $result['scanned'],
'deleted' => $result['deleted'],
'failed' => $result['failed'],
]);
return Command::SUCCESS;
}
}
@@ -0,0 +1,57 @@
<?php
namespace Modules\Sirsoft\Ecommerce\Listeners;
use App\Contracts\Extension\HookListenerInterface;
/**
* 상품 설명·공통 안내를 CKEditor5 이미지 참조 스캔 대상으로 등록하는 리스너
*
* `sirsoft-ckeditor5.image.filter_reference_sources` 필터 훅에 상품 상세 설명과
* 상품 공통 정보 본문 컬럼을 덧붙입니다. 등록하지 않으면 상품 설명에만 쓰이는
* 이미지가 "미참조" 로 판정돼 자동 정리 대상이 됩니다.
*
* 테이블명 문자열만 덧붙이며 DB 에 접근하지 않습니다.
*/
class Ckeditor5ReferenceSourcesListener implements HookListenerInterface
{
/**
* 구독할 훅 목록 반환
*
* @return array<string, mixed>
*/
public static function getSubscribedHooks(): array
{
return [
'sirsoft-ckeditor5.image.filter_reference_sources' => [
'method' => 'addEcommerceSources',
'priority' => 10,
'type' => 'filter',
],
];
}
/**
* 훅 이벤트를 처리합니다.
*
* Filter 훅은 getSubscribedHooks 에서 지정한 메서드를 직접 호출하므로
* 이 메서드는 인터페이스 요구사항 충족을 위해서만 존재합니다.
*
* @param mixed ...$args 훅에서 전달된 인수들
*/
public function handle(...$args): void {}
/**
* 이커머스 참조 소스를 추가합니다.
*
* @param array $sources 기존 참조 소스 목록
* @return array 이커머스 소스가 추가된 목록
*/
public function addEcommerceSources(array $sources): array
{
$sources[] = ['table' => 'ecommerce_products', 'columns' => ['description']];
$sources[] = ['table' => 'ecommerce_product_common_infos', 'columns' => ['content']];
return $sources;
}
}
@@ -11,6 +11,7 @@ use Modules\Sirsoft\Ecommerce\Console\Commands\ExpireMileageCommand;
use Modules\Sirsoft\Ecommerce\Console\Commands\NotifyExpiringMileageCommand;
use Modules\Sirsoft\Ecommerce\Console\Commands\PruneExpiredCartsCommand;
use Modules\Sirsoft\Ecommerce\Console\Commands\PruneExpiredTempOrdersCommand;
use Modules\Sirsoft\Ecommerce\Console\Commands\PruneTempProductImagesCommand;
use Modules\Sirsoft\Ecommerce\Console\Commands\ReconcileMileageBalanceCommand;
use Modules\Sirsoft\Ecommerce\Http\Middleware\DetectDevice;
use Modules\Sirsoft\Ecommerce\Repositories\BrandRepository;
@@ -199,6 +200,7 @@ class EcommerceServiceProvider extends BaseModuleServiceProvider
NotifyExpiringMileageCommand::class,
PruneExpiredCartsCommand::class,
PruneExpiredTempOrdersCommand::class,
PruneTempProductImagesCommand::class,
ReconcileMileageBalanceCommand::class,
];
@@ -90,6 +90,14 @@ class CategoryImageRepository implements CategoryImageRepositoryInterface
return $image?->delete() ?? false;
}
/**
* {@inheritDoc}
*/
public function deleteByCategoryId(int $categoryId): int
{
return $this->model->where('category_id', $categoryId)->delete();
}
/**
* {@inheritDoc}
*/
@@ -13,7 +13,7 @@ interface CategoryImageRepositoryInterface
/**
* ID로 이미지 조회
*
* @param int $id 이미지 ID
* @param int $id 이미지 ID
* @return CategoryImage|null
*/
public function findById(int $id): ?CategoryImage;
@@ -21,7 +21,7 @@ interface CategoryImageRepositoryInterface
/**
* 해시로 이미지 조회
*
* @param string $hash 이미지 해시
* @param string $hash 이미지 해시
* @return CategoryImage|null
*/
public function findByHash(string $hash): ?CategoryImage;
@@ -29,8 +29,8 @@ interface CategoryImageRepositoryInterface
/**
* 카테고리의 모든 이미지 조회
*
* @param int $categoryId 카테고리 ID
* @param string|null $collection 컬렉션 필터
* @param int $categoryId 카테고리 ID
* @param string|null $collection 컬렉션 필터
* @return Collection
*/
public function getByCategoryId(int $categoryId, ?string $collection = null): Collection;
@@ -38,8 +38,8 @@ interface CategoryImageRepositoryInterface
/**
* temp_key로 임시 이미지 조회
*
* @param string $tempKey 임시 키
* @param string|null $collection 컬렉션 필터
* @param string $tempKey 임시 키
* @param string|null $collection 컬렉션 필터
* @return Collection
*/
public function getByTempKey(string $tempKey, ?string $collection = null): Collection;
@@ -47,7 +47,7 @@ interface CategoryImageRepositoryInterface
/**
* 카테고리 이미지 생성
*
* @param array $data 이미지 데이터
* @param array $data 이미지 데이터
* @return CategoryImage
*/
public function create(array $data): CategoryImage;
@@ -55,8 +55,8 @@ interface CategoryImageRepositoryInterface
/**
* 이미지 수정
*
* @param int $id 이미지 ID
* @param array $data 수정할 데이터
* @param int $id 이미지 ID
* @param array $data 수정할 데이터
* @return CategoryImage
*/
public function update(int $id, array $data): CategoryImage;
@@ -64,16 +64,26 @@ interface CategoryImageRepositoryInterface
/**
* 이미지 삭제
*
* @param int $id 이미지 ID
* @param int $id 이미지 ID
* @return bool
*/
public function delete(int $id): bool;
/**
* 카테고리에 속한 이미지 행을 일괄 삭제
*
* 물리 파일 삭제는 호출한 Service 가 담당합니다 (행마다 disk 가 다를 수 있음).
*
* @param int $categoryId 카테고리 ID
* @return int 삭제된 행 수
*/
public function deleteByCategoryId(int $categoryId): int;
/**
* 임시 이미지를 카테고리에 연결
*
* @param string $tempKey 임시 키
* @param int $categoryId 카테고리 ID
* @param string $tempKey 임시 키
* @param int $categoryId 카테고리 ID
* @return int 연결된 이미지 수
*/
public function linkTempImages(string $tempKey, int $categoryId): int;
@@ -81,8 +91,8 @@ interface CategoryImageRepositoryInterface
/**
* 카테고리의 최대 sort_order 조회
*
* @param int $categoryId 카테고리 ID
* @param string $collection 컬렉션명
* @param int $categoryId 카테고리 ID
* @param string $collection 컬렉션명
* @return int
*/
public function getMaxSortOrder(int $categoryId, string $collection): int;
@@ -90,8 +100,8 @@ interface CategoryImageRepositoryInterface
/**
* temp_key의 최대 sort_order 조회
*
* @param string $tempKey 임시 키
* @param string $collection 컬렉션명
* @param string $tempKey 임시 키
* @param string $collection 컬렉션명
* @return int
*/
public function getMaxSortOrderByTempKey(string $tempKey, string $collection): int;
@@ -99,7 +109,7 @@ interface CategoryImageRepositoryInterface
/**
* 순서 변경
*
* @param array<int, int> $orders 이미지 ID => sort_order 매핑
* @param array<int, int> $orders 이미지 ID => sort_order 매핑
* @return bool
*/
public function reorder(array $orders): bool;
@@ -3,6 +3,7 @@
namespace Modules\Sirsoft\Ecommerce\Repositories\Contracts;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Carbon;
use Modules\Sirsoft\Ecommerce\Models\ProductImage;
/**
@@ -69,6 +70,18 @@ interface ProductImageRepositoryInterface
*/
public function delete(int $id): bool;
/**
* 상품에 연결되지 않은 채 방치된 임시 이미지를 오래된 순으로 조회
*
* 상품 등록 폼에서 업로드만 하고 저장 없이 이탈하면 `temp_key` 가 남은 채
* `product_id` 가 비어 있는 행과 그 파일이 영구 잔존합니다. 그 회수 대상을 찾습니다.
*
* @param Carbon $threshold 기준 시각 (이 시각 이전 업로드가 대상)
* @param int $limit 최대 조회 건수
* @return Collection<int, ProductImage> 임시 이미지 목록 (created_at 오름차순)
*/
public function findStaleTempImages(Carbon $threshold, int $limit): Collection;
/**
* 임시 이미지를 상품에 연결
*
@@ -3,6 +3,7 @@
namespace Modules\Sirsoft\Ecommerce\Repositories;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Carbon;
use Modules\Sirsoft\Ecommerce\Models\ProductImage;
use Modules\Sirsoft\Ecommerce\Repositories\Contracts\ProductImageRepositoryInterface;
@@ -90,6 +91,21 @@ class ProductImageRepository implements ProductImageRepositoryInterface
return $image?->forceDelete() ?? false;
}
/**
* {@inheritDoc}
*/
public function findStaleTempImages(Carbon $threshold, int $limit): Collection
{
return $this->model->newQuery()
->whereNotNull('temp_key')
->whereNull('product_id')
->where('created_at', '<', $threshold)
->orderBy('created_at')
->orderBy('id')
->limit($limit)
->get(['id', 'temp_key', 'disk', 'path', 'created_at']);
}
/**
* {@inheritDoc}
*/
@@ -248,6 +248,49 @@ class CategoryImageService
return $result;
}
/**
* 카테고리에 속한 이미지를 파일까지 함께 삭제합니다.
*
* 카테고리 삭제 흐름에서 호출합니다. 단건 삭제(delete)와 달리 남은 이미지 재정렬이
* 필요 없으므로(카테고리 자체가 사라짐) 재정렬 없이 파일 → 행 순으로 정리합니다.
*
* 행마다 disk 가 다를 수 있으므로 파일 삭제는 각 행의 disk 를 향해 수행합니다.
*
* @param int $categoryId 카테고리 ID
* @return int 삭제된 이미지 행 수
*/
public function deleteByCategoryId(int $categoryId): int
{
$images = $this->repository->getByCategoryId($categoryId);
if ($images->isEmpty()) {
return 0;
}
foreach ($images as $image) {
HookManager::doAction('sirsoft-ecommerce.category-image.before_delete', $image);
$rowStorage = $this->storageForRow($image->disk);
if ($rowStorage->exists('images', $image->path)) {
$rowStorage->delete('images', $image->path);
}
}
$deleted = $this->repository->deleteByCategoryId($categoryId);
Log::info('카테고리 이미지 일괄 삭제 완료', [
'category_id' => $categoryId,
'deleted' => $deleted,
]);
foreach ($images as $image) {
HookManager::doAction('sirsoft-ecommerce.category-image.after_delete', $image);
}
return $deleted;
}
/**
* 순서 변경
*
@@ -18,7 +18,8 @@ class CategoryService
{
public function __construct(
protected CategoryRepositoryInterface $repository,
protected CategoryImageRepositoryInterface $imageRepository
protected CategoryImageRepositoryInterface $imageRepository,
protected CategoryImageService $categoryImageService
) {}
/**
@@ -274,7 +275,9 @@ class CategoryService
DB::transaction(function () use ($category) {
// 카테고리 이미지 삭제 (명시적 삭제 - CASCADE 의존 금지)
$category->images()->delete();
// 물리 파일 → 행 순으로 정리한다. 행만 지우면 파일이 디스크에 영구 잔존한다
// (상품 삭제와 동일한 순서 — ProductService::delete 선례).
$this->categoryImageService->deleteByCategoryId($category->id);
// 카테고리 삭제
$this->repository->delete($category->id);
@@ -7,6 +7,7 @@ use App\Extension\HookManager;
use App\Support\ImageResizer;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
@@ -492,6 +493,92 @@ class ProductImageService
return ! in_array(false, $results, true);
}
/**
* 상품에 연결되지 않은 채 방치된 임시 이미지를 정리합니다.
*
* 상품 등록 폼에서 이미지를 올린 뒤 저장하지 않고 이탈하면 `temp_key` 만 남은 행과
* 그 파일이 남습니다. 연결 시점에 본경로로 옮겨지므로 `temp_key` 가 남아 있다는 것은
* "끝내 연결되지 않았다" 는 뜻이고, 그래서 오탐 여지가 없습니다.
*
* 파일은 행마다 기록된 disk 를 향해 지웁니다 (디스크 전환 이후 혼재 대응).
* 파일 → 행 순서를 지켜, 행이 먼저 사라져 파일을 못 찾는 상태를 만들지 않습니다.
*
* @param int $days 보존기간(일)
* @param int $limit 한 회차에 처리할 최대 건수
* @param bool $dryRun true 면 대상만 세고 삭제하지 않음
* @return array{scanned: int, deleted: int, failed: int} 처리 결과
*/
public function pruneTempUploads(int $days, int $limit, bool $dryRun = false): array
{
$threshold = Carbon::now()->subDays($days);
$images = $this->repository->findStaleTempImages($threshold, $limit);
$result = ['scanned' => $images->count(), 'deleted' => 0, 'failed' => 0];
if ($dryRun) {
return $result;
}
foreach ($images as $image) {
$rowStorage = $this->storageForRow($image->disk);
if ($rowStorage->exists('images', $image->path) && ! $rowStorage->delete('images', $image->path)) {
Log::warning('임시 상품 이미지 파일 삭제 실패 — 기록 보존', [
'image_id' => $image->id,
'disk' => $image->disk,
'path' => $image->path,
]);
$result['failed']++;
continue;
}
$this->repository->delete($image->id);
$result['deleted']++;
}
$this->removeEmptyTempDirectories($images);
return $result;
}
/**
* 파일을 모두 지운 temp_key 디렉토리를 정리합니다.
*
* 파일만 지우고 디렉토리를 남기면 폼 세션마다 빈 디렉토리가 쌓여, 정리를 돌려도
* 저장소에는 흔적이 계속 늘어납니다.
*
* 디렉토리에 파일이 남아 있으면(같은 temp_key 의 다른 이미지가 limit 에 걸려 이번 회차에서
* 빠졌거나 파일 삭제에 실패한 경우 등) 삭제하지 않습니다.
*
* @param Collection $images 이번 회차에 처리한 이미지 목록
*/
private function removeEmptyTempDirectories(Collection $images): void
{
$directories = [];
foreach ($images as $image) {
$directory = dirname((string) $image->path);
if ($directory === '' || $directory === '.') {
continue;
}
$directories[$image->disk.'|'.$directory] = [$image->disk, $directory];
}
foreach ($directories as [$disk, $directory]) {
$storage = $this->storageForRow($disk);
if ($storage->files('images', $directory) !== []) {
continue;
}
$storage->deleteDirectory('images', $directory);
}
}
/**
* 상품의 이미지 목록을 조회합니다.
*