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:
1 parent
1d895a6428
commit
cfc2caba1b
170 files changed
+11142
-209
No files matched your search
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Plugins\Sirsoft\Ckeditor5\Repositories\Contracts;
|
||||
|
||||
/**
|
||||
* 에디터 이미지 참조 소스 조회 Repository 인터페이스
|
||||
*
|
||||
* 참조 소스는 확장이 훅으로 등록하는 "테이블명 + 컬럼명" 이라 전용 모델이 없습니다.
|
||||
* 그래서 이 Repository 는 특정 엔티티가 아니라 **선언된 소스에 대한 조회**를 소유합니다 —
|
||||
* Service 는 어느 소스를 볼지와 무엇을 찾을지만 정하고, 실제 데이터 접근은 여기로 모읍니다.
|
||||
*/
|
||||
interface ImageReferenceSourceRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* 소스 선언이 실제 스키마에 존재하는지 검증하고, 존재하는 컬럼만 남깁니다.
|
||||
*
|
||||
* @param string $table 테이블명 (프리픽스 제외)
|
||||
* @param array<int, string> $columns 컬럼명 목록
|
||||
* @return array<int, string> 실재하는 컬럼 목록 (테이블이 없으면 빈 배열)
|
||||
*/
|
||||
public function resolveExistingColumns(string $table, array $columns): array;
|
||||
|
||||
/**
|
||||
* 지정 소스의 컬럼 중 하나라도 토큰을 포함하는 행이 있는지 확인합니다.
|
||||
*
|
||||
* @param string $table 테이블명 (프리픽스 제외)
|
||||
* @param array<int, string> $columns 검사할 컬럼 목록
|
||||
* @param array<int, string> $tokens 판정 토큰 (LIKE 이스케이프는 구현이 담당)
|
||||
* @return bool 하나라도 등장하면 true
|
||||
*/
|
||||
public function containsAnyToken(string $table, array $columns, array $tokens): bool;
|
||||
}
|
||||
+67
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace Plugins\Sirsoft\Ckeditor5\Repositories\Contracts;
|
||||
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Plugins\Sirsoft\Ckeditor5\Models\Ckeditor5ImageUpload;
|
||||
|
||||
/**
|
||||
@@ -24,4 +27,68 @@ interface ImageUploadRepositoryInterface
|
||||
* @return Ckeditor5ImageUpload
|
||||
*/
|
||||
public function create(array $data): Ckeditor5ImageUpload;
|
||||
|
||||
/**
|
||||
* 기준 시각보다 오래된 업로드를 오래된 순으로 조회합니다.
|
||||
*
|
||||
* 정리 후보 조회 전용이라 판정·삭제에 필요한 컬럼만 읽습니다.
|
||||
*
|
||||
* @param Carbon $threshold 기준 시각 (이 시각 이전 업로드가 대상)
|
||||
* @param int $limit 최대 조회 건수
|
||||
* @return Collection<int, Ckeditor5ImageUpload> 업로드 목록 (created_at 오름차순)
|
||||
*/
|
||||
public function findOlderThan(Carbon $threshold, int $limit): Collection;
|
||||
|
||||
/**
|
||||
* 기준 시각보다 오래된 업로드 건수를 반환합니다.
|
||||
*
|
||||
* @param Carbon $threshold 기준 시각
|
||||
* @return int 건수
|
||||
*/
|
||||
public function countOlderThan(Carbon $threshold): int;
|
||||
|
||||
/**
|
||||
* 관리 화면용 업로드 목록을 페이지네이션 조회합니다.
|
||||
*
|
||||
* @param array $filters 필터 (search / date_from / date_to / sort_by / sort_order)
|
||||
* @param int $perPage 페이지 크기
|
||||
* @return LengthAwarePaginator 페이지네이터
|
||||
*/
|
||||
public function paginateForAdmin(array $filters, int $perPage): LengthAwarePaginator;
|
||||
|
||||
/**
|
||||
* 참조 판정 스캔 윈도우를 조회합니다 (최신순 상한).
|
||||
*
|
||||
* 참조 여부는 저장 컬럼이 아니라 매 조회 시 판정하므로, 참조 상태 필터를 쓸 때는
|
||||
* 전수가 아니라 최신 N 건만 훑습니다. 상한을 넘긴 사실은 응답 메타로 알립니다.
|
||||
*
|
||||
* @param array $filters 필터 (search / date_from / date_to)
|
||||
* @param int $limit 스캔 윈도우 상한
|
||||
* @return Collection<int, Ckeditor5ImageUpload> 업로드 목록 (created_at 내림차순)
|
||||
*/
|
||||
public function findScanWindow(array $filters, int $limit): Collection;
|
||||
|
||||
/**
|
||||
* ID 목록으로 업로드를 조회합니다.
|
||||
*
|
||||
* @param array<int, int> $ids 업로드 ID 목록
|
||||
* @return Collection<int, Ckeditor5ImageUpload> 업로드 목록
|
||||
*/
|
||||
public function findManyByIds(array $ids): Collection;
|
||||
|
||||
/**
|
||||
* ID 로 업로드 단건을 조회합니다.
|
||||
*
|
||||
* @param int $id 업로드 ID
|
||||
* @return Ckeditor5ImageUpload|null
|
||||
*/
|
||||
public function findById(int $id): ?Ckeditor5ImageUpload;
|
||||
|
||||
/**
|
||||
* 업로드 기록을 삭제합니다.
|
||||
*
|
||||
* @param Ckeditor5ImageUpload $upload 업로드 기록
|
||||
* @return bool 삭제 성공 여부
|
||||
*/
|
||||
public function delete(Ckeditor5ImageUpload $upload): bool;
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Plugins\Sirsoft\Ckeditor5\Repositories;
|
||||
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Plugins\Sirsoft\Ckeditor5\Repositories\Contracts\ImageReferenceSourceRepositoryInterface;
|
||||
|
||||
/**
|
||||
* 에디터 이미지 참조 소스 조회 Repository 구현체
|
||||
*
|
||||
* 테이블명은 확장이 훅으로 선언한 값이라 런타임에 정해집니다. raw SQL 대신 쿼리빌더를
|
||||
* 쓰는 이유는 테이블 프리픽스를 빌더가 붙이고 값 바인딩도 빌더가 처리하기 때문입니다.
|
||||
*/
|
||||
class ImageReferenceSourceRepository implements ImageReferenceSourceRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function resolveExistingColumns(string $table, array $columns): array
|
||||
{
|
||||
if ($table === '' || $columns === [] || ! Schema::hasTable($table)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return array_values(array_filter(
|
||||
$columns,
|
||||
fn (string $column) => Schema::hasColumn($table, $column)
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function containsAnyToken(string $table, array $columns, array $tokens): bool
|
||||
{
|
||||
if ($columns === [] || $tokens === []) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return DB::table($table)
|
||||
->where(function (Builder $query) use ($columns, $tokens) {
|
||||
foreach ($columns as $column) {
|
||||
foreach ($tokens as $token) {
|
||||
$query->orWhere($column, 'like', '%'.$this->escapeLike($token).'%');
|
||||
}
|
||||
}
|
||||
})
|
||||
->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* LIKE 와일드카드를 이스케이프합니다.
|
||||
*
|
||||
* 원본명·해시에 `%`/`_` 가 포함되면 임의 문자로 해석돼 무관한 본문이 매칭됩니다
|
||||
* (참조됨 오판 → 정리되지 않고 영구 잔존).
|
||||
*
|
||||
* @param string $value 원본 값
|
||||
* @return string 이스케이프된 값
|
||||
*/
|
||||
private function escapeLike(string $value): string
|
||||
{
|
||||
return addcslashes($value, '\\%_');
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,12 @@
|
||||
|
||||
namespace Plugins\Sirsoft\Ckeditor5\Repositories;
|
||||
|
||||
use App\Repositories\Concerns\FiltersByDateRange;
|
||||
use App\Repositories\Concerns\ResolvesSortSpec;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Plugins\Sirsoft\Ckeditor5\Models\Ckeditor5ImageUpload;
|
||||
use Plugins\Sirsoft\Ckeditor5\Repositories\Contracts\ImageUploadRepositoryInterface;
|
||||
|
||||
@@ -10,6 +16,41 @@ use Plugins\Sirsoft\Ckeditor5\Repositories\Contracts\ImageUploadRepositoryInterf
|
||||
*/
|
||||
class ImageUploadRepository implements ImageUploadRepositoryInterface
|
||||
{
|
||||
use FiltersByDateRange;
|
||||
use ResolvesSortSpec;
|
||||
|
||||
/**
|
||||
* 목록·정리 조회에서 읽는 컬럼 목록
|
||||
*
|
||||
* 참조 판정(hash·file_path)·삭제(file_path·storage_disk)·화면 표시에 쓰이는 컬럼만
|
||||
* 읽습니다. 이 테이블에는 본문 성격의 넓은 컬럼이 없으나, 컬럼을 명시해 두면 이후
|
||||
* 컬럼이 늘어도 목록이 자동으로 넓어지지 않습니다.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
private const LIST_COLUMNS = [
|
||||
'id',
|
||||
'hash',
|
||||
'original_name',
|
||||
'file_path',
|
||||
'storage_disk',
|
||||
'file_size',
|
||||
'mime_type',
|
||||
'uploaded_by',
|
||||
'created_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 관리 화면 정렬 허용 컬럼 화이트리스트
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
private const SORTABLE_COLUMNS = [
|
||||
'created_at',
|
||||
'file_size',
|
||||
'original_name',
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
protected Ckeditor5ImageUpload $model
|
||||
) {}
|
||||
@@ -29,4 +70,125 @@ class ImageUploadRepository implements ImageUploadRepositoryInterface
|
||||
{
|
||||
return $this->model->create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function findOlderThan(Carbon $threshold, int $limit): Collection
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('created_at', '<', $threshold)
|
||||
->orderBy('created_at')
|
||||
->orderBy('id')
|
||||
->limit($limit)
|
||||
->get(self::LIST_COLUMNS);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function countOlderThan(Carbon $threshold): int
|
||||
{
|
||||
return $this->model->newQuery()
|
||||
->where('created_at', '<', $threshold)
|
||||
->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function paginateForAdmin(array $filters, int $perPage): LengthAwarePaginator
|
||||
{
|
||||
$sort = $this->resolveSortSpec(
|
||||
$filters,
|
||||
self::SORTABLE_COLUMNS,
|
||||
defaultColumn: 'created_at',
|
||||
defaultDirection: 'desc',
|
||||
)[0];
|
||||
|
||||
$query = $this->applyFilters($this->model->newQuery(), $filters)
|
||||
->with('uploader:id,name')
|
||||
->orderBy($sort['column'], $sort['direction']);
|
||||
|
||||
// 정렬 마지막에 기본키를 덧붙여 전순서를 보장한다 — 동률 구간에서 인접 페이지가
|
||||
// 같은 행을 중복 노출하거나 다른 행을 누락하는 것을 막는다.
|
||||
if ($sort['column'] !== 'id') {
|
||||
$query->orderBy('id', $sort['direction']);
|
||||
}
|
||||
|
||||
return $query->paginate($perPage, self::LIST_COLUMNS);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function findScanWindow(array $filters, int $limit): Collection
|
||||
{
|
||||
return $this->applyFilters($this->model->newQuery(), $filters)
|
||||
->with('uploader:id,name')
|
||||
->orderByDesc('created_at')
|
||||
->orderByDesc('id')
|
||||
->limit($limit)
|
||||
->get(self::LIST_COLUMNS);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function findManyByIds(array $ids): Collection
|
||||
{
|
||||
if ($ids === []) {
|
||||
return new Collection;
|
||||
}
|
||||
|
||||
return $this->model->newQuery()
|
||||
->whereIn('id', $ids)
|
||||
->get(self::LIST_COLUMNS);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function findById(int $id): ?Ckeditor5ImageUpload
|
||||
{
|
||||
return $this->model->newQuery()->find($id, self::LIST_COLUMNS);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function delete(Ckeditor5ImageUpload $upload): bool
|
||||
{
|
||||
return (bool) $upload->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* 목록 필터를 쿼리에 적용합니다.
|
||||
*
|
||||
* @param Builder<Ckeditor5ImageUpload> $query 대상 쿼리
|
||||
* @param array $filters 필터 배열
|
||||
* @return Builder<Ckeditor5ImageUpload> 필터가 적용된 쿼리
|
||||
*/
|
||||
private function applyFilters(Builder $query, array $filters): Builder
|
||||
{
|
||||
$search = trim((string) ($filters['search'] ?? ''));
|
||||
|
||||
if ($search !== '') {
|
||||
$escaped = addcslashes($search, '\\%_');
|
||||
|
||||
$query->where(function (Builder $inner) use ($escaped) {
|
||||
$inner->where('original_name', 'like', '%'.$escaped.'%')
|
||||
->orWhere('hash', 'like', '%'.$escaped.'%');
|
||||
});
|
||||
}
|
||||
|
||||
$this->applyDateRangeFilter(
|
||||
$query,
|
||||
'created_at',
|
||||
$filters['date_from'] ?? null,
|
||||
$filters['date_to'] ?? null,
|
||||
);
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user