feat: 에디터 파일 삭제 R2 훅 추가
- delete_editor_file 이벤트 훅 구현 - cheditor5, smarteditor2 에디터에서 이미지 삭제 시 R2에서도 삭제 - 파일 경로 패턴 매칭으로 R2 키 검색 후 삭제 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -562,6 +562,9 @@ add_replace('get_list_thumbnail_info', 'r2_hook_list_thumbnail', 10, 2);
|
|||||||
// 에디터 이미지 업로드 훅 (cheditor5, smarteditor2)
|
// 에디터 이미지 업로드 훅 (cheditor5, smarteditor2)
|
||||||
add_replace('get_editor_upload_url', 'r2_hook_editor_upload', 10, 3);
|
add_replace('get_editor_upload_url', 'r2_hook_editor_upload', 10, 3);
|
||||||
|
|
||||||
|
// 에디터 이미지 삭제 훅 (cheditor5, smarteditor2)
|
||||||
|
add_event('delete_editor_file', 'r2_hook_delete_editor_file', 10, 2);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 목록 썸네일 정보 (R2 지원)
|
* 목록 썸네일 정보 (R2 지원)
|
||||||
* 메인페이지, 최근게시물, 게시판 목록 등에서 사용
|
* 메인페이지, 최근게시물, 게시판 목록 등에서 사용
|
||||||
@@ -874,6 +877,50 @@ function r2_hook_editor_upload($url, $savefile, $fileInfo)
|
|||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 에디터 파일 삭제 시 R2에서도 삭제
|
||||||
|
*
|
||||||
|
* @param string $filepath 삭제된 로컬 파일 경로
|
||||||
|
* @param bool $success 로컬 삭제 성공 여부
|
||||||
|
*/
|
||||||
|
function r2_hook_delete_editor_file($filepath, $success)
|
||||||
|
{
|
||||||
|
if (!is_r2_enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 파일 경로에서 에디터 이미지 정보 추출
|
||||||
|
// 예: /var/www/html/data/editor/2601/filename.jpg
|
||||||
|
if (preg_match('/\/data\/editor\/(\d+)\/(.+)$/', $filepath, $matches)) {
|
||||||
|
$dateFolder = $matches[1];
|
||||||
|
$filename = $matches[2];
|
||||||
|
|
||||||
|
$handler = get_r2_handler();
|
||||||
|
|
||||||
|
// R2에서 해당 파일 검색 및 삭제
|
||||||
|
// 경로 패턴: users/*/editor/날짜/파일명
|
||||||
|
try {
|
||||||
|
$year = substr($dateFolder, 0, 2);
|
||||||
|
$month = substr($dateFolder, 2, 2);
|
||||||
|
$searchPattern = "editor/20{$year}-{$month}";
|
||||||
|
|
||||||
|
$objects = $handler->getAdapter()->listObjects($searchPattern, 100);
|
||||||
|
|
||||||
|
foreach ($objects as $obj) {
|
||||||
|
if (strpos($obj['Key'], $filename) !== false) {
|
||||||
|
$deleted = $handler->getAdapter()->delete($obj['Key']);
|
||||||
|
if ($deleted) {
|
||||||
|
error_log("[R2] Editor file deleted: {$obj['Key']}");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
error_log("[R2] Editor file delete failed: " . $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* R2 연결 테스트
|
* R2 연결 테스트
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user