Files
sam-api/app/Traits/LockCheckTrait.php
hskwon efa2a84d2c feat(item-master): 잠금 기능 추가 및 FK 레거시 코드 정리
## 잠금 기능 (Lock Feature)
- entity_relationships 테이블에 is_locked, locked_by, locked_at 컬럼 추가
- EntityRelationship 모델에 잠금 관련 헬퍼 메서드 추가
- LockCheckTrait 생성 (destroy 시 잠금 체크 공통 로직)
- 각 Service의 destroy() 메서드에 잠금 체크 적용
- API 응답에 is_locked 필드 포함
- 한국어 에러 메시지 추가

## FK 레거시 코드 정리
- ItemMasterSeeder: entity_relationships 기반으로 전환
- ItemPage 모델: FK 기반 sections() 관계 제거
- ItemSectionService: clone() 메서드 FK 제거
- SectionTemplateService: page_id 컬럼 참조 제거
- EntityRelationship::link() 파라미터 순서 통일

## 기타
- Swagger 스키마에 is_locked 속성 추가
- 프론트엔드 가이드 문서 추가
2025-11-27 15:51:00 +09:00

46 lines
1.3 KiB
PHP

<?php
namespace App\Traits;
use App\Exceptions\BusinessException;
use App\Models\ItemMaster\EntityRelationship;
/**
* LockCheckTrait - 엔티티 잠금 체크 공통 로직
*
* 연결(entity_relationships)의 is_locked가 true인 경우:
* - 해당 연결 해제 불가
* - 연결된 자식 엔티티 삭제 불가 (연결을 통한 보호)
*/
trait LockCheckTrait
{
/**
* 엔티티 삭제 가능 여부 체크
* 잠금된 연결이 있으면 삭제 불가
*
* @throws BusinessException 잠금된 연결이 있는 경우
*/
protected function checkCanDelete(string $entityType, int $entityId): void
{
if (EntityRelationship::hasLockedParentRelationship($entityType, $entityId)) {
throw new BusinessException(__('error.entity_protected_by_locked_relationship'));
}
}
/**
* 엔티티의 잠금 상태 조회 (API Response용)
*/
protected function getEntityLockStatus(string $entityType, int $entityId): array
{
return EntityRelationship::getChildLockStatus($entityType, $entityId);
}
/**
* 엔티티가 잠금 상태인지 확인 (연결을 통한 잠금 포함)
*/
protected function isEntityLocked(string $entityType, int $entityId): bool
{
return EntityRelationship::hasLockedParentRelationship($entityType, $entityId);
}
}